aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@chromium.org>2015-07-09 09:08:00 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-09 09:08:00 -0700
commit5315fd4761a3c510dfff834a84e71e4c471951f9 (patch)
treea0fab94359f53b4c7e9411e06efffd4a801fe6af
parentd17a32966afb2f7fdebfb58d37fa1b2d3e2d474b (diff)
Remove SkImageGenerator pieces only for SkCodec.
Follow up to the split between SkImageGenerator and SkCodec. Now that SkCodec does not inherit from SkImageGenerator, SkImageGenerator no longer needs Options or Result, which were added for SkCodec. Remove them, but keep them behind a flag, since Chromium has its own subclasses of SkImageGenerator which assume the old signature for onGetPixels. Review URL: https://codereview.chromium.org/1226023003
-rw-r--r--include/core/SkImageGenerator.h17
-rw-r--r--src/core/SkImageGenerator.cpp49
-rw-r--r--src/images/SkDecodingImageGenerator.cpp38
-rw-r--r--src/lazy/SkCachingPixelRef.cpp12
-rw-r--r--src/lazy/SkDiscardablePixelRef.cpp18
-rw-r--r--src/ports/SkImageGenerator_skia.cpp24
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp23
7 files changed, 131 insertions, 50 deletions
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index f55c72bc1e..a398697e6b 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -15,6 +15,8 @@ class SkBitmap;
class SkData;
class SkImageGenerator;
+//#define SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
+
/**
* Takes ownership of SkImageGenerator. If this method fails for
* whatever reason, it will return false and immediatetely delete
@@ -67,6 +69,7 @@ public:
*/
const SkImageInfo& getInfo() const { return fInfo; }
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
/**
* Used to describe the result of a call to getPixels().
*
@@ -137,6 +140,7 @@ public:
ZeroInitialized fZeroInitialized;
};
+#endif
/**
* Decode into the given pixels, a block of memory of size at
@@ -165,16 +169,16 @@ public:
* If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount
* is not null, it will be set to 0.
*
- * @return Result kSuccess, or another value explaining the type of failure.
+ * @return true on success.
*/
- Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options*,
- SkPMColor ctable[], int* ctableCount);
+ bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount);
/**
* Simplified version of getPixels() that asserts that info is NOT kIndex8_SkColorType and
* uses the default Options.
*/
- Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
+ bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
/**
* If planes or rowBytes is NULL or if any entry in planes is NULL or if any entry in rowBytes
@@ -202,9 +206,14 @@ protected:
virtual SkData* onRefEncodedData();
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
virtual Result onGetPixels(const SkImageInfo& info,
void* pixels, size_t rowBytes, const Options&,
SkPMColor ctable[], int* ctableCount);
+#else
+ virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount);
+#endif
virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]);
virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
SkYUVColorSpace* colorSpace);
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 36caae99c3..b4a3fc21c8 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -7,22 +7,21 @@
#include "SkImageGenerator.h"
-SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels,
- size_t rowBytes, const Options* options,
- SkPMColor ctable[], int* ctableCount) {
+bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount) {
if (kUnknown_SkColorType == info.colorType()) {
- return kInvalidConversion;
+ return false;
}
if (NULL == pixels) {
- return kInvalidParameters;
+ return false;
}
if (rowBytes < info.minRowBytes()) {
- return kInvalidParameters;
+ return false;
}
if (kIndex_8_SkColorType == info.colorType()) {
if (NULL == ctable || NULL == ctableCount) {
- return kInvalidParameters;
+ return false;
}
} else {
if (ctableCount) {
@@ -32,26 +31,33 @@ SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, vo
ctable = NULL;
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
// Default options.
- Options optsStorage;
- if (NULL == options) {
- options = &optsStorage;
- }
- const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount);
+ Options options;
+ const Result result = this->onGetPixels(info, pixels, rowBytes, options, ctable, ctableCount);
- if ((kIncompleteInput == result || kSuccess == result) && ctableCount) {
+ if (kIncompleteInput != result && kSuccess != result) {
+ return false;
+ }
+ if (ctableCount) {
+ SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
+ }
+ return true;
+#else
+ const bool success = this->onGetPixels(info, pixels, rowBytes, ctable, ctableCount);
+ if (success && ctableCount) {
SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
}
- return result;
+ return success;
+#endif
}
-SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels,
- size_t rowBytes) {
+bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
SkASSERT(kIndex_8_SkColorType != info.colorType());
if (kIndex_8_SkColorType == info.colorType()) {
- return kInvalidConversion;
+ return false;
}
- return this->getPixels(info, pixels, rowBytes, NULL, NULL, NULL);
+ return this->getPixels(info, pixels, rowBytes, NULL, NULL);
}
bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
@@ -112,8 +118,15 @@ SkData* SkImageGenerator::onRefEncodedData() {
return NULL;
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
SkImageGenerator::Result SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst,
size_t rb, const Options& options,
SkPMColor* colors, int* colorCount) {
return kUnimplemented;
}
+#else
+bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb,
+ SkPMColor* colors, int* colorCount) {
+ return false;
+}
+#endif
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
index 2a07308447..6b2f73b2e4 100644
--- a/src/images/SkDecodingImageGenerator.cpp
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -38,9 +38,14 @@ public:
protected:
SkData* onRefEncodedData() override;
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
Result onGetPixels(const SkImageInfo& info,
void* pixels, size_t rowBytes, const Options&,
SkPMColor ctable[], int* ctableCount) override;
+#else
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount) override;
+#endif
bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
SkYUVColorSpace* colorSpace) override;
@@ -144,23 +149,36 @@ SkData* DecodingImageGenerator::onRefEncodedData() {
return SkSafeRef(fData);
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
void* pixels, size_t rowBytes, const Options& options, SkPMColor ctableEntries[],
int* ctableCount) {
+#else
+bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctableEntries[], int* ctableCount) {
+#endif
if (fInfo != info) {
// The caller has specified a different info. This is an
// error for this kind of SkImageGenerator. Use the Options
// to change the settings.
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
if (info.dimensions() != fInfo.dimensions()) {
return kInvalidScale;
}
return kInvalidConversion;
+#else
+ return false;
+#endif
}
SkAssertResult(fStream->rewind());
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
if (NULL == decoder.get()) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidInput;
+#else
+ return false;
+#endif
}
decoder->setDitherImage(fDitherImage);
decoder->setSampleSize(fSampleSize);
@@ -173,7 +191,11 @@ SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo&
SkImageDecoder::kDecodePixels_Mode);
decoder->setAllocator(NULL);
if (SkImageDecoder::kFailure == decodeResult) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidInput;
+#else
+ return false;
+#endif
}
if (allocator.isReady()) { // Did not use pixels!
SkBitmap bm;
@@ -182,7 +204,11 @@ SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo&
if (!copySuccess || allocator.isReady()) {
SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed.");
// Earlier we checked canCopyto(); we expect consistency.
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidConversion;
+#else
+ return false;
+#endif
}
SkASSERT(check_alpha(info.alphaType(), bm.alphaType()));
} else {
@@ -192,20 +218,32 @@ SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo&
if (kIndex_8_SkColorType == info.colorType()) {
if (kIndex_8_SkColorType != bitmap.colorType()) {
// they asked for Index8, but we didn't receive that from decoder
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidConversion;
+#else
+ return false;
+#endif
}
SkColorTable* ctable = bitmap.getColorTable();
if (NULL == ctable) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidConversion;
+#else
+ return false;
+#endif
}
const int count = ctable->count();
memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
*ctableCount = count;
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
if (SkImageDecoder::kPartialSuccess == decodeResult) {
return kIncompleteInput;
}
return kSuccess;
+#else
+ return true;
+#endif
}
bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp
index 5fc0d2a87f..3edd0de4fb 100644
--- a/src/lazy/SkCachingPixelRef.cpp
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -53,15 +53,9 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
fErrorInDecoding = true;
return false;
}
- const SkImageGenerator::Result result = fImageGenerator->getPixels(info,
- fLockedBitmap.getPixels(), fRowBytes);
- switch (result) {
- case SkImageGenerator::kIncompleteInput:
- case SkImageGenerator::kSuccess:
- break;
- default:
- fErrorInDecoding = true;
- return false;
+ if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowBytes)) {
+ fErrorInDecoding = true;
+ return false;
}
fLockedBitmap.setImmutable();
SkBitmapCache::Add(this, info.bounds(), fLockedBitmap);
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index 73fa4ce84c..19bfc8ccc7 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -71,18 +71,12 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) {
SkPMColor colors[256];
int colorCount = 0;
- const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels, fRowBytes, NULL,
- colors, &colorCount);
- switch (result) {
- case SkImageGenerator::kSuccess:
- case SkImageGenerator::kIncompleteInput:
- break;
- default:
- fDiscardableMemory->unlock();
- fDiscardableMemoryIsLocked = false;
- SkDELETE(fDiscardableMemory);
- fDiscardableMemory = NULL;
- return false;
+ if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) {
+ fDiscardableMemory->unlock();
+ fDiscardableMemoryIsLocked = false;
+ SkDELETE(fDiscardableMemory);
+ fDiscardableMemory = NULL;
+ return false;
}
// Note: our ctable is not purgeable, as it is not stored in the discardablememory block.
diff --git a/src/ports/SkImageGenerator_skia.cpp b/src/ports/SkImageGenerator_skia.cpp
index 1784cc228b..f972253306 100644
--- a/src/ports/SkImageGenerator_skia.cpp
+++ b/src/ports/SkImageGenerator_skia.cpp
@@ -46,10 +46,14 @@ protected:
SkData* onRefEncodedData() override {
return SkRef(fData.get());
}
-
- virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
- const Options&,
- SkPMColor ctableEntries[], int* ctableCount) override {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
+ Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options&,
+ SkPMColor ctableEntries[], int* ctableCount) override {
+#else
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctableEntries[], int* ctableCount) override {
+#endif
SkMemoryStream stream(fData->data(), fData->size(), false);
SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocator,
(info, pixels, rowBytes)));
@@ -60,7 +64,11 @@ protected:
const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colorType(),
SkImageDecoder::kDecodePixels_Mode);
if (SkImageDecoder::kFailure == result) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidInput;
+#else
+ return false;
+#endif
}
SkASSERT(info.colorType() == bm.info().colorType());
@@ -70,16 +78,24 @@ protected:
SkColorTable* ctable = bm.getColorTable();
if (NULL == ctable) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidConversion;
+#else
+ return false;
+#endif
}
const int count = ctable->count();
memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
*ctableCount = count;
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
if (SkImageDecoder::kPartialSuccess == result) {
return kIncompleteInput;
}
return kSuccess;
+#else
+ return true;
+#endif
}
bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 465b69b856..a2032ba1de 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -182,16 +182,29 @@ protected:
kOpaque_SkAlphaType);
}
- virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
- const Options&,
- SkPMColor ctable[], int* ctableCount) override {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
+ Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options&,
+ SkPMColor ctable[], int* ctableCount) override {
+#else
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount) override {
+#endif
REPORTER_ASSERT(fReporter, pixels != NULL);
REPORTER_ASSERT(fReporter, rowBytes >= info.minRowBytes());
if (fType != kSucceedGetPixels_TestType) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kUnimplemented;
+#else
+ return false;
+#endif
}
if (info.colorType() != kN32_SkColorType) {
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kInvalidConversion;
+#else
+ return false;
+#endif
}
char* bytePtr = static_cast<char*>(pixels);
for (int y = 0; y < info.height(); ++y) {
@@ -199,7 +212,11 @@ protected:
TestImageGenerator::Color(), info.width());
bytePtr += rowBytes;
}
+#ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS
return kSuccess;
+#else
+ return true;
+#endif
}
private: