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

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

Issue 1577783003: Revert of Add a origin clean flag in ImageBitmap class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get()); 84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create (*Document::create().get());
85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image).get())); 85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m _image).get()));
86 86
87 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(), 87 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag eElement.get(),
88 IntRect(0, 0, m_image->width(), m_image->height()), 88 IntRect(0, 0, m_image->width(), m_image->height()));
89 &(imageElement->document()));
90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat e(imageElement.get(), 89 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), 90 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2));
92 &(imageElement->document()));
93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(), 91 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat e(imageElement.get(),
94 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()), 92 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()));
95 &(imageElement->document()));
96 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(), 93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create (imageElement.get(),
97 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()), 94 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image ->height()));
98 &(imageElement->document()));
99 95
100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame()); 96 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle ment->cachedImage()->image()->imageForCurrentFrame());
101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 97 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame()); 98 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im ageElement->cachedImage()->image()->imageForCurrentFrame());
103 99
104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); 100 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame()); 101 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i mage()->imageForCurrentFrame());
106 } 102 }
107 103
108 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap. 104 // Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriori ty when used to construct an ImageBitmap.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange); 139 memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateFo rPropertyChange);
144 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange); 140 memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateFor PropertyChange);
145 141
146 // HTMLImageElements should default to CacheLiveResourcePriorityLow. 142 // HTMLImageElements should default to CacheLiveResourcePriorityLow.
147 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow); 143 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi veResourcePriorityLow);
148 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 144 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
149 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow); 145 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC acheLiveResourcePriorityLow);
150 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow); 146 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa cheLiveResourcePriorityLow);
151 147
152 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(), 148 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::c reate(imageInteriorCrop.get(),
153 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height()), 149 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width(), m _image->height()));
154 &(imageInteriorCrop->document()));
155 { 150 {
156 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(), 151 RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::cre ate(imageNoCrop.get(),
157 IntRect(0, 0, m_image->width(), m_image->height()), 152 IntRect(0, 0, m_image->width(), m_image->height()));
158 &(imageNoCrop->document()));
159 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(), 153 RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitm ap::create(imageInteriorCrop.get(),
160 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height()), 154 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width( ), m_image->height()));
161 &(imageInteriorCrop->document()));
162 RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitma p::create(imageExteriorCrop.get(), 155 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()), 156 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->widt h(), m_image->height()));
164 &(imageExteriorCrop->document()));
165 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(), 157 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap ::create(imageOutsideCrop.get(),
166 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height()), 158 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_i mage->height()));
167 &(imageOutsideCrop->document()));
168 159
169 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow 160 // Images are not referenced by ImageBitmap anymore, so always CacheLive ResourcePriorityLow
170 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow); 161 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac heLiveResourcePriorityLow);
171 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 162 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
172 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow); 163 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem oryCacheLiveResourcePriorityLow);
173 164
174 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority. 165 // ImageBitmaps that do not contain any of the source image do not eleva te CacheLiveResourcePriority.
175 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow); 166 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo ryCacheLiveResourcePriorityLow);
176 } 167 }
177 // Force a garbage collection to sweep out the local ImageBitmaps. 168 // Force a garbage collection to sweep out the local ImageBitmaps.
(...skipping 11 matching lines...) Expand all
189 180
190 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc e to the original Image if the HTMLImageElement src is changed. 181 // 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) 182 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
192 { 183 {
193 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get()); 184 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum ent::create().get());
194 ResourcePtr<ImageResource> originalImageResource = new ImageResource( 185 ResourcePtr<ImageResource> originalImageResource = new ImageResource(
195 StaticBitmapImage::create(m_image).get()); 186 StaticBitmapImage::create(m_image).get());
196 image->setImageResource(originalImageResource.get()); 187 image->setImageResource(originalImageResource.get());
197 188
198 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ), 189 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get( ),
199 IntRect(0, 0, m_image->width(), m_image->height()), 190 IntRect(0, 0, m_image->width(), m_image->height()));
200 &(image->document()));
201 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame()); 191 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR esource->image()->imageForCurrentFrame());
202 192
203 ResourcePtr<ImageResource> newImageResource = new ImageResource( 193 ResourcePtr<ImageResource> newImageResource = new ImageResource(
204 StaticBitmapImage::create(m_image2).get()); 194 StaticBitmapImage::create(m_image2).get());
205 image->setImageResource(newImageResource.get()); 195 image->setImageResource(newImageResource.get());
206 196
207 // The ImageBitmap should contain the same data as the original cached image 197 // The ImageBitmap should contain the same data as the original cached image
208 { 198 {
209 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame()); 199 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm ageResource->image()->imageForCurrentFrame());
210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 200 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
211 ASSERT_NE(image1, nullptr); 201 ASSERT_NE(image1, nullptr);
212 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get(); 202 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame() .get();
213 ASSERT_NE(image2, nullptr); 203 ASSERT_NE(image2, nullptr);
214 ASSERT_EQ(image1, image2); 204 ASSERT_EQ(image1, image2);
215 } 205 }
216 206
217 { 207 {
218 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame()); 208 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe source->image()->imageForCurrentFrame());
219 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get (); 209 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get ();
220 ASSERT_NE(image1, nullptr); 210 ASSERT_NE(image1, nullptr);
221 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( ); 211 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get( );
222 ASSERT_NE(image2, nullptr); 212 ASSERT_NE(image2, nullptr);
223 ASSERT_NE(image1, image2); 213 ASSERT_NE(image1, image2);
224 } 214 }
225 } 215 }
226 216
227 } // namespace 217 } // namespace
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.cpp ('k') | third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698