OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef ImageFrameGenerator_h | 26 #ifndef ImageFrameGenerator_h |
27 #define ImageFrameGenerator_h | 27 #define ImageFrameGenerator_h |
28 | 28 |
29 #include "platform/PlatformExport.h" | 29 #include "platform/PlatformExport.h" |
| 30 #include "platform/image-decoders/ImageDecoder.h" |
30 #include "platform/image-decoders/SegmentReader.h" | 31 #include "platform/image-decoders/SegmentReader.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/skia/include/core/SkSize.h" | 33 #include "third_party/skia/include/core/SkSize.h" |
33 #include "third_party/skia/include/core/SkTypes.h" | 34 #include "third_party/skia/include/core/SkTypes.h" |
34 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
35 #include "wtf/Noncopyable.h" | 36 #include "wtf/Noncopyable.h" |
36 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
37 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
39 #include "wtf/ThreadSafeRefCounted.h" | 40 #include "wtf/ThreadSafeRefCounted.h" |
(...skipping 15 matching lines...) Expand all Loading... |
55 ImageDecoderFactory() {} | 56 ImageDecoderFactory() {} |
56 virtual ~ImageDecoderFactory() {} | 57 virtual ~ImageDecoderFactory() {} |
57 virtual std::unique_ptr<ImageDecoder> create() = 0; | 58 virtual std::unique_ptr<ImageDecoder> create() = 0; |
58 }; | 59 }; |
59 | 60 |
60 class PLATFORM_EXPORT ImageFrameGenerator final | 61 class PLATFORM_EXPORT ImageFrameGenerator final |
61 : public ThreadSafeRefCounted<ImageFrameGenerator> { | 62 : public ThreadSafeRefCounted<ImageFrameGenerator> { |
62 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); | 63 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); |
63 | 64 |
64 public: | 65 public: |
65 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, | 66 static PassRefPtr<ImageFrameGenerator> create( |
66 sk_sp<SkColorSpace> colorSpace, | 67 const SkISize& fullSize, |
67 bool isMultiFrame = false) { | 68 bool isMultiFrame, |
| 69 ImageDecoder::ColorSpaceOption decoderColorSpaceOption, |
| 70 sk_sp<SkColorSpace> decoderTargetColorSpace) { |
68 return adoptRef( | 71 return adoptRef( |
69 new ImageFrameGenerator(fullSize, std::move(colorSpace), isMultiFrame)); | 72 new ImageFrameGenerator(fullSize, isMultiFrame, decoderColorSpaceOption, |
| 73 std::move(decoderTargetColorSpace))); |
70 } | 74 } |
71 | 75 |
72 ~ImageFrameGenerator(); | 76 ~ImageFrameGenerator(); |
73 | 77 |
74 // Decodes and scales the specified frame at |index|. The dimensions and | 78 // Decodes and scales the specified frame at |index|. The dimensions and |
75 // output format are given in SkImageInfo. Decoded pixels are written into | 79 // output format are given in SkImageInfo. Decoded pixels are written into |
76 // |pixels| with a stride of |rowBytes|. Returns true if decoding was | 80 // |pixels| with a stride of |rowBytes|. Returns true if decoding was |
77 // successful. | 81 // successful. |
78 bool decodeAndScale(SegmentReader*, | 82 bool decodeAndScale(SegmentReader*, |
79 bool allDataReceived, | 83 bool allDataReceived, |
80 size_t index, | 84 size_t index, |
81 const SkImageInfo&, | 85 const SkImageInfo&, |
82 void* pixels, | 86 void* pixels, |
83 size_t rowBytes); | 87 size_t rowBytes); |
84 | 88 |
85 // Decodes YUV components directly into the provided memory planes. Must not | 89 // Decodes YUV components directly into the provided memory planes. Must not |
86 // be called unless getYUVComponentSizes has been called and returned true. | 90 // be called unless getYUVComponentSizes has been called and returned true. |
87 // YUV decoding does not currently support progressive decoding. In order to | 91 // YUV decoding does not currently support progressive decoding. In order to |
88 // support it, ImageDecoder needs something analagous to its ImageFrame cache | 92 // support it, ImageDecoder needs something analagous to its ImageFrame cache |
89 // to hold partial planes, and the GPU code needs to handle them. | 93 // to hold partial planes, and the GPU code needs to handle them. |
90 bool decodeToYUV(SegmentReader*, | 94 bool decodeToYUV(SegmentReader*, |
91 size_t index, | 95 size_t index, |
92 const SkISize componentSizes[3], | 96 const SkISize componentSizes[3], |
93 void* planes[3], | 97 void* planes[3], |
94 const size_t rowBytes[3]); | 98 const size_t rowBytes[3]); |
95 | 99 |
96 const SkISize& getFullSize() const { return m_fullSize; } | 100 const SkISize& getFullSize() const { return m_fullSize; } |
97 sk_sp<SkColorSpace> getColorSpace() const { return m_colorSpace; } | |
98 | 101 |
99 bool isMultiFrame() const { return m_isMultiFrame; } | 102 bool isMultiFrame() const { return m_isMultiFrame; } |
100 bool decodeFailed() const { return m_decodeFailed; } | 103 bool decodeFailed() const { return m_decodeFailed; } |
101 | 104 |
102 bool hasAlpha(size_t index); | 105 bool hasAlpha(size_t index); |
103 | 106 |
104 // Must not be called unless the SkROBuffer has all the data. YUV decoding | 107 // Must not be called unless the SkROBuffer has all the data. YUV decoding |
105 // does not currently support progressive decoding. See comment above on | 108 // does not currently support progressive decoding. See comment above on |
106 // decodeToYUV(). | 109 // decodeToYUV(). |
107 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); | 110 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); |
108 | 111 |
109 private: | 112 private: |
110 ImageFrameGenerator(const SkISize& fullSize, | 113 ImageFrameGenerator(const SkISize& fullSize, |
111 sk_sp<SkColorSpace>, | 114 bool isMultiFrame, |
112 bool isMultiFrame); | 115 ImageDecoder::ColorSpaceOption decoderColorSpaceOption, |
| 116 sk_sp<SkColorSpace> decoderTargetColorSpace); |
113 | 117 |
114 friend class ImageFrameGeneratorTest; | 118 friend class ImageFrameGeneratorTest; |
115 friend class DeferredImageDecoderTest; | 119 friend class DeferredImageDecoderTest; |
116 // For testing. |factory| will overwrite the default ImageDecoder creation | 120 // For testing. |factory| will overwrite the default ImageDecoder creation |
117 // logic if |factory->create()| returns non-zero. | 121 // logic if |factory->create()| returns non-zero. |
118 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { | 122 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { |
119 m_imageDecoderFactory = std::move(factory); | 123 m_imageDecoderFactory = std::move(factory); |
120 } | 124 } |
121 | 125 |
122 void setHasAlpha(size_t index, bool hasAlpha); | 126 void setHasAlpha(size_t index, bool hasAlpha); |
123 | 127 |
124 SkBitmap tryToResumeDecode(SegmentReader*, | 128 SkBitmap tryToResumeDecode(SegmentReader*, |
125 bool allDataReceived, | 129 bool allDataReceived, |
126 size_t index, | 130 size_t index, |
127 const SkISize& scaledSize, | 131 const SkISize& scaledSize, |
128 SkBitmap::Allocator*); | 132 SkBitmap::Allocator*); |
129 // This method should only be called while m_decodeMutex is locked. | 133 // This method should only be called while m_decodeMutex is locked. |
130 bool decode(SegmentReader*, | 134 bool decode(SegmentReader*, |
131 bool allDataReceived, | 135 bool allDataReceived, |
132 size_t index, | 136 size_t index, |
133 ImageDecoder**, | 137 ImageDecoder**, |
134 SkBitmap*, | 138 SkBitmap*, |
135 SkBitmap::Allocator*); | 139 SkBitmap::Allocator*); |
136 | 140 |
137 const SkISize m_fullSize; | 141 const SkISize m_fullSize; |
138 sk_sp<SkColorSpace> m_colorSpace; | 142 |
| 143 // Parameters used to create internal ImageDecoder objects. |
| 144 const ImageDecoder::ColorSpaceOption m_decoderColorSpaceOption; |
| 145 const sk_sp<SkColorSpace> m_decoderTargetColorSpace; |
139 | 146 |
140 const bool m_isMultiFrame; | 147 const bool m_isMultiFrame; |
141 bool m_decodeFailed; | 148 bool m_decodeFailed; |
142 bool m_yuvDecodingFailed; | 149 bool m_yuvDecodingFailed; |
143 size_t m_frameCount; | 150 size_t m_frameCount; |
144 Vector<bool> m_hasAlpha; | 151 Vector<bool> m_hasAlpha; |
145 | 152 |
146 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; | 153 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; |
147 | 154 |
148 // Prevents multiple decode operations on the same data. | 155 // Prevents multiple decode operations on the same data. |
149 Mutex m_decodeMutex; | 156 Mutex m_decodeMutex; |
150 | 157 |
151 // Protect concurrent access to m_hasAlpha. | 158 // Protect concurrent access to m_hasAlpha. |
152 Mutex m_alphaMutex; | 159 Mutex m_alphaMutex; |
153 }; | 160 }; |
154 | 161 |
155 } // namespace blink | 162 } // namespace blink |
156 | 163 |
157 #endif | 164 #endif |
OLD | NEW |