| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class PLATFORM_EXPORT ImageFrameGenerator final | 61 class PLATFORM_EXPORT ImageFrameGenerator final |
| 62 : public ThreadSafeRefCounted<ImageFrameGenerator> { | 62 : public ThreadSafeRefCounted<ImageFrameGenerator> { |
| 63 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); | 63 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); |
| 64 | 64 |
| 65 public: | 65 public: |
| 66 static PassRefPtr<ImageFrameGenerator> create( | 66 static PassRefPtr<ImageFrameGenerator> create( |
| 67 const SkISize& fullSize, | 67 const SkISize& fullSize, |
| 68 bool isMultiFrame, | 68 bool isMultiFrame, |
| 69 ImageDecoder::ColorSpaceOption decoderColorSpaceOption, | 69 const ColorBehavior& colorBehavior) { |
| 70 sk_sp<SkColorSpace> decoderTargetColorSpace) { | |
| 71 return adoptRef( | 70 return adoptRef( |
| 72 new ImageFrameGenerator(fullSize, isMultiFrame, decoderColorSpaceOption, | 71 new ImageFrameGenerator(fullSize, isMultiFrame, colorBehavior)); |
| 73 std::move(decoderTargetColorSpace))); | |
| 74 } | 72 } |
| 75 | 73 |
| 76 ~ImageFrameGenerator(); | 74 ~ImageFrameGenerator(); |
| 77 | 75 |
| 78 // Decodes and scales the specified frame at |index|. The dimensions and | 76 // Decodes and scales the specified frame at |index|. The dimensions and |
| 79 // output format are given in SkImageInfo. Decoded pixels are written into | 77 // output format are given in SkImageInfo. Decoded pixels are written into |
| 80 // |pixels| with a stride of |rowBytes|. Returns true if decoding was | 78 // |pixels| with a stride of |rowBytes|. Returns true if decoding was |
| 81 // successful. | 79 // successful. |
| 82 bool decodeAndScale(SegmentReader*, | 80 bool decodeAndScale(SegmentReader*, |
| 83 bool allDataReceived, | 81 bool allDataReceived, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 bool hasAlpha(size_t index); | 103 bool hasAlpha(size_t index); |
| 106 | 104 |
| 107 // Must not be called unless the SkROBuffer has all the data. YUV decoding | 105 // Must not be called unless the SkROBuffer has all the data. YUV decoding |
| 108 // does not currently support progressive decoding. See comment above on | 106 // does not currently support progressive decoding. See comment above on |
| 109 // decodeToYUV(). | 107 // decodeToYUV(). |
| 110 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); | 108 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); |
| 111 | 109 |
| 112 private: | 110 private: |
| 113 ImageFrameGenerator(const SkISize& fullSize, | 111 ImageFrameGenerator(const SkISize& fullSize, |
| 114 bool isMultiFrame, | 112 bool isMultiFrame, |
| 115 ImageDecoder::ColorSpaceOption decoderColorSpaceOption, | 113 const ColorBehavior&); |
| 116 sk_sp<SkColorSpace> decoderTargetColorSpace); | |
| 117 | 114 |
| 118 friend class ImageFrameGeneratorTest; | 115 friend class ImageFrameGeneratorTest; |
| 119 friend class DeferredImageDecoderTest; | 116 friend class DeferredImageDecoderTest; |
| 120 // For testing. |factory| will overwrite the default ImageDecoder creation | 117 // For testing. |factory| will overwrite the default ImageDecoder creation |
| 121 // logic if |factory->create()| returns non-zero. | 118 // logic if |factory->create()| returns non-zero. |
| 122 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { | 119 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { |
| 123 m_imageDecoderFactory = std::move(factory); | 120 m_imageDecoderFactory = std::move(factory); |
| 124 } | 121 } |
| 125 | 122 |
| 126 void setHasAlpha(size_t index, bool hasAlpha); | 123 void setHasAlpha(size_t index, bool hasAlpha); |
| 127 | 124 |
| 128 SkBitmap tryToResumeDecode(SegmentReader*, | 125 SkBitmap tryToResumeDecode(SegmentReader*, |
| 129 bool allDataReceived, | 126 bool allDataReceived, |
| 130 size_t index, | 127 size_t index, |
| 131 const SkISize& scaledSize, | 128 const SkISize& scaledSize, |
| 132 SkBitmap::Allocator*); | 129 SkBitmap::Allocator*); |
| 133 // This method should only be called while m_decodeMutex is locked. | 130 // This method should only be called while m_decodeMutex is locked. |
| 134 bool decode(SegmentReader*, | 131 bool decode(SegmentReader*, |
| 135 bool allDataReceived, | 132 bool allDataReceived, |
| 136 size_t index, | 133 size_t index, |
| 137 ImageDecoder**, | 134 ImageDecoder**, |
| 138 SkBitmap*, | 135 SkBitmap*, |
| 139 SkBitmap::Allocator*); | 136 SkBitmap::Allocator*); |
| 140 | 137 |
| 141 const SkISize m_fullSize; | 138 const SkISize m_fullSize; |
| 142 | 139 |
| 143 // Parameters used to create internal ImageDecoder objects. | 140 // Parameters used to create internal ImageDecoder objects. |
| 144 const ImageDecoder::ColorSpaceOption m_decoderColorSpaceOption; | 141 const ColorBehavior m_decoderColorBehavior; |
| 145 const sk_sp<SkColorSpace> m_decoderTargetColorSpace; | |
| 146 | 142 |
| 147 const bool m_isMultiFrame; | 143 const bool m_isMultiFrame; |
| 148 bool m_decodeFailed; | 144 bool m_decodeFailed; |
| 149 bool m_yuvDecodingFailed; | 145 bool m_yuvDecodingFailed; |
| 150 size_t m_frameCount; | 146 size_t m_frameCount; |
| 151 Vector<bool> m_hasAlpha; | 147 Vector<bool> m_hasAlpha; |
| 152 | 148 |
| 153 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; | 149 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; |
| 154 | 150 |
| 155 // Prevents multiple decode operations on the same data. | 151 // Prevents multiple decode operations on the same data. |
| 156 Mutex m_decodeMutex; | 152 Mutex m_decodeMutex; |
| 157 | 153 |
| 158 // Protect concurrent access to m_hasAlpha. | 154 // Protect concurrent access to m_hasAlpha. |
| 159 Mutex m_alphaMutex; | 155 Mutex m_alphaMutex; |
| 160 }; | 156 }; |
| 161 | 157 |
| 162 } // namespace blink | 158 } // namespace blink |
| 163 | 159 |
| 164 #endif | 160 #endif |
| OLD | NEW |