OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "LazyDecodeBitmap.h" | 8 #include "LazyDecodeBitmap.h" |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkDecodingImageGenerator.h" | 11 #include "SkDecodingImageGenerator.h" |
12 #include "SkDiscardableMemoryPool.h" | 12 #include "SkDiscardableMemoryPool.h" |
13 #include "SkDiscardablePixelRef.h" | 13 #include "SkDiscardablePixelRef.h" |
14 #include "SkForceLinking.h" | 14 #include "SkForceLinking.h" |
15 | 15 |
16 #include "SkCommandLineFlags.h" | 16 #include "SkCommandLineFlags.h" |
17 | 17 |
18 __SK_FORCE_IMAGE_DECODER_LINKING; | 18 __SK_FORCE_IMAGE_DECODER_LINKING; |
19 | 19 |
20 // TODO(halcanary) Use this flag when ashmem-backed discardable memory lands. | |
21 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de
coding pixels. " | 20 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de
coding pixels. " |
22 "Only meaningful if --deferImageDecoding is set to true and the plat
form has an " | 21 "Only meaningful if --deferImageDecoding is set to true and the plat
form has an " |
23 "implementation."); | 22 "implementation."); |
24 | 23 |
25 // Fits SkPicture::InstallPixelRefProc call signature. | 24 // Fits SkPicture::InstallPixelRefProc call signature. |
26 // Used in SkPicturePlayback::CreateFromStream | 25 // Used in SkPicturePlayback::CreateFromStream |
27 bool sk_tools::LazyDecodeBitmap(const void* src, | 26 bool sk_tools::LazyDecodeBitmap(const void* src, |
28 size_t length, | 27 size_t length, |
29 SkBitmap* dst) { | 28 SkBitmap* dst) { |
30 SkAutoDataUnref data(SkData::NewWithCopy(src, length)); | 29 SkAutoDataUnref data(SkData::NewWithCopy(src, length)); |
31 if (NULL == data.get()) { | 30 if (NULL == data.get()) { |
32 return false; | 31 return false; |
33 } | 32 } |
34 | 33 |
35 SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(SkDecodingImageGenerator, | 34 SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(SkDecodingImageGenerator, |
36 (data))); | 35 (data))); |
37 SkImageInfo info; | 36 SkImageInfo info; |
38 if (!gen->getInfo(&info)) { | 37 if (!gen->getInfo(&info)) { |
39 return false; | 38 return false; |
40 } | 39 } |
41 SkDiscardableMemory::Factory* pool = NULL; | 40 SkDiscardableMemory::Factory* pool = NULL; |
42 if (info.fWidth * info.fHeight > 32 * 1024) { | 41 if ((!FLAGS_useVolatileCache) || (info.fWidth * info.fHeight < 32 * 1024)) { |
43 // how to do switching with SkDiscardableMemory. | 42 // how to do switching with SkDiscardableMemory. |
44 pool = SkGetGlobalDiscardableMemoryPool(); | 43 pool = SkGetGlobalDiscardableMemoryPool(); |
| 44 // Only meaningful if platform has a default discardable |
| 45 // memory implementation that differs from the global DM pool. |
45 } | 46 } |
46 return SkDiscardablePixelRef::Install(gen.detach(), dst, pool); | 47 return SkDiscardablePixelRef::Install(gen.detach(), dst, pool); |
47 } | 48 } |
OLD | NEW |