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" |
| 13 | #include "SkDiscardablePixelRef.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 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 20 | // TODO(halcanary) Use this flag when ashmem-backed discardable memory lands. |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 21 | DEFINE_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.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 25 | // Fits SkPicture::InstallPixelRefProc call signature. |
| 26 | // Used in SkPicturePlayback::CreateFromStream |
| 27 | bool 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.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 33 | } |
| 34 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 35 | SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(SkDecodingImageGenerator, |
| 36 | (data))); |
| 37 | SkImageInfo info; |
| 38 | if (!gen->getInfo(&info)) { |
| 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; |
| 42 | if (info.fWidth * info.fHeight > 32 * 1024) { |
| 43 | // how to do switching with SkDiscardableMemory. |
| 44 | pool = SkGetGlobalDiscardableMemoryPool(); |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 45 | } |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 46 | return SkDiscardablePixelRef::Install(gen.detach(), dst, pool); |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 47 | } |