Flutter Engine
The Flutter Engine
mock_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/testing/mock_layer.h"
6
7#include <utility>
8
9#include "flutter/flow/layers/container_layer.h"
10#include "flutter/flow/layers/layer.h"
11#include "flutter/flow/testing/mock_raster_cache.h"
12namespace flutter {
13namespace testing {
14
16 : fake_paint_path_(path), fake_paint_(std::move(paint)) {}
17
18bool MockLayer::IsReplacing(DiffContext* context, const Layer* layer) const {
19 // Similar to PictureLayer, only return true for identical mock layers;
20 // That way ContainerLayer::DiffChildren can properly detect mock layer
21 // insertion
22 auto mock_layer = layer->as_mock_layer();
23 return mock_layer && mock_layer->fake_paint_ == fake_paint_ &&
24 mock_layer->fake_paint_path_ == fake_paint_path_;
25}
26
27void MockLayer::Diff(DiffContext* context, const Layer* old_layer) {
28 DiffContext::AutoSubtreeRestore subtree(context);
29 context->AddLayerBounds(fake_paint_path_.getBounds());
30 context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
31}
32
34 context->state_stack.fill(&parent_mutators_);
35 parent_matrix_ = context->state_stack.transform_3x3();
36 parent_cull_rect_ = context->state_stack.local_cull_rect();
37
40
43 set_paint_bounds(fake_paint_path_.getBounds());
44 if (fake_reads_surface()) {
45 context->surface_needs_readback = true;
46 }
49 }
50}
51
52void MockLayer::Paint(PaintContext& context) const {
53 FML_DCHECK(needs_painting(context));
54
55 if (expected_paint_matrix_.has_value()) {
57
58 EXPECT_EQ(matrix, expected_paint_matrix_.value());
59 }
60
61 DlPaint paint = fake_paint_;
62 context.state_stack.fill(paint);
63 context.canvas->DrawPath(fake_paint_path_, paint);
64}
65
69 auto cache = AutoCache(layer_raster_cache_item_.get(), context,
70 context->state_stack.transform_3x3());
71
73}
74
78 auto cache = AutoCache(raster_cache_item_.get(), context,
79 context->state_stack.transform_3x3());
80
81 MockLayer::Preroll(context);
82}
83
84} // namespace testing
85} // namespace flutter
Definition: SkPath.h:59
const SkRect & getBounds() const
Definition: SkPath.cpp:430
std::unique_ptr< LayerRasterCacheItem > layer_raster_cache_item_
void Preroll(PrerollContext *context) override
void AddLayerBounds(const SkRect &rect)
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
PaintRegion CurrentSubtreeRegion() const
virtual SkMatrix GetTransform() const =0
virtual void DrawPath(const SkPath &path, const DlPaint &paint)=0
SkMatrix transform_3x3() const
void fill(MutatorsStack *mutators)
static constexpr int kCallerCanApplyOpacity
static AutoPrerollSaveLayerState Create(PrerollContext *preroll_context, bool save_layer_is_active=true, bool layer_itself_performs_readback=false)
Definition: layer.cc:40
virtual const testing::MockLayer * as_mock_layer() const
Definition: layer.h:266
bool needs_painting(PaintContext &context) const
Definition: layer.h:232
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:223
void Preroll(PrerollContext *context) override
Definition: mock_layer.cc:66
void Preroll(PrerollContext *context) override
Definition: mock_layer.cc:75
bool IsReplacing(DiffContext *context, const Layer *layer) const override
Definition: mock_layer.cc:18
MockLayer & set_parent_has_platform_view(bool flag)
Definition: mock_layer.h:70
MockLayer & set_parent_has_texture_layer(bool flag)
Definition: mock_layer.h:76
void Diff(DiffContext *context, const Layer *old_layer) override
Definition: mock_layer.cc:27
void Preroll(PrerollContext *context) override
Definition: mock_layer.cc:33
MockLayer(const SkPath &path, DlPaint paint=DlPaint())
Definition: mock_layer.cc:15
void Paint(PaintContext &context) const override
Definition: mock_layer.cc:52
const Paint & paint
Definition: color_source.cc:38
#define FML_DCHECK(condition)
Definition: logging.h:103
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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
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
Definition: switches.h:57
Definition: ref_ptr.h:256
DlCanvas * canvas
Definition: layer.h:102
LayerStateStack & state_stack
Definition: layer.h:101
LayerStateStack & state_stack
Definition: layer.h:59
bool surface_needs_readback
Definition: layer.h:61
int renderable_state_flags
Definition: layer.h:83