• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <wtf/Noncopyable.h>
31 #include <wtf/Vector.h>
32 
33 #if PLATFORM(WX)
34 class wxBitmap;
35 class wxGraphicsBitmap;
36 #elif PLATFORM(CG)
37 typedef struct CGImageSource* CGImageSourceRef;
38 typedef struct CGImage* CGImageRef;
39 typedef const struct __CFData* CFDataRef;
40 #elif PLATFORM(QT)
41 #include <qglobal.h>
42 QT_BEGIN_NAMESPACE
43 class QPixmap;
44 QT_END_NAMESPACE
45 #elif PLATFORM(CAIRO)
46 struct _cairo_surface;
47 typedef struct _cairo_surface cairo_surface_t;
48 #elif PLATFORM(ANDROID) && PLATFORM(SGL)
49 #include "SkString.h"
50 class SkBitmapRef;
51 class PrivateAndroidImageSourceRec;
52 #elif PLATFORM(SKIA)
53 class NativeImageSkia;
54 #elif PLATFORM(WINCE)
55 #include "SharedBitmap.h"
56 #endif
57 
58 namespace WebCore {
59 
60 class IntSize;
61 class SharedBuffer;
62 class String;
63 
64 #if PLATFORM(WX)
65 class ImageDecoder;
66 typedef ImageDecoder* NativeImageSourcePtr;
67 typedef const Vector<char>* NativeBytePtr;
68 #if USE(WXGC)
69 typedef wxGraphicsBitmap* NativeImagePtr;
70 #else
71 typedef wxBitmap* NativeImagePtr;
72 #endif
73 #elif PLATFORM(CG)
74 typedef CGImageSourceRef NativeImageSourcePtr;
75 typedef CGImageRef NativeImagePtr;
76 #elif PLATFORM(QT)
77 class ImageDecoderQt;
78 typedef ImageDecoderQt* NativeImageSourcePtr;
79 typedef QPixmap* NativeImagePtr;
80 #elif PLATFORM(ANDROID)
81 #if PLATFORM(SGL)
82 class String;
83 #ifdef ANDROID_ANIMATED_GIF
84 class ImageDecoder;
85 #endif
86 struct NativeImageSourcePtr {
87     SkString m_url;
88     PrivateAndroidImageSourceRec* m_image;
89 #ifdef ANDROID_ANIMATED_GIF
90     ImageDecoder* m_gifDecoder;
91 #endif
92 };
93 typedef const Vector<char>* NativeBytePtr;
94 typedef SkBitmapRef* NativeImagePtr;
95 #elif PLATFORM(SKIA) // ANDROID
96 class ImageDecoder;
97 typedef ImageDecoder* NativeImageSourcePtr;
98 typedef NativeImageSkia* NativeImagePtr;
99 #endif
100 #elif PLATFORM(CAIRO)
101 class ImageDecoder;
102 typedef ImageDecoder* NativeImageSourcePtr;
103 typedef cairo_surface_t* NativeImagePtr;
104 #elif PLATFORM(SKIA)
105 class ImageDecoder;
106 typedef ImageDecoder* NativeImageSourcePtr;
107 typedef NativeImageSkia* NativeImagePtr;
108 #elif PLATFORM(WINCE)
109 class ImageDecoder;
110 typedef ImageDecoder* NativeImageSourcePtr;
111 typedef RefPtr<SharedBitmap> NativeImagePtr;
112 #endif
113 
114 const int cAnimationLoopOnce = -1;
115 const int cAnimationNone = -2;
116 
117 class ImageSource : public Noncopyable {
118 public:
119     ImageSource();
120     ~ImageSource();
121 
122     // Tells the ImageSource that the Image no longer cares about decoded frame
123     // data -- at all (if |destroyAll| is true), or before frame
124     // |clearBeforeFrame| (if |destroyAll| is false).  The ImageSource should
125     // delete cached decoded data for these frames where possible to keep memory
126     // usage low.  When |destroyAll| is true, the ImageSource should also reset
127     // any local state so that decoding can begin again.
128     //
129     // Implementations that delete less than what's specified above waste
130     // memory.  Implementations that delete more may burn CPU re-decoding frames
131     // that could otherwise have been cached, or encounter errors if they're
132     // asked to decode frames they can't decode due to the loss of previous
133     // decoded frames.
134     //
135     // Callers should not call clear(false, n) and subsequently call
136     // createFrameAtIndex(m) with m < n, unless they first call clear(true).
137     // This ensures that stateful ImageSources/decoders will work properly.
138     //
139     // The |data| and |allDataReceived| parameters should be supplied by callers
140     // who set |destroyAll| to true if they wish to be able to continue using
141     // the ImageSource.  This way implementations which choose to destroy their
142     // decoders in some cases can reconstruct them correctly.
143     void clear(bool destroyAll,
144                size_t clearBeforeFrame = 0,
145                SharedBuffer* data = NULL,
146                bool allDataReceived = false);
147 
148     bool initialized() const;
149 
150     void setData(SharedBuffer* data, bool allDataReceived);
151     String filenameExtension() const;
152 
153     bool isSizeAvailable();
154     IntSize size() const;
155     IntSize frameSizeAtIndex(size_t) const;
156 
157     int repetitionCount();
158 
159     size_t frameCount() const;
160 
161     // Callers should not call this after calling clear() with a higher index;
162     // see comments on clear() above.
163     NativeImagePtr createFrameAtIndex(size_t);
164 
165     float frameDurationAtIndex(size_t);
166     bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha.
167     bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded.
168 
169 #if PLATFORM(ANDROID)
170 #if PLATFORM(SGL)
171     void clearURL();
172     void setURL(const String& url);
173 #endif
174 #endif
175 private:
176 #if PLATFORM(ANDROID)
177     // FIXME: This is protected only to allow ImageSourceSkia to set ICO decoder
178     // with a preferred size. See ImageSourceSkia.h for discussion.
179 protected:
180 #endif
181     NativeImageSourcePtr m_decoder;
182 };
183 
184 }
185 
186 #endif
187