tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / ImageSource.h
1 /*
2  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2007-2008 Torch Mobile, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #ifndef ImageSource_h
28 #define ImageSource_h
29
30 #include "ImageOrientation.h"
31
32 #include <wtf/Forward.h>
33 #include <wtf/Noncopyable.h>
34 #include <wtf/Vector.h>
35
36 #if PLATFORM(WX)
37 class wxBitmap;
38 class wxGraphicsBitmap;
39 #elif USE(CG)
40 typedef struct CGImageSource* CGImageSourceRef;
41 typedef struct CGImage* CGImageRef;
42 typedef const struct __CFData* CFDataRef;
43 #elif PLATFORM(QT)
44 #include <qglobal.h>
45 QT_BEGIN_NAMESPACE
46 class QImage;
47 QT_END_NAMESPACE
48 #elif USE(CAIRO)
49 #include "NativeImageCairo.h"
50 #elif USE(SKIA)
51 namespace WebCore {
52 class NativeImageSkia;
53 }
54 #elif OS(WINCE)
55 #include "SharedBitmap.h"
56 #endif
57
58 namespace WebCore {
59
60 class ImageOrientation;
61 class IntPoint;
62 class IntSize;
63 class SharedBuffer;
64
65 #if USE(CG)
66 typedef CGImageSourceRef NativeImageSourcePtr;
67 typedef CGImageRef NativeImagePtr;
68 #elif PLATFORM(OPENVG)
69 class ImageDecoder;
70 class TiledImageOpenVG;
71 typedef ImageDecoder* NativeImageSourcePtr;
72 typedef TiledImageOpenVG* NativeImagePtr;
73 #else
74 class ImageDecoder;
75 typedef ImageDecoder* NativeImageSourcePtr;
76 #if PLATFORM(WX)
77 #if USE(WXGC)
78 typedef wxGraphicsBitmap* NativeImagePtr;
79 #else
80 typedef wxBitmap* NativeImagePtr;
81 #endif
82 #elif USE(CAIRO)
83 typedef WebCore::NativeImageCairo* NativeImagePtr;
84 #elif USE(SKIA)
85 typedef WebCore::NativeImageSkia* NativeImagePtr;
86 #elif OS(WINCE)
87 typedef RefPtr<SharedBitmap> NativeImagePtr;
88 #elif PLATFORM(BLACKBERRY)
89 class ImageDecoder;
90 typedef ImageDecoder* NativeImageSourcePtr;
91 typedef void* NativeImagePtr;
92 #elif PLATFORM(QT)
93 typedef QImage* NativeImagePtr;
94 #endif
95 #endif
96
97 // Right now GIFs are the only recognized image format that supports animation.
98 // The animation system and the constants below are designed with this in mind.
99 // GIFs have an optional 16-bit unsigned loop count that describes how an
100 // animated GIF should be cycled.  If the loop count is absent, the animation
101 // cycles once; if it is 0, the animation cycles infinitely; otherwise the
102 // animation plays n + 1 cycles (where n is the specified loop count).  If the
103 // GIF decoder defaults to cAnimationLoopOnce in the absence of any loop count
104 // and translates an explicit "0" loop count to cAnimationLoopInfinite, then we
105 // get a couple of nice side effects:
106 //   * By making cAnimationLoopOnce be 0, we allow the animation cycling code in
107 //     BitmapImage.cpp to avoid special-casing it, and simply treat all
108 //     non-negative loop counts identically.
109 //   * By making the other two constants negative, we avoid conflicts with any
110 //     real loop count values.
111 const int cAnimationLoopOnce = 0;
112 const int cAnimationLoopInfinite = -1;
113 const int cAnimationNone = -2;
114
115 class ImageSource {
116     WTF_MAKE_NONCOPYABLE(ImageSource);
117 public:
118     enum AlphaOption {
119         AlphaPremultiplied,
120         AlphaNotPremultiplied
121     };
122
123     enum GammaAndColorProfileOption {
124         GammaAndColorProfileApplied,
125         GammaAndColorProfileIgnored
126     };
127
128 #if USE(CG)
129     enum ShouldSkipMetadata {
130         DoNotSkipMetadata,
131         SkipMetadata
132     };
133 #endif
134
135     ImageSource(AlphaOption alphaOption = AlphaPremultiplied, GammaAndColorProfileOption gammaAndColorProfileOption = GammaAndColorProfileApplied);
136     ~ImageSource();
137
138     // Tells the ImageSource that the Image no longer cares about decoded frame
139     // data -- at all (if |destroyAll| is true), or before frame
140     // |clearBeforeFrame| (if |destroyAll| is false).  The ImageSource should
141     // delete cached decoded data for these frames where possible to keep memory
142     // usage low.  When |destroyAll| is true, the ImageSource should also reset
143     // any local state so that decoding can begin again.
144     //
145     // Implementations that delete less than what's specified above waste
146     // memory.  Implementations that delete more may burn CPU re-decoding frames
147     // that could otherwise have been cached, or encounter errors if they're
148     // asked to decode frames they can't decode due to the loss of previous
149     // decoded frames.
150     //
151     // Callers should not call clear(false, n) and subsequently call
152     // createFrameAtIndex(m) with m < n, unless they first call clear(true).
153     // This ensures that stateful ImageSources/decoders will work properly.
154     //
155     // The |data| and |allDataReceived| parameters should be supplied by callers
156     // who set |destroyAll| to true if they wish to be able to continue using
157     // the ImageSource.  This way implementations which choose to destroy their
158     // decoders in some cases can reconstruct them correctly.
159     void clear(bool destroyAll,
160                size_t clearBeforeFrame = 0,
161                SharedBuffer* data = NULL,
162                bool allDataReceived = false);
163
164     bool initialized() const;
165
166     void setData(SharedBuffer* data, bool allDataReceived);
167     String filenameExtension() const;
168
169     bool isSizeAvailable();
170     IntSize size(RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
171     IntSize frameSizeAtIndex(size_t, RespectImageOrientationEnum = DoNotRespectImageOrientation) const;
172
173     bool getHotSpot(IntPoint&) const;
174
175     size_t bytesDecodedToDetermineProperties() const;
176
177     int repetitionCount();
178
179     size_t frameCount() const;
180
181     // Callers should not call this after calling clear() with a higher index;
182     // see comments on clear() above.
183     NativeImagePtr createFrameAtIndex(size_t);
184
185     float frameDurationAtIndex(size_t);
186     bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
187     bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
188     ImageOrientation orientationAtIndex(size_t) const; // EXIF image orientation
189
190 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) || ENABLE(TIZEN_JPEG_IMAGE_SCALE_DECODING)
191     static unsigned maxPixelsPerDecodedImage() { return s_maxPixelsPerDecodedImage; }
192     static void setMaxPixelsPerDecodedImage(unsigned maxPixels) { s_maxPixelsPerDecodedImage = maxPixels; }
193 #endif
194
195 #if ENABLE(TIZEN_JPEGIMAGE_DECODING_THREAD)
196     NativeImageSourcePtr decoder() { return m_decoder; }
197 #endif
198
199 private:
200     NativeImageSourcePtr m_decoder;
201     AlphaOption m_alphaOption;
202     GammaAndColorProfileOption m_gammaAndColorProfileOption;
203 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) || ENABLE(TIZEN_JPEG_IMAGE_SCALE_DECODING)
204     static unsigned s_maxPixelsPerDecodedImage;
205 #endif
206 };
207
208 }
209
210 #endif