99#include " flutter/fml/size.h"
1010#include " flutter/fml/trace_event.h"
1111#include " flutter/shell/common/persistent_cache.h"
12- #include " flutter/shell/common/renderer_context_switch_manager.h"
1312#include " third_party/skia/include/core/SkColorFilter.h"
1413#include " third_party/skia/include/core/SkSurface.h"
1514#include " third_party/skia/include/gpu/GrBackendSurface.h"
@@ -40,10 +39,7 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate,
4039 : delegate_(delegate),
4140 render_to_surface_ (render_to_surface),
4241 weak_factory_(this ) {
43- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
44- context_switch = delegate_->GLContextMakeCurrent ();
45-
46- if (!context_switch->GetSwitchResult ()) {
42+ if (!delegate_->GLContextMakeCurrent ()) {
4743 FML_LOG (ERROR)
4844 << " Could not make the context current to setup the gr context." ;
4945 return ;
@@ -91,6 +87,8 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate,
9187 }
9288 FML_LOG (INFO) << " Found " << caches.size () << " SkSL shaders; precompiled "
9389 << compiled_count;
90+
91+ delegate_->GLContextClearCurrent ();
9492}
9593
9694GPUSurfaceGL::GPUSurfaceGL (sk_sp<GrContext> gr_context,
@@ -100,9 +98,7 @@ GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrContext> gr_context,
10098 context_(gr_context),
10199 render_to_surface_(render_to_surface),
102100 weak_factory_(this ) {
103- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
104- context_switch = delegate_->GLContextMakeCurrent ();
105- if (!context_switch->GetSwitchResult ()) {
101+ if (!delegate_->GLContextMakeCurrent ()) {
106102 FML_LOG (ERROR)
107103 << " Could not make the context current to setup the gr context." ;
108104 return ;
@@ -118,9 +114,8 @@ GPUSurfaceGL::~GPUSurfaceGL() {
118114 if (!valid_) {
119115 return ;
120116 }
121- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
122- context_switch = delegate_->GLContextMakeCurrent ();
123- if (!context_switch->GetSwitchResult ()) {
117+
118+ if (!delegate_->GLContextMakeCurrent ()) {
124119 FML_LOG (ERROR) << " Could not make the context current to destroy the "
125120 " GrContext resources." ;
126121 return ;
@@ -131,6 +126,8 @@ GPUSurfaceGL::~GPUSurfaceGL() {
131126 context_->releaseResourcesAndAbandonContext ();
132127 }
133128 context_ = nullptr ;
129+
130+ delegate_->GLContextClearCurrent ();
134131}
135132
136133// |Surface|
@@ -256,9 +253,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
256253 return nullptr ;
257254 }
258255
259- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
260- context_switch = delegate_->GLContextMakeCurrent ();
261- if (!context_switch->GetSwitchResult ()) {
256+ if (!delegate_->GLContextMakeCurrent ()) {
262257 FML_LOG (ERROR)
263258 << " Could not make the context current to acquire the frame." ;
264259 return nullptr ;
@@ -290,18 +285,14 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
290285 return weak ? weak->PresentSurface (canvas) : false ;
291286 };
292287
293- std::unique_ptr<SurfaceFrame> result =
294- std::make_unique<SurfaceFrame>(surface, submit_callback);
295- return result;
288+ return std::make_unique<SurfaceFrame>(surface, submit_callback);
296289}
297290
298291bool GPUSurfaceGL::PresentSurface (SkCanvas* canvas) {
299292 if (delegate_ == nullptr || canvas == nullptr || context_ == nullptr ) {
300293 return false ;
301294 }
302295
303- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
304- context_switch = delegate_->GLContextMakeCurrent ();
305296 if (offscreen_surface_ != nullptr ) {
306297 TRACE_EVENT0 (" flutter" , " CopyTextureOnscreen" );
307298 SkPaint paint;
@@ -338,6 +329,7 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
338329
339330 onscreen_surface_ = std::move (new_onscreen_surface);
340331 }
332+
341333 return true ;
342334}
343335
@@ -368,8 +360,7 @@ flutter::ExternalViewEmbedder* GPUSurfaceGL::GetExternalViewEmbedder() {
368360}
369361
370362// |Surface|
371- std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
372- GPUSurfaceGL::MakeRenderContextCurrent () {
363+ bool GPUSurfaceGL::MakeRenderContextCurrent () {
373364 return delegate_->GLContextMakeCurrent ();
374365}
375366
0 commit comments