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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR
efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false) | 63 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR
efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false) |
64 { | 64 { |
65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived,
isMultiFrame)); | 65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived,
isMultiFrame)); |
66 } | 66 } |
67 | 67 |
68 ~ImageFrameGenerator(); | 68 ~ImageFrameGenerator(); |
69 | 69 |
70 // Decodes and scales the specified frame at |index|. The dimensions and out
put | 70 // Decodes and scales the specified frame at |index|. The dimensions and out
put |
71 // format are given in SkImageInfo. Decoded pixels are written into |pixels|
with | 71 // format are given in SkImageInfo. Decoded pixels are written into |pixels|
with |
72 // a stride of |rowBytes|. Returns true if decoding was successful. | 72 // a stride of |rowBytes|. Returns true if decoding was successful. |
73 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r
owBytes); | 73 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r
owBytes, SkPMColor ctable[] = nullptr, int* ctableCount = nullptr); |
74 | 74 |
75 // Decodes YUV components directly into the provided memory planes. | 75 // Decodes YUV components directly into the provided memory planes. |
76 bool decodeToYUV(SkISize componentSizes[3], void* planes[3], size_t rowBytes
[3]); | 76 bool decodeToYUV(SkISize componentSizes[3], void* planes[3], size_t rowBytes
[3]); |
77 | 77 |
78 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | 78 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); |
79 | 79 |
80 // Return our encoded image data. Caller takes ownership and must unref the
data | 80 // Return our encoded image data. Caller takes ownership and must unref the
data |
81 // according to the contract SkImageGenerator::refEncodedData. | 81 // according to the contract SkImageGenerator::refEncodedData. |
82 // | 82 // |
83 // Returns null if image is not fully received. | 83 // Returns null if image is not fully received. |
84 SkData* refEncodedData(); | 84 SkData* refEncodedData(); |
85 | 85 |
86 const SkISize& getFullSize() const { return m_fullSize; } | 86 const SkISize& getFullSize() const { return m_fullSize; } |
87 | 87 |
88 bool isMultiFrame() const { return m_isMultiFrame; } | 88 bool isMultiFrame() const { return m_isMultiFrame; } |
89 | 89 |
90 bool hasAlpha(size_t index); | 90 bool hasAlpha(size_t index); |
91 | 91 |
92 bool getYUVComponentSizes(SkISize componentSizes[3]); | 92 bool getYUVComponentSizes(SkISize componentSizes[3]); |
93 | 93 |
| 94 // Specifies that there is decoder support, to optimize when to call canDeco
deTo(). |
| 95 void setDecoderCanDecodeToIndex8(bool canIt) { m_decoderCanDecodeToIndex8 =
canIt; } |
| 96 bool canDecodeTo(size_t index, SkColorType outputType); |
| 97 |
94 private: | 98 private: |
95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool
allDataReceived, bool isMultiFrame); | 99 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool
allDataReceived, bool isMultiFrame); |
96 | 100 |
97 friend class ImageFrameGeneratorTest; | 101 friend class ImageFrameGeneratorTest; |
98 friend class DeferredImageDecoderTest; | 102 friend class DeferredImageDecoderTest; |
99 // For testing. |factory| will overwrite the default ImageDecoder creation l
ogic if |factory->create()| returns non-zero. | 103 // For testing. |factory| will overwrite the default ImageDecoder creation l
ogic if |factory->create()| returns non-zero. |
100 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima
geDecoderFactory = factory; } | 104 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima
geDecoderFactory = factory; } |
101 | 105 |
102 void setHasAlpha(size_t index, bool hasAlpha); | 106 void setHasAlpha(size_t index, bool hasAlpha); |
103 | 107 |
104 // These methods are called while m_decodeMutex is locked. | 108 // These methods are called while m_decodeMutex is locked. |
105 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); | 109 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index, SkColorT
ype outputColor); |
106 | 110 |
107 // Use the given decoder to decode. If a decoder is not given then try to cr
eate one. | 111 // Use the given decoder to decode. If a decoder is not given then try to cr
eate one. |
108 // Returns true if decoding was complete. | 112 // Returns true if decoding was complete. |
109 bool decode(size_t index, ImageDecoder**, SkBitmap*); | 113 bool decode(size_t index, ImageDecoder**, SkBitmap*, SkColorType); |
110 | 114 |
111 SkISize m_fullSize; | 115 SkISize m_fullSize; |
112 | 116 |
113 // ThreadSafeDataTransport is referenced by this class and m_encodedData. | 117 // ThreadSafeDataTransport is referenced by this class and m_encodedData. |
114 // In case that ImageFrameGenerator get's deleted before m_encodedData, | 118 // In case that ImageFrameGenerator get's deleted before m_encodedData, |
115 // m_encodedData would hold the reference to it (and underlying data). | 119 // m_encodedData would hold the reference to it (and underlying data). |
116 RefPtr<ThreadSafeDataTransport> m_data; | 120 RefPtr<ThreadSafeDataTransport> m_data; |
117 bool m_isMultiFrame; | 121 bool m_isMultiFrame; |
118 bool m_decodeFailedAndEmpty; | 122 bool m_decodeFailedAndEmpty; |
119 Vector<bool> m_hasAlpha; | 123 Vector<bool> m_hasAlpha; |
(...skipping 11 matching lines...) Expand all Loading... |
131 | 135 |
132 // Protect concurrent access to m_hasAlpha. | 136 // Protect concurrent access to m_hasAlpha. |
133 Mutex m_alphaMutex; | 137 Mutex m_alphaMutex; |
134 | 138 |
135 // Our encoded image data returned in refEncodedData. | 139 // Our encoded image data returned in refEncodedData. |
136 SkData* m_encodedData; | 140 SkData* m_encodedData; |
137 | 141 |
138 #if COMPILER(MSVC) | 142 #if COMPILER(MSVC) |
139 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; | 143 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; |
140 #endif | 144 #endif |
| 145 bool m_decoderCanDecodeToIndex8; |
141 }; | 146 }; |
142 | 147 |
143 } // namespace blink | 148 } // namespace blink |
144 | 149 |
145 #endif | 150 #endif |
OLD | NEW |