Source/core/frame/ImageBitmapTest.cpp
// Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap.
// ImageBitmaps that have crop rects outside of the bounds of the HTMLImageElement do not have elevated CacheLiveResourcePriority.
Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap.
ImageBitmaps that have crop rects outside of the bounds of the HTMLImageElement do not have elevated CacheLiveResourcePriority.
Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap . ImageBitmaps that have crop rects outside of the bounds of the HTMLImageElement do not have elevated CacheLiveResourcePriority .
TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority)
{
    RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::create(*Document::create().get());
    ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceRequest("http://foo.com/1"), BitmapImage::create(NativeImageSkia::create(m_bitmap)).get());
    imageNoCrop->setImageResource(cachedImageNoCrop.get());
    RefPtrWillBePersistent<HTMLImageElement> imageInteriorCrop = HTMLImageElement::create(*Document::create().get());
    ResourcePtr<ImageResource> cachedImageInteriorCrop = new ImageResource(ResourceRequest("http://foo.com/2"), BitmapImage::create(NativeImageSkia::create(m_bitmap)).get());
    imageInteriorCrop->setImageResource(cachedImageInteriorCrop.get());
    RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElement::create(*Document::create().get());
    ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(ResourceRequest("http://foo.com/3"), BitmapImage::create(NativeImageSkia::create(m_bitmap)).get());
    imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get());
    RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement::create(*Document::create().get());
    ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(ResourceRequest("http://foo.com/4"), BitmapImage::create(NativeImageSkia::create(m_bitmap)).get());
    imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get());
    MockImageResourceClient mockClient1, mockClient2, mockClient3, mockClient4;
    cachedImageNoCrop->addClient(&mockClient1);
    cachedImageInteriorCrop->addClient(&mockClient2);
    cachedImageExteriorCrop->addClient(&mockClient3);
    cachedImageOutsideCrop->addClient(&mockClient4);
    memoryCache()->add(cachedImageNoCrop.get());
    memoryCache()->add(cachedImageInteriorCrop.get());
    memoryCache()->add(cachedImageExteriorCrop.get());
    memoryCache()->add(cachedImageOutsideCrop.get());
    memoryCache()->updateDecodedResource(cachedImageNoCrop.get(), UpdateForPropertyChange);
    memoryCache()->updateDecodedResource(cachedImageInteriorCrop.get(), UpdateForPropertyChange);
    memoryCache()->updateDecodedResource(cachedImageExteriorCrop.get(), UpdateForPropertyChange);
    memoryCache()->updateDecodedResource(cachedImageOutsideCrop.get(), UpdateForPropertyChange);
    ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::create(imageInteriorCrop.get(), IntRect(m_bitmap.width() / 2, m_bitmap.height() / 2, m_bitmap.width(), m_bitmap.height()));
    {
        RefPtrWillBePersistent<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imageNoCrop.get(), IntRect(0, 0, m_bitmap.width(), m_bitmap.height()));
        RefPtrWillBePersistent<ImageBitmap> imageBitmapInteriorCrop2 = ImageBitmap::create(imageInteriorCrop.get(), IntRect(m_bitmap.width() / 2, m_bitmap.height() / 2, m_bitmap.width(), m_bitmap.height()));
        RefPtrWillBePersistent<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::create(imageExteriorCrop.get(), IntRect(-m_bitmap.width() / 2, -m_bitmap.height() / 2, m_bitmap.width(), m_bitmap.height()));
        RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create(imageOutsideCrop.get(), IntRect(-m_bitmap.width(), -m_bitmap.height(), m_bitmap.width(), m_bitmap.height()));
        ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
        ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
        ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
        ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    }
    Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
    ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCacheLiveResourcePriorityLow);
    ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryCacheLiveResourcePriorityHigh);
    imageBitmapInteriorCrop = nullptr;
}
TEST_F ( ImageBitmapTest , ImageBitmapLiveResourcePriority ) { RefPtrWillBePersistent < HTMLImageElement > imageNoCrop = HTMLImageElement :: create ( * Document :: create ( ) . get ( ) ) ; ResourcePtr < ImageResource > cachedImageNoCrop = new ImageResource ( ResourceRequest ( " " ) , BitmapImage :: create ( NativeImageSkia :: create ( m_bitmap ) ) . get ( ) ) ; imageNoCrop -> setImageResource ( cachedImageNoCrop . get ( ) ) ; RefPtrWillBePersistent < HTMLImageElement > imageInteriorCrop = HTMLImageElement :: create ( * Document :: create ( ) . get ( ) ) ; ResourcePtr < ImageResource > cachedImageInteriorCrop = new ImageResource ( ResourceRequest ( " " ) , BitmapImage :: create ( NativeImageSkia :: create ( m_bitmap ) ) . get ( ) ) ; imageInteriorCrop -> setImageResource ( cachedImageInteriorCrop . get ( ) ) ; RefPtrWillBePersistent < HTMLImageElement > imageExteriorCrop = HTMLImageElement :: create ( * Document :: create ( ) . get ( ) ) ; ResourcePtr < ImageResource > cachedImageExteriorCrop = new ImageResource ( ResourceRequest ( " " ) , BitmapImage :: create ( NativeImageSkia :: create ( m_bitmap ) ) . get ( ) ) ; imageExteriorCrop -> setImageResource ( cachedImageExteriorCrop . get ( ) ) ; RefPtrWillBePersistent < HTMLImageElement > imageOutsideCrop = HTMLImageElement :: create ( * Document :: create ( ) . get ( ) ) ; ResourcePtr < ImageResource > cachedImageOutsideCrop = new ImageResource ( ResourceRequest ( " " ) , BitmapImage :: create ( NativeImageSkia :: create ( m_bitmap ) ) . get ( ) ) ; imageOutsideCrop -> setImageResource ( cachedImageOutsideCrop . get ( ) ) ; MockImageResourceClient mockClient1 , mockClient2 , mockClient3 , mockClient4 ; cachedImageNoCrop -> addClient ( & mockClient1 ) ; cachedImageInteriorCrop -> addClient ( & mockClient2 ) ; cachedImageExteriorCrop -> addClient ( & mockClient3 ) ; cachedImageOutsideCrop -> addClient ( & mockClient4 ) ; memoryCache ( ) -> add ( cachedImageNoCrop . get ( ) ) ; memoryCache ( ) -> add ( cachedImageInteriorCrop . get ( ) ) ; memoryCache ( ) -> add ( cachedImageExteriorCrop . get ( ) ) ; memoryCache ( ) -> add ( cachedImageOutsideCrop . get ( ) ) ; memoryCache ( ) -> updateDecodedResource ( cachedImageNoCrop . get ( ) , UpdateForPropertyChange ) ; memoryCache ( ) -> updateDecodedResource ( cachedImageInteriorCrop . get ( ) , UpdateForPropertyChange ) ; memoryCache ( ) -> updateDecodedResource ( cachedImageExteriorCrop . get ( ) , UpdateForPropertyChange ) ; memoryCache ( ) -> updateDecodedResource ( cachedImageOutsideCrop . get ( ) , UpdateForPropertyChange ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageNoCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageInteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageExteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageOutsideCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; RefPtrWillBePersistent < ImageBitmap > imageBitmapInteriorCrop = ImageBitmap :: create ( imageInteriorCrop . get ( ) , IntRect ( m_bitmap . width ( ) / 2 , m_bitmap . height ( ) / 2 , m_bitmap . width ( ) , m_bitmap . height ( ) ) ) ; { RefPtrWillBePersistent < ImageBitmap > imageBitmapNoCrop = ImageBitmap :: create ( imageNoCrop . get ( ) , IntRect ( 0 , 0 , m_bitmap . width ( ) , m_bitmap . height ( ) ) ) ; RefPtrWillBePersistent < ImageBitmap > imageBitmapInteriorCrop2 = ImageBitmap :: create ( imageInteriorCrop . get ( ) , IntRect ( m_bitmap . width ( ) / 2 , m_bitmap . height ( ) / 2 , m_bitmap . width ( ) , m_bitmap . height ( ) ) ) ; RefPtrWillBePersistent < ImageBitmap > imageBitmapExteriorCrop = ImageBitmap :: create ( imageExteriorCrop . get ( ) , IntRect ( - m_bitmap . width ( ) / 2 , - m_bitmap . height ( ) / 2 , m_bitmap . width ( ) , m_bitmap . height ( ) ) ) ; RefPtrWillBePersistent < ImageBitmap > imageBitmapOutsideCrop = ImageBitmap :: create ( imageOutsideCrop . get ( ) , IntRect ( - m_bitmap . width ( ) , - m_bitmap . height ( ) , m_bitmap . width ( ) , m_bitmap . height ( ) ) ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageNoCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityHigh ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageInteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityHigh ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageExteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityHigh ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageOutsideCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; } Heap :: collectGarbage ( ThreadState :: NoHeapPointersOnStack ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageNoCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageExteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageOutsideCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityLow ) ; ASSERT_EQ ( memoryCache ( ) -> priority ( imageInteriorCrop -> cachedImage ( ) ) , MemoryCacheLiveResourcePriorityHigh ) ; imageBitmapInteriorCrop = nullptr ; }
Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap.
Verifies that HTMLImageElements are given an elevated CacheLiveResourcePriority when used to construct an ImageBitmap .
// HTMLImageElements should default to CacheLiveResourcePriorityLow. // Images that are referenced by ImageBitmaps have CacheLiveResourcePriorityHigh. // ImageBitmaps that do not contain any of the source image do not elevate CacheLiveResourcePriority. // Force a garbage collection to sweep out the local ImageBitmaps. // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow when no ImageBitmaps reference the image. // There is still an ImageBitmap that references this image.