| 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 24 matching lines...) Expand all Loading... |
| 35 #include "platform/geometry/IntSize.h" | 35 #include "platform/geometry/IntSize.h" |
| 36 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
| 37 #include "platform/graphics/Image.h" | 37 #include "platform/graphics/Image.h" |
| 38 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "third_party/skia/include/core/SkCanvas.h" | 40 #include "third_party/skia/include/core/SkCanvas.h" |
| 41 #include "third_party/skia/include/core/SkColor.h" | 41 #include "third_party/skia/include/core/SkColor.h" |
| 42 #include "third_party/skia/include/core/SkImage.h" | 42 #include "third_party/skia/include/core/SkImage.h" |
| 43 #include "third_party/skia/include/core/SkPixelRef.h" | 43 #include "third_party/skia/include/core/SkPixelRef.h" |
| 44 #include "third_party/skia/include/core/SkSurface.h" | 44 #include "third_party/skia/include/core/SkSurface.h" |
| 45 #include "wtf/OwnPtr.h" | |
| 46 #include "wtf/PassOwnPtr.h" | |
| 47 #include "wtf/PassRefPtr.h" | 45 #include "wtf/PassRefPtr.h" |
| 48 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 47 #include <memory> |
| 49 | 48 |
| 50 namespace blink { | 49 namespace blink { |
| 51 | 50 |
| 52 class TestImage : public Image { | 51 class TestImage : public Image { |
| 53 public: | 52 public: |
| 54 static PassRefPtr<TestImage> create(PassRefPtr<SkImage> image) | 53 static PassRefPtr<TestImage> create(PassRefPtr<SkImage> image) |
| 55 { | 54 { |
| 56 return adoptRef(new TestImage(image)); | 55 return adoptRef(new TestImage(image)); |
| 57 } | 56 } |
| 58 | 57 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 { | 116 { |
| 118 EXPECT_FALSE(DragImage::create(0)); | 117 EXPECT_FALSE(DragImage::create(0)); |
| 119 | 118 |
| 120 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); | 119 RefPtr<TestImage> nullTestImage(TestImage::create(IntSize())); |
| 121 EXPECT_FALSE(DragImage::create(nullTestImage.get())); | 120 EXPECT_FALSE(DragImage::create(nullTestImage.get())); |
| 122 } | 121 } |
| 123 | 122 |
| 124 TEST(DragImageTest, NonNullHandling) | 123 TEST(DragImageTest, NonNullHandling) |
| 125 { | 124 { |
| 126 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); | 125 RefPtr<TestImage> testImage(TestImage::create(IntSize(2, 2))); |
| 127 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get()); | 126 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get()); |
| 128 ASSERT_TRUE(dragImage); | 127 ASSERT_TRUE(dragImage); |
| 129 | 128 |
| 130 dragImage->scale(0.5, 0.5); | 129 dragImage->scale(0.5, 0.5); |
| 131 IntSize size = dragImage->size(); | 130 IntSize size = dragImage->size(); |
| 132 EXPECT_EQ(1, size.width()); | 131 EXPECT_EQ(1, size.width()); |
| 133 EXPECT_EQ(1, size.height()); | 132 EXPECT_EQ(1, size.height()); |
| 134 } | 133 } |
| 135 | 134 |
| 136 TEST(DragImageTest, CreateDragImage) | 135 TEST(DragImageTest, CreateDragImage) |
| 137 { | 136 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 float deviceScaleFactor = 1.0f; | 149 float deviceScaleFactor = 1.0f; |
| 151 | 150 |
| 152 FontDescription fontDescription; | 151 FontDescription fontDescription; |
| 153 fontDescription.firstFamily().setFamily("Arial"); | 152 fontDescription.firstFamily().setFamily("Arial"); |
| 154 fontDescription.setSpecifiedSize(16); | 153 fontDescription.setSpecifiedSize(16); |
| 155 fontDescription.setIsAbsoluteSize(true); | 154 fontDescription.setIsAbsoluteSize(true); |
| 156 fontDescription.setGenericFamily(FontDescription::NoFamily); | 155 fontDescription.setGenericFamily(FontDescription::NoFamily); |
| 157 fontDescription.setWeight(FontWeightNormal); | 156 fontDescription.setWeight(FontWeightNormal); |
| 158 fontDescription.setStyle(FontStyleNormal); | 157 fontDescription.setStyle(FontStyleNormal); |
| 159 | 158 |
| 160 OwnPtr<DragImage> testImage = | 159 std::unique_ptr<DragImage> testImage = |
| 161 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); | 160 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); |
| 162 OwnPtr<DragImage> expectedImage = | 161 std::unique_ptr<DragImage> expectedImage = |
| 163 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor
); | 162 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor
); |
| 164 | 163 |
| 165 EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); | 164 EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); |
| 166 } | 165 } |
| 167 | 166 |
| 168 // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels | 167 // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels |
| 169 // cannot be generated. | 168 // cannot be generated. |
| 170 class InvalidPixelRef : public SkPixelRef { | 169 class InvalidPixelRef : public SkPixelRef { |
| 171 public: | 170 public: |
| 172 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } | 171 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 185 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 184 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 186 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); | 185 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); |
| 187 SkBitmap invalidBitmap; | 186 SkBitmap invalidBitmap; |
| 188 invalidBitmap.setInfo(info); | 187 invalidBitmap.setInfo(info); |
| 189 invalidBitmap.setPixelRef(pixelRef.get()); | 188 invalidBitmap.setPixelRef(pixelRef.get()); |
| 190 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); | 189 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(inv
alidBitmap, OriginRightTop); |
| 191 | 190 |
| 192 // Create a DragImage from it. In MSAN builds, this will cause a failure if | 191 // 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 | 192 // the pixel memory is not initialized, if we have to respect non-default |
| 194 // orientation. | 193 // orientation. |
| 195 OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOri
entation); | 194 std::unique_ptr<DragImage> dragImage = DragImage::create(image.get(), Respec
tImageOrientation); |
| 196 | 195 |
| 197 // With an invalid pixel ref, BitmapImage should have no backing SkImage =>
we don't allocate | 196 // With an invalid pixel ref, BitmapImage should have no backing SkImage =>
we don't allocate |
| 198 // a DragImage. | 197 // a DragImage. |
| 199 ASSERT_FALSE(dragImage); | 198 ASSERT_FALSE(dragImage); |
| 200 } | 199 } |
| 201 | 200 |
| 202 TEST(DragImageTest, InterpolationNone) | 201 TEST(DragImageTest, InterpolationNone) |
| 203 { | 202 { |
| 204 SkBitmap expectedBitmap; | 203 SkBitmap expectedBitmap; |
| 205 expectedBitmap.allocN32Pixels(4, 4); | 204 expectedBitmap.allocN32Pixels(4, 4); |
| 206 { | 205 { |
| 207 SkAutoLockPixels lock(expectedBitmap); | 206 SkAutoLockPixels lock(expectedBitmap); |
| 208 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF); | 207 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 2, 2), 0xFFFFFFFF); |
| 209 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000); | 208 expectedBitmap.eraseArea(SkIRect::MakeXYWH(0, 2, 2, 2), 0xFF000000); |
| 210 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000); | 209 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 0, 2, 2), 0xFF000000); |
| 211 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF); | 210 expectedBitmap.eraseArea(SkIRect::MakeXYWH(2, 2, 2, 2), 0xFFFFFFFF); |
| 212 } | 211 } |
| 213 | 212 |
| 214 SkBitmap testBitmap; | 213 SkBitmap testBitmap; |
| 215 testBitmap.allocN32Pixels(2, 2); | 214 testBitmap.allocN32Pixels(2, 2); |
| 216 { | 215 { |
| 217 SkAutoLockPixels lock(testBitmap); | 216 SkAutoLockPixels lock(testBitmap); |
| 218 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF); | 217 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 0, 1, 1), 0xFFFFFFFF); |
| 219 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000); | 218 testBitmap.eraseArea(SkIRect::MakeXYWH(0, 1, 1, 1), 0xFF000000); |
| 220 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000); | 219 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 0, 1, 1), 0xFF000000); |
| 221 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF); | 220 testBitmap.eraseArea(SkIRect::MakeXYWH(1, 1, 1, 1), 0xFFFFFFFF); |
| 222 } | 221 } |
| 223 | 222 |
| 224 RefPtr<TestImage> testImage = TestImage::create(adoptRef(SkImage::NewFromBit
map(testBitmap))); | 223 RefPtr<TestImage> testImage = TestImage::create(adoptRef(SkImage::NewFromBit
map(testBitmap))); |
| 225 OwnPtr<DragImage> dragImage = DragImage::create(testImage.get(), DoNotRespec
tImageOrientation, 1, InterpolationNone); | 224 std::unique_ptr<DragImage> dragImage = DragImage::create(testImage.get(), Do
NotRespectImageOrientation, 1, InterpolationNone); |
| 226 ASSERT_TRUE(dragImage); | 225 ASSERT_TRUE(dragImage); |
| 227 dragImage->scale(2, 2); | 226 dragImage->scale(2, 2); |
| 228 const SkBitmap& dragBitmap = dragImage->bitmap(); | 227 const SkBitmap& dragBitmap = dragImage->bitmap(); |
| 229 { | 228 { |
| 230 SkAutoLockPixels lock1(dragBitmap); | 229 SkAutoLockPixels lock1(dragBitmap); |
| 231 SkAutoLockPixels lock2(expectedBitmap); | 230 SkAutoLockPixels lock2(expectedBitmap); |
| 232 for (int x = 0; x < dragBitmap.width(); ++x) | 231 for (int x = 0; x < dragBitmap.width(); ++x) |
| 233 for (int y = 0; y < dragBitmap.height(); ++y) | 232 for (int y = 0; y < dragBitmap.height(); ++y) |
| 234 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); | 233 EXPECT_EQ(expectedBitmap.getColor(x, y), dragBitmap.getColor(x,
y)); |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 | 236 |
| 238 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |