-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #435 from Shopify/bugfix/398-fix-crash-in-releasemode
Fix crash in release mode
- Loading branch information
Showing
24 changed files
with
408 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <RNSkDrawViewImpl.h> | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wdocumentation" | ||
|
||
#include <SkSurface.h> | ||
#include <SkCanvas.h> | ||
|
||
#pragma clang diagnostic pop | ||
|
||
#include <RNSkLog.h> | ||
|
||
namespace RNSkia { | ||
RNSkDrawViewImpl::RNSkDrawViewImpl(std::shared_ptr <RNSkia::RNSkPlatformContext> context, std::function<void()> releaseSurfaceCallback) : | ||
RNSkia::RNSkDrawView(context), | ||
_releaseSurfaceCallback(std::move(releaseSurfaceCallback)) {} | ||
|
||
void RNSkDrawViewImpl::surfaceAvailable(ANativeWindow* surface, int width, int height) { | ||
_width = width; | ||
_height = height; | ||
|
||
if (_renderer == nullptr) | ||
{ | ||
// Create renderer! | ||
_renderer = std::make_unique<SkiaOpenGLRenderer>(surface, getNativeId()); | ||
|
||
// Redraw | ||
requestRedraw(); | ||
} | ||
} | ||
|
||
void RNSkDrawViewImpl::surfaceDestroyed() { | ||
if (_renderer != nullptr) | ||
{ | ||
// Start teardown | ||
_renderer->teardown(); | ||
|
||
// Teardown renderer on the render thread since OpenGL demands | ||
// same thread access for OpenGL contexts. | ||
getPlatformContext()->runOnRenderThread([weakSelf = weak_from_this()]() { | ||
auto self = weakSelf.lock(); | ||
if(self) { | ||
auto drawViewImpl = std::dynamic_pointer_cast<RNSkDrawViewImpl>(self); | ||
if(drawViewImpl->_renderer != nullptr) { | ||
drawViewImpl->_renderer->run(nullptr, 0, 0); | ||
} | ||
// Remove renderer | ||
drawViewImpl->_renderer = nullptr; | ||
drawViewImpl->_releaseSurfaceCallback(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
void RNSkDrawViewImpl::surfaceSizeChanged(int width, int height) { | ||
_width = width; | ||
_height = height; | ||
|
||
// Redraw after size change | ||
requestRedraw(); | ||
} | ||
|
||
void RNSkDrawViewImpl::drawPicture(const sk_sp <SkPicture> picture) { | ||
if(_renderer != nullptr) { | ||
_renderer->run(picture, _width, _height); | ||
} | ||
} | ||
} |
Oops, something went wrong.