00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef BitmapImage_h
00028 #define BitmapImage_h
00029
00030 #include "Image.h"
00031 #include "Color.h"
00032 #include "IntSize.h"
00033
00034 #if PLATFORM(MAC)
00035 #include <wtf/RetainPtr.h>
00036 #ifdef __OBJC__
00037 @class NSImage;
00038 #else
00039 class NSImage;
00040 #endif
00041 #endif
00042
00043 #if PLATFORM(WIN)
00044 typedef struct HBITMAP__ *HBITMAP;
00045 #endif
00046
00047 namespace WebCore {
00048 struct FrameData;
00049 }
00050
00051
00052
00053
00054 namespace WTF {
00055 template<> class VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {};
00056 }
00057
00058 namespace WebCore {
00059
00060 template <typename T> class Timer;
00061
00062
00063
00064
00065
00066 struct FrameData : Noncopyable {
00067 FrameData()
00068 : m_frame(0)
00069 , m_duration(0)
00070 , m_hasAlpha(true)
00071 {
00072 }
00073
00074 ~FrameData()
00075 {
00076 clear();
00077 }
00078
00079 void clear();
00080
00081 NativeImagePtr m_frame;
00082 float m_duration;
00083 bool m_hasAlpha;
00084 };
00085
00086
00087
00088
00089
00090 class BitmapImage : public Image {
00091 friend class GraphicsContext;
00092 public:
00093 #if PLATFORM(QT)
00094 BitmapImage(const QPixmap &pixmap, ImageObserver* = 0);
00095 #endif
00096 BitmapImage(ImageObserver* = 0);
00097 ~BitmapImage();
00098
00099 virtual IntSize size() const;
00100
00101 virtual bool dataChanged(bool allDataReceived);
00102
00103
00104
00105
00106 virtual void stopAnimation();
00107 virtual void resetAnimation();
00108
00109 virtual unsigned decodedSize() const { return m_decodedSize; }
00110
00111 #if PLATFORM(MAC)
00112
00113 virtual NSImage* getNSImage();
00114 virtual CFDataRef getTIFFRepresentation();
00115 #endif
00116
00117 #if PLATFORM(CG)
00118 virtual CGImageRef getCGImageRef();
00119 #endif
00120
00121 #if PLATFORM(QT)
00122 virtual QPixmap* getPixmap() const;
00123 #endif
00124
00125 #if PLATFORM(WIN)
00126 virtual bool getHBITMAP(HBITMAP);
00127 virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE);
00128 #endif
00129
00130 virtual NativeImagePtr nativeImageForCurrentFrame() { return frameAtIndex(currentFrame()); }
00131
00132 private:
00133 #if PLATFORM(WIN)
00134 virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator);
00135 #endif
00136 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
00137 #if PLATFORM(QT)
00138 virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
00139 const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
00140 #endif
00141 size_t currentFrame() const { return m_currentFrame; }
00142 size_t frameCount();
00143 NativeImagePtr frameAtIndex(size_t);
00144 float frameDurationAtIndex(size_t);
00145 bool frameHasAlphaAtIndex(size_t);
00146
00147
00148 void cacheFrame(size_t index);
00149
00150
00151
00152 virtual void destroyDecodedData(bool incremental = false);
00153
00154
00155 bool isSizeAvailable();
00156
00157
00158 bool shouldAnimate();
00159 virtual void startAnimation();
00160 void advanceAnimation(Timer<BitmapImage>*);
00161
00162
00163 void initPlatformData();
00164 void invalidatePlatformData();
00165
00166
00167 void checkForSolidColor();
00168
00169 virtual bool mayFillWithSolidColor() const { return m_isSolidColor && m_currentFrame == 0; }
00170 virtual Color solidColor() const { return m_solidColor; }
00171
00172 ImageSource m_source;
00173 mutable IntSize m_size;
00174
00175 size_t m_currentFrame;
00176 Vector<FrameData> m_frames;
00177
00178 Timer<BitmapImage>* m_frameTimer;
00179 int m_repetitionCount;
00180 int m_repetitionsComplete;
00181
00182 #if PLATFORM(MAC)
00183 mutable RetainPtr<NSImage> m_nsImage;
00184 mutable RetainPtr<CFDataRef> m_tiffRep;
00185 #endif
00186
00187 Color m_solidColor;
00188 bool m_isSolidColor;
00189
00190 bool m_animatingImageType;
00191 bool m_animationFinished;
00192
00193 bool m_allDataReceived;
00194
00195 mutable bool m_haveSize;
00196 bool m_sizeAvailable;
00197 unsigned m_decodedSize;
00198
00199 #if PLATFORM(QT)
00200 QPixmap *m_pixmap;
00201 #endif
00202
00203 };
00204
00205 }
00206
00207 #endif