| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 m_bitmap.eraseColor(0xFFFFFFFF); | 58 m_bitmap.eraseColor(0xFFFFFFFF); |
| 59 | 59 |
| 60 m_bitmap2.allocN32Pixels(5, 5); | 60 m_bitmap2.allocN32Pixels(5, 5); |
| 61 m_bitmap2.eraseColor(0xAAAAAAAA); | 61 m_bitmap2.eraseColor(0xAAAAAAAA); |
| 62 | 62 |
| 63 // Save the global memory cache to restore it upon teardown. | 63 // Save the global memory cache to restore it upon teardown. |
| 64 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); | 64 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); |
| 65 } | 65 } |
| 66 virtual void TearDown() | 66 virtual void TearDown() |
| 67 { | 67 { |
| 68 // Garbage collection is required prior to switching out the | |
| 69 // test's memory cache; image resources are released, evicting | |
| 70 // them from the cache. | |
| 71 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
| 72 | |
| 73 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); | 68 replaceMemoryCacheForTesting(m_globalMemoryCache.release()); |
| 74 } | 69 } |
| 75 | 70 |
| 76 SkBitmap m_bitmap, m_bitmap2; | 71 SkBitmap m_bitmap, m_bitmap2; |
| 77 OwnPtrWillBePersistent<MemoryCache> m_globalMemoryCache; | 72 OwnPtrWillBePersistent<MemoryCache> m_globalMemoryCache; |
| 78 }; | 73 }; |
| 79 | 74 |
| 80 // Verifies that the image resource held by an ImageBitmap is the same as the | 75 // Verifies that the image resource held by an ImageBitmap is the same as the |
| 81 // one held by the HTMLImageElement. | 76 // one held by the HTMLImageElement. |
| 82 TEST_F(ImageBitmapTest, ImageResourceConsistency) | 77 TEST_F(ImageBitmapTest, ImageResourceConsistency) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap
::create(imageOutsideCrop.get(), IntRect(-m_bitmap.width(), -m_bitmap.height(),
m_bitmap.width(), m_bitmap.height())); | 141 RefPtrWillBePersistent<ImageBitmap> imageBitmapOutsideCrop = ImageBitmap
::create(imageOutsideCrop.get(), IntRect(-m_bitmap.width(), -m_bitmap.height(),
m_bitmap.width(), m_bitmap.height())); |
| 147 | 142 |
| 148 // Images that are referenced by ImageBitmaps have CacheLiveResourcePrio
rityHigh. | 143 // Images that are referenced by ImageBitmaps have CacheLiveResourcePrio
rityHigh. |
| 149 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac
heLiveResourcePriorityHigh); | 144 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCac
heLiveResourcePriorityHigh); |
| 150 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem
oryCacheLiveResourcePriorityHigh); | 145 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), Mem
oryCacheLiveResourcePriorityHigh); |
| 151 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem
oryCacheLiveResourcePriorityHigh); | 146 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), Mem
oryCacheLiveResourcePriorityHigh); |
| 152 | 147 |
| 153 // ImageBitmaps that do not contain any of the source image do not eleva
te CacheLiveResourcePriority. | 148 // ImageBitmaps that do not contain any of the source image do not eleva
te CacheLiveResourcePriority. |
| 154 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo
ryCacheLiveResourcePriorityLow); | 149 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), Memo
ryCacheLiveResourcePriorityLow); |
| 155 } | 150 } |
| 156 // Force a garbage collection to sweep out the local ImageBitmaps. | |
| 157 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
| 158 | |
| 159 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w
hen no ImageBitmaps reference the image. | 151 // CacheLiveResourcePriroity should return to CacheLiveResourcePriorityLow w
hen no ImageBitmaps reference the image. |
| 160 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi
veResourcePriorityLow); | 152 ASSERT_EQ(memoryCache()->priority(imageNoCrop->cachedImage()), MemoryCacheLi
veResourcePriorityLow); |
| 161 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityLow); | 153 ASSERT_EQ(memoryCache()->priority(imageExteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityLow); |
| 162 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa
cheLiveResourcePriorityLow); | 154 ASSERT_EQ(memoryCache()->priority(imageOutsideCrop->cachedImage()), MemoryCa
cheLiveResourcePriorityLow); |
| 163 | 155 |
| 164 // There is still an ImageBitmap that references this image. | 156 // There is still an ImageBitmap that references this image. |
| 165 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityHigh); | 157 ASSERT_EQ(memoryCache()->priority(imageInteriorCrop->cachedImage()), MemoryC
acheLiveResourcePriorityHigh); |
| 166 imageBitmapInteriorCrop = nullptr; | 158 imageBitmapInteriorCrop = nullptr; |
| 167 | 159 |
| 168 cachedImageNoCrop->removeClient(&mockClient1); | 160 cachedImageNoCrop->removeClient(&mockClient1); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 { | 196 { |
| 205 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre
ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he
ight())); | 197 RefPtrWillBeRawPtr<ImageBitmap> imageBitmapFromCanvas = ImageBitmap::cre
ate(canvasElement.get(), IntRect(0, 0, canvasElement->width(), canvasElement->he
ight())); |
| 206 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In
tRect(0, 0, 20, 20)); | 198 imageBitmapDerived = ImageBitmap::create(imageBitmapFromCanvas.get(), In
tRect(0, 0, 20, 20)); |
| 207 } | 199 } |
| 208 CanvasRenderingContext* context = canvasElement->getContext("2d"); | 200 CanvasRenderingContext* context = canvasElement->getContext("2d"); |
| 209 TrackExceptionState exceptionState; | 201 TrackExceptionState exceptionState; |
| 210 toCanvasRenderingContext2D(context)->drawImage(imageBitmapDerived.get(), 0,
0, exceptionState); | 202 toCanvasRenderingContext2D(context)->drawImage(imageBitmapDerived.get(), 0,
0, exceptionState); |
| 211 } | 203 } |
| 212 | 204 |
| 213 } // namespace | 205 } // namespace |
| OLD | NEW |