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 23 matching lines...) Expand all Loading... | |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/Noncopyable.h" | 35 #include "wtf/Noncopyable.h" |
36 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
37 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
38 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
39 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
40 #include "wtf/ThreadSafeRefCounted.h" | 40 #include "wtf/ThreadSafeRefCounted.h" |
41 #include "wtf/ThreadingPrimitives.h" | 41 #include "wtf/ThreadingPrimitives.h" |
42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
43 | 43 |
44 class SkData; | |
45 | |
44 namespace blink { | 46 namespace blink { |
45 | 47 |
46 class ImageDecoder; | 48 class ImageDecoder; |
47 class SharedBuffer; | 49 class SharedBuffer; |
48 | 50 |
49 class PLATFORM_EXPORT ImageDecoderFactory { | 51 class PLATFORM_EXPORT ImageDecoderFactory { |
50 USING_FAST_MALLOC(ImageDecoderFactory); | 52 USING_FAST_MALLOC(ImageDecoderFactory); |
51 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); | 53 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); |
52 public: | 54 public: |
53 ImageDecoderFactory() {} | 55 ImageDecoderFactory() {} |
(...skipping 14 matching lines...) Expand all Loading... | |
68 // 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 |
69 // 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 |
70 // a stride of |rowBytes|. Returns true if decoding was successful. | 72 // a stride of |rowBytes|. Returns true if decoding was successful. |
71 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); |
72 | 74 |
73 // Decodes YUV components directly into the provided memory planes. | 75 // Decodes YUV components directly into the provided memory planes. |
74 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]); |
75 | 77 |
76 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | 78 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); |
77 | 79 |
78 // Creates a new SharedBuffer containing the data received so far. | 80 // Return our encoded image data. Caller takes ownership and must unref the data |
79 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); | 81 // according to the contract SkImageGenerator::refEncodedData. |
82 // | |
83 // Returns null if image is not complete. | |
Noel Gordon
2015/12/08 15:41:59
"Returns null if image is not complete", not quite
aleksandar.stojiljkovic
2015/12/08 20:28:13
Done. "Fully received" used on other place.
| |
84 SkData* refEncodedData(); | |
80 | 85 |
81 const SkISize& getFullSize() const { return m_fullSize; } | 86 const SkISize& getFullSize() const { return m_fullSize; } |
82 | 87 |
83 bool isMultiFrame() const { return m_isMultiFrame; } | 88 bool isMultiFrame() const { return m_isMultiFrame; } |
84 | 89 |
85 bool hasAlpha(size_t index); | 90 bool hasAlpha(size_t index); |
86 | 91 |
87 bool getYUVComponentSizes(SkISize componentSizes[3]); | 92 bool getYUVComponentSizes(SkISize componentSizes[3]); |
88 | 93 |
89 private: | 94 private: |
90 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame); | 95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame); |
91 | 96 |
92 friend class ImageFrameGeneratorTest; | 97 friend class ImageFrameGeneratorTest; |
93 friend class DeferredImageDecoderTest; | 98 friend class DeferredImageDecoderTest; |
94 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. | 99 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. |
95 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } | 100 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } |
96 | 101 |
97 void setHasAlpha(size_t index, bool hasAlpha); | 102 void setHasAlpha(size_t index, bool hasAlpha); |
98 | 103 |
99 // These methods are called while m_decodeMutex is locked. | 104 // These methods are called while m_decodeMutex is locked. |
100 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); | 105 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); |
101 | 106 |
102 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. | 107 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. |
103 // Returns true if decoding was complete. | 108 // Returns true if decoding was complete. |
104 bool decode(size_t index, ImageDecoder**, SkBitmap*); | 109 bool decode(size_t index, ImageDecoder**, SkBitmap*); |
105 | 110 |
106 SkISize m_fullSize; | 111 SkISize m_fullSize; |
107 ThreadSafeDataTransport m_data; | 112 |
113 // ThreadSafeDataTransport is referenced by this class and m_encodedData. | |
114 // In case that ImageFrameGenerator get's deleted before m_encodedData, | |
115 // m_encodedData would hold the reference to it (and underlying data). | |
116 RefPtr<ThreadSafeDataTransport> m_data; | |
108 bool m_isMultiFrame; | 117 bool m_isMultiFrame; |
109 bool m_decodeFailedAndEmpty; | 118 bool m_decodeFailedAndEmpty; |
110 Vector<bool> m_hasAlpha; | 119 Vector<bool> m_hasAlpha; |
111 int m_decodeCount; | 120 int m_decodeCount; |
112 Vector<bool> m_frameComplete; | 121 Vector<bool> m_frameComplete; |
113 size_t m_frameCount; | 122 size_t m_frameCount; |
114 | 123 |
115 class ExternalMemoryAllocator; | 124 class ExternalMemoryAllocator; |
116 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; | 125 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; |
117 | 126 |
118 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 127 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; |
119 | 128 |
120 // Prevents multiple decode operations on the same data. | 129 // Prevents multiple decode operations on the same data. |
121 Mutex m_decodeMutex; | 130 Mutex m_decodeMutex; |
122 | 131 |
123 // Protect concurrent access to m_hasAlpha. | 132 // Protect concurrent access to m_hasAlpha. |
124 Mutex m_alphaMutex; | 133 Mutex m_alphaMutex; |
125 | 134 |
135 // Our encoded image data returned in refEncodedData. | |
136 SkData* m_encodedData; | |
137 | |
126 #if COMPILER(MSVC) | 138 #if COMPILER(MSVC) |
127 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; | 139 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; |
128 #endif | 140 #endif |
129 }; | 141 }; |
130 | 142 |
131 } // namespace blink | 143 } // namespace blink |
132 | 144 |
133 #endif | 145 #endif |
OLD | NEW |