Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / cc / test / fake_content_layer_client.cc
blobb0dacb32fa03b436575cb60a66d0118098cc32d6
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/playback/clip_display_item.h"
8 #include "cc/playback/drawing_display_item.h"
9 #include "cc/playback/transform_display_item.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkPictureRecorder.h"
12 #include "ui/gfx/skia_util.h"
14 namespace cc {
16 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap,
17 const gfx::Point& point,
18 const SkPaint& paint)
19 : bitmap(bitmap), point(point), paint(paint) {
22 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap,
23 const gfx::Transform& transform,
24 const SkPaint& paint)
25 : bitmap(bitmap), transform(transform), paint(paint) {
28 FakeContentLayerClient::BitmapData::~BitmapData() {
31 FakeContentLayerClient::FakeContentLayerClient()
32 : fill_with_nonsolid_color_(false), last_canvas_(NULL) {
35 FakeContentLayerClient::~FakeContentLayerClient() {
38 void FakeContentLayerClient::PaintContents(
39 SkCanvas* canvas,
40 const gfx::Rect& paint_rect,
41 PaintingControlSetting painting_control) {
42 last_canvas_ = canvas;
43 last_painting_control_ = painting_control;
45 canvas->clipRect(gfx::RectToSkRect(paint_rect));
46 for (RectPaintVector::const_iterator it = draw_rects_.begin();
47 it != draw_rects_.end(); ++it) {
48 const gfx::RectF& draw_rect = it->first;
49 const SkPaint& paint = it->second;
50 canvas->drawRectCoords(draw_rect.x(),
51 draw_rect.y(),
52 draw_rect.right(),
53 draw_rect.bottom(),
54 paint);
57 for (BitmapVector::const_iterator it = draw_bitmaps_.begin();
58 it != draw_bitmaps_.end(); ++it) {
59 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint);
62 if (fill_with_nonsolid_color_) {
63 gfx::RectF draw_rect = paint_rect;
64 bool red = true;
65 while (!draw_rect.IsEmpty()) {
66 SkPaint paint;
67 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE);
68 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint);
69 draw_rect.Inset(1, 1);
74 scoped_refptr<DisplayItemList>
75 FakeContentLayerClient::PaintContentsToDisplayList(
76 const gfx::Rect& clip,
77 PaintingControlSetting painting_control) {
78 // Cached picture is used because unit tests expect to be able to
79 // use GatherPixelRefs.
80 const bool use_cached_picture = true;
81 scoped_refptr<DisplayItemList> display_list =
82 DisplayItemList::Create(clip, use_cached_picture);
83 SkPictureRecorder recorder;
84 skia::RefPtr<SkCanvas> canvas;
85 skia::RefPtr<SkPicture> picture;
86 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>();
87 item->SetNew(clip, std::vector<SkRRect>());
89 for (RectPaintVector::const_iterator it = draw_rects_.begin();
90 it != draw_rects_.end(); ++it) {
91 const gfx::RectF& draw_rect = it->first;
92 const SkPaint& paint = it->second;
93 canvas =
94 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
95 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(),
96 draw_rect.height(), paint);
97 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
98 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
99 item->SetNew(picture.Pass());
102 for (BitmapVector::const_iterator it = draw_bitmaps_.begin();
103 it != draw_bitmaps_.end(); ++it) {
104 if (!it->transform.IsIdentity()) {
105 auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>();
106 item->SetNew(it->transform);
108 canvas = skia::SharePtr(
109 recorder.beginRecording(it->bitmap.width(), it->bitmap.height()));
110 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint);
111 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
112 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
113 item->SetNew(picture.Pass());
114 if (!it->transform.IsIdentity()) {
115 display_list->CreateAndAppendItem<EndTransformDisplayItem>();
119 if (fill_with_nonsolid_color_) {
120 gfx::RectF draw_rect = clip;
121 bool red = true;
122 while (!draw_rect.IsEmpty()) {
123 SkPaint paint;
124 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE);
125 canvas = skia::SharePtr(
126 recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
127 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint);
128 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
129 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
130 item->SetNew(picture.Pass());
131 draw_rect.Inset(1, 1);
135 display_list->CreateAndAppendItem<EndClipDisplayItem>();
137 display_list->Finalize();
138 return display_list;
141 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; }
143 } // namespace cc