commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 10 | #include "SkData.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 11 | #include "SkDiscardableMemoryPool.h" |
commit-bot@chromium.org | 2d970b5 | 2014-05-27 14:14:22 +0000 | [diff] [blame] | 12 | #include "SkImageGeneratorPriv.h" |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 13 | #include "SkForceLinking.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 15 | #include "SkCommandLineFlags.h" |
| 16 | |
| 17 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 18 | |
| 19 | DEFINE_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.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 23 | // Fits SkPicture::InstallPixelRefProc call signature. |
robertphillips | db53990 | 2014-07-01 08:47:04 -0700 | [diff] [blame] | 24 | // Used in SkPictureData::CreateFromStream |
reed | 3ef71e3 | 2015-03-19 08:31:14 -0700 | [diff] [blame] | 25 | bool sk_tools::LazyDecodeBitmap(const void* src, size_t length, SkBitmap* dst) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 26 | SkAutoDataUnref data(SkData::NewWithCopy(src, length)); |
| 27 | if (NULL == data.get()) { |
| 28 | return false; |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 29 | } |
| 30 | |
reed | 5965c8a | 2015-01-07 18:04:45 -0800 | [diff] [blame] | 31 | SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(data)); |
reed | 3ef71e3 | 2015-03-19 08:31:14 -0700 | [diff] [blame] | 32 | if (NULL == gen.get()) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 33 | return false; |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 34 | } |
reed | 3ef71e3 | 2015-03-19 08:31:14 -0700 | [diff] [blame] | 35 | const SkImageInfo info = gen->getInfo(); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 36 | SkDiscardableMemory::Factory* pool = NULL; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 37 | if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024)) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 38 | // how to do switching with SkDiscardableMemory. |
| 39 | pool = SkGetGlobalDiscardableMemoryPool(); |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 40 | // Only meaningful if platform has a default discardable |
| 41 | // memory implementation that differs from the global DM pool. |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 42 | } |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 43 | return SkInstallDiscardablePixelRef(gen.detach(), dst, pool); |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 44 | } |