@@ -16,74 +16,45 @@ namespace RNSkia {
16
16
17
17
sk_sp<SkSurface> OpenGLWindowContext::getSurface () {
18
18
if (_skSurface == nullptr ) {
19
-
20
- struct ReleaseContext {
21
- std::unique_ptr<gl::Surface> surface = nullptr ;
22
- };
23
-
24
- if (!_window) {
25
- throw std::runtime_error (" No native window provided" );
26
- }
27
- auto releaseCtx = new ReleaseContext ();
28
- releaseCtx->surface =
29
- _context->_glDisplay ->makeWindowSurface (_context->_glConfig , _window);
30
- if (!releaseCtx->surface ) {
31
- throw std::runtime_error (" Failed to create window surface" );
32
- }
33
- _glSurface = releaseCtx->surface .get ();
34
-
35
- // Now make this one current
36
- auto success = _context->_glContext ->makeCurrent (releaseCtx->surface .get ());
37
- if (!success) {
38
- throw std::runtime_error (" Failed to make window surface current" );
39
- }
40
-
41
- // Set up parameters for the render target so that it
42
- // matches the underlying OpenGL context.
43
- GrGLFramebufferInfo fboInfo;
44
-
45
- // We pass 0 as the framebuffer id, since the
46
- // underlying Skia GrGlGpu will read this when wrapping the context in the
47
- // render target and the GrGlGpu object.
48
- fboInfo.fFBOID = 0 ;
49
- fboInfo.fFormat = 0x8058 ; // GL_RGBA8
50
-
19
+ _glContext->makeCurrent (_glSurface.get ());
51
20
GLint stencil;
52
21
glGetIntegerv (GL_STENCIL_BITS, &stencil);
53
22
54
23
GLint samples;
55
24
glGetIntegerv (GL_SAMPLES, &samples);
56
25
57
- auto colorType = kN32_SkColorType ;
26
+ auto colorType = kRGBA_8888_SkColorType ;
58
27
59
28
auto maxSamples =
60
- _context-> _directContext ->maxSurfaceSampleCountForColorType (colorType);
29
+ _directContext->maxSurfaceSampleCountForColorType (colorType);
61
30
62
31
if (samples > maxSamples) {
63
32
samples = maxSamples;
64
33
}
65
34
66
- auto renderTarget = GrBackendRenderTargets::MakeGL (_width, _height, samples,
67
- stencil, fboInfo);
68
-
69
- SkSurfaceProps props (0 , kUnknown_SkPixelGeometry );
70
-
71
- // Create surface object
35
+ GrGLFramebufferInfo fbInfo;
36
+ fbInfo.fFBOID = 0 ;
37
+ fbInfo.fFormat = GR_GL_RGBA8;
38
+ // fbInfo.fProtected =
39
+ // skgpu::Protected(fDisplayParams.fCreateProtectedNativeBackend);
40
+
41
+ auto width = ANativeWindow_getWidth (_window);
42
+ auto height = ANativeWindow_getHeight (_window);
43
+ auto backendRT =
44
+ GrBackendRenderTargets::MakeGL (width, height, samples, stencil, fbInfo);
45
+ sk_sp<SkColorSpace> colorSpace (nullptr );
46
+ SkSurfaceProps surfaceProps (0 , kRGB_H_SkPixelGeometry );
72
47
_skSurface = SkSurfaces::WrapBackendRenderTarget (
73
- _context->_directContext .get (), renderTarget,
74
- kBottomLeft_GrSurfaceOrigin , colorType, nullptr , &props,
75
- [](void *addr) {
76
- auto releaseCtx = reinterpret_cast <ReleaseContext *>(addr);
77
- delete releaseCtx;
78
- },
79
- reinterpret_cast <void *>(releaseCtx));
48
+ _directContext.get (), backendRT, kBottomLeft_GrSurfaceOrigin ,
49
+ kRGBA_8888_SkColorType , colorSpace, &surfaceProps);
80
50
}
81
51
return _skSurface;
82
52
}
83
53
84
54
void OpenGLWindowContext::present () {
85
- _context->_glContext ->makeCurrent (_glSurface);
86
- _context->_directContext ->flushAndSubmit ();
55
+ _glContext->makeCurrent (_glSurface.get ());
56
+ // TODO: is flushAndSubmit needed here?
57
+ _directContext->flushAndSubmit ();
87
58
_glSurface->present ();
88
59
}
89
60
0 commit comments