| 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 "core/platform/graphics/LazyDecodingPixelRef.h" | |
| 28 | |
| 29 #include "SkData.h" | |
| 30 #include "core/platform/graphics/ImageDecodingStore.h" | |
| 31 #include "core/platform/graphics/ImageFrameGenerator.h" | |
| 32 #include "platform/TraceEvent.h" | |
| 33 | |
| 34 namespace WebCore { | |
| 35 | |
| 36 LazyDecodingPixelRef::LazyDecodingPixelRef(PassRefPtr<ImageFrameGenerator> frame
Generator, size_t index) | |
| 37 : m_frameGenerator(frameGenerator) | |
| 38 , m_frameIndex(index) | |
| 39 , m_lockedImageResource(0) | |
| 40 , m_objectTracker(this) | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 LazyDecodingPixelRef::~LazyDecodingPixelRef() | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 SkData* LazyDecodingPixelRef::onRefEncodedData() | |
| 49 { | |
| 50 // If the image has been clipped or scaled, do not return the original encod
ed data, since | |
| 51 // on playback it will not be known how the clipping/scaling was done. | |
| 52 RefPtr<SharedBuffer> buffer = 0; | |
| 53 bool allDataReceived = false; | |
| 54 m_frameGenerator->copyData(&buffer, &allDataReceived); | |
| 55 if (buffer && allDataReceived) { | |
| 56 SkData* skdata = SkData::NewWithCopy((void*)buffer->data(), buffer->size
()); | |
| 57 return skdata; | |
| 58 } | |
| 59 return 0; | |
| 60 } | |
| 61 | |
| 62 void* LazyDecodingPixelRef::onLockPixels(SkColorTable**) | |
| 63 { | |
| 64 TRACE_EVENT_ASYNC_BEGIN0("webkit", "LazyDecodingPixelRef::lockPixels", this)
; | |
| 65 | |
| 66 ASSERT(!m_lockedImageResource); | |
| 67 | |
| 68 SkISize size = m_frameGenerator->getFullSize(); | |
| 69 if (!ImageDecodingStore::instance()->lockCache(m_frameGenerator.get(), size,
m_frameIndex, &m_lockedImageResource)) | |
| 70 m_lockedImageResource = 0; | |
| 71 | |
| 72 // Use ImageFrameGenerator to generate the image. It will lock the cache | |
| 73 // entry for us. | |
| 74 if (!m_lockedImageResource) { | |
| 75 PlatformInstrumentation::willDecodeLazyPixelRef(reinterpret_cast<unsigne
d long long>(this)); | |
| 76 m_lockedImageResource = m_frameGenerator->decodeAndScale(size, m_frameIn
dex); | |
| 77 PlatformInstrumentation::didDecodeLazyPixelRef(reinterpret_cast<unsigned
long long>(this)); | |
| 78 } | |
| 79 if (!m_lockedImageResource) | |
| 80 return 0; | |
| 81 | |
| 82 ASSERT(!m_lockedImageResource->bitmap().isNull()); | |
| 83 ASSERT(m_lockedImageResource->scaledSize() == size); | |
| 84 return m_lockedImageResource->bitmap().getAddr(0, 0); | |
| 85 } | |
| 86 | |
| 87 void LazyDecodingPixelRef::onUnlockPixels() | |
| 88 { | |
| 89 if (m_lockedImageResource) { | |
| 90 ImageDecodingStore::instance()->unlockCache(m_frameGenerator.get(), m_lo
ckedImageResource); | |
| 91 m_lockedImageResource = 0; | |
| 92 } | |
| 93 | |
| 94 TRACE_EVENT_ASYNC_END0("webkit", "LazyDecodingPixelRef::lockPixels", this); | |
| 95 } | |
| 96 | |
| 97 bool LazyDecodingPixelRef::onLockPixelsAreWritable() const | |
| 98 { | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 bool LazyDecodingPixelRef::MaybeDecoded() | |
| 103 { | |
| 104 return ImageDecodingStore::instance()->isCached(m_frameGenerator.get(), m_fr
ameGenerator->getFullSize(), m_frameIndex); | |
| 105 } | |
| 106 | |
| 107 bool LazyDecodingPixelRef::PrepareToDecode(const LazyPixelRef::PrepareParams& pa
rams) | |
| 108 { | |
| 109 ASSERT(false); | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 void LazyDecodingPixelRef::Decode() | |
| 114 { | |
| 115 lockPixels(); | |
| 116 unlockPixels(); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 } // namespace blink | |
| OLD | NEW |