OLD | NEW |
(Empty) | |
| 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/SharedBuffer.h" |
| 32 #include "platform/TraceEvent.h" |
| 33 #include "platform/graphics/ImageFrameGenerator.h" |
| 34 |
| 35 namespace WebCore { |
| 36 |
| 37 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
rameGenerator, const SkImageInfo& info, size_t index) |
| 38 : m_frameGenerator(frameGenerator) |
| 39 , m_imageInfo(info) |
| 40 , m_frameIndex(index) |
| 41 { |
| 42 } |
| 43 |
| 44 DecodingImageGenerator::~DecodingImageGenerator() |
| 45 { |
| 46 } |
| 47 |
| 48 SkData* DecodingImageGenerator::refEncodedData() |
| 49 { |
| 50 // FIXME: If the image has been clipped or scaled, do not return the origina
l |
| 51 // encoded data, since on playback it will not be known how the clipping/sca
ling |
| 52 // was done. |
| 53 RefPtr<SharedBuffer> buffer = 0; |
| 54 bool allDataReceived = false; |
| 55 m_frameGenerator->copyData(&buffer, &allDataReceived); |
| 56 if (buffer && allDataReceived) { |
| 57 return SkData::NewWithCopy(buffer->data(), buffer->size()); |
| 58 } |
| 59 return 0; |
| 60 } |
| 61 |
| 62 bool DecodingImageGenerator::getInfo(SkImageInfo* info) |
| 63 { |
| 64 *info = m_imageInfo; |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool DecodingImageGenerator::getPixels(const SkImageInfo& info, void* pixels, si
ze_t rowBytes) |
| 69 { |
| 70 TRACE_EVENT1("webkit", "DecodingImageGenerator::getPixels", "index", static_
cast<int>(m_frameIndex)); |
| 71 |
| 72 // Implementation doesn't support scaling yet so make sure we're not given |
| 73 // a different size. |
| 74 ASSERT(info.fWidth == m_imageInfo.fWidth); |
| 75 ASSERT(info.fHeight == m_imageInfo.fHeight); |
| 76 ASSERT(info.fColorType == m_imageInfo.fColorType); |
| 77 ASSERT(info.fAlphaType == m_imageInfo.fAlphaType); |
| 78 return m_frameGenerator->decodeAndScale(m_imageInfo, m_frameIndex, pixels, r
owBytes); |
| 79 } |
| 80 |
| 81 } // namespace blink |
OLD | NEW |