1 // Copyright 2012 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 #include "cc/test/fake_content_layer_client.h"
7 #include "cc/resources/clip_display_item.h"
8 #include "cc/resources/drawing_display_item.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPictureRecorder.h"
11 #include "ui/gfx/skia_util.h"
15 FakeContentLayerClient::FakeContentLayerClient()
16 : fill_with_nonsolid_color_(false), last_canvas_(NULL
) {
19 FakeContentLayerClient::~FakeContentLayerClient() {
22 void FakeContentLayerClient::PaintContents(
24 const gfx::Rect
& paint_rect
,
25 PaintingControlSetting painting_control
) {
26 last_canvas_
= canvas
;
27 last_painting_control_
= painting_control
;
29 canvas
->clipRect(gfx::RectToSkRect(paint_rect
));
30 for (RectPaintVector::const_iterator it
= draw_rects_
.begin();
31 it
!= draw_rects_
.end(); ++it
) {
32 const gfx::RectF
& draw_rect
= it
->first
;
33 const SkPaint
& paint
= it
->second
;
34 canvas
->drawRectCoords(draw_rect
.x(),
41 for (BitmapVector::const_iterator it
= draw_bitmaps_
.begin();
42 it
!= draw_bitmaps_
.end(); ++it
) {
43 canvas
->drawBitmap(it
->bitmap
, it
->point
.x(), it
->point
.y(), &it
->paint
);
46 if (fill_with_nonsolid_color_
) {
47 gfx::RectF draw_rect
= paint_rect
;
49 while (!draw_rect
.IsEmpty()) {
51 paint
.setColor(red
? SK_ColorRED
: SK_ColorBLUE
);
52 canvas
->drawRect(gfx::RectFToSkRect(draw_rect
), paint
);
53 draw_rect
.Inset(1, 1);
58 scoped_refptr
<DisplayItemList
>
59 FakeContentLayerClient::PaintContentsToDisplayList(
60 const gfx::Rect
& clip
,
61 PaintingControlSetting painting_control
) {
62 SkPictureRecorder recorder
;
63 skia::RefPtr
<SkCanvas
> canvas
;
64 skia::RefPtr
<SkPicture
> picture
;
65 scoped_refptr
<DisplayItemList
> list
= DisplayItemList::Create();
66 list
->AppendItem(ClipDisplayItem::Create(clip
, std::vector
<SkRRect
>()));
68 for (RectPaintVector::const_iterator it
= draw_rects_
.begin();
69 it
!= draw_rects_
.end(); ++it
) {
70 const gfx::RectF
& draw_rect
= it
->first
;
71 const SkPaint
& paint
= it
->second
;
73 skia::SharePtr(recorder
.beginRecording(gfx::RectFToSkRect(draw_rect
)));
74 canvas
->drawRectCoords(0.f
, 0.f
, draw_rect
.width(), draw_rect
.height(),
76 picture
= skia::AdoptRef(recorder
.endRecording());
77 list
->AppendItem(DrawingDisplayItem::Create(picture
));
80 for (BitmapVector::const_iterator it
= draw_bitmaps_
.begin();
81 it
!= draw_bitmaps_
.end(); ++it
) {
82 canvas
= skia::SharePtr(
83 recorder
.beginRecording(it
->bitmap
.width(), it
->bitmap
.height()));
84 canvas
->drawBitmap(it
->bitmap
, 0.f
, 0.f
, &it
->paint
);
85 picture
= skia::AdoptRef(recorder
.endRecording());
86 list
->AppendItem(DrawingDisplayItem::Create(picture
));
89 if (fill_with_nonsolid_color_
) {
90 gfx::RectF draw_rect
= clip
;
92 while (!draw_rect
.IsEmpty()) {
94 paint
.setColor(red
? SK_ColorRED
: SK_ColorBLUE
);
95 canvas
= skia::SharePtr(
96 recorder
.beginRecording(gfx::RectFToSkRect(draw_rect
)));
97 canvas
->drawRect(gfx::RectFToSkRect(draw_rect
), paint
);
98 picture
= skia::AdoptRef(recorder
.endRecording());
99 list
->AppendItem(DrawingDisplayItem::Create(picture
));
100 draw_rect
.Inset(1, 1);
104 list
->AppendItem(EndClipDisplayItem::Create());
108 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; }