OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium 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 CC_TEST_FAKE_PICTURE_PILE_H_ | |
6 #define CC_TEST_FAKE_PICTURE_PILE_H_ | |
7 | |
8 #include "cc/playback/picture_pile.h" | |
9 #include "cc/test/fake_content_layer_client.h" | |
10 | |
11 namespace base { | |
12 class WaitableEvent; | |
13 } | |
14 | |
15 namespace cc { | |
16 | |
17 class FakePicturePile : public PicturePile { | |
18 public: | |
19 using PictureMapKey = PicturePile::PictureMapKey; | |
20 using PictureMap = PicturePile::PictureMap; | |
21 | |
22 FakePicturePile(float min_contents_scale, const gfx::Size& tile_grid_size) | |
23 : PicturePile(min_contents_scale, tile_grid_size), | |
24 playback_allowed_event_(nullptr) {} | |
25 ~FakePicturePile() override {} | |
26 | |
27 static scoped_ptr<FakePicturePile> CreateFilledPile( | |
28 const gfx::Size& tile_size, | |
29 const gfx::Size& layer_bounds); | |
30 static scoped_ptr<FakePicturePile> CreateEmptyPile( | |
31 const gfx::Size& tile_size, | |
32 const gfx::Size& layer_bounds); | |
33 | |
34 // PicturePile overrides. | |
35 scoped_refptr<RasterSource> CreateRasterSource( | |
36 bool can_use_lcd_text) const override; | |
37 | |
38 using PicturePile::buffer_pixels; | |
39 using PicturePile::CanRasterSlowTileCheck; | |
40 using PicturePile::Clear; | |
41 using PicturePile::SetMinContentsScale; | |
42 using PicturePile::SetTileGridSize; | |
43 | |
44 PictureMap& picture_map() { return picture_map_; } | |
45 const gfx::Rect& recorded_viewport() const { return recorded_viewport_; } | |
46 | |
47 bool CanRasterLayerRect(gfx::Rect layer_rect) { | |
48 layer_rect.Intersect(gfx::Rect(tiling_.tiling_size())); | |
49 if (recorded_viewport_.Contains(layer_rect)) | |
50 return true; | |
51 return CanRasterSlowTileCheck(layer_rect); | |
52 } | |
53 | |
54 bool HasRecordings() const { return has_any_recordings_; } | |
55 | |
56 void SetRecordedViewport(const gfx::Rect& viewport) { | |
57 recorded_viewport_ = viewport; | |
58 } | |
59 | |
60 void SetHasAnyRecordings(bool has_recordings) { | |
61 has_any_recordings_ = has_recordings; | |
62 } | |
63 | |
64 void SetClearCanvasWithDebugColor(bool clear) { | |
65 clear_canvas_with_debug_color_ = clear; | |
66 } | |
67 | |
68 void SetPlaybackAllowedEvent(base::WaitableEvent* event) { | |
69 playback_allowed_event_ = event; | |
70 } | |
71 | |
72 TilingData& tiling() { return tiling_; } | |
73 | |
74 bool is_solid_color() const { return is_solid_color_; } | |
75 SkColor solid_color() const { return solid_color_; } | |
76 void SetIsSolidColor(bool is_solid) { is_solid_color_ = is_solid; } | |
77 | |
78 void SetPixelRecordDistance(int d) { pixel_record_distance_ = d; } | |
79 | |
80 void add_draw_rect(const gfx::Rect& rect) { | |
81 client_.add_draw_rect(rect, default_paint_); | |
82 } | |
83 | |
84 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) { | |
85 client_.add_draw_rect(rect, paint); | |
86 } | |
87 | |
88 void add_draw_rectf(const gfx::RectF& rect) { | |
89 client_.add_draw_rectf(rect, default_paint_); | |
90 } | |
91 | |
92 void add_draw_rectf_with_paint(const gfx::RectF& rect, const SkPaint& paint) { | |
93 client_.add_draw_rectf(rect, paint); | |
94 } | |
95 | |
96 void add_draw_image(const SkImage* image, const gfx::Point& point) { | |
97 client_.add_draw_image(image, point, default_paint_); | |
98 } | |
99 | |
100 void add_draw_image_with_paint(const SkImage* image, | |
101 const gfx::Point& point, | |
102 const SkPaint& paint) { | |
103 client_.add_draw_image(image, point, paint); | |
104 } | |
105 | |
106 void set_default_paint(const SkPaint& paint) { default_paint_ = paint; } | |
107 | |
108 void AddRecordingAt(int x, int y); | |
109 void RemoveRecordingAt(int x, int y); | |
110 bool HasRecordingAt(int x, int y) const; | |
111 int num_tiles_x() const { return tiling_.num_tiles_x(); } | |
112 int num_tiles_y() const { return tiling_.num_tiles_y(); } | |
113 void Rerecord(); | |
114 | |
115 private: | |
116 base::WaitableEvent* playback_allowed_event_; | |
117 | |
118 FakeContentLayerClient client_; | |
119 SkPaint default_paint_; | |
120 }; | |
121 | |
122 } // namespace cc | |
123 | |
124 #endif // CC_TEST_FAKE_PICTURE_PILE_H_ | |
OLD | NEW |