Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / test / fake_picture_pile.h
blobf1eb2c1881600433a25c87b8c7f460bb39889eb7
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.
5 #ifndef CC_TEST_FAKE_PICTURE_PILE_H_
6 #define CC_TEST_FAKE_PICTURE_PILE_H_
8 #include "cc/playback/picture_pile.h"
9 #include "cc/test/fake_content_layer_client.h"
11 namespace base {
12 class WaitableEvent;
15 namespace cc {
17 class FakePicturePile : public PicturePile {
18 public:
19 using PictureMapKey = PicturePile::PictureMapKey;
20 using PictureMap = PicturePile::PictureMap;
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 {}
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);
34 // PicturePile overrides.
35 scoped_refptr<RasterSource> CreateRasterSource(
36 bool can_use_lcd_text) const override;
38 using PicturePile::buffer_pixels;
39 using PicturePile::CanRasterSlowTileCheck;
40 using PicturePile::Clear;
41 using PicturePile::SetMinContentsScale;
42 using PicturePile::SetTileGridSize;
44 PictureMap& picture_map() { return picture_map_; }
45 const gfx::Rect& recorded_viewport() const { return recorded_viewport_; }
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);
54 bool HasRecordings() const { return has_any_recordings_; }
56 void SetRecordedViewport(const gfx::Rect& viewport) {
57 recorded_viewport_ = viewport;
60 void SetHasAnyRecordings(bool has_recordings) {
61 has_any_recordings_ = has_recordings;
64 void SetClearCanvasWithDebugColor(bool clear) {
65 clear_canvas_with_debug_color_ = clear;
68 void SetPlaybackAllowedEvent(base::WaitableEvent* event) {
69 playback_allowed_event_ = event;
72 TilingData& tiling() { return tiling_; }
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; }
78 void SetPixelRecordDistance(int d) { pixel_record_distance_ = d; }
80 void add_draw_rect(const gfx::Rect& rect) {
81 client_.add_draw_rect(rect, default_paint_);
84 void add_draw_rect_with_paint(const gfx::Rect& rect, const SkPaint& paint) {
85 client_.add_draw_rect(rect, paint);
88 void add_draw_rectf(const gfx::RectF& rect) {
89 client_.add_draw_rectf(rect, default_paint_);
92 void add_draw_rectf_with_paint(const gfx::RectF& rect, const SkPaint& paint) {
93 client_.add_draw_rectf(rect, paint);
96 void add_draw_image(const SkImage* image, const gfx::Point& point) {
97 client_.add_draw_image(image, point, default_paint_);
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);
106 void set_default_paint(const SkPaint& paint) { default_paint_ = paint; }
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();
115 private:
116 base::WaitableEvent* playback_allowed_event_;
118 FakeContentLayerClient client_;
119 SkPaint default_paint_;
122 } // namespace cc
124 #endif // CC_TEST_FAKE_PICTURE_PILE_H_