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 "SkDiscardableMemoryPool.h" | 11 #include "SkDiscardableMemoryPool.h" |
12 #include "SkImageGeneratorPriv.h" | 12 #include "SkImageGeneratorPriv.h" |
13 #include "SkForceLinking.h" | 13 #include "SkForceLinking.h" |
14 | 14 |
15 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
16 | 16 |
17 __SK_FORCE_IMAGE_DECODER_LINKING; | 17 __SK_FORCE_IMAGE_DECODER_LINKING; |
18 | 18 |
19 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de
coding pixels. " | 19 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de
coding pixels. " |
20 "Only meaningful if --deferImageDecoding is set to true and the plat
form has an " | 20 "Only meaningful if --deferImageDecoding is set to true and the plat
form has an " |
21 "implementation."); | 21 "implementation."); |
22 | 22 |
23 // Fits SkPicture::InstallPixelRefProc call signature. | 23 // Fits SkPicture::InstallPixelRefProc call signature. |
24 // Used in SkPictureData::CreateFromStream | 24 // Used in SkPictureData::CreateFromStream |
25 bool sk_tools::LazyDecodeBitmap(const void* src, | 25 bool sk_tools::LazyDecodeBitmap(const void* src, size_t length, SkBitmap* dst) { |
26 size_t length, | |
27 SkBitmap* dst) { | |
28 SkAutoDataUnref data(SkData::NewWithCopy(src, length)); | 26 SkAutoDataUnref data(SkData::NewWithCopy(src, length)); |
29 if (NULL == data.get()) { | 27 if (NULL == data.get()) { |
30 return false; | 28 return false; |
31 } | 29 } |
32 | 30 |
33 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(data)); | 31 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(data)); |
34 SkImageInfo info; | 32 if (NULL == gen.get()) { |
35 if ((NULL == gen.get()) || !gen->getInfo(&info)) { | |
36 return false; | 33 return false; |
37 } | 34 } |
| 35 const SkImageInfo info = gen->getInfo(); |
38 SkDiscardableMemory::Factory* pool = NULL; | 36 SkDiscardableMemory::Factory* pool = NULL; |
39 if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024))
{ | 37 if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024))
{ |
40 // how to do switching with SkDiscardableMemory. | 38 // how to do switching with SkDiscardableMemory. |
41 pool = SkGetGlobalDiscardableMemoryPool(); | 39 pool = SkGetGlobalDiscardableMemoryPool(); |
42 // Only meaningful if platform has a default discardable | 40 // Only meaningful if platform has a default discardable |
43 // memory implementation that differs from the global DM pool. | 41 // memory implementation that differs from the global DM pool. |
44 } | 42 } |
45 return SkInstallDiscardablePixelRef(gen.detach(), dst, pool); | 43 return SkInstallDiscardablePixelRef(gen.detach(), dst, pool); |
46 } | 44 } |
OLD | NEW |