This source file includes following definitions.
- m_objectTracker
- onRefEncodedData
- onNewLockPixels
- onUnlockPixels
- onLockPixelsAreWritable
- MaybeDecoded
- PrepareToDecode
- Decode
#include "config.h"
#include "platform/graphics/LazyDecodingPixelRef.h"
#include "SkData.h"
#include "platform/TraceEvent.h"
#include "platform/graphics/ImageDecodingStore.h"
#include "platform/graphics/ImageFrameGenerator.h"
namespace WebCore {
LazyDecodingPixelRef::LazyDecodingPixelRef(const SkImageInfo& info, PassRefPtr<ImageFrameGenerator> frameGenerator, size_t index)
: LazyPixelRef(info)
, m_frameGenerator(frameGenerator)
, m_frameIndex(index)
, m_lockedImageResource(0)
, m_objectTracker(this)
{
}
LazyDecodingPixelRef::~LazyDecodingPixelRef()
{
}
SkData* LazyDecodingPixelRef::onRefEncodedData()
{
RefPtr<SharedBuffer> buffer = nullptr;
bool allDataReceived = false;
m_frameGenerator->copyData(&buffer, &allDataReceived);
if (buffer && allDataReceived) {
SkData* skdata = SkData::NewWithCopy((void*)buffer->data(), buffer->size());
return skdata;
}
return 0;
}
bool LazyDecodingPixelRef::onNewLockPixels(LockRec* rec)
{
TRACE_EVENT_ASYNC_BEGIN0("webkit", "LazyDecodingPixelRef::onNewLockPixels", this);
ASSERT(!m_lockedImageResource);
SkISize size = m_frameGenerator->getFullSize();
if (!ImageDecodingStore::instance()->lockCache(m_frameGenerator.get(), size, m_frameIndex, &m_lockedImageResource))
m_lockedImageResource = 0;
if (!m_lockedImageResource) {
PlatformInstrumentation::willDecodeLazyPixelRef(getGenerationID());
m_lockedImageResource = m_frameGenerator->decodeAndScale(size, m_frameIndex);
PlatformInstrumentation::didDecodeLazyPixelRef(getGenerationID());
}
if (!m_lockedImageResource)
return false;
ASSERT(!m_lockedImageResource->bitmap().isNull());
ASSERT(m_lockedImageResource->scaledSize() == size);
rec->fPixels = m_lockedImageResource->bitmap().getAddr(0, 0);
rec->fColorTable = 0;
rec->fRowBytes = m_lockedImageResource->bitmap().rowBytes();
return true;
}
void LazyDecodingPixelRef::onUnlockPixels()
{
if (m_lockedImageResource) {
ImageDecodingStore::instance()->unlockCache(m_frameGenerator.get(), m_lockedImageResource);
m_lockedImageResource = 0;
}
TRACE_EVENT_ASYNC_END0("webkit", "LazyDecodingPixelRef::lockPixels", this);
}
bool LazyDecodingPixelRef::onLockPixelsAreWritable() const
{
return false;
}
bool LazyDecodingPixelRef::MaybeDecoded()
{
return ImageDecodingStore::instance()->isCached(m_frameGenerator.get(), m_frameGenerator->getFullSize(), m_frameIndex);
}
bool LazyDecodingPixelRef::PrepareToDecode(const LazyPixelRef::PrepareParams& params)
{
ASSERT(false);
return false;
}
void LazyDecodingPixelRef::Decode()
{
lockPixels();
unlockPixels();
}
}