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 @@ -46,7 +46,7 @@ class FlutterCompositor {
// Present sets frame_started_ to false.
virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0;

using PresentCallback = std::function<bool()>;
using PresentCallback = std::function<bool(bool has_flutter_content)>;

// PresentCallback is called at the end of the Present function.
void SetPresentCallback(const PresentCallback& present_callback);
Expand All @@ -73,7 +73,7 @@ class FlutterCompositor {

// Calls the present callback and ensures the frame status is updated
// to frame ended, returning whether the present was successful or not.
bool EndFrame();
bool EndFrame(bool has_flutter_content);

// Creates a CALayer object which is backed by the supplied IOSurface, and
// adds it to the root CALayer for this FlutterViewController's view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
SetFrameStatus(FrameStatus::kStarted);
}

bool FlutterCompositor::EndFrame() {
bool status = present_callback_();
bool FlutterCompositor::EndFrame(bool has_flutter_content) {
bool status = present_callback_(has_flutter_content);
SetFrameStatus(FrameStatus::kEnded);
return status;
}
Expand Down
24 changes: 16 additions & 8 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,29 @@ - (FlutterCompositor*)createFlutterCompositor {
FlutterMetalRenderer* metalRenderer = reinterpret_cast<FlutterMetalRenderer*>(_renderer);
_macOSCompositor =
std::make_unique<flutter::FlutterMetalCompositor>(_viewController, metalRenderer.device);
_macOSCompositor->SetPresentCallback([weakSelf]() {
FlutterMetalRenderer* metalRenderer =
reinterpret_cast<FlutterMetalRenderer*>(weakSelf.renderer);
return [metalRenderer present:0 /*=textureID*/];
_macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) {
if (has_flutter_content) {
FlutterMetalRenderer* metalRenderer =
reinterpret_cast<FlutterMetalRenderer*>(weakSelf.renderer);
return [metalRenderer present:0 /*=textureID*/] == YES;
} else {
return true;
}
});
} else {
FlutterOpenGLRenderer* openGLRenderer = reinterpret_cast<FlutterOpenGLRenderer*>(_renderer);
[openGLRenderer.openGLContext makeCurrentContext];
_macOSCompositor = std::make_unique<flutter::FlutterGLCompositor>(_viewController,
openGLRenderer.openGLContext);

_macOSCompositor->SetPresentCallback([weakSelf]() {
FlutterOpenGLRenderer* openGLRenderer =
reinterpret_cast<FlutterOpenGLRenderer*>(weakSelf.renderer);
return [openGLRenderer glPresent];
_macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) {
if (has_flutter_content) {
FlutterOpenGLRenderer* openGLRenderer =
reinterpret_cast<FlutterOpenGLRenderer*>(weakSelf.renderer);
return [openGLRenderer glPresent] == YES;
} else {
return true;
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ @interface FlutterEngine (Test)
// Latch to ensure the entire layer tree has been generated and presented.
fml::AutoResetWaitableEvent latch;
auto compositor = engine.macOSCompositor;
compositor->SetPresentCallback([&]() {
compositor->SetPresentCallback([&](bool has_flutter_content) {
latch.Signal();
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
bool FlutterGLCompositor::Present(const FlutterLayer** layers, size_t layers_count) {
SetFrameStatus(FrameStatus::kPresenting);

bool has_flutter_content = false;

for (size_t i = 0; i < layers_count; ++i) {
const auto* layer = layers[i];
FlutterBackingStore* backing_store = const_cast<FlutterBackingStore*>(layer->backing_store);
Expand All @@ -93,6 +95,7 @@
// and needs to be flipped vertically
InsertCALayerForIOSurface(io_surface, CATransform3DMakeScale(1, -1, 1));
}
has_flutter_content = true;
break;
}
case kFlutterLayerContentTypePlatformView:
Expand All @@ -102,7 +105,7 @@
};
}

return EndFrame();
return EndFrame(has_flutter_content);
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
std::make_unique<FlutterGLCompositor>(mockViewController, nullptr);

bool flag = false;
macos_compositor->SetPresentCallback([f = &flag]() {
macos_compositor->SetPresentCallback([f = &flag](bool has_flutter_content) {
*f = true;
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
bool FlutterMetalCompositor::Present(const FlutterLayer** layers, size_t layers_count) {
SetFrameStatus(FrameStatus::kPresenting);

bool has_flutter_content = false;

for (size_t i = 0; i < layers_count; ++i) {
const auto* layer = layers[i];
FlutterBackingStore* backing_store = const_cast<FlutterBackingStore*>(layer->backing_store);
Expand All @@ -88,6 +90,7 @@
IOSurfaceRef io_surface = [io_surface_holder ioSurface];
InsertCALayerForIOSurface(io_surface);
}
has_flutter_content = true;
break;
}
case kFlutterLayerContentTypePlatformView:
Expand All @@ -97,7 +100,7 @@
};
}

return EndFrame();
return EndFrame(has_flutter_content);
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
std::make_unique<FlutterMetalCompositor>(mockViewController, nullptr);

bool flag = false;
macos_compositor->SetPresentCallback([f = &flag]() {
macos_compositor->SetPresentCallback([f = &flag](bool has_flutter_content) {
*f = true;
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ - (instancetype)init {
FlutterMetalSurfaceManager* surfaceManager = CreateSurfaceManager();
CGSize size = CGSizeMake(100, 50);
[surfaceManager ensureSurfaceSize:size];
[surfaceManager renderBuffer]; // make sure we have back buffer
[surfaceManager swapBuffers];
id<MTLTexture> texture =
(reinterpret_cast<FlutterMetalRenderBackingStore*>([surfaceManager renderBuffer])).texture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ - (void)ensureSurfaceSize:(CGSize)size {
}

- (void)swapBuffers {
#ifndef NDEBUG
// swapBuffers should not be called unless a frame was drawn
@synchronized(self) {
assert(_frameInProgress);
}
#endif

_contentLayer.frame = _containingLayer.bounds;
_contentLayer.transform = _contentTransform;
IOSurfaceRef contentIOSurface = [_ioSurfaces[kFlutterSurfaceManagerBackBuffer] ioSurface];
Expand Down