Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.h

Issue 2462803002: Plumb color space to DecodingImageGenerator and ImageFrameGenerator (Closed)
Patch Set: Incorporate review feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual ~ImageDecoderFactory() {} 57 virtual ~ImageDecoderFactory() {}
58 virtual std::unique_ptr<ImageDecoder> create() = 0; 58 virtual std::unique_ptr<ImageDecoder> create() = 0;
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(const SkISize& fullSize, 66 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize,
67 sk_sp<SkColorSpace> colorSpace,
67 bool isMultiFrame = false) { 68 bool isMultiFrame = false) {
68 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame)); 69 return adoptRef(
70 new ImageFrameGenerator(fullSize, std::move(colorSpace), isMultiFrame));
69 } 71 }
70 72
71 ~ImageFrameGenerator(); 73 ~ImageFrameGenerator();
72 74
73 // Decodes and scales the specified frame at |index|. The dimensions and 75 // Decodes and scales the specified frame at |index|. The dimensions and
74 // output format are given in SkImageInfo. Decoded pixels are written into 76 // output format are given in SkImageInfo. Decoded pixels are written into
75 // |pixels| with a stride of |rowBytes|. Returns true if decoding was 77 // |pixels| with a stride of |rowBytes|. Returns true if decoding was
76 // successful. 78 // successful.
77 bool decodeAndScale(SegmentReader*, 79 bool decodeAndScale(SegmentReader*,
78 bool allDataReceived, 80 bool allDataReceived,
79 size_t index, 81 size_t index,
80 const SkImageInfo&, 82 const SkImageInfo&,
81 void* pixels, 83 void* pixels,
82 size_t rowBytes); 84 size_t rowBytes);
83 85
84 // Decodes YUV components directly into the provided memory planes. Must not 86 // Decodes YUV components directly into the provided memory planes. Must not
85 // be called unless getYUVComponentSizes has been called and returned true. 87 // be called unless getYUVComponentSizes has been called and returned true.
86 // YUV decoding does not currently support progressive decoding. In order to 88 // YUV decoding does not currently support progressive decoding. In order to
87 // support it, ImageDecoder needs something analagous to its ImageFrame cache 89 // support it, ImageDecoder needs something analagous to its ImageFrame cache
88 // to hold partial planes, and the GPU code needs to handle them. 90 // to hold partial planes, and the GPU code needs to handle them.
89 bool decodeToYUV(SegmentReader*, 91 bool decodeToYUV(SegmentReader*,
90 size_t index, 92 size_t index,
91 const SkISize componentSizes[3], 93 const SkISize componentSizes[3],
92 void* planes[3], 94 void* planes[3],
93 const size_t rowBytes[3]); 95 const size_t rowBytes[3]);
94 96
95 const SkISize& getFullSize() const { return m_fullSize; } 97 const SkISize& getFullSize() const { return m_fullSize; }
98 sk_sp<SkColorSpace> getColorSpace() const { return m_colorSpace; }
96 99
97 bool isMultiFrame() const { return m_isMultiFrame; } 100 bool isMultiFrame() const { return m_isMultiFrame; }
98 bool decodeFailed() const { return m_decodeFailed; } 101 bool decodeFailed() const { return m_decodeFailed; }
99 102
100 bool hasAlpha(size_t index); 103 bool hasAlpha(size_t index);
101 104
102 // 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
103 // does not currently support progressive decoding. See comment above on 106 // does not currently support progressive decoding. See comment above on
104 // decodeToYUV(). 107 // decodeToYUV().
105 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); 108 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*);
106 109
107 private: 110 private:
108 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame); 111 ImageFrameGenerator(const SkISize& fullSize,
112 sk_sp<SkColorSpace>,
113 bool isMultiFrame);
109 114
110 friend class ImageFrameGeneratorTest; 115 friend class ImageFrameGeneratorTest;
111 friend class DeferredImageDecoderTest; 116 friend class DeferredImageDecoderTest;
112 // For testing. |factory| will overwrite the default ImageDecoder creation 117 // For testing. |factory| will overwrite the default ImageDecoder creation
113 // logic if |factory->create()| returns non-zero. 118 // logic if |factory->create()| returns non-zero.
114 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { 119 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) {
115 m_imageDecoderFactory = std::move(factory); 120 m_imageDecoderFactory = std::move(factory);
116 } 121 }
117 122
118 void setHasAlpha(size_t index, bool hasAlpha); 123 void setHasAlpha(size_t index, bool hasAlpha);
119 124
120 SkBitmap tryToResumeDecode(SegmentReader*, 125 SkBitmap tryToResumeDecode(SegmentReader*,
121 bool allDataReceived, 126 bool allDataReceived,
122 size_t index, 127 size_t index,
123 const SkISize& scaledSize, 128 const SkISize& scaledSize,
124 SkBitmap::Allocator*); 129 SkBitmap::Allocator*);
125 // This method should only be called while m_decodeMutex is locked. 130 // This method should only be called while m_decodeMutex is locked.
126 bool decode(SegmentReader*, 131 bool decode(SegmentReader*,
127 bool allDataReceived, 132 bool allDataReceived,
128 size_t index, 133 size_t index,
129 ImageDecoder**, 134 ImageDecoder**,
130 SkBitmap*, 135 SkBitmap*,
131 SkBitmap::Allocator*); 136 SkBitmap::Allocator*);
132 137
133 const SkISize m_fullSize; 138 const SkISize m_fullSize;
139 sk_sp<SkColorSpace> m_colorSpace;
134 140
135 const bool m_isMultiFrame; 141 const bool m_isMultiFrame;
136 bool m_decodeFailed; 142 bool m_decodeFailed;
137 bool m_yuvDecodingFailed; 143 bool m_yuvDecodingFailed;
138 size_t m_frameCount; 144 size_t m_frameCount;
139 Vector<bool> m_hasAlpha; 145 Vector<bool> m_hasAlpha;
140 146
141 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; 147 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory;
142 148
143 // Prevents multiple decode operations on the same data. 149 // Prevents multiple decode operations on the same data.
144 Mutex m_decodeMutex; 150 Mutex m_decodeMutex;
145 151
146 // Protect concurrent access to m_hasAlpha. 152 // Protect concurrent access to m_hasAlpha.
147 Mutex m_alphaMutex; 153 Mutex m_alphaMutex;
148 }; 154 };
149 155
150 } // namespace blink 156 } // namespace blink
151 157
152 #endif 158 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698