diff options
author | halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-02 13:15:13 +0000 |
---|---|---|
committer | halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-02 13:15:13 +0000 |
commit | b069d37f47254a90562667dee0aed9f43de59a93 (patch) | |
tree | 311f5353a5a85c233cb967871213290dc082e72d /lazy | |
parent | 0f888e610d338db2f7d5c43e4d87a5bf66e24441 (diff) | |
download | src-b069d37f47254a90562667dee0aed9f43de59a93.tar.gz |
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/src@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'lazy')
-rw-r--r-- | lazy/SkCachingPixelRef.cpp | 1 | ||||
-rw-r--r-- | lazy/SkDiscardablePixelRef.cpp | 15 | ||||
-rw-r--r-- | lazy/SkDiscardablePixelRef.h | 9 |
3 files changed, 16 insertions, 9 deletions
diff --git a/lazy/SkCachingPixelRef.cpp b/lazy/SkCachingPixelRef.cpp index 668f57ef..fb30d051 100644 --- a/lazy/SkCachingPixelRef.cpp +++ b/lazy/SkCachingPixelRef.cpp @@ -12,7 +12,6 @@ bool SkCachingPixelRef::Install(SkImageGenerator* generator, SkBitmap* dst) { SkImageInfo info; - SkASSERT(generator != NULL); SkASSERT(dst != NULL); if ((NULL == generator) || !(generator->getInfo(&info)) diff --git a/lazy/SkDiscardablePixelRef.cpp b/lazy/SkDiscardablePixelRef.cpp index 160ca5b4..28861561 100644 --- a/lazy/SkDiscardablePixelRef.cpp +++ b/lazy/SkDiscardablePixelRef.cpp @@ -72,20 +72,19 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, SkDiscardableMemory::Factory* factory) { SkImageInfo info; - SkASSERT(generator != NULL); - if ((NULL == generator) - || (!generator->getInfo(&info)) + SkAutoTDelete<SkImageGenerator> autoGenerator(generator); + if ((NULL == autoGenerator.get()) + || (!autoGenerator->getInfo(&info)) || (!dst->setConfig(info, 0))) { - SkDELETE(generator); return false; } SkASSERT(dst->config() != SkBitmap::kNo_Config); - if (dst->empty()) { // Use a normal pixelref. - SkDELETE(generator); // Do not need this anymore. + if (dst->empty()) { // Use a normal pixelref. return dst->allocPixels(NULL, NULL); } - SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, - (info, generator, dst->rowBytes(), factory))); + SkAutoTUnref<SkDiscardablePixelRef> ref( + SkNEW_ARGS(SkDiscardablePixelRef, + (info, autoGenerator.detach(), dst->rowBytes(), factory))); dst->setPixelRef(ref); return true; } diff --git a/lazy/SkDiscardablePixelRef.h b/lazy/SkDiscardablePixelRef.h index 4b669383..3367096c 100644 --- a/lazy/SkDiscardablePixelRef.h +++ b/lazy/SkDiscardablePixelRef.h @@ -13,6 +13,15 @@ #include "SkImageInfo.h" #include "SkPixelRef.h" +/** + * A PixelRef backed by SkDiscardableMemory, with the ability to + * re-generate the pixels (via a SkImageGenerator) if the DM is + * purged. + * + * Since SkColorTable is reference-counted, we do not support indexed + * color with this class; there would be no way for the discardable + * memory system to unref the color table. + */ class SkDiscardablePixelRef : public SkPixelRef { public: SK_DECLARE_UNFLATTENABLE_OBJECT() |