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 4 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
3 changes: 2 additions & 1 deletion flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void ExternalViewEmbedder::SubmitFlutterView(
int64_t flutter_view_id,
GrDirectContext* context,
const std::shared_ptr<impeller::AiksContext>& aiks_context,
std::unique_ptr<SurfaceFrame> frame) {
std::unique_ptr<SurfaceFrame> frame,
fml::RefPtr<fml::TaskRunner> platform_task_runner) {
frame->Submit();
}

Expand Down
4 changes: 3 additions & 1 deletion flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "flutter/flow/surface_frame.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/raster_thread_merger.h"
#include "fml/task_runner.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRRect.h"
Expand Down Expand Up @@ -459,7 +460,8 @@ class ExternalViewEmbedder {
int64_t flutter_view_id,
GrDirectContext* context,
const std::shared_ptr<impeller::AiksContext>& aiks_context,
std::unique_ptr<SurfaceFrame> frame);
std::unique_ptr<SurfaceFrame> frame,
fml::RefPtr<fml::TaskRunner> platform_task_runner);

// This method provides the embedder a way to do additional tasks after
// |SubmitFrame|. For example, merge task runners if `should_resubmit_frame`
Expand Down
6 changes: 6 additions & 0 deletions flow/surface_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/time/time_point.h"

#include "fml/synchronization/count_down_latch.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"

Expand All @@ -26,6 +27,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 +91,8 @@ class SurfaceFrame {
//
// Defaults to true, which is generally a safe value.
bool frame_boundary = true;

SubmitReciever submit_receiver;
};

bool Submit();
Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/metal/surface_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QuartzCore/CAMetalLayer.h>
#include <memory>

#include "fml/synchronization/count_down_latch.h"
#include "impeller/geometry/rect.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/surface.h"
Expand Down Expand Up @@ -58,6 +59,14 @@ 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 @@ -70,6 +79,8 @@ class SurfaceMTL final : public Surface {
bool requires_blit_ = false;
std::optional<IRect> clip_rect_;

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 @@ -294,6 +294,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
5 changes: 2 additions & 3 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,11 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe(

frame->set_submit_info(submit_info);

if (external_view_embedder_ &&
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
if (external_view_embedder_) {
FML_DCHECK(!frame->IsSubmitted());
external_view_embedder_->SubmitFlutterView(
view_id, surface_->GetContext(), surface_->GetAiksContext(),
std::move(frame));
std::move(frame), delegate_.GetTaskRunners().GetPlatformTaskRunner());
} else {
frame->Submit();
}
Expand Down
3 changes: 3 additions & 0 deletions shell/gpu/gpu_surface_metal_impeller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,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 @@ -277,6 +278,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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "flutter/shell/platform/android/external_view_embedder/surface_pool.h"
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
#include "flutter/shell/platform/android/surface/android_surface.h"
#include "fml/memory/ref_ptr.h"

namespace flutter {

Expand Down Expand Up @@ -47,7 +48,8 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
int64_t flutter_view_id,
GrDirectContext* context,
const std::shared_ptr<impeller::AiksContext>& aiks_context,
std::unique_ptr<SurfaceFrame> frame) override;
std::unique_ptr<SurfaceFrame> frame,
fml::RefPtr<fml::TaskRunner> platform_task_runner) override;

// |ExternalViewEmbedder|
PostPrerollResult PostPrerollAction(
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