| OLD | NEW |
| 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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const gfx::Size& layer_size) { | 55 const gfx::Size& layer_size) { |
| 56 gfx::PointF offset(2.f, 3.f); | 56 gfx::PointF offset(2.f, 3.f); |
| 57 PaintRecorder recorder; | 57 PaintRecorder recorder; |
| 58 | 58 |
| 59 PaintFlags red_paint; | 59 PaintFlags red_paint; |
| 60 red_paint.setColor(SK_ColorRED); | 60 red_paint.setColor(SK_ColorRED); |
| 61 | 61 |
| 62 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | 62 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
| 63 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | 63 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
| 64 canvas->translate(offset.x(), offset.y()); | 64 canvas->translate(offset.x(), offset.y()); |
| 65 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 65 canvas->drawRect(SkRect::MakeWH(4, 4), red_paint); |
| 66 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 66 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 67 kVisualRect, recorder.finishRecordingAsPicture()); | 67 kVisualRect, recorder.finishRecordingAsPicture()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 TEST(DisplayItemListTest, SingleDrawingItem) { | 72 TEST(DisplayItemListTest, SingleDrawingItem) { |
| 73 gfx::Rect layer_rect(100, 100); | 73 gfx::Rect layer_rect(100, 100); |
| 74 PaintRecorder recorder; | 74 PaintRecorder recorder; |
| 75 PaintFlags blue_flags; | 75 PaintFlags blue_flags; |
| 76 blue_flags.setColor(SK_ColorBLUE); | 76 blue_flags.setColor(SK_ColorBLUE); |
| 77 PaintFlags red_paint; | 77 PaintFlags red_paint; |
| 78 red_paint.setColor(SK_ColorRED); | 78 red_paint.setColor(SK_ColorRED); |
| 79 unsigned char pixels[4 * 100 * 100] = {0}; | 79 unsigned char pixels[4 * 100 * 100] = {0}; |
| 80 auto list = make_scoped_refptr(new DisplayItemList); | 80 auto list = make_scoped_refptr(new DisplayItemList); |
| 81 | 81 |
| 82 gfx::PointF offset(8.f, 9.f); | 82 gfx::PointF offset(8.f, 9.f); |
| 83 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 83 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
| 84 PaintCanvas* canvas = | 84 PaintCanvas* canvas = |
| 85 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 85 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
| 86 canvas->translate(offset.x(), offset.y()); | 86 canvas->translate(offset.x(), offset.y()); |
| 87 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 87 canvas->drawRect(SkRect::MakeLTRB(0.f, 0.f, 60.f, 60.f), red_paint); |
| 88 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags); | 88 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
| 89 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 89 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 90 kVisualRect, recorder.finishRecordingAsPicture()); | 90 kVisualRect, recorder.finishRecordingAsPicture()); |
| 91 list->Finalize(); | 91 list->Finalize(); |
| 92 DrawDisplayList(pixels, layer_rect, list); | 92 DrawDisplayList(pixels, layer_rect, list); |
| 93 | 93 |
| 94 SkBitmap expected_bitmap; | 94 SkBitmap expected_bitmap; |
| 95 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 95 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 96 SkImageInfo info = | 96 SkImageInfo info = |
| 97 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 97 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 98 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 98 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 99 PaintCanvas expected_canvas(expected_bitmap); | 99 PaintCanvas expected_canvas(expected_bitmap); |
| 100 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 100 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 101 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 101 expected_canvas.drawRect( |
| 102 60.f + offset.x(), 60.f + offset.y(), | 102 SkRect::MakeLTRB(0.f + offset.x(), 0.f + offset.y(), 60.f + offset.x(), |
| 103 red_paint); | 103 60.f + offset.y()), |
| 104 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 104 red_paint); |
| 105 75.f + offset.x(), 75.f + offset.y(), | 105 expected_canvas.drawRect( |
| 106 blue_flags); | 106 SkRect::MakeLTRB(50.f + offset.x(), 50.f + offset.y(), 75.f + offset.x(), |
| 107 75.f + offset.y()), |
| 108 blue_flags); |
| 107 | 109 |
| 108 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 110 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 TEST(DisplayItemListTest, ClipItem) { | 113 TEST(DisplayItemListTest, ClipItem) { |
| 112 gfx::Rect layer_rect(100, 100); | 114 gfx::Rect layer_rect(100, 100); |
| 113 PaintRecorder recorder; | 115 PaintRecorder recorder; |
| 114 PaintFlags blue_flags; | 116 PaintFlags blue_flags; |
| 115 blue_flags.setColor(SK_ColorBLUE); | 117 blue_flags.setColor(SK_ColorBLUE); |
| 116 PaintFlags red_paint; | 118 PaintFlags red_paint; |
| 117 red_paint.setColor(SK_ColorRED); | 119 red_paint.setColor(SK_ColorRED); |
| 118 unsigned char pixels[4 * 100 * 100] = {0}; | 120 unsigned char pixels[4 * 100 * 100] = {0}; |
| 119 auto list = make_scoped_refptr(new DisplayItemList); | 121 auto list = make_scoped_refptr(new DisplayItemList); |
| 120 | 122 |
| 121 gfx::PointF first_offset(8.f, 9.f); | 123 gfx::PointF first_offset(8.f, 9.f); |
| 122 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 124 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 123 PaintCanvas* canvas = | 125 PaintCanvas* canvas = |
| 124 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 126 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
| 125 canvas->translate(first_offset.x(), first_offset.y()); | 127 canvas->translate(first_offset.x(), first_offset.y()); |
| 126 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 128 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); |
| 127 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 129 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 128 kVisualRect, recorder.finishRecordingAsPicture()); | 130 kVisualRect, recorder.finishRecordingAsPicture()); |
| 129 | 131 |
| 130 gfx::Rect clip_rect(60, 60, 10, 10); | 132 gfx::Rect clip_rect(60, 60, 10, 10); |
| 131 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 133 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
| 132 clip_rect, std::vector<SkRRect>(), true); | 134 clip_rect, std::vector<SkRRect>(), true); |
| 133 | 135 |
| 134 gfx::PointF second_offset(2.f, 3.f); | 136 gfx::PointF second_offset(2.f, 3.f); |
| 135 gfx::RectF second_recording_rect(second_offset, | 137 gfx::RectF second_recording_rect(second_offset, |
| 136 gfx::SizeF(layer_rect.size())); | 138 gfx::SizeF(layer_rect.size())); |
| 137 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 139 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
| 138 canvas->translate(second_offset.x(), second_offset.y()); | 140 canvas->translate(second_offset.x(), second_offset.y()); |
| 139 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags); | 141 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
| 140 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 142 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 141 kVisualRect, recorder.finishRecordingAsPicture()); | 143 kVisualRect, recorder.finishRecordingAsPicture()); |
| 142 | 144 |
| 143 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 145 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
| 144 list->Finalize(); | 146 list->Finalize(); |
| 145 | 147 |
| 146 DrawDisplayList(pixels, layer_rect, list); | 148 DrawDisplayList(pixels, layer_rect, list); |
| 147 | 149 |
| 148 SkBitmap expected_bitmap; | 150 SkBitmap expected_bitmap; |
| 149 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 151 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 150 SkImageInfo info = | 152 SkImageInfo info = |
| 151 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 153 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 152 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 154 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 153 PaintCanvas expected_canvas(expected_bitmap); | 155 PaintCanvas expected_canvas(expected_bitmap); |
| 154 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 156 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 155 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 157 expected_canvas.drawRect( |
| 156 60.f + first_offset.x(), | 158 SkRect::MakeLTRB(0.f + first_offset.x(), 0.f + first_offset.y(), |
| 157 60.f + first_offset.y(), red_paint); | 159 60.f + first_offset.x(), 60.f + first_offset.y()), |
| 160 red_paint); |
| 158 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | 161 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); |
| 159 expected_canvas.drawRectCoords( | 162 expected_canvas.drawRect( |
| 160 50.f + second_offset.x(), 50.f + second_offset.y(), | 163 SkRect::MakeLTRB(50.f + second_offset.x(), 50.f + second_offset.y(), |
| 161 75.f + second_offset.x(), 75.f + second_offset.y(), blue_flags); | 164 75.f + second_offset.x(), 75.f + second_offset.y()), |
| 165 blue_flags); |
| 162 | 166 |
| 163 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 167 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 164 } | 168 } |
| 165 | 169 |
| 166 TEST(DisplayItemListTest, TransformItem) { | 170 TEST(DisplayItemListTest, TransformItem) { |
| 167 gfx::Rect layer_rect(100, 100); | 171 gfx::Rect layer_rect(100, 100); |
| 168 PaintRecorder recorder; | 172 PaintRecorder recorder; |
| 169 PaintFlags blue_flags; | 173 PaintFlags blue_flags; |
| 170 blue_flags.setColor(SK_ColorBLUE); | 174 blue_flags.setColor(SK_ColorBLUE); |
| 171 PaintFlags red_paint; | 175 PaintFlags red_paint; |
| 172 red_paint.setColor(SK_ColorRED); | 176 red_paint.setColor(SK_ColorRED); |
| 173 unsigned char pixels[4 * 100 * 100] = {0}; | 177 unsigned char pixels[4 * 100 * 100] = {0}; |
| 174 auto list = make_scoped_refptr(new DisplayItemList); | 178 auto list = make_scoped_refptr(new DisplayItemList); |
| 175 | 179 |
| 176 gfx::PointF first_offset(8.f, 9.f); | 180 gfx::PointF first_offset(8.f, 9.f); |
| 177 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 181 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
| 178 PaintCanvas* canvas = | 182 PaintCanvas* canvas = |
| 179 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 183 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
| 180 canvas->translate(first_offset.x(), first_offset.y()); | 184 canvas->translate(first_offset.x(), first_offset.y()); |
| 181 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 185 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); |
| 182 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 186 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 183 kVisualRect, recorder.finishRecordingAsPicture()); | 187 kVisualRect, recorder.finishRecordingAsPicture()); |
| 184 | 188 |
| 185 gfx::Transform transform; | 189 gfx::Transform transform; |
| 186 transform.Rotate(45.0); | 190 transform.Rotate(45.0); |
| 187 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | 191 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); |
| 188 | 192 |
| 189 gfx::PointF second_offset(2.f, 3.f); | 193 gfx::PointF second_offset(2.f, 3.f); |
| 190 gfx::RectF second_recording_rect(second_offset, | 194 gfx::RectF second_recording_rect(second_offset, |
| 191 gfx::SizeF(layer_rect.size())); | 195 gfx::SizeF(layer_rect.size())); |
| 192 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 196 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
| 193 canvas->translate(second_offset.x(), second_offset.y()); | 197 canvas->translate(second_offset.x(), second_offset.y()); |
| 194 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_flags); | 198 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
| 195 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 199 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 196 kVisualRect, recorder.finishRecordingAsPicture()); | 200 kVisualRect, recorder.finishRecordingAsPicture()); |
| 197 | 201 |
| 198 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 202 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
| 199 list->Finalize(); | 203 list->Finalize(); |
| 200 | 204 |
| 201 DrawDisplayList(pixels, layer_rect, list); | 205 DrawDisplayList(pixels, layer_rect, list); |
| 202 | 206 |
| 203 SkBitmap expected_bitmap; | 207 SkBitmap expected_bitmap; |
| 204 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 208 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 205 SkImageInfo info = | 209 SkImageInfo info = |
| 206 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 210 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 207 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 211 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 208 PaintCanvas expected_canvas(expected_bitmap); | 212 PaintCanvas expected_canvas(expected_bitmap); |
| 209 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 213 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 210 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 214 expected_canvas.drawRect( |
| 211 60.f + first_offset.x(), | 215 SkRect::MakeLTRB(0.f + first_offset.x(), 0.f + first_offset.y(), |
| 212 60.f + first_offset.y(), red_paint); | 216 60.f + first_offset.x(), 60.f + first_offset.y()), |
| 217 red_paint); |
| 213 expected_canvas.setMatrix(transform.matrix()); | 218 expected_canvas.setMatrix(transform.matrix()); |
| 214 expected_canvas.drawRectCoords( | 219 expected_canvas.drawRect( |
| 215 50.f + second_offset.x(), 50.f + second_offset.y(), | 220 SkRect::MakeLTRB(50.f + second_offset.x(), 50.f + second_offset.y(), |
| 216 75.f + second_offset.x(), 75.f + second_offset.y(), blue_flags); | 221 75.f + second_offset.x(), 75.f + second_offset.y()), |
| 222 blue_flags); |
| 217 | 223 |
| 218 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 224 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 219 } | 225 } |
| 220 | 226 |
| 221 TEST(DisplayItemListTest, FilterItem) { | 227 TEST(DisplayItemListTest, FilterItem) { |
| 222 gfx::Rect layer_rect(100, 100); | 228 gfx::Rect layer_rect(100, 100); |
| 223 FilterOperations filters; | 229 FilterOperations filters; |
| 224 unsigned char pixels[4 * 100 * 100] = {0}; | 230 unsigned char pixels[4 * 100 * 100] = {0}; |
| 225 auto list = make_scoped_refptr(new DisplayItemList); | 231 auto list = make_scoped_refptr(new DisplayItemList); |
| 226 | 232 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 249 | 255 |
| 250 // Include a rect drawing so that filter is actually applied to something. | 256 // Include a rect drawing so that filter is actually applied to something. |
| 251 { | 257 { |
| 252 PaintRecorder recorder; | 258 PaintRecorder recorder; |
| 253 | 259 |
| 254 PaintFlags red_paint; | 260 PaintFlags red_paint; |
| 255 red_paint.setColor(SK_ColorRED); | 261 red_paint.setColor(SK_ColorRED); |
| 256 | 262 |
| 257 PaintCanvas* canvas = recorder.beginRecording( | 263 PaintCanvas* canvas = recorder.beginRecording( |
| 258 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); | 264 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); |
| 259 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), | 265 canvas->drawRect( |
| 260 filter_bounds.right(), filter_bounds.bottom(), | 266 SkRect::MakeLTRB(filter_bounds.x(), filter_bounds.y(), |
| 261 red_paint); | 267 filter_bounds.right(), filter_bounds.bottom()), |
| 268 red_paint); |
| 262 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 269 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 263 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); | 270 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); |
| 264 } | 271 } |
| 265 | 272 |
| 266 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | 273 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); |
| 267 list->Finalize(); | 274 list->Finalize(); |
| 268 | 275 |
| 269 DrawDisplayList(pixels, layer_rect, list); | 276 DrawDisplayList(pixels, layer_rect, list); |
| 270 | 277 |
| 271 SkBitmap expected_bitmap; | 278 SkBitmap expected_bitmap; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 669 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
| 663 | 670 |
| 664 EXPECT_EQ(4u, list->size()); | 671 EXPECT_EQ(4u, list->size()); |
| 665 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | 672 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); |
| 666 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | 673 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); |
| 667 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | 674 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); |
| 668 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | 675 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); |
| 669 } | 676 } |
| 670 | 677 |
| 671 } // namespace cc | 678 } // namespace cc |
| OLD | NEW |