#ifndef BitmapImage_h
#define BitmapImage_h
#include "Image.h"
#include "Color.h"
#include "ImageOrientation.h"
#include "ImageSource.h"
#include "IntSize.h"
#if PLATFORM(MAC)
#include <wtf/RetainPtr.h>
#if !PLATFORM(IOS)
OBJC_CLASS NSImage;
#endif // PLATFORM(IOS)
#endif
#if PLATFORM(WIN)
typedef struct HBITMAP__ *HBITMAP;
#endif
namespace WebCore {
struct FrameData;
}
namespace WTF {
template<> struct VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {
static const bool canInitializeWithMemset = false; };
}
namespace WebCore {
template <typename T> class Timer;
struct FrameData {
WTF_MAKE_NONCOPYABLE(FrameData);
public:
FrameData()
: m_frame(0)
, m_orientation(DefaultImageOrientation)
#if PLATFORM(IOS)
, m_bytes(0)
, m_scale(0.0f)
, m_haveInfo(false)
#endif
, m_duration(0)
, m_haveMetadata(false)
, m_isComplete(false)
, m_hasAlpha(true)
, m_frameBytes(0)
{
}
~FrameData()
{
clear(true);
}
bool clear(bool clearMetadata);
NativeImagePtr m_frame;
ImageOrientation m_orientation;
#if PLATFORM(IOS)
ssize_t m_bytes;
float m_scale;
bool m_haveInfo;
#endif
float m_duration;
bool m_haveMetadata : 1;
bool m_isComplete : 1;
bool m_hasAlpha : 1;
unsigned m_frameBytes;
};
class BitmapImage : public Image {
friend class GeneratedImage;
friend class CrossfadeGeneratedImage;
friend class GeneratorGeneratedImage;
friend class GraphicsContext;
public:
static PassRefPtr<BitmapImage> create(PassNativeImagePtr nativeImage, ImageObserver* observer = 0)
{
return adoptRef(new BitmapImage(nativeImage, observer));
}
static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0)
{
return adoptRef(new BitmapImage(observer));
}
virtual ~BitmapImage();
virtual bool isBitmapImage() const;
virtual bool hasSingleSecurityOrigin() const;
virtual IntSize size() const;
IntSize sizeRespectingOrientation() const;
#if PLATFORM(IOS)
virtual IntSize originalSize() const;
IntSize originalSizeRespectingOrientation() const;
#endif
IntSize currentFrameSize() const;
virtual bool getHotSpot(IntPoint&) const;
virtual bool dataChanged(bool allDataReceived);
virtual String filenameExtension() const;
virtual void stopAnimation();
virtual void resetAnimation();
virtual unsigned decodedSize() const;
#if PLATFORM(MAC)
#if !PLATFORM(IOS)
virtual NSImage* getNSImage();
#endif
virtual CFDataRef getTIFFRepresentation();
#endif
#if USE(CG)
virtual CGImageRef getCGImageRef();
virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&);
virtual RetainPtr<CFArrayRef> getCGImageArray();
#endif
#if PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS))
static PassRefPtr<BitmapImage> create(HBITMAP);
#endif
#if PLATFORM(WIN)
virtual bool getHBITMAP(HBITMAP);
virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE);
#endif
#if PLATFORM(GTK)
virtual GdkPixbuf* getGdkPixbuf();
#endif
#if PLATFORM(EFL)
virtual Evas_Object* getEvasObject(Evas*);
#endif
virtual PassNativeImagePtr nativeImageForCurrentFrame() OVERRIDE;
virtual bool currentFrameKnownToBeOpaque() OVERRIDE;
ImageOrientation currentFrameOrientation();
#if !ASSERT_DISABLED
virtual bool notSolidColor();
#endif
bool canAnimate();
private:
void updateSize() const;
protected:
enum RepetitionCountStatus {
Unknown, Uncertain, Certain };
BitmapImage(PassNativeImagePtr, ImageObserver* = 0);
BitmapImage(ImageObserver* = 0);
#if PLATFORM(WIN)
virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, ColorSpace styleColorSpace, CompositeOperator);
#endif
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode);
#if USE(CG) || USE(CAIRO) || PLATFORM(BLACKBERRY)
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, RespectImageOrientationEnum) OVERRIDE;
#endif
#if USE(WINGDI)
virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
#endif
size_t currentFrame() const { return m_currentFrame; }
virtual size_t frameCount();
#if PLATFORM(IOS)
PassNativeImagePtr frameAtIndex(size_t, float scaleHint);
PassNativeImagePtr copyUnscaledFrameAtIndex(size_t);
#endif
PassNativeImagePtr frameAtIndex(size_t);
bool frameIsCompleteAtIndex(size_t);
float frameDurationAtIndex(size_t);
bool frameHasAlphaAtIndex(size_t);
ImageOrientation frameOrientationAtIndex(size_t);
#if PLATFORM(IOS)
void cacheFrame(size_t index, float scaleHint);
void cacheFrameInfo(size_t index);
bool ensureFrameInfoIsCached(size_t index);
virtual bool canDestroyDecodedDataIfNecessary() const { return true; }
#else
void cacheFrame(size_t index);
bool ensureFrameIsCached(size_t index);
#endif
virtual void destroyDecodedData(bool destroyAll = true);
void destroyDecodedDataIfNecessary(bool destroyAll);
void destroyMetadataAndNotify(unsigned frameBytesCleared);
bool isSizeAvailable();
void didDecodeProperties() const;
int repetitionCount(bool imageKnownToBeComplete); bool shouldAnimate();
virtual void startAnimation(bool catchUpIfNecessary = true);
void advanceAnimation(Timer<BitmapImage>*);
bool internalAdvanceAnimation(bool skippingFrames);
void invalidatePlatformData();
void checkForSolidColor();
virtual bool mayFillWithSolidColor();
virtual Color solidColor() const;
ImageSource m_source;
mutable IntSize m_size; mutable IntSize m_sizeRespectingOrientation;
#if PLATFORM(IOS)
mutable IntSize m_originalSize; mutable IntSize m_originalSizeRespectingOrientation;
#endif
size_t m_currentFrame; Vector<FrameData, 1> m_frames;
Timer<BitmapImage>* m_frameTimer;
int m_repetitionCount; RepetitionCountStatus m_repetitionCountStatus;
int m_repetitionsComplete; double m_desiredFrameStartTime;
#if PLATFORM(MAC)
#if !PLATFORM(IOS)
mutable RetainPtr<NSImage> m_nsImage; #endif
mutable RetainPtr<CFDataRef> m_tiffRep; #endif
Color m_solidColor;
unsigned m_decodedSize; mutable unsigned m_decodedPropertiesSize; size_t m_frameCount;
#if PLATFORM(IOS)
double m_progressiveLoadChunkTime;
uint16_t m_progressiveLoadChunkCount;
#endif
bool m_isSolidColor : 1; bool m_checkedForSolidColor : 1;
bool m_animationFinished : 1;
bool m_allDataReceived : 1; mutable bool m_haveSize : 1; bool m_sizeAvailable : 1; mutable bool m_hasUniformFrameSize : 1;
mutable bool m_haveFrameCount : 1;
};
}
#endif