[Impeller] DlAiksCanvas as a DlCanvas wrapper for impeller::Canvas (flutter/engine#45131)

This is a reland of https://github.com/flutter/engine/pull/44248

Fixes https://github.com/flutter/flutter/issues/132416

Changes from last time:

- The `drawPoints` benchmark was failing to render anything meaningful because of an error in `AiksLayer` that resulted in an infinitely sized bounding rectangle poisoning the bounds with `NaN` (this happens, for example, with a `drawPaint` call, which that benchmark happens to use). Added a test covering this and filed https://github.com/flutter/flutter/issues/132770 to explore ways to avoid this in the future.
- There was a bug in `DlAiksCanvas::SaveLayer` where a `nullptr` `paint` but non-`nullptr` `backdrop` was failing to actually save the layer. This resulted in incorrect rendering.
- There was a bug in `impeller::Canvas::DrawPicture` that resulted in incorrect stencil depth counting. That was fixed separately by @bdero, but was the cause of incorrect rendering in some Wonderous screens.
- I've added a simple implementation for `AiksLayer::IsReplacing`. It does not currently compare as deeply as the `DisplayListLayer` version potentially does, but it is good enough to avoid the regression noted in https://github.com/flutter/flutter/issues/132071. That regression was on a benchmark that greatly benefits from partial repaint. With the new implementation, it still gains partial repaint where it previously did not. There is more work that can be done here, filed https://github.com/flutter/flutter/issues/133361 to track that work.

I merged but did not fully integrate the `DisplayListBuilder`/`CanvasToReceiver` work that @flar has done. I have a local experiment with that, but would prefer to see this land and run through the device lab so we get some better comparison numbers for which one performs better.
This commit is contained in:
Dan Field
2023-08-25 22:37:28 -07:00
committed by GitHub
parent 4ece6251d3
commit e9b2008748
85 changed files with 2621 additions and 430 deletions

View File

@@ -32,6 +32,7 @@
../../../flutter/display_list/benchmarking/dl_complexity_unittests.cc
../../../flutter/display_list/display_list_unittests.cc
../../../flutter/display_list/dl_color_unittests.cc
../../../flutter/display_list/dl_op_spy_unittests.cc
../../../flutter/display_list/dl_paint_unittests.cc
../../../flutter/display_list/dl_vertices_unittests.cc
../../../flutter/display_list/effects/dl_color_filter_unittests.cc
@@ -54,6 +55,7 @@
../../../flutter/flow/frame_timings_recorder_unittests.cc
../../../flutter/flow/gl_context_switch_unittests.cc
../../../flutter/flow/instrumentation_unittests.cc
../../../flutter/flow/layers/aiks_layer_unittests.cc
../../../flutter/flow/layers/backdrop_filter_layer_unittests.cc
../../../flutter/flow/layers/checkerboard_layertree_unittests.cc
../../../flutter/flow/layers/clip_path_layer_unittests.cc
@@ -219,7 +221,6 @@
../../../flutter/runtime/type_conversions_unittests.cc
../../../flutter/shell/common/animator_unittests.cc
../../../flutter/shell/common/context_options_unittests.cc
../../../flutter/shell/common/dl_op_spy_unittests.cc
../../../flutter/shell/common/engine_unittests.cc
../../../flutter/shell/common/fixtures
../../../flutter/shell/common/input_events_unittests.cc

View File

@@ -735,6 +735,8 @@ ORIGIN: ../../../flutter/display_list/dl_op_recorder.cc + ../../../flutter/LICEN
ORIGIN: ../../../flutter/display_list/dl_op_recorder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_op_records.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_op_records.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_op_spy.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_op_spy.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_paint.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_paint.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/display_list/dl_sampling_options.h + ../../../flutter/LICENSE
@@ -791,6 +793,8 @@ ORIGIN: ../../../flutter/flow/instrumentation.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/instrumentation.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layer_snapshot_store.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layer_snapshot_store.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layers/aiks_layer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layers/aiks_layer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/flow/layers/cacheable_layer.cc + ../../../flutter/LICENSE
@@ -1163,6 +1167,8 @@ ORIGIN: ../../../flutter/impeller/core/texture_descriptor.cc + ../../../flutter/
ORIGIN: ../../../flutter/impeller/core/texture_descriptor.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/vertex_buffer.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/core/vertex_buffer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/display_list/dl_aiks_canvas.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/display_list/dl_aiks_canvas.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/display_list/dl_dispatcher.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/display_list/dl_dispatcher.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/display_list/dl_image_impeller.cc + ../../../flutter/LICENSE
@@ -2243,8 +2249,6 @@ ORIGIN: ../../../flutter/shell/common/display.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/display.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/display_manager.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/display_manager.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/dl_op_spy.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/dl_op_spy.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/engine.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/engine.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/common/pipeline.cc + ../../../flutter/LICENSE
@@ -3481,6 +3485,8 @@ FILE: ../../../flutter/display_list/dl_op_recorder.cc
FILE: ../../../flutter/display_list/dl_op_recorder.h
FILE: ../../../flutter/display_list/dl_op_records.cc
FILE: ../../../flutter/display_list/dl_op_records.h
FILE: ../../../flutter/display_list/dl_op_spy.cc
FILE: ../../../flutter/display_list/dl_op_spy.h
FILE: ../../../flutter/display_list/dl_paint.cc
FILE: ../../../flutter/display_list/dl_paint.h
FILE: ../../../flutter/display_list/dl_sampling_options.h
@@ -3537,6 +3543,8 @@ FILE: ../../../flutter/flow/instrumentation.cc
FILE: ../../../flutter/flow/instrumentation.h
FILE: ../../../flutter/flow/layer_snapshot_store.cc
FILE: ../../../flutter/flow/layer_snapshot_store.h
FILE: ../../../flutter/flow/layers/aiks_layer.cc
FILE: ../../../flutter/flow/layers/aiks_layer.h
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.cc
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.h
FILE: ../../../flutter/flow/layers/cacheable_layer.cc
@@ -3909,6 +3917,8 @@ FILE: ../../../flutter/impeller/core/texture_descriptor.cc
FILE: ../../../flutter/impeller/core/texture_descriptor.h
FILE: ../../../flutter/impeller/core/vertex_buffer.cc
FILE: ../../../flutter/impeller/core/vertex_buffer.h
FILE: ../../../flutter/impeller/display_list/dl_aiks_canvas.cc
FILE: ../../../flutter/impeller/display_list/dl_aiks_canvas.h
FILE: ../../../flutter/impeller/display_list/dl_dispatcher.cc
FILE: ../../../flutter/impeller/display_list/dl_dispatcher.h
FILE: ../../../flutter/impeller/display_list/dl_image_impeller.cc
@@ -4994,8 +5004,6 @@ FILE: ../../../flutter/shell/common/display.cc
FILE: ../../../flutter/shell/common/display.h
FILE: ../../../flutter/shell/common/display_manager.cc
FILE: ../../../flutter/shell/common/display_manager.h
FILE: ../../../flutter/shell/common/dl_op_spy.cc
FILE: ../../../flutter/shell/common/dl_op_spy.h
FILE: ../../../flutter/shell/common/engine.cc
FILE: ../../../flutter/shell/common/engine.h
FILE: ../../../flutter/shell/common/pipeline.cc

View File

@@ -43,6 +43,8 @@ source_set("display_list") {
"dl_op_recorder.h",
"dl_op_records.cc",
"dl_op_records.h",
"dl_op_spy.cc",
"dl_op_spy.h",
"dl_paint.cc",
"dl_paint.h",
"dl_sampling_options.h",
@@ -111,6 +113,7 @@ if (enable_unittests) {
"benchmarking/dl_complexity_unittests.cc",
"display_list_unittests.cc",
"dl_color_unittests.cc",
"dl_op_spy_unittests.cc",
"dl_paint_unittests.cc",
"dl_vertices_unittests.cc",
"effects/dl_color_filter_unittests.cc",

View File

@@ -33,7 +33,7 @@ DisplayList::DisplayList(DlStorage&& storage,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
sk_sp<const DlRTree> rtree)
std::shared_ptr<const DlRTree> rtree)
: storage_(std::move(storage)),
op_count_(op_count),
nested_byte_count_(nested_byte_count),

View File

@@ -234,7 +234,7 @@ class DisplayList : public SkRefCnt {
const SkRect& bounds() const { return bounds_; }
bool has_rtree() const { return rtree_ != nullptr; }
sk_sp<const DlRTree> rtree() const { return rtree_; }
std::shared_ptr<const DlRTree> rtree() const { return rtree_; }
bool Equals(const DisplayList* other) const;
bool Equals(const DisplayList& other) const { return Equals(&other); }
@@ -300,7 +300,7 @@ class DisplayList : public SkRefCnt {
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
sk_sp<const DlRTree> rtree);
std::shared_ptr<const DlRTree> rtree);
static uint32_t next_unique_id();
@@ -317,7 +317,7 @@ class DisplayList : public SkRefCnt {
const bool is_ui_thread_safe_;
const bool modifies_transparent_black_;
const sk_sp<const DlRTree> rtree_;
const std::shared_ptr<const DlRTree> rtree_;
void Dispatch(DlOpReceiver& ctx,
uint8_t* ptr,

View File

@@ -1932,7 +1932,7 @@ TEST_F(DisplayListTest, FlatDrawPointsProducesBounds) {
}
}
static void test_rtree(const sk_sp<const DlRTree>& rtree,
static void test_rtree(const std::shared_ptr<const DlRTree>& rtree,
const SkRect& query,
std::vector<SkRect> expected_rects,
const std::vector<int>& expected_indices) {

View File

@@ -18,6 +18,10 @@
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkTextBlob.h"
namespace impeller {
struct Picture;
} // namespace impeller
namespace flutter {
// The primary class used to express rendering operations in the
@@ -59,7 +63,12 @@ class DlCanvas {
const DlImageFilter* backdrop = nullptr) = 0;
virtual void Restore() = 0;
virtual int GetSaveCount() const = 0;
virtual void RestoreToCount(int restore_count) = 0;
virtual void RestoreToCount(int restore_count) {
FML_DCHECK(restore_count <= GetSaveCount());
while (restore_count < GetSaveCount() && GetSaveCount() > 1) {
Restore();
}
}
virtual void Translate(SkScalar tx, SkScalar ty) = 0;
virtual void Scale(SkScalar sx, SkScalar sy) = 0;
@@ -199,6 +208,9 @@ class DlCanvas {
const DlPaint* paint = nullptr) = 0;
virtual void DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity = SK_Scalar1) = 0;
virtual void DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity = SK_Scalar1) = 0;
virtual void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
SkScalar x,
SkScalar y,

View File

@@ -811,6 +811,12 @@ void DlCanvasToReceiver::DrawDisplayList(const sk_sp<DisplayList> display_list,
: OpResult::kPreservesTransparency,
display_list->can_apply_group_opacity());
}
void DlCanvasToReceiver::DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity) {
FML_LOG(ERROR) << "Cannot draw Impeller Picture in to a a display list.";
FML_DCHECK(false);
}
void DlCanvasToReceiver::DrawTextBlob(const sk_sp<SkTextBlob>& blob,
SkScalar x,
SkScalar y,

View File

@@ -10,6 +10,10 @@
#include "flutter/display_list/dl_op_receiver.h"
#include "flutter/fml/macros.h"
namespace impeller {
struct Picture;
}
namespace flutter {
class DlCanvasReceiver : public DlOpReceiver {
@@ -337,6 +341,10 @@ class DlCanvasToReceiver : public virtual DlCanvas, //
void DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity = SK_Scalar1) override;
// |DlCanvas|
void DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity = SK_Scalar1) override;
// |DlCanvas|
void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
SkScalar x,
SkScalar y,

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/common/dl_op_spy.h"
#include "flutter/display_list/dl_op_spy.h"
namespace flutter {

View File

@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_
#define FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_
#pragma once
#include "flutter/display_list/dl_op_receiver.h"
#include "flutter/display_list/utils/dl_receiver_utils.h"
@@ -105,5 +104,3 @@ class DlOpSpy final : public virtual DlOpReceiver,
};
} // namespace flutter
#endif // FLUTTER_DISPLAY_LIST_DL_OP_SPY_H_

View File

@@ -4,7 +4,7 @@
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/display_list_builder.h"
#include "flutter/shell/common/dl_op_spy.h"
#include "flutter/display_list/dl_op_spy.h"
#include "flutter/testing/testing.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkRSXform.h"

View File

@@ -25,7 +25,7 @@ namespace flutter {
/// - Query for a set of non-overlapping rectangles that are joined
/// from the original rectangles that intersect a query rect
/// @see |searchAndConsolidateRects|
class DlRTree : public SkRefCnt {
class DlRTree {
private:
static constexpr int kMaxChildren = 11;

View File

@@ -294,6 +294,13 @@ void DlSkCanvasAdapter::DrawAtlas(const sk_sp<DlImage>& atlas,
ToSk(sampling), cullRect, sk_paint());
}
void DlSkCanvasAdapter::DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity) {
FML_LOG(ERROR) << "Cannot draw Impeller Picture in to a Skia canvas.";
FML_DCHECK(false);
}
void DlSkCanvasAdapter::DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity) {
const int restore_count = delegate_->getSaveCount();

View File

@@ -136,6 +136,9 @@ class DlSkCanvasAdapter final : public virtual DlCanvas {
DlImageSampling sampling,
const SkRect* cullRect,
const DlPaint* paint = nullptr) override;
void DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity = SK_Scalar1) override;
void DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity = SK_Scalar1) override;
void DrawTextBlob(const sk_sp<SkTextBlob>& blob,

View File

@@ -125,10 +125,11 @@ SkRect RTreeBoundsAccumulator::bounds() const {
return accumulator.bounds();
}
sk_sp<DlRTree> RTreeBoundsAccumulator::rtree() const {
std::shared_ptr<DlRTree> RTreeBoundsAccumulator::rtree() const {
FML_DCHECK(saved_offsets_.empty());
return sk_make_sp<DlRTree>(rects_.data(), rects_.size(), rect_indices_.data(),
[](int id) { return id >= 0; });
return std::make_shared<DlRTree>(rects_.data(), rects_.size(),
rect_indices_.data(),
[](int id) { return id >= 0; });
}
} // namespace flutter

View File

@@ -87,7 +87,7 @@ class BoundsAccumulator {
virtual SkRect bounds() const = 0;
virtual sk_sp<DlRTree> rtree() const = 0;
virtual std::shared_ptr<DlRTree> rtree() const = 0;
};
class RectBoundsAccumulator final : public virtual BoundsAccumulator {
@@ -111,7 +111,7 @@ class RectBoundsAccumulator final : public virtual BoundsAccumulator {
Type type() const override { return Type::kRect; }
sk_sp<DlRTree> rtree() const override { return nullptr; }
std::shared_ptr<DlRTree> rtree() const override { return nullptr; }
private:
class AccumulationRect {
@@ -150,7 +150,7 @@ class RTreeBoundsAccumulator final : public virtual BoundsAccumulator {
SkRect bounds() const override;
sk_sp<DlRTree> rtree() const override;
std::shared_ptr<DlRTree> rtree() const override;
Type type() const override { return Type::kRTree; }

View File

@@ -22,6 +22,8 @@ source_set("flow") {
"instrumentation.h",
"layer_snapshot_store.cc",
"layer_snapshot_store.h",
"layers/aiks_layer.cc",
"layers/aiks_layer.h",
"layers/backdrop_filter_layer.cc",
"layers/backdrop_filter_layer.h",
"layers/cacheable_layer.cc",
@@ -187,6 +189,11 @@ if (enable_unittests) {
"//third_party/skia",
]
if (impeller_supports_rendering) {
sources += [ "layers/aiks_layer_unittests.cc" ]
deps += [ "//flutter/impeller" ]
}
if (!defined(defines)) {
defines = []
}

View File

@@ -3,9 +3,45 @@
// found in the LICENSE file.
#include "flutter/flow/embedded_views.h"
#include "flutter/display_list/dl_op_spy.h"
namespace flutter {
#if IMPELLER_SUPPORTS_RENDERING
ImpellerEmbedderViewSlice::ImpellerEmbedderViewSlice(SkRect view_bounds) {
canvas_ = std::make_unique<impeller::DlAiksCanvas>(
/*bounds=*/view_bounds);
}
DlCanvas* ImpellerEmbedderViewSlice::canvas() {
return canvas_ ? canvas_.get() : nullptr;
}
void ImpellerEmbedderViewSlice::end_recording() {
picture_ =
std::make_shared<impeller::Picture>(canvas_->EndRecordingAsPicture());
canvas_.reset();
}
std::list<SkRect> ImpellerEmbedderViewSlice::searchNonOverlappingDrawnRects(
const SkRect& query) const {
FML_DCHECK(picture_);
return picture_->rtree->searchAndConsolidateRects(query);
}
void ImpellerEmbedderViewSlice::render_into(DlCanvas* canvas) {
canvas->DrawImpellerPicture(picture_);
}
bool ImpellerEmbedderViewSlice::recording_ended() {
return canvas_ == nullptr;
}
bool ImpellerEmbedderViewSlice::renders_anything() {
return !picture_->rtree->bounds().isEmpty();
}
#endif // IMPELLER_SUPPORTS_RENDERING
DisplayListEmbedderViewSlice::DisplayListEmbedderViewSlice(SkRect view_bounds) {
builder_ = std::make_unique<DisplayListBuilder>(
/*bounds=*/view_bounds,
@@ -30,10 +66,6 @@ void DisplayListEmbedderViewSlice::render_into(DlCanvas* canvas) {
canvas->DrawDisplayList(display_list_);
}
void DisplayListEmbedderViewSlice::dispatch(DlOpReceiver& receiver) {
display_list_->Dispatch(receiver);
}
bool DisplayListEmbedderViewSlice::is_empty() {
return display_list_->bounds().isEmpty();
}
@@ -42,6 +74,12 @@ bool DisplayListEmbedderViewSlice::recording_ended() {
return builder_ == nullptr;
}
bool DisplayListEmbedderViewSlice::renders_anything() {
DlOpSpy dl_op_spy;
display_list_->Dispatch(dl_op_spy);
return dl_op_spy.did_draw() && !is_empty();
}
void ExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
const std::shared_ptr<impeller::AiksContext>& aiks_context,

View File

@@ -340,11 +340,33 @@ class EmbedderViewSlice {
virtual std::list<SkRect> searchNonOverlappingDrawnRects(
const SkRect& query) const = 0;
virtual void render_into(DlCanvas* canvas) = 0;
virtual bool recording_ended() = 0;
virtual bool renders_anything() = 0;
};
#if IMPELLER_SUPPORTS_RENDERING
class ImpellerEmbedderViewSlice : public EmbedderViewSlice {
public:
explicit ImpellerEmbedderViewSlice(SkRect view_bounds);
~ImpellerEmbedderViewSlice() override = default;
DlCanvas* canvas() override;
void end_recording() override;
std::list<SkRect> searchNonOverlappingDrawnRects(
const SkRect& query) const override;
void render_into(DlCanvas* canvas) override;
bool recording_ended() override;
bool renders_anything() override;
private:
std::unique_ptr<impeller::DlAiksCanvas> canvas_;
std::shared_ptr<const impeller::Picture> picture_;
};
#endif
class DisplayListEmbedderViewSlice : public EmbedderViewSlice {
public:
DisplayListEmbedderViewSlice(SkRect view_bounds);
explicit DisplayListEmbedderViewSlice(SkRect view_bounds);
~DisplayListEmbedderViewSlice() override = default;
DlCanvas* canvas() override;
@@ -352,9 +374,9 @@ class DisplayListEmbedderViewSlice : public EmbedderViewSlice {
std::list<SkRect> searchNonOverlappingDrawnRects(
const SkRect& query) const override;
void render_into(DlCanvas* canvas) override;
void dispatch(DlOpReceiver& receiver);
bool is_empty();
bool recording_ended();
bool recording_ended() override;
bool renders_anything() override;
private:
std::unique_ptr<DisplayListBuilder> builder_;

View File

@@ -0,0 +1,67 @@
// 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/layers/aiks_layer.h"
#include <utility>
namespace flutter {
AiksLayer::AiksLayer(const SkPoint& offset,
const std::shared_ptr<const impeller::Picture>& picture)
: offset_(offset), picture_(picture) {
#if IMPELLER_SUPPORTS_RENDERING
if (picture_) {
auto bounds = picture_->pass->GetElementsCoverage(std::nullopt)
.value_or(impeller::Rect())
.Shift({offset_.x(), offset_.y()});
bounds_ = SkRect::MakeLTRB(bounds.GetLeft(), bounds.GetTop(),
bounds.GetRight(), bounds.GetBottom());
}
#endif
}
bool AiksLayer::IsReplacing(DiffContext* context, const Layer* layer) const {
auto old_layer = layer->as_aiks_layer();
return old_layer != nullptr && offset_ == old_layer->offset_ &&
old_layer->picture_ == picture_;
}
void AiksLayer::Diff(DiffContext* context, const Layer* old_layer) {
DiffContext::AutoSubtreeRestore subtree(context);
context->PushTransform(SkMatrix::Translate(offset_.x(), offset_.y()));
context->AddLayerBounds(bounds_);
context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
}
void AiksLayer::Preroll(PrerollContext* frame) {
// There is no opacity peepholing to do here because Impeller handles that
// in the Entities, and this layer will never participate in raster caching.
FML_DCHECK(!frame->raster_cache);
set_paint_bounds(bounds_);
}
void AiksLayer::Paint(PaintContext& context) const {
FML_DCHECK(needs_painting(context));
auto mutator = context.state_stack.save();
mutator.translate(offset_.x(), offset_.y());
FML_DCHECK(!context.raster_cache);
SkScalar opacity = context.state_stack.outstanding_opacity();
if (context.enable_leaf_layer_tracing) {
// TODO(dnfield): Decide if we need to capture this for Impeller.
// We can't do this the same way as on the Skia backend, because Impeller
// does not expose primitives for flushing things down to the GPU without
// also allocating a texture.
// https://github.com/flutter/flutter/issues/131941
FML_LOG(ERROR) << "Leaf layer tracing unsupported for Impeller.";
}
context.canvas->DrawImpellerPicture(picture_, opacity);
}
} // namespace flutter

View File

@@ -0,0 +1,44 @@
// 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.
#pragma once
#include <memory>
#include "flutter/flow/layers/layer.h"
#if IMPELLER_SUPPORTS_RENDERING
#include "impeller/aiks/picture.h" // nogncheck
#else // IMPELLER_SUPPORTS_RENDERING
namespace impeller {
struct Picture;
} // namespace impeller
#endif // !IMPELLER_SUPPORTS_RENDERING
namespace flutter {
class AiksLayer : public Layer {
public:
AiksLayer(const SkPoint& offset,
const std::shared_ptr<const impeller::Picture>& picture);
const AiksLayer* as_aiks_layer() const override { return this; }
bool IsReplacing(DiffContext* context, const Layer* layer) const override;
void Diff(DiffContext* context, const Layer* old_layer) override;
void Preroll(PrerollContext* frame) override;
void Paint(PaintContext& context) const override;
private:
SkPoint offset_;
SkRect bounds_;
std::shared_ptr<const impeller::Picture> picture_;
FML_DISALLOW_COPY_AND_ASSIGN(AiksLayer);
};
} // namespace flutter

View File

@@ -0,0 +1,49 @@
// 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.
#define FML_USED_ON_EMBEDDER
#include "flow/layers/layer.h"
#include "flutter/flow/layers/aiks_layer.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/testing/layer_test.h"
#include "impeller/aiks/canvas.h"
namespace flutter {
namespace testing {
using AiksLayerTest = LayerTest;
TEST_F(AiksLayerTest, InfiniteBounds) {
impeller::Canvas canvas;
canvas.DrawPaint(impeller::Paint{.color = impeller::Color::Red()});
auto picture =
std::make_shared<const impeller::Picture>(canvas.EndRecordingAsPicture());
AiksLayer layer(SkPoint::Make(0.0f, 0.0f), picture);
const FixedRefreshRateStopwatch unused_stopwatch;
LayerStateStack state_stack;
state_stack.set_preroll_delegate(kGiantRect, SkMatrix::I());
PrerollContext preroll_context{
.state_stack = state_stack,
.raster_time = unused_stopwatch,
.ui_time = unused_stopwatch,
.texture_registry = nullptr,
};
PaintContext context{
// clang-format off
.state_stack = state_stack,
.raster_time = unused_stopwatch,
.ui_time = unused_stopwatch,
.texture_registry = nullptr,
// clang-format on
};
EXPECT_FALSE(layer.needs_painting(context));
layer.Preroll(&preroll_context);
EXPECT_TRUE(layer.needs_painting(context));
}
} // namespace testing
} // namespace flutter

View File

@@ -41,6 +41,7 @@ class MockLayer;
} // namespace testing
class ContainerLayer;
class AiksLayer;
class DisplayListLayer;
class PerformanceOverlayLayer;
class TextureLayer;
@@ -255,6 +256,7 @@ class Layer {
return RasterCacheKeyID(unique_id_, RasterCacheKeyType::kLayer);
}
virtual const ContainerLayer* as_container_layer() const { return nullptr; }
virtual const AiksLayer* as_aiks_layer() const { return nullptr; }
virtual const DisplayListLayer* as_display_list_layer() const {
return nullptr;
}

View File

@@ -155,6 +155,69 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
}
}
std::shared_ptr<const impeller::Picture> LayerTree::FlattenToImpellerPicture(
const SkRect& bounds,
const std::shared_ptr<TextureRegistry>& texture_registry) {
#if IMPELLER_SUPPORTS_RENDERING
TRACE_EVENT0("flutter", "LayerTree::FlattenToImpellerPicture");
impeller::DlAiksCanvas canvas(bounds);
const FixedRefreshRateStopwatch unused_stopwatch;
LayerStateStack preroll_state_stack;
// No root surface transformation. So assume identity.
preroll_state_stack.set_preroll_delegate(bounds);
PrerollContext preroll_context{
// clang-format off
.raster_cache = nullptr,
.gr_context = nullptr,
.view_embedder = nullptr,
.state_stack = preroll_state_stack,
.dst_color_space = nullptr,
.surface_needs_readback = false,
.raster_time = unused_stopwatch,
.ui_time = unused_stopwatch,
.texture_registry = texture_registry,
// clang-format on
};
LayerStateStack paint_state_stack;
paint_state_stack.set_delegate(&canvas);
PaintContext paint_context = {
// clang-format off
.state_stack = paint_state_stack,
.canvas = &canvas,
.gr_context = nullptr,
.dst_color_space = nullptr,
.view_embedder = nullptr,
.raster_time = unused_stopwatch,
.ui_time = unused_stopwatch,
.texture_registry = texture_registry,
.raster_cache = nullptr,
.layer_snapshot_store = nullptr,
.enable_leaf_layer_tracing = false,
// clang-format on
};
// Even if we don't have a root layer, we still need to create an empty
// picture.
if (root_layer_) {
root_layer_->Preroll(&preroll_context);
// The needs painting flag may be set after the preroll. So check it after.
if (root_layer_->needs_painting(paint_context)) {
root_layer_->Paint(paint_context);
}
}
return std::make_shared<const impeller::Picture>(
canvas.EndRecordingAsPicture());
#else // IMPELLER_SUPPORTS_RENDERING
return nullptr;
#endif // !IMPELLER_SUPPORTS_RENDERING
}
sk_sp<DisplayList> LayerTree::Flatten(
const SkRect& bounds,
const std::shared_ptr<TextureRegistry>& texture_registry,

View File

@@ -54,6 +54,10 @@ class LayerTree {
const std::shared_ptr<TextureRegistry>& texture_registry = nullptr,
GrDirectContext* gr_context = nullptr);
std::shared_ptr<const impeller::Picture> FlattenToImpellerPicture(
const SkRect& bounds,
const std::shared_ptr<TextureRegistry>& texture_registry);
Layer* root_layer() const { return root_layer_.get(); }
const SkISize& frame_size() const { return frame_size_; }

View File

@@ -27,7 +27,7 @@ namespace flutter {
RasterCacheResult::RasterCacheResult(sk_sp<DlImage> image,
const SkRect& logical_rect,
const char* type,
sk_sp<const DlRTree> rtree)
std::shared_ptr<const DlRTree> rtree)
: image_(std::move(image)),
logical_rect_(logical_rect),
flow_(type),
@@ -77,7 +77,7 @@ RasterCache::RasterCache(size_t access_threshold,
/// @note Procedure doesn't copy all closures.
std::unique_ptr<RasterCacheResult> RasterCache::Rasterize(
const RasterCache::Context& context,
sk_sp<const DlRTree> rtree,
std::shared_ptr<const DlRTree> rtree,
const std::function<void(DlCanvas*)>& draw_function,
const std::function<void(DlCanvas*, const SkRect& rect)>& draw_checkerboard)
const {
@@ -119,7 +119,7 @@ bool RasterCache::UpdateCacheEntry(
const RasterCacheKeyID& id,
const Context& raster_cache_context,
const std::function<void(DlCanvas*)>& render_function,
sk_sp<const DlRTree> rtree) const {
std::shared_ptr<const DlRTree> rtree) const {
RasterCacheKey key = RasterCacheKey(id, raster_cache_context.matrix);
Entry& entry = cache_[key];
if (!entry.image) {

View File

@@ -29,7 +29,7 @@ class RasterCacheResult {
RasterCacheResult(sk_sp<DlImage> image,
const SkRect& logical_rect,
const char* type,
sk_sp<const DlRTree> rtree = nullptr);
std::shared_ptr<const DlRTree> rtree = nullptr);
virtual ~RasterCacheResult() = default;
@@ -49,7 +49,7 @@ class RasterCacheResult {
sk_sp<DlImage> image_;
SkRect logical_rect_;
fml::tracing::TraceFlow flow_;
sk_sp<const DlRTree> rtree_;
std::shared_ptr<const DlRTree> rtree_;
};
class Layer;
@@ -129,7 +129,7 @@ class RasterCache {
std::unique_ptr<RasterCacheResult> Rasterize(
const RasterCache::Context& context,
sk_sp<const DlRTree> rtree,
std::shared_ptr<const DlRTree> rtree,
const std::function<void(DlCanvas*)>& draw_function,
const std::function<void(DlCanvas*, const SkRect& rect)>&
draw_checkerboard) const;
@@ -244,7 +244,7 @@ class RasterCache {
bool UpdateCacheEntry(const RasterCacheKeyID& id,
const Context& raster_cache_context,
const std::function<void(DlCanvas*)>& render_function,
sk_sp<const DlRTree> rtree = nullptr) const;
std::shared_ptr<const DlRTree> rtree = nullptr) const;
private:
struct Entry {

View File

@@ -5,6 +5,7 @@
#include "flutter/flow/surface_frame.h"
#include <limits>
#include <memory>
#include <utility>
#include "flutter/fml/logging.h"
@@ -31,9 +32,13 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
canvas_ = &adapter_;
} else if (display_list_fallback) {
FML_DCHECK(!frame_size.isEmpty());
dl_builder_ =
sk_make_sp<DisplayListBuilder>(SkRect::Make(frame_size), true);
canvas_ = dl_builder_.get();
#if IMPELLER_SUPPORTS_RENDERING
aiks_canvas_ =
std::make_shared<impeller::DlAiksCanvas>(SkRect::Make(frame_size));
canvas_ = aiks_canvas_.get();
#else
FML_DCHECK(false);
#endif // IMPELLER_SUPPORTS_RENDERING
}
}
@@ -72,9 +77,14 @@ bool SurfaceFrame::PerformSubmit() {
return false;
}
sk_sp<DisplayList> SurfaceFrame::BuildDisplayList() {
TRACE_EVENT0("impeller", "SurfaceFrame::BuildDisplayList");
return dl_builder_ ? dl_builder_->Build() : nullptr;
std::shared_ptr<const impeller::Picture> SurfaceFrame::GetImpellerPicture() {
#if IMPELLER_SUPPORTS_RENDERING
return std::make_shared<impeller::Picture>(
aiks_canvas_->EndRecordingAsPicture());
#else
FML_DCHECK(false);
return nullptr;
#endif // IMPELLER_SUPPORTS_RENDERING
}
} // namespace flutter

View File

@@ -14,6 +14,14 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/time/time_point.h"
#if IMPELLER_SUPPORTS_RENDERING
#include "impeller/display_list/dl_aiks_canvas.h" // nogncheck
#else // IMPELLER_SUPPORTS_RENDERINGƒ
namespace impeller {
class DlAiksCanvas;
} // namespace impeller
#endif // !IMPELLER_SUPPORTS_RENDERING
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
@@ -97,14 +105,14 @@ class SurfaceFrame {
}
const SubmitInfo& submit_info() const { return submit_info_; }
sk_sp<DisplayList> BuildDisplayList();
std::shared_ptr<const impeller::Picture> GetImpellerPicture();
private:
bool submitted_ = false;
DlSkCanvasAdapter adapter_;
sk_sp<DisplayListBuilder> dl_builder_;
sk_sp<SkSurface> surface_;
std::shared_ptr<impeller::DlAiksCanvas> aiks_canvas_;
DlCanvas* canvas_ = nullptr;
FramebufferInfo framebuffer_info_;
SubmitInfo submit_info_;

View File

@@ -22,6 +22,7 @@ TEST(FlowTest, SurfaceFrameDoesNotSubmitInDtor) {
surface_frame.reset();
}
#if IMPELLER_SUPPORTS_RENDERING
TEST(FlowTest, SurfaceFrameDoesNotHaveEmptyCanvas) {
SurfaceFrame::FramebufferInfo framebuffer_info;
SurfaceFrame frame(
@@ -33,5 +34,6 @@ TEST(FlowTest, SurfaceFrameDoesNotHaveEmptyCanvas) {
EXPECT_FALSE(frame.Canvas()->GetLocalClipBounds().isEmpty());
EXPECT_FALSE(frame.Canvas()->QuickReject(SkRect::MakeLTRB(10, 10, 50, 50)));
}
#endif // IMPELLER_SUPPORTS_RENDERING
} // namespace flutter

View File

@@ -30,6 +30,7 @@ impeller_component("aiks") {
"../base",
"../entity",
"../geometry",
"//flutter/display_list",
]
deps = [ "//flutter/fml" ]

View File

@@ -8,6 +8,7 @@
#include <optional>
#include <utility>
#include "display_list/geometry/dl_rtree.h"
#include "flutter/fml/logging.h"
#include "impeller/aiks/paint_pass_delegate.h"
#include "impeller/entity/contents/atlas_contents.h"
@@ -19,6 +20,7 @@
#include "impeller/entity/contents/vertices_contents.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/geometry/path_builder.h"
#include "include/core/SkRect.h"
namespace impeller {
@@ -403,7 +405,7 @@ void Canvas::RestoreClip() {
GetCurrentPass().AddEntity(entity);
}
void Canvas::DrawPoints(std::vector<Point> points,
void Canvas::DrawPoints(const std::vector<Point>& points,
Scalar radius,
const Paint& paint,
PointStyle point_style) {
@@ -416,7 +418,7 @@ void Canvas::DrawPoints(std::vector<Point> points,
entity.SetStencilDepth(GetStencilDepth());
entity.SetBlendMode(paint.blend_mode);
entity.SetContents(paint.WithFilters(paint.CreateContentsForGeometry(
Geometry::MakePointField(std::move(points), radius,
Geometry::MakePointField(points, radius,
/*round=*/point_style == PointStyle::kRound))));
GetCurrentPass().AddEntity(entity);
@@ -502,6 +504,19 @@ Picture Canvas::EndRecordingAsPicture() {
Picture picture;
picture.pass = std::move(base_pass_);
std::vector<SkRect> rects;
picture.pass->IterateAllEntities([&rects](const Entity& entity) {
auto coverage = entity.GetCoverage();
if (coverage.has_value()) {
rects.push_back(SkRect::MakeLTRB(coverage->GetLeft(), coverage->GetTop(),
coverage->GetRight(),
coverage->GetBottom()));
}
return true;
});
picture.rtree =
std::make_shared<flutter::DlRTree>(rects.data(), rects.size());
Reset();
Initialize(initial_cull_rect_);

View File

@@ -64,6 +64,8 @@ class Canvas {
~Canvas();
std::optional<Rect> BaseCullRect() const { return initial_cull_rect_; }
void Save();
void SaveLayer(const Paint& paint,
@@ -108,7 +110,7 @@ class Canvas {
void DrawCircle(Point center, Scalar radius, const Paint& paint);
void DrawPoints(std::vector<Point>,
void DrawPoints(const std::vector<Point>&,
Scalar radius,
const Paint& paint,
PointStyle point_style);

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <optional>
#include "display_list/geometry/dl_rtree.h"
#include "flutter/fml/macros.h"
#include "impeller/aiks/aiks_context.h"
#include "impeller/aiks/image.h"
@@ -18,6 +19,7 @@ namespace impeller {
struct Picture {
std::unique_ptr<EntityPass> pass;
std::shared_ptr<const flutter::DlRTree> rtree;
std::optional<Snapshot> Snapshot(AiksContext& context);

View File

@@ -22,6 +22,8 @@ impeller_component("skia_conversions") {
impeller_component("display_list") {
sources = [
"dl_aiks_canvas.cc",
"dl_aiks_canvas.h",
"dl_dispatcher.cc",
"dl_dispatcher.h",
"dl_image_impeller.cc",

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,242 @@
// 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.
#pragma once
#include "flutter/display_list/dl_canvas.h"
#include "flutter/display_list/geometry/dl_rtree.h"
#include "flutter/display_list/utils/dl_bounds_accumulator.h"
#include "flutter/fml/macros.h"
#include "impeller/aiks/canvas.h"
#include "impeller/aiks/paint.h"
#include "impeller/display_list/skia_conversions.h"
namespace impeller {
class DlAiksCanvas final : public flutter::DlCanvas {
public:
DlAiksCanvas();
explicit DlAiksCanvas(const SkRect& cull_rect, bool prepare_tree = false);
explicit DlAiksCanvas(const SkIRect& cull_rect, bool prepare_rtree = false);
~DlAiksCanvas();
Picture EndRecordingAsPicture();
// |DlCanvas|
SkISize GetBaseLayerSize() const override;
// |DlCanvas|
SkImageInfo GetImageInfo() const override;
// |DlCanvas|
void Save() override;
// |DlCanvas|
void SaveLayer(const SkRect* bounds,
const flutter::DlPaint* paint = nullptr,
const flutter::DlImageFilter* backdrop = nullptr) override;
// |DlCanvas|
void Restore() override;
// |DlCanvas|
int GetSaveCount() const override { return canvas_.GetSaveCount(); }
// |DlCanvas|
void RestoreToCount(int restore_count) override;
// |DlCanvas|
void Translate(SkScalar tx, SkScalar ty) override;
// |DlCanvas|
void Scale(SkScalar sx, SkScalar sy) override;
// |DlCanvas|
void Rotate(SkScalar degrees) override;
// |DlCanvas|
void Skew(SkScalar sx, SkScalar sy) override;
// clang-format off
// 2x3 2D affine subset of a 4x4 transform in row major order
// |DlCanvas|
void Transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt,
SkScalar myx, SkScalar myy, SkScalar myt) override;
// full 4x4 transform in row major order
// |DlCanvas|
void TransformFullPerspective(
SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt,
SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt,
SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt,
SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override;
// clang-format on
// |DlCanvas|
void TransformReset() override;
// |DlCanvas|
void Transform(const SkMatrix* matrix) override;
// |DlCanvas|
void Transform(const SkM44* matrix44) override;
// |DlCanvas|
void SetTransform(const SkMatrix* matrix) override {
TransformReset();
Transform(matrix);
}
// |DlCanvas|
void SetTransform(const SkM44* matrix44) override {
TransformReset();
Transform(matrix44);
}
using flutter::DlCanvas::Transform;
/// Returns the 4x4 full perspective transform representing all transform
/// operations executed so far in this DisplayList within the enclosing
/// save stack.
// |DlCanvas|
SkM44 GetTransformFullPerspective() const override {
return skia_conversions::ToSkM44(canvas_.GetCurrentTransformation());
}
/// Returns the 3x3 partial perspective transform representing all transform
/// operations executed so far in this DisplayList within the enclosing
/// save stack.
// |DlCanvas|
SkMatrix GetTransform() const override {
return skia_conversions::ToSkMatrix(canvas_.GetCurrentTransformation());
}
// |DlCanvas|
void ClipRect(const SkRect& rect,
ClipOp clip_op = ClipOp::kIntersect,
bool is_aa = false) override;
// |DlCanvas|
void ClipRRect(const SkRRect& rrect,
ClipOp clip_op = ClipOp::kIntersect,
bool is_aa = false) override;
// |DlCanvas|
void ClipPath(const SkPath& path,
ClipOp clip_op = ClipOp::kIntersect,
bool is_aa = false) override;
/// Conservative estimate of the bounds of all outstanding clip operations
/// measured in the coordinate space within which this DisplayList will
/// be rendered.
// |DlCanvas|
SkRect GetDestinationClipBounds() const override {
auto rect = canvas_.GetCurrentLocalCullingBounds().value_or(Rect::Giant());
return SkRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), rect.GetRight(),
rect.GetBottom());
}
/// Conservative estimate of the bounds of all outstanding clip operations
/// transformed into the local coordinate space in which currently
/// recorded rendering operations are interpreted.
// |DlCanvas|
SkRect GetLocalClipBounds() const override {
auto rect = canvas_.GetCurrentLocalCullingBounds().value_or(Rect::Giant());
return SkRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), rect.GetRight(),
rect.GetBottom());
}
/// Return true iff the supplied bounds are easily shown to be outside
/// of the current clip bounds. This method may conservatively return
/// false if it cannot make the determination.
// |DlCanvas|
bool QuickReject(const SkRect& bounds) const override;
// |DlCanvas|
void DrawPaint(const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawColor(flutter::DlColor color, flutter::DlBlendMode mode) override;
// |DlCanvas|
void DrawLine(const SkPoint& p0,
const SkPoint& p1,
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawRect(const SkRect& rect, const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawOval(const SkRect& bounds, const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawCircle(const SkPoint& center,
SkScalar radius,
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawRRect(const SkRRect& rrect, const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawDRRect(const SkRRect& outer,
const SkRRect& inner,
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawPath(const SkPath& path, const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawArc(const SkRect& bounds,
SkScalar start,
SkScalar sweep,
bool useCenter,
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawPoints(PointMode mode,
uint32_t count,
const SkPoint pts[],
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawVertices(const flutter::DlVertices* vertices,
flutter::DlBlendMode mode,
const flutter::DlPaint& paint) override;
using flutter::DlCanvas::DrawVertices;
// |DlCanvas|
void DrawImage(const sk_sp<flutter::DlImage>& image,
const SkPoint point,
flutter::DlImageSampling sampling,
const flutter::DlPaint* paint = nullptr) override;
// |DlCanvas|
void DrawImageRect(
const sk_sp<flutter::DlImage>& image,
const SkRect& src,
const SkRect& dst,
flutter::DlImageSampling sampling,
const flutter::DlPaint* paint = nullptr,
SrcRectConstraint constraint = SrcRectConstraint::kFast) override;
using flutter::DlCanvas::DrawImageRect;
// |DlCanvas|
void DrawImageNine(const sk_sp<flutter::DlImage>& image,
const SkIRect& center,
const SkRect& dst,
flutter::DlFilterMode filter,
const flutter::DlPaint* paint = nullptr) override;
// |DlCanvas|
void DrawAtlas(const sk_sp<flutter::DlImage>& atlas,
const SkRSXform xform[],
const SkRect tex[],
const flutter::DlColor colors[],
int count,
flutter::DlBlendMode mode,
flutter::DlImageSampling sampling,
const SkRect* cullRect,
const flutter::DlPaint* paint = nullptr) override;
// |DlCanvas|
void DrawDisplayList(const sk_sp<flutter::DisplayList> display_list,
SkScalar opacity = SK_Scalar1) override;
// |DlCanvas|
void DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity = SK_Scalar1) override;
// |DlCanvas|
void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
SkScalar x,
SkScalar y,
const flutter::DlPaint& paint) override;
// |DlCanvas|
void DrawShadow(const SkPath& path,
const flutter::DlColor color,
const SkScalar elevation,
bool transparent_occluder,
SkScalar dpr) override;
// |DlCanvas|
void Flush() override {}
private:
Canvas canvas_;
std::unique_ptr<flutter::BoundsAccumulator> accumulator_;
FML_DISALLOW_COPY_AND_ASSIGN(DlAiksCanvas);
};
} // namespace impeller

View File

@@ -7,12 +7,15 @@
#include "display_list/dl_color.h"
#include "impeller/core/formats.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/geometry/point.h"
#include "impeller/geometry/rect.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorType.h"
#include "third_party/skia/include/core/SkM44.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkRRect.h"
@@ -46,5 +49,29 @@ Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob);
std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type);
constexpr SkM44 ToSkM44(const Matrix& matrix) {
// SkM44 construction is in row major order (even though it stores the data in
// column major).
// clang-format off
return SkM44(
matrix.vec[0].x, matrix.vec[1].x, matrix.vec[2].x, matrix.vec[3].x,
matrix.vec[0].y, matrix.vec[1].y, matrix.vec[2].y, matrix.vec[3].y,
matrix.vec[0].z, matrix.vec[1].z, matrix.vec[2].z, matrix.vec[3].z,
matrix.vec[0].w, matrix.vec[1].w, matrix.vec[2].w, matrix.vec[3].w
);
// clang-format on
}
constexpr SkMatrix ToSkMatrix(const Matrix& matrix) {
// SkMatrix is in row major order.
// clang-format off
return SkMatrix::MakeAll(
matrix.vec[0].x, matrix.vec[1].x, matrix.vec[3].x,
matrix.vec[0].y, matrix.vec[1].y, matrix.vec[3].y,
matrix.vec[0].w, matrix.vec[1].w, matrix.vec[3].w
);
/// clang-format on
}
} // namespace skia_conversions
} // namespace impeller

View File

@@ -127,6 +127,9 @@ std::optional<Rect> EntityPass::GetElementsCoverage(
if (!coverage.has_value()) {
continue;
}
if (coverage->IsMaximum()) {
return coverage;
}
result = result->Union(coverage.value());
}
return result;

View File

@@ -31,7 +31,6 @@ class EntityPass {
/// When the element is a child `EntityPass`, it may be rendered to an
/// offscreen texture and converted into an `Entity` that draws the texture
/// into the current pass, or its children may be collapsed into the current
///
/// `EntityPass`. Elements are converted to Entities in
/// `GetEntityForElement()`.
using Element = std::variant<Entity, std::unique_ptr<EntityPass>>;

View File

@@ -116,10 +116,11 @@ std::unique_ptr<Geometry> Geometry::MakeFillPath(
return std::make_unique<FillPathGeometry>(path, inner_rect);
}
std::unique_ptr<Geometry> Geometry::MakePointField(std::vector<Point> points,
Scalar radius,
bool round) {
return std::make_unique<PointFieldGeometry>(std::move(points), radius, round);
std::unique_ptr<Geometry> Geometry::MakePointField(
const std::vector<Point>& points,
Scalar radius,
bool round) {
return std::make_unique<PointFieldGeometry>(points, radius, round);
}
std::unique_ptr<Geometry> Geometry::MakeStrokePath(const Path& path,

View File

@@ -72,9 +72,8 @@ class Geometry {
static std::unique_ptr<Geometry> MakeRect(Rect rect);
static std::unique_ptr<Geometry> MakePointField(std::vector<Point> points,
Scalar radius,
bool round);
static std::unique_ptr<Geometry>
MakePointField(const std::vector<Point>& points, Scalar radius, bool round);
virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
const Entity& entity,

View File

@@ -9,10 +9,10 @@
namespace impeller {
PointFieldGeometry::PointFieldGeometry(std::vector<Point> points,
PointFieldGeometry::PointFieldGeometry(const std::vector<Point>& points,
Scalar radius,
bool round)
: points_(std::move(points)), radius_(radius), round_(round) {}
: points_(points), radius_(radius), round_(round) {}
PointFieldGeometry::~PointFieldGeometry() = default;

View File

@@ -10,7 +10,9 @@ namespace impeller {
class PointFieldGeometry : public Geometry {
public:
PointFieldGeometry(std::vector<Point> points, Scalar radius, bool round);
PointFieldGeometry(const std::vector<Point>& points,
Scalar radius,
bool round);
~PointFieldGeometry();

View File

@@ -72,6 +72,11 @@ struct TRect {
return TRect::MakeLTRB(left, top, right, bottom);
}
constexpr static TRect Giant() {
// See flutter::kGiantRect.
return TRect::MakeLTRB(-1E9, -1E9, 1E9, 1E9);
}
constexpr static TRect MakeMaximum() {
return TRect::MakeLTRB(-std::numeric_limits<Type>::infinity(),
-std::numeric_limits<Type>::infinity(),

View File

@@ -20,7 +20,7 @@ namespace impeller {
/// quality blurs (with exponentially diminishing returns for the same sigma
/// input). Making this value any lower results in a noticable loss of
/// quality in the blur.
constexpr static float kKernelRadiusPerSigma = 1.73205080757;
constexpr static float kKernelRadiusPerSigma = 1.73205080757f;
struct Radius;
@@ -29,7 +29,7 @@ struct Radius;
/// the filter input. In other words, this determines how wide the
/// distribution stretches.
struct Sigma {
Scalar sigma = 0.0;
Scalar sigma = 0.0f;
constexpr Sigma() = default;
@@ -45,7 +45,7 @@ struct Sigma {
/// relationship with `Sigma`. See `kKernelRadiusPerSigma` for
/// details on how this relationship works.
struct Radius {
Scalar radius = 0.0;
Scalar radius = 0.0f;
constexpr Radius() = default;

View File

@@ -88,13 +88,13 @@ static sk_sp<DlImage> CreateDeferredImage(
bool impeller,
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner,
fml::RefPtr<SkiaUnrefQueue> unref_queue) {
#if IMPELLER_SUPPORTS_RENDERING
if (impeller) {
return DlDeferredImageGPUImpeller::Make(std::move(layer_tree),
std::move(snapshot_delegate),
std::move(raster_task_runner));
raster_task_runner);
}
#endif // IMPELLER_SUPPORTS_RENDERING
@@ -121,8 +121,7 @@ void Scene::RasterizeToImage(uint32_t width,
auto image = CanvasImage::Create();
auto dl_image = CreateDeferredImage(
dart_state->IsImpellerEnabled(), BuildLayerTree(width, height),
std::move(snapshot_delegate), std::move(raster_task_runner),
std::move(unref_queue));
std::move(snapshot_delegate), raster_task_runner, std::move(unref_queue));
image->set_image(dl_image);
image->AssociateWithDartWrapper(raw_image_handle);
}

View File

@@ -4,6 +4,7 @@
#include "flutter/lib/ui/compositing/scene_builder.h"
#include "flutter/flow/layers/aiks_layer.h"
#include "flutter/flow/layers/backdrop_filter_layer.h"
#include "flutter/flow/layers/clip_path_layer.h"
#include "flutter/flow/layers/clip_rect_layer.h"
@@ -226,6 +227,15 @@ void SceneBuilder::addPicture(double dx,
SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)), picture->display_list(),
!!(hints & 1), !!(hints & 2));
AddLayer(std::move(layer));
return;
}
auto impeller_picture = picture->impeller_picture();
if (impeller_picture) {
auto layer = std::make_unique<flutter::AiksLayer>(
SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)),
std::move(impeller_picture));
AddLayer(std::move(layer));
}
}

View File

@@ -6,7 +6,7 @@
#include <cmath>
#include "flutter/display_list/display_list_builder.h"
#include "flutter/display_list/dl_canvas.h"
#include "flutter/lib/ui/floating_point.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/image_filter.h"
@@ -38,18 +38,18 @@ void Canvas::Create(Dart_Handle wrapper,
fml::MakeRefCounted<Canvas>(recorder->BeginRecording(
SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
SafeNarrow(bottom))));
FML_DCHECK(canvas->dl_canvas_);
recorder->set_canvas(canvas);
canvas->AssociateWithDartWrapper(wrapper);
}
Canvas::Canvas(sk_sp<DisplayListBuilder> builder)
: display_list_builder_(std::move(builder)) {}
Canvas::Canvas(DlCanvas* canvas) : dl_canvas_(canvas) {}
Canvas::~Canvas() {}
void Canvas::save() {
if (display_list_builder_) {
builder()->Save();
if (dl_canvas_) {
dl_canvas_->Save();
}
}
@@ -58,12 +58,12 @@ void Canvas::saveLayerWithoutBounds(Dart_Handle paint_objects,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
const DlPaint* save_paint = paint.paint(dl_paint, kSaveLayerWithPaintFlags);
FML_DCHECK(save_paint);
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
builder()->SaveLayer(nullptr, save_paint);
dl_canvas_->SaveLayer(nullptr, save_paint);
}
}
@@ -78,65 +78,65 @@ void Canvas::saveLayer(double left,
FML_DCHECK(paint.isNotNull());
SkRect bounds = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
SafeNarrow(right), SafeNarrow(bottom));
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
const DlPaint* save_paint = paint.paint(dl_paint, kSaveLayerWithPaintFlags);
FML_DCHECK(save_paint);
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
builder()->SaveLayer(&bounds, save_paint);
dl_canvas_->SaveLayer(&bounds, save_paint);
}
}
void Canvas::restore() {
if (display_list_builder_) {
builder()->Restore();
if (dl_canvas_) {
dl_canvas_->Restore();
}
}
int Canvas::getSaveCount() {
if (display_list_builder_) {
return builder()->GetSaveCount();
if (dl_canvas_) {
return dl_canvas_->GetSaveCount();
} else {
return 0;
}
}
void Canvas::restoreToCount(int count) {
if (display_list_builder_ && count < getSaveCount()) {
builder()->RestoreToCount(count);
if (dl_canvas_ && count < getSaveCount()) {
dl_canvas_->RestoreToCount(count);
}
}
void Canvas::translate(double dx, double dy) {
if (display_list_builder_) {
builder()->Translate(SafeNarrow(dx), SafeNarrow(dy));
if (dl_canvas_) {
dl_canvas_->Translate(SafeNarrow(dx), SafeNarrow(dy));
}
}
void Canvas::scale(double sx, double sy) {
if (display_list_builder_) {
builder()->Scale(SafeNarrow(sx), SafeNarrow(sy));
if (dl_canvas_) {
dl_canvas_->Scale(SafeNarrow(sx), SafeNarrow(sy));
}
}
void Canvas::rotate(double radians) {
if (display_list_builder_) {
builder()->Rotate(SafeNarrow(radians) * 180.0f / static_cast<float>(M_PI));
if (dl_canvas_) {
dl_canvas_->Rotate(SafeNarrow(radians) * 180.0f / static_cast<float>(M_PI));
}
}
void Canvas::skew(double sx, double sy) {
if (display_list_builder_) {
builder()->Skew(SafeNarrow(sx), SafeNarrow(sy));
if (dl_canvas_) {
dl_canvas_->Skew(SafeNarrow(sx), SafeNarrow(sy));
}
}
void Canvas::transform(const tonic::Float64List& matrix4) {
// The Float array stored by Dart Matrix4 is in column-major order
// Both DisplayList and SkM44 constructor take row-major matrix order
if (display_list_builder_) {
if (dl_canvas_) {
// clang-format off
builder()->TransformFullPerspective(
dl_canvas_->TransformFullPerspective(
SafeNarrow(matrix4[ 0]), SafeNarrow(matrix4[ 4]), SafeNarrow(matrix4[ 8]), SafeNarrow(matrix4[12]),
SafeNarrow(matrix4[ 1]), SafeNarrow(matrix4[ 5]), SafeNarrow(matrix4[ 9]), SafeNarrow(matrix4[13]),
SafeNarrow(matrix4[ 2]), SafeNarrow(matrix4[ 6]), SafeNarrow(matrix4[10]), SafeNarrow(matrix4[14]),
@@ -146,8 +146,8 @@ void Canvas::transform(const tonic::Float64List& matrix4) {
}
void Canvas::getTransform(Dart_Handle matrix4_handle) {
if (display_list_builder_) {
SkM44 sk_m44 = builder()->GetTransformFullPerspective();
if (dl_canvas_) {
SkM44 sk_m44 = dl_canvas_->GetTransformFullPerspective();
SkScalar m44_values[16];
// The Float array stored by Dart Matrix4 is in column-major order
sk_m44.getColMajor(m44_values);
@@ -164,17 +164,18 @@ void Canvas::clipRect(double left,
double bottom,
DlCanvas::ClipOp clipOp,
bool doAntiAlias) {
if (display_list_builder_) {
builder()->ClipRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
SafeNarrow(right), SafeNarrow(bottom)),
clipOp, doAntiAlias);
if (dl_canvas_) {
dl_canvas_->ClipRect(
SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
SafeNarrow(bottom)),
clipOp, doAntiAlias);
}
}
void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) {
if (display_list_builder_) {
builder()->ClipRRect(rrect.sk_rrect, DlCanvas::ClipOp::kIntersect,
doAntiAlias);
if (dl_canvas_) {
dl_canvas_->ClipRRect(rrect.sk_rrect, DlCanvas::ClipOp::kIntersect,
doAntiAlias);
}
}
@@ -184,16 +185,16 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) {
ToDart("Canvas.clipPath called with non-genuine Path."));
return;
}
if (display_list_builder_) {
builder()->ClipPath(path->path(), DlCanvas::ClipOp::kIntersect,
doAntiAlias);
if (dl_canvas_) {
dl_canvas_->ClipPath(path->path(), DlCanvas::ClipOp::kIntersect,
doAntiAlias);
}
}
void Canvas::getDestinationClipBounds(Dart_Handle rect_handle) {
if (display_list_builder_) {
if (dl_canvas_) {
auto rect = tonic::Float64List(rect_handle);
SkRect bounds = builder()->GetDestinationClipBounds();
SkRect bounds = dl_canvas_->GetDestinationClipBounds();
rect[0] = bounds.fLeft;
rect[1] = bounds.fTop;
rect[2] = bounds.fRight;
@@ -202,9 +203,9 @@ void Canvas::getDestinationClipBounds(Dart_Handle rect_handle) {
}
void Canvas::getLocalClipBounds(Dart_Handle rect_handle) {
if (display_list_builder_) {
if (dl_canvas_) {
auto rect = tonic::Float64List(rect_handle);
SkRect bounds = builder()->GetLocalClipBounds();
SkRect bounds = dl_canvas_->GetLocalClipBounds();
rect[0] = bounds.fLeft;
rect[1] = bounds.fTop;
rect[2] = bounds.fRight;
@@ -213,8 +214,8 @@ void Canvas::getLocalClipBounds(Dart_Handle rect_handle) {
}
void Canvas::drawColor(SkColor color, DlBlendMode blend_mode) {
if (display_list_builder_) {
builder()->DrawColor(color, blend_mode);
if (dl_canvas_) {
dl_canvas_->DrawColor(color, blend_mode);
}
}
@@ -227,12 +228,12 @@ void Canvas::drawLine(double x1,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawLineFlags);
builder()->DrawLine(SkPoint::Make(SafeNarrow(x1), SafeNarrow(y1)),
SkPoint::Make(SafeNarrow(x2), SafeNarrow(y2)),
dl_paint);
dl_canvas_->DrawLine(SkPoint::Make(SafeNarrow(x1), SafeNarrow(y1)),
SkPoint::Make(SafeNarrow(x2), SafeNarrow(y2)),
dl_paint);
}
}
@@ -240,7 +241,7 @@ void Canvas::drawPaint(Dart_Handle paint_objects, Dart_Handle paint_data) {
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawPaintFlags);
std::shared_ptr<const DlImageFilter> filter = dl_paint.getImageFilter();
@@ -249,7 +250,7 @@ void Canvas::drawPaint(Dart_Handle paint_objects, Dart_Handle paint_data) {
// present that cannot be replaced by an SkColorFilter.
TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)");
}
builder()->DrawPaint(dl_paint);
dl_canvas_->DrawPaint(dl_paint);
}
}
@@ -262,12 +263,13 @@ void Canvas::drawRect(double left,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawRectFlags);
builder()->DrawRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
SafeNarrow(right), SafeNarrow(bottom)),
dl_paint);
dl_canvas_->DrawRect(
SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
SafeNarrow(bottom)),
dl_paint);
}
}
@@ -277,10 +279,10 @@ void Canvas::drawRRect(const RRect& rrect,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawRRectFlags);
builder()->DrawRRect(rrect.sk_rrect, dl_paint);
dl_canvas_->DrawRRect(rrect.sk_rrect, dl_paint);
}
}
@@ -291,10 +293,10 @@ void Canvas::drawDRRect(const RRect& outer,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawDRRectFlags);
builder()->DrawDRRect(outer.sk_rrect, inner.sk_rrect, dl_paint);
dl_canvas_->DrawDRRect(outer.sk_rrect, inner.sk_rrect, dl_paint);
}
}
@@ -307,12 +309,13 @@ void Canvas::drawOval(double left,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawOvalFlags);
builder()->DrawOval(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
SafeNarrow(right), SafeNarrow(bottom)),
dl_paint);
dl_canvas_->DrawOval(
SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
SafeNarrow(bottom)),
dl_paint);
}
}
@@ -324,11 +327,11 @@ void Canvas::drawCircle(double x,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawCircleFlags);
builder()->DrawCircle(SkPoint::Make(SafeNarrow(x), SafeNarrow(y)),
SafeNarrow(radius), dl_paint);
dl_canvas_->DrawCircle(SkPoint::Make(SafeNarrow(x), SafeNarrow(y)),
SafeNarrow(radius), dl_paint);
}
}
@@ -344,12 +347,12 @@ void Canvas::drawArc(double left,
Paint paint(paint_objects, paint_data);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, useCenter //
? kDrawArcWithCenterFlags
: kDrawArcNoCenterFlags);
builder()->DrawArc(
dl_canvas_->DrawArc(
SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right),
SafeNarrow(bottom)),
SafeNarrow(startAngle) * 180.0f / static_cast<float>(M_PI),
@@ -369,10 +372,10 @@ void Canvas::drawPath(const CanvasPath* path,
ToDart("Canvas.drawPath called with non-genuine Path."));
return;
}
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawPathFlags);
builder()->DrawPath(path->path(), dl_paint);
dl_canvas_->DrawPath(path->path(), dl_paint);
}
}
@@ -399,11 +402,11 @@ Dart_Handle Canvas::drawImage(const CanvasImage* image,
}
auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex);
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
const DlPaint* opt_paint = paint.paint(dl_paint, kDrawImageWithPaintFlags);
builder()->DrawImage(dl_image, SkPoint::Make(SafeNarrow(x), SafeNarrow(y)),
sampling, opt_paint);
dl_canvas_->DrawImage(dl_image, SkPoint::Make(SafeNarrow(x), SafeNarrow(y)),
sampling, opt_paint);
}
return Dart_Null();
}
@@ -441,12 +444,12 @@ Dart_Handle Canvas::drawImageRect(const CanvasImage* image,
SkRect dst = SkRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top),
SafeNarrow(dst_right), SafeNarrow(dst_bottom));
auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex);
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
const DlPaint* opt_paint =
paint.paint(dl_paint, kDrawImageRectWithPaintFlags);
builder()->DrawImageRect(dl_image, src, dst, sampling, opt_paint,
DlCanvas::SrcRectConstraint::kFast);
dl_canvas_->DrawImageRect(dl_image, src, dst, sampling, opt_paint,
DlCanvas::SrcRectConstraint::kFast);
}
return Dart_Null();
}
@@ -486,11 +489,11 @@ Dart_Handle Canvas::drawImageNine(const CanvasImage* image,
SkRect dst = SkRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top),
SafeNarrow(dst_right), SafeNarrow(dst_bottom));
auto filter = ImageFilter::FilterModeFromIndex(bitmapSamplingIndex);
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
const DlPaint* opt_paint =
paint.paint(dl_paint, kDrawImageNineWithPaintFlags);
builder()->DrawImageNine(dl_image, icenter, dst, filter, opt_paint);
dl_canvas_->DrawImageNine(dl_image, icenter, dst, filter, opt_paint);
}
return Dart_Null();
}
@@ -501,12 +504,20 @@ void Canvas::drawPicture(Picture* picture) {
ToDart("Canvas.drawPicture called with non-genuine Picture."));
return;
}
if (!dl_canvas_) {
return;
}
if (picture->display_list()) {
if (display_list_builder_) {
builder()->DrawDisplayList(picture->display_list());
}
dl_canvas_->DrawDisplayList(picture->display_list());
} else {
FML_DCHECK(false);
auto impeller_picture = picture->impeller_picture();
if (impeller_picture) {
dl_canvas_->DrawImpellerPicture(impeller_picture);
} else {
FML_DCHECK(false);
}
}
}
@@ -520,7 +531,7 @@ void Canvas::drawPoints(Dart_Handle paint_objects,
"SkPoint doesn't use floats.");
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
switch (point_mode) {
case DlCanvas::PointMode::kPoints:
@@ -533,10 +544,10 @@ void Canvas::drawPoints(Dart_Handle paint_objects,
paint.paint(dl_paint, kDrawPointsAsPolygonFlags);
break;
}
builder()->DrawPoints(point_mode,
points.num_elements() / 2, // SkPoints have 2 floats
reinterpret_cast<const SkPoint*>(points.data()),
dl_paint);
dl_canvas_->DrawPoints(point_mode,
points.num_elements() / 2, // SkPoints have 2 floats
reinterpret_cast<const SkPoint*>(points.data()),
dl_paint);
}
}
@@ -552,10 +563,10 @@ void Canvas::drawVertices(const Vertices* vertices,
return;
}
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
DlPaint dl_paint;
paint.paint(dl_paint, kDrawVerticesFlags);
builder()->DrawVertices(vertices->vertices(), blend_mode, dl_paint);
dl_canvas_->DrawVertices(vertices->vertices(), blend_mode, dl_paint);
}
}
@@ -590,7 +601,7 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects,
auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex);
FML_DCHECK(paint.isNotNull());
if (display_list_builder_) {
if (dl_canvas_) {
tonic::Float32List transforms(transforms_handle);
tonic::Float32List rects(rects_handle);
tonic::Int32List colors(colors_handle);
@@ -598,7 +609,7 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects,
DlPaint dl_paint;
const DlPaint* opt_paint = paint.paint(dl_paint, kDrawAtlasWithPaintFlags);
builder()->DrawAtlas(
dl_canvas_->DrawAtlas(
dl_image, reinterpret_cast<const SkRSXform*>(transforms.data()),
reinterpret_cast<const SkRect*>(rects.data()),
reinterpret_cast<const DlColor*>(colors.data()),
@@ -630,7 +641,7 @@ void Canvas::drawShadow(const CanvasPath* path,
} else {
dpr = static_cast<float>(metrics->device_pixel_ratio);
}
if (display_list_builder_) {
if (dl_canvas_) {
// The DrawShadow mechanism results in non-public operations to be
// performed on the canvas involving an SkDrawShadowRec. Since we
// cannot include the header that defines that structure, we cannot
@@ -638,13 +649,13 @@ void Canvas::drawShadow(const CanvasPath* path,
// that situation we bypass the canvas interface and inject the
// shadow parameters directly into the underlying DisplayList.
// See: https://bugs.chromium.org/p/skia/issues/detail?id=12125
builder()->DrawShadow(path->path(), color, SafeNarrow(elevation),
transparentOccluder, dpr);
dl_canvas_->DrawShadow(path->path(), color, SafeNarrow(elevation),
transparentOccluder, dpr);
}
}
void Canvas::Invalidate() {
display_list_builder_ = nullptr;
dl_canvas_ = nullptr;
if (dart_wrapper()) {
ClearDartWrapper();
}

View File

@@ -186,12 +186,12 @@ class Canvas : public RefCountedDartWrappable<Canvas>, DisplayListOpFlags {
void Invalidate();
DisplayListBuilder* builder() { return display_list_builder_.get(); }
DlCanvas* dl_canvas() { return dl_canvas_; }
private:
explicit Canvas(sk_sp<DisplayListBuilder> builder);
explicit Canvas(DlCanvas* canvas);
sk_sp<DisplayListBuilder> display_list_builder_;
DlCanvas* dl_canvas_;
};
} // namespace flutter

View File

@@ -6,6 +6,7 @@
#include <utility>
#include "display_list_deferred_image_gpu_impeller.h"
#include "flutter/fml/make_copyable.h"
namespace flutter {
@@ -13,22 +14,33 @@ namespace flutter {
sk_sp<DlDeferredImageGPUImpeller> DlDeferredImageGPUImpeller::Make(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner) {
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
return sk_sp<DlDeferredImageGPUImpeller>(new DlDeferredImageGPUImpeller(
DlDeferredImageGPUImpeller::ImageWrapper::Make(
std::move(layer_tree), std::move(snapshot_delegate),
std::move(raster_task_runner))));
raster_task_runner)));
}
sk_sp<DlDeferredImageGPUImpeller> DlDeferredImageGPUImpeller::Make(
sk_sp<DisplayList> display_list,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner) {
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
return sk_sp<DlDeferredImageGPUImpeller>(new DlDeferredImageGPUImpeller(
DlDeferredImageGPUImpeller::ImageWrapper::Make(
std::move(display_list), size, std::move(snapshot_delegate),
std::move(raster_task_runner))));
raster_task_runner)));
}
sk_sp<DlDeferredImageGPUImpeller> DlDeferredImageGPUImpeller::Make(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
return sk_sp<DlDeferredImageGPUImpeller>(new DlDeferredImageGPUImpeller(
DlDeferredImageGPUImpeller::ImageWrapper::Make(
impeller_picture, size, std::move(snapshot_delegate),
raster_task_runner)));
}
DlDeferredImageGPUImpeller::DlDeferredImageGPUImpeller(
@@ -96,22 +108,41 @@ DlDeferredImageGPUImpeller::ImageWrapper::Make(
sk_sp<DisplayList> display_list,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner) {
auto wrapper = std::shared_ptr<ImageWrapper>(new ImageWrapper(
std::move(display_list), size, std::move(snapshot_delegate),
std::move(raster_task_runner)));
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(std::move(display_list), size,
std::move(snapshot_delegate), raster_task_runner));
wrapper->SnapshotDisplayList();
return wrapper;
}
std::shared_ptr<DlDeferredImageGPUImpeller::ImageWrapper>
DlDeferredImageGPUImpeller::ImageWrapper::Make(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
auto wrapper = std::shared_ptr<ImageWrapper>(new ImageWrapper(size));
wrapper->SnapshotPicture(impeller_picture, std::move(snapshot_delegate),
raster_task_runner);
return wrapper;
}
std::shared_ptr<DlDeferredImageGPUImpeller::ImageWrapper>
DlDeferredImageGPUImpeller::ImageWrapper::Make(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner) {
auto wrapper = std::shared_ptr<ImageWrapper>(new ImageWrapper(
nullptr, layer_tree->frame_size(), std::move(snapshot_delegate),
std::move(raster_task_runner)));
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
if (layer_tree) {
auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(layer_tree->frame_size()));
wrapper->SnapshotLayer(std::move(layer_tree), std::move(snapshot_delegate),
raster_task_runner);
return wrapper;
}
auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(sk_sp<DisplayList>(), layer_tree->frame_size(),
std::move(snapshot_delegate), raster_task_runner));
wrapper->SnapshotDisplayList(std::move(layer_tree));
return wrapper;
}
@@ -126,14 +157,84 @@ DlDeferredImageGPUImpeller::ImageWrapper::ImageWrapper(
snapshot_delegate_(std::move(snapshot_delegate)),
raster_task_runner_(std::move(raster_task_runner)) {}
DlDeferredImageGPUImpeller::ImageWrapper::~ImageWrapper() {
DlDeferredImageGPUImpeller::ImageWrapper::ImageWrapper(const SkISize& size)
: size_(size) {}
void DlDeferredImageGPUImpeller::ImageWrapper::SnapshotPicture(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner_, [id = reinterpret_cast<uintptr_t>(this),
texture_registry = std::move(texture_registry_)]() {
if (texture_registry) {
texture_registry->UnregisterContextListener(id);
raster_task_runner,
fml::MakeCopyable([weak_this = weak_from_this(), impeller_picture,
snapshot_delegate = std::move(snapshot_delegate)]() {
TRACE_EVENT0("flutter", "SnapshotPicture (impeller)");
auto wrapper = weak_this.lock();
if (!wrapper) {
return;
}
});
if (!snapshot_delegate) {
return;
}
wrapper->texture_registry_ = snapshot_delegate->GetTextureRegistry();
auto snapshot = snapshot_delegate->MakeRasterSnapshot(impeller_picture,
wrapper->size_);
if (!snapshot) {
std::scoped_lock lock(wrapper->error_mutex_);
wrapper->error_ = "Failed to create snapshot.";
return;
}
wrapper->texture_ = snapshot->impeller_texture();
}));
}
void DlDeferredImageGPUImpeller::ImageWrapper::SnapshotLayer(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner) {
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner,
fml::MakeCopyable([weak_this = weak_from_this(),
layer_tree = std::move(layer_tree),
snapshot_delegate = std::move(snapshot_delegate)]() {
TRACE_EVENT0("flutter", "SnapshotLayer (impeller)");
auto wrapper = weak_this.lock();
if (!wrapper) {
return;
}
if (!snapshot_delegate) {
return;
}
wrapper->texture_registry_ = snapshot_delegate->GetTextureRegistry();
auto impeller_picture = layer_tree->FlattenToImpellerPicture(
SkRect::MakeWH(wrapper->size_.width(), wrapper->size_.height()),
wrapper->texture_registry_);
auto snapshot = snapshot_delegate->MakeRasterSnapshot(impeller_picture,
wrapper->size_);
if (!snapshot) {
std::scoped_lock lock(wrapper->error_mutex_);
wrapper->error_ = "Failed to create snapshot.";
return;
}
wrapper->texture_ = snapshot->impeller_texture();
}));
}
DlDeferredImageGPUImpeller::ImageWrapper::~ImageWrapper() {
if (display_list_) {
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner_,
[id = reinterpret_cast<uintptr_t>(this),
texture_registry = std::move(texture_registry_)]() {
if (texture_registry) {
texture_registry->UnregisterContextListener(id);
}
});
}
}
void DlDeferredImageGPUImpeller::ImageWrapper::OnGrContextCreated() {
@@ -142,8 +243,9 @@ void DlDeferredImageGPUImpeller::ImageWrapper::OnGrContextCreated() {
}
void DlDeferredImageGPUImpeller::ImageWrapper::OnGrContextDestroyed() {
// Impeller textures do not have threading requirements for deletion, and
texture_.reset();
if (display_list_) {
texture_.reset();
}
}
bool DlDeferredImageGPUImpeller::ImageWrapper::isTextureBacked() const {
@@ -152,6 +254,7 @@ bool DlDeferredImageGPUImpeller::ImageWrapper::isTextureBacked() const {
void DlDeferredImageGPUImpeller::ImageWrapper::SnapshotDisplayList(
std::unique_ptr<LayerTree> layer_tree) {
FML_DCHECK(display_list_ || layer_tree);
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner_,
fml::MakeCopyable([weak_this = weak_from_this(),

View File

@@ -20,13 +20,19 @@ class DlDeferredImageGPUImpeller final : public DlImage {
static sk_sp<DlDeferredImageGPUImpeller> Make(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner);
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
static sk_sp<DlDeferredImageGPUImpeller> Make(
sk_sp<DisplayList> display_list,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner);
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
static sk_sp<DlDeferredImageGPUImpeller> Make(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
// |DlImage|
~DlDeferredImageGPUImpeller() override;
@@ -67,12 +73,18 @@ class DlDeferredImageGPUImpeller final : public DlImage {
sk_sp<DisplayList> display_list,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner);
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
static std::shared_ptr<ImageWrapper> Make(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
const SkISize& size,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
static std::shared_ptr<ImageWrapper> Make(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner);
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
bool isTextureBacked() const;
@@ -101,6 +113,18 @@ class DlDeferredImageGPUImpeller final : public DlImage {
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner);
explicit ImageWrapper(const SkISize& size);
void SnapshotPicture(
const std::shared_ptr<const impeller::Picture>& impeller_picture,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
void SnapshotLayer(
std::unique_ptr<LayerTree> layer_tree,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner);
// If a layer tree is provided, it will be flattened during the raster
// thread task spawned by this method. After being flattened into a display
// list, the image wrapper will be updated to hold this display list and the

View File

@@ -145,10 +145,10 @@ const DlPaint* Paint::paint(DlPaint& paint,
paint.setBlendMode(static_cast<DlBlendMode>(blend_mode));
}
if (flags.applies_style()) {
uint32_t style = uint_data[kStyleIndex];
paint.setDrawStyle(static_cast<DlDrawStyle>(style));
}
// if (flags.applies_style()) {
uint32_t style = uint_data[kStyleIndex];
paint.setDrawStyle(static_cast<DlDrawStyle>(style));
// }
if (flags.is_stroked(paint.getDrawStyle())) {
float stroke_width = float_data[kStrokeWidthIndex];

View File

@@ -16,9 +16,6 @@
#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"
#include "third_party/tonic/dart_library_natives.h"
#include "third_party/tonic/dart_persistent_value.h"
#include "third_party/tonic/logging/dart_invoke.h"
@@ -27,48 +24,53 @@ namespace flutter {
IMPLEMENT_WRAPPERTYPEINFO(ui, Picture);
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));
DisplayListOrPicture picture) {
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture));
canvas_picture->AssociateWithDartWrapper(dart_handle);
return canvas_picture;
}
Picture::Picture(sk_sp<DisplayList> display_list)
: display_list_(std::move(display_list)) {}
Picture::Picture(DisplayListOrPicture picture) : picture_(std::move(picture)) {}
Picture::~Picture() = default;
Dart_Handle Picture::toImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
if (!display_list_) {
if (!impeller_picture() && !display_list()) {
return tonic::ToDart("Picture is null");
}
return RasterizeToImage(display_list_, width, height, raw_image_callback);
return RasterizeToImage(width, height, raw_image_callback);
}
void Picture::toImageSync(uint32_t width,
uint32_t height,
Dart_Handle raw_image_handle) {
FML_DCHECK(display_list_);
RasterizeToImageSync(display_list_, width, height, raw_image_handle);
FML_DCHECK(impeller_picture() || display_list());
RasterizeToImageSync(width, height, raw_image_handle);
}
static sk_sp<DlImage> CreateDeferredImage(
bool impeller,
sk_sp<DisplayList> display_list,
const std::shared_ptr<const impeller::Picture>& impeller_picture,
uint32_t width,
uint32_t height,
fml::TaskRunnerAffineWeakPtr<SnapshotDelegate> snapshot_delegate,
fml::RefPtr<fml::TaskRunner> raster_task_runner,
const fml::RefPtr<fml::TaskRunner>& raster_task_runner,
fml::RefPtr<SkiaUnrefQueue> unref_queue) {
#if IMPELLER_SUPPORTS_RENDERING
if (impeller) {
if (display_list) {
return DlDeferredImageGPUImpeller::Make(
std::move(display_list), SkISize::Make(width, height),
std::move(snapshot_delegate), raster_task_runner);
}
FML_DCHECK(impeller_picture);
return DlDeferredImageGPUImpeller::Make(
std::move(display_list), SkISize::Make(width, height),
std::move(snapshot_delegate), std::move(raster_task_runner));
impeller_picture, SkISize::Make(width, height),
std::move(snapshot_delegate), raster_task_runner);
}
#endif // IMPELLER_SUPPORTS_RENDERING
@@ -79,80 +81,58 @@ static sk_sp<DlImage> CreateDeferredImage(
raster_task_runner, std::move(unref_queue));
}
// static
void Picture::RasterizeToImageSync(sk_sp<DisplayList> display_list,
uint32_t width,
void Picture::RasterizeToImageSync(uint32_t width,
uint32_t height,
Dart_Handle raw_image_handle) {
auto* dart_state = UIDartState::Current();
if (!dart_state) {
return;
}
auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
auto unref_queue = dart_state->GetSkiaUnrefQueue();
auto snapshot_delegate = dart_state->GetSnapshotDelegate();
auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
auto image = CanvasImage::Create();
auto dl_image = CreateDeferredImage(
dart_state->IsImpellerEnabled(), std::move(display_list), width, height,
std::move(snapshot_delegate), std::move(raster_task_runner),
dart_state->IsImpellerEnabled(), display_list(), impeller_picture(),
width, height, std::move(snapshot_delegate), raster_task_runner,
std::move(unref_queue));
image->set_image(dl_image);
image->AssociateWithDartWrapper(raw_image_handle);
}
void Picture::dispose() {
display_list_.reset();
picture_ = sk_sp<DisplayList>(nullptr);
ClearDartWrapper();
}
size_t Picture::GetAllocationSize() const {
if (display_list_) {
return display_list_->bytes() + sizeof(Picture);
} else {
return sizeof(Picture);
auto size = sizeof(Picture);
if (display_list()) {
size += display_list()->bytes();
}
// TODO(dnfield): Add support to EntityPass to get its allocation size.
return size;
}
Dart_Handle Picture::RasterizeToImage(const sk_sp<DisplayList>& display_list,
uint32_t width,
Dart_Handle Picture::RasterizeToImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
return DoRasterizeToImage(display_list, nullptr, width, height,
raw_image_callback);
return DoRasterizeToImage(width, height, raw_image_callback);
}
Dart_Handle Picture::RasterizeLayerTreeToImage(
std::unique_ptr<LayerTree> layer_tree,
Dart_Handle raw_image_callback) {
FML_DCHECK(layer_tree != nullptr);
auto frame_size = layer_tree->frame_size();
return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width(),
frame_size.height(), raw_image_callback);
}
Dart_Handle Picture::DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
std::unique_ptr<LayerTree> layer_tree,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
// Either display_list or layer_tree should be provided.
FML_DCHECK((display_list == nullptr) != (layer_tree == nullptr));
if (Dart_IsNull(raw_image_callback) || !Dart_IsClosure(raw_image_callback)) {
return tonic::ToDart("Image callback was invalid");
}
if (width == 0 || height == 0) {
return tonic::ToDart("Image dimensions for scene were invalid.");
}
auto* dart_state = UIDartState::Current();
auto image_callback = std::make_unique<tonic::DartPersistentValue>(
dart_state, raw_image_callback);
auto unref_queue = dart_state->GetSkiaUnrefQueue();
auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
auto unref_queue = dart_state->GetSkiaUnrefQueue();
auto snapshot_delegate = dart_state->GetSnapshotDelegate();
// We can't create an image on this task runner because we don't have a
@@ -161,7 +141,8 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
// raster thread.
auto ui_task =
// The static leak checker gets confused by the use of fml::MakeCopyable.
// The static leak checker gets confused by the use of
// fml::MakeCopyable.
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
fml::MakeCopyable([image_callback = std::move(image_callback),
unref_queue](sk_sp<DlImage> image) mutable {
@@ -199,22 +180,101 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
// Kick things off on the raster rask runner.
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner,
fml::MakeCopyable([ui_task_runner, snapshot_delegate, display_list, width,
height, ui_task,
fml::MakeCopyable([ui_task_runner, snapshot_delegate, ui_task,
layer_tree = std::move(layer_tree)]() mutable {
sk_sp<DlImage> image;
auto display_list = layer_tree->Flatten(
SkRect::MakeXYWH(0, 0, layer_tree->frame_size().width(),
layer_tree->frame_size().height()),
snapshot_delegate->GetTextureRegistry(),
snapshot_delegate->GetGrContext());
image = snapshot_delegate->MakeRasterSnapshot(display_list,
layer_tree->frame_size());
fml::TaskRunner::RunNowOrPostTask(
ui_task_runner, [ui_task, image]() { ui_task(image); });
}));
return Dart_Null();
}
Dart_Handle Picture::DoRasterizeToImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback) {
if (Dart_IsNull(raw_image_callback) || !Dart_IsClosure(raw_image_callback)) {
return tonic::ToDart("Image callback was invalid");
}
if (width == 0 || height == 0) {
return tonic::ToDart("Image dimensions for scene were invalid.");
}
auto* dart_state = UIDartState::Current();
auto image_callback = std::make_unique<tonic::DartPersistentValue>(
dart_state, raw_image_callback);
auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner();
auto unref_queue = dart_state->GetSkiaUnrefQueue();
auto snapshot_delegate = dart_state->GetSnapshotDelegate();
// We can't create an image on this task runner because we don't have a
// graphics context. Even if we did, it would be slow anyway. Also, this
// thread owns the sole reference to the layer tree. So we do it in the
// raster thread.
auto ui_task =
// The static leak checker gets confused by the use of
// fml::MakeCopyable.
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
fml::MakeCopyable([image_callback = std::move(image_callback),
unref_queue](sk_sp<DlImage> image) mutable {
auto dart_state = image_callback->dart_state().lock();
if (!dart_state) {
// The root isolate could have died in the meantime.
return;
}
tonic::DartState::Scope scope(dart_state);
if (!image) {
tonic::DartInvoke(image_callback->Get(), {Dart_Null()});
return;
}
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)});
}
auto dart_image = CanvasImage::Create();
dart_image->set_image(image);
auto* raw_dart_image = tonic::ToDart(dart_image);
// All done!
tonic::DartInvoke(image_callback->Get(), {raw_dart_image});
// image_callback is associated with the Dart isolate and must be
// deleted on the UI thread.
image_callback.reset();
});
// Kick things off on the raster rask runner.
fml::TaskRunner::RunNowOrPostTask(
raster_task_runner,
fml::MakeCopyable([ui_task_runner, snapshot_delegate,
display_list = display_list(),
impeller_picture = impeller_picture(), width, height,
ui_task]() mutable {
auto picture_bounds = SkISize::Make(width, height);
sk_sp<DlImage> image;
if (layer_tree) {
FML_DCHECK(picture_bounds == layer_tree->frame_size());
auto display_list =
layer_tree->Flatten(SkRect::MakeWH(width, height),
snapshot_delegate->GetTextureRegistry(),
snapshot_delegate->GetGrContext());
if (display_list) {
image = snapshot_delegate->MakeRasterSnapshot(display_list,
picture_bounds);
} else {
image = snapshot_delegate->MakeRasterSnapshot(display_list,
FML_DCHECK(impeller_picture);
image = snapshot_delegate->MakeRasterSnapshot(impeller_picture,
picture_bounds);
}

View File

@@ -5,15 +5,29 @@
#ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_H_
#define FLUTTER_LIB_UI_PAINTING_PICTURE_H_
#include <variant>
#include "flutter/display_list/display_list.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "third_party/skia/include/core/SkPicture.h"
#if IMPELLER_SUPPORTS_RENDERING
#include "impeller/aiks/picture.h" // nogncheck
#else // IMPELLER_SUPPORTS_RENDERING
namespace impeller {
struct Picture;
} // namespace impeller
#endif // !IMPELLER_SUPPORTS_RENDERING
namespace flutter {
class Canvas;
using DisplayListOrPicture =
std::variant<sk_sp<DisplayList>, std::shared_ptr<const impeller::Picture>>;
class Picture : public RefCountedDartWrappable<Picture> {
DEFINE_WRAPPERTYPEINFO();
FML_FRIEND_MAKE_REF_COUNTED(Picture);
@@ -21,9 +35,22 @@ class Picture : public RefCountedDartWrappable<Picture> {
public:
~Picture() override;
static fml::RefPtr<Picture> Create(Dart_Handle dart_handle,
sk_sp<DisplayList> display_list);
DisplayListOrPicture picture);
sk_sp<DisplayList> display_list() const { return display_list_; }
const sk_sp<DisplayList> display_list() const {
if (std::holds_alternative<sk_sp<DisplayList>>(picture_)) {
return std::get<sk_sp<DisplayList>>(picture_);
}
return nullptr;
}
std::shared_ptr<const impeller::Picture> impeller_picture() const {
if (std::holds_alternative<std::shared_ptr<const impeller::Picture>>(
picture_)) {
return std::get<std::shared_ptr<const impeller::Picture>>(picture_);
}
return nullptr;
}
Dart_Handle toImage(uint32_t width,
uint32_t height,
@@ -37,34 +64,26 @@ class Picture : public RefCountedDartWrappable<Picture> {
size_t GetAllocationSize() const;
static void RasterizeToImageSync(sk_sp<DisplayList> display_list,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_handle);
static Dart_Handle RasterizeToImage(const sk_sp<DisplayList>& display_list,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback);
static Dart_Handle RasterizeLayerTreeToImage(
std::unique_ptr<LayerTree> layer_tree,
Dart_Handle raw_image_callback);
// Callers may provide either a display list or a layer tree, but not both.
//
// If a layer tree is provided, it will be flattened on the raster thread, and
// picture_bounds should be the layer tree's frame_size().
static Dart_Handle DoRasterizeToImage(const sk_sp<DisplayList>& display_list,
std::unique_ptr<LayerTree> layer_tree,
uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback);
private:
explicit Picture(sk_sp<DisplayList> display_list);
explicit Picture(DisplayListOrPicture picture);
sk_sp<DisplayList> display_list_;
DisplayListOrPicture picture_;
void RasterizeToImageSync(uint32_t width,
uint32_t height,
Dart_Handle raw_image_handle);
Dart_Handle RasterizeToImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback);
Dart_Handle DoRasterizeToImage(uint32_t width,
uint32_t height,
Dart_Handle raw_image_callback);
};
} // namespace flutter

View File

@@ -6,6 +6,7 @@
#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/lib/ui/painting/picture.h"
#include "impeller/display_list/skia_conversions.h" // nogncheck
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_args.h"
#include "third_party/tonic/dart_binding_macros.h"
@@ -25,21 +26,39 @@ PictureRecorder::PictureRecorder() {}
PictureRecorder::~PictureRecorder() {}
sk_sp<DisplayListBuilder> PictureRecorder::BeginRecording(SkRect bounds) {
display_list_builder_ =
sk_make_sp<DisplayListBuilder>(bounds, /*prepare_rtree=*/true);
return display_list_builder_;
DlCanvas* PictureRecorder::BeginRecording(SkRect bounds) {
#if IMPELLER_SUPPORTS_RENDERING
if (UIDartState::Current()->IsImpellerEnabled()) {
dl_aiks_canvas_ = std::make_shared<impeller::DlAiksCanvas>(bounds);
return dl_aiks_canvas_.get();
} else {
#endif // IMPELLER_SUPPORTS_RENDERING
builder_ = sk_make_sp<DisplayListBuilder>(bounds, /*prepare_rtree=*/true);
return builder_.get();
#if IMPELLER_SUPPORTS_RENDERING
}
#endif // IMPELLER_SUPPORTS_RENDERING
}
fml::RefPtr<Picture> PictureRecorder::endRecording(Dart_Handle dart_picture) {
if (!canvas_) {
return nullptr;
}
fml::RefPtr<Picture> picture;
picture = Picture::Create(dart_picture, display_list_builder_->Build());
display_list_builder_ = nullptr;
#if IMPELLER_SUPPORTS_RENDERING
if (UIDartState::Current()->IsImpellerEnabled()) {
picture = Picture::Create(dart_picture,
std::make_shared<impeller::Picture>(
dl_aiks_canvas_->EndRecordingAsPicture()));
dl_aiks_canvas_ = nullptr;
} else {
#endif
picture = Picture::Create(dart_picture, builder_->Build());
builder_ = nullptr;
#if IMPELLER_SUPPORTS_RENDERING
}
#endif // IMPELLER_SUPPORTS_RENDERING
canvas_->Invalidate();
canvas_ = nullptr;

View File

@@ -5,9 +5,19 @@
#ifndef FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
#define FLUTTER_LIB_UI_PAINTING_PICTURE_RECORDER_H_
#include <variant>
#include "flutter/display_list/display_list_builder.h"
#include "flutter/lib/ui/dart_wrapper.h"
#if IMPELLER_SUPPORTS_RENDERING
#include "impeller/display_list/dl_aiks_canvas.h" // nogncheck
#else // IMPELLER_SUPPORTS_RENDERING
namespace impeller {
class DlAiksCanvas;
} // namespace impeller
#endif // !IMPELLER_SUPPORTS_RENDERING
namespace flutter {
class Canvas;
class Picture;
@@ -21,7 +31,7 @@ class PictureRecorder : public RefCountedDartWrappable<PictureRecorder> {
~PictureRecorder() override;
sk_sp<DisplayListBuilder> BeginRecording(SkRect bounds);
DlCanvas* BeginRecording(SkRect bounds);
fml::RefPtr<Picture> endRecording(Dart_Handle dart_picture);
void set_canvas(fml::RefPtr<Canvas> canvas) { canvas_ = std::move(canvas); }
@@ -29,7 +39,8 @@ class PictureRecorder : public RefCountedDartWrappable<PictureRecorder> {
private:
PictureRecorder();
sk_sp<DisplayListBuilder> display_list_builder_;
std::shared_ptr<impeller::DlAiksCanvas> dl_aiks_canvas_;
sk_sp<DisplayListBuilder> builder_;
fml::RefPtr<Canvas> canvas_;
};

View File

@@ -70,6 +70,10 @@ class SnapshotDelegate {
virtual sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize picture_size) = 0;
virtual sk_sp<DlImage> MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize picture_size) = 0;
virtual sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage> image) = 0;
};

View File

@@ -64,9 +64,9 @@ void Paragraph::paint(Canvas* canvas, double x, double y) {
return;
}
DisplayListBuilder* builder = canvas->builder();
if (builder) {
m_paragraph->Paint(builder, x, y);
DlCanvas* dl_canvas = canvas->dl_canvas();
if (dl_canvas) {
m_paragraph->Paint(dl_canvas, x, y);
}
}

View File

@@ -85,8 +85,6 @@ source_set("common") {
"context_options.h",
"display_manager.cc",
"display_manager.h",
"dl_op_spy.cc",
"dl_op_spy.h",
"engine.cc",
"engine.h",
"pipeline.cc",
@@ -294,7 +292,6 @@ if (enable_unittests) {
sources = [
"animator_unittests.cc",
"context_options_unittests.cc",
"dl_op_spy_unittests.cc",
"engine_unittests.cc",
"input_events_unittests.cc",
"persistent_cache_unittests.cc",

View File

@@ -379,6 +379,12 @@ sk_sp<DlImage> Rasterizer::MakeRasterSnapshot(sk_sp<DisplayList> display_list,
return snapshot_controller_->MakeRasterSnapshot(display_list, picture_size);
}
sk_sp<DlImage> Rasterizer::MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize picture_size) {
return snapshot_controller_->MakeRasterSnapshot(picture, picture_size);
}
sk_sp<SkImage> Rasterizer::ConvertToRasterImage(sk_sp<SkImage> image) {
TRACE_EVENT0("flutter", __FUNCTION__);
return snapshot_controller_->ConvertToRasterImage(image);

View File

@@ -534,6 +534,11 @@ class Rasterizer final : public SnapshotDelegate,
sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize picture_size) override;
// |SnapshotDelegate|
sk_sp<DlImage> MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize picture_size) override;
// |SnapshotDelegate|
sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage> image) override;

View File

@@ -42,6 +42,10 @@ class SnapshotController {
virtual sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize size) = 0;
virtual sk_sp<DlImage> MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize size) = 0;
virtual sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage> image) = 0;
protected:

View File

@@ -30,13 +30,36 @@ sk_sp<DlImage> SnapshotControllerImpeller::MakeRasterSnapshot(
return result;
}
sk_sp<DlImage> SnapshotControllerImpeller::MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize size) {
sk_sp<DlImage> result;
if (!picture) {
return result;
}
GetDelegate().GetIsGpuDisabledSyncSwitch()->Execute(
fml::SyncSwitch::Handlers()
.SetIfTrue([&] {
// Do nothing.
})
.SetIfFalse([&] { result = DoMakeRasterSnapshot(*picture, size); }));
return result;
}
sk_sp<DlImage> SnapshotControllerImpeller::DoMakeRasterSnapshot(
const sk_sp<DisplayList>& display_list,
SkISize size) {
TRACE_EVENT0("flutter", __FUNCTION__);
impeller::DlDispatcher dispatcher;
display_list->Dispatch(dispatcher);
impeller::Picture picture = dispatcher.EndRecordingAsPicture();
return DoMakeRasterSnapshot(dispatcher.EndRecordingAsPicture(), size);
}
sk_sp<DlImage> SnapshotControllerImpeller::DoMakeRasterSnapshot(
const impeller::Picture& picture,
SkISize size) {
TRACE_EVENT0("flutter", __FUNCTION__);
auto context = GetDelegate().GetAiksContext();
if (context) {
auto max_size = context->GetContext()

View File

@@ -18,12 +18,19 @@ class SnapshotControllerImpeller : public SnapshotController {
sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize size) override;
sk_sp<DlImage> MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize size) override;
sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage> image) override;
private:
sk_sp<DlImage> DoMakeRasterSnapshot(const sk_sp<DisplayList>& display_list,
SkISize size);
sk_sp<DlImage> DoMakeRasterSnapshot(const impeller::Picture& picture,
SkISize size);
FML_DISALLOW_COPY_AND_ASSIGN(SnapshotControllerImpeller);
};

View File

@@ -137,6 +137,13 @@ sk_sp<DlImage> SnapshotControllerSkia::MakeRasterSnapshot(
});
}
sk_sp<DlImage> SnapshotControllerSkia::MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize size) {
FML_DCHECK(false);
return sk_sp<DlImage>();
}
sk_sp<SkImage> SnapshotControllerSkia::ConvertToRasterImage(
sk_sp<SkImage> image) {
// If the rasterizer does not have a surface with a GrContext, then it will

View File

@@ -18,6 +18,10 @@ class SnapshotControllerSkia : public SnapshotController {
sk_sp<DlImage> MakeRasterSnapshot(sk_sp<DisplayList> display_list,
SkISize size) override;
sk_sp<DlImage> MakeRasterSnapshot(
const std::shared_ptr<const impeller::Picture>& picture,
SkISize size) override;
virtual sk_sp<SkImage> ConvertToRasterImage(sk_sp<SkImage> image) override;
private:

View File

@@ -5,10 +5,9 @@
#include "flutter/shell/gpu/gpu_surface_gl_impeller.h"
#include "flutter/fml/make_copyable.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/renderer/backend/gles/surface_gles.h"
#include "impeller/renderer/renderer.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "flutter/impeller/renderer/backend/gles/surface_gles.h"
#include "flutter/impeller/renderer/renderer.h"
#include "flutter/impeller/typographer/backends/skia/typographer_context_skia.h"
namespace flutter {
@@ -102,27 +101,14 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
return false;
}
auto display_list = surface_frame.BuildDisplayList();
if (!display_list) {
FML_LOG(ERROR) << "Could not build display list for surface frame.";
return false;
}
auto cull_rect =
surface->GetTargetRenderPassDescriptor().GetRenderTargetSize();
impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
display_list->Dispatch(
impeller_dispatcher,
SkIRect::MakeWH(cull_rect.width, cull_rect.height));
auto picture = impeller_dispatcher.EndRecordingAsPicture();
auto picture = surface_frame.GetImpellerPicture();
return renderer->Render(
std::move(surface),
fml::MakeCopyable(
[aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target);
return aiks_context->Render(*picture, render_target);
}));
});

View File

@@ -11,9 +11,8 @@
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/trace_event.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/renderer/backend/metal/surface_mtl.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "flutter/impeller/renderer/backend/metal/surface_mtl.h"
#include "flutter/impeller/typographer/backends/skia/typographer_context_skia.h"
static_assert(!__has_feature(objc_arc), "ARC must be disabled.");
@@ -115,12 +114,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromCAMetalLa
return false;
}
auto display_list = surface_frame.BuildDisplayList();
if (!display_list) {
FML_LOG(ERROR) << "Could not build display list for surface frame.";
return false;
}
if (!disable_partial_repaint_) {
uintptr_t texture = reinterpret_cast<uintptr_t>(last_texture);
@@ -150,17 +143,13 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromCAMetalLa
return surface->Present();
}
impeller::IRect cull_rect = surface->coverage();
SkIRect sk_cull_rect = SkIRect::MakeWH(cull_rect.size.width, cull_rect.size.height);
impeller::DlDispatcher impeller_dispatcher(cull_rect);
display_list->Dispatch(impeller_dispatcher, sk_cull_rect);
auto picture = impeller_dispatcher.EndRecordingAsPicture();
auto picture = surface_frame.GetImpellerPicture();
return renderer->Render(
std::move(surface),
fml::MakeCopyable([aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target);
return aiks_context->Render(*picture, render_target);
}));
});
@@ -213,12 +202,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromMTLTextur
return false;
}
auto display_list = surface_frame.BuildDisplayList();
if (!display_list) {
FML_LOG(ERROR) << "Could not build display list for surface frame.";
return false;
}
if (!disable_partial_repaint_) {
uintptr_t texture_ptr = reinterpret_cast<uintptr_t>(mtl_texture);
@@ -248,17 +231,13 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromMTLTextur
return surface->Present();
}
impeller::IRect cull_rect = surface->coverage();
SkIRect sk_cull_rect = SkIRect::MakeWH(cull_rect.size.width, cull_rect.size.height);
impeller::DlDispatcher impeller_dispatcher(cull_rect);
display_list->Dispatch(impeller_dispatcher, sk_cull_rect);
auto picture = impeller_dispatcher.EndRecordingAsPicture();
auto picture = surface_frame.GetImpellerPicture();
bool render_result =
renderer->Render(std::move(surface),
fml::MakeCopyable([aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target);
return aiks_context->Render(*picture, render_target);
}));
if (!render_result) {
FML_LOG(ERROR) << "Failed to render Impeller frame";

View File

@@ -5,7 +5,7 @@
#include "flutter/shell/gpu/gpu_surface_vulkan_impeller.h"
#include "flutter/fml/make_copyable.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "flutter/impeller/renderer/renderer.h"
#include "impeller/renderer/backend/vulkan/surface_context_vk.h"
#include "impeller/renderer/renderer.h"
#include "impeller/renderer/surface.h"
@@ -69,27 +69,14 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
return false;
}
auto display_list = surface_frame.BuildDisplayList();
if (!display_list) {
FML_LOG(ERROR) << "Could not build display list for surface frame.";
return false;
}
auto cull_rect =
surface->GetTargetRenderPassDescriptor().GetRenderTargetSize();
impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
display_list->Dispatch(
impeller_dispatcher,
SkIRect::MakeWH(cull_rect.width, cull_rect.height));
auto picture = impeller_dispatcher.EndRecordingAsPicture();
auto picture = surface_frame.GetImpellerPicture();
return renderer->Render(
std::move(surface),
fml::MakeCopyable(
[aiks_context, picture = std::move(picture)](
impeller::RenderTarget& render_target) -> bool {
return aiks_context->Render(picture, render_target);
return aiks_context->Render(*picture, render_target);
}));
});

View File

@@ -12,13 +12,15 @@ AndroidExternalViewEmbedder::AndroidExternalViewEmbedder(
const AndroidContext& android_context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::shared_ptr<AndroidSurfaceFactory> surface_factory,
const TaskRunners& task_runners)
const TaskRunners& task_runners,
bool enable_impeller)
: ExternalViewEmbedder(),
android_context_(android_context),
jni_facade_(std::move(jni_facade)),
surface_factory_(std::move(surface_factory)),
surface_pool_(std::make_unique<SurfacePool>()),
task_runners_(task_runners) {}
task_runners_(task_runners),
enable_impeller_(enable_impeller) {}
// |ExternalViewEmbedder|
void AndroidExternalViewEmbedder::PrerollCompositeEmbeddedView(
@@ -29,7 +31,11 @@ void AndroidExternalViewEmbedder::PrerollCompositeEmbeddedView(
SkRect view_bounds = SkRect::Make(frame_size_);
std::unique_ptr<EmbedderViewSlice> view;
view = std::make_unique<DisplayListEmbedderViewSlice>(view_bounds);
if (enable_impeller_) {
view = std::make_unique<ImpellerEmbedderViewSlice>(view_bounds);
} else {
view = std::make_unique<DisplayListEmbedderViewSlice>(view_bounds);
}
slices_.insert_or_assign(view_id, std::move(view));
composition_order_.push_back(view_id);

View File

@@ -32,7 +32,8 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
const AndroidContext& android_context,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
std::shared_ptr<AndroidSurfaceFactory> surface_factory,
const TaskRunners& task_runners);
const TaskRunners& task_runners,
bool enable_impeller);
// |ExternalViewEmbedder|
void PrerollCompositeEmbeddedView(
@@ -123,6 +124,8 @@ class AndroidExternalViewEmbedder final : public ExternalViewEmbedder {
// The number of platform views in the previous frame.
int64_t previous_frame_view_count_;
bool enable_impeller_ = false;
// Destroys the surfaces created from the surface factory.
// This method schedules a task on the platform thread, and waits for
// the task until it completes.

View File

@@ -107,7 +107,7 @@ TaskRunners GetTaskRunnersForFixture() {
TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) {
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, nullptr, nullptr, GetTaskRunnersForFixture());
android_context, nullptr, nullptr, GetTaskRunnersForFixture(), false);
ASSERT_EQ(nullptr, embedder->CompositeEmbeddedView(0));
embedder->PrerollCompositeEmbeddedView(
@@ -123,7 +123,7 @@ TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) {
TEST(AndroidExternalViewEmbedder, CancelFrame) {
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, nullptr, nullptr, GetTaskRunnersForFixture());
android_context, nullptr, nullptr, GetTaskRunnersForFixture(), false);
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>());
@@ -136,7 +136,7 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnPlatformThread) {
auto jni_mock = std::make_shared<JNIMock>();
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
@@ -170,7 +170,7 @@ TEST(AndroidExternalViewEmbedder, RasterizerRunsOnRasterizerThread) {
auto jni_mock = std::make_shared<JNIMock>();
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
@@ -191,7 +191,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) {
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
GetThreadMergerFromPlatformThread(&rasterizer_thread);
@@ -219,7 +219,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRectChangedParams) {
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
GetThreadMergerFromPlatformThread(&rasterizer_thread);
@@ -295,7 +295,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
@@ -494,7 +495,8 @@ TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) {
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
@@ -592,7 +594,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) {
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
@@ -695,7 +698,8 @@ TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) {
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
@@ -735,7 +739,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotCallJNIPlatformThreadOnlyMethods) {
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
// While on the raster thread, don't make JNI calls as these methods can only
// run on the platform thread.
@@ -784,7 +788,8 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
GetThreadMergerFromPlatformThread(&rasterizer_thread);
@@ -872,7 +877,8 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
// ------------------ First frame ------------------ //
{
@@ -930,7 +936,7 @@ TEST(AndroidExternalViewEmbedder, SupportsDynamicThreadMerging) {
auto jni_mock = std::make_shared<JNIMock>();
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
ASSERT_TRUE(embedder->SupportsDynamicThreadMerging());
}
@@ -938,7 +944,7 @@ TEST(AndroidExternalViewEmbedder, DisableThreadMerger) {
auto jni_mock = std::make_shared<JNIMock>();
auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
fml::Thread platform_thread("platform");
auto raster_thread_merger = GetThreadMergerFromRasterThread(&platform_thread);
@@ -994,7 +1000,8 @@ TEST(AndroidExternalViewEmbedder, Teardown) {
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture(),
false);
fml::Thread rasterizer_thread("rasterizer");
auto raster_thread_merger =
GetThreadMergerFromPlatformThread(&rasterizer_thread);
@@ -1037,7 +1044,7 @@ TEST(AndroidExternalViewEmbedder, TeardownDoesNotCallJNIMethod) {
auto android_context =
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, nullptr, GetTaskRunnersForFixture());
*android_context, jni_mock, nullptr, GetTaskRunnersForFixture(), false);
EXPECT_CALL(*jni_mock, FlutterViewDestroyOverlaySurfaces()).Times(0);
embedder->Teardown();

View File

@@ -363,7 +363,8 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() {
std::shared_ptr<ExternalViewEmbedder>
PlatformViewAndroid::CreateExternalViewEmbedder() {
return std::make_shared<AndroidExternalViewEmbedder>(
*android_context_, jni_facade_, surface_factory_, task_runners_);
*android_context_, jni_facade_, surface_factory_, task_runners_,
delegate_.OnPlatformViewGetSettings().enable_impeller);
}
// |PlatformView|

View File

@@ -1310,7 +1310,7 @@ InferExternalViewEmbedderFromArgs(const FlutterCompositor* compositor,
return {std::make_unique<flutter::EmbedderExternalViewEmbedder>(
avoid_backing_store_cache, create_render_target_callback,
present_callback),
present_callback, enable_impeller),
false};
}

View File

@@ -4,13 +4,8 @@
#include "flutter/shell/platform/embedder/embedder_external_view.h"
#include "flutter/display_list/display_list_builder.h"
#include "flow/embedded_views.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/dl_op_spy.h"
#ifdef IMPELLER_SUPPORTS_RENDERING
#include "impeller/display_list/dl_dispatcher.h" // nogncheck
#endif // IMPELLER_SUPPORTS_RENDERING
namespace flutter {
@@ -23,21 +18,37 @@ static SkISize TransformedSurfaceSize(const SkISize& size,
EmbedderExternalView::EmbedderExternalView(
const SkISize& frame_size,
const SkMatrix& surface_transformation)
: EmbedderExternalView(frame_size, surface_transformation, {}, nullptr) {}
const SkMatrix& surface_transformation,
bool enable_impeller)
: EmbedderExternalView(frame_size,
surface_transformation,
{},
nullptr,
enable_impeller) {}
EmbedderExternalView::EmbedderExternalView(
const SkISize& frame_size,
const SkMatrix& surface_transformation,
ViewIdentifier view_identifier,
std::unique_ptr<EmbeddedViewParams> params)
std::unique_ptr<EmbeddedViewParams> params,
bool enable_impeller)
: render_surface_size_(
TransformedSurfaceSize(frame_size, surface_transformation)),
surface_transformation_(surface_transformation),
view_identifier_(view_identifier),
embedded_view_params_(std::move(params)),
slice_(std::make_unique<DisplayListEmbedderViewSlice>(
SkRect::Make(frame_size))) {}
embedded_view_params_(std::move(params)) {
#if IMPELLER_SUPPORTS_RENDERING
if (enable_impeller) {
slice_ =
std::make_unique<ImpellerEmbedderViewSlice>(SkRect::Make(frame_size));
} else {
#endif // IMPELLER_SUPPORTS_RENDERING
slice_ = std::make_unique<DisplayListEmbedderViewSlice>(
SkRect::Make(frame_size));
#if IMPELLER_SUPPORTS_RENDERING
}
#endif // IMPELLER_SUPPORTS_RENDERING
}
EmbedderExternalView::~EmbedderExternalView() = default;
@@ -67,9 +78,7 @@ bool EmbedderExternalView::HasEngineRenderedContents() {
return has_engine_rendered_contents_.value();
}
TryEndRecording();
DlOpSpy dl_op_spy;
slice_->dispatch(dl_op_spy);
has_engine_rendered_contents_ = dl_op_spy.did_draw() && !slice_->is_empty();
has_engine_rendered_contents_ = slice_->renders_anything();
return has_engine_rendered_contents_.value();
}
@@ -94,13 +103,12 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target) {
if (impeller_target) {
auto aiks_context = render_target.GetAiksContext();
auto dl_builder = DisplayListBuilder();
dl_builder.SetTransform(&surface_transformation_);
slice_->render_into(&dl_builder);
impeller::DlAiksCanvas dl_canvas(
SkRect::Make(render_target.GetRenderTargetSize()));
dl_canvas.SetTransform(&surface_transformation_);
slice_->render_into(&dl_canvas);
auto dispatcher = impeller::DlDispatcher();
dispatcher.drawDisplayList(dl_builder.Build(), 1);
return aiks_context->Render(dispatcher.EndRecordingAsPicture(),
return aiks_context->Render(dl_canvas.EndRecordingAsPicture(),
*impeller_target);
}
#endif // IMPELLER_SUPPORTS_RENDERING

View File

@@ -82,12 +82,14 @@ class EmbedderExternalView {
ViewIdentifier::Equal>;
EmbedderExternalView(const SkISize& frame_size,
const SkMatrix& surface_transformation);
const SkMatrix& surface_transformation,
bool enable_impeller);
EmbedderExternalView(const SkISize& frame_size,
const SkMatrix& surface_transformation,
ViewIdentifier view_identifier,
std::unique_ptr<EmbeddedViewParams> params);
std::unique_ptr<EmbeddedViewParams> params,
bool enable_impeller);
~EmbedderExternalView();
@@ -118,7 +120,7 @@ class EmbedderExternalView {
const SkMatrix surface_transformation_;
ViewIdentifier view_identifier_;
std::unique_ptr<EmbeddedViewParams> embedded_view_params_;
std::unique_ptr<DisplayListEmbedderViewSlice> slice_;
std::unique_ptr<EmbedderViewSlice> slice_;
std::optional<bool> has_engine_rendered_contents_;
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalView);

View File

@@ -16,8 +16,10 @@ namespace flutter {
EmbedderExternalViewEmbedder::EmbedderExternalViewEmbedder(
bool avoid_backing_store_cache,
const CreateRenderTargetCallback& create_render_target_callback,
const PresentCallback& present_callback)
: avoid_backing_store_cache_(avoid_backing_store_cache),
const PresentCallback& present_callback,
bool enable_impeller)
: enable_impeller_(enable_impeller),
avoid_backing_store_cache_(avoid_backing_store_cache),
create_render_target_callback_(create_render_target_callback),
present_callback_(present_callback) {
FML_DCHECK(create_render_target_callback_);
@@ -65,7 +67,7 @@ void EmbedderExternalViewEmbedder::BeginFrame(
EmbedderExternalView::ViewIdentifier{};
pending_views_[kRootViewIdentifier] = std::make_unique<EmbedderExternalView>(
pending_frame_size_, pending_surface_transformation_);
pending_frame_size_, pending_surface_transformation_, enable_impeller_);
composition_order_.push_back(kRootViewIdentifier);
}
@@ -80,7 +82,8 @@ void EmbedderExternalViewEmbedder::PrerollCompositeEmbeddedView(
pending_frame_size_, // frame size
pending_surface_transformation_, // surface xformation
vid, // view identifier
std::move(params) // embedded view params
std::move(params), // embedded view params
enable_impeller_ // enable_impeller
);
composition_order_.push_back(vid);
}

View File

@@ -58,7 +58,8 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder {
EmbedderExternalViewEmbedder(
bool avoid_backing_store_cache,
const CreateRenderTargetCallback& create_render_target_callback,
const PresentCallback& present_callback);
const PresentCallback& present_callback,
bool enable_impeller);
//----------------------------------------------------------------------------
/// @brief Collects the external view embedder.
@@ -104,6 +105,7 @@ class EmbedderExternalViewEmbedder final : public ExternalViewEmbedder {
DlCanvas* GetRootCanvas() override;
private:
bool enable_impeller_ = false;
const bool avoid_backing_store_cache_;
const CreateRenderTargetCallback create_render_target_callback_;
const PresentCallback present_callback_;

View File

@@ -193,6 +193,14 @@ void MockCanvas::DrawImage(const sk_sp<DlImage>& image,
}
}
void MockCanvas::DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity) {
draw_calls_.emplace_back(
DrawCall{.layer = current_layer_,
.data = DrawImpellerPictureData{picture, opacity}});
}
void MockCanvas::DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity) {
draw_calls_.emplace_back(
@@ -462,6 +470,16 @@ std::ostream& operator<<(std::ostream& os,
<< data.options;
}
bool operator==(const MockCanvas::DrawImpellerPictureData& a,
const MockCanvas::DrawImpellerPictureData& b) {
return a.picture == b.picture && a.opacity == b.opacity;
}
std::ostream& operator<<(std::ostream& os,
const MockCanvas::DrawImpellerPictureData& data) {
return os << "[Impeller picture] " << data.opacity;
}
bool operator==(const MockCanvas::DrawDisplayListData& a,
const MockCanvas::DrawDisplayListData& b) {
return a.display_list->Equals(b.display_list) && a.opacity == b.opacity;

View File

@@ -95,6 +95,11 @@ class MockCanvas final : public DlCanvas {
DlPaint paint;
};
struct DrawImpellerPictureData {
std::shared_ptr<const impeller::Picture> picture;
SkScalar opacity;
};
struct DrawDisplayListData {
sk_sp<DisplayList> display_list;
SkScalar opacity;
@@ -142,6 +147,7 @@ class MockCanvas final : public DlCanvas {
DrawTextData,
DrawImageDataNoPaint,
DrawImageData,
DrawImpellerPictureData,
DrawDisplayListData,
DrawShadowData,
ClipRectData,
@@ -266,7 +272,9 @@ class MockCanvas final : public DlCanvas {
DlImageSampling sampling,
const SkRect* cullRect,
const DlPaint* paint = nullptr) override;
void DrawImpellerPicture(
const std::shared_ptr<const impeller::Picture>& picture,
SkScalar opacity = SK_Scalar1) override;
void DrawDisplayList(const sk_sp<DisplayList> display_list,
SkScalar opacity) override;
void DrawTextBlob(const sk_sp<SkTextBlob>& blob,
@@ -327,6 +335,11 @@ extern bool operator==(const MockCanvas::DrawImageDataNoPaint& a,
const MockCanvas::DrawImageDataNoPaint& b);
extern std::ostream& operator<<(std::ostream& os,
const MockCanvas::DrawImageDataNoPaint& data);
extern std::ostream& operator<<(
std::ostream& os,
const MockCanvas::DrawImpellerPictureData& data);
extern bool operator==(const MockCanvas::DrawImpellerPictureData& a,
const MockCanvas::DrawImpellerPictureData& b);
extern bool operator==(const MockCanvas::DrawDisplayListData& a,
const MockCanvas::DrawDisplayListData& b);
extern std::ostream& operator<<(std::ostream& os,

View File

@@ -45,9 +45,9 @@ txt::FontStyle GetTxtFontStyle(SkFontStyle::Slant font_slant) {
class DisplayListParagraphPainter : public skt::ParagraphPainter {
public:
DisplayListParagraphPainter(DisplayListBuilder* builder,
DisplayListParagraphPainter(DlCanvas* canvas,
const std::vector<DlPaint>& dl_paints)
: builder_(builder), dl_paints_(dl_paints) {}
: canvas_(canvas), dl_paints_(dl_paints) {}
DlPaint toDlPaint(const DecorationStyle& decor_style,
DlDrawStyle draw_style = DlDrawStyle::kStroke) {
@@ -76,7 +76,7 @@ class DisplayListParagraphPainter : public skt::ParagraphPainter {
}
size_t paint_id = std::get<PaintID>(paint);
FML_DCHECK(paint_id < dl_paints_.size());
builder_->DrawTextBlob(blob, x, y, dl_paints_[paint_id]);
canvas_->DrawTextBlob(blob, x, y, dl_paints_[paint_id]);
}
void drawTextShadow(const sk_sp<SkTextBlob>& blob,
@@ -93,24 +93,24 @@ class DisplayListParagraphPainter : public skt::ParagraphPainter {
DlBlurMaskFilter filter(DlBlurStyle::kNormal, blur_sigma, false);
paint.setMaskFilter(&filter);
}
builder_->DrawTextBlob(blob, x, y, paint);
canvas_->DrawTextBlob(blob, x, y, paint);
}
void drawRect(const SkRect& rect, const SkPaintOrID& paint) override {
size_t paint_id = std::get<PaintID>(paint);
FML_DCHECK(paint_id < dl_paints_.size());
builder_->DrawRect(rect, dl_paints_[paint_id]);
canvas_->DrawRect(rect, dl_paints_[paint_id]);
}
void drawFilledRect(const SkRect& rect,
const DecorationStyle& decor_style) override {
DlPaint paint = toDlPaint(decor_style, DlDrawStyle::kFill);
builder_->DrawRect(rect, paint);
canvas_->DrawRect(rect, paint);
}
void drawPath(const SkPath& path,
const DecorationStyle& decor_style) override {
builder_->DrawPath(path, toDlPaint(decor_style));
canvas_->DrawPath(path, toDlPaint(decor_style));
}
void drawLine(SkScalar x0,
@@ -118,24 +118,24 @@ class DisplayListParagraphPainter : public skt::ParagraphPainter {
SkScalar x1,
SkScalar y1,
const DecorationStyle& decor_style) override {
builder_->DrawLine(SkPoint::Make(x0, y0), SkPoint::Make(x1, y1),
toDlPaint(decor_style));
canvas_->DrawLine(SkPoint::Make(x0, y0), SkPoint::Make(x1, y1),
toDlPaint(decor_style));
}
void clipRect(const SkRect& rect) override {
builder_->ClipRect(rect, DlCanvas::ClipOp::kIntersect, false);
canvas_->ClipRect(rect, DlCanvas::ClipOp::kIntersect, false);
}
void translate(SkScalar dx, SkScalar dy) override {
builder_->Translate(dx, dy);
canvas_->Translate(dx, dy);
}
void save() override { builder_->Save(); }
void save() override { canvas_->Save(); }
void restore() override { builder_->Restore(); }
void restore() override { canvas_->Restore(); }
private:
DisplayListBuilder* builder_;
DlCanvas* canvas_;
const std::vector<DlPaint>& dl_paints_;
};
@@ -222,7 +222,7 @@ void ParagraphSkia::Layout(double width) {
paragraph_->layout(width);
}
bool ParagraphSkia::Paint(DisplayListBuilder* builder, double x, double y) {
bool ParagraphSkia::Paint(DlCanvas* builder, double x, double y) {
DisplayListParagraphPainter painter(builder, dl_paints_);
paragraph_->paint(&painter, x, y);
return true;

View File

@@ -53,7 +53,7 @@ class ParagraphSkia : public Paragraph {
void Layout(double width) override;
bool Paint(flutter::DisplayListBuilder* builder, double x, double y) override;
bool Paint(flutter::DlCanvas* canvas, double x, double y) override;
std::vector<TextBox> GetRectsForRange(
size_t start,

View File

@@ -18,7 +18,7 @@
#ifndef LIB_TXT_SRC_PARAGRAPH_H_
#define LIB_TXT_SRC_PARAGRAPH_H_
#include "flutter/display_list/display_list_builder.h"
#include "flutter/display_list/dl_canvas.h"
#include "line_metrics.h"
#include "paragraph_style.h"
#include "third_party/skia/include/core/SkRect.h"
@@ -143,11 +143,9 @@ class Paragraph {
// before Painting and getting any statistics from this class.
virtual void Layout(double width) = 0;
// Paints the laid out text onto the supplied DisplayListBuilder at
// Paints the laid out text onto the supplied DlCanvas at
// (x, y) offset from the origin. Only valid after Layout() is called.
virtual bool Paint(flutter::DisplayListBuilder* builder,
double x,
double y) = 0;
virtual bool Paint(flutter::DlCanvas* canvas, double x, double y) = 0;
// Returns a vector of bounding boxes that enclose all text between start and
// end glyph indexes, including start and excluding end.