| 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/resources/display_item_list.h" | 5 #include "cc/resources/display_item_list.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "cc/resources/clip_display_item.h" | 9 #include "cc/resources/clip_display_item.h" |
| 10 #include "cc/resources/drawing_display_item.h" | 10 #include "cc/resources/drawing_display_item.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 SkPictureRecorder recorder; | 26 SkPictureRecorder recorder; |
| 27 skia::RefPtr<SkCanvas> canvas; | 27 skia::RefPtr<SkCanvas> canvas; |
| 28 skia::RefPtr<SkPicture> picture; | 28 skia::RefPtr<SkPicture> picture; |
| 29 SkPaint blue_paint; | 29 SkPaint blue_paint; |
| 30 blue_paint.setColor(SK_ColorBLUE); | 30 blue_paint.setColor(SK_ColorBLUE); |
| 31 SkPaint red_paint; | 31 SkPaint red_paint; |
| 32 red_paint.setColor(SK_ColorRED); | 32 red_paint.setColor(SK_ColorRED); |
| 33 unsigned char pixels[4 * 100 * 100] = {0}; | 33 unsigned char pixels[4 * 100 * 100] = {0}; |
| 34 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); | 34 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); |
| 35 | 35 |
| 36 gfx::PointF offset(8.f, 9.f); |
| 37 gfx::RectF recording_rect(offset, layer_rect.size()); |
| 36 canvas = skia::SharePtr( | 38 canvas = skia::SharePtr( |
| 37 recorder.beginRecording(layer_rect.width(), layer_rect.height())); | 39 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
| 38 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 40 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 39 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 41 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 40 picture = skia::AdoptRef(recorder.endRecording()); | 42 picture = skia::AdoptRef(recorder.endRecording()); |
| 41 gfx::PointF offset(8.f, 9.f); | 43 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 42 list->AppendItem(DrawingDisplayItem::Create(picture, offset)); | |
| 43 DrawDisplayList(pixels, layer_rect, list); | 44 DrawDisplayList(pixels, layer_rect, list); |
| 44 | 45 |
| 45 SkBitmap expected_bitmap; | 46 SkBitmap expected_bitmap; |
| 46 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 47 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 47 SkImageInfo info = | 48 SkImageInfo info = |
| 48 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 49 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 49 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 50 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 50 SkCanvas expected_canvas(expected_bitmap); | 51 SkCanvas expected_canvas(expected_bitmap); |
| 51 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 52 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 52 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 53 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 SkPictureRecorder recorder; | 65 SkPictureRecorder recorder; |
| 65 skia::RefPtr<SkCanvas> canvas; | 66 skia::RefPtr<SkCanvas> canvas; |
| 66 skia::RefPtr<SkPicture> picture; | 67 skia::RefPtr<SkPicture> picture; |
| 67 SkPaint blue_paint; | 68 SkPaint blue_paint; |
| 68 blue_paint.setColor(SK_ColorBLUE); | 69 blue_paint.setColor(SK_ColorBLUE); |
| 69 SkPaint red_paint; | 70 SkPaint red_paint; |
| 70 red_paint.setColor(SK_ColorRED); | 71 red_paint.setColor(SK_ColorRED); |
| 71 unsigned char pixels[4 * 100 * 100] = {0}; | 72 unsigned char pixels[4 * 100 * 100] = {0}; |
| 72 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); | 73 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); |
| 73 | 74 |
| 75 gfx::PointF first_offset(8.f, 9.f); |
| 76 gfx::RectF first_recording_rect(first_offset, layer_rect.size()); |
| 74 canvas = skia::SharePtr( | 77 canvas = skia::SharePtr( |
| 75 recorder.beginRecording(layer_rect.width(), layer_rect.height())); | 78 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 76 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 79 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 77 picture = skia::AdoptRef(recorder.endRecording()); | 80 picture = skia::AdoptRef(recorder.endRecording()); |
| 78 gfx::PointF first_offset(8.f, 9.f); | 81 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 79 list->AppendItem(DrawingDisplayItem::Create(picture, first_offset)); | |
| 80 | 82 |
| 81 gfx::Rect clip_rect(60, 60, 10, 10); | 83 gfx::Rect clip_rect(60, 60, 10, 10); |
| 82 list->AppendItem(ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>())); | 84 list->AppendItem(ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>())); |
| 83 | 85 |
| 86 gfx::PointF second_offset(2.f, 3.f); |
| 87 gfx::RectF second_recording_rect(second_offset, layer_rect.size()); |
| 84 canvas = skia::SharePtr( | 88 canvas = skia::SharePtr( |
| 85 recorder.beginRecording(layer_rect.width(), layer_rect.height())); | 89 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
| 86 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 90 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 87 picture = skia::AdoptRef(recorder.endRecording()); | 91 picture = skia::AdoptRef(recorder.endRecording()); |
| 88 gfx::PointF second_offset(2.f, 3.f); | 92 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 89 list->AppendItem(DrawingDisplayItem::Create(picture, second_offset)); | |
| 90 | 93 |
| 91 list->AppendItem(EndClipDisplayItem::Create()); | 94 list->AppendItem(EndClipDisplayItem::Create()); |
| 92 | 95 |
| 93 DrawDisplayList(pixels, layer_rect, list); | 96 DrawDisplayList(pixels, layer_rect, list); |
| 94 | 97 |
| 95 SkBitmap expected_bitmap; | 98 SkBitmap expected_bitmap; |
| 96 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 99 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 97 SkImageInfo info = | 100 SkImageInfo info = |
| 98 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 101 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 99 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 102 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 115 SkPictureRecorder recorder; | 118 SkPictureRecorder recorder; |
| 116 skia::RefPtr<SkCanvas> canvas; | 119 skia::RefPtr<SkCanvas> canvas; |
| 117 skia::RefPtr<SkPicture> picture; | 120 skia::RefPtr<SkPicture> picture; |
| 118 SkPaint blue_paint; | 121 SkPaint blue_paint; |
| 119 blue_paint.setColor(SK_ColorBLUE); | 122 blue_paint.setColor(SK_ColorBLUE); |
| 120 SkPaint red_paint; | 123 SkPaint red_paint; |
| 121 red_paint.setColor(SK_ColorRED); | 124 red_paint.setColor(SK_ColorRED); |
| 122 unsigned char pixels[4 * 100 * 100] = {0}; | 125 unsigned char pixels[4 * 100 * 100] = {0}; |
| 123 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); | 126 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); |
| 124 | 127 |
| 128 gfx::PointF first_offset(8.f, 9.f); |
| 129 gfx::RectF first_recording_rect(first_offset, layer_rect.size()); |
| 125 canvas = skia::SharePtr( | 130 canvas = skia::SharePtr( |
| 126 recorder.beginRecording(layer_rect.width(), layer_rect.height())); | 131 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
| 127 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 132 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
| 128 picture = skia::AdoptRef(recorder.endRecording()); | 133 picture = skia::AdoptRef(recorder.endRecording()); |
| 129 gfx::PointF first_offset(8.f, 9.f); | 134 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 130 list->AppendItem(DrawingDisplayItem::Create(picture, first_offset)); | |
| 131 | 135 |
| 132 gfx::Transform transform; | 136 gfx::Transform transform; |
| 133 transform.Rotate(45.0); | 137 transform.Rotate(45.0); |
| 134 list->AppendItem(TransformDisplayItem::Create(transform)); | 138 list->AppendItem(TransformDisplayItem::Create(transform)); |
| 135 | 139 |
| 140 gfx::PointF second_offset(2.f, 3.f); |
| 141 gfx::RectF second_recording_rect(second_offset, layer_rect.size()); |
| 136 canvas = skia::SharePtr( | 142 canvas = skia::SharePtr( |
| 137 recorder.beginRecording(layer_rect.width(), layer_rect.height())); | 143 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
| 138 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 144 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
| 139 picture = skia::AdoptRef(recorder.endRecording()); | 145 picture = skia::AdoptRef(recorder.endRecording()); |
| 140 gfx::PointF second_offset(2.f, 3.f); | 146 list->AppendItem(DrawingDisplayItem::Create(picture)); |
| 141 list->AppendItem(DrawingDisplayItem::Create(picture, second_offset)); | |
| 142 | 147 |
| 143 list->AppendItem(EndTransformDisplayItem::Create()); | 148 list->AppendItem(EndTransformDisplayItem::Create()); |
| 144 | 149 |
| 145 DrawDisplayList(pixels, layer_rect, list); | 150 DrawDisplayList(pixels, layer_rect, list); |
| 146 | 151 |
| 147 SkBitmap expected_bitmap; | 152 SkBitmap expected_bitmap; |
| 148 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 153 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 149 SkImageInfo info = | 154 SkImageInfo info = |
| 150 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 155 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 151 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 156 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 152 SkCanvas expected_canvas(expected_bitmap); | 157 SkCanvas expected_canvas(expected_bitmap); |
| 153 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 158 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 154 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 159 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), |
| 155 60.f + first_offset.x(), | 160 60.f + first_offset.x(), |
| 156 60.f + first_offset.y(), red_paint); | 161 60.f + first_offset.y(), red_paint); |
| 157 expected_canvas.setMatrix(transform.matrix()); | 162 expected_canvas.setMatrix(transform.matrix()); |
| 158 expected_canvas.drawRectCoords( | 163 expected_canvas.drawRectCoords( |
| 159 50.f + second_offset.x(), 50.f + second_offset.y(), | 164 50.f + second_offset.x(), 50.f + second_offset.y(), |
| 160 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 165 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
| 161 | 166 |
| 162 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 167 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 163 } | 168 } |
| 164 | 169 |
| 165 } // namespace | 170 } // namespace |
| 166 } // namespace cc | 171 } // namespace cc |
| OLD | NEW |