@@ -34,16 +34,13 @@ static const int kGrCacheMaxCount = 8192;
3434// system channel.
3535static const size_t kGrCacheMaxByteSize = 24 * (1 << 20 );
3636
37- GPUSurfaceGL::GPUSurfaceGL (GPUSurfaceGLDelegate* delegate,
38- bool render_to_surface)
39- : delegate_(delegate),
40- render_to_surface_ (render_to_surface),
41- weak_factory_(this ) {
42- auto context_switch = delegate_->GLContextMakeCurrent ();
37+ sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext (
38+ GPUSurfaceGLDelegate* delegate) {
39+ auto context_switch = delegate->GLContextMakeCurrent ();
4340 if (!context_switch->GetResult ()) {
4441 FML_LOG (ERROR)
4542 << " Could not make the context current to setup the gr context." ;
46- return ;
43+ return nullptr ;
4744 }
4845
4946 GrContextOptions options;
@@ -64,32 +61,31 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate,
6461 // TODO(goderbauer): remove option when skbug.com/7523 is fixed.
6562 // A similar work-around is also used in shell/common/io_manager.cc.
6663 options.fDisableGpuYUVConversion = true ;
64+ auto context = GrDirectContext::MakeGL (delegate->GetGLInterface (), options);
6765
68- auto context = GrDirectContext::MakeGL (delegate_->GetGLInterface (), options);
69-
70- if (context == nullptr ) {
66+ if (!context) {
7167 FML_LOG (ERROR) << " Failed to setup Skia Gr context." ;
72- return ;
68+ return nullptr ;
7369 }
7470
75- context_ = std::move (context);
76-
77- context_->setResourceCacheLimits (kGrCacheMaxCount , kGrCacheMaxByteSize );
78-
79- context_owner_ = true ;
80-
81- valid_ = true ;
71+ context->setResourceCacheLimits (kGrCacheMaxCount , kGrCacheMaxByteSize );
8272
8373 std::vector<PersistentCache::SkSLCache> caches =
8474 PersistentCache::GetCacheForProcess ()->LoadSkSLs ();
8575 int compiled_count = 0 ;
8676 for (const auto & cache : caches) {
87- compiled_count += context_ ->precompileShader (*cache.first , *cache.second );
77+ compiled_count += context ->precompileShader (*cache.first , *cache.second );
8878 }
8979 FML_LOG (INFO) << " Found " << caches.size () << " SkSL shaders; precompiled "
9080 << compiled_count;
9181
92- delegate_->GLContextClearCurrent ();
82+ return context;
83+ }
84+
85+ GPUSurfaceGL::GPUSurfaceGL (GPUSurfaceGLDelegate* delegate,
86+ bool render_to_surface)
87+ : GPUSurfaceGL(MakeGLContext(delegate), delegate, render_to_surface) {
88+ context_owner_ = true ;
9389}
9490
9591GPUSurfaceGL::GPUSurfaceGL (sk_sp<GrDirectContext> gr_context,
@@ -109,7 +105,6 @@ GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrDirectContext> gr_context,
109105 delegate_->GLContextClearCurrent ();
110106
111107 valid_ = true ;
112- context_owner_ = false ;
113108}
114109
115110GPUSurfaceGL::~GPUSurfaceGL () {
0 commit comments