#ifndef BitmapImage_h
#define BitmapImage_h
#include "Image.h"
#include "Color.h"
#include "ImageOrientation.h"
#include "ImageSource.h"
#include "IntSize.h"
#if USE(CG) || USE(APPKIT)
#include <wtf/RetainPtr.h>
#endif
#if USE(APPKIT)
OBJC_CLASS NSImage;
#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 {
class Timer;
struct FrameData {
WTF_MAKE_NONCOPYABLE(FrameData);
public:
FrameData()
: m_frame(0)
, m_orientation(DefaultImageOrientation)
#if PLATFORM(IOS)
, m_subsamplingScale(0)
, 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)
float m_subsamplingScale;
bool m_haveInfo;
#endif
float m_duration;
bool m_haveMetadata : 1;
bool m_isComplete : 1;
bool m_hasAlpha : 1;
unsigned m_frameBytes;
};
class BitmapImage final : public Image {
friend class GeneratedImage;
friend class CrossfadeGeneratedImage;
friend class GradientImage;
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));
}
#if PLATFORM(WIN)
static PassRefPtr<BitmapImage> create(HBITMAP);
#endif
virtual ~BitmapImage();
virtual bool isBitmapImage() const override { return true; }
virtual bool hasSingleSecurityOrigin() const override;
virtual FloatSize size() const override;
IntSize sizeRespectingOrientation(ImageOrientationDescription = ImageOrientationDescription()) const;
#if PLATFORM(IOS)
virtual FloatSize originalSize() const override;
IntSize originalSizeRespectingOrientation() const;
#endif
IntSize currentFrameSize() const;
virtual bool getHotSpot(IntPoint&) const override;
unsigned decodedSize() const { return m_decodedSize; }
virtual bool dataChanged(bool allDataReceived) override;
virtual String filenameExtension() const override;
virtual void stopAnimation() override;
virtual void resetAnimation() override;
virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal) override;
#if USE(APPKIT)
virtual NSImage* getNSImage() override;
#endif
#if PLATFORM(COCOA)
virtual CFDataRef getTIFFRepresentation() override;
#endif
#if USE(CG)
virtual CGImageRef getCGImageRef() override;
virtual CGImageRef getFirstCGImageRefOfSize(const IntSize&) override;
virtual RetainPtr<CFArrayRef> getCGImageArray() override;
#endif
#if PLATFORM(WIN)
virtual bool getHBITMAP(HBITMAP) override;
virtual bool getHBITMAPOfSize(HBITMAP, const IntSize*) override;
#endif
#if PLATFORM(GTK)
virtual GdkPixbuf* getGdkPixbuf() override;
#endif
#if PLATFORM(EFL)
virtual Evas_Object* getEvasObject(Evas*) override;
#endif
virtual PassNativeImagePtr nativeImageForCurrentFrame() override;
virtual ImageOrientation orientationForCurrentFrame() override { return frameOrientationAtIndex(currentFrame()); }
virtual bool currentFrameKnownToBeOpaque() override;
bool canAnimate();
private:
void updateSize(ImageOrientationDescription = ImageOrientationDescription()) 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) override;
#endif
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, ImageOrientationDescription) override;
#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; }
#if PLATFORM(IOS)
PassNativeImagePtr frameAtIndex(size_t, float scaleHint);
PassNativeImagePtr copyUnscaledFrameAtIndex(size_t);
#endif
size_t frameCount();
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);
#else
void cacheFrame(size_t index);
bool ensureFrameIsCached(size_t index);
#endif
virtual void destroyDecodedData(bool destroyAll = true) override;
void destroyDecodedDataIfNecessary(bool destroyAll);
void destroyMetadataAndNotify(unsigned frameBytesCleared);
bool isSizeAvailable();
void didDecodeProperties() const;
int repetitionCount(bool imageKnownToBeComplete); bool shouldAnimate();
virtual void startAnimation(CatchUpAnimation = CatchUp) override;
void advanceAnimation(Timer&);
bool internalAdvanceAnimation(bool skippingFrames);
void invalidatePlatformData();
void checkForSolidColor();
virtual bool mayFillWithSolidColor() override;
virtual Color solidColor() const override;
#if !ASSERT_DISABLED
virtual bool notSolidColor() override;
#endif
private:
ImageSource m_source;
mutable IntSize m_size; mutable IntSize m_sizeRespectingOrientation;
mutable unsigned m_imageOrientation : 4; mutable unsigned m_shouldRespectImageOrientation : 1;
#if PLATFORM(IOS)
mutable IntSize m_originalSize; mutable IntSize m_originalSizeRespectingOrientation;
#endif
size_t m_currentFrame; Vector<FrameData, 1> m_frames;
std::unique_ptr<Timer> m_frameTimer;
int m_repetitionCount; RepetitionCountStatus m_repetitionCountStatus;
int m_repetitionsComplete; double m_desiredFrameStartTime;
#if USE(APPKIT)
mutable RetainPtr<NSImage> m_nsImage; #endif
#if USE(CG)
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;
RefPtr<Image> m_cachedImage;
};
IMAGE_TYPE_CASTS(BitmapImage)
}
#endif