Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 1609763002: Implement ImageBitmap options premultiplyAlpha (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: apply comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); 75 replaceMemoryCacheForTesting(m_globalMemoryCache.release());
76 } 76 }
77 77
78 RefPtr<SkImage> m_image, m_image2; 78 RefPtr<SkImage> m_image, m_image2;
79 Persistent<MemoryCache> m_globalMemoryCache; 79 Persistent<MemoryCache> m_globalMemoryCache;
80 }; 80 };
81 81
82 TEST_F(ImageBitmapTest, ImageResourceConsistency) 82 TEST_F(ImageBitmapTest, ImageResourceConsistency)
83 { 83 {
84 const ImageBitmapOptions defaultOptions;
84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get()); 85 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get());
85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image).get())); 86 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image).get()));
86 87
87 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(), 88 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(),
88 IntRect(0, 0, m_image->width(), m_image->height()), 89 IntRect(0, 0, m_image->width(), m_image->height()),
89 &(imageElement->document())); 90 &(imageElement->document()), defaultOptions);
90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat e(imageElement.get(), 91 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), 92 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2),
92 &(imageElement->document())); 93 &(imageElement->document()), defaultOptions);
93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(), 94 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(),
94 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()), 95 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()),
95 &(imageElement->document())); 96 &(imageElement->document()), defaultOptions);
96 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(), 97 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(),
97 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()), 98 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()),
98 &(imageElement->document())); 99 &(imageElement->document()), defaultOptions);
99 100
100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame()); 101 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame());
101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 102 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 103 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
103 104
104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 105 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame()); 106 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame());
106 } 107 }
107 108
108 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap. 109 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange); 143 memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateFo rPropertyChange);
143 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange); 144 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange);
144 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange); 145 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange);
145 146
146 // HTMLImageElements should default to CacheLiveResourcePriorityLow. 147 // HTMLImageElements should default to CacheLiveResourcePriorityLow.
147 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow); 148 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow);
148 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 149 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
149 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 150 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
150 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow); 151 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow);
151 152
153 const ImageBitmapOptions defaultOptions;
152 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(), 154 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(),
153 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height()), 155 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height()),
154 &(imageInteriorCrop->document())); 156 &(imageInteriorCrop->document()), defaultOptions);
155 { 157 {
156 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(), 158 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(),
157 IntRect(0, 0, m_image->width(), m_image->height()), 159 IntRect(0, 0, m_image->width(), m_image->height()),
158 &(imageNoCrop->document())); 160 &(imageNoCrop->document()), defaultOptions);
159 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(), 161 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(),
160 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height()), 162 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height()),
161 &(imageInteriorCrop->document())); 163 &(imageInteriorCrop->document()), defaultOptions);
162 RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitma p::create(imageExteriorCrop.get(), 164 RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitma p::create(imageExteriorCrop.get(),
163 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->widt h(), m_image->height()), 165 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->widt h(), m_image->height()),
164 &(imageExteriorCrop->document())); 166 &(imageExteriorCrop->document()), defaultOptions);
165 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(), 167 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(),
166 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height()), 168 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height()),
167 &(imageOutsideCrop->document())); 169 &(imageOutsideCrop->document()), defaultOptions);
168 170
169 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow 171 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow
170 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow); 172 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow);
171 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 173 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
172 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 174 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
173 175
174 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority. 176 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority.
175 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow); 177 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow);
176 } 178 }
177 // Force a garbage collection to sweep out the local ImageBitmaps. 179 // Force a garbage collection to sweep out the local ImageBitmaps.
(...skipping 10 matching lines...) Expand all
188 } 190 }
189 191
190 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed. 192 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed.
191 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) 193 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
192 { 194 {
193 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get()); 195 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get());
194 ResourcePtr<ImageResource> originalImageResource = new ImageResource( 196 ResourcePtr<ImageResource> originalImageResource = new ImageResource(
195 StaticBitmapImage::create(m_image).get()); 197 StaticBitmapImage::create(m_image).get());
196 image->setImageResource(originalImageResource.get()); 198 image->setImageResource(originalImageResource.get());
197 199
200 const ImageBitmapOptions defaultOptions;
198 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ), 201 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ),
199 IntRect(0, 0, m_image->width(), m_image->height()), 202 IntRect(0, 0, m_image->width(), m_image->height()),
200 &(image->document())); 203 &(image->document()), defaultOptions);
201 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame()); 204 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame());
202 205
203 ResourcePtr<ImageResource> newImageResource = new ImageResource( 206 ResourcePtr<ImageResource> newImageResource = new ImageResource(
204 StaticBitmapImage::create(m_image2).get()); 207 StaticBitmapImage::create(m_image2).get());
205 image->setImageResource(newImageResource.get()); 208 image->setImageResource(newImageResource.get());
206 209
207 // The ImageBitmap should contain the same data as the original cached image 210 // The ImageBitmap should contain the same data as the original cached image
208 { 211 {
209 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame()); 212 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame());
210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 213 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
211 ASSERT_NE(image1, nullptr); 214 ASSERT_NE(image1, nullptr);
212 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get(); 215 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get();
213 ASSERT_NE(image2, nullptr); 216 ASSERT_NE(image2, nullptr);
214 ASSERT_EQ(image1, image2); 217 ASSERT_EQ(image1, image2);
215 } 218 }
216 219
217 { 220 {
218 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame()); 221 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame());
219 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 222 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
220 ASSERT_NE(image1, nullptr); 223 ASSERT_NE(image1, nullptr);
221 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( ); 224 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( );
222 ASSERT_NE(image2, nullptr); 225 ASSERT_NE(image2, nullptr);
223 ASSERT_NE(image1, image2); 226 ASSERT_NE(image1, image2);
224 } 227 }
225 } 228 }
226 229
227 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698