This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
implemented GetMainContext() for opengl - reland #23865
Merged
gaaclarke
merged 1 commit into
flutter:master
from
gaaclarke:lfe-share-context-opengl-reland
Jan 22, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,13 @@ static const int kGrCacheMaxCount = 8192; | |
// system channel. | ||
static const size_t kGrCacheMaxByteSize = 24 * (1 << 20); | ||
|
||
GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, | ||
bool render_to_surface) | ||
: delegate_(delegate), | ||
render_to_surface_(render_to_surface), | ||
weak_factory_(this) { | ||
auto context_switch = delegate_->GLContextMakeCurrent(); | ||
sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext( | ||
GPUSurfaceGLDelegate* delegate) { | ||
auto context_switch = delegate->GLContextMakeCurrent(); | ||
if (!context_switch->GetResult()) { | ||
FML_LOG(ERROR) | ||
<< "Could not make the context current to setup the gr context."; | ||
return; | ||
return nullptr; | ||
} | ||
|
||
GrContextOptions options; | ||
|
@@ -64,39 +61,39 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, | |
// TODO(goderbauer): remove option when skbug.com/7523 is fixed. | ||
// A similar work-around is also used in shell/common/io_manager.cc. | ||
options.fDisableGpuYUVConversion = true; | ||
auto context = GrDirectContext::MakeGL(delegate->GetGLInterface(), options); | ||
|
||
auto context = GrDirectContext::MakeGL(delegate_->GetGLInterface(), options); | ||
|
||
if (context == nullptr) { | ||
if (!context) { | ||
FML_LOG(ERROR) << "Failed to setup Skia Gr context."; | ||
return; | ||
return nullptr; | ||
} | ||
|
||
context_ = std::move(context); | ||
|
||
context_->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize); | ||
|
||
context_owner_ = true; | ||
|
||
valid_ = true; | ||
context->setResourceCacheLimits(kGrCacheMaxCount, kGrCacheMaxByteSize); | ||
|
||
std::vector<PersistentCache::SkSLCache> caches = | ||
PersistentCache::GetCacheForProcess()->LoadSkSLs(); | ||
int compiled_count = 0; | ||
for (const auto& cache : caches) { | ||
compiled_count += context_->precompileShader(*cache.first, *cache.second); | ||
compiled_count += context->precompileShader(*cache.first, *cache.second); | ||
} | ||
FML_LOG(INFO) << "Found " << caches.size() << " SkSL shaders; precompiled " | ||
<< compiled_count; | ||
|
||
delegate_->GLContextClearCurrent(); | ||
return context; | ||
} | ||
|
||
GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, | ||
bool render_to_surface) | ||
: GPUSurfaceGL(MakeGLContext(delegate), delegate, render_to_surface) { | ||
context_owner_ = true; | ||
} | ||
|
||
GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrDirectContext> gr_context, | ||
GPUSurfaceGLDelegate* delegate, | ||
bool render_to_surface) | ||
: delegate_(delegate), | ||
context_(gr_context), | ||
context_owner_(false), | ||
render_to_surface_(render_to_surface), | ||
weak_factory_(this) { | ||
auto context_switch = delegate_->GLContextMakeCurrent(); | ||
|
@@ -108,8 +105,7 @@ GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrDirectContext> gr_context, | |
|
||
delegate_->GLContextClearCurrent(); | ||
|
||
valid_ = true; | ||
context_owner_ = false; | ||
valid_ = gr_context != nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the changed line from the previous PR that was reverted. |
||
} | ||
|
||
GPUSurfaceGL::~GPUSurfaceGL() { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how valid_ was getting set to false previously.