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

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

Issue 303033004: Enable Skia discardable memory path on Android (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months 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
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 18 matching lines...) Expand all
29 #include "platform/graphics/DecodingImageGenerator.h" 29 #include "platform/graphics/DecodingImageGenerator.h"
30 #include "platform/graphics/ImageDecodingStore.h" 30 #include "platform/graphics/ImageDecodingStore.h"
31 #include "platform/graphics/LazyDecodingPixelRef.h" 31 #include "platform/graphics/LazyDecodingPixelRef.h"
32 #include "third_party/skia/include/core/SkImageInfo.h" 32 #include "third_party/skia/include/core/SkImageInfo.h"
33 #include "wtf/PassOwnPtr.h" 33 #include "wtf/PassOwnPtr.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 namespace { 37 namespace {
38 38
39 // URI label for a lazily decoded SkPixelRef.
40 const char labelLazyDecoded[] = "lazy";
41
42 // URI label for SkDiscardablePixelRef. 39 // URI label for SkDiscardablePixelRef.
43 const char labelDiscardable[] = "discardable"; 40 const char labelDiscardable[] = "discardable";
44 41
45 } // namespace 42 } // namespace
46 43
47 bool DeferredImageDecoder::s_enabled = false; 44 bool DeferredImageDecoder::s_enabled = false;
48 bool DeferredImageDecoder::s_skiaDiscardableMemoryEnabled = false;
49 45
50 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r) 46 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r)
51 : m_allDataReceived(false) 47 : m_allDataReceived(false)
52 , m_lastDataSize(0) 48 , m_lastDataSize(0)
53 , m_dataChanged(false) 49 , m_dataChanged(false)
54 , m_actualDecoder(actualDecoder) 50 , m_actualDecoder(actualDecoder)
55 , m_orientation(DefaultImageOrientation) 51 , m_orientation(DefaultImageOrientation)
56 , m_repetitionCount(cAnimationNone) 52 , m_repetitionCount(cAnimationNone)
57 , m_hasColorProfile(false) 53 , m_hasColorProfile(false)
58 { 54 {
(...skipping 11 matching lines...) Expand all
70 66
71 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> decoder) 67 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> decoder)
72 { 68 {
73 return adoptPtr(new DeferredImageDecoder(decoder)); 69 return adoptPtr(new DeferredImageDecoder(decoder));
74 } 70 }
75 71
76 bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap) 72 bool DeferredImageDecoder::isLazyDecoded(const SkBitmap& bitmap)
77 { 73 {
78 return bitmap.pixelRef() 74 return bitmap.pixelRef()
79 && bitmap.pixelRef()->getURI() 75 && bitmap.pixelRef()->getURI()
80 && (!memcmp(bitmap.pixelRef()->getURI(), labelLazyDecoded, sizeof(labelL azyDecoded)) 76 && !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(labelDi scardable));
81 || !memcmp(bitmap.pixelRef()->getURI(), labelDiscardable, sizeof(lab elDiscardable)));
82 } 77 }
83 78
84 void DeferredImageDecoder::setEnabled(bool enabled) 79 void DeferredImageDecoder::setEnabled(bool enabled)
85 { 80 {
86 s_enabled = enabled; 81 s_enabled = enabled;
87 #if !OS(ANDROID)
88 // FIXME: This code is temporary to enable discardable memory for
89 // non-Android platforms. In the future all platforms will be
90 // the same and we can remove this code.
91 s_skiaDiscardableMemoryEnabled = enabled;
92 if (enabled) 82 if (enabled)
93 ImageDecodingStore::setImageCachingEnabled(false); 83 ImageDecodingStore::setImageCachingEnabled(false);
94 #endif
95 } 84 }
96 85
97 bool DeferredImageDecoder::enabled() 86 bool DeferredImageDecoder::enabled()
98 { 87 {
99 return s_enabled; 88 return s_enabled;
100 } 89 }
101 90
102 String DeferredImageDecoder::filenameExtension() const 91 String DeferredImageDecoder::filenameExtension() const
103 { 92 {
104 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension; 93 return m_actualDecoder ? m_actualDecoder->filenameExtension() : m_filenameEx tension;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 255 }
267 } 256 }
268 257
269 if (m_allDataReceived) { 258 if (m_allDataReceived) {
270 m_repetitionCount = m_actualDecoder->repetitionCount(); 259 m_repetitionCount = m_actualDecoder->repetitionCount();
271 m_actualDecoder.clear(); 260 m_actualDecoder.clear();
272 m_data = nullptr; 261 m_data = nullptr;
273 } 262 }
274 } 263 }
275 264
276 // Creates either a SkBitmap backed by SkDiscardablePixelRef or a SkBitmap using the 265 // Creates a SkBitmap that is backed by SkDiscardablePixelRef.
277 // legacy LazyDecodingPixelRef.
Stephen White 2014/05/29 20:07:44 Out of curiosity, does this mean we can also remov
278 SkBitmap DeferredImageDecoder::createBitmap(size_t index) 266 SkBitmap DeferredImageDecoder::createBitmap(size_t index)
279 { 267 {
280 // This code is temporary until the transition to SkDiscardablePixelRef is c omplete.
281 if (s_skiaDiscardableMemoryEnabled)
282 return createSkiaDiscardableBitmap(index);
283 return createLazyDecodingBitmap(index);
284 }
285
286 // Creates a SkBitmap that is backed by SkDiscardablePixelRef.
287 SkBitmap DeferredImageDecoder::createSkiaDiscardableBitmap(size_t index)
288 {
289 IntSize decodedSize = m_actualDecoder->decodedSize(); 268 IntSize decodedSize = m_actualDecoder->decodedSize();
290 ASSERT(decodedSize.width() > 0); 269 ASSERT(decodedSize.width() > 0);
291 ASSERT(decodedSize.height() > 0); 270 ASSERT(decodedSize.height() > 0);
292 271
293 SkImageInfo info; 272 SkImageInfo info;
294 info.fWidth = decodedSize.width(); 273 info.fWidth = decodedSize.width();
295 info.fHeight = decodedSize.height(); 274 info.fHeight = decodedSize.height();
275 #if SK_B32_SHIFT // Little-endian RGBA pixels. (Android)
reveman 2014/05/29 03:30:55 I assume this is the reason my previous patch fail
276 info.fColorType = kRGBA_8888_SkColorType;
277 #else
296 info.fColorType = kBGRA_8888_SkColorType; 278 info.fColorType = kBGRA_8888_SkColorType;
279 #endif
297 info.fAlphaType = kPremul_SkAlphaType; 280 info.fAlphaType = kPremul_SkAlphaType;
298 281
299 SkBitmap bitmap; 282 SkBitmap bitmap;
300 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, info, index); 283 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, info, index);
301 bool installed = SkInstallDiscardablePixelRef(generator, &bitmap); 284 bool installed = SkInstallDiscardablePixelRef(generator, &bitmap);
302 ASSERT_UNUSED(installed, installed); 285 ASSERT_UNUSED(installed, installed);
303 bitmap.pixelRef()->setURI(labelDiscardable); 286 bitmap.pixelRef()->setURI(labelDiscardable);
304 generator->setGenerationId(bitmap.getGenerationID()); 287 generator->setGenerationId(bitmap.getGenerationID());
305 return bitmap; 288 return bitmap;
306 } 289 }
307 290
308 SkBitmap DeferredImageDecoder::createLazyDecodingBitmap(size_t index)
309 {
310 IntSize decodedSize = m_actualDecoder->decodedSize();
311 ASSERT(decodedSize.width() > 0);
312 ASSERT(decodedSize.height() > 0);
313
314 SkImageInfo info;
315 info.fWidth = decodedSize.width();
316 info.fHeight = decodedSize.height();
317 info.fColorType = kPMColor_SkColorType;
318 info.fAlphaType = kPremul_SkAlphaType;
319
320 // Creates a lazily decoded SkPixelRef that references the entire image with out scaling.
321 SkBitmap bitmap;
322 bitmap.setConfig(info);
323 bitmap.setPixelRef(new LazyDecodingPixelRef(info, m_frameGenerator, index))- >unref();
324
325 // Use the URI to identify this as a lazily decoded SkPixelRef of type LazyD ecodingPixelRef.
326 // FIXME: It would be more useful to give the actual image URI.
327 bitmap.pixelRef()->setURI(labelLazyDecoded);
328
329 // Inform the bitmap that we will never change the pixels. This is a perform ance hint
330 // subsystems that may try to cache this bitmap (e.g. pictures, pipes, gpu, pdf, etc.)
331 bitmap.setImmutable();
332
333 return bitmap;
334 }
335
336 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const 291 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const
337 { 292 {
338 // TODO: Implement. 293 // TODO: Implement.
339 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; 294 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false;
340 } 295 }
341 296
342 } // namespace WebCore 297 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698