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 "SkDecodingImageGenerator.h" |
| 12 | #include "SkDiscardableMemoryPool.h" |
commit-bot@chromium.org | 2d970b5 | 2014-05-27 14:14:22 +0000 | [diff] [blame] | 13 | #include "SkImageGeneratorPriv.h" |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 14 | #include "SkForceLinking.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 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 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 24 | // Fits SkPicture::InstallPixelRefProc call signature. |
robertphillips | db53990 | 2014-07-01 08:47:04 -0700 | [diff] [blame] | 25 | // Used in SkPictureData::CreateFromStream |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 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; |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 32 | } |
| 33 | |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 34 | SkAutoTDelete<SkImageGenerator> gen( |
| 35 | SkDecodingImageGenerator::Create( |
| 36 | data, SkDecodingImageGenerator::Options())); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 37 | SkImageInfo info; |
halcanary@google.com | 3d50ea1 | 2014-01-02 13:15:13 +0000 | [diff] [blame] | 38 | if ((NULL == gen.get()) || !gen->getInfo(&info)) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 39 | return false; |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 40 | } |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 41 | SkDiscardableMemory::Factory* pool = NULL; |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 42 | if ((!FLAGS_useVolatileCache) || (info.fWidth * info.fHeight < 32 * 1024)) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 43 | // how to do switching with SkDiscardableMemory. |
| 44 | pool = SkGetGlobalDiscardableMemoryPool(); |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 45 | // Only meaningful if platform has a default discardable |
| 46 | // memory implementation that differs from the global DM pool. |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 47 | } |
halcanary@google.com | edd370f | 2013-12-10 21:11:12 +0000 | [diff] [blame] | 48 | return SkInstallDiscardablePixelRef(gen.detach(), dst, pool); |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 49 | } |