Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: cc/playback/display_item_list_unittest.cc

Issue 2710153004: cc: Fix up code to work with concrete cc paint types (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/discardable_image_map_unittest.cc ('k') | cc/playback/drawing_display_item.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/playback/display_item_list.h" 5 #include "cc/playback/display_item_list.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "cc/output/filter_operation.h" 12 #include "cc/output/filter_operation.h"
13 #include "cc/output/filter_operations.h" 13 #include "cc/output/filter_operations.h"
14 #include "cc/paint/paint_canvas.h"
15 #include "cc/paint/paint_flags.h"
16 #include "cc/paint/paint_record.h"
17 #include "cc/paint/paint_recorder.h"
18 #include "cc/paint/paint_surface.h"
14 #include "cc/playback/clip_display_item.h" 19 #include "cc/playback/clip_display_item.h"
15 #include "cc/playback/clip_path_display_item.h" 20 #include "cc/playback/clip_path_display_item.h"
16 #include "cc/playback/compositing_display_item.h" 21 #include "cc/playback/compositing_display_item.h"
17 #include "cc/playback/drawing_display_item.h" 22 #include "cc/playback/drawing_display_item.h"
18 #include "cc/playback/filter_display_item.h" 23 #include "cc/playback/filter_display_item.h"
19 #include "cc/playback/float_clip_display_item.h" 24 #include "cc/playback/float_clip_display_item.h"
20 #include "cc/playback/transform_display_item.h" 25 #include "cc/playback/transform_display_item.h"
21 #include "cc/test/geometry_test_utils.h" 26 #include "cc/test/geometry_test_utils.h"
22 #include "cc/test/skia_common.h" 27 #include "cc/test/skia_common.h"
23 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 30 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/skia/include/core/SkCanvas.h"
27 #include "third_party/skia/include/core/SkColor.h" 31 #include "third_party/skia/include/core/SkColor.h"
28 #include "third_party/skia/include/core/SkPictureRecorder.h"
29 #include "third_party/skia/include/core/SkSurface.h"
30
31 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 32 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
32 #include "third_party/skia/include/effects/SkImageSource.h" 33 #include "third_party/skia/include/effects/SkImageSource.h"
33 #include "third_party/skia/include/utils/SkPictureUtils.h"
34 #include "ui/gfx/geometry/rect.h" 34 #include "ui/gfx/geometry/rect.h"
35 #include "ui/gfx/geometry/rect_conversions.h" 35 #include "ui/gfx/geometry/rect_conversions.h"
36 #include "ui/gfx/skia_util.h" 36 #include "ui/gfx/skia_util.h"
37 37
38 namespace cc { 38 namespace cc {
39 39
40 namespace { 40 namespace {
41 41
42 const gfx::Rect kVisualRect(0, 0, 42, 42); 42 const gfx::Rect kVisualRect(0, 0, 42, 42);
43 43
44 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) { 44 sk_sp<const PaintRecord> CreateRectPicture(const gfx::Rect& bounds) {
45 SkPictureRecorder recorder; 45 PaintRecorder recorder;
46 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); 46 PaintCanvas* canvas =
47 recorder.beginRecording(bounds.width(), bounds.height());
47 canvas->drawRect( 48 canvas->drawRect(
48 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), 49 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
49 SkPaint()); 50 PaintFlags());
50 return recorder.finishRecordingAsPicture(); 51 return recorder.finishRecordingAsPicture();
51 } 52 }
52 53
53 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, 54 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list,
54 const gfx::Size& layer_size) { 55 const gfx::Size& layer_size) {
55 gfx::PointF offset(2.f, 3.f); 56 gfx::PointF offset(2.f, 3.f);
56 SkPictureRecorder recorder; 57 PaintRecorder recorder;
57 58
58 SkPaint red_paint; 59 PaintFlags red_paint;
59 red_paint.setColor(SK_ColorRED); 60 red_paint.setColor(SK_ColorRED);
60 61
61 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( 62 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
62 offset.x(), offset.y(), layer_size.width(), layer_size.height())); 63 offset.x(), offset.y(), layer_size.width(), layer_size.height()));
63 canvas->translate(offset.x(), offset.y()); 64 canvas->translate(offset.x(), offset.y());
64 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); 65 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
65 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 66 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
66 kVisualRect, recorder.finishRecordingAsPicture()); 67 kVisualRect, recorder.finishRecordingAsPicture());
67 } 68 }
68 69
69 } // namespace 70 } // namespace
70 71
71 TEST(DisplayItemListTest, SingleDrawingItem) { 72 TEST(DisplayItemListTest, SingleDrawingItem) {
72 gfx::Rect layer_rect(100, 100); 73 gfx::Rect layer_rect(100, 100);
73 SkPictureRecorder recorder; 74 PaintRecorder recorder;
74 SkPaint blue_paint; 75 PaintFlags blue_flags;
75 blue_paint.setColor(SK_ColorBLUE); 76 blue_flags.setColor(SK_ColorBLUE);
76 SkPaint red_paint; 77 PaintFlags red_paint;
77 red_paint.setColor(SK_ColorRED); 78 red_paint.setColor(SK_ColorRED);
78 unsigned char pixels[4 * 100 * 100] = {0}; 79 unsigned char pixels[4 * 100 * 100] = {0};
79 auto list = make_scoped_refptr(new DisplayItemList); 80 auto list = make_scoped_refptr(new DisplayItemList);
80 81
81 gfx::PointF offset(8.f, 9.f); 82 gfx::PointF offset(8.f, 9.f);
82 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 83 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
83 SkCanvas* canvas = 84 PaintCanvas* canvas =
84 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); 85 recorder.beginRecording(gfx::RectFToSkRect(recording_rect));
85 canvas->translate(offset.x(), offset.y()); 86 canvas->translate(offset.x(), offset.y());
86 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 87 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
87 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 88 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags);
88 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 89 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
89 kVisualRect, recorder.finishRecordingAsPicture()); 90 kVisualRect, recorder.finishRecordingAsPicture());
90 list->Finalize(); 91 list->Finalize();
91 DrawDisplayList(pixels, layer_rect, list); 92 DrawDisplayList(pixels, layer_rect, list);
92 93
93 SkBitmap expected_bitmap; 94 SkBitmap expected_bitmap;
94 unsigned char expected_pixels[4 * 100 * 100] = {0}; 95 unsigned char expected_pixels[4 * 100 * 100] = {0};
95 SkImageInfo info = 96 SkImageInfo info =
96 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 97 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
97 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 98 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
98 SkCanvas expected_canvas(expected_bitmap); 99 PaintCanvas expected_canvas(expected_bitmap);
99 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 100 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
100 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), 101 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(),
101 60.f + offset.x(), 60.f + offset.y(), 102 60.f + offset.x(), 60.f + offset.y(),
102 red_paint); 103 red_paint);
103 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), 104 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(),
104 75.f + offset.x(), 75.f + offset.y(), 105 75.f + offset.x(), 75.f + offset.y(),
105 blue_paint); 106 blue_flags);
106 107
107 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 108 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
108 } 109 }
109 110
110 TEST(DisplayItemListTest, ClipItem) { 111 TEST(DisplayItemListTest, ClipItem) {
111 gfx::Rect layer_rect(100, 100); 112 gfx::Rect layer_rect(100, 100);
112 SkPictureRecorder recorder; 113 PaintRecorder recorder;
113 SkPaint blue_paint; 114 PaintFlags blue_flags;
114 blue_paint.setColor(SK_ColorBLUE); 115 blue_flags.setColor(SK_ColorBLUE);
115 SkPaint red_paint; 116 PaintFlags red_paint;
116 red_paint.setColor(SK_ColorRED); 117 red_paint.setColor(SK_ColorRED);
117 unsigned char pixels[4 * 100 * 100] = {0}; 118 unsigned char pixels[4 * 100 * 100] = {0};
118 auto list = make_scoped_refptr(new DisplayItemList); 119 auto list = make_scoped_refptr(new DisplayItemList);
119 120
120 gfx::PointF first_offset(8.f, 9.f); 121 gfx::PointF first_offset(8.f, 9.f);
121 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 122 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
122 SkCanvas* canvas = 123 PaintCanvas* canvas =
123 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); 124 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
124 canvas->translate(first_offset.x(), first_offset.y()); 125 canvas->translate(first_offset.x(), first_offset.y());
125 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 126 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
126 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 127 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
127 kVisualRect, recorder.finishRecordingAsPicture()); 128 kVisualRect, recorder.finishRecordingAsPicture());
128 129
129 gfx::Rect clip_rect(60, 60, 10, 10); 130 gfx::Rect clip_rect(60, 60, 10, 10);
130 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( 131 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
131 clip_rect, std::vector<SkRRect>(), true); 132 clip_rect, std::vector<SkRRect>(), true);
132 133
133 gfx::PointF second_offset(2.f, 3.f); 134 gfx::PointF second_offset(2.f, 3.f);
134 gfx::RectF second_recording_rect(second_offset, 135 gfx::RectF second_recording_rect(second_offset,
135 gfx::SizeF(layer_rect.size())); 136 gfx::SizeF(layer_rect.size()));
136 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); 137 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect));
137 canvas->translate(second_offset.x(), second_offset.y()); 138 canvas->translate(second_offset.x(), second_offset.y());
138 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 139 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags);
139 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 140 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
140 kVisualRect, recorder.finishRecordingAsPicture()); 141 kVisualRect, recorder.finishRecordingAsPicture());
141 142
142 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 143 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
143 list->Finalize(); 144 list->Finalize();
144 145
145 DrawDisplayList(pixels, layer_rect, list); 146 DrawDisplayList(pixels, layer_rect, list);
146 147
147 SkBitmap expected_bitmap; 148 SkBitmap expected_bitmap;
148 unsigned char expected_pixels[4 * 100 * 100] = {0}; 149 unsigned char expected_pixels[4 * 100 * 100] = {0};
149 SkImageInfo info = 150 SkImageInfo info =
150 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 151 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
151 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 152 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
152 SkCanvas expected_canvas(expected_bitmap); 153 PaintCanvas expected_canvas(expected_bitmap);
153 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 154 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
154 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), 155 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(),
155 60.f + first_offset.x(), 156 60.f + first_offset.x(),
156 60.f + first_offset.y(), red_paint); 157 60.f + first_offset.y(), red_paint);
157 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); 158 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect));
158 expected_canvas.drawRectCoords( 159 expected_canvas.drawRectCoords(
159 50.f + second_offset.x(), 50.f + second_offset.y(), 160 50.f + second_offset.x(), 50.f + second_offset.y(),
160 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 161 75.f + second_offset.x(), 75.f + second_offset.y(), blue_flags);
161 162
162 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 163 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
163 } 164 }
164 165
165 TEST(DisplayItemListTest, TransformItem) { 166 TEST(DisplayItemListTest, TransformItem) {
166 gfx::Rect layer_rect(100, 100); 167 gfx::Rect layer_rect(100, 100);
167 SkPictureRecorder recorder; 168 PaintRecorder recorder;
168 SkPaint blue_paint; 169 PaintFlags blue_flags;
169 blue_paint.setColor(SK_ColorBLUE); 170 blue_flags.setColor(SK_ColorBLUE);
170 SkPaint red_paint; 171 PaintFlags red_paint;
171 red_paint.setColor(SK_ColorRED); 172 red_paint.setColor(SK_ColorRED);
172 unsigned char pixels[4 * 100 * 100] = {0}; 173 unsigned char pixels[4 * 100 * 100] = {0};
173 auto list = make_scoped_refptr(new DisplayItemList); 174 auto list = make_scoped_refptr(new DisplayItemList);
174 175
175 gfx::PointF first_offset(8.f, 9.f); 176 gfx::PointF first_offset(8.f, 9.f);
176 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 177 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
177 SkCanvas* canvas = 178 PaintCanvas* canvas =
178 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); 179 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
179 canvas->translate(first_offset.x(), first_offset.y()); 180 canvas->translate(first_offset.x(), first_offset.y());
180 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 181 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
181 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 182 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
182 kVisualRect, recorder.finishRecordingAsPicture()); 183 kVisualRect, recorder.finishRecordingAsPicture());
183 184
184 gfx::Transform transform; 185 gfx::Transform transform;
185 transform.Rotate(45.0); 186 transform.Rotate(45.0);
186 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); 187 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
187 188
188 gfx::PointF second_offset(2.f, 3.f); 189 gfx::PointF second_offset(2.f, 3.f);
189 gfx::RectF second_recording_rect(second_offset, 190 gfx::RectF second_recording_rect(second_offset,
190 gfx::SizeF(layer_rect.size())); 191 gfx::SizeF(layer_rect.size()));
191 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); 192 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect));
192 canvas->translate(second_offset.x(), second_offset.y()); 193 canvas->translate(second_offset.x(), second_offset.y());
193 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 194 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags);
194 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 195 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
195 kVisualRect, recorder.finishRecordingAsPicture()); 196 kVisualRect, recorder.finishRecordingAsPicture());
196 197
197 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); 198 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
198 list->Finalize(); 199 list->Finalize();
199 200
200 DrawDisplayList(pixels, layer_rect, list); 201 DrawDisplayList(pixels, layer_rect, list);
201 202
202 SkBitmap expected_bitmap; 203 SkBitmap expected_bitmap;
203 unsigned char expected_pixels[4 * 100 * 100] = {0}; 204 unsigned char expected_pixels[4 * 100 * 100] = {0};
204 SkImageInfo info = 205 SkImageInfo info =
205 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 206 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
206 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 207 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
207 SkCanvas expected_canvas(expected_bitmap); 208 PaintCanvas expected_canvas(expected_bitmap);
208 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 209 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
209 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), 210 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(),
210 60.f + first_offset.x(), 211 60.f + first_offset.x(),
211 60.f + first_offset.y(), red_paint); 212 60.f + first_offset.y(), red_paint);
212 expected_canvas.setMatrix(transform.matrix()); 213 expected_canvas.setMatrix(transform.matrix());
213 expected_canvas.drawRectCoords( 214 expected_canvas.drawRectCoords(
214 50.f + second_offset.x(), 50.f + second_offset.y(), 215 50.f + second_offset.x(), 50.f + second_offset.y(),
215 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 216 75.f + second_offset.x(), 75.f + second_offset.y(), blue_flags);
216 217
217 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 218 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
218 } 219 }
219 220
220 TEST(DisplayItemListTest, FilterItem) { 221 TEST(DisplayItemListTest, FilterItem) {
221 gfx::Rect layer_rect(100, 100); 222 gfx::Rect layer_rect(100, 100);
222 FilterOperations filters; 223 FilterOperations filters;
223 unsigned char pixels[4 * 100 * 100] = {0}; 224 unsigned char pixels[4 * 100 * 100] = {0};
224 auto list = make_scoped_refptr(new DisplayItemList); 225 auto list = make_scoped_refptr(new DisplayItemList);
225 226
(...skipping 15 matching lines...) Expand all
241 // below. 242 // below.
242 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); 243 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image);
243 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); 244 filters.Append(FilterOperation::CreateReferenceFilter(image_filter));
244 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); 245 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
245 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); 246 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f);
246 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( 247 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>(
247 filters, filter_bounds, filter_bounds.origin()); 248 filters, filter_bounds, filter_bounds.origin());
248 249
249 // Include a rect drawing so that filter is actually applied to something. 250 // Include a rect drawing so that filter is actually applied to something.
250 { 251 {
251 SkPictureRecorder recorder; 252 PaintRecorder recorder;
252 253
253 SkPaint red_paint; 254 PaintFlags red_paint;
254 red_paint.setColor(SK_ColorRED); 255 red_paint.setColor(SK_ColorRED);
255 256
256 SkCanvas* canvas = recorder.beginRecording( 257 PaintCanvas* canvas = recorder.beginRecording(
257 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); 258 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height()));
258 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), 259 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(),
259 filter_bounds.right(), filter_bounds.bottom(), 260 filter_bounds.right(), filter_bounds.bottom(),
260 red_paint); 261 red_paint);
261 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 262 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
262 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); 263 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture());
263 } 264 }
264 265
265 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); 266 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>();
266 list->Finalize(); 267 list->Finalize();
267 268
268 DrawDisplayList(pixels, layer_rect, list); 269 DrawDisplayList(pixels, layer_rect, list);
269 270
270 SkBitmap expected_bitmap; 271 SkBitmap expected_bitmap;
271 unsigned char expected_pixels[4 * 100 * 100] = {0}; 272 unsigned char expected_pixels[4 * 100 * 100] = {0};
272 SkPaint paint; 273 PaintFlags paint;
273 paint.setColor(SkColorSetRGB(64, 64, 64)); 274 paint.setColor(SkColorSetRGB(64, 64, 64));
274 SkImageInfo info = 275 SkImageInfo info =
275 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 276 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
276 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 277 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
277 SkCanvas expected_canvas(expected_bitmap); 278 PaintCanvas expected_canvas(expected_bitmap);
278 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); 279 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint);
279 280
280 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 281 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
281 } 282 }
282 283
283 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 284 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
284 const int kNumCommandsInTestSkPicture = 1000; 285 const int kNumCommandsInTestSkPicture = 1000;
285 size_t memory_usage; 286 size_t memory_usage;
286 287
287 // Make an SkPicture whose size is known. 288 // Make an PaintRecord whose size is known.
288 gfx::Rect layer_rect(100, 100); 289 gfx::Rect layer_rect(100, 100);
289 SkPictureRecorder recorder; 290 PaintRecorder recorder;
290 SkPaint blue_paint; 291 PaintFlags blue_flags;
291 blue_paint.setColor(SK_ColorBLUE); 292 blue_flags.setColor(SK_ColorBLUE);
292 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 293 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
293 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 294 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
294 canvas->drawPaint(blue_paint); 295 canvas->drawRect(SkRect(), blue_flags);
295 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 296 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
296 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 297 size_t record_size = record->approximateBytesUsed();
297 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 298 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect));
298 299
299 auto list = make_scoped_refptr(new DisplayItemList); 300 auto list = make_scoped_refptr(new DisplayItemList);
300 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); 301 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, record);
301 list->Finalize(); 302 list->Finalize();
302 memory_usage = list->ApproximateMemoryUsage(); 303 memory_usage = list->ApproximateMemoryUsage();
303 EXPECT_GE(memory_usage, picture_size); 304 EXPECT_GE(memory_usage, record_size);
304 EXPECT_LE(memory_usage, 2 * picture_size); 305 EXPECT_LE(memory_usage, 2 * record_size);
305 } 306 }
306 307
307 TEST(DisplayItemListTest, AsValueWithNoItems) { 308 TEST(DisplayItemListTest, AsValueWithNoItems) {
308 auto list = make_scoped_refptr(new DisplayItemList); 309 auto list = make_scoped_refptr(new DisplayItemList);
309 list->SetRetainVisualRectsForTesting(true); 310 list->SetRetainVisualRectsForTesting(true);
310 list->Finalize(); 311 list->Finalize();
311 312
312 std::string value = list->AsValue(true)->ToString(); 313 std::string value = list->AsValue(true)->ToString();
313 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos); 314 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos);
314 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 315 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 662 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
662 663
663 EXPECT_EQ(4u, list->size()); 664 EXPECT_EQ(4u, list->size());
664 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); 665 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0));
665 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); 666 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1));
666 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); 667 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2));
667 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); 668 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3));
668 } 669 }
669 670
670 } // namespace cc 671 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/discardable_image_map_unittest.cc ('k') | cc/playback/drawing_display_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698