| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/frame/ImageBitmap.h" | 31 #include "core/frame/ImageBitmap.h" |
| 32 | 32 |
| 33 #include "SkPixelRef.h" // FIXME: qualify this skia header file. | 33 #include "SkPixelRef.h" // FIXME: qualify this skia header file. |
| 34 #include "bindings/core/v8/UnionTypesCore.h" | 34 #include "bindings/core/v8/UnionTypesCore.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/fetch/ImageResource.h" | 36 #include "core/fetch/ImageResource.h" |
| 37 #include "core/fetch/MemoryCache.h" | 37 #include "core/fetch/MemoryCache.h" |
| 38 #include "core/fetch/MockImageResourceClient.h" | 38 #include "core/fetch/MockImageResourceClient.h" |
| 39 #include "core/fetch/ResourcePtr.h" | |
| 40 #include "core/html/HTMLCanvasElement.h" | 39 #include "core/html/HTMLCanvasElement.h" |
| 41 #include "core/html/HTMLImageElement.h" | 40 #include "core/html/HTMLImageElement.h" |
| 42 #include "core/html/HTMLVideoElement.h" | 41 #include "core/html/HTMLVideoElement.h" |
| 43 #include "platform/graphics/StaticBitmapImage.h" | 42 #include "platform/graphics/StaticBitmapImage.h" |
| 44 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
| 45 #include "platform/network/ResourceRequest.h" | 44 #include "platform/network/ResourceRequest.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "third_party/skia/include/core/SkImage.h" | 46 #include "third_party/skia/include/core/SkImage.h" |
| 48 #include "third_party/skia/include/core/SkSurface.h" | 47 #include "third_party/skia/include/core/SkSurface.h" |
| 49 #include "wtf/OwnPtr.h" | 48 #include "wtf/OwnPtr.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); | 74 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); |
| 76 } | 75 } |
| 77 | 76 |
| 78 RefPtr<SkImage> m_image, m_image2; | 77 RefPtr<SkImage> m_image, m_image2; |
| 79 Persistent<MemoryCache> m_globalMemoryCache; | 78 Persistent<MemoryCache> m_globalMemoryCache; |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 TEST_F(ImageBitmapTest, ImageResourceConsistency) | 81 TEST_F(ImageBitmapTest, ImageResourceConsistency) |
| 83 { | 82 { |
| 84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create
(*Document::create().get()); | 83 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create
(*Document::create().get()); |
| 85 imageElement->setImageResource(new ImageResource(StaticBitmapImage::create(m
_image).get())); | 84 RefPtrWillBeRawPtr<ImageResource> image = ImageResource::create(StaticBitmap
Image::create(m_image).get()); |
| 85 imageElement->setImageResource(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 &(imageElement->document())); |
| 90 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 90 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), | 91 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() /
2, m_image->height() / 2), |
| 92 &(imageElement->document())); | 92 &(imageElement->document())); |
| 93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 93 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat
e(imageElement.get(), |
| 94 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())); | 95 &(imageElement->document())); |
| 96 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create
(imageElement.get(), | 96 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create
(imageElement.get(), |
| 97 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())); | 98 &(imageElement->document())); |
| 99 | 99 |
| 100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle
ment->cachedImage()->image()->imageForCurrentFrame()); | 100 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle
ment->cachedImage()->image()->imageForCurrentFrame()); |
| 101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); | 101 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); |
| 102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); | 102 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->image()->imageForCurrentFrame()); |
| 103 | 103 |
| 104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); | 104 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); |
| 105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i
mage()->imageForCurrentFrame()); | 105 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->i
mage()->imageForCurrentFrame()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // 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. |
| 109 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme
nt do not have elevated CacheLiveResourcePriority. | 109 // ImageBitmaps that have crop rects outside of the bounds of the HTMLImageEleme
nt do not have elevated CacheLiveResourcePriority. |
| 110 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority) | 110 TEST_F(ImageBitmapTest, ImageBitmapLiveResourcePriority) |
| 111 { | 111 { |
| 112 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre
ate(*Document::create().get()); | 112 RefPtrWillBePersistent<HTMLImageElement> imageNoCrop = HTMLImageElement::cre
ate(*Document::create().get()); |
| 113 ResourcePtr<ImageResource> cachedImageNoCrop = new ImageResource(ResourceReq
uest("http://foo.com/1"), | 113 RefPtrWillBeRawPtr<ImageResource> cachedImageNoCrop = ImageResource::create(
ResourceRequest("http://foo.com/1"), |
| 114 StaticBitmapImage::create(m_image).get()); | 114 StaticBitmapImage::create(m_image).get()); |
| 115 imageNoCrop->setImageResource(cachedImageNoCrop.get()); | 115 imageNoCrop->setImageResource(cachedImageNoCrop.get()); |
| 116 | 116 |
| 117 RefPtrWillBePersistent<HTMLImageElement> imageInteriorCrop = HTMLImageElemen
t::create(*Document::create().get()); | 117 RefPtrWillBePersistent<HTMLImageElement> imageInteriorCrop = HTMLImageElemen
t::create(*Document::create().get()); |
| 118 ResourcePtr<ImageResource> cachedImageInteriorCrop = new ImageResource(Resou
rceRequest("http://foo.com/2"), | 118 RefPtrWillBeRawPtr<ImageResource> cachedImageInteriorCrop = ImageResource::c
reate(ResourceRequest("http://foo.com/2"), |
| 119 StaticBitmapImage::create(m_image).get()); | 119 StaticBitmapImage::create(m_image).get()); |
| 120 imageInteriorCrop->setImageResource(cachedImageInteriorCrop.get()); | 120 imageInteriorCrop->setImageResource(cachedImageInteriorCrop.get()); |
| 121 | 121 |
| 122 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen
t::create(*Document::create().get()); | 122 RefPtrWillBePersistent<HTMLImageElement> imageExteriorCrop = HTMLImageElemen
t::create(*Document::create().get()); |
| 123 ResourcePtr<ImageResource> cachedImageExteriorCrop = new ImageResource(Resou
rceRequest("http://foo.com/3"), | 123 RefPtrWillBeRawPtr<ImageResource> cachedImageExteriorCrop = ImageResource::c
reate(ResourceRequest("http://foo.com/3"), |
| 124 StaticBitmapImage::create(m_image).get()); | 124 StaticBitmapImage::create(m_image).get()); |
| 125 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get()); | 125 imageExteriorCrop->setImageResource(cachedImageExteriorCrop.get()); |
| 126 | 126 |
| 127 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement
::create(*Document::create().get()); | 127 RefPtrWillBePersistent<HTMLImageElement> imageOutsideCrop = HTMLImageElement
::create(*Document::create().get()); |
| 128 ResourcePtr<ImageResource> cachedImageOutsideCrop = new ImageResource(Resour
ceRequest("http://foo.com/4"), | 128 RefPtrWillBeRawPtr<ImageResource> cachedImageOutsideCrop = ImageResource::cr
eate(ResourceRequest("http://foo.com/4"), |
| 129 StaticBitmapImage::create(m_image).get()); | 129 StaticBitmapImage::create(m_image).get()); |
| 130 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get()); | 130 imageOutsideCrop->setImageResource(cachedImageOutsideCrop.get()); |
| 131 | 131 |
| 132 MockImageResourceClient mockClient1(cachedImageNoCrop); | 132 MockImageResourceClient mockClient1(cachedImageNoCrop); |
| 133 MockImageResourceClient mockClient2(cachedImageInteriorCrop); | 133 MockImageResourceClient mockClient2(cachedImageInteriorCrop); |
| 134 MockImageResourceClient mockClient3(cachedImageExteriorCrop); | 134 MockImageResourceClient mockClient3(cachedImageExteriorCrop); |
| 135 MockImageResourceClient mockClient4(cachedImageOutsideCrop); | 135 MockImageResourceClient mockClient4(cachedImageOutsideCrop); |
| 136 | 136 |
| 137 memoryCache()->add(cachedImageNoCrop.get()); | 137 memoryCache()->add(cachedImageNoCrop.get()); |
| 138 memoryCache()->add(cachedImageInteriorCrop.get()); | 138 memoryCache()->add(cachedImageInteriorCrop.get()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 // There is still an ImageBitmap that references this image. | 185 // There is still an ImageBitmap that references this image. |
| 186 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityLow); | 186 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityLow); |
| 187 imageBitmapInteriorCrop = nullptr; | 187 imageBitmapInteriorCrop = nullptr; |
| 188 } | 188 } |
| 189 | 189 |
| 190 // 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. |
| 191 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) | 191 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) |
| 192 { | 192 { |
| 193 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum
ent::create().get()); | 193 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum
ent::create().get()); |
| 194 ResourcePtr<ImageResource> originalImageResource = new ImageResource( | 194 RefPtrWillBeRawPtr<ImageResource> originalImageResource = ImageResource::cre
ate( |
| 195 StaticBitmapImage::create(m_image).get()); | 195 StaticBitmapImage::create(m_image).get()); |
| 196 image->setImageResource(originalImageResource.get()); | 196 image->setImageResource(originalImageResource.get()); |
| 197 | 197 |
| 198 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(
), | 198 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(
), |
| 199 IntRect(0, 0, m_image->width(), m_image->height()), | 199 IntRect(0, 0, m_image->width(), m_image->height()), |
| 200 &(image->document())); | 200 &(image->document())); |
| 201 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR
esource->image()->imageForCurrentFrame()); | 201 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR
esource->image()->imageForCurrentFrame()); |
| 202 | 202 |
| 203 ResourcePtr<ImageResource> newImageResource = new ImageResource( | 203 RefPtrWillBeRawPtr<ImageResource> newImageResource = ImageResource::create( |
| 204 StaticBitmapImage::create(m_image2).get()); | 204 StaticBitmapImage::create(m_image2).get()); |
| 205 image->setImageResource(newImageResource.get()); | 205 image->setImageResource(newImageResource.get()); |
| 206 | 206 |
| 207 // 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 |
| 208 { | 208 { |
| 209 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm
ageResource->image()->imageForCurrentFrame()); | 209 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm
ageResource->image()->imageForCurrentFrame()); |
| 210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); | 210 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
| 211 ASSERT_NE(image1, nullptr); | 211 ASSERT_NE(image1, nullptr); |
| 212 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame()
.get(); | 212 SkImage* image2 = originalImageResource->image()->imageForCurrentFrame()
.get(); |
| 213 ASSERT_NE(image2, nullptr); | 213 ASSERT_NE(image2, nullptr); |
| 214 ASSERT_EQ(image1, image2); | 214 ASSERT_EQ(image1, image2); |
| 215 } | 215 } |
| 216 | 216 |
| 217 { | 217 { |
| 218 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe
source->image()->imageForCurrentFrame()); | 218 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe
source->image()->imageForCurrentFrame()); |
| 219 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); | 219 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
| 220 ASSERT_NE(image1, nullptr); | 220 ASSERT_NE(image1, nullptr); |
| 221 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get(
); | 221 SkImage* image2 = newImageResource->image()->imageForCurrentFrame().get(
); |
| 222 ASSERT_NE(image2, nullptr); | 222 ASSERT_NE(image2, nullptr); |
| 223 ASSERT_NE(image1, image2); | 223 ASSERT_NE(image1, image2); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |