started providing the GPU sync switch to external view embedders (flutter/engine#22302)

This commit is contained in:
gaaclarke
2020-11-17 18:43:01 -08:00
committed by GitHub
parent 88eae0a43d
commit 0901a93e5b
19 changed files with 89 additions and 40 deletions

View File

@@ -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();
};

View File

@@ -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"
@@ -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`

View File

@@ -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();
}

View File

@@ -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));

View File

@@ -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(),

View File

@@ -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(

View File

@@ -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()) {

View File

@@ -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(

View File

@@ -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.
@@ -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.
@@ -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.
@@ -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);
@@ -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);

View File

@@ -462,9 +462,22 @@ SkRect FlutterPlatformViewsController::GetPlatformViewRect(int view_id) {
);
}
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([&] {
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) {

View File

@@ -800,8 +800,10 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
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);
@@ -810,8 +812,10 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
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();
}

View File

@@ -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
@@ -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);
};

View File

@@ -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(

View File

@@ -72,11 +72,14 @@ SkCanvas* IOSExternalViewEmbedder::CompositeEmbeddedView(int view_id) {
}
// |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");
}

View File

@@ -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_);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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(); }

View File

@@ -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;
}