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

Side by Side Diff: Source/core/page/ImageBitmapTest.cpp

Issue 22613002: Allow ImageBitmaps derived from HTMLImageElements to be evicted from RAM. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make destructor virtual. Created 7 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/ImageBitmap.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "core/page/ImageBitmap.h"
33
34 #include "core/dom/Document.h"
35 #include "core/html/HTMLImageElement.h"
36 #include "core/loader/cache/CachedImage.h"
37 #include "core/platform/graphics/BitmapImage.h"
38 #include "core/platform/graphics/skia/NativeImageSkia.h"
39
40 #include <gtest/gtest.h>
41
42 namespace WebCore {
43
44 class ImageBitmapTest : public ::testing::Test {
45 };
46
47 // Verifies that the cached image held by an ImageBitmap is the same as the
48 // one held by the HTMLImageElement.
49 TEST_F(ImageBitmapTest, CachedImageConsistency)
50 {
51 SkBitmap bitmap;
52 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
53 bitmap.allocPixels();
54 int width = bitmap.width();
55 int height = bitmap.height();
56 for (int y = 0; y < height; ++y)
57 for (int x = 0; x < width; ++x)
58 *bitmap.getAddr32(x, y) = 0xFFFFFFFF;
59
60 RefPtr<HTMLImageElement> imageElement = HTMLImageElement::create(Document::c reate().get());
61 imageElement->setCachedImage(new CachedImage(BitmapImage::create(NativeImage Skia::create(bitmap)).get()));
62
63 RefPtr<ImageBitmap> imageBitmapNoCrop = ImageBitmap::create(imageElement.get (), IntRect(0, 0, width, height));
64 RefPtr<ImageBitmap> imageBitmapInteriorCrop = ImageBitmap::create(imageEleme nt.get(), IntRect(width / 2, height / 2, width / 2, height / 2));
65 RefPtr<ImageBitmap> imageBitmapExteriorCrop = ImageBitmap::create(imageEleme nt.get(), IntRect(-width / 2, -height / 2, width, height));
66 RefPtr<ImageBitmap> imageBitmapOutsideImageRect = ImageBitmap::create(imageE lement.get(), IntRect(-width, -height, width, height));
67
68 ASSERT_EQ(imageBitmapNoCrop->bitmapImage().get(), imageElement->cachedImage( )->image());
69 ASSERT_EQ(imageBitmapInteriorCrop->bitmapImage().get(), imageElement->cached Image()->image());
70 ASSERT_EQ(imageBitmapExteriorCrop->bitmapImage().get(), imageElement->cached Image()->image());
71 ASSERT_EQ(imageBitmapOutsideImageRect->bitmapImage().get(), imageElement->ca chedImage()->image());
72 }
73
74 } // namespace
OLDNEW
« no previous file with comments | « Source/core/page/ImageBitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698