11#include " ISkiaGLWindow.h"
22
33#include " include/gpu/gl/GrGLInterface.h"
4- #include " include/gpu/GrContext.h"
54#include " include/core/SkImageInfo.h"
65#include " include/core/SkGraphics.h"
76
87// The Skia Surface is the object we use to talk to the GPU
98// In order to render to an OpenGL context, we need to obtain the
109// SkSurface from the GL context directly.
1110// Ref: https://skia.org/docs/user/api/skcanvas_creation/
12- sk_sp<SkSurface> obtainSkiaSurfaceFromCurrentGLContext (GLWindow *glWindow ) {
13- auto glContext = glWindow ->glContext ();
11+ sk_sp<SkSurface> ISkiaGLWindow:: obtainSkiaSurfaceFromCurrentGLContext () {
12+ auto glContext = m_glWindow ->glContext ();
1413
1514 // You've already created your OpenGL context and bound it.
1615 sk_sp<const GrGLInterface> interface = nullptr ;
1716
1817 const GrContextOptions &grOptions = GrContextOptions ();
19- auto grContext = GrContext::MakeGL (interface, grOptions);
18+ m_graphicsContext = GrContext::MakeGL (interface, grOptions);
2019
21- int width = glWindow ->width ();
22- int height = glWindow ->height ();
20+ int width = m_glWindow ->width ();
21+ int height = m_glWindow ->height ();
2322 SkImageInfo imageInformation = SkImageInfo::MakeN32Premul (width, height);
2423
2524
2625 SkSurfaceProps props (0 , kUnknown_SkPixelGeometry );
2726
2827 // Create the Skia Surface from the GL context
2928 return SkSurface::MakeRenderTarget (
30- grContext .get (),
29+ m_graphicsContext .get (),
3130 SkBudgeted::kNo ,
3231 imageInformation,
3332 kTopLeft_GrSurfaceOrigin ,
@@ -39,7 +38,7 @@ sk_sp<SkSurface> obtainSkiaSurfaceFromCurrentGLContext(GLWindow *glWindow) {
3938SkCanvas* ISkiaGLWindow::obtainSkCanvas () {
4039 // NOTE: We put SkiaSurface in a class field to keep it in memory
4140 // So we can keep drawing (either it crashes)
42- m_skiaSurface = obtainSkiaSurfaceFromCurrentGLContext (m_glWindow );
41+ m_skiaSurface = obtainSkiaSurfaceFromCurrentGLContext ();
4342 if (!m_skiaSurface) {
4443 return nullptr ;
4544 }
@@ -56,6 +55,8 @@ void ISkiaGLWindow::requestPaint() {
5655 if (!m_skiaContext || !m_skiaSurface) return ;
5756
5857 paintThisFrame (m_skiaContext);
58+ // Tell Skia to render stuff to GPU
59+ m_graphicsContext->flush ();
5960};
6061
6162ISkiaGLWindow::ISkiaGLWindow (GLWindow *glWindow)
0 commit comments