11#include " ISkiaGLWindow.h"
22
33#include " include/gpu/gl/GrGLInterface.h"
4+ #include " include/gpu/GrContext.h"
45#include " include/core/SkImageInfo.h"
56#include " include/core/SkGraphics.h"
67
78// The Skia Surface is the object we use to talk to the GPU
89// In order to render to an OpenGL context, we need to obtain the
910// SkSurface from the GL context directly.
1011// Ref: https://skia.org/docs/user/api/skcanvas_creation/
11- sk_sp<SkSurface> ISkiaGLWindow:: obtainSkiaSurfaceFromCurrentGLContext () {
12- auto glContext = m_glWindow ->glContext ();
12+ sk_sp<SkSurface> obtainSkiaSurfaceFromCurrentGLContext (GLWindow *glWindow ) {
13+ auto glContext = glWindow ->glContext ();
1314
1415 // Grabs the OpenGL context that is currently set as "current"
1516 // (we set it with `glfwMakeContextCurrent` in `main.cpp`)
1617 auto interface = GrGLMakeNativeInterface ();
1718
1819 const GrContextOptions &grOptions = GrContextOptions ();
19- m_graphicsContext = GrContext::MakeGL (interface, grOptions);
20+ auto grContext = GrContext::MakeGL (interface, grOptions);
2021
21- int width = m_glWindow ->width ();
22- int height = m_glWindow ->height ();
22+ int width = glWindow ->width ();
23+ int height = glWindow ->height ();
2324 SkImageInfo imageInformation = SkImageInfo::MakeN32Premul (width, height);
2425
2526
2627 SkSurfaceProps props (0 , kUnknown_SkPixelGeometry );
2728
2829 // Create the Skia Surface from the GL context
2930 return SkSurface::MakeRenderTarget (
30- m_graphicsContext .get (),
31+ grContext .get (),
3132 SkBudgeted::kNo ,
3233 imageInformation,
3334 kTopLeft_GrSurfaceOrigin ,
@@ -39,7 +40,7 @@ sk_sp<SkSurface> ISkiaGLWindow::obtainSkiaSurfaceFromCurrentGLContext() {
3940SkCanvas* ISkiaGLWindow::obtainSkCanvas () {
4041 // NOTE: We put SkiaSurface in a class field to keep it in memory
4142 // So we can keep drawing (either it crashes)
42- m_skiaSurface = obtainSkiaSurfaceFromCurrentGLContext ();
43+ m_skiaSurface = obtainSkiaSurfaceFromCurrentGLContext (m_glWindow );
4344 if (!m_skiaSurface) {
4445 return nullptr ;
4546 }
@@ -56,8 +57,6 @@ void ISkiaGLWindow::requestPaint() {
5657 if (!m_skiaContext || !m_skiaSurface) return ;
5758
5859 paintThisFrame (m_skiaContext);
59- // Tell Skia to render stuff to GPU
60- m_graphicsContext->flush ();
6160};
6261
6362ISkiaGLWindow::ISkiaGLWindow (GLWindow *glWindow)
0 commit comments