Do not share the GrDirectContext across engine instances on Android (flutter/engine#28694)

This commit is contained in:
Jason Simmons
2021-09-17 17:43:01 -07:00
committed by GitHub
parent cff8296459
commit 5cca7e4f66
4 changed files with 4 additions and 59 deletions

View File

@@ -52,13 +52,7 @@ std::unique_ptr<Surface> AndroidSurfaceGL::CreateGPUSurface(
if (gr_context) {
return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true);
} else {
sk_sp<GrDirectContext> main_skia_context =
GLContextPtr()->GetMainSkiaContext();
if (!main_skia_context) {
main_skia_context = GPUSurfaceGL::MakeGLContext(this);
GLContextPtr()->SetMainSkiaContext(main_skia_context);
}
return std::make_unique<GPUSurfaceGL>(main_skia_context, this, true);
return std::make_unique<GPUSurfaceGL>(this, true);
}
}
@@ -177,14 +171,7 @@ AndroidContextGL* AndroidSurfaceGL::GLContextPtr() const {
std::unique_ptr<Surface> AndroidSurfaceGL::CreatePbufferSurface() {
onscreen_surface_ = GLContextPtr()->CreatePbufferSurface();
sk_sp<GrDirectContext> main_skia_context =
GLContextPtr()->GetMainSkiaContext();
if (!main_skia_context) {
main_skia_context = GPUSurfaceGL::MakeGLContext(this);
GLContextPtr()->SetMainSkiaContext(main_skia_context);
}
return std::make_unique<GPUSurfaceGL>(main_skia_context, this, true);
return std::make_unique<GPUSurfaceGL>(this, true);
}
} // namespace flutter

View File

@@ -9,11 +9,7 @@ namespace flutter {
AndroidContext::AndroidContext(AndroidRenderingAPI rendering_api)
: rendering_api_(rendering_api) {}
AndroidContext::~AndroidContext() {
if (main_context_) {
main_context_->releaseResourcesAndAbandonContext();
}
};
AndroidContext::~AndroidContext() = default;
AndroidRenderingAPI AndroidContext::RenderingApi() const {
return rendering_api_;
@@ -23,13 +19,4 @@ bool AndroidContext::IsValid() const {
return true;
}
void AndroidContext::SetMainSkiaContext(
const sk_sp<GrDirectContext>& main_context) {
main_context_ = main_context;
}
sk_sp<GrDirectContext> AndroidContext::GetMainSkiaContext() const {
return main_context_;
}
} // namespace flutter

View File

@@ -28,37 +28,9 @@ class AndroidContext {
virtual bool IsValid() const;
//----------------------------------------------------------------------------
/// @brief Setter for the Skia context to be used by subsequent
/// AndroidSurfaces.
/// @details This is useful to reduce memory consumption when creating
/// multiple AndroidSurfaces for the same AndroidContext.
///
/// The first AndroidSurface should set this for the
/// AndroidContext if the AndroidContext does not yet have a
/// Skia context to share via GetMainSkiaContext.
///
void SetMainSkiaContext(const sk_sp<GrDirectContext>& main_context);
//----------------------------------------------------------------------------
/// @brief Accessor for the Skia context associated with AndroidSurfaces
/// and the raster thread.
/// @details This context is created lazily by the AndroidSurface based
/// on their respective rendering backend and set on this
/// AndroidContext to share via SetMainSkiaContext.
/// @returns `nullptr` when no Skia context has been set yet by its
/// AndroidSurface via SetMainSkiaContext.
/// @attention The software context doesn't have a Skia context, so this
/// value will be nullptr.
///
sk_sp<GrDirectContext> GetMainSkiaContext() const;
private:
const AndroidRenderingAPI rendering_api_;
// This is the Skia context used for on-screen rendering.
sk_sp<GrDirectContext> main_context_;
FML_DISALLOW_COPY_AND_ASSIGN(AndroidContext);
};

View File

@@ -293,8 +293,7 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
if (!android_surface_) {
return nullptr;
}
return android_surface_->CreateGPUSurface(
android_context_->GetMainSkiaContext().get());
return android_surface_->CreateGPUSurface();
}
// |PlatformView|