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 38 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
02556ae
++
Jul 11, 2024
b3f6670
move all state updates to end of compositing.
Jul 11, 2024
b31aae6
working but unsynchronized.
Jul 11, 2024
75f931a
hey it almost works.
Jul 12, 2024
4525bd8
disable partial repaint.
Jul 12, 2024
6ce3aa0
cleanups.
Jul 12, 2024
be03cf8
set presentsWithTransaction.
Jul 12, 2024
6770376
sanity refactor.
Jul 12, 2024
912cd40
linting.
Jul 12, 2024
1f65cc3
skip post message if there are no platform views.
Jul 12, 2024
53adc81
linting.
Jul 12, 2024
870b950
dispose views in callback.
Jul 15, 2024
f8267bd
++
Jul 15, 2024
80565d5
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 16, 2024
2b9a825
tear down.
Jul 16, 2024
0a7dc5a
reserve.
Jul 17, 2024
2745e88
++
Jul 17, 2024
6002aa0
++
Jul 17, 2024
e7a832f
++
Jul 17, 2024
f099d74
come on big money no whammies.
Jul 17, 2024
e2e6a2a
okay one more.
Jul 17, 2024
44d5b5b
debug printf
Jul 17, 2024
b53063a
++
Jul 19, 2024
9a84539
make test work.
Jul 23, 2024
65a5210
++
Jul 23, 2024
735ce22
testing fixes.
Jul 24, 2024
a4f523b
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 24, 2024
b6c3345
merge in view slicer.
Jul 24, 2024
a4b771e
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 24, 2024
cd8e1de
++
Jul 25, 2024
6603d18
minor cleanups.
Jul 25, 2024
27c0daa
formatting.
Jul 25, 2024
d794211
add back clear
Jul 26, 2024
2f4314b
++
Jul 26, 2024
25a4e06
++
Jul 26, 2024
ea2e66d
merge threads on SIM.
Jul 26, 2024
d220885
++
Jul 26, 2024
9b534cd
Update shell/platform/darwin/ios/ios_external_view_embedder.mm
Jul 26, 2024
970e13a
++
Jul 26, 2024
63ebe66
Merge branch 'three_phase_render' of github.com:jonahwilliams/engine …
Jul 26, 2024
ff4802a
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 26, 2024
e3fc731
does it blend?
Jul 26, 2024
c0fab3b
++
Jul 26, 2024
d73671e
test fixes and clang tidy.
Jul 27, 2024
7285907
simplify and clean up thread access for UIViews.
Jul 27, 2024
bcd8519
reset before clearning composition order.
Jul 27, 2024
b25a742
Merge branch 'main' of github.com:flutter/engine into three_phase_render
Jul 30, 2024
5f6a8d4
switch to SurfaceFrame API.
Jul 30, 2024
be7853d
++
Jul 30, 2024
b19b4d8
Remove extra include.
Jul 30, 2024
ab08739
clang tidy
Jul 30, 2024
6e6e5a2
bracken feedback
Jul 30, 2024
355ab30
more bracken review.
Aug 1, 2024
8cd1c74
++
Aug 1, 2024
30e7b97
review comments and remove dead code.
Aug 1, 2024
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
7 changes: 7 additions & 0 deletions flow/surface_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class SurfaceFrame {
using SubmitCallback =
std::function<bool(SurfaceFrame& surface_frame, DlCanvas* canvas)>;

using DeferredSubmit = std::function<bool()>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chinmaygarde this is something I could use some help designing a better solution for.

Essentially what I need is to split SurfaceFrame submit into two methods, Flush and Submit (with the current Submit method being Flush+Submit). The flush would do everything up to presenting the drawable, while submit would actually do the presentation. That would allow us to finish the encoding work on the raster thread and then present from the platform thread as part of the CATransaction.

But this is complicated by all of the layers between SurfaceFrame and the impeller::Frame, and what to do about backends where a split Flush/Submit isn't feasible yet.

Copy link
Member

Choose a reason for hiding this comment

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

We can sketch this offline but SurfaceFrame may be EOL of its use. How about a SurfaceFrameBuilder that creates a view hierarchy state representation that you can submit elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Walk me through it :)

Or throw some time on my calendar

using SubmitReciever = std::function<void(DeferredSubmit)>;

