Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1307)

Side by Side Diff: Source/platform/graphics/DeferredImageDecoder.cpp

Issue 105003005: Revert of Teach Skia to use discardable memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF 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 "platform/graphics/DeferredImageDecoder.h" 27 #include "platform/graphics/DeferredImageDecoder.h"
28 28
29 #include "platform/graphics/DecodingImageGenerator.h"
30 #include "platform/graphics/LazyDecodingPixelRef.h" 29 #include "platform/graphics/LazyDecodingPixelRef.h"
31 #include "third_party/skia/include/core/SkImageInfo.h" 30
32 #include "wtf/PassOwnPtr.h" 31 #include "wtf/PassOwnPtr.h"
33 32
34 namespace WebCore { 33 namespace WebCore {
35 34
36 namespace { 35 namespace {
37 36
38 // URI label for a lazily decoded SkPixelRef. 37 // URI label for a lazily decoded SkPixelRef.
39 const char labelLazyDecoded[] = "lazy"; 38 const char labelLazyDecoded[] = "lazy";
40 39
41 // URI label for SkDiscardablePixelRef.
42 const char labelDiscardable[] = "discardable";
43
44 } // namespace 40 } // namespace
45 41
46 bool DeferredImageDecoder::s_enabled = false; 42 bool DeferredImageDecoder::s_enabled = false;
47 bool DeferredImageDecoder::s_skiaDiscardableMemoryEnabled = false;
48 43
49 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r) 44 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r)
50 : m_allDataReceived(false) 45 : m_allDataReceived(false)
51 , m_actualDecoder(actualDecoder) 46 , m_actualDecoder(actualDecoder)
52 , m_orientation(DefaultImageOrientation) 47 , m_orientation(DefaultImageOrientation)
53 , m_repetitionCount(cAnimationNone) 48 , m_repetitionCount(cAnimationNone)
54 { 49 {
55 } 50 }
56 51
57 DeferredImageDecoder::~DeferredImageDecoder() 52 DeferredImageDecoder::~DeferredImageDecoder()
58 { 53 {
59 } 54 }
60 55
61 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileO ption gammaAndColorOption) 56 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileO ption gammaAndColorOption)
62 { 57 {
63 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, gammaAndColorOption); 58 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, gammaAndColorOption);
64 return actualDecoder ? adoptPtr(new DeferredImageDecoder(actualDecoder.relea se())) : nullptr; 59 return actualDecoder ? adoptPtr(new DeferredImageDecoder(actualDecoder.relea se())) : nullptr;
65 } 60 }
66 61
67 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> decoder) 62 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> decoder)
68 { 63 {
69 return adoptPtr(new DeferredImageDecoder(decoder)); 64 return adoptPtr(new DeferredImageDecoder(decoder));
70 } 65 }
71 66
72 bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap) 67 bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap)
73 { 68 {
74 return bitmap.pixelRef() 69 return bitmap.pixelRef()
75 && bitmap.pixelRef()->getURI() 70 && bitmap.pixelRef()->getURI()
76 && (!memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelL azyDecoded)) 71 && !memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelLa zyDecoded));
77 || !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(lab elDiscardable)));
78 } 72 }
79 73
80 void DeferredImageDecoder::setEnabled(bool enabled) 74 void DeferredImageDecoder::setEnabled(bool enabled)
81 { 75 {
82 s_enabled = enabled; 76 s_enabled = enabled;
83 } 77 }
84 78
85 void DeferredImageDecoder::setSkiaDiscardableMemoryEnabled(bool enabled)
86 {
87 s_skiaDiscardableMemoryEnabled = enabled;
88 }
89
90 String DeferredImageDecoder::filenameExtension() const 79 String DeferredImageDecoder::filenameExtension() const
91 { 80 {
92 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension; 81 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension;
93 } 82 }
94 83
95 ImageFrame* DeferredImageDecoder::frameBufferAtIndex(size_t index) 84 ImageFrame* DeferredImageDecoder::frameBufferAtIndex(size_t index)
96 { 85 {
97 prepareLazyDecodedFrames(); 86 prepareLazyDecodedFrames();
98 if (index < m_lazyDecodedFrames.size()) { 87 if (index < m_lazyDecodedFrames.size()) {
99 // ImageFrameGenerator has the latest known alpha state. There will 88 // ImageFrameGenerator has the latest known alpha state. There will
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 || !m_actualDecoder->isSizeAvailable() 201 || !m_actualDecoder->isSizeAvailable()
213 || m_actualDecoder->filenameExtension() == "ico") 202 || m_actualDecoder->filenameExtension() == "ico")
214 return; 203 return;
215 204
216 activateLazyDecoding(); 205 activateLazyDecoding();
217 206
218 const size_t previousSize = m_lazyDecodedFrames.size(); 207 const size_t previousSize = m_lazyDecodedFrames.size();
219 m_lazyDecodedFrames.resize(m_actualDecoder->frameCount()); 208 m_lazyDecodedFrames.resize(m_actualDecoder->frameCount());
220 for (size_t i = previousSize; i < m_lazyDecodedFrames.size(); ++i) { 209 for (size_t i = previousSize; i < m_lazyDecodedFrames.size(); ++i) {
221 OwnPtr<ImageFrame> frame(adoptPtr(new ImageFrame())); 210 OwnPtr<ImageFrame> frame(adoptPtr(new ImageFrame()));
222 frame->setSkBitmap(createBitmap(i)); 211 frame->setSkBitmap(createLazyDecodingBitmap(i));
223 frame->setDuration(m_actualDecoder->frameDurationAtIndex(i)); 212 frame->setDuration(m_actualDecoder->frameDurationAtIndex(i));
224 frame->setStatus(m_actualDecoder->frameIsCompleteAtIndex(i) ? ImageFrame ::FrameComplete : ImageFrame::FramePartial); 213 frame->setStatus(m_actualDecoder->frameIsCompleteAtIndex(i) ? ImageFrame ::FrameComplete : ImageFrame::FramePartial);
225 m_lazyDecodedFrames[i] = frame.release(); 214 m_lazyDecodedFrames[i] = frame.release();
226 } 215 }
227 216
228 // The last lazy decoded frame created from previous call might be 217 // The last lazy decoded frame created from previous call might be
229 // incomplete so update its state. 218 // incomplete so update its state.
230 if (previousSize) 219 if (previousSize)
231 m_lazyDecodedFrames[previousSize - 1]->setStatus(m_actualDecoder->frameI sCompleteAtIndex(previousSize - 1) ? ImageFrame::FrameComplete : ImageFrame::Fra mePartial); 220 m_lazyDecodedFrames[previousSize - 1]->setStatus(m_actualDecoder->frameI sCompleteAtIndex(previousSize - 1) ? ImageFrame::FrameComplete : ImageFrame::Fra mePartial);
232 221
233 if (m_allDataReceived) { 222 if (m_allDataReceived) {
234 m_repetitionCount = m_actualDecoder->repetitionCount(); 223 m_repetitionCount = m_actualDecoder->repetitionCount();
235 m_actualDecoder.clear(); 224 m_actualDecoder.clear();
236 m_data = nullptr; 225 m_data = nullptr;
237 } 226 }
238 } 227 }
239 228
240 // Creates either a SkBitmap backed by SkDiscardablePixelRef or a SkBitmap using the
241 // legacy LazyDecodingPixelRef.
242 SkBitmap DeferredImageDecoder::createBitmap(size_t index)
243 {
244 // This code is temporary until the transition to SkDiscardablePixelRef is c omplete.
245 if (s_skiaDiscardableMemoryEnabled)
246 return createSkiaDiscardableBitmap(index);
247 return createLazyDecodingBitmap(index);
248 }
249
250 // Creates a SkBitmap that is backed by SkDiscardablePixelRef.
251 SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index)
252 {
253 IntSize decodedSize = m_actualDecoder->decodedSize();
254 ASSERT(decodedSize.width() > 0);
255 ASSERT(decodedSize.height() > 0);
256
257 SkImageInfo info;
258 info.fWidth = decodedSize.width();
259 info.fHeight = decodedSize.height();
260 info.fColorType = kBGRA_8888_SkColorType;
261 info.fAlphaType = frameHasAlphaAtIndex(index) ? kPremul_SkAlphaType : kOpaqu e_SkAlphaType;
262
263 SkBitmap bitmap;
264 bool installed = SkInstallDiscardablePixelRef(new DecodingImageGenerator(m_f rameGenerator, info, index), &bitmap);
265 ASSERT_UNUSED(installed, installed);
266 bitmap.pixelRef()->setURI(labelDiscardable);
267 return bitmap;
268 }
269
270 SkBitmap DeferredImageDecoder::createLazyDecodingBitmap(size_t index) 229 SkBitmap DeferredImageDecoder::createLazyDecodingBitmap(size_t index)
271 { 230 {
272 IntSize decodedSize = m_actualDecoder->decodedSize(); 231 IntSize decodedSize = m_actualDecoder->decodedSize();
273 ASSERT(decodedSize.width() > 0); 232 ASSERT(decodedSize.width() > 0);
274 ASSERT(decodedSize.height() > 0); 233 ASSERT(decodedSize.height() > 0);
275 234
276 SkImageInfo info; 235 SkImageInfo info;
277 info.fWidth = decodedSize.width(); 236 info.fWidth = decodedSize.width();
278 info.fHeight = decodedSize.height(); 237 info.fHeight = decodedSize.height();
279 info.fColorType = kPMColor_SkColorType; 238 info.fColorType = kPMColor_SkColorType;
(...skipping 15 matching lines...) Expand all
295 return bitmap; 254 return bitmap;
296 } 255 }
297 256
298 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const 257 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const
299 { 258 {
300 // TODO: Implement. 259 // TODO: Implement.
301 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; 260 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false;
302 } 261 }
303 262
304 } // namespace WebCore 263 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.h ('k') | Source/platform/graphics/ImageFrameGenerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698