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

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

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small cleanups; remove unneeded changes Created 4 years, 9 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
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/graphics/ThreadSafeDataTransport.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" 36 #include "wtf/PassOwnPtr.h"
37 #include "wtf/PassRefPtr.h" 37 #include "wtf/PassRefPtr.h"
38 #include "wtf/RefCounted.h" 38 #include "wtf/RefCounted.h"
39 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
40 #include "wtf/ThreadSafeRefCounted.h" 40 #include "wtf/ThreadSafeRefCounted.h"
41 #include "wtf/ThreadingPrimitives.h" 41 #include "wtf/ThreadingPrimitives.h"
42 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
43 43
44 class SkData; 44 class SkData;
45 45
46 namespace blink { 46 namespace blink {
47 47
48 class ImageDecoder; 48 class ImageDecoder;
49 class SharedBuffer;
50 49
51 class PLATFORM_EXPORT ImageDecoderFactory { 50 class PLATFORM_EXPORT ImageDecoderFactory {
52 USING_FAST_MALLOC(ImageDecoderFactory); 51 USING_FAST_MALLOC(ImageDecoderFactory);
53 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); 52 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory);
54 public: 53 public:
55 ImageDecoderFactory() {} 54 ImageDecoderFactory() {}
56 virtual ~ImageDecoderFactory() { } 55 virtual ~ImageDecoderFactory() { }
57 virtual PassOwnPtr<ImageDecoder> create() = 0; 56 virtual PassOwnPtr<ImageDecoder> create() = 0;
58 }; 57 };
59 58
60 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> { 59 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> {
61 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); 60 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator);
62 public: 61 public:
63 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false) 62 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, bool isMultiFrame = false)
64 { 63 {
65 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, isMultiFrame)); 64 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame));
66 } 65 }
67 66
68 ~ImageFrameGenerator(); 67 ~ImageFrameGenerator();
69 68
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
77 // Decodes and scales the specified frame at |index|. The dimensions and out put 69 // Decodes and scales the specified frame at |index|. The dimensions and out put
78 // format are given in SkImageInfo. Decoded pixels are written into |pixels| with 70 // format are given in SkImageInfo. Decoded pixels are written into |pixels| with
79 // a stride of |rowBytes|. Returns true if decoding was successful. 71 // a stride of |rowBytes|. Returns true if decoding was successful.
80 bool decodeAndScale(size_t index, const SkImageInfo&, void* pixels, size_t r owBytes); 72 bool decodeAndScale(SegmentReader*, bool allDataReceived, size_t index, cons t SkImageInfo&, void* pixels, size_t rowBytes);
81 73
82 // Decodes YUV components directly into the provided memory planes. 74 // Decodes YUV components directly into the provided memory planes.
83 bool decodeToYUV(size_t index, SkISize componentSizes[3], void* planes[3], s ize_t rowBytes[3]); 75 // Must not be called unless getYUVComponentSizes has been called and return ed true.
76 bool decodeToYUV(SegmentReader*, size_t index, SkISize componentSizes[3], vo id* planes[3], size_t rowBytes[3]);
84 77
85 const SkISize& getFullSize() const { return m_fullSize; } 78 const SkISize& getFullSize() const { return m_fullSize; }
86 79
87 bool isMultiFrame() const { return m_isMultiFrame; } 80 bool isMultiFrame() const { return m_isMultiFrame; }
88 bool decodeFailed() const { return m_decodeFailed; } 81 bool decodeFailed() const { return m_decodeFailed; }
89 82
90 bool hasAlpha(size_t index); 83 bool hasAlpha(size_t index);
91 84
92 bool getYUVComponentSizes(SkISize componentSizes[3]); 85 // Must not be called unless the SkROBuffer has all the data.
86 // FIXME: YUV decoding does not currently support progressive decoding.
87 bool getYUVComponentSizes(SegmentReader*, SkISize componentSizes[3]);
93 88
94 private: 89 private:
95 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame); 90 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame);
96 91
97 friend class ImageFrameGeneratorTest; 92 friend class ImageFrameGeneratorTest;
98 friend class DeferredImageDecoderTest; 93 friend class DeferredImageDecoderTest;
99 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. 94 // 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); } 95 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = std::move(factory); }
101 96
102 void setHasAlpha(size_t index, bool hasAlpha); 97 void setHasAlpha(size_t index, bool hasAlpha);
103 98
104 // These methods are called while m_decodeMutex is locked. 99 SkBitmap tryToResumeDecode(SegmentReader*, bool allDataReceived, size_t inde x, const SkISize& scaledSize, SkBitmap::Allocator*);
105 SkBitmap tryToResumeDecode(size_t index, const SkISize& scaledSize); 100 // This method should only be called while m_decodeMutex is locked.
106 bool decode(size_t index, ImageDecoder**, SkBitmap*); 101 bool decode(SegmentReader*, bool allDataReceived, size_t index, ImageDecoder **, SkBitmap*, SkBitmap::Allocator*);
107 102
108 SkISize m_fullSize; 103 const SkISize m_fullSize;
109 104
110 // ThreadSafeDataTransport is referenced by this class and m_encodedData. 105 const bool m_isMultiFrame;
111 // In case that ImageFrameGenerator get's deleted before m_encodedData,
112 // m_encodedData would hold the reference to it (and underlying data).
113 RefPtr<ThreadSafeDataTransport> m_data;
114
115 bool m_isMultiFrame;
116 bool m_decodeFailed; 106 bool m_decodeFailed;
117 size_t m_frameCount; 107 size_t m_frameCount;
118 Vector<bool> m_hasAlpha; 108 Vector<bool> m_hasAlpha;
119 Vector<bool> m_frameComplete; 109 Vector<bool> m_frameComplete;
120 110
121 class ExternalMemoryAllocator;
122 OwnPtr<ExternalMemoryAllocator> m_externalAllocator;
123
124 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; 111 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory;
125 112
126 // Prevents multiple decode operations on the same data. 113 // Prevents multiple decode operations on the same data.
127 Mutex m_decodeMutex; 114 Mutex m_decodeMutex;
128 115
129 // Protect concurrent access to m_hasAlpha. 116 // Protect concurrent access to m_hasAlpha.
130 Mutex m_alphaMutex; 117 Mutex m_alphaMutex;
131
132 // Our encoded image data returned in refEncodedData.
133 SkData* m_encodedData;
134
135 #if COMPILER(MSVC)
136 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>;
137 #endif
138 }; 118 };
139 119
140 } // namespace blink 120 } // namespace blink
141 121
142 #endif 122 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698