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
6 changes: 4 additions & 2 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace flutter {

void ExternalViewEmbedder::SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
void ExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
frame->Submit();
};

Expand Down
7 changes: 5 additions & 2 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/flow/surface_frame.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/raster_thread_merger.h"
#include "flutter/fml/synchronization/sync_switch.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
Expand Down Expand Up @@ -309,8 +310,10 @@ class ExternalViewEmbedder {
// This method can mutate the root Skia canvas before submitting the frame.
//
// It can also allocate frames for overlay surfaces to compose hybrid views.
virtual void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame);
virtual void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch);

// This method provides the embedder a way to do additional tasks after
// |SubmitFrame|. For example, merge task runners if `should_resubmit_frame`
Expand Down
5 changes: 3 additions & 2 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,9 @@ RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) {
if (external_view_embedder_ &&
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
FML_DCHECK(!frame->IsSubmitted());
external_view_embedder_->SubmitFrame(surface_->GetContext(),
std::move(frame));
external_view_embedder_->SubmitFrame(
surface_->GetContext(), std::move(frame),
delegate_.GetIsGpuDisabledSyncSwitch());
} else {
frame->Submit();
}
Expand Down
8 changes: 5 additions & 3 deletions shell/common/rasterizer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class MockExternalViewEmbedder : public ExternalViewEmbedder {
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger));
MOCK_METHOD0(GetCurrentCanvases, std::vector<SkCanvas*>());
MOCK_METHOD1(CompositeEmbeddedView, SkCanvas*(int view_id));
MOCK_METHOD2(SubmitFrame,
void(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame));
MOCK_METHOD3(
SubmitFrame,
void(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch));
MOCK_METHOD2(EndFrame,
void(bool should_resubmit_frame,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger));
Expand Down
3 changes: 2 additions & 1 deletion shell/common/shell_test_external_view_embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ SkCanvas* ShellTestExternalViewEmbedder::CompositeEmbeddedView(int view_id) {
// |ExternalViewEmbedder|
void ShellTestExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
frame->Submit();
if (frame && frame->SkiaSurface()) {
last_submitted_frame_size_ = SkISize::Make(frame->SkiaSurface()->width(),
Expand Down
6 changes: 4 additions & 2 deletions shell/common/shell_test_external_view_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class ShellTestExternalViewEmbedder final : public ExternalViewEmbedder {
SkCanvas* CompositeEmbeddedView(int view_id) override;

// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) override;
void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) override;

// |ExternalViewEmbedder|
void EndFrame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ SkRect AndroidExternalViewEmbedder::GetViewRect(int view_id) const {
// |ExternalViewEmbedder|
void AndroidExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
TRACE_EVENT0("flutter", "AndroidExternalViewEmbedder::SubmitFrame");

if (!FrameHasPlatformLayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
std::vector<SkCanvas*> GetCurrentCanvases() override;

// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) override;
void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) override;

// |ExternalViewEmbedder|
PostPrerollResult PostPrerollAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
return true;
});

embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame), nullptr);
// Submits frame if no Android view in the current frame.
EXPECT_TRUE(did_submit_frame);
// Doesn't resubmit frame.
Expand Down Expand Up @@ -398,7 +398,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
return true;
});

embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame), nullptr);
// Doesn't submit frame if there aren't Android views in the previous frame.
EXPECT_FALSE(did_submit_frame);
// Resubmits frame.
Expand Down Expand Up @@ -462,7 +462,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
}
return true;
});
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame), nullptr);
// Submits frame if there are Android views in the previous frame.
EXPECT_TRUE(did_submit_frame);
// Doesn't resubmit frame.
Expand Down Expand Up @@ -560,7 +560,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
std::make_unique<SurfaceFrame>(SkSurface::MakeNull(1000, 1000), false,
[](const SurfaceFrame& surface_frame,
SkCanvas* canvas) { return true; });
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame), nullptr);

EXPECT_CALL(*jni_mock, FlutterViewEndFrame());
embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger);
Expand Down Expand Up @@ -640,7 +640,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
std::make_unique<SurfaceFrame>(SkSurface::MakeNull(1000, 1000), false,
[](const SurfaceFrame& surface_frame,
SkCanvas* canvas) { return true; });
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame), nullptr);

EXPECT_CALL(*jni_mock, FlutterViewEndFrame());
embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger);
Expand Down
19 changes: 16 additions & 3 deletions shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,22 @@
);
}

