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

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

Issue 1866243003: Revert of Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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/image-decoders/SegmentReader.h" 30 #include "platform/graphics/ThreadSafeDataTransport.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 "third_party/skia/include/core/SkYUVSizeInfo.h" 34 #include "third_party/skia/include/core/SkYUVSizeInfo.h"
35 #include "wtf/Allocator.h" 35 #include "wtf/Allocator.h"
36 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
37 #include "wtf/PassOwnPtr.h" 37 #include "wtf/PassOwnPtr.h"
38 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h" 39 #include "wtf/RefCounted.h"
40 #include "wtf/RefPtr.h" 40 #include "wtf/RefPtr.h"
41 #include "wtf/ThreadSafeRefCounted.h" 41 #include "wtf/ThreadSafeRefCounted.h"
42 #include "wtf/ThreadingPrimitives.h" 42 #include "wtf/ThreadingPrimitives.h"
43 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
44 44
45 class SkData; 45 class SkData;
46 46
47 namespace blink { 47 namespace blink {
48 48
49 class ImageDecoder; 49 class ImageDecoder;
50 class SharedBuffer;
50 51
51 class PLATFORM_EXPORT ImageDecoderFactory { 52 class PLATFORM_EXPORT ImageDecoderFactory {
52 USING_FAST_MALLOC(ImageDecoderFactory); 53 USING_FAST_MALLOC(ImageDecoderFactory);
53 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory); 54 WTF_MAKE_NONCOPYABLE(ImageDecoderFactory);
54 public: 55 public:
55 ImageDecoderFactory() {} 56 ImageDecoderFactory() {}
56 virtual ~ImageDecoderFactory() { } 57 virtual ~ImageDecoderFactory() { }
57 virtual PassOwnPtr<ImageDecoder> create() = 0; 58 virtual PassOwnPtr<ImageDecoder> create() = 0;
58 }; 59 };
59 60
60 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> { 61 class PLATFORM_EXPORT ImageFrameGenerator final : public ThreadSafeRefCounted<Im ageFrameGenerator> {
61 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator); 62 WTF_MAKE_NONCOPYABLE(ImageFrameGenerator);
62 public: 63 public:
63 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, bool isMultiFrame = false) 64 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false)
64 { 65 {
65 return adoptRef(new ImageFrameGenerator(fullSize, isMultiFrame)); 66 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, isMultiFrame));
66 } 67 }
67 68
68 ~ImageFrameGenerator(); 69 ~ImageFrameGenerator();
69 70
71 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived);
72
73 // Return our encoded image data. Caller takes ownership and must unref the data
74 // according to the contract SkImageGenerator::refEncodedData. Returns null if
75 // the data is has not been fully received.
76 SkData* refEncodedData();
77
70 // Decodes and scales the specified frame at |index|. The dimensions and out put 78 // 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 79 // format are given in SkImageInfo. Decoded pixels are written into |pixels| with
72 // a stride of |rowBytes|. Returns true if decoding was successful. 80 // a stride of |rowBytes|. Returns true if decoding was successful.
73 bool decodeAndScale(SegmentReader*, bool allDataReceived, size_t index, cons t SkImageInfo&, void* pixels, size_t rowBytes); 81 bool decodeAndScale(size_t index, const SkImageInfo&, void* pixels, size_t r owBytes);
74 82
75 // Decodes YUV components directly into the provided memory planes. 83 // Decodes YUV components directly into the provided memory planes.
76 // Must not be called unless getYUVComponentSizes has been called and return ed true. 84 bool decodeToYUV(size_t index, const SkISize componentSizes[3], void* planes [3], const size_t rowBytes[3]);
77 // YUV decoding does not currently support progressive decoding. In order to support it, ImageDecoder needs something
78 // analagous to its ImageFrame cache to hold partial planes, and the GPU cod e needs to handle them.
79 bool decodeToYUV(SegmentReader*, size_t index, const SkISize componentSizes[ 3], void* planes[3], const size_t rowBytes[3]);
80 85
81 const SkISize& getFullSize() const { return m_fullSize; } 86 const SkISize& getFullSize() const { return m_fullSize; }
82 87
83 bool isMultiFrame() const { return m_isMultiFrame; } 88 bool isMultiFrame() const { return m_isMultiFrame; }
84 bool decodeFailed() const { return m_decodeFailed; } 89 bool decodeFailed() const { return m_decodeFailed; }
85 90
86 bool hasAlpha(size_t index); 91 bool hasAlpha(size_t index);
87 92
88 // Must not be called unless the SkROBuffer has all the data. 93 bool getYUVComponentSizes(SkYUVSizeInfo*);
89 // YUV decoding does not currently support progressive decoding. See comment above on decodeToYUV.
90 bool getYUVComponentSizes(SegmentReader*, SkYUVSizeInfo*);
91 94
92 private: 95 private:
93 ImageFrameGenerator(const SkISize& fullSize, bool isMultiFrame); 96 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame);
94 97
95 friend class ImageFrameGeneratorTest; 98 friend class ImageFrameGeneratorTest;
96 friend class DeferredImageDecoderTest; 99 friend class DeferredImageDecoderTest;
97 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero. 100 // 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); } 101 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = std::move(factory); }
99 102
100 void setHasAlpha(size_t index, bool hasAlpha); 103 void setHasAlpha(size_t index, bool hasAlpha);
101 104
102 SkBitmap tryToResumeDecode(SegmentReader*, bool allDataReceived, size_t inde x, const SkISize& scaledSize, SkBitmap::Allocator*); 105 // These methods are called while m_decodeMutex is locked.
103 // This method should only be called while m_decodeMutex is locked. 106 SkBitmap tryToResumeDecode(size_t index, const SkISize& scaledSize);
104 bool decode(SegmentReader*, bool allDataReceived, size_t index, ImageDecoder **, SkBitmap*, SkBitmap::Allocator*); 107 bool decode(size_t index, ImageDecoder**, SkBitmap*);
105 108
106 const SkISize m_fullSize; 109 SkISize m_fullSize;
107 110
108 const bool m_isMultiFrame; 111 // ThreadSafeDataTransport is referenced by this class and m_encodedData.
112 // In case that ImageFrameGenerator get's deleted before m_encodedData,
113 // m_encodedData would hold the reference to it (and underlying data).
114 RefPtr<ThreadSafeDataTransport> m_data;
115
116 bool m_isMultiFrame;
109 bool m_decodeFailed; 117 bool m_decodeFailed;
110 bool m_yuvDecodingFailed; 118 bool m_yuvDecodingFailed;
111 size_t m_frameCount; 119 size_t m_frameCount;
112 Vector<bool> m_hasAlpha; 120 Vector<bool> m_hasAlpha;
113 121
122 class ExternalMemoryAllocator;
123 OwnPtr<ExternalMemoryAllocator> m_externalAllocator;
124
114 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory; 125 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory;
115 126
116 // Prevents multiple decode operations on the same data. 127 // Prevents multiple decode operations on the same data.
117 Mutex m_decodeMutex; 128 Mutex m_decodeMutex;
118 129
119 // Protect concurrent access to m_hasAlpha. 130 // Protect concurrent access to m_hasAlpha.
120 Mutex m_alphaMutex; 131 Mutex m_alphaMutex;
132
133 // Our encoded image data returned in refEncodedData.
134 SkData* m_encodedData;
135
136 #if COMPILER(MSVC)
137 friend struct ::WTF::OwnedPtrDeleter<ExternalMemoryAllocator>;
138 #endif
121 }; 139 };
122 140
123 } // namespace blink 141 } // namespace blink
124 142
125 #endif 143 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698