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

Side by Side Diff: Source/core/platform/graphics/test/MockImageDecoder.h

Issue 99103006: Moving GraphicsContext and dependencies from core to platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final patch - fixes Android Created 7 years 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
(Empty)
1 /*
2 * Copyright (C) 2012 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
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef MockImageDecoder_h
27
28 #include "core/platform/graphics/ImageFrameGenerator.h"
29 #include "core/platform/image-decoders/ImageDecoder.h"
30 #include "wtf/PassOwnPtr.h"
31
32 namespace WebCore {
33
34 class MockImageDecoderClient {
35 public:
36 virtual void decoderBeingDestroyed() = 0;
37 virtual void frameBufferRequested() = 0;
38 virtual ImageFrame::Status status() = 0;
39 virtual size_t frameCount() = 0;
40 virtual int repetitionCount() const = 0;
41 virtual float frameDuration() const = 0;
42
43 // Clients can control the behavior of MockImageDecoder::decodedSize() by
44 // overriding this method. The default implementation causes
45 // MockImageDecoder::decodedSize() to return the same thing as
46 // MockImageDecoder::size(). See the precise implementation of
47 // MockImageDecoder::decodedSize() below.
48 virtual IntSize decodedSize() const { return IntSize(); }
49 };
50
51 class MockImageDecoder : public ImageDecoder {
52 public:
53 static PassOwnPtr<MockImageDecoder> create(MockImageDecoderClient* client) { return adoptPtr(new MockImageDecoder(client)); }
54
55 MockImageDecoder(MockImageDecoderClient* client)
56 : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndCol orProfileApplied, noDecodedImageByteLimit)
57 , m_client(client)
58 { }
59
60 ~MockImageDecoder()
61 {
62 m_client->decoderBeingDestroyed();
63 }
64
65 virtual IntSize decodedSize() const OVERRIDE
66 {
67 return m_client->decodedSize().isEmpty() ? size() : m_client->decodedSiz e();
68 }
69
70 virtual bool setSize(unsigned width, unsigned height) OVERRIDE
71 {
72 ImageDecoder::setSize(width, height);
73 m_frameBufferCache.resize(1);
74 m_frameBufferCache[0].setSize(width, height);
75 return true;
76 }
77
78 virtual String filenameExtension() const OVERRIDE
79 {
80 return "mock";
81 }
82
83 virtual size_t frameCount() OVERRIDE
84 {
85 return m_client->frameCount();
86 }
87
88 virtual int repetitionCount() const OVERRIDE
89 {
90 return m_client->repetitionCount();
91 }
92
93 virtual ImageFrame* frameBufferAtIndex(size_t) OVERRIDE
94 {
95 m_client->frameBufferRequested();
96
97 m_frameBufferCache[0].setStatus(m_client->status());
98 return &m_frameBufferCache[0];
99 }
100
101 virtual bool frameIsCompleteAtIndex(size_t) const OVERRIDE
102 {
103 return m_client->status() == ImageFrame::FrameComplete;
104 }
105
106 virtual float frameDurationAtIndex(size_t) const OVERRIDE
107 {
108 return m_client->frameDuration();
109 }
110
111 void setFrameHasAlpha(bool hasAlpha) { m_frameBufferCache[0].setHasAlpha(has Alpha); }
112
113 private:
114 MockImageDecoderClient* m_client;
115 };
116
117 class MockImageDecoderFactory : public ImageDecoderFactory {
118 public:
119 static PassOwnPtr<MockImageDecoderFactory> create(MockImageDecoderClient* cl ient, const SkISize& decodedSize)
120 {
121 return adoptPtr(new MockImageDecoderFactory(client, IntSize(decodedSize. width(), decodedSize.height())));
122 }
123
124 static PassOwnPtr<MockImageDecoderFactory> create(MockImageDecoderClient* cl ient, const IntSize& decodedSize)
125 {
126 return adoptPtr(new MockImageDecoderFactory(client, decodedSize));
127 }
128
129 virtual PassOwnPtr<ImageDecoder> create() OVERRIDE
130 {
131 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(m_client);
132 decoder->setSize(m_decodedSize.width(), m_decodedSize.height());
133 decoder->setFrameHasAlpha(false);
134 return decoder.release();
135 }
136
137 private:
138 MockImageDecoderFactory(MockImageDecoderClient* client, const IntSize& decod edSize)
139 : m_client(client)
140 , m_decodedSize(decodedSize)
141 {
142 }
143
144 MockImageDecoderClient* m_client;
145 IntSize m_decodedSize;
146 };
147
148 } // namespace WebCore
149
150 #endif // MockImageDecoder_h
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/test/MockDiscardablePixelRef.h ('k') | Source/core/platform/graphics/win/FontCacheWin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698