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/resources/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 PictureInfo
= PicturePile::PictureInfo
;
21 using PictureMapKey
= PicturePile::PictureMapKey
;
22 using PictureMap
= PicturePile::PictureMap
;
24 FakePicturePile(float min_contents_scale
, const gfx::Size
& tile_grid_size
)
25 : PicturePile(min_contents_scale
, tile_grid_size
),
26 playback_allowed_event_(nullptr) {}
27 ~FakePicturePile() override
{}
29 static scoped_ptr
<FakePicturePile
> CreateFilledPile(
30 const gfx::Size
& tile_size
,
31 const gfx::Size
& layer_bounds
);
32 static scoped_ptr
<FakePicturePile
> CreateEmptyPile(
33 const gfx::Size
& tile_size
,
34 const gfx::Size
& layer_bounds
);
36 // PicturePile overrides.
37 scoped_refptr
<RasterSource
> CreateRasterSource(
38 bool can_use_lcd_text
) const override
;
40 using PicturePile::buffer_pixels
;
41 using PicturePile::CanRasterSlowTileCheck
;
42 using PicturePile::Clear
;
43 using PicturePile::SetMinContentsScale
;
44 using PicturePile::SetTileGridSize
;
46 PictureMap
& picture_map() { return picture_map_
; }
47 const gfx::Rect
& recorded_viewport() const { return recorded_viewport_
; }
49 bool CanRasterLayerRect(gfx::Rect layer_rect
) {
50 layer_rect
.Intersect(gfx::Rect(tiling_
.tiling_size()));
51 if (recorded_viewport_
.Contains(layer_rect
))
53 return CanRasterSlowTileCheck(layer_rect
);
56 bool HasRecordings() const { return has_any_recordings_
; }
58 void SetRecordedViewport(const gfx::Rect
& viewport
) {
59 recorded_viewport_
= viewport
;
62 void SetHasAnyRecordings(bool has_recordings
) {
63 has_any_recordings_
= has_recordings
;
66 void SetClearCanvasWithDebugColor(bool clear
) {
67 clear_canvas_with_debug_color_
= clear
;
70 void SetPlaybackAllowedEvent(base::WaitableEvent
* event
) {
71 playback_allowed_event_
= event
;
74 TilingData
& tiling() { return tiling_
; }
76 bool is_solid_color() const { return is_solid_color_
; }
77 SkColor
solid_color() const { return solid_color_
; }
78 void SetIsSolidColor(bool is_solid
) { is_solid_color_
= is_solid
; }
80 void SetPixelRecordDistance(int d
) { pixel_record_distance_
= d
; }
82 void add_draw_rect(const gfx::RectF
& rect
) {
83 client_
.add_draw_rect(rect
, default_paint_
);
86 void add_draw_bitmap(const SkBitmap
& bitmap
, const gfx::Point
& point
) {
87 client_
.add_draw_bitmap(bitmap
, point
, default_paint_
);
90 void add_draw_rect_with_paint(const gfx::RectF
& rect
, const SkPaint
& paint
) {
91 client_
.add_draw_rect(rect
, paint
);
94 void add_draw_bitmap_with_paint(const SkBitmap
& bitmap
,
95 const gfx::Point
& point
,
96 const SkPaint
& paint
) {
97 client_
.add_draw_bitmap(bitmap
, point
, paint
);
100 void set_default_paint(const SkPaint
& paint
) { default_paint_
= paint
; }
102 void AddRecordingAt(int x
, int y
);
103 void RemoveRecordingAt(int x
, int y
);
104 bool HasRecordingAt(int x
, int y
) const;
105 int num_tiles_x() const { return tiling_
.num_tiles_x(); }
106 int num_tiles_y() const { return tiling_
.num_tiles_y(); }
110 base::WaitableEvent
* playback_allowed_event_
;
112 FakeContentLayerClient client_
;
113 SkPaint default_paint_
;
118 #endif // CC_TEST_FAKE_PICTURE_PILE_H_