bool DeferredImageDecoder::createFrameAtIndex(size_t index, SkBitmap* bitmap) { prepareLazyDecodedFrames(); if (index < m_frameData.size()) { // ImageFrameGenerator has the latest known alpha state. There will // be a performance boost if this frame is opaque. *bitmap = createBitmap(index); if (m_frameGenerator->hasAlpha(index)) { m_frameData[index].m_hasAlpha = true; bitmap->setAlphaType(kPremul_SkAlphaType); } else { m_frameData[index].m_hasAlpha = false; bitmap->setAlphaType(kOpaque_SkAlphaType); } m_frameData[index].m_frameBytes = m_size.area() * sizeof(ImageFrame::PixelData); return true; } if (m_actualDecoder) { ImageFrame* buffer = m_actualDecoder->frameBufferAtIndex(index); if (!buffer || buffer->status() == ImageFrame::FrameEmpty) return false; *bitmap = buffer->bitmap(); return true; } return false; }
sk_sp<SkImage> DeferredImageDecoder::createFrameAtIndex(size_t index) { if (m_frameGenerator && m_frameGenerator->decodeFailed()) return nullptr; prepareLazyDecodedFrames(); if (index < m_frameData.size()) { DeferredFrameData* frameData = &m_frameData[index]; if (m_actualDecoder) frameData->m_frameBytes = m_actualDecoder->frameBytesAtIndex(index); else frameData->m_frameBytes = m_size.area() * sizeof(ImageFrame::PixelData); // ImageFrameGenerator has the latest known alpha state. There will be a // performance boost if this frame is opaque. DCHECK(m_frameGenerator); return createFrameImageAtIndex(index, !m_frameGenerator->hasAlpha(index)); } if (!m_actualDecoder || m_actualDecoder->failed()) return nullptr; ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) return nullptr; return (frame->getStatus() == ImageFrame::FrameComplete) ? frame->finalizePixelsAndGetImage() : SkImage::MakeFromBitmap(frame->bitmap()); }
void DeferredImageDecoder::setData(SharedBuffer* data, bool allDataReceived) { if (m_actualDecoder) { m_data = data; m_allDataReceived = allDataReceived; m_actualDecoder->setData(data, allDataReceived); prepareLazyDecodedFrames(); } if (m_frameGenerator) m_frameGenerator->setData(data, allDataReceived); }
ImageFrame* DeferredImageDecoder::frameBufferAtIndex(size_t index) { prepareLazyDecodedFrames(); if (index < m_lazyDecodedFrames.size()) { // ImageFrameGenerator has the latest known alpha state. There will // be a performance boost if this frame is opaque. m_lazyDecodedFrames[index]->setHasAlpha(m_frameGenerator->hasAlpha(index)); return m_lazyDecodedFrames[index].get(); } if (m_actualDecoder) return m_actualDecoder->frameBufferAtIndex(index); return 0; }
void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) { if (m_actualDecoder) { m_data = RefPtr<SharedBuffer>(data); m_lastDataSize = data.size(); m_allDataReceived = allDataReceived; m_actualDecoder->setData(&data, allDataReceived); prepareLazyDecodedFrames(); } if (m_frameGenerator) m_frameGenerator->setData(&data, allDataReceived); }
void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) { if (m_actualDecoder) { const bool firstData = !m_data; const bool moreData = data.size() > m_lastDataSize; m_dataChanged = firstData || moreData; m_data = RefPtr<SharedBuffer>(data); m_lastDataSize = data.size(); m_allDataReceived = allDataReceived; m_actualDecoder->setData(&data, allDataReceived); prepareLazyDecodedFrames(); } if (m_frameGenerator) m_frameGenerator->setData(&data, allDataReceived); }
PassRefPtr<SkImage> DeferredImageDecoder::createFrameAtIndex(size_t index) { prepareLazyDecodedFrames(); if (index < m_frameData.size()) { // ImageFrameGenerator has the latest known alpha state. There will be a // performance boost if this frame is opaque. FrameData* frameData = &m_frameData[index]; frameData->m_hasAlpha = m_frameGenerator->hasAlpha(index); frameData->m_frameBytes = m_size.area() * sizeof(ImageFrame::PixelData); return createImage(index, !frameData->m_hasAlpha); } if (!m_actualDecoder) return nullptr; ImageFrame* buffer = m_actualDecoder->frameBufferAtIndex(index); if (!buffer || buffer->status() == ImageFrame::FrameEmpty) return nullptr; return adoptRef(SkImage::NewFromBitmap(buffer->bitmap())); }
void DeferredImageDecoder::setDataInternal(PassRefPtr<SharedBuffer> passData, bool allDataReceived, bool pushDataToDecoder) { RefPtr<SharedBuffer> data = passData; if (m_actualDecoder) { m_allDataReceived = allDataReceived; if (pushDataToDecoder) m_actualDecoder->setData(data, allDataReceived); prepareLazyDecodedFrames(); } if (m_frameGenerator) { if (!m_rwBuffer) m_rwBuffer = wrapUnique(new SkRWBuffer(data->size())); const char* segment = 0; for (size_t length = data->getSomeData(segment, m_rwBuffer->size()); length; length = data->getSomeData(segment, m_rwBuffer->size())) { DCHECK_GE(data->size(), m_rwBuffer->size() + length); const size_t remaining = data->size() - m_rwBuffer->size() - length; m_rwBuffer->append(segment, length, remaining); } } }