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

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

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