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

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

Issue 1527433002: Deferred GIF image decodes should report decode failures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 4 years, 12 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, PassR efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false)
64 { 64 {
65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, isMultiFrame)); 65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, 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
70 // Decodes and scales the specified frame at |index|. The dimensions and out put 77 // Decodes and scales the specified frame at |index|. The dimensions and out put
71 // format are given in SkImageInfo. Decoded pixels are written into |pixels| with 78 // format are given in SkImageInfo. Decoded pixels are written into |pixels| with
72 // a stride of |rowBytes|. Returns true if decoding was successful. 79 // a stride of |rowBytes|. Returns true if decoding was successful.
73 bool decodeAndScale(const SkImageInfo&, size_t index, void* pixels, size_t r owBytes); 80 bool decodeAndScale(size_t index, const SkImageInfo&, void* pixels, size_t r owBytes);
74 81
75 // Decodes YUV components directly into the provided memory planes. 82 // Decodes YUV components directly into the provided memory planes.
76 bool decodeToYUV(SkISize componentSizes[3], void* planes[3], size_t rowBytes [3]); 83 bool decodeToYUV(size_t index, SkISize componentSizes[3], void* planes[3], s ize_t rowBytes[3]);
77
78 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived);
79
80 // Return our encoded image data. Caller takes ownership and must unref the data
81 // according to the contract SkImageGenerator::refEncodedData.
82 //
83 // Returns null if image is not fully received.
84 SkData* refEncodedData();
85 84
86 const SkISize& getFullSize() const { return m_fullSize; } 85 const SkISize& getFullSize() const { return m_fullSize; }
87 86
88 bool isMultiFrame() const { return m_isMultiFrame; } 87 bool isMultiFrame() const { return m_isMultiFrame; }
88 bool decodeFailed() const { return m_decodeFailed; }
89 89
90 bool hasAlpha(size_t index); 90 bool hasAlpha(size_t index);
91 91
92 bool getYUVComponentSizes(SkISize componentSizes[3]); 92 bool getYUVComponentSizes(SkISize componentSizes[3]);
93 93
94 private: 94 private:
95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame); 95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame);
96 96
97 friend class ImageFrameGeneratorTest; 97 friend class ImageFrameGeneratorTest;
98 friend class DeferredImageDecoderTest; 98 friend class DeferredImageDecoderTest;
99 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. 99 // 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); } 100 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = std::move(factory); }
101 101
102 void setHasAlpha(size_t index, bool hasAlpha); 102 void setHasAlpha(size_t index, bool hasAlpha);
103 103
104 // These methods are called while m_decodeMutex is locked. 104 // These methods are called while m_decodeMutex is locked.
105 SkBitmap tryToResumeDecode(const SkISize& scaledSize, size_t index); 105 SkBitmap tryToResumeDecode(size_t index, const SkISize& scaledSize);
106
107 // Use the given decoder to decode. If a decoder is not given then try to cr eate one.
108 // Returns true if decoding was complete.
109 bool decode(size_t index, ImageDecoder**, SkBitmap*); 106 bool decode(size_t index, ImageDecoder**, SkBitmap*);
110 107
111 SkISize m_fullSize; 108 SkISize m_fullSize;
112 109
113 // ThreadSafeDataTransport is referenced by this class and m_encodedData. 110 // ThreadSafeDataTransport is referenced by this class and m_encodedData.
114 // In case that ImageFrameGenerator get's deleted before m_encodedData, 111 // In case that ImageFrameGenerator get's deleted before m_encodedData,
115 // m_encodedData would hold the reference to it (and underlying data). 112 // m_encodedData would hold the reference to it (and underlying data).
116 RefPtr<ThreadSafeDataTransport> m_data; 113 RefPtr<ThreadSafeDataTransport> m_data;
114
117 bool m_isMultiFrame; 115 bool m_isMultiFrame;
118 bool m_decodeFailedAndEmpty; 116 bool m_decodeFailed;
117 size_t m_frameCount;
119 Vector<bool> m_hasAlpha; 118 Vector<bool> m_hasAlpha;
120 int m_decodeCount;
121 Vector<bool> m_frameComplete; 119 Vector<bool> m_frameComplete;
122 size_t m_frameCount;
123 120
124 class ExternalMemoryAllocator; 121 class ExternalMemoryAllocator;
125 OwnPtr<ExternalMemoryAllocator> m_externalAllocator; 122 OwnPtr<ExternalMemoryAllocator> m_externalAllocator;
126 123
127 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; 124 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory;
128 125
129 // Prevents multiple decode operations on the same data. 126 // Prevents multiple decode operations on the same data.
130 Mutex m_decodeMutex; 127 Mutex m_decodeMutex;
131 128
132 // Protect concurrent access to m_hasAlpha. 129 // Protect concurrent access to m_hasAlpha.
133 Mutex m_alphaMutex; 130 Mutex m_alphaMutex;
134 131
135 // Our encoded image data returned in refEncodedData. 132 // Our encoded image data returned in refEncodedData.
136 SkData* m_encodedData; 133 SkData* m_encodedData;
137 134
138 #if COMPILER(MSVC) 135 #if COMPILER(MSVC)
139 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>; 136 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>;
140 #endif 137 #endif
141 }; 138 };
142 139
143 } // namespace blink 140 } // namespace blink
144 141
145 #endif 142 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698