blob: 9e850e5753b6b26f6b67396abd480be8dba32e63 [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 "SkDecodingImageGenerator.h"
12#include "SkDiscardableMemoryPool.h"
13#include "SkDiscardablePixelRef.h"
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000014#include "SkForceLinking.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000015
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000016#include "SkCommandLineFlags.h"
17
18__SK_FORCE_IMAGE_DECODER_LINKING;
19
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000020// TODO(halcanary) Use this flag when ashmem-backed discardable memory lands.
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000021DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
22 "Only meaningful if --deferImageDecoding is set to true and the platform has an "
23 "implementation.");
24
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000025// Fits SkPicture::InstallPixelRefProc call signature.
26// Used in SkPicturePlayback::CreateFromStream
27bool sk_tools::LazyDecodeBitmap(const void* src,
28 size_t length,
29 SkBitmap* dst) {
30 SkAutoDataUnref data(SkData::NewWithCopy(src, length));
31 if (NULL == data.get()) {
32 return false;
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000033 }
34
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000035 SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(SkDecodingImageGenerator,
36 (data)));
37 SkImageInfo info;
38 if (!gen->getInfo(&info)) {
39 return false;
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000040 }
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000041 SkDiscardableMemory::Factory* pool = NULL;
42 if (info.fWidth * info.fHeight > 32 * 1024) {
43 // how to do switching with SkDiscardableMemory.
44 pool = SkGetGlobalDiscardableMemoryPool();
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000045 }
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000046 return SkDiscardablePixelRef::Install(gen.detach(), dst, pool);
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000047}