Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
display_list_layer.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/flow/layers/display_list_layer.h"
6
7#include <utility>
8
9#include "flutter/display_list/dl_builder.h"
10#include "flutter/flow/layer_snapshot_store.h"
11#include "flutter/flow/layers/cacheable_layer.h"
12#include "flutter/flow/layers/offscreen_surface.h"
13#include "flutter/flow/raster_cache.h"
14#include "flutter/flow/raster_cache_util.h"
15
16namespace flutter {
17
19 sk_sp<DisplayList> display_list,
20 bool is_complex,
21 bool will_change)
22 : offset_(offset), display_list_(std::move(display_list)) {
23 if (display_list_) {
24 bounds_ = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
25 display_list_raster_cache_item_ = DisplayListRasterCacheItem::Make(
26 display_list_, offset_, is_complex, will_change);
27 }
28}
29
31 const Layer* layer) const {
32 // Only return true for identical display lists; This way
33 // ContainerLayer::DiffChildren can detect when a display list layer
34 // got inserted between other display list layers
35 auto old_layer = layer->as_display_list_layer();
36 return old_layer != nullptr && offset_ == old_layer->offset_ &&
37 Compare(context->statistics(), this, old_layer);
38}
39
40void DisplayListLayer::Diff(DiffContext* context, const Layer* old_layer) {
41 DiffContext::AutoSubtreeRestore subtree(context);
42 if (!context->IsSubtreeDirty()) {
43#ifndef NDEBUG
44 FML_DCHECK(old_layer);
45 auto prev = old_layer->as_display_list_layer();
46 DiffContext::Statistics dummy_statistics;
47 // IsReplacing has already determined that the display list is same
48 FML_DCHECK(prev->offset_ == offset_ &&
49 Compare(dummy_statistics, this, prev));
50#endif
51 }
52 context->PushTransform(SkMatrix::Translate(offset_.x(), offset_.y()));
53 if (context->has_raster_cache()) {
55 }
56 context->AddLayerBounds(display_list()->bounds());
57 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
58}
59
60bool DisplayListLayer::Compare(DiffContext::Statistics& statistics,
61 const DisplayListLayer* l1,
62 const DisplayListLayer* l2) {
63 const auto& dl1 = l1->display_list_;
64 const auto& dl2 = l2->display_list_;
65 if (dl1.get() == dl2.get()) {
66 statistics.AddSameInstancePicture();
67 return true;
68 }
69 const auto op_cnt_1 = dl1->op_count();
70 const auto op_cnt_2 = dl2->op_count();
71 const auto op_bytes_1 = dl1->bytes();
72 const auto op_bytes_2 = dl2->bytes();
73 if (op_cnt_1 != op_cnt_2 || op_bytes_1 != op_bytes_2 ||
74 dl1->bounds() != dl2->bounds()) {
75 statistics.AddNewPicture();
76 return false;
77 }
78
79 if (op_bytes_1 > kMaxBytesToCompare) {
81 return false;
82 }
83
84 statistics.AddDeepComparePicture();
85
86 auto res = dl1->Equals(*dl2);
87 if (res) {
89 } else {
90 statistics.AddNewPicture();
91 }
92 return res;
93}
94
96 DisplayList* disp_list = display_list();
97
98 AutoCache cache = AutoCache(display_list_raster_cache_item_.get(), context,
99 context->state_stack.transform_3x3());
100 if (disp_list->can_apply_group_opacity()) {
102 }
103 set_paint_bounds(bounds_);
104}
105
107 FML_DCHECK(display_list_);
108 FML_DCHECK(needs_painting(context));
109
110 auto mutator = context.state_stack.save();
111 mutator.translate(offset_.x(), offset_.y());
112
113 if (context.raster_cache) {
114 // Always apply the integral transform in the presence of a raster cache
115 // whether or not we successfully draw from the cache
116 mutator.integralTransform();
117
118 if (display_list_raster_cache_item_) {
120 if (display_list_raster_cache_item_->Draw(
121 context, context.state_stack.fill(paint))) {
122 TRACE_EVENT_INSTANT0("flutter", "raster cache hit");
123 return;
124 }
125 }
126 }
127
128 SkScalar opacity = context.state_stack.outstanding_opacity();
129
130 if (context.enable_leaf_layer_tracing) {
131 const auto canvas_size = context.canvas->GetBaseLayerSize();
132 auto offscreen_surface =
133 std::make_unique<OffscreenSurface>(context.gr_context, canvas_size);
134
135 const auto& ctm = context.canvas->GetTransform();
136
137 const auto start_time = fml::TimePoint::Now();
138 {
139 // render display list to offscreen surface.
140 auto* canvas = offscreen_surface->GetCanvas();
141 {
142 DlAutoCanvasRestore save(canvas, true);
143 canvas->Clear(DlColor::kTransparent());
144 canvas->SetTransform(ctm);
145 canvas->DrawDisplayList(display_list_, opacity);
146 }
147 canvas->Flush();
148 }
149 const fml::TimeDelta offscreen_render_time =
150 fml::TimePoint::Now() - start_time;
151
152 const SkRect device_bounds =
154 sk_sp<SkData> raster_data = offscreen_surface->GetRasterData(true);
155 LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time,
156 raster_data, device_bounds);
157 context.layer_snapshot_store->Add(snapshot_data);
158 }
159
160 context.canvas->DrawDisplayList(display_list_, opacity);
161}
162
163} // namespace flutter
static float prev(float f)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
void PushTransform(const SkMatrix &transform)
void WillPaintWithIntegralTransform()
void AddLayerBounds(const SkRect &rect)
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
Statistics & statistics()
PaintRegion CurrentSubtreeRegion() const
bool has_raster_cache() const
bool IsSubtreeDirty() const
bool IsReplacing(DiffContext *context, const Layer *layer) const override
void Preroll(PrerollContext *frame) override
void Diff(DiffContext *context, const Layer *old_layer) override
DisplayList * display_list() const
DisplayListLayer(const SkPoint &offset, sk_sp< DisplayList > display_list, bool is_complex, bool will_change)
static constexpr size_t kMaxBytesToCompare
void Paint(PaintContext &context) const override
static std::unique_ptr< DisplayListRasterCacheItem > Make(const sk_sp< DisplayList > &, const SkPoint &offset, bool is_complex, bool will_change)
bool can_apply_group_opacity() const
virtual SkISize GetBaseLayerSize() const =0
virtual void DrawDisplayList(const sk_sp< DisplayList > display_list, SkScalar opacity=SK_Scalar1)=0
virtual SkMatrix GetTransform() const =0
void Add(const LayerSnapshotData &data)
void translate(SkScalar tx, SkScalar ty)
void fill(MutatorsStack *mutators)
SkScalar outstanding_opacity() const
static constexpr int kCallerCanApplyOpacity
const SkRect & paint_bounds() const
Definition layer.h:209
bool needs_painting(PaintContext &context) const
Definition layer.h:231
virtual const DisplayListLayer * as_display_list_layer() const
Definition layer.h:256
uint64_t unique_id() const
Definition layer.h:250
void set_paint_bounds(const SkRect &paint_bounds)
Definition layer.h:222
static TimePoint Now()
Definition time_point.cc:49
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define FML_DCHECK(condition)
Definition logging.h:103
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
Definition ref_ptr.h:256
Point offset
constexpr float y() const
constexpr float x() const
static constexpr DlColor kTransparent()
Definition dl_color.h:21
bool enable_leaf_layer_tracing
Definition layer.h:119
LayerSnapshotStore * layer_snapshot_store
Definition layer.h:118
DlCanvas * canvas
Definition layer.h:101
GrDirectContext * gr_context
Definition layer.h:108
LayerStateStack & state_stack
Definition layer.h:100
const RasterCache * raster_cache
Definition layer.h:114
LayerStateStack & state_stack
Definition layer.h:58
static SkRect GetDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
#define TRACE_EVENT_INSTANT0(category_group, name)