// Information about the underlying framebuffer
struct FramebufferInfo {
// Indicates whether or not the surface supports pixel readback as used in
Expand Down Expand Up @@ -87,6 +90,10 @@ class SurfaceFrame {
//
// Defaults to true, which is generally a safe value.
bool frame_boundary = true;

bool present_with_transaction = false;
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is necessary for things to correctly work with FlutterMetalLayer disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FlutterMetalLayer is always presenting with a CATransaction, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it always makes the jump to platform thread (can't set CALayer content on background thread).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I ported this over from the existing logic, but once we remove the old metal layer usage we could remove this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


SubmitReciever submit_receiver;
};

bool Submit();
Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/backend/metal/surface_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class SurfaceMTL final : public Surface {
// Returns a Rect defining the area of the surface in device pixels
IRect coverage() const;

using DeferredSubmit = std::function<bool()>;
using SubmitReciever = std::function<void(DeferredSubmit)>;

void SetSubmitInfo(const SubmitReciever& submit_reciever) {
submit_reciever_ = submit_reciever;
}

// |Surface|
bool Present() const override;

Expand All @@ -75,6 +82,8 @@ class SurfaceMTL final : public Surface {
std::optional<IRect> clip_rect_;
bool frame_boundary_ = false;

SubmitReciever submit_reciever_;

static bool ShouldPerformPartialRepaint(std::optional<IRect> damage_rect);

SurfaceMTL(const std::weak_ptr<Context>& context,
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/metal/surface_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ - (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
[command_buffer waitUntilScheduled];
#endif // defined(FML_OS_IOS_SIMULATOR) && defined(FML_ARCH_CPU_X86_64)
[drawable_ present];
} else if (submit_reciever_) {
auto drawable = drawable_;
[command_buffer commit];
[command_buffer waitUntilScheduled];
submit_reciever_([drawable]() -> bool {
[drawable present];
return true;
});
} else {
// The drawable may come from a FlutterMetalLayer, so it can't be
// presented through the command buffer.
Expand Down
2 changes: 2 additions & 0 deletions shell/gpu/gpu_surface_metal_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class GPUSurfaceMetalDelegate {
///
virtual bool PresentDrawable(GrMTLHandle drawable) const = 0;

virtual bool PreparePresent(GrMTLHandle drawable) const { return true; }

//------------------------------------------------------------------------------
/// @brief Returns the handle to the MTLTexture to render to. This is only
/// called when the specified render target type is `kMTLTexture`.
Expand Down
15 changes: 14 additions & 1 deletion shell/gpu/gpu_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,18 @@
renderer = impeller_renderer_, //
aiks_context = aiks_context_, //
drawable, //
last_texture //
last_texture, //
mtl_layer //
](SurfaceFrame& surface_frame, DlCanvas* canvas) mutable -> bool {
// When there are platform views in the scene, the drawable needs to be presented in the
// same transaction as the one created for platform views. When the drawable are being
// presented from the raster thread, we may not be able to use a transaction as it will
// dirty the UIViews being presented. If there is a non-Flutter UIView active, such as in
// add2app or a presentViewController page transition, then this will cause CoreAnimation
// assertion errors and
// exit the app.
mtl_layer.presentsWithTransaction = surface_frame.submit_info().present_with_transaction;

if (!aiks_context) {
return false;
}
Expand Down Expand Up @@ -159,6 +169,7 @@
if (!surface) {
return false;
}
surface->SetSubmitInfo(surface_frame.submit_info().submit_receiver);

if (clip_rect && clip_rect->IsEmpty()) {
return surface->Present();
Expand Down Expand Up @@ -286,6 +297,8 @@
auto surface =
impeller::SurfaceMTL::MakeFromTexture(renderer->GetContext(), mtl_texture, clip_rect);

surface->SetSubmitInfo(surface_frame.submit_info().submit_receiver);

if (clip_rect && clip_rect->IsEmpty()) {
return surface->Present();
}
Expand Down
16 changes: 13 additions & 3 deletions shell/gpu/gpu_surface_metal_skia.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@
return nullptr;
}

auto submit_callback = [this, drawable](const SurfaceFrame& surface_frame,
DlCanvas* canvas) -> bool {
auto submit_callback = [this, drawable, mtl_layer](const SurfaceFrame& surface_frame,
DlCanvas* canvas) -> bool {
mtl_layer.presentsWithTransaction = surface_frame.submit_info().present_with_transaction;

TRACE_EVENT0("flutter", "GPUSurfaceMetal::Submit");
if (canvas == nullptr) {
FML_DLOG(ERROR) << "Canvas not available.";
Expand All @@ -179,7 +181,15 @@
damage_[texture] = SkIRect::MakeEmpty();
}

return delegate_->PresentDrawable(drawable);
if (surface_frame.submit_info().submit_receiver) {
delegate_->PreparePresent(drawable);
surface_frame.submit_info().submit_receiver(
[&, drawable = drawable]() { return delegate_->PresentDrawable(drawable); });
return true;
} else {
delegate_->PreparePresent(drawable);
return delegate_->PresentDrawable(drawable);
}
};

SurfaceFrame::FramebufferInfo framebuffer_info;
Expand Down
5 changes: 4 additions & 1 deletion shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ - (instancetype)initWithName:(NSString*)labelPrefix
_pluginPublications = [[NSMutableDictionary alloc] init];
_registrars = [[NSMutableDictionary alloc] init];
[self recreatePlatformViewController];

_binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
_textureRegistry = [[FlutterTextureRegistryRelay alloc] initWithParent:self];
_connections.reset(new flutter::ConnectionCollection());
Expand Down Expand Up @@ -869,6 +868,8 @@ - (BOOL)createShell:(NSString*)entrypoint
flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
[self](flutter::Shell& shell) {
[self recreatePlatformViewController];
self->_platformViewsController->SetTaskRunner(
shell.GetTaskRunners().GetPlatformTaskRunner());
return std::make_unique<flutter::PlatformViewIOS>(
shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners(),
shell.GetConcurrentWorkerTaskRunner(), shell.GetIsGpuDisabledSyncSwitch());
Expand Down Expand Up @@ -1468,6 +1469,8 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint
flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
[result, context](flutter::Shell& shell) {
[result recreatePlatformViewController];
result->_platformViewsController->SetTaskRunner(
shell.GetTaskRunners().GetPlatformTaskRunner());
return std::make_unique<flutter::PlatformViewIOS>(
shell, context, result->_platformViewsController, shell.GetTaskRunners());
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
FLUTTER_ASSERT_ARC

// This is mostly a duplication of FlutterView.
// TODO(amirh): once GL support is in evaluate if we can merge this with FlutterView.
@implementation FlutterOverlayView {
fml::CFRef<CGColorSpaceRef> _colorSpaceRef;
}
Expand Down
Loading