add flag to identify sub-trees with PlatformViewLayers and always paint them (flutter/engine#25824)

This commit is contained in:
Jim Graham
2021-04-29 20:50:59 -07:00
committed by GitHub
parent 0920288265
commit 6de972e85e
8 changed files with 169 additions and 1 deletions

View File

@@ -112,6 +112,8 @@ if (enable_unittests) {
"testing/gl_context_switch_test.cc",
"testing/gl_context_switch_test.h",
"testing/layer_test.h",
"testing/mock_embedder.cc",
"testing/mock_embedder.h",
"testing/mock_layer.cc",
"testing/mock_layer.h",
"testing/mock_raster_cache.cc",

View File

@@ -161,6 +161,7 @@ void ContainerLayer::PrerollChildren(PrerollContext* context,
context->has_platform_view = child_has_platform_view;
context->has_texture_layer = child_has_texture_layer;
set_subtree_has_platform_view(child_has_platform_view);
#if defined(LEGACY_FUCHSIA_EMBEDDER)
if (child_layer_exists_below_) {

View File

@@ -13,7 +13,8 @@ Layer::Layer()
: paint_bounds_(SkRect::MakeEmpty()),
unique_id_(NextUniqueID()),
original_layer_id_(unique_id_),
needs_system_composite_(false) {}
needs_system_composite_(false),
subtree_has_platform_view_(false) {}
Layer::~Layer() = default;

View File

@@ -202,6 +202,11 @@ class Layer {
needs_system_composite_ = value;
}
bool subtree_has_platform_view() const { return subtree_has_platform_view_; }
void set_subtree_has_platform_view(bool value) {
subtree_has_platform_view_ = value;
}
// Returns the paint bounds in the layer's local coordinate system
// as determined during Preroll(). The bounds should include any
// transform, clip or distortions performed by the layer itself,
@@ -229,6 +234,16 @@ class Layer {
// Determines if the Paint() method is necessary based on the properties
// of the indicated PaintContext object.
bool needs_painting(PaintContext& context) const {
if (subtree_has_platform_view_) {
// Workaround for the iOS embedder. The iOS embedder expects that
// if we preroll it, then we will later call its Paint() method.
// Now that we preroll all layers without any culling, we may
// call its Preroll() without calling its Paint(). For now, we
// will not perform paint culling on any subtree that has a
// platform view.
// See https://github.com/flutter/flutter/issues/81419
return true;
}
// Workaround for Skia bug (quickReject does not reject empty bounds).
// https://bugs.chromium.org/p/skia/issues/detail?id=10951
if (paint_bounds_.isEmpty()) {
@@ -264,6 +279,7 @@ class Layer {
uint64_t unique_id_;
uint64_t original_layer_id_;
bool needs_system_composite_;
bool subtree_has_platform_view_;
static uint64_t NextUniqueID();

View File

@@ -27,6 +27,7 @@ void PlatformViewLayer::Preroll(PrerollContext* context,
return;
}
context->has_platform_view = true;
set_subtree_has_platform_view(true);
std::unique_ptr<EmbeddedViewParams> params =
std::make_unique<EmbeddedViewParams>(matrix, size_,
context->mutators_stack);

View File

@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/layers/clip_rect_layer.h"
#include "flutter/flow/layers/platform_view_layer.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_embedder.h"
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
#include "flutter/testing/mock_canvas.h"
@@ -32,11 +34,64 @@ TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) {
#else
EXPECT_FALSE(layer->needs_system_composite());
#endif // LEGACY_FUCHSIA_EMBEDDER
EXPECT_FALSE(layer->subtree_has_platform_view());
layer->Paint(paint_context());
EXPECT_EQ(paint_context().leaf_nodes_canvas, &mock_canvas());
EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
}
TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
const SkRect child_clip = SkRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f);
const SkRect parent_clip = SkRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f);
const int64_t view_id = 0;
auto layer =
std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
auto child_clip_layer =
std::make_shared<ClipRectLayer>(child_clip, Clip::hardEdge);
auto parent_clip_layer =
std::make_shared<ClipRectLayer>(parent_clip, Clip::hardEdge);
parent_clip_layer->Add(child_clip_layer);
child_clip_layer->Add(layer);
auto embedder = MockViewEmbedder();
preroll_context()->view_embedder = &embedder;
parent_clip_layer->Preroll(preroll_context(), SkMatrix());
EXPECT_TRUE(preroll_context()->has_platform_view);
EXPECT_EQ(layer->paint_bounds(),
SkRect::MakeSize(layer_size)
.makeOffset(layer_offset.fX, layer_offset.fY));
EXPECT_TRUE(layer->needs_painting(paint_context()));
EXPECT_TRUE(child_clip_layer->needs_painting(paint_context()));
EXPECT_TRUE(parent_clip_layer->needs_painting(paint_context()));
#if defined(LEGACY_FUCHSIA_EMBEDDER)
EXPECT_TRUE(layer->needs_system_composite());
#else
EXPECT_FALSE(layer->needs_system_composite());
#endif // LEGACY_FUCHSIA_EMBEDDER
EXPECT_TRUE(layer->subtree_has_platform_view());
EXPECT_TRUE(child_clip_layer->subtree_has_platform_view());
EXPECT_TRUE(parent_clip_layer->subtree_has_platform_view());
parent_clip_layer->Paint(paint_context());
EXPECT_EQ(paint_context().leaf_nodes_canvas, &mock_canvas());
EXPECT_EQ(
mock_canvas().draw_calls(),
std::vector(
{MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{
1, MockCanvas::ClipRectData{parent_clip, SkClipOp::kIntersect,
MockCanvas::kHard_ClipEdgeStyle}},
MockCanvas::DrawCall{1, MockCanvas::SaveData{2}},
MockCanvas::DrawCall{
2, MockCanvas::ClipRectData{child_clip, SkClipOp::kIntersect,
MockCanvas::kHard_ClipEdgeStyle}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}}));
}
} // namespace testing
} // namespace flutter

View File

@@ -0,0 +1,45 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/testing/mock_embedder.h"
namespace flutter {
namespace testing {
MockViewEmbedder::MockViewEmbedder() = default;
MockViewEmbedder::~MockViewEmbedder() = default;
// |ExternalViewEmbedder|
SkCanvas* MockViewEmbedder::GetRootCanvas() {
return nullptr;
}
// |ExternalViewEmbedder|
void MockViewEmbedder::CancelFrame() {}
// |ExternalViewEmbedder|
void MockViewEmbedder::BeginFrame(
SkISize frame_size,
GrDirectContext* context,
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) {}
// |ExternalViewEmbedder|
void MockViewEmbedder::PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) {}
// |ExternalViewEmbedder|
std::vector<SkCanvas*> MockViewEmbedder::GetCurrentCanvases() {
return std::vector<SkCanvas*>({});
}
// |ExternalViewEmbedder|
SkCanvas* MockViewEmbedder::CompositeEmbeddedView(int view_id) {
return nullptr;
}
} // namespace testing
} // namespace flutter

View File

@@ -0,0 +1,47 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLOW_TESTING_MOCK_EMBEDDER_H_
#define FLOW_TESTING_MOCK_EMBEDDER_H_
#include "flutter/flow/embedded_views.h"
namespace flutter {
namespace testing {
class MockViewEmbedder : public ExternalViewEmbedder {
public:
MockViewEmbedder();
~MockViewEmbedder();
// |ExternalViewEmbedder|
SkCanvas* GetRootCanvas() override;
// |ExternalViewEmbedder|
void CancelFrame() override;
// |ExternalViewEmbedder|
void BeginFrame(
SkISize frame_size,
GrDirectContext* context,
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override;
// |ExternalViewEmbedder|
void PrerollCompositeEmbeddedView(
int view_id,
std::unique_ptr<EmbeddedViewParams> params) override;
// |ExternalViewEmbedder|
std::vector<SkCanvas*> GetCurrentCanvases() override;
// |ExternalViewEmbedder|
SkCanvas* CompositeEmbeddedView(int view_id) override;
};
} // namespace testing
} // namespace flutter
#endif // FLOW_TESTING_MOCK_EMBEDDER_H_