Chromium Code Reviews| 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/ThreadingPrimitives.h" | 40 #include "wtf/ThreadingPrimitives.h" |
| 41 #include "wtf/ThreadSafeRefCounted.h" | 41 #include "wtf/ThreadSafeRefCounted.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 17 matching lines...) Expand all Loading... | |
| 71 // into |pixels| with a stride of |rowBytes|. | 73 // into |pixels| with a stride of |rowBytes|. |
| 72 // | 74 // |
| 73 // Returns true if decoding was successful. | 75 // Returns true if decoding was successful. |
| 74 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r owBytes); | 76 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r owBytes); |
| 75 | 77 |
| 76 // Decodes YUV components directly into the provided memory planes. | 78 // Decodes YUV components directly into the provided memory planes. |
| 77 bool decodeToYUV(SkISize componentSizes[3], void* planes[3], size_t rowBytes [3]); | 79 bool decodeToYUV(SkISize componentSizes[3], void* planes[3], size_t rowBytes [3]); |
| 78 | 80 |
| 79 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | 81 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); |
| 80 | 82 |
| 81 // Creates a new SharedBuffer containing the data received so far. | 83 // Returns pointer to SkData. Caller needs to unref it, according to contrac t in |
|
Noel Gordon
2015/12/04 03:28:03
How about ...
Return our encoded image data. Call
aleksandar.stojiljkovic
2015/12/04 11:11:43
Done.
| |
| 82 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived); | 84 // SkImageGenerator::refEncodedData. |
| 85 SkData* refEncodedData() const; | |
| 83 | 86 |
| 84 SkISize getFullSize() const { return m_fullSize; } | 87 SkISize getFullSize() const { return m_fullSize; } |
| 85 | 88 |
| 86 bool isMultiFrame() const { return m_isMultiFrame; } | 89 bool isMultiFrame() const { return m_isMultiFrame; } |
| 87 | 90 |
| 88 // FIXME: Return alpha state for each frame. | 91 // FIXME: Return alpha state for each frame. |
| 89 bool hasAlpha(size_t); | 92 bool hasAlpha(size_t); |
| 90 | 93 |
| 91 bool getYUVComponentSizes(SkISize componentSizes[3]); | 94 bool getYUVComponentSizes(SkISize componentSizes[3]); |
| 92 | 95 |
| 93 private: | 96 private: |
| 94 class ExternalMemoryAllocator; | 97 class ExternalMemoryAllocator; |
| 95 friend class ImageFrameGeneratorTest; | 98 friend class ImageFrameGeneratorTest; |
| 96 friend class DeferredImageDecoderTest; | 99 friend class DeferredImageDecoderTest; |
| 97 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. | 100 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. |
| 98 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } | 101 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; } |
| 99 | 102 |
| 100 void setHasAlpha(size_t index, bool hasAlpha); | 103 void setHasAlpha(size_t index, bool hasAlpha); |
| 101 | 104 |
| 102 // These methods are called while m_decodeMutex is locked. | 105 // These methods are called while m_decodeMutex is locked. |
| 103 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); | 106 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); |
| 104 | 107 |
| 105 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. | 108 // Use the given decoder to decode. If a decoder is not given then try to cr eate one. |
| 106 // Returns true if decoding was complete. | 109 // Returns true if decoding was complete. |
| 107 bool decode(size_t index, ImageDecoder**, SkBitmap*); | 110 bool decode(size_t index, ImageDecoder**, SkBitmap*); |
| 108 | 111 |
| 109 SkISize m_fullSize; | 112 SkISize m_fullSize; |
| 110 ThreadSafeDataTransport m_data; | 113 |
| 114 // ThreadSafeDataTransport is referenced by ImageFrameGenerator and SkData | |
| 115 // from refEncodedData. In case ImageFrameGenerator get's deleted, SkData | |
| 116 // would hold the reference to it (and underlying data). | |
| 117 RefPtr<ThreadSafeDataTransport> m_data; | |
| 111 bool m_isMultiFrame; | 118 bool m_isMultiFrame; |
| 112 bool m_decodeFailedAndEmpty; | 119 bool m_decodeFailedAndEmpty; |
| 113 Vector<bool> m_hasAlpha; | 120 Vector<bool> m_hasAlpha; |
| 114 int m_decodeCount; | 121 int m_decodeCount; |
| 115 Vector<bool> m_frameComplete; | 122 Vector<bool> m_frameComplete; |
| 116 size_t m_frameCount; | 123 size_t m_frameCount; |
| 117 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; | 124 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; |
| 118 | 125 |
| 119 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 126 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; |
| 120 | 127 |
| 121 // Prevents multiple decode operations on the same data. | 128 // Prevents multiple decode operations on the same data. |
| 122 Mutex m_decodeMutex; | 129 Mutex m_decodeMutex; |
| 123 | 130 |
| 124 // Protect concurrent access to m_hasAlpha. | 131 // Protect concurrent access to m_hasAlpha. |
| 125 Mutex m_alphaMutex; | 132 Mutex m_alphaMutex; |
| 126 | 133 |
| 127 #if COMPILER(MSVC) | 134 #if COMPILER(MSVC) |
| 128 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; | 135 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; |
| 129 #endif | 136 #endif |
| 130 }; | 137 }; |
| 131 | 138 |
| 132 } // namespace blink | 139 } // namespace blink |
| 133 | 140 |
| 134 #endif | 141 #endif |
| OLD | NEW |