Change SkDecodingImageGenerator to hide implementation details.

Motivation: A later CL will move SkDecodingImageGenerator into
include/ for Android to use.

R=scroggo@google.com

Author: halcanary@google.com

Review URL: https://codereview.chromium.org/226253003

git-svn-id: http://skia.googlecode.com/svn/trunk@14066 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-04-04 20:13:05 +00:00
parent 25595ed6e9
commit 1f2d357436
2 changed files with 66 additions and 63 deletions

View File

@ -14,12 +14,36 @@
#include "SkStream.h" #include "SkStream.h"
#include "SkUtils.h" #include "SkUtils.h"
static bool equal_modulo_alpha(const SkImageInfo& a, const SkImageInfo& b) { namespace {
bool equal_modulo_alpha(const SkImageInfo& a, const SkImageInfo& b) {
return a.width() == b.width() && a.height() == b.height() && return a.width() == b.width() && a.height() == b.height() &&
a.colorType() == b.colorType(); a.colorType() == b.colorType();
} }
namespace { class DecodingImageGenerator : public SkImageGenerator {
public:
virtual ~DecodingImageGenerator();
virtual SkData* refEncodedData() SK_OVERRIDE;
// This implementaion of getInfo() always returns true.
virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
virtual bool getPixels(const SkImageInfo& info,
void* pixels,
size_t rowBytes) SK_OVERRIDE;
SkData* fData;
SkStreamRewindable* fStream;
const SkImageInfo fInfo;
const int fSampleSize;
const bool fDitherImage;
DecodingImageGenerator(SkData* data,
SkStreamRewindable* stream,
const SkImageInfo& info,
int sampleSize,
bool ditherImage);
typedef SkImageGenerator INHERITED;
};
/** /**
* Special allocator used by getPixels(). Uses preallocated memory * Special allocator used by getPixels(). Uses preallocated memory
* provided if possible, else fall-back on the default allocator * provided if possible, else fall-back on the default allocator
@ -76,10 +100,9 @@ inline bool check_alpha(SkAlphaType reported, SkAlphaType actual) {
} }
#endif // SK_DEBUG #endif // SK_DEBUG
} // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
SkDecodingImageGenerator::SkDecodingImageGenerator( DecodingImageGenerator::DecodingImageGenerator(
SkData* data, SkData* data,
SkStreamRewindable* stream, SkStreamRewindable* stream,
const SkImageInfo& info, const SkImageInfo& info,
@ -95,19 +118,19 @@ SkDecodingImageGenerator::SkDecodingImageGenerator(
SkSafeRef(fData); // may be NULL. SkSafeRef(fData); // may be NULL.
} }
SkDecodingImageGenerator::~SkDecodingImageGenerator() { DecodingImageGenerator::~DecodingImageGenerator() {
SkSafeUnref(fData); SkSafeUnref(fData);
fStream->unref(); fStream->unref();
} }
bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) { bool DecodingImageGenerator::getInfo(SkImageInfo* info) {
if (info != NULL) { if (info != NULL) {
*info = fInfo; *info = fInfo;
} }
return true; return true;
} }
SkData* SkDecodingImageGenerator::refEncodedData() { SkData* DecodingImageGenerator::refEncodedData() {
// This functionality is used in `gm --serialize` // This functionality is used in `gm --serialize`
// Does not encode options. // Does not encode options.
if (fData != NULL) { if (fData != NULL) {
@ -128,7 +151,7 @@ SkData* SkDecodingImageGenerator::refEncodedData() {
return SkSafeRef(fData); return SkSafeRef(fData);
} }
bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info, bool DecodingImageGenerator::getPixels(const SkImageInfo& info,
void* pixels, void* pixels,
size_t rowBytes) { size_t rowBytes) {
if (NULL == pixels) { if (NULL == pixels) {
@ -180,35 +203,10 @@ bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info,
return true; return true;
} }
SkImageGenerator* SkDecodingImageGenerator::Create(
SkData* data,
const SkDecodingImageGenerator::Options& opts) {
SkASSERT(data != NULL);
if (NULL == data) {
return NULL;
}
SkStreamRewindable* stream = SkNEW_ARGS(SkMemoryStream, (data));
SkASSERT(stream != NULL);
SkASSERT(stream->unique());
return SkDecodingImageGenerator::Create(data, stream, opts);
}
SkImageGenerator* SkDecodingImageGenerator::Create(
SkStreamRewindable* stream,
const SkDecodingImageGenerator::Options& opts) {
SkASSERT(stream != NULL);
SkASSERT(stream->unique());
if ((stream == NULL) || !stream->unique()) {
SkSafeUnref(stream);
return NULL;
}
return SkDecodingImageGenerator::Create(NULL, stream, opts);
}
// A contructor-type function that returns NULL on failure. This // A contructor-type function that returns NULL on failure. This
// prevents the returned SkImageGenerator from ever being in a bad // prevents the returned SkImageGenerator from ever being in a bad
// state. Called by both Create() functions // state. Called by both Create() functions
SkImageGenerator* SkDecodingImageGenerator::Create( SkImageGenerator* CreateDecodingImageGenerator(
SkData* data, SkData* data,
SkStreamRewindable* stream, SkStreamRewindable* stream,
const SkDecodingImageGenerator::Options& opts) { const SkDecodingImageGenerator::Options& opts) {
@ -250,7 +248,36 @@ SkImageGenerator* SkDecodingImageGenerator::Create(
} }
info.fColorType = opts.fRequestedColorType; info.fColorType = opts.fRequestedColorType;
} }
return SkNEW_ARGS(SkDecodingImageGenerator, return SkNEW_ARGS(DecodingImageGenerator,
(data, autoStream.detach(), info, (data, autoStream.detach(), info,
opts.fSampleSize, opts.fDitherImage)); opts.fSampleSize, opts.fDitherImage));
} }
} // namespace
////////////////////////////////////////////////////////////////////////////////
SkImageGenerator* SkDecodingImageGenerator::Create(
SkData* data,
const SkDecodingImageGenerator::Options& opts) {
SkASSERT(data != NULL);
if (NULL == data) {
return NULL;
}
SkStreamRewindable* stream = SkNEW_ARGS(SkMemoryStream, (data));
SkASSERT(stream != NULL);
SkASSERT(stream->unique());
return CreateDecodingImageGenerator(data, stream, opts);
}
SkImageGenerator* SkDecodingImageGenerator::Create(
SkStreamRewindable* stream,
const SkDecodingImageGenerator::Options& opts) {
SkASSERT(stream != NULL);
SkASSERT(stream->unique());
if ((stream == NULL) || !stream->unique()) {
SkSafeUnref(stream);
return NULL;
}
return CreateDecodingImageGenerator(NULL, stream, opts);
}

View File

@ -18,15 +18,7 @@ class SkStreamRewindable;
* An implementation of SkImageGenerator that calls into * An implementation of SkImageGenerator that calls into
* SkImageDecoder. * SkImageDecoder.
*/ */
class SkDecodingImageGenerator : public SkImageGenerator { namespace SkDecodingImageGenerator {
public:
virtual ~SkDecodingImageGenerator();
virtual SkData* refEncodedData() SK_OVERRIDE;
// This implementaion of getInfo() always returns true.
virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
virtual bool getPixels(const SkImageInfo& info,
void* pixels,
size_t rowBytes) SK_OVERRIDE;
/** /**
* These options will be passed on to the image decoder. The * These options will be passed on to the image decoder. The
* defaults are sensible. * defaults are sensible.
@ -97,7 +89,7 @@ public:
* *
* @return NULL on failure, a new SkImageGenerator on success. * @return NULL on failure, a new SkImageGenerator on success.
*/ */
static SkImageGenerator* Create(SkStreamRewindable* stream, SkImageGenerator* Create(SkStreamRewindable* stream,
const Options& opt); const Options& opt);
/** /**
@ -105,23 +97,7 @@ public:
* the SkDecodingImageGenerator. Will be ref()ed by the * the SkDecodingImageGenerator. Will be ref()ed by the
* SkImageGenerator constructor and and unref()ed on deletion. * SkImageGenerator constructor and and unref()ed on deletion.
*/ */
static SkImageGenerator* Create(SkData* data, const Options& opt); SkImageGenerator* Create(SkData* data, const Options& opt);
private:
SkData* fData;
SkStreamRewindable* fStream;
const SkImageInfo fInfo;
const int fSampleSize;
const bool fDitherImage;
SkDecodingImageGenerator(SkData* data,
SkStreamRewindable* stream,
const SkImageInfo& info,
int sampleSize,
bool ditherImage);
static SkImageGenerator* Create(SkData*, SkStreamRewindable*,
const Options&);
typedef SkImageGenerator INHERITED;
}; };
// // Example of most basic use case: // // Example of most basic use case: