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