aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/skia_for_chromium_defines.gypi1
-rw-r--r--include/codec/SkCodec.h4
-rw-r--r--include/core/SkImageGenerator.h40
-rw-r--r--src/codec/SkCodec_libbmp.cpp3
-rw-r--r--src/codec/SkCodec_libbmp.h2
-rw-r--r--src/codec/SkCodec_libpng.cpp8
-rw-r--r--src/codec/SkCodec_libpng.h3
-rw-r--r--src/codec/SkSwizzler.cpp10
-rw-r--r--src/codec/SkSwizzler.h19
-rw-r--r--src/core/SkImageGenerator.cpp25
-rw-r--r--src/images/SkDecodingImageGenerator.cpp5
-rw-r--r--src/lazy/SkDiscardablePixelRef.cpp2
-rw-r--r--src/ports/SkImageGenerator_skia.cpp1
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp1
-rw-r--r--tests/DrawBitmapRectTest.cpp2
15 files changed, 94 insertions, 32 deletions
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi
index bcc6096a1d..3045e426f4 100644
--- a/gyp/skia_for_chromium_defines.gypi
+++ b/gyp/skia_for_chromium_defines.gypi
@@ -14,6 +14,7 @@
#
'skia_for_chromium_defines': [
'SK_LEGACY_DRAWPICTURECALLBACK',
+ 'SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS',
],
},
}
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h
index c46985268d..93416be51e 100644
--- a/include/codec/SkCodec.h
+++ b/include/codec/SkCodec.h
@@ -94,8 +94,8 @@ protected:
}
private:
- const SkImageInfo fInfo;
+ const SkImageInfo fInfo;
SkAutoTDelete<SkStream> fStream;
- bool fNeedsRewind;
+ bool fNeedsRewind;
};
#endif // SkCodec_DEFINED
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 5de9d3d85a..a5440bd3b4 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -15,6 +15,8 @@ class SkBitmap;
class SkData;
class SkImageGenerator;
+//#define SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS
+
/**
* Takes ownership of SkImageGenerator. If this method fails for
* whatever reason, it will return false and immediatetely delete
@@ -117,6 +119,34 @@ public:
};
/**
+ * Whether or not the memory passed to getPixels is zero initialized.
+ */
+ enum ZeroInitialized {
+ /**
+ * The memory passed to getPixels is zero initialized. The SkCodec
+ * may take advantage of this by skipping writing zeroes.
+ */
+ kYes_ZeroInitialized,
+ /**
+ * The memory passed to getPixels has not been initialized to zero,
+ * so the SkCodec must write all zeroes to memory.
+ *
+ * This is the default. It will be used if no Options struct is used.
+ */
+ kNo_ZeroInitialized,
+ };
+
+ /**
+ * Additional options to pass to getPixels.
+ */
+ struct Options {
+ Options()
+ : fZeroInitialized(kNo_ZeroInitialized) {}
+
+ ZeroInitialized fZeroInitialized;
+ };
+
+ /**
* Decode into the given pixels, a block of memory of size at
* least (info.fHeight - 1) * rowBytes + (info.fWidth *
* bytesPerPixel)
@@ -145,11 +175,12 @@ public:
*
* @return Result kSuccess, or another value explaining the type of failure.
*/
- Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options*,
SkPMColor ctable[], int* ctableCount);
/**
- * Simplified version of getPixels() that asserts that info is NOT kIndex8_SkColorType.
+ * 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);
@@ -177,9 +208,14 @@ public:
protected:
virtual SkData* onRefEncodedData();
virtual bool onGetInfo(SkImageInfo* info);
+#ifdef SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS
virtual Result onGetPixels(const SkImageInfo& info,
void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount);
+#endif
+ virtual Result onGetPixels(const SkImageInfo& info,
+ void* pixels, size_t rowBytes, const Options&,
+ SkPMColor ctable[], int* ctableCount);
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/codec/SkCodec_libbmp.cpp b/src/codec/SkCodec_libbmp.cpp
index 5b9691c087..a96cd665b8 100644
--- a/src/codec/SkCodec_libbmp.cpp
+++ b/src/codec/SkCodec_libbmp.cpp
@@ -502,6 +502,7 @@ SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream,
*/
SkCodec::Result SkBmpCodec::onGetPixels(const SkImageInfo& dstInfo,
void* dst, size_t dstRowBytes,
+ const Options&,
SkPMColor*, int*) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
@@ -844,7 +845,7 @@ SkCodec::Result SkBmpCodec::decode(const SkImageInfo& dstInfo,
// Create swizzler
SkSwizzler* swizzler = SkSwizzler::CreateSwizzler(config, fColorTable.get(),
- dstInfo, dst, dstRowBytes, false);
+ dstInfo, dst, dstRowBytes, SkImageGenerator::kNo_ZeroInitialized);
// Allocate space for a row buffer and a source for the swizzler
SkAutoTDeleteArray<uint8_t> srcBuffer(SkNEW_ARRAY(uint8_t, rowBytes));
diff --git a/src/codec/SkCodec_libbmp.h b/src/codec/SkCodec_libbmp.h
index f35b88dc69..21dab1a4d9 100644
--- a/src/codec/SkCodec_libbmp.h
+++ b/src/codec/SkCodec_libbmp.h
@@ -56,7 +56,7 @@ protected:
*
*/
virtual Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
- size_t dstRowBytes, SkPMColor*,
+ size_t dstRowBytes, const Options&, SkPMColor*,
int*) SK_OVERRIDE;
private:
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index f42af38fea..bf0647dd24 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -363,8 +363,8 @@ static bool conversion_possible(const SkImageInfo& A, const SkImageInfo& B) {
}
SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst,
- size_t rowBytes, SkPMColor ctable[],
- int* ctableCount) {
+ size_t rowBytes, const Options& options,
+ SkPMColor ctable[], int* ctableCount) {
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
@@ -430,9 +430,9 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
sc = SkSwizzler::kRGBA;
}
const SkPMColor* colors = colorTable ? colorTable->readColors() : NULL;
- // TODO: Support skipZeroes.
swizzler.reset(SkSwizzler::CreateSwizzler(sc, colors, requestedInfo,
- dst, rowBytes, false));
+ dst, rowBytes,
+ options.fZeroInitialized));
if (!swizzler) {
// FIXME: CreateSwizzler could fail for another reason.
return kUnimplemented;
diff --git a/src/codec/SkCodec_libpng.h b/src/codec/SkCodec_libpng.h
index a5327dda41..b255449fb5 100644
--- a/src/codec/SkCodec_libpng.h
+++ b/src/codec/SkCodec_libpng.h
@@ -22,7 +22,8 @@ public:
static SkCodec* NewFromStream(SkStream*);
static bool IsPng(SkStream*);
protected:
- Result onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) SK_OVERRIDE;
+ Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*)
+ SK_OVERRIDE;
private:
png_structp fPng_ptr;
png_infop fInfo_ptr;
diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
index 0668db6db9..1aa3793f15 100644
--- a/src/codec/SkSwizzler.cpp
+++ b/src/codec/SkSwizzler.cpp
@@ -199,7 +199,8 @@ static bool swizzle_rgba_to_n32_unpremul_skipZ(void* SK_RESTRICT dstRow,
SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
const SkPMColor* ctable,
const SkImageInfo& info, void* dst,
- size_t dstRowBytes, bool skipZeroes) {
+ size_t dstRowBytes,
+ SkImageGenerator::ZeroInitialized zeroInit) {
if (kUnknown_SkColorType == info.colorType()) {
return NULL;
}
@@ -226,7 +227,8 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
case kIndex:
switch (info.colorType()) {
case kN32_SkColorType:
- if (skipZeroes) {
+ // We assume the color premultiplied ctable (or not) as desired.
+ if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) {
proc = &swizzle_index_to_n32_skipZ;
} else {
proc = &swizzle_index_to_n32;
@@ -269,10 +271,10 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
switch (info.colorType()) {
case kN32_SkColorType:
if (info.alphaType() == kUnpremul_SkAlphaType) {
- // Respect skipZeroes?
+ // Respect zeroInit?
proc = &swizzle_rgba_to_n32_unpremul;
} else {
- if (skipZeroes) {
+ if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) {
proc = &swizzle_rgba_to_n32_premul_skipZ;
} else {
proc = &swizzle_rgba_to_n32_premul;
diff --git a/src/codec/SkSwizzler.h b/src/codec/SkSwizzler.h
index e22c05b267..be20d0ea99 100644
--- a/src/codec/SkSwizzler.h
+++ b/src/codec/SkSwizzler.h
@@ -8,7 +8,7 @@
#ifndef SkSwizzler_DEFINED
#define SkSwizzler_DEFINED
-#include "SkTypes.h"
+#include "SkCodec.h"
#include "SkColor.h"
#include "SkImageInfo.h"
@@ -113,19 +113,20 @@ public:
/**
* Create a new SkSwizzler.
- * @param sc SrcConfig
- * @param info dimensions() describe both the src and the dst.
+ * @param SrcConfig Description of the format of the source.
+ * @param SkImageInfo dimensions() describe both the src and the dst.
* Other fields describe the dst.
* @param dst Destination to write pixels. Must match info and dstRowBytes
* @param dstRowBytes rowBytes for dst.
- * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
- * zero-initialized. The implementation may or may not respect this.
+ * @param ZeroInitialized Whether dst is zero-initialized. The
+ implementation may choose to skip writing zeroes
+ * if set to kYes_ZeroInitialized.
* @return A new SkSwizzler or NULL on failure.
*/
- static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable,
- const SkImageInfo& info, void* dst,
- size_t dstRowBytes, bool skipZeroes);
-
+ static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable,
+ const SkImageInfo&, void* dst,
+ size_t dstRowBytes,
+ SkImageGenerator::ZeroInitialized);
/**
* Swizzle the next line. Call height times, once for each row of source.
* @param src The next row of the source data.
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index aabe83e4f9..4c69fd2a0b 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -16,8 +16,8 @@ bool SkImageGenerator::getInfo(SkImageInfo* info) {
}
SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels,
- size_t rowBytes, SkPMColor ctable[],
- int* ctableCount) {
+ size_t rowBytes, const Options* options,
+ SkPMColor ctable[], int* ctableCount) {
if (kUnknown_SkColorType == info.colorType()) {
return kInvalidConversion;
}
@@ -40,7 +40,12 @@ SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, vo
ctable = NULL;
}
- const Result result = this->onGetPixels(info, pixels, rowBytes, ctable, ctableCount);
+ // Default options.
+ Options optsStorage;
+ if (NULL == options) {
+ options = &optsStorage;
+ }
+ const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount);
if ((kIncompleteInput == result || kSuccess == result) && ctableCount) {
SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
@@ -54,7 +59,7 @@ SkImageGenerator::Result SkImageGenerator::getPixels(const SkImageInfo& info, vo
if (kIndex_8_SkColorType == info.colorType()) {
return kInvalidConversion;
}
- return this->getPixels(info, pixels, rowBytes, NULL, NULL);
+ return this->getPixels(info, pixels, rowBytes, NULL, NULL, NULL);
}
bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
@@ -119,7 +124,19 @@ bool SkImageGenerator::onGetInfo(SkImageInfo*) {
return false;
}
+#ifdef SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS
SkImageGenerator::Result SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t,
SkPMColor*, int*) {
return kUnimplemented;
}
+#endif
+
+SkImageGenerator::Result SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst,
+ size_t rb, const Options& options,
+ SkPMColor* colors, int* colorCount) {
+#ifdef SK_SUPPORT_LEGACY_OPTIONLESS_GET_PIXELS
+ return this->onGetPixels(info, dst, rb, colors, colorCount);
+#else
+ return kUnimplemented;
+#endif
+}
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
index f9b9393e00..170397dda1 100644
--- a/src/images/SkDecodingImageGenerator.cpp
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -43,7 +43,7 @@ protected:
return true;
}
virtual Result onGetPixels(const SkImageInfo& info,
- void* pixels, size_t rowBytes,
+ void* pixels, size_t rowBytes, const Options&,
SkPMColor ctable[], int* ctableCount) SK_OVERRIDE;
virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
SkYUVColorSpace* colorSpace) SK_OVERRIDE;
@@ -148,7 +148,8 @@ SkData* DecodingImageGenerator::onRefEncodedData() {
}
SkImageGenerator::Result DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
- void* pixels, size_t rowBytes, SkPMColor ctableEntries[], int* ctableCount) {
+ void* pixels, size_t rowBytes, const Options& options, SkPMColor ctableEntries[],
+ int* ctableCount) {
if (fInfo != info) {
// The caller has specified a different info. This is an
// error for this kind of SkImageGenerator. Use the Options
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index b6dec1b3a1..b810c2b183 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -71,7 +71,7 @@ bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) {
SkPMColor colors[256];
int colorCount = 0;
- const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels, fRowBytes,
+ const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels, fRowBytes, NULL,
colors, &colorCount);
switch (result) {
case SkImageGenerator::kSuccess:
diff --git a/src/ports/SkImageGenerator_skia.cpp b/src/ports/SkImageGenerator_skia.cpp
index 6c27f45a56..1448d57ce5 100644
--- a/src/ports/SkImageGenerator_skia.cpp
+++ b/src/ports/SkImageGenerator_skia.cpp
@@ -53,6 +53,7 @@ protected:
}
virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options&,
SkPMColor ctableEntries[], int* ctableCount) SK_OVERRIDE {
SkMemoryStream stream(fData->data(), fData->size(), false);
SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocator,
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 3882026c77..d6edda75cb 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -190,6 +190,7 @@ protected:
}
virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options&,
SkPMColor ctable[], int* ctableCount) SK_OVERRIDE {
REPORTER_ASSERT(fReporter, pixels != NULL);
REPORTER_ASSERT(fReporter, rowBytes >= info.minRowBytes());
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 9203879a9e..9c0c6839b2 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -28,7 +28,7 @@ protected:
*info = SkImageInfo::MakeN32Premul(100, 100);
return true;
}
- // default onGetPixels() returns false, which is what we want.
+ // default onGetPixels() returns kUnimplemented, which is what we want.
};
// crbug.com/295895