]> git.saurik.com Git - iphone-api.git/blob - WebCore/ImageSource.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / ImageSource.h
1 /*
2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 ImageSource_h
27 #define ImageSource_h
28
29 #include <wtf/Noncopyable.h>
30 #include <wtf/Vector.h>
31
32 #if PLATFORM(WX)
33 class wxBitmap;
34 #elif PLATFORM(CG)
35 typedef struct CGImageSource* CGImageSourceRef;
36 typedef struct CGImage* CGImageRef;
37 typedef const struct __CFData* CFDataRef;
38 #elif PLATFORM(QT)
39 #include <qglobal.h>
40 QT_BEGIN_NAMESPACE
41 class QPixmap;
42 QT_END_NAMESPACE
43 #elif PLATFORM(CAIRO)
44 struct _cairo_surface;
45 typedef struct _cairo_surface cairo_surface_t;
46 #elif PLATFORM(SKIA)
47 class NativeImageSkia;
48 #endif
49
50 namespace WebCore {
51
52 class IntSize;
53 class SharedBuffer;
54 class String;
55
56 #if PLATFORM(WX)
57 class ImageDecoder;
58 typedef ImageDecoder* NativeImageSourcePtr;
59 typedef const Vector<char>* NativeBytePtr;
60 typedef wxBitmap* NativeImagePtr;
61 #elif PLATFORM(CG)
62 typedef CGImageSourceRef NativeImageSourcePtr;
63 typedef CGImageRef NativeImagePtr;
64 #elif PLATFORM(QT)
65 class ImageDecoderQt;
66 typedef ImageDecoderQt* NativeImageSourcePtr;
67 typedef QPixmap* NativeImagePtr;
68 #elif PLATFORM(CAIRO)
69 class ImageDecoder;
70 typedef ImageDecoder* NativeImageSourcePtr;
71 typedef cairo_surface_t* NativeImagePtr;
72 #elif PLATFORM(SKIA)
73 class ImageDecoder;
74 typedef ImageDecoder* NativeImageSourcePtr;
75 typedef NativeImageSkia* NativeImagePtr;
76 #endif
77
78 const int cAnimationLoopOnce = -1;
79 const int cAnimationNone = -2;
80
81 class ImageSource : Noncopyable {
82 public:
83 ImageSource();
84 ~ImageSource();
85
86 // Tells the ImageSource that the Image no longer cares about decoded frame
87 // data -- at all (if |destroyAll| is true), or before frame
88 // |clearBeforeFrame| (if |destroyAll| is false). The ImageSource should
89 // delete cached decoded data for these frames where possible to keep memory
90 // usage low. When |destroyAll| is true, the ImageSource should also reset
91 // any local state so that decoding can begin again.
92 //
93 // Implementations that delete less than what's specified above waste
94 // memory. Implementations that delete more may burn CPU re-decoding frames
95 // that could otherwise have been cached, or encounter errors if they're
96 // asked to decode frames they can't decode due to the loss of previous
97 // decoded frames.
98 //
99 // Callers should not call clear(false, n) and subsequently call
100 // createFrameAtIndex(m) with m < n, unless they first call clear(true).
101 // This ensures that stateful ImageSources/decoders will work properly.
102 //
103 // The |data| and |allDataReceived| parameters should be supplied by callers
104 // who set |destroyAll| to true if they wish to be able to continue using
105 // the ImageSource. This way implementations which choose to destroy their
106 // decoders in some cases can reconstruct them correctly.
107 void clear(bool destroyAll,
108 size_t clearBeforeFrame = 0,
109 SharedBuffer* data = NULL,
110 bool allDataReceived = false);
111
112 bool initialized() const;
113
114 void setData(SharedBuffer* data, bool allDataReceived);
115 String filenameExtension() const;
116
117 bool isSizeAvailable();
118 IntSize size() const;
119 IntSize frameSizeAtIndex(size_t) const;
120 #if ENABLE(RESPECT_EXIF_ORIENTATION)
121 int orientationAtIndex(size_t) const; // EXIF image orientation
122 #endif
123
124 int repetitionCount();
125
126 size_t frameCount() const;
127
128 // Callers should not call this after calling clear() with a higher index;
129 // see comments on clear() above.
130 NativeImagePtr createFrameAtIndex(size_t, float scaleHint, float* actualScaleOut, ssize_t* bytesOut);
131
132 float frameDurationAtIndex(size_t);
133 bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
134 bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
135
136 // FIXME: This is protected only to allow ImageSourceSkia to set ICO decoder
137 // with a preferred size. See ImageSourceSkia.h for discussion.
138 protected:
139 NativeImageSourcePtr m_decoder;
140 mutable int m_baseSubsampling;
141 mutable bool m_isProgressive;
142 CFDictionaryRef imageSourceOptions(int subsampling = 0) const;
143 };
144
145 }
146
147 #endif