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