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/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
35 #include "wtf/PassRefPtr.h" | 35 #include "wtf/PassRefPtr.h" |
36 #include "wtf/RefCounted.h" | 36 #include "wtf/RefCounted.h" |
37 #include "wtf/RefPtr.h" | 37 #include "wtf/RefPtr.h" |
38 #include "wtf/ThreadingPrimitives.h" | 38 #include "wtf/ThreadingPrimitives.h" |
39 #include "wtf/ThreadSafeRefCounted.h" | 39 #include "wtf/ThreadSafeRefCounted.h" |
40 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class DecodingBuffers; | |
44 class ImageDecoder; | 45 class ImageDecoder; |
45 class ScaledImageFragment; | 46 class ScaledImageFragment; |
46 class SharedBuffer; | 47 class SharedBuffer; |
47 | 48 |
48 class PLATFORM_EXPORT ImageDecoderFactory { | 49 class PLATFORM_EXPORT ImageDecoderFactory { |
49 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); | 50 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); |
50 public: | 51 public: |
51 ImageDecoderFactory() {} | 52 ImageDecoderFactory() {} |
52 virtual ~ImageDecoderFactory() { } | 53 virtual ~ImageDecoderFactory() { } |
53 virtual PassOwnPtr<ImageDecoder> create() = 0; | 54 virtual PassOwnPtr<ImageDecoder> create() = 0; |
(...skipping 12 matching lines...) Expand all Loading... | |
66 | 67 |
67 const ScaledImageFragment* decodeAndScale(const SkISize& scaledSize, size_t index = 0); | 68 const ScaledImageFragment* decodeAndScale(const SkISize& scaledSize, size_t index = 0); |
68 | 69 |
69 // Decodes and scales the specified frame indicated by |index|. Dimensions | 70 // Decodes and scales the specified frame indicated by |index|. Dimensions |
70 // and output format are specified in |info|. Decoded pixels are written | 71 // and output format are specified in |info|. Decoded pixels are written |
71 // into |pixels| with a stride of |rowBytes|. | 72 // into |pixels| with a stride of |rowBytes|. |
72 // | 73 // |
73 // Returns true if decoding was successful. | 74 // Returns true if decoding was successful. |
74 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r owBytes); | 75 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r owBytes); |
75 | 76 |
77 // Decodes components directly into the provided memory planes | |
Peter Kasting
2014/07/23 22:17:37
Nit: Trailing period
sugoi1
2014/07/24 15:48:29
Done.
| |
78 bool decodeAndScale(void* planes[3], size_t rowBytes[3]); | |
79 | |
76 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | 80 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); |
77 | 81 |
78 // Creates a new SharedBuffer containing the data received so far. | 82 // Creates a new SharedBuffer containing the data received so far. |
79 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); | 83 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); |
80 | 84 |
81 SkISize getFullSize() const { return m_fullSize; } | 85 SkISize getFullSize() const { return m_fullSize; } |
82 | 86 |
83 bool isMultiFrame() const { return m_isMultiFrame; } | 87 bool isMultiFrame() const { return m_isMultiFrame; } |
84 | 88 |
85 // FIXME: Return alpha state for each frame. | 89 // FIXME: Return alpha state for each frame. |
86 bool hasAlpha(size_t); | 90 bool hasAlpha(size_t); |
87 | 91 |
92 // Returns sizes for the first 3 components of an image (could be RGB, YUV, etc) | |
93 bool getComponentSizes(SkISize* componentSizes); | |
Peter Kasting
2014/07/23 22:17:37
Above you pass arrays with sizes, but here you pas
sugoi1
2014/07/24 15:48:29
Done. Used arrays in both cases.
| |
94 | |
88 private: | 95 private: |
89 class ExternalMemoryAllocator; | 96 class ExternalMemoryAllocator; |
90 friend class ImageFrameGeneratorTest; | 97 friend class ImageFrameGeneratorTest; |
91 friend class DeferredImageDecoderTest; | 98 friend class DeferredImageDecoderTest; |
92 // 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. |
93 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } | 100 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } |
94 // For testing. | 101 // For testing. |
95 SkBitmap::Allocator* allocator() const { return m_discardableAllocator.get() ; } | 102 SkBitmap::Allocator* allocator() const { return m_discardableAllocator.get() ; } |
96 void setAllocator(PassOwnPtr<SkBitmap::Allocator> allocator) { m_discardable Allocator = allocator; } | 103 void setAllocator(PassOwnPtr<SkBitmap::Allocator> allocator) { m_discardable Allocator = allocator; } |
97 | 104 |
98 // These methods are called while m_decodeMutex is locked. | 105 // These methods are called while m_decodeMutex is locked. |
99 const ScaledImageFragment* tryToLockCompleteCache(const SkISize& scaledSize, size_t index); | 106 const ScaledImageFragment* tryToLockCompleteCache(const SkISize& scaledSize, size_t index); |
100 const ScaledImageFragment* tryToResumeDecode(const SkISize& scaledSize, size _t index); | 107 const ScaledImageFragment* tryToResumeDecode(const SkISize& scaledSize, size _t index); |
101 | 108 |
102 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. | 109 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. |
103 PassOwnPtr<ScaledImageFragment> decode(size_t index, ImageDecoder**); | 110 PassOwnPtr<ScaledImageFragment> decode(size_t index, ImageDecoder**); |
104 | 111 |
105 // Return the next generation ID of a new image object. This is used | 112 // Return the next generation ID of a new image object. This is used |
106 // to identify images of the same frame from different stages of | 113 // to identify images of the same frame from different stages of |
107 // progressive decode. | 114 // progressive decode. |
108 size_t nextGenerationId() { return m_decodeCount++; } | 115 size_t nextGenerationId() { return m_decodeCount++; } |
109 | 116 |
110 SkISize m_fullSize; | 117 SkISize m_fullSize; |
111 ThreadSafeDataTransport m_data; | 118 ThreadSafeDataTransport m_data; |
112 bool m_isMultiFrame; | 119 bool m_isMultiFrame; |
113 bool m_decodeFailedAndEmpty; | 120 bool m_decodeFailedAndEmpty; |
121 bool m_hardwareDecoding; | |
122 OwnPtr<DecodingBuffers> m_decodingBuffers; | |
114 Vector<bool> m_hasAlpha; | 123 Vector<bool> m_hasAlpha; |
115 size_t m_decodeCount; | 124 size_t m_decodeCount; |
116 OwnPtr<SkBitmap::Allocator> m_discardableAllocator; | 125 OwnPtr<SkBitmap::Allocator> m_discardableAllocator; |
117 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; | 126 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; |
118 | 127 |
119 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 128 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; |
120 | 129 |
121 // Prevents multiple decode operations on the same data. | 130 // Prevents multiple decode operations on the same data. |
122 Mutex m_decodeMutex; | 131 Mutex m_decodeMutex; |
123 | 132 |
124 // Protect concurrent access to m_hasAlpha. | 133 // Protect concurrent access to m_hasAlpha. |
125 Mutex m_alphaMutex; | 134 Mutex m_alphaMutex; |
126 }; | 135 }; |
127 | 136 |
128 } // namespace blink | 137 } // namespace blink |
129 | 138 |
130 #endif | 139 #endif |
OLD | NEW |