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 17 matching lines...) Expand all Loading... |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "platform/DragImage.h" | 33 #include "platform/DragImage.h" |
34 | 34 |
35 #include "platform/fonts/FontDescription.h" | 35 #include "platform/fonts/FontDescription.h" |
36 #include "platform/fonts/FontTraits.h" | 36 #include "platform/fonts/FontTraits.h" |
37 #include "platform/geometry/IntSize.h" | 37 #include "platform/geometry/IntSize.h" |
| 38 #include "platform/graphics/BitmapImage.h" |
38 #include "platform/graphics/Image.h" | 39 #include "platform/graphics/Image.h" |
39 #include "platform/graphics/skia/NativeImageSkia.h" | 40 #include "platform/graphics/skia/NativeImageSkia.h" |
40 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
41 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
42 #include "third_party/skia/include/core/SkColor.h" | 43 #include "third_party/skia/include/core/SkColor.h" |
| 44 #include "third_party/skia/include/core/SkPixelRef.h" |
43 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
44 #include "wtf/PassOwnPtr.h" | 46 #include "wtf/PassOwnPtr.h" |
45 #include "wtf/PassRefPtr.h" | 47 #include "wtf/PassRefPtr.h" |
46 #include "wtf/RefPtr.h" | 48 #include "wtf/RefPtr.h" |
47 | 49 |
48 #include <gtest/gtest.h> | 50 #include <gtest/gtest.h> |
49 | 51 |
50 using namespace blink; | 52 using namespace blink; |
51 | 53 |
52 namespace { | 54 namespace { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 fontDescription.setStyle(FontStyleNormal); | 162 fontDescription.setStyle(FontStyleNormal); |
161 | 163 |
162 OwnPtr<DragImage> testImage = | 164 OwnPtr<DragImage> testImage = |
163 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); | 165 DragImage::create(url, testLabel, fontDescription, deviceScaleFactor); |
164 OwnPtr<DragImage> expectedImage = | 166 OwnPtr<DragImage> expectedImage = |
165 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor
); | 167 DragImage::create(url, expectedLabel, fontDescription, deviceScaleFactor
); |
166 | 168 |
167 EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); | 169 EXPECT_EQ(testImage->size().width(), expectedImage->size().width()); |
168 } | 170 } |
169 | 171 |
| 172 // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels |
| 173 // cannot be generated. |
| 174 class InvalidPixelRef : public SkPixelRef { |
| 175 public: |
| 176 InvalidPixelRef(const SkImageInfo& info) : SkPixelRef(info) { } |
| 177 private: |
| 178 bool onNewLockPixels(LockRec*) override { return false; } |
| 179 void onUnlockPixels() override { ASSERT_NOT_REACHED(); } |
| 180 }; |
| 181 |
| 182 TEST(DragImageTest, InvalidRotatedBitmapImage) |
| 183 { |
| 184 // This test is mostly useful with MSAN builds, which can actually detect |
| 185 // the use of uninitialized memory. |
| 186 |
| 187 // Create a BitmapImage which will fail to produce pixels, and hence not |
| 188 // draw. |
| 189 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 190 RefPtr<SkPixelRef> pixelRef = adoptRef(new InvalidPixelRef(info)); |
| 191 SkBitmap invalidBitmap; |
| 192 invalidBitmap.setInfo(info); |
| 193 invalidBitmap.setPixelRef(pixelRef.get()); |
| 194 RefPtr<NativeImageSkia> nativeImage = NativeImageSkia::create(invalidBitmap)
; |
| 195 RefPtr<BitmapImage> image = BitmapImage::createWithOrientationForTesting(nat
iveImage, OriginRightTop); |
| 196 |
| 197 // Create a DragImage from it. In MSAN builds, this will cause a failure if |
| 198 // the pixel memory is not initialized, if we have to respect non-default |
| 199 // orientation. |
| 200 OwnPtr<DragImage> dragImage = DragImage::create(image.get(), RespectImageOri
entation); |
| 201 |
| 202 // The DragImage should be fully transparent. |
| 203 SkBitmap dragImageBitmap = dragImage->bitmap(); |
| 204 SkAutoLockPixels lock(dragImageBitmap); |
| 205 ASSERT_NE(nullptr, dragImageBitmap.getPixels()); |
| 206 for (int x = 0; x < dragImageBitmap.width(); x++) { |
| 207 for (int y = 0; y < dragImageBitmap.height(); y++) { |
| 208 int alpha = SkColorGetA(dragImageBitmap.getColor(x, y)); |
| 209 ASSERT_EQ(0, alpha); |
| 210 } |
| 211 } |
| 212 } |
| 213 |
170 } // anonymous namespace | 214 } // anonymous namespace |
OLD | NEW |