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

Side by Side Diff: Source/platform/graphics/ImageLayerChromiumTest.cpp

Issue 1001703003: Take NativeImageSkia out behind the woodshed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make bitmapForCurrentFrame() return SkBitmap by value. Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "platform/graphics/Image.h" 26 #include "platform/graphics/Image.h"
27 27
28 #include "platform/graphics/GraphicsLayer.h" 28 #include "platform/graphics/GraphicsLayer.h"
29 #include "platform/graphics/skia/NativeImageSkia.h"
30 #include "wtf/PassOwnPtr.h" 29 #include "wtf/PassOwnPtr.h"
31 30
32 #include <gtest/gtest.h> 31 #include <gtest/gtest.h>
33 32
34 using namespace blink; 33 using namespace blink;
35 34
36 namespace { 35 namespace {
37 36
38 class MockGraphicsLayerClient : public GraphicsLayerClient { 37 class MockGraphicsLayerClient : public GraphicsLayerClient {
39 public: 38 public:
40 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL ayerPaintingPhase, const IntRect& inClip) override { } 39 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL ayerPaintingPhase, const IntRect& inClip) override { }
41 virtual String debugName(const GraphicsLayer*) override { return String(); } 40 virtual String debugName(const GraphicsLayer*) override { return String(); }
42 }; 41 };
43 42
44 class TestImage : public Image { 43 class TestImage : public Image {
45 public: 44 public:
46 45
47 static PassRefPtr<TestImage> create(const IntSize& size, bool isOpaque) 46 static PassRefPtr<TestImage> create(const IntSize& size, bool isOpaque)
48 { 47 {
49 return adoptRef(new TestImage(size, isOpaque)); 48 return adoptRef(new TestImage(size, isOpaque));
50 } 49 }
51 50
52 explicit TestImage(const IntSize& size, bool isOpaque) 51 explicit TestImage(const IntSize& size, bool isOpaque)
53 : Image(0) 52 : Image(0)
54 , m_size(size) 53 , m_size(size)
55 { 54 {
56 SkBitmap bitmap; 55 m_bitmap.allocN32Pixels(size.width(), size.height(), isOpaque);
57 bitmap.allocN32Pixels(size.width(), size.height(), isOpaque); 56 m_bitmap.eraseColor(SK_ColorTRANSPARENT);
58 bitmap.eraseColor(SK_ColorTRANSPARENT);
59 m_nativeImage = NativeImageSkia::create(bitmap);
60 } 57 }
61 58
62 virtual bool isBitmapImage() const override 59 virtual bool isBitmapImage() const override
63 { 60 {
64 return true; 61 return true;
65 } 62 }
66 63
67 virtual bool currentFrameKnownToBeOpaque() override 64 virtual bool currentFrameKnownToBeOpaque() override
68 { 65 {
69 return m_nativeImage->bitmap().isOpaque(); 66 return m_bitmap.isOpaque();
70 } 67 }
71 68
72 virtual IntSize size() const override 69 virtual IntSize size() const override
73 { 70 {
74 return m_size; 71 return m_size;
75 } 72 }
76 73
77 virtual PassRefPtr<NativeImageSkia> nativeImageForCurrentFrame() override 74 virtual SkBitmap bitmapForCurrentFrame() override
78 { 75 {
79 if (m_size.isZero()) 76 if (m_size.isZero())
80 return nullptr; 77 return SkBitmap();
81 78
82 return m_nativeImage; 79 return m_bitmap;
83 } 80 }
84 81
85 // Stub implementations of pure virtual Image functions. 82 // Stub implementations of pure virtual Image functions.
86 virtual void destroyDecodedData(bool) override 83 virtual void destroyDecodedData(bool) override
87 { 84 {
88 } 85 }
89 86
90 void draw(GraphicsContext*, const FloatRect&, const FloatRect&, SkXfermode:: Mode, RespectImageOrientationEnum) override 87 void draw(GraphicsContext*, const FloatRect&, const FloatRect&, SkXfermode:: Mode, RespectImageOrientationEnum) override
91 { 88 {
92 } 89 }
93 90
94 private: 91 private:
95 92
96 IntSize m_size; 93 IntSize m_size;
97 94
98 RefPtr<NativeImageSkia> m_nativeImage; 95 SkBitmap m_bitmap;
99 }; 96 };
100 97
101 class GraphicsLayerForTesting : public GraphicsLayer { 98 class GraphicsLayerForTesting : public GraphicsLayer {
102 public: 99 public:
103 explicit GraphicsLayerForTesting(GraphicsLayerClient* client) 100 explicit GraphicsLayerForTesting(GraphicsLayerClient* client)
104 : GraphicsLayer(client) { }; 101 : GraphicsLayer(client) { };
105 102
106 virtual WebLayer* contentsLayer() const { return GraphicsLayer::contentsLaye r(); } 103 virtual WebLayer* contentsLayer() const { return GraphicsLayer::contentsLaye r(); }
107 }; 104 };
108 105
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ASSERT_FALSE(graphicsLayer->contentsLayer()); 138 ASSERT_FALSE(graphicsLayer->contentsLayer());
142 139
143 graphicsLayer->setContentsToImage(opaqueImage.get()); 140 graphicsLayer->setContentsToImage(opaqueImage.get());
144 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque()); 141 ASSERT_TRUE(graphicsLayer->contentsLayer()->opaque());
145 142
146 graphicsLayer->setContentsToImage(nonOpaqueImage.get()); 143 graphicsLayer->setContentsToImage(nonOpaqueImage.get());
147 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque()); 144 ASSERT_FALSE(graphicsLayer->contentsLayer()->opaque());
148 } 145 }
149 146
150 } // namespace 147 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698