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 |
| 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/graphics/ThreadSafeDataTransport.h" | 30 #include "platform/image-decoders/SegmentReader.h" |
| 31 #include "skia/ext/refptr.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/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 38 #include "wtf/RefCounted.h" | 39 #include "wtf/RefCounted.h" |
| 39 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 40 #include "wtf/ThreadSafeRefCounted.h" | 41 #include "wtf/ThreadSafeRefCounted.h" |
| 41 #include "wtf/ThreadingPrimitives.h" | 42 #include "wtf/ThreadingPrimitives.h" |
| 42 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
| 43 | 44 |
| 44 class SkData; | 45 class SkData; |
| 45 | 46 |
| 46 namespace blink { | 47 namespace blink { |
| 47 | 48 |
| 48 class ImageDecoder; | 49 class ImageDecoder; |
| 49 class SharedBuffer; | |
| 50 | 50 |
| 51 class PLATFORM_EXPORT ImageDecoderFactory { | 51 class PLATFORM_EXPORT ImageDecoderFactory { |
| 52 USING_FAST_MALLOC(ImageDecoderFactory); | 52 USING_FAST_MALLOC(ImageDecoderFactory); |
| 53 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); | 53 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); |
| 54 public: | 54 public: |
| 55 ImageDecoderFactory() {} | 55 ImageDecoderFactory() {} |
| 56 virtual ~ImageDecoderFactory() { } | 56 virtual ~ImageDecoderFactory() { } |
| 57 virtual PassOwnPtr<ImageDecoder> create() = 0; | 57 virtual PassOwnPtr<ImageDecoder> create() = 0; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> { | 60 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> { |
| 61 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); | 61 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); |
| 62 public: | 62 public: |
| 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, bool isMultiFrame = false) |
| 64 { | 64 { |
| 65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, isMultiFrame)); | 65 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 ~ImageFrameGenerator(); | 68 ~ImageFrameGenerator(); |
| 69 | 69 |
| 70 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived); | |
| 71 | |
| 72 // Return our encoded image data. Caller takes ownership and must unref the data | |
| 73 // according to the contract SkImageGenerator::refEncodedData. Returns null if | |
| 74 // the data is has not been fully received. | |
| 75 SkData* refEncodedData(); | |
| 76 | |
| 77 // 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 |
| 78 // 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 |
| 79 // a stride of |rowBytes|. Returns true if decoding was successful. | 72 // a stride of |rowBytes|. Returns true if decoding was successful. |
| 80 bool decodeAndScale(size_t index, const SkImageInfo&, void* pixels, size_t r owBytes); | 73 bool decodeAndScale(SegmentReader*, bool allDataReceived, size_t index, cons t SkImageInfo&, void* pixels, size_t rowBytes); |
| 81 | 74 |
| 82 // Decodes YUV components directly into the provided memory planes. | 75 // Decodes YUV components directly into the provided memory planes. |
| 83 bool decodeToYUV(size_t index, SkISize componentSizes[3], void* planes[3], s ize_t rowBytes[3]); | 76 // Must not be called unless getYUVCompenentSizes has been called and return ed true. |
|
Peter Kasting
2016/03/23 02:42:58
Nit: Component
scroggo_chromium
2016/03/24 13:59:45
Done.
| |
| 77 bool decodeToYUV(SegmentReader*, size_t index, SkISize componentSizes[3], vo id* planes[3], size_t rowBytes[3]); | |
| 84 | 78 |
| 85 const SkISize& getFullSize() const { return m_fullSize; } | 79 const SkISize& getFullSize() const { return m_fullSize; } |
| 86 | 80 |
| 87 bool isMultiFrame() const { return m_isMultiFrame; } | 81 bool isMultiFrame() const { return m_isMultiFrame; } |
| 88 bool decodeFailed() const { return m_decodeFailed; } | 82 bool decodeFailed() const { return m_decodeFailed; } |
| 89 | 83 |
| 90 bool hasAlpha(size_t index); | 84 bool hasAlpha(size_t index); |
| 91 | 85 |
| 92 bool getYUVComponentSizes(SkISize componentSizes[3]); | 86 // Must not be called unless the SkROBuffer has all the data. |
| 87 // FIXME: YUV decoding does not currently support progressive decoding. | |
| 88 bool getYUVComponentSizes(SegmentReader*, SkISize componentSizes[3]); | |
| 93 | 89 |
| 94 private: | 90 private: |
| 95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame); | 91 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame); |
| 96 | 92 |
| 97 friend class ImageFrameGeneratorTest; | 93 friend class ImageFrameGeneratorTest; |
| 98 friend class DeferredImageDecoderTest; | 94 friend class DeferredImageDecoderTest; |
| 99 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. | 95 // 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 = std::move(factory); } | 96 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = std::move(factory); } |
| 101 | 97 |
| 102 void setHasAlpha(size_t index, bool hasAlpha); | 98 void setHasAlpha(size_t index, bool hasAlpha); |
| 103 | 99 |
| 104 // These methods are called while m_decodeMutex is locked. | 100 // FIXME: Change the parameter to take an SkBitmap::Allocator, and no need f or declaring this class. |
|
Peter Kasting
2016/03/23 02:42:58
Are you planning to do that in this CL?
scroggo_chromium
2016/03/24 13:59:45
Done.
| |
| 105 SkBitmap tryToResumeDecode(size_t index, const SkISize& scaledSize); | 101 class ExternalMemoryAllocator; |
| 106 bool decode(size_t index, ImageDecoder**, SkBitmap*); | 102 SkBitmap tryToResumeDecode(SegmentReader*, bool allDataReceived, size_t inde x, const SkISize& scaledSize, ExternalMemoryAllocator*); |
| 103 // This method is called while m_decodeMutex is locked. | |
|
Peter Kasting
2016/03/23 02:42:58
Nit: Unclear what this means: can be called while,
scroggo_chromium
2016/03/24 13:59:45
Should. Done.
| |
| 104 bool decode(SegmentReader*, bool allDataReceived, size_t index, ImageDecoder **, SkBitmap*, ExternalMemoryAllocator*); | |
| 107 | 105 |
| 108 SkISize m_fullSize; | 106 const SkISize m_fullSize; |
| 109 | 107 |
| 110 // ThreadSafeDataTransport is referenced by this class and m_encodedData. | 108 const bool m_isMultiFrame; |
| 111 // In case that ImageFrameGenerator get's deleted before m_encodedData, | |
| 112 // m_encodedData would hold the reference to it (and underlying data). | |
| 113 RefPtr<ThreadSafeDataTransport> m_data; | |
| 114 | |
| 115 bool m_isMultiFrame; | |
| 116 bool m_decodeFailed; | 109 bool m_decodeFailed; |
| 117 size_t m_frameCount; | 110 size_t m_frameCount; |
| 118 Vector<bool> m_hasAlpha; | 111 Vector<bool> m_hasAlpha; |
| 119 Vector<bool> m_frameComplete; | 112 Vector<bool> m_frameComplete; |
| 120 | 113 |
| 121 class ExternalMemoryAllocator; | |
| 122 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; | |
| 123 | |
| 124 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 114 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; |
| 125 | 115 |
| 126 // Prevents multiple decode operations on the same data. | 116 // Prevents multiple decode operations on the same data. |
| 127 Mutex m_decodeMutex; | 117 Mutex m_decodeMutex; |
| 128 | 118 |
| 129 // Protect concurrent access to m_hasAlpha. | 119 // Protect concurrent access to m_hasAlpha. |
| 130 Mutex m_alphaMutex; | 120 Mutex m_alphaMutex; |
| 131 | |
| 132 // Our encoded image data returned in refEncodedData. | |
| 133 SkData* m_encodedData; | |
| 134 | |
| 135 #if COMPILER(MSVC) | |
| 136 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; | |
| 137 #endif | |
| 138 }; | 121 }; |
| 139 | 122 |
| 140 } // namespace blink | 123 } // namespace blink |
| 141 | 124 |
| 142 #endif | 125 #endif |
| OLD | NEW |