2013-07-16 18:21:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LazyDecodeBitmap.h"
|
|
|
|
|
|
|
|
#include "SkData.h"
|
2013-12-05 18:31:42 +00:00
|
|
|
#include "SkDiscardableMemoryPool.h"
|
2014-05-27 14:14:22 +00:00
|
|
|
#include "SkImageGeneratorPriv.h"
|
2013-07-16 18:21:46 +00:00
|
|
|
#include "SkForceLinking.h"
|
2013-12-05 18:31:42 +00:00
|
|
|
|
2013-07-16 18:21:46 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
|
|
|
|
"Only meaningful if --deferImageDecoding is set to true and the platform has an "
|
|
|
|
"implementation.");
|
|
|
|
|
2013-12-05 18:31:42 +00:00
|
|
|
// Fits SkPicture::InstallPixelRefProc call signature.
|
2014-07-01 15:47:04 +00:00
|
|
|
// Used in SkPictureData::CreateFromStream
|
2015-03-19 15:31:14 +00:00
|
|
|
bool sk_tools::LazyDecodeBitmap(const void* src, size_t length, SkBitmap* dst) {
|
2013-12-05 18:31:42 +00:00
|
|
|
SkAutoDataUnref data(SkData::NewWithCopy(src, length));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == data.get()) {
|
2013-12-05 18:31:42 +00:00
|
|
|
return false;
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 18:47:36 +00:00
|
|
|
SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(data));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == gen.get()) {
|
2013-12-05 18:31:42 +00:00
|
|
|
return false;
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|
2015-03-19 15:31:14 +00:00
|
|
|
const SkImageInfo info = gen->getInfo();
|
2015-08-27 14:41:13 +00:00
|
|
|
SkDiscardableMemory::Factory* pool = nullptr;
|
2014-09-03 18:54:58 +00:00
|
|
|
if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024)) {
|
2013-12-05 18:31:42 +00:00
|
|
|
// how to do switching with SkDiscardableMemory.
|
|
|
|
pool = SkGetGlobalDiscardableMemoryPool();
|
2013-12-10 18:33:07 +00:00
|
|
|
// Only meaningful if platform has a default discardable
|
|
|
|
// memory implementation that differs from the global DM pool.
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
return SkInstallDiscardablePixelRef(gen.detach(), nullptr, dst, pool);
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|