#include "config.h"
#include "ImageFrame.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
ImageFrame::ImageFrame()
{
}
ImageFrame::~ImageFrame()
{
clearImage();
}
const ImageFrame& ImageFrame::defaultFrame()
{
static NeverDestroyed<ImageFrame> sharedInstance;
return sharedInstance;
}
ImageFrame& ImageFrame::operator=(const ImageFrame& other)
{
if (this == &other)
return *this;
m_decoding = other.m_decoding;
m_size = other.m_size;
#if !USE(CG)
if (other.backingStore())
initialize(*other.backingStore());
else
m_backingStore = nullptr;
m_disposalMethod = other.m_disposalMethod;
#endif
m_nativeImage = other.m_nativeImage;
m_subsamplingLevel = other.m_subsamplingLevel;
m_orientation = other.m_orientation;
m_duration = other.m_duration;
m_hasAlpha = other.m_hasAlpha;
return *this;
}
unsigned ImageFrame::clearImage()
{
#if !USE(CG)
if (hasBackingStore())
m_backingStore = nullptr;
#endif
if (!hasNativeImage())
return 0;
unsigned frameBytes = this->frameBytes();
clearNativeImageSubimages(m_nativeImage);
m_nativeImage = nullptr;
return frameBytes;
}
unsigned ImageFrame::clear()
{
unsigned frameBytes = clearImage();
*this = ImageFrame();
return frameBytes;
}
#if !USE(CG)
bool ImageFrame::initialize(const ImageBackingStore& backingStore)
{
if (&backingStore == this->backingStore())
return true;
m_backingStore = ImageBackingStore::create(backingStore);
return m_backingStore != nullptr;
}
bool ImageFrame::initialize(const IntSize& size, bool premultiplyAlpha)
{
if (size.isEmpty())
return false;
m_backingStore = ImageBackingStore::create(size, premultiplyAlpha);
return m_backingStore != nullptr;
}
#endif
IntSize ImageFrame::size() const
{
#if !USE(CG)
if (hasBackingStore())
return backingStore()->size();
#endif
return m_size;
}
Color ImageFrame::singlePixelSolidColor() const
{
if (!hasNativeImage() || m_size != IntSize(1, 1))
return Color();
return nativeImageSinglePixelSolidColor(m_nativeImage);
}
}