Skip to content

Commit

Permalink
🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Nov 20, 2024
1 parent bc09a44 commit 8afeef3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
std::unique_ptr<gl::Surface> surface = nullptr;
};

if (!_window) {
throw std::runtime_error("No native window provided");
}
auto releaseCtx = new ReleaseContext();
releaseCtx->surface =
_context->_glDisplay->makeWindowSurface(_context->_glConfig, _window);
Expand Down
10 changes: 8 additions & 2 deletions packages/skia/android/cpp/rnskia-android/OpenGLWindowContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ class OpenGLWindowContext : public WindowContext {
public:
OpenGLWindowContext(OpenGLContext *context, ANativeWindow *window, int width,
int height)
: _context(context), _window(window), _width(width), _height(height) {}
: _context(context), _window(window), _width(width), _height(height) {
ANativeWindow_acquire(_window);
}

~OpenGLWindowContext() = default;
~OpenGLWindowContext() {
_skSurface = nullptr;
_glSurface = nullptr;
ANativeWindow_release(_window);
}

sk_sp<SkSurface> getSurface() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext {
#if defined(SK_GRAPHITE)
return DawnContext::getInstance().MakeWindow(surface, width, height);
#else
return OpenGLContext::getInstance().MakeWindow(
reinterpret_cast<ANativeWindow *>(surface), width, height);
auto aWindow = reinterpret_cast<ANativeWindow *>(surface);
return OpenGLContext::getInstance().MakeWindow(aWindow, width, height);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion packages/skia/android/cpp/rnskia-android/gl/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Context {

const EGLContext &getHandle() const { return _context; }

bool makeCurrent(const Surface* surface) {
bool makeCurrent(const Surface *surface) {
if (_context == EGL_NO_CONTEXT) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/skia/android/cpp/rnskia-android/gl/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Display {
}

std::unique_ptr<Surface> makeWindowSurface(const EGLConfig &config,
ANativeWindow* window) {
ANativeWindow *window) {
const EGLint attribs[] = {EGL_NONE};
auto surface = eglCreateWindowSurface(_display, config, window, attribs);
if (surface == EGL_NO_SURFACE) {
Expand Down
3 changes: 2 additions & 1 deletion packages/skia/android/cpp/rnskia-android/gl/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace gl {

class Surface {
public:
Surface(EGLDisplay display, EGLSurface surface): _display(display), _surface(surface) {}
Surface(EGLDisplay display, EGLSurface surface)
: _display(display), _surface(surface) {}

~Surface() {
if (_surface != EGL_NO_SURFACE) {
Expand Down
3 changes: 3 additions & 0 deletions packages/skia/cpp/api/JsiSkiaContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class JsiSkiaContext : public JsiSkWrappingSharedPtrHostObject<WindowContext> {
void *surface = reinterpret_cast<void *>(nativeBufferPointer);
auto width = static_cast<int>(arguments[1].asNumber());
auto height = static_cast<int>(arguments[2].asNumber());
if (surface == nullptr) {
throw std::runtime_error("Surface is null");
}
auto result =
context->makeContextFromNativeSurface(surface, width, height);
// Return the newly constructed object
Expand Down

0 comments on commit 8afeef3

Please sign in to comment.