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 namespace flutter {
8 namespace testing {
9 
11  SkPaint paint,
12  bool fake_has_platform_view,
13  bool fake_reads_surface)
14  : fake_paint_path_(path),
15  fake_paint_(paint),
16  fake_has_platform_view_(fake_has_platform_view),
17  fake_reads_surface_(fake_reads_surface) {}
18 
19 bool MockLayer::IsReplacing(DiffContext* context, const Layer* layer) const {
20  // Similar to PictureLayer, only return true for identical mock layers;
21  // That way ContainerLayer::DiffChildren can properly detect mock layer
22  // insertion
23  auto mock_layer = layer->as_mock_layer();
24  return mock_layer && mock_layer->fake_paint_ == fake_paint_ &&
25  mock_layer->fake_paint_path_ == fake_paint_path_;
26 }
27 
28 void MockLayer::Diff(DiffContext* context, const Layer* old_layer) {
29  DiffContext::AutoSubtreeRestore subtree(context);
30  context->AddLayerBounds(fake_paint_path_.getBounds());
31  context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion());
32 }
33 
34 void MockLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
35  parent_mutators_ = context->mutators_stack;
36  parent_matrix_ = matrix;
37  parent_cull_rect_ = context->cull_rect;
38  parent_has_platform_view_ = context->has_platform_view;
39 
40  context->has_platform_view = fake_has_platform_view_;
41  set_paint_bounds(fake_paint_path_.getBounds());
42  if (fake_reads_surface_) {
43  context->surface_needs_readback = true;
44  }
45 }
46 
47 void MockLayer::Paint(PaintContext& context) const {
48  FML_DCHECK(needs_painting(context));
49 
50  context.leaf_nodes_canvas->drawPath(fake_paint_path_, fake_paint_);
51 }
52 
53 } // namespace testing
54 } // namespace flutter
void SetLayerPaintRegion(const Layer *layer, const PaintRegion &region)
#define FML_DCHECK(condition)
Definition: logging.h:86
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
Definition: mock_layer.cc:34
bool IsReplacing(DiffContext *context, const Layer *layer) const override
Definition: mock_layer.cc:19
void AddLayerBounds(const SkRect &rect)
void Diff(DiffContext *context, const Layer *old_layer) override
Definition: mock_layer.cc:28
bool needs_painting(PaintContext &context) const
Definition: layer.h:245
void Paint(PaintContext &context) const override
Definition: mock_layer.cc:47
virtual const testing::MockLayer * as_mock_layer() const
Definition: layer.h:278
SkCanvas * leaf_nodes_canvas
Definition: layer.h:141
void set_paint_bounds(const SkRect &paint_bounds)
Definition: layer.h:236
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
PaintRegion CurrentSubtreeRegion() const
bool surface_needs_readback
Definition: layer.h:49
MockLayer(SkPath path, SkPaint paint=SkPaint(), bool fake_has_platform_view=false, bool fake_reads_surface=false)
Definition: mock_layer.cc:10
MutatorsStack & mutators_stack
Definition: layer.h:46