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

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

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: Response to comments Created 3 years, 8 months 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( 66 static PassRefPtr<ImageFrameGenerator> create(
67 const SkISize& fullSize, 67 const SkImageInfo& info,
68 bool isMultiFrame, 68 bool isMultiFrame,
69 const ColorBehavior& colorBehavior) { 69 const ColorBehavior& colorBehavior) {
70 return adoptRef( 70 return adoptRef(new ImageFrameGenerator(info, isMultiFrame, colorBehavior));
71 new ImageFrameGenerator(fullSize, isMultiFrame, colorBehavior));
72 } 71 }
73 72
74 ~ImageFrameGenerator(); 73 ~ImageFrameGenerator();
75 74
76 // Decodes and scales the specified frame at |index|. The dimensions and 75 // Decodes and scales the specified frame at |index|. The dimensions and
77 // output format are given in SkImageInfo. Decoded pixels are written into 76 // output format are given in SkImageInfo. Decoded pixels are written into
78 // |pixels| with a stride of |rowBytes|. Returns true if decoding was 77 // |pixels| with a stride of |rowBytes|. Returns true if decoding was
79 // successful. 78 // successful.
80 bool decodeAndScale(SegmentReader*, 79 bool decodeAndScale(SegmentReader*,
81 bool allDataReceived, 80 bool allDataReceived,
82 size_t index, 81 size_t index,
83 const SkImageInfo&, 82 const SkImageInfo&,
84 void* pixels, 83 void* pixels,
85 size_t rowBytes); 84 size_t rowBytes);
86 85
87 // Decodes YUV components directly into the provided memory planes. Must not 86 // Decodes YUV components directly into the provided memory planes. Must not
88 // be called unless getYUVComponentSizes has been called and returned true. 87 // be called unless getYUVComponentSizes has been called and returned true.
89 // YUV decoding does not currently support progressive decoding. In order to 88 // YUV decoding does not currently support progressive decoding. In order to
90 // support it, ImageDecoder needs something analagous to its ImageFrame cache 89 // support it, ImageDecoder needs something analagous to its ImageFrame cache
91 // 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.
92 bool decodeToYUV(SegmentReader*, 91 bool decodeToYUV(SegmentReader*,
93 size_t index, 92 size_t index,
94 const SkISize componentSizes[3], 93 const SkISize componentSizes[3],
95 void* planes[3], 94 void* planes[3],
96 const size_t rowBytes[3]); 95 const size_t rowBytes[3]);
97 96
98 const SkISize& getFullSize() const { return m_fullSize; } 97 SkISize getFullSize() const { return m_info.dimensions(); }
99 98
100 bool isMultiFrame() const { return m_isMultiFrame; } 99 bool isMultiFrame() const { return m_isMultiFrame; }
101 bool decodeFailed() const { return m_decodeFailed; } 100 bool decodeFailed() const { return m_decodeFailed; }
102 101
103 bool hasAlpha(size_t index); 102 bool hasAlpha(size_t index);
104 103
105 // Must not be called unless the SkROBuffer has all the data. YUV decoding 104 // Must not be called unless the SkROBuffer has all the data. YUV decoding
106 // does not currently support progressive decoding. See comment above on 105 // does not currently support progressive decoding. See comment above on
107 // decodeToYUV(). 106 // decodeToYUV().
108 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*); 107 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*);
109 108
110 private: 109 private:
111 ImageFrameGenerator(const SkISize& fullSize, 110 ImageFrameGenerator(const SkImageInfo&,
112 bool isMultiFrame, 111 bool isMultiFrame,
113 const ColorBehavior&); 112 const ColorBehavior&);
114 113
115 friend class ImageFrameGeneratorTest; 114 friend class ImageFrameGeneratorTest;
116 friend class DeferredImageDecoderTest; 115 friend class DeferredImageDecoderTest;
117 // For testing. |factory| will overwrite the default ImageDecoder creation 116 // For testing. |factory| will overwrite the default ImageDecoder creation
118 // logic if |factory->create()| returns non-zero. 117 // logic if |factory->create()| returns non-zero.
119 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) { 118 void setImageDecoderFactory(std::unique_ptr<ImageDecoderFactory> factory) {
120 m_imageDecoderFactory = std::move(factory); 119 m_imageDecoderFactory = std::move(factory);
121 } 120 }
122 121
123 void setHasAlpha(size_t index, bool hasAlpha); 122 void setHasAlpha(size_t index, bool hasAlpha);
124 123
125 SkBitmap tryToResumeDecode(SegmentReader*, 124 SkBitmap tryToResumeDecode(SegmentReader*,
126 bool allDataReceived, 125 bool allDataReceived,
127 size_t index, 126 size_t index,
128 const SkISize& scaledSize, 127 const SkISize& scaledSize,
129 SkBitmap::Allocator*); 128 SkBitmap::Allocator*,
129 const SkImageInfo& dstInfo);
130 // This method should only be called while m_decodeMutex is locked. 130 // This method should only be called while m_decodeMutex is locked.
131 bool decode(SegmentReader*, 131 bool decode(SegmentReader*,
132 bool allDataReceived, 132 bool allDataReceived,
133 size_t index, 133 size_t index,
134 ImageDecoder**, 134 ImageDecoder**,
135 SkBitmap*, 135 SkBitmap*,
136 SkBitmap::Allocator*); 136 SkBitmap::Allocator*,
137 ImageDecoder::AlphaOption,
138 const SkImageInfo& dstInfo);
137 139
138 const SkISize m_fullSize; 140 const SkImageInfo m_info;
139 141
140 // Parameters used to create internal ImageDecoder objects. 142 // Parameters used to create internal ImageDecoder objects.
141 const ColorBehavior m_decoderColorBehavior; 143 const ColorBehavior m_decoderColorBehavior;
142 144
143 const bool m_isMultiFrame; 145 const bool m_isMultiFrame;
144 bool m_decodeFailed; 146 bool m_decodeFailed;
145 bool m_yuvDecodingFailed; 147 bool m_yuvDecodingFailed;
146 size_t m_frameCount; 148 size_t m_frameCount;
147 Vector<bool> m_hasAlpha; 149 Vector<bool> m_hasAlpha;
148 150
149 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory; 151 std::unique_ptr<ImageDecoderFactory> m_imageDecoderFactory;
150 152
151 // Prevents multiple decode operations on the same data. 153 // Prevents multiple decode operations on the same data.
152 Mutex m_decodeMutex; 154 Mutex m_decodeMutex;
153 155
154 // Protect concurrent access to m_hasAlpha. 156 // Protect concurrent access to m_hasAlpha.
155 Mutex m_alphaMutex; 157 Mutex m_alphaMutex;
156 }; 158 };
157 159
158 } // namespace blink 160 } // namespace blink
159 161
160 #endif 162 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698