| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "third_party/skia/include/core/SkPixelRef.h" | 44 #include "third_party/skia/include/core/SkPixelRef.h" |
| 45 #include "third_party/skia/include/core/SkSurface.h" | 45 #include "third_party/skia/include/core/SkSurface.h" |
| 46 #include "wtf/PassRefPtr.h" | 46 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/RefPtr.h" | 47 #include "wtf/RefPtr.h" |
| 48 #include <memory> | 48 #include <memory> |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 class TestImage : public Image { | 52 class TestImage : public Image { |
| 53 public: | 53 public: |
| 54 static PassRefPtr<TestImage> create(PassRefPtr<SkImage> image) | 54 static PassRefPtr<TestImage> create(sk_sp<SkImage> image) |
| 55 { | 55 { |
| 56 return adoptRef(new TestImage(image)); | 56 return adoptRef(new TestImage(image)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 static PassRefPtr<TestImage> create(const IntSize& size) | 59 static PassRefPtr<TestImage> create(const IntSize& size) |
| 60 { | 60 { |
| 61 return adoptRef(new TestImage(size)); | 61 return adoptRef(new TestImage(size)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 IntSize size() const override | 64 IntSize size() const override |
| 65 { | 65 { |
| 66 ASSERT(m_image); | 66 ASSERT(m_image); |
| 67 | 67 |
| 68 return IntSize(m_image->width(), m_image->height()); | 68 return IntSize(m_image->width(), m_image->height()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtr<SkImage> imageForCurrentFrame() override | 71 sk_sp<SkImage> imageForCurrentFrame() override |
| 72 { | 72 { |
| 73 return m_image; | 73 return m_image; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override | 76 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override |
| 77 { | 77 { |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void destroyDecodedData() override | 81 void destroyDecodedData() override |
| 82 { | 82 { |
| 83 // Image pure virtual stub. | 83 // Image pure virtual stub. |
| 84 } | 84 } |
| 85 | 85 |
| 86 void draw(SkCanvas*, const SkPaint&, const FloatRect&, const FloatRect&, Res
pectImageOrientationEnum, ImageClampingMode) override | 86 void draw(SkCanvas*, const SkPaint&, const FloatRect&, const FloatRect&, Res
pectImageOrientationEnum, ImageClampingMode) override |
| 87 { | 87 { |
| 88 // Image pure virtual stub. | 88 // Image pure virtual stub. |
| 89 } | 89 } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 explicit TestImage(PassRefPtr<SkImage> image) | 92 explicit TestImage(sk_sp<SkImage> image) |
| 93 : m_image(image) | 93 : m_image(image) |
| 94 { | 94 { |
| 95 } | 95 } |
| 96 | 96 |
| 97 explicit TestImage(IntSize size) | 97 explicit TestImage(IntSize size) |
| 98 : m_image(nullptr) | 98 : m_image(nullptr) |
| 99 { | 99 { |
| 100 sk_sp<SkSurface> surface = createSkSurface(size); | 100 sk_sp<SkSurface> surface = createSkSurface(size); |
| 101 if (!surface) | 101 if (!surface) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 104 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| 105 m_image = fromSkSp(surface->makeImageSnapshot()); | 105 m_image = surface->makeImageSnapshot(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 static sk_sp<SkSurface> createSkSurface(IntSize size) | 108 static sk_sp<SkSurface> createSkSurface(IntSize size) |
| 109 { | 109 { |
| 110 return SkSurface::MakeRaster(SkImageInfo::MakeN32(size.width(), size.hei
ght(), kPremul_SkAlphaType)); | 110 return SkSurface::MakeRaster(SkImageInfo::MakeN32(size.width(), size.hei
ght(), kPremul_SkAlphaType)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 RefPtr<SkImage> m_image; | 113 sk_sp<SkImage> m_image; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST(DragImageTest, NullHandling) | 116 TEST(DragImageTest, NullHandling) |
| 117 { | 117 { |
| 118 EXPECT_FALSE(DragImage::create(0)); | 118 EXPECT_FALSE(DragImage::create(0)); |
| 119 | 119 |
| 120 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); | 120 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); |
| 121 EXPECT_FALSE(DragImage::create(nullTestImage.get())); | 121 EXPECT_FALSE(DragImage::create(nullTestImage.get())); |
| 122 } | 122 } |
| 123 | 123 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 TEST(DragImageTest, InvalidRotatedBitmapImage) | 178 TEST(DragImageTest, InvalidRotatedBitmapImage) |
| 179 { | 179 { |
| 180 // This test is mostly useful with MSAN builds, which can actually detect | 180 // This test is mostly useful with MSAN builds, which can actually detect |
| 181 // the use of uninitialized memory. | 181 // the use of uninitialized memory. |
| 182 | 182 |
| 183 // Create a BitmapImage which will fail to produce pixels, and hence not | 183 // Create a BitmapImage which will fail to produce pixels, and hence not |
| 184 // draw. | 184 // draw. |
| 185 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 185 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 186 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); | 186 sk_sp<SkPixelRef> pixelRef(new InvalidPixelRef(info)); |
| 187 SkBitmap invalidBitmap; | 187 SkBitmap invalidBitmap; |
| 188 invalidBitmap.setInfo(info); | 188 invalidBitmap.setInfo(info); |
| 189 invalidBitmap.setPixelRef(pixelRef.get()); | 189 invalidBitmap.setPixelRef(pixelRef.get()); |
| 190 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); | 190 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); |
| 191 | 191 |
| 192 // Create a DragImage from it. In MSAN builds, this will cause a failure if | 192 // Create a DragImage from it. In MSAN builds, this will cause a failure if |
| 193 // the pixel memory is not initialized, if we have to respect non-default | 193 // the pixel memory is not initialized, if we have to respect non-default |
| 194 // orientation. | 194 // orientation. |
| 195 std::unique_ptr<DragImage> dragImage = DragImage::create(image.get(), Respec
tImageOrientation); | 195 std::unique_ptr<DragImage> dragImage = DragImage::create(image.get(), Respec
tImageOrientation); |
| 196 | 196 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 214 SkBitmap testBitmap; | 214 SkBitmap testBitmap; |
| 215 testBitmap.allocN32Pixels(2, 2); | 215 testBitmap.allocN32Pixels(2, 2); |
| 216 { | 216 { |
| 217 SkAutoLockPixels lock(testBitmap); | 217 SkAutoLockPixels lock(testBitmap); |
| 218 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF); | 218 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF); |
| 219 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000); | 219 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000); |
| 220 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000); | 220 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000); |
| 221 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF); | 221 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF); |
| 222 } | 222 } |
| 223 | 223 |
| 224 RefPtr<TestImage> testImage = TestImage::create(fromSkSp(SkImage::MakeFromBi
tmap(testBitmap))); | 224 RefPtr<TestImage> testImage = TestImage::create(SkImage::MakeFromBitmap(test
Bitmap)); |
| 225 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get(), Do
NotRespectImageOrientation, 1, InterpolationNone); | 225 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get(), Do
NotRespectImageOrientation, 1, InterpolationNone); |
| 226 ASSERT_TRUE(dragImage); | 226 ASSERT_TRUE(dragImage); |
| 227 dragImage->scale(2, 2); | 227 dragImage->scale(2, 2); |
| 228 const SkBitmap& dragBitmap = dragImage->bitmap(); | 228 const SkBitmap& dragBitmap = dragImage->bitmap(); |
| 229 { | 229 { |
| 230 SkAutoLockPixels lock1(dragBitmap); | 230 SkAutoLockPixels lock1(dragBitmap); |
| 231 SkAutoLockPixels lock2(expectedBitmap); | 231 SkAutoLockPixels lock2(expectedBitmap); |
| 232 for (int x = 0; x < dragBitmap.width(); ++x) | 232 for (int x = 0; x < dragBitmap.width(); ++x) |
| 233 for (int y = 0; y < dragBitmap.height(); ++y) | 233 for (int y = 0; y < dragBitmap.height(); ++y) |
| 234 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); | 234 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace blink | 238 } // namespace blink |
| OLD | NEW |