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