1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "platform/graphics/DecodingImageGenerator.h" 28 29 #include "SkData.h" 30 #include "SkImageInfo.h" 31 #include "platform/PlatformInstrumentation.h" 32 #include "platform/SharedBuffer.h" 33 #include "platform/TraceEvent.h" 34 #include "platform/graphics/ImageFrameGenerator.h" 35 36 namespace WebCore { 37 38 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> frameGenerator, const SkImageInfo& info, size_t index) 39 : m_frameGenerator(frameGenerator) 40 , m_imageInfo(info) 41 , m_frameIndex(index) 42 , m_generationId(0) 43 { 44 } 45 46 DecodingImageGenerator::~DecodingImageGenerator() 47 { 48 } 49 50 SkData* DecodingImageGenerator::onRefEncodedData() 51 { 52 // FIXME: If the image has been clipped or scaled, do not return the original 53 // encoded data, since on playback it will not be known how the clipping/scaling 54 // was done. 55 RefPtr<SharedBuffer> buffer = nullptr; 56 bool allDataReceived = false; 57 m_frameGenerator->copyData(&buffer, &allDataReceived); 58 if (buffer && allDataReceived) 59 return SkData::NewWithCopy(buffer->data(), buffer->size()); 60 return 0; 61 } 62 63 bool DecodingImageGenerator::onGetInfo(SkImageInfo* info) 64 { 65 *info = m_imageInfo; 66 return true; 67 } 68 69 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) 70 { 71 TRACE_EVENT1("webkit", "DecodingImageGenerator::getPixels", "index", static_cast<int>(m_frameIndex)); 72 73 // Implementation doesn't support scaling yet so make sure we're not given 74 // a different size. 75 ASSERT(info.fWidth == m_imageInfo.fWidth); 76 ASSERT(info.fHeight == m_imageInfo.fHeight); 77 ASSERT(info.fColorType == m_imageInfo.fColorType); 78 ASSERT(info.fAlphaType == m_imageInfo.fAlphaType); 79 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); 80 bool decoded = m_frameGenerator->decodeAndScale(m_imageInfo, m_frameIndex, pixels, rowBytes); 81 PlatformInstrumentation::didDecodeLazyPixelRef(); 82 return decoded; 83 } 84 85 } // namespace blink 86