bool FlutterPlatformViewsController::SubmitFrame(GrDirectContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame) {
bool FlutterPlatformViewsController::SubmitFrame(
GrDirectContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
bool result = false;
gpu_disable_sync_switch->Execute(
fml::SyncSwitch::Handlers().SetIfTrue([&] { result = false; }).SetIfFalse([&] {
Copy link
Member

Choose a reason for hiding this comment

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

Is the SetIfTrue handler necessary? result is already set to false by default

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, it shouldn't be necessary. Once I get things sorted out I'll try removing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, shoot I forgot to do this before it landed. I was in a rush. It's probably not a big deal, if you want it gone I can do it in a separate PR. Sorry.

result = SubmitFrameGpuSafe(gr_context, ios_context, std::move(frame));
}));
return result;
}

bool FlutterPlatformViewsController::SubmitFrameGpuSafe(GrDirectContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame) {
// Any UIKit related code has to run on main thread.
FML_DCHECK([[NSThread currentThread] isMainThread]);
if (flutter_view_ == nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,10 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
nullptr, true,
[](const flutter::SurfaceFrame& surface_frame, SkCanvas* canvas) { return false; });
XCTAssertFalse(
flutterPlatformViewsController->SubmitFrame(nullptr, nullptr, std::move(mock_surface)));
auto is_gpu_disabled = std::make_shared<fml::SyncSwitch>();
is_gpu_disabled->SetSwitch(false);
XCTAssertFalse(flutterPlatformViewsController->SubmitFrame(
nullptr, nullptr, std::move(mock_surface), is_gpu_disabled));

auto embeddedViewParams_2 =
std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
Expand All @@ -810,8 +812,10 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin
auto mock_surface_submit_false = std::make_unique<flutter::SurfaceFrame>(
nullptr, true,
[](const flutter::SurfaceFrame& surface_frame, SkCanvas* canvas) { return true; });
XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(nullptr, nullptr,
std::move(mock_surface_submit_false)));
auto gpu_is_disabled = std::make_shared<fml::SyncSwitch>();
gpu_is_disabled->SetSwitch(false);
XCTAssertTrue(flutterPlatformViewsController->SubmitFrame(
nullptr, nullptr, std::move(mock_surface_submit_false), gpu_is_disabled));

flutterPlatformViewsController->Reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class FlutterPlatformViewsController {

bool SubmitFrame(GrDirectContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame);
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch);

// Invoked at the very end of a frame.
// After invoking this method, nothing should happen on the current TaskRunner during the same
Expand Down Expand Up @@ -304,6 +305,10 @@ class FlutterPlatformViewsController {
// Commit a CATransaction if |BeginCATransaction| has been called during the frame.
void CommitCATransactionIfNeeded();

bool SubmitFrameGpuSafe(GrDirectContext* gr_context,
std::shared_ptr<IOSContext> ios_context,
std::unique_ptr<SurfaceFrame> frame);

FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController);
};

Expand Down
6 changes: 4 additions & 2 deletions shell/platform/darwin/ios/ios_external_view_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder {
SkCanvas* CompositeEmbeddedView(int view_id) override;

// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) override;
void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) override;

// |ExternalViewEmbedder|
void EndFrame(
Expand Down
9 changes: 6 additions & 3 deletions shell/platform/darwin/ios/ios_external_view_embedder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@
}

// |ExternalViewEmbedder|
void IOSExternalViewEmbedder::SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
void IOSExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::SubmitFrame");
FML_CHECK(platform_views_controller_);
platform_views_controller_->SubmitFrame(std::move(context), ios_context_, std::move(frame));
platform_views_controller_->SubmitFrame(std::move(context), ios_context_, std::move(frame),
gpu_disable_sync_switch);
TRACE_EVENT0("flutter", "IOSExternalViewEmbedder::DidSubmitFrame");
}

Expand Down
3 changes: 2 additions & 1 deletion shell/platform/embedder/embedder_external_view_embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static FlutterBackingStoreConfig MakeBackingStoreConfig(
// |ExternalViewEmbedder|
void EmbedderExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
auto [matched_render_targets, pending_keys] =
render_target_cache_.GetExistingTargetsInCache(pending_views_);

Expand Down
6 changes: 4 additions & 2 deletions shell/platform/embedder/embedder_external_view_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder {
SkCanvas* CompositeEmbeddedView(int view_id) override;

// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) override;
void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) override;

// |ExternalViewEmbedder|
SkCanvas* GetRootCanvas() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void FuchsiaExternalViewEmbedder::EndFrame(

void FuchsiaExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
std::unique_ptr<flutter::SurfaceFrame> frame) {
std::unique_ptr<flutter::SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) {
TRACE_EVENT0("flutter", "FuchsiaExternalViewEmbedder::SubmitFrame");
std::vector<std::unique_ptr<SurfaceProducerSurface>> frame_surfaces;
std::unordered_map<EmbedderLayerId, size_t> frame_surface_indices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ class FuchsiaExternalViewEmbedder final : public flutter::ExternalViewEmbedder {
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override;

// |ExternalViewEmbedder|
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<flutter::SurfaceFrame> frame) override;
void SubmitFrame(
GrDirectContext* context,
std::unique_ptr<flutter::SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>& gpu_disable_sync_switch) override;

// |ExternalViewEmbedder|
void CancelFrame() override { Reset(); }
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/platform_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder {
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override {}
void SubmitFrame(GrDirectContext* context,
std::unique_ptr<flutter::SurfaceFrame> frame) override {
std::unique_ptr<flutter::SurfaceFrame> frame,
const std::shared_ptr<fml::SyncSwitch>&
gpu_disable_sync_switch) override {
return;
}

Expand Down