focus SkiaGPUObject wrappers on only those objects that need the protection (flutter/engine#41237)

With this PR we no longer need to hold DisplayLists in GPUObject wrappers and they can be disposed instantly instead of queueing on the Unref thread.

This will definitely be a win for Impeller as none of the objects used in a frame now require queueing, but the performance impact on apps running on top of skia is less clear if they depend on a lot of images inside their DisplayLists that still need to be queued to be freed. After getting further in the work, it looks like only decoded images need to use the protected DlImage wrappers and most of those should survive many frames before they are disposed. That should hopefully leave very few unrefs happening per frame.

~There are 3 unit tests in `shell_unittests.cc` and `embedder_metal_unittests.mm` that are now GSKIP'd as they now invoke code that needs a fully initialized UIDartState in order to protect their images. I will look into fixing the tests and/or making the code they invoke provide protection without relying on UIDartState.~ (This looks to be fixed in the latest commit by simply not creating DlImageGPUs all over the source base and simply catching only those that end up in UI data structures. There is actually existing code in one of the modules that feeds ui.Image with an answer to wrap the image in a DlImageGPU if it has a skia image anyway, so most of these additional uses of DlImageGPU that were having trouble getting the Skia unref queue just didn't need it anyway.)
This commit is contained in:
Jim Graham
2023-04-17 16:47:20 -07:00
committed by GitHub
parent 1cdb28e0d8
commit d4a56c721b
47 changed files with 244 additions and 251 deletions

View File

