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"
10 #include "cc/test/impl_side_painting_settings.h"
18 class FakePicturePile
: public PicturePile
{
20 using PictureMapKey
= PicturePile::PictureMapKey
;
21 using PictureMap
= PicturePile::PictureMap
;
23 FakePicturePile(float min_contents_scale
, const gfx::Size
& tile_grid_size
)
24 : PicturePile(min_contents_scale
, tile_grid_size
),
25 playback_allowed_event_(nullptr) {}
26 ~FakePicturePile() override
{}
28 static scoped_ptr
<FakePicturePile
> CreateFilledPile(
29 const gfx::Size
& tile_size
,
30 const gfx::Size
& layer_bounds
);
31 static scoped_ptr
<FakePicturePile
> CreateEmptyPile(
32 const gfx::Size
& tile_size
,
33 const gfx::Size
& layer_bounds
);
35 // PicturePile overrides.
36 scoped_refptr
<RasterSource
> CreateRasterSource(
37 bool can_use_lcd_text
) const override
;
39 using PicturePile::buffer_pixels
;
40 using PicturePile::CanRasterSlowTileCheck
;
41 using PicturePile::Clear
;
42 using PicturePile::SetMinContentsScale
;
43 using PicturePile::SetTileGridSize
;
45 PictureMap
& picture_map() { return picture_map_
; }
46 const gfx::Rect
& recorded_viewport() const { return recorded_viewport_
; }
48 bool CanRasterLayerRect(gfx::Rect layer_rect
) {
49 layer_rect
.Intersect(gfx::Rect(tiling_
.tiling_size()));
50 if (recorded_viewport_
.Contains(layer_rect
))
52 return CanRasterSlowTileCheck(layer_rect
);
55 bool HasRecordings() const { return has_any_recordings_
; }
57 void SetRecordedViewport(const gfx::Rect
& viewport
) {
58 recorded_viewport_
= viewport
;
61 void SetHasAnyRecordings(bool has_recordings
) {
62 has_any_recordings_
= has_recordings
;
65 void SetClearCanvasWithDebugColor(bool clear
) {
66 clear_canvas_with_debug_color_
= clear
;
69 void SetPlaybackAllowedEvent(base::WaitableEvent
* event
) {
70 playback_allowed_event_
= event
;
73 TilingData
& tiling() { return tiling_
; }
75 bool is_solid_color() const { return is_solid_color_
; }
76 SkColor
solid_color() const { return solid_color_
; }
77 void SetIsSolidColor(bool is_solid
) { is_solid_color_
= is_solid
; }
79 void SetPixelRecordDistance(int d
) { pixel_record_distance_
= d
; }
81 void add_draw_rect(const gfx::RectF
& rect
) {
82 client_
.add_draw_rect(rect
, default_paint_
);
85 void add_draw_bitmap(const SkBitmap
& bitmap
, const gfx::Point
& point
) {
86 client_
.add_draw_bitmap(bitmap
, point
, default_paint_
);
89 void add_draw_rect_with_paint(const gfx::RectF
& rect
, const SkPaint
& paint
) {
90 client_
.add_draw_rect(rect
, paint
);
93 void add_draw_bitmap_with_paint(const SkBitmap
& bitmap
,
94 const gfx::Point
& point
,
95 const SkPaint
& paint
) {
96 client_
.add_draw_bitmap(bitmap
, point
, paint
);
99 void set_default_paint(const SkPaint
& paint
) { default_paint_
= paint
; }
101 void AddRecordingAt(int x
, int y
);
102 void RemoveRecordingAt(int x
, int y
);
103 bool HasRecordingAt(int x
, int y
) const;
104 int num_tiles_x() const { return tiling_
.num_tiles_x(); }
105 int num_tiles_y() const { return tiling_
.num_tiles_y(); }
109 base::WaitableEvent
* playback_allowed_event_
;
111 FakeContentLayerClient client_
;
112 SkPaint default_paint_
;
117 #endif // CC_TEST_FAKE_PICTURE_PILE_H_