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"
17 class FakePicturePile
: public PicturePile
{
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
))
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::RectF
& rect
) {
81 client_
.add_draw_rect(rect
, default_paint_
);
84 void add_draw_bitmap(const SkBitmap
& bitmap
, const gfx::Point
& point
) {
85 client_
.add_draw_bitmap(bitmap
, point
, default_paint_
);
88 void add_draw_rect_with_paint(const gfx::RectF
& rect
, const SkPaint
& paint
) {
89 client_
.add_draw_rect(rect
, paint
);
92 void add_draw_bitmap_with_paint(const SkBitmap
& bitmap
,
93 const gfx::Point
& point
,
94 const SkPaint
& paint
) {
95 client_
.add_draw_bitmap(bitmap
, point
, paint
);
98 void set_default_paint(const SkPaint
& paint
) { default_paint_
= paint
; }
100 void AddRecordingAt(int x
, int y
);
101 void RemoveRecordingAt(int x
, int y
);
102 bool HasRecordingAt(int x
, int y
) const;
103 int num_tiles_x() const { return tiling_
.num_tiles_x(); }
104 int num_tiles_y() const { return tiling_
.num_tiles_y(); }
108 base::WaitableEvent
* playback_allowed_event_
;
110 FakeContentLayerClient client_
;
111 SkPaint default_paint_
;
116 #endif // CC_TEST_FAKE_PICTURE_PILE_H_