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 "SkDecodingImageGenerator.h"
|
|
|
|
#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
|
2013-12-05 18:31:42 +00:00
|
|
|
bool sk_tools::LazyDecodeBitmap(const void* src,
|
|
|
|
size_t length,
|
|
|
|
SkBitmap* dst) {
|
|
|
|
SkAutoDataUnref data(SkData::NewWithCopy(src, length));
|
|
|
|
if (NULL == data.get()) {
|
|
|
|
return false;
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|
|
|
|
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkAutoTDelete<SkImageGenerator> gen(
|
|
|
|
SkDecodingImageGenerator::Create(
|
|
|
|
data, SkDecodingImageGenerator::Options()));
|
2013-12-05 18:31:42 +00:00
|
|
|
SkImageInfo info;
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
if ((NULL == gen.get()) || !gen->getInfo(&info)) {
|
2013-12-05 18:31:42 +00:00
|
|
|
return false;
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|
2013-12-05 18:31:42 +00:00
|
|
|
SkDiscardableMemory::Factory* pool = NULL;
|
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
|
|
|
}
|
2013-12-10 21:11:12 +00:00
|
|
|
return SkInstallDiscardablePixelRef(gen.detach(), dst, pool);
|
2013-07-16 18:21:46 +00:00
|
|
|
}
|