@@ -34,13 +34,16 @@ static const int kGrCacheMaxCount = 8192;
3434// system channel.
3535static const size_t kGrCacheMaxByteSize = 24 * (1 << 20 );
3636
37- sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext (
38- GPUSurfaceGLDelegate* delegate) {
39- auto context_switch = delegate->GLContextMakeCurrent ();
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 ();
4043 if (!context_switch->GetResult ()) {
4144 FML_LOG (ERROR)
4245 << " Could not make the context current to setup the gr context." ;
43- return nullptr ;
46+ return ;
4447 }
4548
4649 GrContextOptions options;
@@ -61,39 +64,39 @@ sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext(
6164 // TODO(goderbauer): remove option when skbug.com/7523 is fixed.
6265 // A similar work-around is also used in shell/common/io_manager.cc.
6366 options.fDisableGpuYUVConversion = true ;
64- auto context = GrDirectContext::MakeGL (delegate->GetGLInterface (), options);
6567
66- if (!context) {
68+ auto context = GrDirectContext::MakeGL (delegate_->GetGLInterface (), options);
69+
70+ if (context == nullptr ) {
6771 FML_LOG (ERROR) << " Failed to setup Skia Gr context." ;
68- return nullptr ;
72+ return ;
6973 }
7074
71- context->setResourceCacheLimits (kGrCacheMaxCount , kGrCacheMaxByteSize );
75+ context_ = std::move (context);
76+
77+ context_->setResourceCacheLimits (kGrCacheMaxCount , kGrCacheMaxByteSize );
78+
79+ context_owner_ = true ;
80+
81+ valid_ = true ;
7282
7383 std::vector<PersistentCache::SkSLCache> caches =
7484 PersistentCache::GetCacheForProcess ()->LoadSkSLs ();
7585 int compiled_count = 0 ;
7686 for (const auto & cache : caches) {
77- compiled_count += context ->precompileShader (*cache.first , *cache.second );
87+ compiled_count += context_ ->precompileShader (*cache.first , *cache.second );
7888 }
7989 FML_LOG (INFO) << " Found " << caches.size () << " SkSL shaders; precompiled "
8090 << compiled_count;
8191
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 ;
92+ delegate_->GLContextClearCurrent ();
8993}
9094
9195GPUSurfaceGL::GPUSurfaceGL (sk_sp<GrDirectContext> gr_context,
9296 GPUSurfaceGLDelegate* delegate,
9397 bool render_to_surface)
9498 : delegate_(delegate),
9599 context_(gr_context),
96- context_owner_(false ),
97100 render_to_surface_(render_to_surface),
98101 weak_factory_(this ) {
99102 auto context_switch = delegate_->GLContextMakeCurrent ();
@@ -106,6 +109,7 @@ GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrDirectContext> gr_context,
106109 delegate_->GLContextClearCurrent ();
107110
108111 valid_ = true ;
112+ context_owner_ = false ;
109113}
110114
111115GPUSurfaceGL::~GPUSurfaceGL () {
0 commit comments