Flutter Engine
mock_raster_cache.h
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 #ifndef FLOW_TESTING_MOCK_RASTER_CACHE_H_
6 #define FLOW_TESTING_MOCK_RASTER_CACHE_H_
7 
8 #include "flutter/flow/raster_cache.h"
9 #include "third_party/skia/include/core/SkImage.h"
10 #include "third_party/skia/include/core/SkPicture.h"
11 
12 namespace flutter {
13 namespace testing {
14 
15 /**
16  * @brief A RasterCacheResult implementation that represents a cached Layer or
17  * SkPicture without the overhead of storage.
18  *
19  * This implementation is used by MockRasterCache only for testing proper usage
20  * of the RasterCache in layer unit tests.
21  */
23  public:
24  MockRasterCacheResult(SkIRect device_rect);
25 
26  void draw(SkCanvas& canvas, const SkPaint* paint = nullptr) const override{};
27 
28  SkISize image_dimensions() const override { return device_rect_.size(); };
29 
30  int64_t image_bytes() const override {
31  return image_dimensions().area() *
32  SkColorTypeBytesPerPixel(kBGRA_8888_SkColorType);
33  }
34 
35  private:
36  SkIRect device_rect_;
37 };
38 
39 /**
40  * @brief A RasterCache implementation that simulates the act of rendering a
41  * Layer or SkPicture without the overhead of rasterization or pixel storage.
42  * This implementation is used only for testing proper usage of the RasterCache
43  * in layer unit tests.
44  */
45 class MockRasterCache : public RasterCache {
46  public:
47  std::unique_ptr<RasterCacheResult> RasterizePicture(
48  SkPicture* picture,
49  GrDirectContext* context,
50  const SkMatrix& ctm,
51  SkColorSpace* dst_color_space,
52  bool checkerboard) const override;
53 
54  std::unique_ptr<RasterCacheResult> RasterizeLayer(
55  PrerollContext* context,
56  Layer* layer,
57  const SkMatrix& ctm,
58  bool checkerboard) const override;
59 };
60 
61 } // namespace testing
62 } // namespace flutter
63 
64 #endif // FLOW_TESTING_MOCK_RASTER_CACHE_H_
A RasterCache implementation that simulates the act of rendering a Layer or SkPicture without the ove...
void draw(SkCanvas &canvas, const SkPaint *paint=nullptr) const override
SkISize image_dimensions() const override
A RasterCacheResult implementation that represents a cached Layer or SkPicture without the overhead o...