Skip to content

Commit 27281c4

Browse files
Do not share the GrDirectContext across engine instances on Android (flutter#28694)
1 parent 8872b44 commit 27281c4

File tree

4 files changed

+4
-59
lines changed

4 files changed

+4
-59
lines changed

shell/platform/android/android_surface_gl.cc

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ std::unique_ptr<Surface> AndroidSurfaceGL::CreateGPUSurface(
5252
if (gr_context) {
5353
return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true);
5454
} else {
55-
sk_sp<GrDirectContext> main_skia_context =
56-
GLContextPtr()->GetMainSkiaContext();
57-
if (!main_skia_context) {
58-
main_skia_context = GPUSurfaceGL::MakeGLContext(this);
59-
GLContextPtr()->SetMainSkiaContext(main_skia_context);
60-
}
61-
return std::make_unique<GPUSurfaceGL>(main_skia_context, this, true);
55+
return std::make_unique<GPUSurfaceGL>(this, true);
6256
}
6357
}
6458

@@ -177,14 +171,7 @@ AndroidContextGL* AndroidSurfaceGL::GLContextPtr() const {
177171

178172
std::unique_ptr<Surface> AndroidSurfaceGL::CreatePbufferSurface() {
179173
onscreen_surface_ = GLContextPtr()->CreatePbufferSurface();
180-
sk_sp<GrDirectContext> main_skia_context =
181-
GLContextPtr()->GetMainSkiaContext();
182-
if (!main_skia_context) {
183-
main_skia_context = GPUSurfaceGL::MakeGLContext(this);
184-
GLContextPtr()->SetMainSkiaContext(main_skia_context);
185-
}
186-
187-
return std::make_unique<GPUSurfaceGL>(main_skia_context, this, true);
174+
return std::make_unique<GPUSurfaceGL>(this, true);
188175
}
189176

190177
} // namespace flutter

shell/platform/android/context/android_context.cc

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ namespace flutter {
99
AndroidContext::AndroidContext(AndroidRenderingAPI rendering_api)
1010
: rendering_api_(rendering_api) {}
1111

12-
AndroidContext::~AndroidContext() {
13-
if (main_context_) {
14-
main_context_->releaseResourcesAndAbandonContext();
15-
}
16-
};
12+
AndroidContext::~AndroidContext() = default;
1713

1814
AndroidRenderingAPI AndroidContext::RenderingApi() const {
1915
return rendering_api_;
@@ -23,13 +19,4 @@ bool AndroidContext::IsValid() const {
2319
return true;
2420
}
2521

26-
void AndroidContext::SetMainSkiaContext(
27-
const sk_sp<GrDirectContext>& main_context) {
28-
main_context_ = main_context;
29-
}
30-
31-
sk_sp<GrDirectContext> AndroidContext::GetMainSkiaContext() const {
32-
return main_context_;
33-
}
34-
3522
} // namespace flutter

shell/platform/android/context/android_context.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,9 @@ class AndroidContext {
2828

2929
virtual bool IsValid() const;
3030

31-
//----------------------------------------------------------------------------
32-
/// @brief Setter for the Skia context to be used by subsequent
33-
/// AndroidSurfaces.
34-
/// @details This is useful to reduce memory consumption when creating
35-
/// multiple AndroidSurfaces for the same AndroidContext.
36-
///
37-
/// The first AndroidSurface should set this for the
38-
/// AndroidContext if the AndroidContext does not yet have a
39-
/// Skia context to share via GetMainSkiaContext.
40-
///
41-
void SetMainSkiaContext(const sk_sp<GrDirectContext>& main_context);
42-
43-
//----------------------------------------------------------------------------
44-
/// @brief Accessor for the Skia context associated with AndroidSurfaces
45-
/// and the raster thread.
46-
/// @details This context is created lazily by the AndroidSurface based
47-
/// on their respective rendering backend and set on this
48-
/// AndroidContext to share via SetMainSkiaContext.
49-
/// @returns `nullptr` when no Skia context has been set yet by its
50-
/// AndroidSurface via SetMainSkiaContext.
51-
/// @attention The software context doesn't have a Skia context, so this
52-
/// value will be nullptr.
53-
///
54-
sk_sp<GrDirectContext> GetMainSkiaContext() const;
55-
5631
private:
5732
const AndroidRenderingAPI rendering_api_;
5833

59-
// This is the Skia context used for on-screen rendering.
60-
sk_sp<GrDirectContext> main_context_;
61-
6234
FML_DISALLOW_COPY_AND_ASSIGN(AndroidContext);
6335
};
6436

shell/platform/android/platform_view_android.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
293293
if (!android_surface_) {
294294
return nullptr;
295295
}
296-
return android_surface_->CreateGPUSurface(
297-
android_context_->GetMainSkiaContext().get());
296+
return android_surface_->CreateGPUSurface();
298297
}
299298

300299
// |PlatformView|

0 commit comments

Comments
 (0)