Flutter Engine
mock_raster_cache.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_raster_cache.h"
6 
7 #include "third_party/skia/include/core/SkPictureRecorder.h"
8 
9 namespace flutter {
10 namespace testing {
11 
13  : RasterCacheResult(nullptr, SkRect::MakeEmpty()),
14  device_rect_(device_rect) {}
15 
16 std::unique_ptr<RasterCacheResult> MockRasterCache::RasterizePicture(
17  SkPicture* picture,
18  GrDirectContext* context,
19  const SkMatrix& ctm,
20  SkColorSpace* dst_color_space,
21  bool checkerboard) const {
22  SkRect logical_rect = picture->cullRect();
23  SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
24 
25  return std::make_unique<MockRasterCacheResult>(cache_rect);
26 }
27 
28 std::unique_ptr<RasterCacheResult> MockRasterCache::RasterizeLayer(
29  PrerollContext* context,
30  Layer* layer,
31  const SkMatrix& ctm,
32  bool checkerboard) const {
33  SkRect logical_rect = layer->paint_bounds();
34  SkIRect cache_rect = RasterCache::GetDeviceBounds(logical_rect, ctm);
35 
36  return std::make_unique<MockRasterCacheResult>(cache_rect);
37 }
38 
40  SkMatrix ctm = SkMatrix::I();
41  SkPath path;
42  path.addRect(100, 100, 100 + width, 100 + height);
43  MockLayer layer = MockLayer(path);
44  layer.Preroll(&preroll_context_, ctm);
45  Prepare(&preroll_context_, &layer, ctm);
46 }
47 
49  FML_DCHECK(access_threshold() > 0);
50  SkMatrix ctm = SkMatrix::I();
51  SkPictureRecorder skp_recorder;
52  SkRTreeFactory rtree_factory;
53  SkPath path;
54  path.addRect(100, 100, 100 + width, 100 + height);
55  SkCanvas* recorder_canvas = skp_recorder.beginRecording(
56  SkRect::MakeLTRB(0, 0, 200 + width, 200 + height), &rtree_factory);
57  recorder_canvas->drawPath(path, SkPaint());
58  sk_sp<SkPicture> picture = skp_recorder.finishRecordingAsPicture();
61  for (int i = 0; i < access_threshold(); i++) {
62  Prepare(&holder.preroll_context, picture.get(), true, false, ctm);
63  Draw(*picture, mock_canvas_);
64  }
65  Prepare(&holder.preroll_context, picture.get(), true, false, ctm);
66 }
67 
69  Stopwatch raster_time;
70  Stopwatch ui_time;
71  MutatorsStack mutators_stack;
72  TextureRegistry texture_registry;
73  sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
74  PrerollContextHolder holder = {
75  {
76  nullptr, /* raster_cache */
77  nullptr, /* gr_context */
78  nullptr, /* external_view_embedder */
79  mutators_stack, srgb.get(), /* color_space */
80  kGiantRect, /* cull_rect */
81  false, /* layer reads from surface */
82  raster_time, ui_time, texture_registry,
83  false, /* checkerboard_offscreen_layers */
84  1.0f, /* frame_device_pixel_ratio */
85  false, /* has_platform_view */
86  },
87  srgb};
88 
89  return holder;
90 }
91 
92 } // namespace testing
93 } // namespace flutter
static SkIRect GetDeviceBounds(const SkRect &rect, const SkMatrix &ctm)
Definition: raster_cache.h:105
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define FML_DCHECK(condition)
Definition: logging.h:86
void Preroll(PrerollContext *context, const SkMatrix &matrix) override
Definition: mock_layer.cc:38
void AddMockLayer(int width, int height)
sk_sp< SkColorSpace > color_space_
static constexpr SkRect kGiantRect
Definition: layer.h:37
std::unique_ptr< RasterCacheResult > RasterizeLayer(PrerollContext *context, Layer *layer, const SkMatrix &ctm, bool checkerboard) const override
Rasterize an engine Layer and produce a RasterCacheResult to be stored in the cache.
void AddMockPicture(int width, int height)
SkColorSpace * dst_color_space
Definition: layer.h:47
PrerollContextHolder GetSamplePrerollContextHolder()
int32_t width
const SkRect & paint_bounds() const
Definition: layer.h:227
int32_t height
std::unique_ptr< RasterCacheResult > RasterizePicture(SkPicture *picture, GrDirectContext *context, const SkMatrix &ctm, SkColorSpace *dst_color_space, bool checkerboard) const override
Rasterize a picture object and produce a RasterCacheResult to be stored in the cache.