OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag
eElement.get(), | 88 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag
eElement.get(), |
89 IntRect(0, 0, m_image->width(), m_image->height())); | 89 IntRect(0, 0, m_image->width(), m_image->height())); |
90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat
e(imageElement.get(), |
91 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() /
2, m_image->height() / 2)); | 91 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() /
2, m_image->height() / 2)); |
92 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 92 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat
e(imageElement.get(), |
93 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(),
m_image->height())); | 93 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(),
m_image->height())); |
94 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create
(imageElement.get(), | 94 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create
(imageElement.get(), |
95 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image
->height())); | 95 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image
->height())); |
96 | 96 |
97 // Now that we use SkImage::newSubset() to crop the image, the ImageBitmap::
skImage() is not necessary the same | 97 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle
ment->cachedImage()->image()->imageForCurrentFrame()); |
98 // as the source imageElement. See SkImage::newSubset() for details. | 98 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); |
99 ASSERT_EQ(imageBitmapNoCrop->skImage(), imageElement->cachedImage()->image()
->imageForCurrentFrame().get()); | 99 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); |
100 ASSERT_NE(imageBitmapInteriorCrop->skImage(), imageElement->cachedImage()->i
mage()->imageForCurrentFrame().get()); | |
101 ASSERT_NE(imageBitmapExteriorCrop->skImage(), imageElement->cachedImage()->i
mage()->imageForCurrentFrame().get()); | |
102 | 100 |
103 SkImage* emptyImage = imageBitmapOutsideCrop->skImage(); | 101 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); |
104 ASSERT_NE(emptyImage, imageElement->cachedImage()->image()->imageForCurrentF
rame()); | 102 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i
mage()->imageForCurrentFrame()); |
105 } | 103 } |
106 | 104 |
107 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori
ty when used to construct an ImageBitmap. | 105 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori
ty when used to construct an ImageBitmap. |
108 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme
nt do not have elevated CacheLiveResourcePriority. | 106 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme
nt do not have elevated CacheLiveResourcePriority. |
109 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority) | 107 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority) |
110 { | 108 { |
111 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre
ate(*Document::create().get()); | 109 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre
ate(*Document::create().get()); |
112 ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceReq
uest("http://foo.com/1"), | 110 ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceReq
uest("http://foo.com/1"), |
113 StaticBitmapImage::create(m_image).get()); | 111 StaticBitmapImage::create(m_image).get()); |
114 imageNoCrop->setImageResource(cachedImageNoCrop.get()); | 112 imageNoCrop->setImageResource(cachedImageNoCrop.get()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc
e to the original Image if the HTMLImageElement src is changed. | 182 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc
e to the original Image if the HTMLImageElement src is changed. |
185 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) | 183 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) |
186 { | 184 { |
187 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum
ent::create().get()); | 185 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum
ent::create().get()); |
188 ResourcePtr<ImageResource> originalImageResource = new ImageResource( | 186 ResourcePtr<ImageResource> originalImageResource = new ImageResource( |
189 StaticBitmapImage::create(m_image).get()); | 187 StaticBitmapImage::create(m_image).get()); |
190 image->setImageResource(originalImageResource.get()); | 188 image->setImageResource(originalImageResource.get()); |
191 | 189 |
192 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(
), | 190 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(
), |
193 IntRect(0, 0, m_image->width(), m_image->height())); | 191 IntRect(0, 0, m_image->width(), m_image->height())); |
194 ASSERT_EQ(imageBitmap->skImage(), originalImageResource->image()->imageForCu
rrentFrame().get()); | 192 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR
esource->image()->imageForCurrentFrame()); |
195 | 193 |
196 ResourcePtr<ImageResource> newImageResource = new ImageResource( | 194 ResourcePtr<ImageResource> newImageResource = new ImageResource( |
197 StaticBitmapImage::create(m_image2).get()); | 195 StaticBitmapImage::create(m_image2).get()); |
198 image->setImageResource(newImageResource.get()); | 196 image->setImageResource(newImageResource.get()); |
199 | 197 |
200 // The ImageBitmap should contain the same data as the original cached image | 198 // The ImageBitmap should contain the same data as the original cached image |
201 { | 199 { |
202 ASSERT_EQ(imageBitmap->skImage(), originalImageResource->image()->imageF
orCurrentFrame().get()); | 200 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm
ageResource->image()->imageForCurrentFrame()); |
203 SkImage* image1 = imageBitmap->skImage(); | 201 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
204 ASSERT_NE(image1, nullptr); | 202 ASSERT_NE(image1, nullptr); |
205 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame()
.get(); | 203 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame()
.get(); |
206 ASSERT_NE(image2, nullptr); | 204 ASSERT_NE(image2, nullptr); |
207 ASSERT_EQ(image1, image2); | 205 ASSERT_EQ(image1, image2); |
208 } | 206 } |
209 | 207 |
210 { | 208 { |
211 ASSERT_NE(imageBitmap->skImage(), newImageResource->image()->imageForCur
rentFrame().get()); | 209 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe
source->image()->imageForCurrentFrame()); |
212 SkImage* image1 = imageBitmap->skImage(); | 210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
213 ASSERT_NE(image1, nullptr); | 211 ASSERT_NE(image1, nullptr); |
214 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get(
); | 212 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get(
); |
215 ASSERT_NE(image2, nullptr); | 213 ASSERT_NE(image2, nullptr); |
216 ASSERT_NE(image1, image2); | 214 ASSERT_NE(image1, image2); |
217 } | 215 } |
218 } | 216 } |
219 | 217 |
220 } // namespace | 218 } // namespace |
OLD | NEW |