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

Unified Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 1413583004: refractoring ImageBitmap class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix memory leak issue Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
index 0aa638f8170f49389c142cea35afc3cb571fdbfa..bae0e24393f2035b9bba140ac9fc27349f4e68b7 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
@@ -81,8 +81,6 @@ protected:
Persistent<MemoryCache> m_globalMemoryCache;
};
-// Verifies that the image resource held by an ImageBitmap is the same as the
-// one held by the HTMLImageElement.
TEST_F(ImageBitmapTest, ImageResourceConsistency)
{
RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create(*Document::create().get());
@@ -97,12 +95,14 @@ TEST_F(ImageBitmapTest, ImageResourceConsistency)
RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create(imageElement.get(),
IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image->height()));
- ASSERT_EQ(imageBitmapNoCrop->bitmapImage().get(), imageElement->cachedImage()->image());
- ASSERT_EQ(imageBitmapInteriorCrop->bitmapImage().get(), imageElement->cachedImage()->image());
- ASSERT_EQ(imageBitmapExteriorCrop->bitmapImage().get(), imageElement->cachedImage()->image());
+ // Now that we use SkImage::newSubset() to crop the image, the ImageBitmap::skImage() is not necessary the same
+ // as the source imageElement. See SkImage::newSubset() for details.
+ ASSERT_EQ(imageBitmapNoCrop->skImage(), imageElement->cachedImage()->image()->imageForCurrentFrame().get());
+ ASSERT_NE(imageBitmapInteriorCrop->skImage(), imageElement->cachedImage()->image()->imageForCurrentFrame().get());
+ ASSERT_NE(imageBitmapExteriorCrop->skImage(), imageElement->cachedImage()->image()->imageForCurrentFrame().get());
- RefPtr<Image> emptyImage = imageBitmapOutsideCrop->bitmapImage();
- ASSERT_NE(emptyImage.get(), imageElement->cachedImage()->image());
+ SkImage* emptyImage = imageBitmapOutsideCrop->skImage();
+ ASSERT_NE(emptyImage, imageElement->cachedImage()->image()->imageForCurrentFrame());
}
// Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap.
@@ -161,10 +161,10 @@ TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority)
RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create(imageOutsideCrop.get(),
IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image->height()));
- // Images that are referenced by ImageBitmaps have CacheLiveResourcePriorityHigh.
- ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
- ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
- ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
+ // Images are not referenced by ImageBitmap anymore, so always CacheLiveResourcePriorityLow
+ ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
+ ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
+ ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
// ImageBitmaps that do not contain any of the source image do not elevate CacheLiveResourcePriority.
ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
@@ -178,7 +178,7 @@ TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority)
ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
// There is still an ImageBitmap that references this image.
- ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
+ ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
imageBitmapInteriorCrop = nullptr;
}
@@ -192,27 +192,27 @@ TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(),
IntRect(0, 0, m_image->width(), m_image->height()));
- ASSERT_EQ(imageBitmap->bitmapImage().get(), originalImageResource->image());
+ ASSERT_EQ(imageBitmap->skImage(), originalImageResource->image()->imageForCurrentFrame().get());
ResourcePtr<ImageResource> newImageResource = new ImageResource(
StaticBitmapImage::create(m_image2).get());
image->setImageResource(newImageResource.get());
- // The ImageBitmap should contain the same data as the original cached image but should no longer hold a reference.
+ // The ImageBitmap should contain the same data as the original cached image
{
- ASSERT_NE(imageBitmap->bitmapImage().get(), originalImageResource->image());
- RefPtr<SkImage> image1 = imageBitmap->bitmapImage()->imageForCurrentFrame();
+ ASSERT_EQ(imageBitmap->skImage(), originalImageResource->image()->imageForCurrentFrame().get());
+ SkImage* image1 = imageBitmap->skImage();
ASSERT_NE(image1, nullptr);
- RefPtr<SkImage> image2 = originalImageResource->image()->imageForCurrentFrame();
+ SkImage* image2 = originalImageResource->image()->imageForCurrentFrame().get();
ASSERT_NE(image2, nullptr);
ASSERT_EQ(image1, image2);
}
{
- ASSERT_NE(imageBitmap->bitmapImage().get(), newImageResource->image());
- RefPtr<SkImage> image1 = imageBitmap->bitmapImage()->imageForCurrentFrame();
+ ASSERT_NE(imageBitmap->skImage(), newImageResource->image()->imageForCurrentFrame().get());
+ SkImage* image1 = imageBitmap->skImage();
ASSERT_NE(image1, nullptr);
- RefPtr<SkImage> image2 = newImageResource->image()->imageForCurrentFrame();
+ SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get();
ASSERT_NE(image2, nullptr);
ASSERT_NE(image1, image2);
}
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698