| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/test/skia_common.h" | 5 #include "cc/test/skia_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/playback/display_item_list.h" | 9 #include "cc/playback/display_item_list.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkImageGenerator.h" | 11 #include "third_party/skia/include/core/SkImageGenerator.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class TestImageGenerator : public SkImageGenerator { | 19 class TestImageGenerator : public SkImageGenerator { |
| 20 public: | 20 public: |
| 21 explicit TestImageGenerator(const SkImageInfo& info) | 21 explicit TestImageGenerator(const SkImageInfo& info) |
| 22 : SkImageGenerator(info) {} | 22 : SkImageGenerator(info) {} |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 } // anonymous namespace | 25 } // anonymous namespace |
| 26 | 26 |
| 27 void DrawDisplayList(unsigned char* buffer, | 27 void DrawDisplayList(unsigned char* buffer, |
| 28 const gfx::Rect& layer_rect, | 28 const gfx::Rect& layer_rect, |
| 29 scoped_refptr<DisplayItemList> list) { | 29 scoped_refptr<const DisplayItemList> list) { |
| 30 SkImageInfo info = | 30 SkImageInfo info = |
| 31 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 31 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
| 32 SkBitmap bitmap; | 32 SkBitmap bitmap; |
| 33 bitmap.installPixels(info, buffer, info.minRowBytes()); | 33 bitmap.installPixels(info, buffer, info.minRowBytes()); |
| 34 SkCanvas canvas(bitmap); | 34 SkCanvas canvas(bitmap); |
| 35 canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 35 canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 36 list->Raster(&canvas, NULL, gfx::Rect(), 1.0f); | 36 list->Raster(&canvas, NULL, gfx::Rect(), 1.0f); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool AreDisplayListDrawingResultsSame(const gfx::Rect& layer_rect, | 39 bool AreDisplayListDrawingResultsSame(const gfx::Rect& layer_rect, |
| 40 scoped_refptr<DisplayItemList> list_a, | 40 const DisplayItemList* list_a, |
| 41 scoped_refptr<DisplayItemList> list_b) { | 41 const DisplayItemList* list_b) { |
| 42 const size_t pixel_size = 4 * layer_rect.size().GetArea(); | 42 const size_t pixel_size = 4 * layer_rect.size().GetArea(); |
| 43 | 43 |
| 44 std::unique_ptr<unsigned char[]> pixels_a(new unsigned char[pixel_size]); | 44 std::unique_ptr<unsigned char[]> pixels_a(new unsigned char[pixel_size]); |
| 45 std::unique_ptr<unsigned char[]> pixels_b(new unsigned char[pixel_size]); | 45 std::unique_ptr<unsigned char[]> pixels_b(new unsigned char[pixel_size]); |
| 46 memset(pixels_a.get(), 0, pixel_size); | 46 memset(pixels_a.get(), 0, pixel_size); |
| 47 memset(pixels_b.get(), 0, pixel_size); | 47 memset(pixels_b.get(), 0, pixel_size); |
| 48 DrawDisplayList(pixels_a.get(), layer_rect, list_a); | 48 DrawDisplayList(pixels_a.get(), layer_rect, list_a); |
| 49 DrawDisplayList(pixels_b.get(), layer_rect, list_b); | 49 DrawDisplayList(pixels_b.get(), layer_rect, list_b); |
| 50 | 50 |
| 51 return !memcmp(pixels_a.get(), pixels_b.get(), pixel_size); | 51 return !memcmp(pixels_a.get(), pixels_b.get(), pixel_size); |
| 52 } | 52 } |
| 53 | 53 |
| 54 sk_sp<SkImage> CreateDiscardableImage(const gfx::Size& size) { | 54 sk_sp<SkImage> CreateDiscardableImage(const gfx::Size& size) { |
| 55 return SkImage::MakeFromGenerator(new TestImageGenerator( | 55 return SkImage::MakeFromGenerator(new TestImageGenerator( |
| 56 SkImageInfo::MakeN32Premul(size.width(), size.height()))); | 56 SkImageInfo::MakeN32Premul(size.width(), size.height()))); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace cc | 59 } // namespace cc |
| OLD | NEW |