| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); | 74 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 RefPtr<SkImage> m_image, m_image2; | 77 RefPtr<SkImage> m_image, m_image2; |
| 78 Persistent<MemoryCache> m_globalMemoryCache; | 78 Persistent<MemoryCache> m_globalMemoryCache; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 TEST_F(ImageBitmapTest, ImageResourceConsistency) | 81 TEST_F(ImageBitmapTest, ImageResourceConsistency) |
| 82 { | 82 { |
| 83 const ImageBitmapOptions defaultOptions; | 83 const ImageBitmapOptions defaultOptions; |
| 84 RefPtrWillBeRawPtr<HTMLImageElement> imageElement = HTMLImageElement::create
(*Document::create().get()); | 84 RawPtr<HTMLImageElement> imageElement = HTMLImageElement::create(*Document::
create().get()); |
| 85 RefPtrWillBeRawPtr<ImageResource> image = ImageResource::create(StaticBitmap
Image::create(m_image).get()); | 85 RawPtr<ImageResource> image = ImageResource::create(StaticBitmapImage::creat
e(m_image).get()); |
| 86 imageElement->setImageResource(image.get()); | 86 imageElement->setImageResource(image.get()); |
| 87 | 87 |
| 88 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imag
eElement.get(), | 88 RawPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imageElement.get
(), |
| 89 IntRect(0, 0, m_image->width(), m_image->height()), | 89 IntRect(0, 0, m_image->width(), m_image->height()), |
| 90 &(imageElement->document()), defaultOptions); | 90 &(imageElement->document()), defaultOptions); |
| 91 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 91 RawPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::create(imageEleme
nt.get(), |
| 92 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() /
2, m_image->height() / 2), | 92 IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() /
2, m_image->height() / 2), |
| 93 &(imageElement->document()), defaultOptions); | 93 &(imageElement->document()), defaultOptions); |
| 94 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::creat
e(imageElement.get(), | 94 RawPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::create(imageEleme
nt.get(), |
| 95 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(),
m_image->height()), | 95 IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(),
m_image->height()), |
| 96 &(imageElement->document()), defaultOptions); | 96 &(imageElement->document()), defaultOptions); |
| 97 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create
(imageElement.get(), | 97 RawPtr<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap::create(imageElemen
t.get(), |
| 98 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image
->height()), | 98 IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image
->height()), |
| 99 &(imageElement->document()), defaultOptions); | 99 &(imageElement->document()), defaultOptions); |
| 100 | 100 |
| 101 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle
ment->cachedImage()->getImage()->imageForCurrentFrame()); | 101 ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageEle
ment->cachedImage()->getImage()->imageForCurrentFrame()); |
| 102 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->getImage()->imageForCurrentFrame()); | 102 ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->getImage()->imageForCurrentFrame()); |
| 103 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->getImage()->imageForCurrentFrame()); | 103 ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), im
ageElement->cachedImage()->getImage()->imageForCurrentFrame()); |
| 104 | 104 |
| 105 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); | 105 StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); |
| 106 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->g
etImage()->imageForCurrentFrame()); | 106 ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->g
etImage()->imageForCurrentFrame()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc
e to the original Image if the HTMLImageElement src is changed. | 109 // Verifies that ImageBitmaps constructed from HTMLImageElements hold a referenc
e to the original Image if the HTMLImageElement src is changed. |
| 110 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) | 110 TEST_F(ImageBitmapTest, ImageBitmapSourceChanged) |
| 111 { | 111 { |
| 112 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*Docum
ent::create().get()); | 112 RawPtr<HTMLImageElement> image = HTMLImageElement::create(*Document::create(
).get()); |
| 113 RefPtrWillBeRawPtr<ImageResource> originalImageResource = ImageResource::cre
ate( | 113 RawPtr<ImageResource> originalImageResource = ImageResource::create( |
| 114 StaticBitmapImage::create(m_image).get()); | 114 StaticBitmapImage::create(m_image).get()); |
| 115 image->setImageResource(originalImageResource.get()); | 115 image->setImageResource(originalImageResource.get()); |
| 116 | 116 |
| 117 const ImageBitmapOptions defaultOptions; | 117 const ImageBitmapOptions defaultOptions; |
| 118 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(
), | 118 RawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(), |
| 119 IntRect(0, 0, m_image->width(), m_image->height()), | 119 IntRect(0, 0, m_image->width(), m_image->height()), |
| 120 &(image->document()), defaultOptions); | 120 &(image->document()), defaultOptions); |
| 121 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR
esource->getImage()->imageForCurrentFrame()); | 121 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageR
esource->getImage()->imageForCurrentFrame()); |
| 122 | 122 |
| 123 RefPtrWillBeRawPtr<ImageResource> newImageResource = ImageResource::create( | 123 RawPtr<ImageResource> newImageResource = ImageResource::create( |
| 124 StaticBitmapImage::create(m_image2).get()); | 124 StaticBitmapImage::create(m_image2).get()); |
| 125 image->setImageResource(newImageResource.get()); | 125 image->setImageResource(newImageResource.get()); |
| 126 | 126 |
| 127 // The ImageBitmap should contain the same data as the original cached image | 127 // The ImageBitmap should contain the same data as the original cached image |
| 128 { | 128 { |
| 129 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm
ageResource->getImage()->imageForCurrentFrame()); | 129 ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalIm
ageResource->getImage()->imageForCurrentFrame()); |
| 130 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); | 130 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
| 131 ASSERT_NE(image1, nullptr); | 131 ASSERT_NE(image1, nullptr); |
| 132 SkImage* image2 = originalImageResource->getImage()->imageForCurrentFram
e().get(); | 132 SkImage* image2 = originalImageResource->getImage()->imageForCurrentFram
e().get(); |
| 133 ASSERT_NE(image2, nullptr); | 133 ASSERT_NE(image2, nullptr); |
| 134 ASSERT_EQ(image1, image2); | 134 ASSERT_EQ(image1, image2); |
| 135 } | 135 } |
| 136 | 136 |
| 137 { | 137 { |
| 138 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe
source->getImage()->imageForCurrentFrame()); | 138 ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageRe
source->getImage()->imageForCurrentFrame()); |
| 139 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); | 139 SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get
(); |
| 140 ASSERT_NE(image1, nullptr); | 140 ASSERT_NE(image1, nullptr); |
| 141 SkImage* image2 = newImageResource->getImage()->imageForCurrentFrame().g
et(); | 141 SkImage* image2 = newImageResource->getImage()->imageForCurrentFrame().g
et(); |
| 142 ASSERT_NE(image2, nullptr); | 142 ASSERT_NE(image2, nullptr); |
| 143 ASSERT_NE(image1, image2); | 143 ASSERT_NE(image1, image2); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |