#include "platform/graphics/ImageObserver.h"
#include "platform/graphics/skia/NativeImageSkia.h"
#include "platform/graphics/skia/SkiaUtils.h"
-#include "wtf/CurrentTime.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/WTFString.h"
namespace blink {
+PassRefPtr<BitmapImage> BitmapImage::create(PassRefPtr<NativeImageSkia> nativeImage, ImageObserver* observer)
+{
+ if (!nativeImage) {
+ return BitmapImage::create(observer);
+ }
+
+ return adoptRef(new BitmapImage(nativeImage, observer));
+}
+
BitmapImage::BitmapImage(ImageObserver* observer)
: Image(observer)
, m_currentFrame(0)
- , m_frames(0)
+ , m_frames()
, m_frameTimer(0)
, m_repetitionCount(cAnimationNone)
, m_repetitionCountStatus(Unknown)
return true;
}
+bool BitmapImage::currentFrameHasSingleSecurityOrigin() const
+{
+ return true;
+}
+
void BitmapImage::destroyDecodedData(bool destroyAll)
{
for (size_t i = 0; i < m_frames.size(); ++i) {
const IntSize frameSize(index ? m_source.frameSizeAtIndex(index) : m_size);
if (frameSize != m_size)
m_hasUniformFrameSize = false;
+
if (m_frames[index].m_frame) {
int deltaBytes = safeCast<int>(m_frames[index].m_frameBytes);
// The fully-decoded frame will subsume the partially decoded data used
return m_sizeRespectingOrientation;
}
-IntSize BitmapImage::currentFrameSize() const
-{
- if (!m_currentFrame || m_hasUniformFrameSize)
- return size();
- IntSize frameSize = m_source.frameSizeAtIndex(m_currentFrame);
- return frameSize;
-}
-
bool BitmapImage::getHotSpot(IntPoint& hotSpot) const
{
- bool result = m_source.getHotSpot(hotSpot);
- return result;
+ return m_source.getHotSpot(hotSpot);
}
bool BitmapImage::dataChanged(bool allDataReceived)
return isSizeAvailable();
}
-bool BitmapImage::isAllDataReceived() const
-{
- return m_allDataReceived;
-}
-
bool BitmapImage::hasColorProfile() const
{
return m_source.hasColorProfile();
// causing flicker and wasting CPU.
startAnimation();
- RefPtr<NativeImageSkia> bm = nativeImageForCurrentFrame();
- if (!bm)
+ RefPtr<NativeImageSkia> image = nativeImageForCurrentFrame();
+ if (!image)
return; // It's too early and we don't have an image yet.
FloatRect normDstRect = adjustForNegativeSize(dstRect);
FloatRect normSrcRect = adjustForNegativeSize(srcRect);
- normSrcRect.intersect(FloatRect(0, 0, bm->bitmap().width(), bm->bitmap().height()));
+ normSrcRect.intersect(FloatRect(0, 0, image->bitmap().width(), image->bitmap().height()));
if (normSrcRect.isEmpty() || normDstRect.isEmpty())
return; // Nothing to draw.
}
}
- bm->draw(ctxt, normSrcRect, normDstRect, compositeOp, blendMode);
+ image->draw(ctxt, normSrcRect, normDstRect, compositeOp, blendMode);
if (ImageObserver* observer = imageObserver())
observer->didDraw(this);
}
+void BitmapImage::resetDecoder()
+{
+ ASSERT(isMainThread());
+
+ m_source.resetDecoder();
+}
+
size_t BitmapImage::frameCount()
{
if (!m_haveFrameCount) {
m_frameCount = m_source.frameCount();
// If decoder is not initialized yet, m_source.frameCount() returns 0.
- if (m_frameCount) {
+ if (m_frameCount)
m_haveFrameCount = true;
- }
}
+
return m_frameCount;
}
if (index >= m_frames.size() || !m_frames[index].m_frame)
cacheFrame(index);
+
return true;
}
{
if (!ensureFrameIsCached(index))
return nullptr;
+
return m_frames[index].m_frame;
}
{
if (index < m_frames.size() && m_frames[index].m_haveMetadata && m_frames[index].m_isComplete)
return true;
+
return m_source.frameIsCompleteAtIndex(index);
}
{
if (index < m_frames.size() && m_frames[index].m_haveMetadata)
return m_frames[index].m_duration;
+
return m_source.frameDurationAtIndex(index);
}
PassRefPtr<Image> BitmapImage::imageForDefaultFrame()
{
- if (isAnimated())
+ if (frameCount() > 1 && frameAtIndex(0))
return BitmapImage::create(frameAtIndex(0));
return Image::imageForDefaultFrame();
}
#endif
-
-
int BitmapImage::repetitionCount(bool imageKnownToBeComplete)
{
if ((m_repetitionCountStatus == Unknown) || ((m_repetitionCountStatus == Uncertain) && imageKnownToBeComplete)) {
{
if (m_animationFinished)
return false;
- if (isAnimated())
+ if (frameCount() > 1)
return true;
return m_source.repetitionCount() != cAnimationNone;
}
-bool BitmapImage::isAnimated()
-{
- return frameCount() > 1;
-}
-
void BitmapImage::advanceAnimation(Timer<BitmapImage>*)
{
internalAdvanceAnimation(false);
checkForSolidColor();
ASSERT(m_checkedForSolidColor);
}
+
return m_isSolidColor && !m_currentFrame;
}