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

Side by Side Diff: Source/core/platform/graphics/ImageFrameGenerator.h

Issue 99103006: Moving GraphicsContext and dependencies from core to platform. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final patch - fixes Android Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24 */
25
26 #ifndef ImageFrameGenerator_h
27 #define ImageFrameGenerator_h
28
29 #include "SkBitmap.h"
30 #include "SkSize.h"
31 #include "SkTypes.h"
32 #include "platform/graphics/ThreadSafeDataTransport.h"
33 #include "wtf/PassOwnPtr.h"
34 #include "wtf/PassRefPtr.h"
35 #include "wtf/RefCounted.h"
36 #include "wtf/RefPtr.h"
37 #include "wtf/ThreadingPrimitives.h"
38 #include "wtf/ThreadSafeRefCounted.h"
39 #include "wtf/Vector.h"
40
41 namespace WebCore {
42
43 class ImageDecoder;
44 class ScaledImageFragment;
45 class SharedBuffer;
46
47 class ImageDecoderFactory {
48 public:
49 virtual ~ImageDecoderFactory() { }
50 virtual PassOwnPtr<ImageDecoder> create() = 0;
51 };
52
53 class ImageFrameGenerator : public ThreadSafeRefCounted<ImageFrameGenerator> {
54 public:
55 static PassRefPtr<ImageFrameGenerator> create(const SkISize& fullSize, PassR efPtr<SharedBuffer> data, bool allDataReceived, bool isMultiFrame = false)
56 {
57 return adoptRef(new ImageFrameGenerator(fullSize, data, allDataReceived, isMultiFrame));
58 }
59
60 ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<SharedBuffer>, bool allDataReceived, bool isMultiFrame);
61 ~ImageFrameGenerator();
62
63 const ScaledImageFragment* decodeAndScale(const SkISize& scaledSize, size_t index = 0);
64
65 void setData(PassRefPtr<SharedBuffer>, bool allDataReceived);
66
67 // Creates a new SharedBuffer containing the data received so far.
68 void copyData(RefPtr<SharedBuffer>*, bool* allDataReceived);
69
70 SkISize getFullSize() const { return m_fullSize; }
71
72 bool isMultiFrame() const { return m_isMultiFrame; }
73
74 // FIXME: Return alpha state for each frame.
75 bool hasAlpha(size_t);
76
77 private:
78 friend class ImageFrameGeneratorTest;
79 friend class DeferredImageDecoderTest;
80 // For testing. |factory| will overwrite the default ImageDecoder creation l ogic if |factory->create()| returns non-zero.
81 void setImageDecoderFactory(PassOwnPtr<ImageDecoderFactory> factory) { m_ima geDecoderFactory = factory; }
82 // For testing.
83 SkBitmap::Allocator* allocator() const { return m_allocator.get(); }
84 void setAllocator(PassOwnPtr<SkBitmap::Allocator> allocator) { m_allocator = allocator; }
85
86 // These methods are called while m_decodeMutex is locked.
87 const ScaledImageFragment* tryToLockCompleteCache(const SkISize& scaledSize, size_t index);
88 const ScaledImageFragment* tryToScale(const ScaledImageFragment* fullSizeIma ge, const SkISize& scaledSize, size_t index);
89 const ScaledImageFragment* tryToResumeDecodeAndScale(const SkISize& scaledSi ze, size_t index);
90
91 // Use the given decoder to decode. If a decoder is not given then try to cr eate one.
92 PassOwnPtr<ScaledImageFragment> decode(size_t index, ImageDecoder**);
93
94 // Return the next generation ID of a new image object. This is used
95 // to identify images of the same frame from different stages of
96 // progressive decode.
97 size_t nextGenerationId() { return m_decodeCount++; }
98
99 SkISize m_fullSize;
100 ThreadSafeDataTransport m_data;
101 bool m_isMultiFrame;
102 bool m_decodeFailedAndEmpty;
103 Vector<bool> m_hasAlpha;
104 size_t m_decodeCount;
105 OwnPtr<SkBitmap::Allocator> m_allocator;
106
107 OwnPtr<ImageDecoderFactory> m_imageDecoderFactory;
108
109 // Prevents multiple decode operations on the same data.
110 Mutex m_decodeMutex;
111
112 // Protect concurrent access to m_hasAlpha.
113 Mutex m_alphaMutex;
114 };
115
116 } // namespace WebCore
117
118 #endif
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/ImageDecodingStoreTest.cpp ('k') | Source/core/platform/graphics/ImageFrameGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698