| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/platform/graphics/chromium/LazyDecodingPixelRef.h" | 27 #include "core/platform/graphics/chromium/LazyDecodingPixelRef.h" |
| 28 | 28 |
| 29 #include "SkData.h" | 29 #include "SkData.h" |
| 30 #include "core/platform/chromium/TraceEvent.h" | 30 #include "core/platform/chromium/TraceEvent.h" |
| 31 #include "core/platform/graphics/chromium/ImageDecodingStore.h" | 31 #include "core/platform/graphics/chromium/ImageDecodingStore.h" |
| 32 #include "core/platform/graphics/chromium/ImageFrameGenerator.h" | 32 #include "core/platform/graphics/chromium/ImageFrameGenerator.h" |
| 33 #include <wtf/MainThread.h> | |
| 34 | 33 |
| 35 namespace WebCore { | 34 namespace WebCore { |
| 36 | 35 |
| 37 LazyDecodingPixelRef::LazyDecodingPixelRef(PassRefPtr<ImageFrameGenerator> frame
Generator, const SkISize& scaledSize, const SkIRect& scaledSubset) | 36 LazyDecodingPixelRef::LazyDecodingPixelRef(PassRefPtr<ImageFrameGenerator> frame
Generator, const SkISize& scaledSize, size_t index, const SkIRect& scaledSubset) |
| 38 : m_frameGenerator(frameGenerator) | 37 : m_frameGenerator(frameGenerator) |
| 38 , m_frameIndex(index) |
| 39 , m_scaledSize(scaledSize) | 39 , m_scaledSize(scaledSize) |
| 40 , m_scaledSubset(scaledSubset) | 40 , m_scaledSubset(scaledSubset) |
| 41 , m_lockedCachedImage(0) | 41 , m_lockedCachedImage(0) |
| 42 { | 42 { |
| 43 } | 43 } |
| 44 | 44 |
| 45 LazyDecodingPixelRef::~LazyDecodingPixelRef() | 45 LazyDecodingPixelRef::~LazyDecodingPixelRef() |
| 46 { | 46 { |
| 47 } | 47 } |
| 48 | 48 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 SkData* skdata = SkData::NewWithCopy((void*)buffer->data(), buffer->size
()); | 69 SkData* skdata = SkData::NewWithCopy((void*)buffer->data(), buffer->size
()); |
| 70 return skdata; | 70 return skdata; |
| 71 } | 71 } |
| 72 return 0; | 72 return 0; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void* LazyDecodingPixelRef::onLockPixels(SkColorTable**) | 75 void* LazyDecodingPixelRef::onLockPixels(SkColorTable**) |
| 76 { | 76 { |
| 77 TRACE_EVENT_ASYNC_BEGIN0("webkit", "LazyDecodingPixelRef::lockPixels", this)
; | 77 TRACE_EVENT_ASYNC_BEGIN0("webkit", "LazyDecodingPixelRef::lockPixels", this)
; |
| 78 | 78 |
| 79 m_mutex.lock(); | |
| 80 ASSERT(!m_lockedCachedImage); | 79 ASSERT(!m_lockedCachedImage); |
| 81 | 80 |
| 82 if (!ImageDecodingStore::instance()->lockCache(m_frameGenerator.get(), m_sca
ledSize, 0, &m_lockedCachedImage)) | 81 if (!ImageDecodingStore::instance()->lockCache(m_frameGenerator.get(), m_sca
ledSize, m_frameIndex, &m_lockedCachedImage)) |
| 83 m_lockedCachedImage = 0; | 82 m_lockedCachedImage = 0; |
| 84 | 83 |
| 85 // Use ImageFrameGenerator to generate the image. It will lock the cache | 84 // Use ImageFrameGenerator to generate the image. It will lock the cache |
| 86 // entry for us. | 85 // entry for us. |
| 87 if (!m_lockedCachedImage) | 86 if (!m_lockedCachedImage) |
| 88 m_lockedCachedImage = m_frameGenerator->decodeAndScale(m_scaledSize); | 87 m_lockedCachedImage = m_frameGenerator->decodeAndScale(m_scaledSize, m_f
rameIndex); |
| 89 | 88 |
| 90 if (!m_lockedCachedImage) | 89 if (!m_lockedCachedImage) |
| 91 return 0; | 90 return 0; |
| 92 | 91 |
| 93 ASSERT(!m_lockedCachedImage->bitmap().isNull()); | 92 ASSERT(!m_lockedCachedImage->bitmap().isNull()); |
| 94 ASSERT(m_lockedCachedImage->scaledSize() == m_scaledSize); | 93 ASSERT(m_lockedCachedImage->scaledSize() == m_scaledSize); |
| 95 return m_lockedCachedImage->bitmap().getAddr(m_scaledSubset.x(), m_scaledSub
set.y()); | 94 return m_lockedCachedImage->bitmap().getAddr(m_scaledSubset.x(), m_scaledSub
set.y()); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void LazyDecodingPixelRef::onUnlockPixels() | 97 void LazyDecodingPixelRef::onUnlockPixels() |
| 99 { | 98 { |
| 100 if (m_lockedCachedImage) { | 99 if (m_lockedCachedImage) { |
| 101 ImageDecodingStore::instance()->unlockCache(m_frameGenerator.get(), m_lo
ckedCachedImage); | 100 ImageDecodingStore::instance()->unlockCache(m_frameGenerator.get(), m_lo
ckedCachedImage); |
| 102 m_lockedCachedImage = 0; | 101 m_lockedCachedImage = 0; |
| 103 } | 102 } |
| 104 m_mutex.unlock(); | |
| 105 | 103 |
| 106 TRACE_EVENT_ASYNC_END0("webkit", "LazyDecodingPixelRef::lockPixels", this); | 104 TRACE_EVENT_ASYNC_END0("webkit", "LazyDecodingPixelRef::lockPixels", this); |
| 107 } | 105 } |
| 108 | 106 |
| 109 bool LazyDecodingPixelRef::onLockPixelsAreWritable() const | 107 bool LazyDecodingPixelRef::onLockPixelsAreWritable() const |
| 110 { | 108 { |
| 111 return false; | 109 return false; |
| 112 } | 110 } |
| 113 | 111 |
| 114 bool LazyDecodingPixelRef::MaybeDecoded() | 112 bool LazyDecodingPixelRef::MaybeDecoded() |
| 115 { | 113 { |
| 116 return ImageDecodingStore::instance()->isCached(m_frameGenerator.get(), m_sc
aledSize, 0); | 114 return ImageDecodingStore::instance()->isCached(m_frameGenerator.get(), m_sc
aledSize, m_frameIndex); |
| 117 } | 115 } |
| 118 | 116 |
| 119 bool LazyDecodingPixelRef::PrepareToDecode(const LazyPixelRef::PrepareParams& pa
rams) | 117 bool LazyDecodingPixelRef::PrepareToDecode(const LazyPixelRef::PrepareParams& pa
rams) |
| 120 { | 118 { |
| 121 // TODO: check if only a particular rect is available in image cache. | 119 ASSERT(false); |
| 122 UNUSED_PARAM(params); | 120 return false; |
| 123 const ScaledImageFragment* cachedImage = 0; | |
| 124 bool cached = ImageDecodingStore::instance()->lockCache(m_frameGenerator.get
(), m_scaledSize, 0, &cachedImage); | |
| 125 if (cached) | |
| 126 ImageDecodingStore::instance()->unlockCache(m_frameGenerator.get(), cach
edImage); | |
| 127 return cached; | |
| 128 } | 121 } |
| 129 | 122 |
| 130 void LazyDecodingPixelRef::Decode() | 123 void LazyDecodingPixelRef::Decode() |
| 131 { | 124 { |
| 132 lockPixels(); | 125 lockPixels(); |
| 133 unlockPixels(); | 126 unlockPixels(); |
| 134 } | 127 } |
| 135 | 128 |
| 136 | 129 |
| 137 } // namespace WebKit | 130 } // namespace WebKit |
| OLD | NEW |