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 15 matching lines...) Expand all Loading... |
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/image-decoders/SegmentReader.h" | 30 #include "platform/image-decoders/SegmentReader.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/skia/include/core/SkSize.h" | 32 #include "third_party/skia/include/core/SkSize.h" |
33 #include "third_party/skia/include/core/SkTypes.h" | 33 #include "third_party/skia/include/core/SkTypes.h" |
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" | |
37 #include "wtf/PassRefPtr.h" | 36 #include "wtf/PassRefPtr.h" |
38 #include "wtf/RefCounted.h" | 37 #include "wtf/RefCounted.h" |
39 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
40 #include "wtf/ThreadSafeRefCounted.h" | 39 #include "wtf/ThreadSafeRefCounted.h" |
41 #include "wtf/ThreadingPrimitives.h" | 40 #include "wtf/ThreadingPrimitives.h" |
42 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
| 42 #include <memory> |
43 | 43 |
44 class SkData; | 44 class SkData; |
45 struct SkYUVSizeInfo; | 45 struct SkYUVSizeInfo; |
46 | 46 |
47 namespace blink { | 47 namespace blink { |
48 | 48 |
49 class ImageDecoder; | 49 class ImageDecoder; |
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 std::unique_ptr<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, bool
isMultiFrame = false) | 63 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, bool
isMultiFrame = false) |
64 { | 64 { |
65 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame)); | 65 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame)); |
66 } | 66 } |
67 | 67 |
(...skipping 20 matching lines...) Expand all Loading... |
88 // Must not be called unless the SkROBuffer has all the data. | 88 // Must not be called unless the SkROBuffer has all the data. |
89 // YUV decoding does not currently support progressive decoding. See comment
above on decodeToYUV. | 89 // YUV decoding does not currently support progressive decoding. See comment
above on decodeToYUV. |
90 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); | 90 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); |
91 | 91 |
92 private: | 92 private: |
93 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame); | 93 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame); |
94 | 94 |
95 friend class ImageFrameGeneratorTest; | 95 friend class ImageFrameGeneratorTest; |
96 friend class DeferredImageDecoderTest; | 96 friend class DeferredImageDecoderTest; |
97 // For testing. |factory| will overwrite the default ImageDecoder creation l
ogic if |factory->create()| returns non-zero. | 97 // 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 = std::move(factory); } | 98 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) {
m_imageDecoderFactory = std::move(factory); } |
99 | 99 |
100 void setHasAlpha(size_t index, bool hasAlpha); | 100 void setHasAlpha(size_t index, bool hasAlpha); |
101 | 101 |
102 SkBitmap tryToResumeDecode(SegmentReader*, bool allDataReceived, size_t inde
x, const SkISize& scaledSize, SkBitmap::Allocator*); | 102 SkBitmap tryToResumeDecode(SegmentReader*, bool allDataReceived, size_t inde
x, const SkISize& scaledSize, SkBitmap::Allocator*); |
103 // This method should only be called while m_decodeMutex is locked. | 103 // This method should only be called while m_decodeMutex is locked. |
104 bool decode(SegmentReader*, bool allDataReceived, size_t index, ImageDecoder
**, SkBitmap*, SkBitmap::Allocator*); | 104 bool decode(SegmentReader*, bool allDataReceived, size_t index, ImageDecoder
**, SkBitmap*, SkBitmap::Allocator*); |
105 | 105 |
106 const SkISize m_fullSize; | 106 const SkISize m_fullSize; |
107 | 107 |
108 const bool m_isMultiFrame; | 108 const bool m_isMultiFrame; |
109 bool m_decodeFailed; | 109 bool m_decodeFailed; |
110 bool m_yuvDecodingFailed; | 110 bool m_yuvDecodingFailed; |
111 size_t m_frameCount; | 111 size_t m_frameCount; |
112 Vector<bool> m_hasAlpha; | 112 Vector<bool> m_hasAlpha; |
113 | 113 |
114 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; | 114 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; |
115 | 115 |
116 // Prevents multiple decode operations on the same data. | 116 // Prevents multiple decode operations on the same data. |
117 Mutex m_decodeMutex; | 117 Mutex m_decodeMutex; |
118 | 118 |
119 // Protect concurrent access to m_hasAlpha. | 119 // Protect concurrent access to m_hasAlpha. |
120 Mutex m_alphaMutex; | 120 Mutex m_alphaMutex; |
121 }; | 121 }; |
122 | 122 |
123 } // namespace blink | 123 } // namespace blink |
124 | 124 |
125 #endif | 125 #endif |
OLD | NEW |