blob: 0dca16b3f1bba7b2f5c3a3f0138f714b7875f064 [file] [log] [blame]
commit-bot@chromium.org56799e22013-07-16 18:21:46 +00001/*
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
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000010#include "SkData.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000011#include "SkDiscardableMemoryPool.h"
commit-bot@chromium.org2d970b52014-05-27 14:14:22 +000012#include "SkImageGeneratorPriv.h"
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000013#include "SkForceLinking.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000014
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000015#include "SkCommandLineFlags.h"
16
17__SK_FORCE_IMAGE_DECODER_LINKING;
18
19DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
20 "Only meaningful if --deferImageDecoding is set to true and the platform has an "
21 "implementation.");
22
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000023// Fits SkPicture::InstallPixelRefProc call signature.
robertphillipsdb539902014-07-01 08:47:04 -070024// Used in SkPictureData::CreateFromStream
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000025bool sk_tools::LazyDecodeBitmap(const void* src,
26 size_t length,
27 SkBitmap* dst) {
28 SkAutoDataUnref data(SkData::NewWithCopy(src, length));
29 if (NULL == data.get()) {
30 return false;
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000031 }
32
reed5965c8a2015-01-07 18:04:45 -080033 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(data));
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000034 SkImageInfo info;
halcanary@google.com3d50ea12014-01-02 13:15:13 +000035 if ((NULL == gen.get()) || !gen->getInfo(&info)) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000036 return false;
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000037 }
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000038 SkDiscardableMemory::Factory* pool = NULL;
reede5ea5002014-09-03 11:54:58 -070039 if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024)) {
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000040 // how to do switching with SkDiscardableMemory.
41 pool = SkGetGlobalDiscardableMemoryPool();
halcanary@google.combc55eec2013-12-10 18:33:07 +000042 // Only meaningful if platform has a default discardable
43 // memory implementation that differs from the global DM pool.
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000044 }
halcanary@google.comedd370f2013-12-10 21:11:12 +000045 return SkInstallDiscardablePixelRef(gen.detach(), dst, pool);
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000046}