Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ - (void)testSpawnsShareGpuContext {
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
14 changes: 14 additions & 0 deletions shell/platform/darwin/ios/ios_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/ios_context_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions shell/platform/darwin/ios/ios_context_gl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
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>(
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/darwin/ios/ios_context_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class IOSContextMetal final : public IOSContext {

fml::scoped_nsobject<FlutterDarwinContextMetal> GetDarwinContext() const;

sk_sp<GrDirectContext> GetMainContext() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is that there's 2, a main rendering context on the raster thread and a resource secondary context on the io thread? If so, be fully descriptive in the doc so someone new can understand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated docstring in ios_context, added link to it.

// |IOSContext|
sk_sp<GrDirectContext> GetMainContext() const override;

sk_sp<GrDirectContext> GetResourceContext() const;

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/darwin/ios/ios_context_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions shell/platform/darwin/ios/ios_context_software.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
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.
Expand Down