| 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/output/filter_operation.h" |
| 10 #include "cc/output/filter_operations.h" |
| 9 #include "cc/resources/clip_display_item.h" | 11 #include "cc/resources/clip_display_item.h" |
| 10 #include "cc/resources/drawing_display_item.h" | 12 #include "cc/resources/drawing_display_item.h" |
| 13 #include "cc/resources/filter_display_item.h" |
| 11 #include "cc/resources/transform_display_item.h" | 14 #include "cc/resources/transform_display_item.h" |
| 12 #include "cc/test/skia_common.h" | 15 #include "cc/test/skia_common.h" |
| 13 #include "skia/ext/refptr.h" | 16 #include "skia/ext/refptr.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkPictureRecorder.h" | 21 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 22 #include "third_party/skia/include/effects/SkBitmapSource.h" |
| 19 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
| 20 | 24 |
| 21 namespace cc { | 25 namespace cc { |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 TEST(DisplayItemListTest, SingleDrawingItem) { | 28 TEST(DisplayItemListTest, SingleDrawingItem) { |
| 25 gfx::Rect layer_rect(100, 100); | 29 gfx::Rect layer_rect(100, 100); |
| 26 SkPictureRecorder recorder; | 30 SkPictureRecorder recorder; |
| 27 skia::RefPtr<SkCanvas> canvas; | 31 skia::RefPtr<SkCanvas> canvas; |
| 28 skia::RefPtr<SkPicture> picture; | 32 skia::RefPtr<SkPicture> picture; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 60.f + first_offset.x(), | 159 60.f + first_offset.x(), |
| 156 60.f + first_offset.y(), red_paint); | 160 60.f + first_offset.y(), red_paint); |
| 157 expected_canvas.setMatrix(transform.matrix()); | 161 expected_canvas.setMatrix(transform.matrix()); |
| 158 expected_canvas.drawRectCoords( | 162 expected_canvas.drawRectCoords( |
| 159 50.f + second_offset.x(), 50.f + second_offset.y(), | 163 50.f + second_offset.x(), 50.f + second_offset.y(), |
| 160 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 164 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
| 161 | 165 |
| 162 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 166 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 163 } | 167 } |
| 164 | 168 |
| 169 TEST(DisplayItemList, FilterItem) { |
| 170 gfx::Rect layer_rect(100, 100); |
| 171 FilterOperations filters; |
| 172 unsigned char pixels[4 * 100 * 100] = {0}; |
| 173 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(); |
| 174 |
| 175 SkBitmap source_bitmap; |
| 176 source_bitmap.allocN32Pixels(50, 50); |
| 177 SkCanvas source_canvas(source_bitmap); |
| 178 source_canvas.clear(SkColorSetRGB(128, 128, 128)); |
| 179 |
| 180 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are |
| 181 // dependent on the provided |src| bounds. This means, for example, that |
| 182 // translating |src| results in a corresponding translation of |dst|. But this |
| 183 // is not the case for all SkImageFilters; for some of them (e.g. |
| 184 // SkBitmapSource), the computation of |dst| in computeFastBounds doesn't |
| 185 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by |
| 186 // translating |dst| after it is computed by computeFastBounds, rather than |
| 187 // translating |src| before it provided to computedFastBounds) can cause |
| 188 // incorrect clipping of filter output. To test for this, we include an |
| 189 // SkBitmapSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
| 190 // below. |
| 191 skia::RefPtr<SkImageFilter> image_filter = |
| 192 skia::AdoptRef(SkBitmapSource::Create(source_bitmap)); |
| 193 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
| 194 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
| 195 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
| 196 list->AppendItem(FilterDisplayItem::Create(filters, filter_bounds)); |
| 197 list->AppendItem(EndFilterDisplayItem::Create()); |
| 198 |
| 199 DrawDisplayList(pixels, layer_rect, list); |
| 200 |
| 201 SkBitmap expected_bitmap; |
| 202 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
| 203 SkPaint paint; |
| 204 paint.setColor(SkColorSetRGB(64, 64, 64)); |
| 205 SkImageInfo info = |
| 206 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 207 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
| 208 SkCanvas expected_canvas(expected_bitmap); |
| 209 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); |
| 210 |
| 211 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
| 212 } |
| 213 |
| 165 } // namespace | 214 } // namespace |
| 166 } // namespace cc | 215 } // namespace cc |
| OLD | NEW |