Add Apps.AppListSearchQueryLength UMA histogram.
[chromium-blink-merge.git] / cc / test / fake_content_layer_client.cc
blobdce5e6ecba57d27c2a37e28d2e3c30c0bc593808
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 "cc/resources/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 void FakeContentLayerClient::PaintContentsToDisplayList(
75 DisplayItemList* display_list,
76 const gfx::Rect& clip,
77 PaintingControlSetting painting_control) {
78 SkPictureRecorder recorder;
79 skia::RefPtr<SkCanvas> canvas;
80 skia::RefPtr<SkPicture> picture;
81 auto* item = display_list->CreateAndAppendItem<ClipDisplayItem>();
82 item->SetNew(clip, std::vector<SkRRect>());
84 for (RectPaintVector::const_iterator it = draw_rects_.begin();
85 it != draw_rects_.end(); ++it) {
86 const gfx::RectF& draw_rect = it->first;
87 const SkPaint& paint = it->second;
88 canvas =
89 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
90 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(),
91 draw_rect.height(), paint);
92 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
93 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
94 item->SetNew(picture.Pass());
97 for (BitmapVector::const_iterator it = draw_bitmaps_.begin();
98 it != draw_bitmaps_.end(); ++it) {
99 if (!it->transform.IsIdentity()) {
100 auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>();
101 item->SetNew(it->transform);
103 canvas = skia::SharePtr(
104 recorder.beginRecording(it->bitmap.width(), it->bitmap.height()));
105 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint);
106 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
107 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
108 item->SetNew(picture.Pass());
109 if (!it->transform.IsIdentity()) {
110 display_list->CreateAndAppendItem<EndTransformDisplayItem>();
114 if (fill_with_nonsolid_color_) {
115 gfx::RectF draw_rect = clip;
116 bool red = true;
117 while (!draw_rect.IsEmpty()) {
118 SkPaint paint;
119 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE);
120 canvas = skia::SharePtr(
121 recorder.beginRecording(gfx::RectFToSkRect(draw_rect)));
122 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint);
123 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
124 auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>();
125 item->SetNew(picture.Pass());
126 draw_rect.Inset(1, 1);
130 display_list->CreateAndAppendItem<EndClipDisplayItem>();
133 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; }
135 } // namespace cc