@@ -21,7 +21,8 @@ DisplayList::DisplayList()
nested_op_count_(0),
unique_id_(0),
bounds_({0, 0, 0, 0}),
can_apply_group_opacity_(true) {}
can_apply_group_opacity_(true),
is_ui_thread_safe_(true) {}
DisplayList::DisplayList(DisplayListStorage&& storage,
size_t byte_count,
@@ -30,6 +31,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
unsigned int nested_op_count,
const SkRect& bounds,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
sk_sp<const DlRTree> rtree)
: storage_(std::move(storage)),
byte_count_(byte_count),
@@ -39,6 +41,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
unique_id_(next_unique_id()),
bounds_(bounds),
can_apply_group_opacity_(can_apply_group_opacity),
is_ui_thread_safe_(is_ui_thread_safe),
rtree_(std::move(rtree)) {}
DisplayList::~DisplayList() {

View File

@@ -262,6 +262,7 @@ class DisplayList : public SkRefCnt {
}
bool can_apply_group_opacity() const { return can_apply_group_opacity_; }
bool isUIThreadSafe() const { return is_ui_thread_safe_; }
static void DisposeOps(uint8_t* ptr, uint8_t* end);
@@ -273,6 +274,7 @@ class DisplayList : public SkRefCnt {
unsigned int nested_op_count,
const SkRect& bounds,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
sk_sp<const DlRTree> rtree);
static uint32_t next_unique_id();
@@ -288,6 +290,7 @@ class DisplayList : public SkRefCnt {
const SkRect bounds_;
const bool can_apply_group_opacity_;
const bool is_ui_thread_safe_;
const sk_sp<const DlRTree> rtree_;
void Dispatch(DlOpReceiver& ctx,

View File

@@ -73,9 +73,10 @@ sk_sp<DisplayList> DisplayListBuilder::Build() {
nested_bytes_ = nested_op_count_ = 0;
storage_.realloc(bytes);
bool compatible = layer_stack_.back().is_group_opacity_compatible();
return sk_sp<DisplayList>(new DisplayList(std::move(storage_), bytes, count,
nested_bytes, nested_count,
bounds(), compatible, rtree()));
bool is_safe = is_ui_thread_safe_;
return sk_sp<DisplayList>(
new DisplayList(std::move(storage_), bytes, count, nested_bytes,
nested_count, bounds(), compatible, is_safe, rtree()));
}
DisplayListBuilder::DisplayListBuilder(const SkRect& cull_rect,
@@ -156,6 +157,7 @@ void DisplayListBuilder::onSetColorSource(const DlColorSource* source) {
Push<ClearColorSourceOp>(0, 0);
} else {
current_.setColorSource(source->shared());
is_ui_thread_safe_ = is_ui_thread_safe_ && source->isUIThreadSafe();
switch (source->type()) {
case DlColorSourceType::kColor: {
const DlColorColorSource* color_source = source->asColor();
@@ -923,6 +925,7 @@ void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
? Push<DrawImageWithAttrOp>(0, 1, image, point, sampling)
: Push<DrawImageOp>(0, 1, image, point, sampling);
CheckLayerOpacityCompatibility(render_with_attributes);
is_ui_thread_safe_ = is_ui_thread_safe_ && image->isUIThreadSafe();
SkRect bounds = SkRect::MakeXYWH(point.fX, point.fY, //
image->width(), image->height());
DisplayListAttributeFlags flags = render_with_attributes //
@@ -951,6 +954,7 @@ void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
Push<DrawImageRectOp>(0, 1, image, src, dst, sampling, render_with_attributes,
constraint);
CheckLayerOpacityCompatibility(render_with_attributes);
is_ui_thread_safe_ = is_ui_thread_safe_ && image->isUIThreadSafe();
DisplayListAttributeFlags flags = render_with_attributes
? kDrawImageRectWithPaintFlags
: kDrawImageRectFlags;
@@ -979,6 +983,7 @@ void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
? Push<DrawImageNineWithAttrOp>(0, 1, image, center, dst, filter)
: Push<DrawImageNineOp>(0, 1, image, center, dst, filter);
CheckLayerOpacityCompatibility(render_with_attributes);
is_ui_thread_safe_ = is_ui_thread_safe_ && image->isUIThreadSafe();
DisplayListAttributeFlags flags = render_with_attributes
? kDrawImageNineWithPaintFlags
: kDrawImageNineFlags;
@@ -1034,6 +1039,7 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
// on it to distribute the opacity without overlap without checking all
// of the transforms and texture rectangles.
UpdateLayerOpacityCompatibility(false);
is_ui_thread_safe_ = is_ui_thread_safe_ && atlas->isUIThreadSafe();
SkPoint quad[4];
RectBoundsAccumulator atlasBounds;
@@ -1075,6 +1081,7 @@ void DisplayListBuilder::DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity) {
DlPaint current_paint = current_;
Push<DrawDisplayListOp>(0, 1, display_list, opacity);
is_ui_thread_safe_ = is_ui_thread_safe_ && display_list->isUIThreadSafe();
// Not really necessary if the developer is interacting with us via
// our attribute-state-less DlCanvas methods, but this avoids surprises
// for those who may have been using the stateful Dispatcher methods.

View File

@@ -480,6 +480,8 @@ class DisplayListBuilder final : public virtual DlCanvas,
size_t nested_bytes_ = 0;
int nested_op_count_ = 0;
bool is_ui_thread_safe_ = true;
template <typename T, typename... Args>
void* Push(size_t extra, int op_inc, Args&&... args);

View File

@@ -109,6 +109,16 @@ class DlColorSource : public DlAttribute<DlColorSource, DlColorSourceType> {
virtual bool is_opaque() const = 0;
//----------------------------------------------------------------------------
/// @brief If the underlying platform data held by this object is
/// held in a way that it can be stored and potentially
/// released from the UI thread, this method returns true.
///
/// @return True if the class has no GPU related resources or if any
/// that it holds are held in a thread-safe manner.
///
virtual bool isUIThreadSafe() const = 0;
// Return a DlColorColorSource pointer to this object iff it is an Color
// type of ColorSource, otherwise return nullptr.
virtual const DlColorColorSource* asColor() const { return nullptr; }
@@ -160,6 +170,8 @@ class DlColorColorSource final : public DlColorSource {
public:
DlColorColorSource(DlColor color) : color_(color) {}
bool isUIThreadSafe() const override { return true; }
std::shared_ptr<DlColorSource> shared() const override {
return std::make_shared<DlColorColorSource>(color_);
}
@@ -215,6 +227,10 @@ class DlImageColorSource final : public SkRefCnt,
vertical_tile_mode_(vertical_tile_mode),
sampling_(sampling) {}
bool isUIThreadSafe() const override {
return image_ ? image_->isUIThreadSafe() : true;
}
const DlImageColorSource* asImage() const override { return this; }
std::shared_ptr<DlColorSource> shared() const override {
@@ -338,6 +354,8 @@ class DlLinearGradientColorSource final : public DlGradientColorSourceBase {
return this;
}
bool isUIThreadSafe() const override { return true; }
DlColorSourceType type() const override {
return DlColorSourceType::kLinearGradient;
}
@@ -399,6 +417,8 @@ class DlRadialGradientColorSource final : public DlGradientColorSourceBase {
return this;
}
bool isUIThreadSafe() const override { return true; }
std::shared_ptr<DlColorSource> shared() const override {
return MakeRadial(center_, radius_, stop_count(), colors(), stops(),
tile_mode(), matrix_ptr());
@@ -460,6 +480,8 @@ class DlConicalGradientColorSource final : public DlGradientColorSourceBase {
return this;
}
bool isUIThreadSafe() const override { return true; }
std::shared_ptr<DlColorSource> shared() const override {
return MakeConical(start_center_, start_radius_, end_center_, end_radius_,
stop_count(), colors(), stops(), tile_mode(),
@@ -534,6 +556,8 @@ class DlSweepGradientColorSource final : public DlGradientColorSourceBase {
return this;
}
bool isUIThreadSafe() const override { return true; }
std::shared_ptr<DlColorSource> shared() const override {
return MakeSweep(center_, start_, end_, stop_count(), colors(), stops(),
tile_mode(), matrix_ptr());
@@ -604,6 +628,15 @@ class DlRuntimeEffectColorSource final : public DlColorSource {
samplers_(std::move(samplers)),
uniform_data_(std::move(uniform_data)) {}
bool isUIThreadSafe() const override {
for (auto sampler : samplers_) {
if (!sampler->isUIThreadSafe()) {
return false;
}
}
return true;
}
const DlRuntimeEffectColorSource* asRuntimeEffect() const override {
return this;
}
@@ -666,6 +699,8 @@ class DlSceneColorSource final : public DlColorSource {
impeller::Matrix camera_matrix)
: node_(std::move(node)), camera_matrix_(camera_matrix) {}
bool isUIThreadSafe() const override { return true; }
const DlSceneColorSource* asScene() const override { return this; }
std::shared_ptr<DlColorSource> shared() const override {

View File

@@ -67,6 +67,16 @@ class DlImage : public SkRefCnt {
virtual bool isTextureBacked() const = 0;
//----------------------------------------------------------------------------
/// @brief If the underlying platform image held by this object has no
/// threading requirements for the release of that image (or if
/// arrangements have already been made to forward that image to
/// the correct thread upon deletion), this method returns true.
///
/// @return True if the underlying image is held in a thread-safe manner.
///
virtual bool isUIThreadSafe() const = 0;
//----------------------------------------------------------------------------
/// @return The dimensions of the pixel grid.
///

View File

@@ -31,6 +31,17 @@ bool DlImageSkia::isTextureBacked() const {
return image_ ? image_->isTextureBacked() : false;
}
// |DlImage|
bool DlImageSkia::isUIThreadSafe() const {
// Technically if the image is null then we are thread-safe, and possibly
// if the image is constructed from a heap raster as well, but there
// should never be a leak of an instance of this class into any data that
// is shared with the UI thread, regardless of value.
// All images intended to be shared with the UI thread should be constructed
// via one of the DlImage subclasses designed for that purpose.
return false;
}
// |DlImage|
SkISize DlImageSkia::dimensions() const {
return image_ ? image_->dimensions() : SkISize::MakeEmpty();

View File

@@ -29,6 +29,9 @@ class DlImageSkia final : public DlImage {
// |DlImage|
bool isTextureBacked() const override;
// |DlImage|
bool isUIThreadSafe() const override;
// |DlImage|
SkISize dimensions() const override;

View File

@@ -123,8 +123,6 @@ if (enable_unittests) {
"testing/mock_raster_cache.h",
"testing/mock_texture.cc",
"testing/mock_texture.h",
"testing/skia_gpu_object_layer_test.cc",
"testing/skia_gpu_object_layer_test.h",
]
public_deps = [

View File

@@ -16,15 +16,14 @@
namespace flutter {
DisplayListLayer::DisplayListLayer(const SkPoint& offset,
SkiaGPUObject<DisplayList> display_list,
sk_sp<DisplayList> display_list,
bool is_complex,
bool will_change)
: offset_(offset), display_list_(std::move(display_list)) {
if (display_list_.skia_object() != nullptr) {
bounds_ = display_list_.skia_object()->bounds().makeOffset(offset_.x(),
offset_.y());
if (display_list_) {
bounds_ = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
display_list_raster_cache_item_ = DisplayListRasterCacheItem::Make(
display_list_.skia_object(), offset_, is_complex, will_change);
display_list_, offset_, is_complex, will_change);
}
}
@@ -61,8 +60,8 @@ void DisplayListLayer::Diff(DiffContext* context, const Layer* old_layer) {
bool DisplayListLayer::Compare(DiffContext::Statistics& statistics,
const DisplayListLayer* l1,
const DisplayListLayer* l2) {
const auto& dl1 = l1->display_list_.skia_object();
const auto& dl2 = l2->display_list_.skia_object();
const auto& dl1 = l1->display_list_;
const auto& dl2 = l2->display_list_;
if (dl1.get() == dl2.get()) {
statistics.AddSameInstancePicture();
return true;
@@ -105,7 +104,7 @@ void DisplayListLayer::Preroll(PrerollContext* context) {
}
void DisplayListLayer::Paint(PaintContext& context) const {
FML_DCHECK(display_list_.skia_object());
FML_DCHECK(display_list_);
FML_DCHECK(needs_painting(context));
auto mutator = context.state_stack.save();
@@ -143,7 +142,7 @@ void DisplayListLayer::Paint(PaintContext& context) const {
DlAutoCanvasRestore save(canvas, true);
canvas->Clear(DlColor::kTransparent());
canvas->SetTransform(ctm);
canvas->DrawDisplayList(display_list_.skia_object(), opacity);
canvas->DrawDisplayList(display_list_, opacity);
}
canvas->Flush();
}
@@ -158,8 +157,7 @@ void DisplayListLayer::Paint(PaintContext& context) const {
context.layer_snapshot_store->Add(snapshot_data);
}
auto display_list = display_list_.skia_object();
context.canvas->DrawDisplayList(display_list, opacity);
context.canvas->DrawDisplayList(display_list_, opacity);
}
} // namespace flutter

View File

@@ -11,7 +11,6 @@
#include "flutter/flow/layers/display_list_raster_cache_item.h"
#include "flutter/flow/layers/layer.h"
#include "flutter/flow/raster_cache_item.h"
#include "flutter/flow/skia_gpu_object.h"
namespace flutter {
@@ -20,13 +19,11 @@ class DisplayListLayer : public Layer {
static constexpr size_t kMaxBytesToCompare = 10000;
DisplayListLayer(const SkPoint& offset,
SkiaGPUObject<DisplayList> display_list,
sk_sp<DisplayList> display_list,
bool is_complex,
bool will_change);
DisplayList* display_list() const {
return display_list_.skia_object().get();
}
DisplayList* display_list() const { return display_list_.get(); }
bool IsReplacing(DiffContext* context, const Layer* layer) const override;
@@ -55,7 +52,7 @@ class DisplayListLayer : public Layer {
SkPoint offset_;
SkRect bounds_;
flutter::SkiaGPUObject<DisplayList> display_list_;
sk_sp<DisplayList> display_list_;
static bool Compare(DiffContext::Statistics& statistics,
const DisplayListLayer* l1,

View File

@@ -9,23 +9,21 @@
#include "flutter/display_list/dl_builder.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/testing/diff_context_test.h"
#include "flutter/flow/testing/skia_gpu_object_layer_test.h"
#include "flutter/fml/macros.h"
#include "flutter/testing/mock_canvas.h"
namespace flutter {
namespace testing {
using DisplayListLayerTest = SkiaGPUObjectLayerTest;
using DisplayListLayerTest = LayerTest;
#ifndef NDEBUG
TEST_F(DisplayListLayerTest, PaintBeforePrerollInvalidDisplayListDies) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject<DisplayList>(), false, false);
layer_offset, sk_sp<DisplayList>(), false, false);
EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"display_list_\\.skia_object\\(\\)");
EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "display_list_");
}
TEST_F(DisplayListLayerTest, PaintBeforePrerollDies) {
@@ -34,9 +32,8 @@ TEST_F(DisplayListLayerTest, PaintBeforePrerollDies) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject<DisplayList>(display_list, unref_queue()),
false, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
false, false);
EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty());
EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
@@ -49,9 +46,8 @@ TEST_F(DisplayListLayerTest, PaintingEmptyLayerDies) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject<DisplayList>(display_list, unref_queue()),
false, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
false, false);
layer->Preroll(preroll_context());
EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty());
@@ -64,7 +60,7 @@ TEST_F(DisplayListLayerTest, PaintingEmptyLayerDies) {
TEST_F(DisplayListLayerTest, InvalidDisplayListDies) {
const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject<DisplayList>(), false, false);
layer_offset, sk_sp<DisplayList>(), false, false);
// Crashes reading a nullptr.
EXPECT_DEATH_IF_SUPPORTED(layer->Preroll(preroll_context()), "");
@@ -79,8 +75,8 @@ TEST_F(DisplayListLayerTest, SimpleDisplayList) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), false, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
false, false);
layer->Preroll(preroll_context());
EXPECT_EQ(layer->paint_bounds(),
@@ -104,8 +100,8 @@ TEST_F(DisplayListLayerTest, CachingDoesNotChangeCullRect) {
DisplayListBuilder builder;
builder.DrawRect({10, 10, 20, 20}, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), true, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
true, false);
SkRect original_cull_rect = preroll_context()->state_stack.device_cull_rect();
use_mock_raster_cache();
@@ -121,7 +117,7 @@ TEST_F(DisplayListLayerTest, SimpleDisplayListOpacityInheritance) {
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto display_list_layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), false, false);
layer_offset, display_list, false, false);
EXPECT_TRUE(display_list->can_apply_group_opacity());
auto context = preroll_context();
@@ -173,7 +169,7 @@ TEST_F(DisplayListLayerTest, IncompatibleDisplayListOpacityInheritance) {
builder.DrawRect(picture2_bounds, DlPaint());
auto display_list = builder.Build();
auto display_list_layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), false, false);
layer_offset, display_list, false, false);
EXPECT_FALSE(display_list->can_apply_group_opacity());
auto context = preroll_context();
@@ -233,7 +229,7 @@ TEST_F(DisplayListLayerTest, CachedIncompatibleDisplayListOpacityInheritance) {
builder.DrawRect(picture2_bounds, DlPaint());
auto display_list = builder.Build();
auto display_list_layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), true, false);
layer_offset, display_list, true, false);
EXPECT_FALSE(display_list->can_apply_group_opacity());
use_skia_raster_cache();
@@ -383,8 +379,8 @@ TEST_F(DisplayListLayerTest, LayerTreeSnapshotsWhenEnabled) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), false, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
false, false);
layer->Preroll(preroll_context());
@@ -402,8 +398,8 @@ TEST_F(DisplayListLayerTest, NoLayerTreeSnapshotsWhenDisabledByDefault) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), false, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
false, false);
layer->Preroll(preroll_context());
layer->Paint(paint_context());
@@ -420,8 +416,8 @@ TEST_F(DisplayListLayerTest, DisplayListAccessCountDependsOnVisibility) {
DisplayListBuilder builder;
builder.DrawRect(picture_bounds, DlPaint());
auto display_list = builder.Build();
auto layer = std::make_shared<DisplayListLayer>(
layer_offset, SkiaGPUObject(display_list, unref_queue()), true, false);
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
true, false);
auto raster_cache_item = layer->raster_cache_item();
use_mock_raster_cache();
@@ -525,8 +521,8 @@ TEST_F(DisplayListLayerTest, OverflowCachedDisplayListOpacityInheritance) {
ASSERT_FALSE(display_list->can_apply_group_opacity());
SkPoint offset = {i * 200.0f, 0};
layers[i] = std::make_shared<DisplayListLayer>(
offset, SkiaGPUObject(display_list, unref_queue()), true, false);
layers[i] =
std::make_shared<DisplayListLayer>(offset, display_list, true, false);
opacity_layer->Add(layers[i]);
}
for (size_t j = 0; j < context->raster_cache->access_threshold(); j++) {

View File

@@ -14,7 +14,7 @@
#include "flutter/flow/raster_cache_item.h"
#include "flutter/flow/raster_cache_key.h"
#include "flutter/flow/raster_cache_util.h"
#include "flutter/flow/skia_gpu_object.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
namespace flutter {

View File

@@ -13,8 +13,8 @@
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/flow/raster_cache.h"
#include "flutter/flow/raster_cache_item.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_raster_cache.h"
#include "flutter/flow/testing/skia_gpu_object_layer_test.h"
#include "flutter/testing/assertions_skia.h"
#include "gtest/gtest.h"
#include "include/core/SkMatrix.h"
@@ -858,7 +858,7 @@ TEST(RasterCache, RasterCacheKeyIDHashCode) {
ASSERT_EQ(fourth_hash, fourth.GetHash());
}
using RasterCacheTest = SkiaGPUObjectLayerTest;
using RasterCacheTest = LayerTest;
TEST_F(RasterCacheTest, RasterCacheKeyIDLayerChildrenIds) {
auto layer = std::make_shared<ContainerLayer>();
@@ -869,8 +869,7 @@ TEST_F(RasterCacheTest, RasterCacheKeyIDLayerChildrenIds) {
auto display_list = GetSampleDisplayList();
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(0.0f, 0.0f),
SkiaGPUObject<DisplayList>(display_list, unref_queue()), false, false);
SkPoint::Make(0.0f, 0.0f), display_list, false, false);
layer->Add(display_list_layer);
auto ids = RasterCacheKeyID::LayerChildrenIds(layer.get()).value();

View File

@@ -10,10 +10,7 @@
namespace flutter {
namespace testing {
DiffContextTest::DiffContextTest()
: unref_queue_(fml::MakeRefCounted<SkiaUnrefQueue>(
GetCurrentTaskRunner(),
fml::TimeDelta::FromSeconds(0))) {}
DiffContextTest::DiffContextTest() {}
Damage DiffContextTest::DiffLayerTree(MockLayerTree& layer_tree,
const MockLayerTree& old_layer_tree,
@@ -40,11 +37,9 @@ sk_sp<DisplayList> DiffContextTest::CreateDisplayList(const SkRect& bounds,
}
std::shared_ptr<DisplayListLayer> DiffContextTest::CreateDisplayListLayer(
sk_sp<DisplayList> display_list,
const sk_sp<DisplayList>& display_list,
const SkPoint& offset) {
return std::make_shared<DisplayListLayer>(
offset, SkiaGPUObject(std::move(display_list), unref_queue()), false,
false);
return std::make_shared<DisplayListLayer>(offset, display_list, false, false);
}
std::shared_ptr<ContainerLayer> DiffContextTest::CreateContainerLayer(

View File

@@ -5,7 +5,7 @@
#include "flutter/flow/layers/container_layer.h"
#include "flutter/flow/layers/display_list_layer.h"
#include "flutter/flow/layers/opacity_layer.h"
#include "flutter/flow/testing/skia_gpu_object_layer_test.h"
#include "flutter/flow/testing/layer_test.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -31,7 +31,7 @@ class MockLayerTree {
SkISize size_;
};
class DiffContextTest : public ThreadTest {
class DiffContextTest : public LayerTest {
public:
DiffContextTest();
@@ -47,7 +47,7 @@ class DiffContextTest : public ThreadTest {
sk_sp<DisplayList> CreateDisplayList(const SkRect& bounds, uint32_t color);
std::shared_ptr<DisplayListLayer> CreateDisplayListLayer(
sk_sp<DisplayList> display_list,
const sk_sp<DisplayList>& display_list,
const SkPoint& offset = SkPoint::Make(0, 0));
std::shared_ptr<ContainerLayer> CreateContainerLayer(
@@ -62,11 +62,6 @@ class DiffContextTest : public ThreadTest {
std::initializer_list<std::shared_ptr<Layer>> layers,
SkAlpha alpha,
const SkPoint& offset = SkPoint::Make(0, 0));
fml::RefPtr<SkiaUnrefQueue> unref_queue() { return unref_queue_; }
private:
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
};
} // namespace testing

View File

@@ -4,7 +4,7 @@
#include "flutter/flow/testing/mock_texture.h"
#include "flutter/flow/layers/layer.h"
#include "flutter/flow/testing/skia_gpu_object_layer_test.h"
#include "flutter/testing/display_list_testing.h"
namespace flutter {
namespace testing {

View File

@@ -1,18 +0,0 @@
// 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/skia_gpu_object_layer_test.h"
#include "flutter/fml/time/time_delta.h"
namespace flutter {
namespace testing {
SkiaGPUObjectLayerTest::SkiaGPUObjectLayerTest()
: unref_queue_(fml::MakeRefCounted<SkiaUnrefQueue>(
GetCurrentTaskRunner(),
fml::TimeDelta::FromSeconds(0))) {}
} // namespace testing
} // namespace flutter

View File

@@ -1,30 +0,0 @@
// 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_SKIA_GPU_OBJECT_LAYER_TEST_H_
#define FLOW_TESTING_SKIA_GPU_OBJECT_LAYER_TEST_H_
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/flow/testing/layer_test.h"
#include "flutter/testing/thread_test.h"
namespace flutter {
namespace testing {
// This fixture allows generating tests that create |SkiaGPUObject|'s which
// are destroyed on a |SkiaUnrefQueue|.
class SkiaGPUObjectLayerTest : public LayerTestBase<ThreadTest> {
public:
SkiaGPUObjectLayerTest();
fml::RefPtr<SkiaUnrefQueue> unref_queue() { return unref_queue_; }
private:
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
};
} // namespace testing
} // namespace flutter
#endif // FLOW_TESTING_SKIA_GPU_OBJECT_LAYER_TEST_H_

View File

@@ -64,6 +64,12 @@ bool DlImageImpeller::isTextureBacked() const {
return true;
}
// |DlImage|
bool DlImageImpeller::isUIThreadSafe() const {
// Impeller textures are always thread-safe
return true;
}
// |DlImage|
SkISize DlImageImpeller::dimensions() const {
const auto size = texture_ ? texture_->GetSize() : ISize{};

View File

@@ -39,6 +39,9 @@ class DlImageImpeller final : public flutter::DlImage {
// |DlImage|
bool isTextureBacked() const override;
// |DlImage|
bool isUIThreadSafe() const override;
// |DlImage|
SkISize dimensions() const override;

View File

@@ -243,9 +243,8 @@ void SceneBuilder::addPicture(double dx,
// been disposed but not collected yet, but the display list is null.
if (picture->display_list()) {
auto layer = std::make_unique<flutter::DisplayListLayer>(
SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)),
UIDartState::CreateGPUObject(picture->display_list()), !!(hints & 1),
!!(hints & 2));
SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)), picture->display_list(),
!!(hints & 1), !!(hints & 2));
AddLayer(std::move(layer));
}
}

View File

@@ -63,6 +63,11 @@ bool DlDeferredImageGPUImpeller::isTextureBacked() const {
return wrapper_ && wrapper_->isTextureBacked();
}
// |DlImage|
bool DlDeferredImageGPUImpeller::isUIThreadSafe() const {
return true;
}
// |DlImage|
SkISize DlDeferredImageGPUImpeller::dimensions() const {
if (!wrapper_) {

View File

@@ -44,6 +44,9 @@ class DlDeferredImageGPUImpeller final : public DlImage {
// |DlImage|
bool isTextureBacked() const override;
// |DlImage|
bool isUIThreadSafe() const override;
// |DlImage|
SkISize dimensions() const override;

View File

@@ -75,6 +75,11 @@ bool DlDeferredImageGPUSkia::isTextureBacked() const {
return image_wrapper_ ? image_wrapper_->isTextureBacked() : false;
}
// |DlImage|
bool DlDeferredImageGPUSkia::isUIThreadSafe() const {
return true;
}
// |DlImage|
SkISize DlDeferredImageGPUSkia::dimensions() const {
return image_wrapper_ ? image_wrapper_->image_info().dimensions()

View File

@@ -12,7 +12,6 @@
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/image/dl_image.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/lib/ui/io_manager.h"
@@ -55,6 +54,9 @@ class DlDeferredImageGPUSkia final : public DlImage {
// |DlImage|
bool isTextureBacked() const override;
// |DlImage|
bool isUIThreadSafe() const override;
// |DlImage|
SkISize dimensions() const override;

View File

@@ -45,6 +45,11 @@ bool DlImageGPU::isTextureBacked() const {
return false;
}
// |DlImage|
bool DlImageGPU::isUIThreadSafe() const {
return true;
}
// |DlImage|
SkISize DlImageGPU::dimensions() const {
const auto image = skia_image();

View File

@@ -30,6 +30,9 @@ class DlImageGPU final : public DlImage {
// |DlImage|
bool isTextureBacked() const override;
// |DlImage|
bool isUIThreadSafe() const override;
// |DlImage|
SkISize dimensions() const override;

View File

@@ -59,6 +59,9 @@ bool ReusableFragmentShader::ValidateSamplers() {
if (samplers_[i] == nullptr) {
return false;
}
// The samplers should have been checked as they were added, this
// is a double-sanity-check.
FML_DCHECK(samplers_[i]->isUIThreadSafe());
}
return true;
}
@@ -71,12 +74,18 @@ void ReusableFragmentShader::SetImageSampler(Dart_Handle index_handle,
if (index >= samplers_.size()) {
Dart_ThrowException(tonic::ToDart("Sampler index out of bounds"));
}
if (!image->image()->isUIThreadSafe()) {
Dart_ThrowException(tonic::ToDart("Image is not thread-safe"));
}
// TODO(115794): Once the DlImageSampling enum is replaced, expose the
// sampling options as a new default parameter for users.
samplers_[index] = std::make_shared<DlImageColorSource>(
image->image(), DlTileMode::kClamp, DlTileMode::kClamp,
DlImageSampling::kNearestNeighbor, nullptr);
// This should be true since we already checked the image above, but
// we check again for sanity.
FML_DCHECK(samplers_[index]->isUIThreadSafe());
auto* uniform_floats =
reinterpret_cast<float*>(uniform_data_->writable_data());
@@ -95,7 +104,11 @@ std::shared_ptr<DlColorSource> ReusableFragmentShader::shader(
uniform_data->resize(uniform_data_->size());
memcpy(uniform_data->data(), uniform_data_->bytes(), uniform_data->size());
return program_->MakeDlColorSource(std::move(uniform_data), samplers_);
auto source = program_->MakeDlColorSource(std::move(uniform_data), samplers_);
// The samplers should have been checked as they were added, this
// is a double-sanity-check.
FML_DCHECK(source->isUIThreadSafe());
return source;
}
void ReusableFragmentShader::Dispose() {

View File

@@ -50,6 +50,8 @@ void CanvasGradient::initLinear(const tonic::Float32List& end_points,
dl_shader_ = DlColorSource::MakeLinear(
p0, p1, colors.num_elements(), colors_array, color_stops.data(),
tile_mode, has_matrix ? &sk_matrix : nullptr);
// Just a sanity check, all gradient shaders should be thread-safe
FML_DCHECK(dl_shader_->isUIThreadSafe());
}
void CanvasGradient::initRadial(double center_x,
@@ -77,6 +79,8 @@ void CanvasGradient::initRadial(double center_x,
SkPoint::Make(SafeNarrow(center_x), SafeNarrow(center_y)),
SafeNarrow(radius), colors.num_elements(), colors_array,
color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr);
// Just a sanity check, all gradient shaders should be thread-safe
FML_DCHECK(dl_shader_->isUIThreadSafe());
}
void CanvasGradient::initSweep(double center_x,
@@ -107,6 +111,8 @@ void CanvasGradient::initSweep(double center_x,
SafeNarrow(end_angle) * 180.0f / static_cast<float>(M_PI),
colors.num_elements(), colors_array, color_stops.data(), tile_mode,
has_matrix ? &sk_matrix : nullptr);
// Just a sanity check, all gradient shaders should be thread-safe
FML_DCHECK(dl_shader_->isUIThreadSafe());
}
void CanvasGradient::initTwoPointConical(double start_x,
@@ -139,6 +145,8 @@ void CanvasGradient::initTwoPointConical(double start_x,
SkPoint::Make(SafeNarrow(end_x), SafeNarrow(end_y)),
SafeNarrow(end_radius), colors.num_elements(), colors_array,
color_stops.data(), tile_mode, has_matrix ? &sk_matrix : nullptr);
// Just a sanity check, all gradient shaders should be thread-safe
FML_DCHECK(dl_shader_->isUIThreadSafe());
}
CanvasGradient::CanvasGradient() = default;

View File

@@ -6,9 +6,7 @@
#define FLUTTER_LIB_UI_PAINTING_IMAGE_H_
#include "flutter/display_list/image/dl_image.h"
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/display_list_image_gpu.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "third_party/skia/include/core/SkImage.h"
@@ -41,7 +39,10 @@ class CanvasImage final : public RefCountedDartWrappable<CanvasImage> {
sk_sp<DlImage> image() const { return image_; }
void set_image(sk_sp<DlImage> image) { image_ = image; }
void set_image(sk_sp<DlImage> image) {
FML_DCHECK(image->isUIThreadSafe());
image_ = image;
}
int colorSpace();

View File

@@ -35,6 +35,7 @@ class MockDlImage : public DlImage {
MOCK_CONST_METHOD0(impeller_texture, std::shared_ptr<impeller::Texture>());
MOCK_CONST_METHOD0(isOpaque, bool());
MOCK_CONST_METHOD0(isTextureBacked, bool());
MOCK_CONST_METHOD0(isUIThreadSafe, bool());
MOCK_CONST_METHOD0(dimensions, SkISize());
MOCK_CONST_METHOD0(GetApproximateByteSize, size_t());
};

View File

@@ -28,7 +28,8 @@ Dart_Handle ImageShader::initWithImage(CanvasImage* image,
DlTileMode tmy,
int filter_quality_index,
Dart_Handle matrix_handle) {
if (!image) {
// CanvasImage should have already checked for a UI thread safe image.
if (!image || !image->image()->isUIThreadSafe()) {
return ToDart("ImageShader constructor called with non-genuine Image.");
}
@@ -40,25 +41,17 @@ Dart_Handle ImageShader::initWithImage(CanvasImage* image,
DlImageSampling sampling =
sampling_is_locked_ ? ImageFilter::SamplingFromIndex(filter_quality_index)
: DlImageSampling::kLinear;
cached_shader_ = UIDartState::CreateGPUObject(sk_make_sp<DlImageColorSource>(
image_, tmx, tmy, sampling, &local_matrix));
cached_shader_ = std::make_shared<DlImageColorSource>(
image_, tmx, tmy, sampling, &local_matrix);
FML_DCHECK(cached_shader_->isUIThreadSafe());
return Dart_Null();
}
std::shared_ptr<DlColorSource> ImageShader::shader(DlImageSampling sampling) {
if (sampling_is_locked_) {
return cached_shader_.skia_object()->with_sampling(
cached_shader_.skia_object()->sampling());
if (sampling_is_locked_ || sampling == cached_shader_->sampling()) {
return cached_shader_;
}
// It might seem that if the sampling is locked we can just return the
// cached version, but since we need to hold the cached shader in a
// Skia GPU wrapper, and that wrapper requires an sk_sp<>, we are holding
// an sk_sp<> version of the shared object and we need a shared_ptr version.
// So, either way, we need the with_sampling() method to shared_ptr'ify
// our copy.
// If we can get rid of the need for the GPU unref queue, then this can all
// be simplified down to just a shared_ptr.
return cached_shader_.skia_object()->with_sampling(sampling);
return cached_shader_->with_sampling(sampling);
}
int ImageShader::width() {

View File

@@ -43,7 +43,7 @@ class ImageShader : public Shader {
sk_sp<const DlImage> image_;
bool sampling_is_locked_;
flutter::SkiaGPUObject<DlImageColorSource> cached_shader_;
std::shared_ptr<DlImageColorSource> cached_shader_;
};
} // namespace flutter

View File

@@ -7,6 +7,7 @@
#include <utility>
#include "flutter/fml/make_copyable.h"
#include "flutter/lib/ui/painting/display_list_image_gpu.h"
#include "flutter/lib/ui/painting/image.h"
#if IMPELLER_SUPPORTS_RENDERING
#include "flutter/lib/ui/painting/image_decoder_impeller.h"

View File

@@ -14,6 +14,7 @@
#if IMPELLER_SUPPORTS_RENDERING
#include "flutter/lib/ui/painting/display_list_deferred_image_gpu_impeller.h"
#endif // IMPELLER_SUPPORTS_RENDERING
#include "flutter/lib/ui/painting/display_list_image_gpu.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_args.h"
#include "third_party/tonic/dart_binding_macros.h"
@@ -25,16 +26,16 @@ namespace flutter {
IMPLEMENT_WRAPPERTYPEINFO(ui, Picture);
fml::RefPtr<Picture> Picture::Create(
Dart_Handle dart_handle,
flutter::SkiaGPUObject<DisplayList> display_list) {
fml::RefPtr<Picture> Picture::Create(Dart_Handle dart_handle,
sk_sp<DisplayList> display_list) {
FML_DCHECK(display_list->isUIThreadSafe());
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(display_list));
canvas_picture->AssociateWithDartWrapper(dart_handle);
return canvas_picture;
}
Picture::Picture(flutter::SkiaGPUObject<DisplayList> display_list)
Picture::Picture(sk_sp<DisplayList> display_list)
: display_list_(std::move(display_list)) {}
Picture::~Picture() = default;
@@ -42,19 +43,17 @@ Picture::~Picture() = default;
Dart_Handle Picture::toImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
if (!display_list_.skia_object()) {
if (!display_list_) {
return tonic::ToDart("Picture is null");
}
return RasterizeToImage(display_list_.skia_object(), width, height,
raw_image_callback);
return RasterizeToImage(display_list_, width, height, raw_image_callback);
}
void Picture::toImageSync(uint32_t width,
uint32_t height,
Dart_Handle raw_image_handle) {
FML_DCHECK(display_list_.skia_object());
RasterizeToImageSync(display_list_.skia_object(), width, height,
raw_image_handle);
FML_DCHECK(display_list_);
RasterizeToImageSync(display_list_, width, height, raw_image_handle);
}
static sk_sp<DlImage> CreateDeferredImage(
@@ -108,8 +107,8 @@ void Picture::dispose() {
}
size_t Picture::GetAllocationSize() const {
if (auto display_list = display_list_.skia_object()) {
return display_list->bytes() + sizeof(Picture);
if (display_list_) {
return display_list_->bytes() + sizeof(Picture);
} else {
return sizeof(Picture);
}
@@ -177,7 +176,9 @@ Dart_Handle Picture::RasterizeToImage(const sk_sp<DisplayList>& display_list,
return;
}
if (image->skia_image()) {
if (!image->isUIThreadSafe()) {
// All images with impeller textures should already be safe.
FML_DCHECK(image->impeller_texture() == nullptr);
image =
DlImageGPU::Make({image->skia_image(), std::move(unref_queue)});
}

View File

@@ -7,7 +7,6 @@
#include "flutter/display_list/display_list.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/ui_dart_state.h"
@@ -22,13 +21,10 @@ class Picture : public RefCountedDartWrappable<Picture> {
public:
~Picture() override;
static fml::RefPtr<Picture> Create(
Dart_Handle dart_handle,
flutter::SkiaGPUObject<DisplayList> display_list);
static fml::RefPtr<Picture> Create(Dart_Handle dart_handle,
sk_sp<DisplayList> display_list);
sk_sp<DisplayList> display_list() const {
return display_list_.skia_object();
}
sk_sp<DisplayList> display_list() const { return display_list_; }
Dart_Handle toImage(uint32_t width,
uint32_t height,
@@ -68,9 +64,9 @@ class Picture : public RefCountedDartWrappable<Picture> {
Dart_Handle raw_image_callback);
private:
explicit Picture(flutter::SkiaGPUObject<DisplayList> display_list);
explicit Picture(sk_sp<DisplayList> display_list);
flutter::SkiaGPUObject<DisplayList> display_list_;
sk_sp<DisplayList> display_list_;
};
} // namespace flutter

View File

@@ -38,8 +38,7 @@ fml::RefPtr<Picture> PictureRecorder::endRecording(Dart_Handle dart_picture) {
fml::RefPtr<Picture> picture;
picture = Picture::Create(dart_picture, UIDartState::CreateGPUObject(
display_list_builder_->Build()));
picture = Picture::Create(dart_picture, display_list_builder_->Build());
display_list_builder_ = nullptr;
canvas_->Invalidate();

View File

@@ -78,10 +78,13 @@ std::shared_ptr<DlColorSource> SceneShader::shader(DlImageSampling sampling) {
// TODO(bdero): Gather the mutation log and include it in the scene color
// source.
return std::make_shared<DlSceneColorSource>(scene_node_->node_,
camera_transform_.IsIdentity()
? DefaultCameraTransform()
: camera_transform_);
auto source = std::make_shared<DlSceneColorSource>(
scene_node_->node_, camera_transform_.IsIdentity()
? DefaultCameraTransform()
: camera_transform_);
// Just a sanity check, all scene shaders should be thread-safe
FML_DCHECK(source->isUIThreadSafe());
return source;
}
void SceneShader::Dispose() {

View File

@@ -9,7 +9,6 @@
#include "flutter/common/graphics/texture.h"
#include "flutter/display_list/display_list.h"
#include "flutter/flow/skia_gpu_object.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPromiseImageTexture.h"

View File

@@ -11,7 +11,6 @@
#include "flutter/common/settings.h"
#include "flutter/common/task_runners.h"
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/synchronization/waitable_event.h"
@@ -153,17 +152,6 @@ class UIDartState : public tonic::DartState {
// @param[in] message The message to be logged.
void LogMessage(const std::string& tag, const std::string& message) const;
template <class T>
static flutter::SkiaGPUObject<T> CreateGPUObject(sk_sp<T> object) {
if (!object) {
return {};
}
auto* state = UIDartState::Current();
FML_DCHECK(state);
auto queue = state->GetSkiaUnrefQueue();
return {std::move(object), std::move(queue)};
};
UnhandledExceptionCallback unhandled_exception_callback() const {
return unhandled_exception_callback_;
}

View File

@@ -804,13 +804,8 @@ TEST_F(ShellTest, ExternalEmbedderNoThreadMerger) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -935,13 +930,8 @@ TEST_F(ShellTest,
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -981,13 +971,8 @@ TEST_F(ShellTest, OnPlatformViewDestroyDisablesThreadMerger) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -1048,13 +1033,8 @@ TEST_F(ShellTest, OnPlatformViewDestroyAfterMergingThreads) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -1117,13 +1097,8 @@ TEST_F(ShellTest, OnPlatformViewDestroyWhenThreadsAreMerging) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -1185,13 +1160,8 @@ TEST_F(ShellTest,
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
PumpOneFrame(shell.get(), 100, 100, builder);
@@ -1229,13 +1199,8 @@ TEST_F(ShellTest, OnPlatformViewDestroyWithoutRasterThreadMerger) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
PumpOneFrame(shell.get(), 100, 100, builder);
@@ -1295,13 +1260,8 @@ TEST_F(ShellTest, OnPlatformViewDestroyWithStaticThreadMerging) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
PumpOneFrame(shell.get(), 100, 100, builder);
@@ -1341,13 +1301,8 @@ TEST_F(ShellTest, GetUsedThisFrameShouldBeSetBeforeEndFrame) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
PumpOneFrame(shell.get(), 100, 100, builder);
@@ -2083,13 +2038,8 @@ TEST_F(ShellTest, Screenshot) {
RunEngine(shell.get(), std::move(configuration));
LayerTreeBuilder builder = [&](const std::shared_ptr<ContainerLayer>& root) {
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
this->GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(10, 10),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(80, 80), queue}),
false, false);
SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false);
root->Add(display_list_layer);
};
@@ -2441,13 +2391,8 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) {
// 1. Construct a picture and a picture layer to be raster cached.
sk_sp<DisplayList> display_list = MakeSizedDisplayList(10, 10);
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
GetCurrentTaskRunner(), fml::TimeDelta::Zero());
auto display_list_layer = std::make_shared<DisplayListLayer>(
SkPoint::Make(0, 0),
flutter::SkiaGPUObject<DisplayList>(
{MakeSizedDisplayList(100, 100), queue}),
false, false);
SkPoint::Make(0, 0), MakeSizedDisplayList(100, 100), false, false);
display_list_layer->set_paint_bounds(SkRect::MakeWH(100, 100));
// 2. Rasterize the picture and the picture layer in the raster cache.

View File

@@ -36,6 +36,9 @@ class SnapshotController {
virtual ~SnapshotController() = default;
// Note that this image is not guaranteed to be UIThreadSafe and must
// be converted to a DlImageGPU if it is to be handed back to the UI
// thread.
virtual sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize size) = 0;

View File

@@ -120,6 +120,8 @@ sk_sp<DlImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
}));
}
// It is up to the caller to create a DlImageGPU version of this image
// if the result will interact with the UI thread.
return DlImage::Make(result);
}

View File

@@ -227,6 +227,7 @@ FLUTTER_ASSERT_ARC
return nullptr;
}
// This image should not escape local use by this flutter::Texture implementation
return flutter::DlImage::Make(skImage);
}
@@ -272,6 +273,8 @@ FLUTTER_ASSERT_ARC
if (!skImage) {
return nullptr;
}
// This image should not escape local use by this flutter::Texture implementation
return flutter::DlImage::Make(skImage);
}

View File

@@ -101,6 +101,7 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture(
return nullptr;
}
// This image should not escape local use by EmbedderExternalTextureGL
return DlImage::Make(std::move(image));
}

View File

@@ -100,6 +100,7 @@ sk_sp<DlImage> EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id,
FML_LOG(ERROR) << "Could not create external texture: " << texture_id;
}
// This image should not escape local use by EmbedderExternalTextureMetal
return DlImage::Make(std::move(image));
}