OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/test/fake_content_layer_client.h" | 5 #include "cc/test/fake_content_layer_client.h" |
6 | 6 |
7 #include "cc/resources/clip_display_item.h" | 7 #include "cc/resources/clip_display_item.h" |
8 #include "cc/resources/drawing_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" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
11 #include "third_party/skia/include/core/SkPictureRecorder.h" | 10 #include "third_party/skia/include/core/SkPictureRecorder.h" |
12 #include "ui/gfx/skia_util.h" | 11 #include "ui/gfx/skia_util.h" |
13 | 12 |
14 namespace cc { | 13 namespace cc { |
15 | 14 |
16 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap, | |
17 const gfx::Point& point, | |
18 const SkPaint& paint) | |
19 : bitmap(bitmap), point(point), paint(paint) { | |
20 } | |
21 | |
22 FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap, | |
23 const gfx::Transform& transform, | |
24 const SkPaint& paint) | |
25 : bitmap(bitmap), transform(transform), paint(paint) { | |
26 } | |
27 | |
28 FakeContentLayerClient::BitmapData::~BitmapData() { | |
29 } | |
30 | |
31 FakeContentLayerClient::FakeContentLayerClient() | 15 FakeContentLayerClient::FakeContentLayerClient() |
32 : fill_with_nonsolid_color_(false), last_canvas_(NULL) { | 16 : fill_with_nonsolid_color_(false), last_canvas_(NULL) { |
33 } | 17 } |
34 | 18 |
35 FakeContentLayerClient::~FakeContentLayerClient() { | 19 FakeContentLayerClient::~FakeContentLayerClient() { |
36 } | 20 } |
37 | 21 |
38 void FakeContentLayerClient::PaintContents( | 22 void FakeContentLayerClient::PaintContents( |
39 SkCanvas* canvas, | 23 SkCanvas* canvas, |
40 const gfx::Rect& paint_rect, | 24 const gfx::Rect& paint_rect, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 canvas = | 72 canvas = |
89 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 73 skia::SharePtr(recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
90 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(), | 74 canvas->drawRectCoords(draw_rect.x(), draw_rect.y(), draw_rect.width(), |
91 draw_rect.height(), paint); | 75 draw_rect.height(), paint); |
92 picture = skia::AdoptRef(recorder.endRecording()); | 76 picture = skia::AdoptRef(recorder.endRecording()); |
93 list->AppendItem(DrawingDisplayItem::Create(picture)); | 77 list->AppendItem(DrawingDisplayItem::Create(picture)); |
94 } | 78 } |
95 | 79 |
96 for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); | 80 for (BitmapVector::const_iterator it = draw_bitmaps_.begin(); |
97 it != draw_bitmaps_.end(); ++it) { | 81 it != draw_bitmaps_.end(); ++it) { |
98 if (!it->transform.IsIdentity()) { | |
99 list->AppendItem(TransformDisplayItem::Create(it->transform)); | |
100 } | |
101 canvas = skia::SharePtr( | 82 canvas = skia::SharePtr( |
102 recorder.beginRecording(it->bitmap.width(), it->bitmap.height())); | 83 recorder.beginRecording(it->bitmap.width(), it->bitmap.height())); |
103 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); | 84 canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); |
104 picture = skia::AdoptRef(recorder.endRecording()); | 85 picture = skia::AdoptRef(recorder.endRecording()); |
105 list->AppendItem(DrawingDisplayItem::Create(picture)); | 86 list->AppendItem(DrawingDisplayItem::Create(picture)); |
106 if (!it->transform.IsIdentity()) { | |
107 list->AppendItem(EndTransformDisplayItem::Create()); | |
108 } | |
109 } | 87 } |
110 | 88 |
111 if (fill_with_nonsolid_color_) { | 89 if (fill_with_nonsolid_color_) { |
112 gfx::RectF draw_rect = clip; | 90 gfx::RectF draw_rect = clip; |
113 bool red = true; | 91 bool red = true; |
114 while (!draw_rect.IsEmpty()) { | 92 while (!draw_rect.IsEmpty()) { |
115 SkPaint paint; | 93 SkPaint paint; |
116 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); | 94 paint.setColor(red ? SK_ColorRED : SK_ColorBLUE); |
117 canvas = skia::SharePtr( | 95 canvas = skia::SharePtr( |
118 recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); | 96 recorder.beginRecording(gfx::RectFToSkRect(draw_rect))); |
119 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); | 97 canvas->drawRect(gfx::RectFToSkRect(draw_rect), paint); |
120 picture = skia::AdoptRef(recorder.endRecording()); | 98 picture = skia::AdoptRef(recorder.endRecording()); |
121 list->AppendItem(DrawingDisplayItem::Create(picture)); | 99 list->AppendItem(DrawingDisplayItem::Create(picture)); |
122 draw_rect.Inset(1, 1); | 100 draw_rect.Inset(1, 1); |
123 } | 101 } |
124 } | 102 } |
125 | 103 |
126 list->AppendItem(EndClipDisplayItem::Create()); | 104 list->AppendItem(EndClipDisplayItem::Create()); |
127 return list; | 105 return list; |
128 } | 106 } |
129 | 107 |
130 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } | 108 bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; } |
131 | 109 |
132 } // namespace cc | 110 } // namespace cc |
OLD | NEW |