Skip to content

Commit

Permalink
Reuse SkSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 7, 2024
1 parent 5bbfed2 commit 775da6f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Submodules/UIKit/include/platforms/ios/SkiaCtx_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class SkiaCtx_ios : public SkiaCtx_sdlBase {

private:
sk_sp<GrDirectContext> context;

sk_sp<SkSurface> surface;

void initContext();
};

Expand Down
3 changes: 2 additions & 1 deletion Submodules/UIKit/include/platforms/macos/SkiaCtx_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class SkiaCtx_macos: public SkiaCtx_sdlBase {
sk_sp<GrDirectContext> directContext() override { return context; }
private:
sk_sp<GrDirectContext> context;

sk_sp<SkSurface> surface;

void initContext();
};

Expand Down
11 changes: 6 additions & 5 deletions Submodules/UIKit/lib/platforms/apple/ios/SkiaCtx_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@

sk_sp<SkSurface> SkiaCtx_ios::getBackbufferSurface() {
auto size = getSize();
if (_size.width != size.width || _size.height != size.height) {
_size = size;
initContext();
}
if (_size.width == size.width && _size.height == size.height && surface != nullptr) { return surface; }

_size = size;

GrGLFramebufferInfo framebuffer_info;
framebuffer_info.fFormat = GL_RGBA8;
Expand All @@ -61,9 +60,11 @@
SkSurfaceProps props;

glViewport(0, 0, _size.width * scaleFactor, _size.height * scaleFactor);
return SkSurfaces::WrapBackendRenderTarget(context.get(), target,
surface = SkSurfaces::WrapBackendRenderTarget(context.get(), target,
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
nullptr, &props);

return surface;
}

std::unique_ptr<SkiaCtx> NXKit::MakeSkiaCtx() {
Expand Down
13 changes: 7 additions & 6 deletions Submodules/UIKit/lib/platforms/apple/macos/SkiaCtx_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@

sk_sp<SkSurface> SkiaCtx_macos::getBackbufferSurface() {
auto size = getSize();
if (_size.width != size.width || _size.height != size.height) {
_size = size;
initContext();
}
if (_size.width == size.width && _size.height == size.height && surface != nullptr) { return surface; }

_size = size;

GrGLFramebufferInfo framebuffer_info;
framebuffer_info.fFormat = GL_RGBA8;
Expand All @@ -61,9 +60,11 @@
SkSurfaceProps props;

glViewport(0, 0, _size.width * scaleFactor, _size.height * scaleFactor);
return SkSurfaces::WrapBackendRenderTarget(context.get(), target,
surface = SkSurfaces::WrapBackendRenderTarget(context.get(), target,
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
nullptr, &props);

return surface;
}

std::unique_ptr<SkiaCtx> NXKit::MakeSkiaCtx() {
Expand All @@ -74,4 +75,4 @@
@autoreleasepool {
return loop();
}
}
}

0 comments on commit 775da6f

Please sign in to comment.