Started asserting that metal gpu contexts are shared (flutter/engine#23539)

Started asserting that metal gpu contexts are shared, added ability
for IOSContexts to store their skia contexts so we can make the OpenGL
code work like the Metal code.
This commit is contained in:
gaaclarke 2021-01-11 16:39:37 -08:00 committed by GitHub
parent 1121d94ae5
commit 0df5eaaa89
7 changed files with 48 additions and 3 deletions

View File

@ -30,8 +30,17 @@ FLUTTER_ASSERT_NOT_ARC
XCTAssertNotNil(spawn);
XCTAssertTrue([engine iosPlatformView] != nullptr);
XCTAssertTrue([spawn iosPlatformView] != nullptr);
XCTAssertEqual([engine iosPlatformView]->GetIosContext(),
[spawn iosPlatformView]->GetIosContext());
std::shared_ptr<flutter::IOSContext> engine_context = [engine iosPlatformView]->GetIosContext();
std::shared_ptr<flutter::IOSContext> spawn_context = [spawn iosPlatformView]->GetIosContext();
XCTAssertEqual(engine_context, spawn_context);
// If this assert fails it means we may be using the software or OpenGL
// renderer when we were expecting Metal. For software rendering, this is
// expected to be nullptr. For OpenGL, implementing this is an outstanding
// change see https://github.com/flutter/flutter/issues/73744.
XCTAssertTrue(engine_context->GetMainContext() != nullptr);
XCTAssertEqual(engine_context->GetMainContext(), spawn_context->GetMainContext());
[engine release];
[spawn release];
}
@end

View File

@ -106,6 +106,20 @@ class IOSContext {
int64_t texture_id,
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) = 0;
//----------------------------------------------------------------------------
/// @brief Accessor for the Skia context associated with IOSSurfaces and
/// the raster thread.
/// @details There can be any number of resource contexts but this is the
/// one context that will be used by surfaces to draw to the
/// screen from the raster thread.
/// @returns `nullptr` on failure.
/// @attention The software context doesn't have a Skia context, so this
/// value will be nullptr.
/// @see For contexts which are used for offscreen work like loading
/// textures see IOSContext::CreateResourceContext.
///
virtual sk_sp<GrDirectContext> GetMainContext() const = 0;
protected:
IOSContext();

View File

@ -32,6 +32,9 @@ class IOSContextGL final : public IOSContext {
// |IOSContext|
sk_sp<GrDirectContext> CreateResourceContext() override;
// |IOSContext|
sk_sp<GrDirectContext> GetMainContext() const override;
// |IOSContext|
std::unique_ptr<GLContextResult> MakeCurrent() override;

View File

@ -43,6 +43,16 @@ sk_sp<GrDirectContext> IOSContextGL::CreateResourceContext() {
GrBackend::kOpenGL_GrBackend, GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface());
}
// |IOSContext|
sk_sp<GrDirectContext> IOSContextGL::GetMainContext() const {
/// TODO(73744): Currently the GPUSurfaceGL creates the main context for
/// OpenGL. With Metal the IOSContextMetal creates the main context and is
/// shared across surfaces. We should refactor the OpenGL Context/Surfaces to
/// behave like the Metal equivalents. Until then engines in the same group
/// will have a heavier memory cost if they are using OpenGL.
return nullptr;
}
// |IOSContext|
std::unique_ptr<GLContextResult> IOSContextGL::MakeCurrent() {
return std::make_unique<GLContextSwitch>(

View File

@ -24,7 +24,8 @@ class IOSContextMetal final : public IOSContext {
fml::scoped_nsobject<FlutterDarwinContextMetal> GetDarwinContext() const;
sk_sp<GrDirectContext> GetMainContext() const;
// |IOSContext|
sk_sp<GrDirectContext> GetMainContext() const override;
sk_sp<GrDirectContext> GetResourceContext() const;

View File

@ -20,6 +20,9 @@ class IOSContextSoftware final : public IOSContext {
// |IOSContext|
sk_sp<GrDirectContext> CreateResourceContext() override;
// |IOSContext|
sk_sp<GrDirectContext> GetMainContext() const override;
// |IOSContext|
std::unique_ptr<GLContextResult> MakeCurrent() override;

View File

@ -16,6 +16,11 @@ sk_sp<GrDirectContext> IOSContextSoftware::CreateResourceContext() {
return nullptr;
}
// |IOSContext|
sk_sp<GrDirectContext> IOSContextSoftware::GetMainContext() const {
return nullptr;
}
// |IOSContext|
std::unique_ptr<GLContextResult> IOSContextSoftware::MakeCurrent() {
// This only makes sense for context that need to be bound to a specific thread.