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