Use a wrapper for SkDebugf in SkCodec.
It can be silenced or not with one flag.
Always print when building for the android framework.
Also remove the meaningless define of override to override.
BUG=skia:3257
Review URL: https://codereview.chromium.org/1032093004
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi
index a38c92d..7f0b602 100644
--- a/gyp/common_conditions.gypi
+++ b/gyp/common_conditions.gypi
@@ -419,7 +419,7 @@
# We can't use the skia_shared_library gyp setting because we need expose
# this define globally and the the implemention define as a cflag.
'SKIA_DLL',
- 'override override',
+ 'SK_PRINT_CODEC_MESSAGES',
# Defines from skia_for_android_framework_defines.gypi
'<@(skia_for_android_framework_defines)',
],
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index 7c57a9f..da75746 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -105,4 +105,10 @@
#endif
}
+#ifdef SK_PRINT_CODEC_MESSAGES
+ #define SkCodecPrintf SkDebugf
+#else
+ #define SkCodecPrintf(...)
+#endif
+
#endif // SkCodecPriv_DEFINED
diff --git a/src/codec/SkCodec_libbmp.cpp b/src/codec/SkCodec_libbmp.cpp
index ac6cf3a..d0c9623 100644
--- a/src/codec/SkCodec_libbmp.cpp
+++ b/src/codec/SkCodec_libbmp.cpp
@@ -139,14 +139,14 @@
SkNEW_ARRAY(uint8_t, kBmpHeaderBytesPlusFour));
if (stream->read(hBuffer.get(), kBmpHeaderBytesPlusFour) !=
kBmpHeaderBytesPlusFour) {
- SkDebugf("Error: unable to read first bitmap header.\n");
+ SkCodecPrintf("Error: unable to read first bitmap header.\n");
return NULL;
}
totalBytes = get_int(hBuffer.get(), 2);
offset = get_int(hBuffer.get(), 10);
if (offset < kBmpHeaderBytes + kBmpOS2V1Bytes) {
- SkDebugf("Error: invalid starting location for pixel data\n");
+ SkCodecPrintf("Error: invalid starting location for pixel data\n");
return NULL;
}
@@ -155,7 +155,7 @@
// read the first four infoBytes.
infoBytes = get_int(hBuffer.get(), 14);
if (infoBytes < kBmpOS2V1Bytes) {
- SkDebugf("Error: invalid second header size.\n");
+ SkCodecPrintf("Error: invalid second header size.\n");
return NULL;
}
} else {
@@ -173,12 +173,12 @@
SkAutoTDeleteArray<uint8_t> hBuffer(
SkNEW_ARRAY(uint8_t, 4));
if (stream->read(hBuffer.get(), 4) != 4) {
- SkDebugf("Error: unable to read size of second bitmap header.\n");
+ SkCodecPrintf("Error: unable to read size of second bitmap header.\n");
return NULL;
}
infoBytes = get_int(hBuffer.get(), 0);
if (infoBytes < kBmpOS2V1Bytes) {
- SkDebugf("Error: invalid second header size.\n");
+ SkCodecPrintf("Error: invalid second header size.\n");
return NULL;
}
}
@@ -190,7 +190,7 @@
SkAutoTDeleteArray<uint8_t> iBuffer(
SkNEW_ARRAY(uint8_t, infoBytesRemaining));
if (stream->read(iBuffer.get(), infoBytesRemaining) != infoBytesRemaining) {
- SkDebugf("Error: unable to read second bitmap header.\n");
+ SkCodecPrintf("Error: unable to read second bitmap header.\n");
return NULL;
}
@@ -248,7 +248,7 @@
// of the newer versions of bmp headers are similar to and
// build off of the older versions, so we may still be able to
// decode the bmp.
- SkDebugf("Warning: unknown bmp header format.\n");
+ SkCodecPrintf("Warning: unknown bmp header format.\n");
headerType = kUnknown_BitmapHeaderType;
break;
}
@@ -281,7 +281,7 @@
bytesPerColor = 3;
} else {
// There are no valid bmp headers
- SkDebugf("Error: second bitmap header size is invalid.\n");
+ SkCodecPrintf("Error: second bitmap header size is invalid.\n");
return NULL;
}
@@ -299,7 +299,7 @@
static const int kBmpMaxDim = 1 << 16;
if (width < 0 || width >= kBmpMaxDim || height >= kBmpMaxDim) {
// TODO: Decide if we want to support really large bmps.
- SkDebugf("Error: invalid bitmap dimensions.\n");
+ SkCodecPrintf("Error: invalid bitmap dimensions.\n");
return NULL;
}
@@ -316,14 +316,14 @@
break;
case k8BitRLE_BitmapCompressionMethod:
if (bitsPerPixel != 8) {
- SkDebugf("Warning: correcting invalid bitmap format.\n");
+ SkCodecPrintf("Warning: correcting invalid bitmap format.\n");
bitsPerPixel = 8;
}
inputFormat = kRLE_BitmapInputFormat;
break;
case k4BitRLE_BitmapCompressionMethod:
if (bitsPerPixel != 4) {
- SkDebugf("Warning: correcting invalid bitmap format.\n");
+ SkCodecPrintf("Warning: correcting invalid bitmap format.\n");
bitsPerPixel = 4;
}
inputFormat = kRLE_BitmapInputFormat;
@@ -339,7 +339,7 @@
SkNEW_ARRAY(uint8_t, kBmpMaskBytes));
if (stream->read(mBuffer.get(), kBmpMaskBytes) !=
kBmpMaskBytes) {
- SkDebugf("Error: unable to read bit inputMasks.\n");
+ SkCodecPrintf("Error: unable to read bit inputMasks.\n");
return NULL;
}
maskBytes = kBmpMaskBytes;
@@ -365,10 +365,10 @@
// It is unsupported in the previous version and
// in chromium. I have not come across a test case
// that uses this format.
- SkDebugf("Error: huffman format unsupported.\n");
+ SkCodecPrintf("Error: huffman format unsupported.\n");
return NULL;
default:
- SkDebugf("Error: invalid bmp bit masks header.\n");
+ SkCodecPrintf("Error: invalid bmp bit masks header.\n");
return NULL;
}
break;
@@ -382,16 +382,16 @@
// TODO: Decide if we intend to support this.
// It is unsupported in the previous version and
// in chromium. I think it is used mostly for printers.
- SkDebugf("Error: compression format not supported.\n");
+ SkCodecPrintf("Error: compression format not supported.\n");
return NULL;
case kCMYK_BitmapCompressionMethod:
case kCMYK8BitRLE_BitmapCompressionMethod:
case kCMYK4BitRLE_BitmapCompressionMethod:
// TODO: Same as above.
- SkDebugf("Error: CMYK not supported for bitmap decoding.\n");
+ SkCodecPrintf("Error: CMYK not supported for bitmap decoding.\n");
return NULL;
default:
- SkDebugf("Error: invalid format for bitmap decoding.\n");
+ SkCodecPrintf("Error: invalid format for bitmap decoding.\n");
return NULL;
}
@@ -446,7 +446,7 @@
case 32:
break;
default:
- SkDebugf("Error: invalid input value for bits per pixel.\n");
+ SkCodecPrintf("Error: invalid input value for bits per pixel.\n");
return NULL;
}
@@ -454,13 +454,13 @@
SkAutoTDelete<SkMasks>
masks(SkMasks::CreateMasks(inputMasks, bitsPerPixel));
if (NULL == masks) {
- SkDebugf("Error: invalid input masks.\n");
+ SkCodecPrintf("Error: invalid input masks.\n");
return NULL;
}
// Check for a valid number of total bytes when in RLE mode
if (totalBytes <= offset && kRLE_BitmapInputFormat == inputFormat) {
- SkDebugf("Error: RLE requires valid input size.\n");
+ SkCodecPrintf("Error: RLE requires valid input size.\n");
return NULL;
}
const size_t RLEBytes = totalBytes - offset;
@@ -468,7 +468,7 @@
// Calculate the number of bytes read so far
const uint32_t bytesRead = kBmpHeaderBytes + infoBytes + maskBytes;
if (!isIco && offset < bytesRead) {
- SkDebugf("Error: pixel data offset less than header size.\n");
+ SkCodecPrintf("Error: pixel data offset less than header size.\n");
return NULL;
}
@@ -523,17 +523,17 @@
return kCouldNotRewind;
}
if (dstInfo.dimensions() != this->getInfo().dimensions()) {
- SkDebugf("Error: scaling not supported.\n");
+ SkCodecPrintf("Error: scaling not supported.\n");
return kInvalidScale;
}
if (!conversion_possible(dstInfo, this->getInfo())) {
- SkDebugf("Error: cannot convert input type to output type.\n");
+ SkCodecPrintf("Error: cannot convert input type to output type.\n");
return kInvalidConversion;
}
// Create the color table if necessary and prepare the stream for decode
if (!createColorTable(dstInfo.alphaType())) {
- SkDebugf("Error: could not create color table.\n");
+ SkCodecPrintf("Error: could not create color table.\n");
return kInvalidInput;
}
@@ -573,7 +573,7 @@
colorBytes = fNumColors * fBytesPerColor;
SkAutoTDeleteArray<uint8_t> cBuffer(SkNEW_ARRAY(uint8_t, colorBytes));
if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) {
- SkDebugf("Error: unable to read color table.\n");
+ SkCodecPrintf("Error: unable to read color table.\n");
return false;
}
@@ -626,13 +626,13 @@
// color table. This is invalid, and our decision is to indicate
// an error, rather than try to guess the intended size of the
// color table.
- SkDebugf("Error: pixel data offset less than color table size.\n");
+ SkCodecPrintf("Error: pixel data offset less than color table size.\n");
return false;
}
// After reading the color table, skip to the start of the pixel array
if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) {
- SkDebugf("Error: unable to skip to image data.\n");
+ SkCodecPrintf("Error: unable to skip to image data.\n");
return false;
}
}
@@ -669,7 +669,7 @@
for (int y = 0; y < height; y++) {
// Read a row of the input
if (stream()->read(srcRow, rowBytes) != rowBytes) {
- SkDebugf("Warning: incomplete input stream.\n");
+ SkCodecPrintf("Warning: incomplete input stream.\n");
return kIncompleteInput;
}
@@ -807,9 +807,9 @@
SkAutoTDeleteArray<uint8_t> buffer(SkNEW_ARRAY(uint8_t, fRLEBytes));
size_t totalBytes = stream()->read(buffer.get(), fRLEBytes);
if (totalBytes < fRLEBytes) {
- SkDebugf("Warning: incomplete RLE file.\n");
+ SkCodecPrintf("Warning: incomplete RLE file.\n");
} else if (totalBytes <= 0) {
- SkDebugf("Error: could not read RLE image data.\n");
+ SkCodecPrintf("Error: could not read RLE image data.\n");
return kInvalidInput;
}
@@ -824,7 +824,7 @@
while (true) {
// Every entry takes at least two bytes
if ((int) totalBytes - currByte < 2) {
- SkDebugf("Warning: incomplete RLE input.\n");
+ SkCodecPrintf("Warning: incomplete RLE input.\n");
return kIncompleteInput;
}
@@ -838,7 +838,7 @@
// If we have reached a row that is beyond the image size, and the RLE
// code does not indicate end of file, abort and signal a warning.
if (y >= height && (flag != RLE_ESCAPE || (task != RLE_EOF))) {
- SkDebugf("Warning: invalid RLE input.\n");
+ SkCodecPrintf("Warning: invalid RLE input.\n");
return kIncompleteInput;
}
@@ -854,7 +854,7 @@
case RLE_DELTA: {
// Two bytes are needed to specify delta
if ((int) totalBytes - currByte < 2) {
- SkDebugf("Warning: incomplete RLE input\n");
+ SkCodecPrintf("Warning: incomplete RLE input\n");
return kIncompleteInput;
}
// Modify x and y
@@ -863,7 +863,7 @@
x += dx;
y += dy;
if (x > width || y > height) {
- SkDebugf("Warning: invalid RLE input.\n");
+ SkCodecPrintf("Warning: invalid RLE input.\n");
return kIncompleteInput;
}
break;
@@ -881,7 +881,7 @@
// remaining in the stream to set numPixels.
if (x + numPixels > width ||
(int) totalBytes - currByte < SkAlign2(rowBytes)) {
- SkDebugf("Warning: invalid RLE input.\n");
+ SkCodecPrintf("Warning: invalid RLE input.\n");
return kIncompleteInput;
}
// Set numPixels number of pixels
@@ -938,7 +938,7 @@
// There are two more required bytes to finish encoding the
// color.
if ((int) totalBytes - currByte < 2) {
- SkDebugf("Warning: incomplete RLE input\n");
+ SkCodecPrintf("Warning: incomplete RLE input\n");
return kIncompleteInput;
}
@@ -1028,7 +1028,7 @@
for (int y = 0; y < height; y++) {
// Read a row of the input
if (stream()->read(srcBuffer.get(), rowBytes) != rowBytes) {
- SkDebugf("Warning: incomplete input stream.\n");
+ SkCodecPrintf("Warning: incomplete input stream.\n");
return kIncompleteInput;
}
@@ -1080,7 +1080,7 @@
for (int y = 0; y < height; y++) {
// The srcBuffer will at least be large enough
if (stream()->read(srcBuffer.get(), rowBytes) != rowBytes) {
- SkDebugf("Warning: incomplete AND mask for bmp-in-ico.\n");
+ SkCodecPrintf("Warning: incomplete AND mask for bmp-in-ico.\n");
return kIncompleteInput;
}
diff --git a/src/codec/SkCodec_libbmp.h b/src/codec/SkCodec_libbmp.h
index 8ec2abd..3328af2 100644
--- a/src/codec/SkCodec_libbmp.h
+++ b/src/codec/SkCodec_libbmp.h
@@ -14,7 +14,6 @@
#include "SkTypes.h"
// TODO: rename SkCodec_libbmp files to SkBmpCodec
-// TODO: define a wrapper for SkDebugf that doesn't always print
/*
*
* This class implements the decoding for bmp images
diff --git a/src/codec/SkCodec_libico.cpp b/src/codec/SkCodec_libico.cpp
index 6a62ed8..97404af 100644
--- a/src/codec/SkCodec_libico.cpp
+++ b/src/codec/SkCodec_libico.cpp
@@ -45,14 +45,14 @@
SkNEW_ARRAY(uint8_t, kIcoDirectoryBytes));
if (inputStream.get()->read(dirBuffer.get(), kIcoDirectoryBytes) !=
kIcoDirectoryBytes) {
- SkDebugf("Error: unable to read ico directory header.\n");
+ SkCodecPrintf("Error: unable to read ico directory header.\n");
return NULL;
}
// Process the directory header
const uint16_t numImages = get_short(dirBuffer.get(), 4);
if (0 == numImages) {
- SkDebugf("Error: No images embedded in ico.\n");
+ SkCodecPrintf("Error: No images embedded in ico.\n");
return NULL;
}
@@ -61,7 +61,7 @@
SkNEW_ARRAY(uint8_t, numImages*kIcoDirEntryBytes));
if (inputStream.get()->read(entryBuffer.get(), numImages*kIcoDirEntryBytes) !=
numImages*kIcoDirEntryBytes) {
- SkDebugf("Error: unable to read ico directory entries.\n");
+ SkCodecPrintf("Error: unable to read ico directory entries.\n");
return NULL;
}
@@ -118,14 +118,14 @@
// Ensure that the offset is valid
if (offset < bytesRead) {
- SkDebugf("Warning: invalid ico offset.\n");
+ SkCodecPrintf("Warning: invalid ico offset.\n");
continue;
}
// If we cannot skip, assume we have reached the end of the stream and
// stop trying to make codecs
if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) {
- SkDebugf("Warning: could not skip to ico offset.\n");
+ SkCodecPrintf("Warning: could not skip to ico offset.\n");
break;
}
bytesRead = offset;
@@ -134,7 +134,7 @@
SkAutoTUnref<SkData> data(
SkData::NewFromStream(inputStream.get(), size));
if (NULL == data.get()) {
- SkDebugf("Warning: could not create embedded stream.\n");
+ SkCodecPrintf("Warning: could not create embedded stream.\n");
break;
}
SkAutoTDelete<SkMemoryStream>
@@ -159,7 +159,7 @@
// Recognize if there are no valid codecs
if (0 == codecs->count()) {
- SkDebugf("Error: could not find any valid embedded ico codecs.\n");
+ SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n");
return NULL;
}
@@ -244,7 +244,7 @@
// On a fatal error, keep trying to find an image to decode
if (kInvalidConversion == result || kInvalidInput == result ||
kInvalidScale == result) {
- SkDebugf("Warning: Attempt to decode candidate ico failed.\n");
+ SkCodecPrintf("Warning: Attempt to decode candidate ico failed.\n");
continue;
}
@@ -253,6 +253,6 @@
}
}
- SkDebugf("Error: No matching candidate image in ico.\n");
+ SkCodecPrintf("Error: No matching candidate image in ico.\n");
return result;
}
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp
index 8c0b624..8f2bdd3 100644
--- a/src/codec/SkCodec_libpng.cpp
+++ b/src/codec/SkCodec_libpng.cpp
@@ -46,7 +46,7 @@
///////////////////////////////////////////////////////////////////////////////
static void sk_error_fn(png_structp png_ptr, png_const_charp msg) {
- SkDebugf("------ png error %s\n", msg);
+ SkCodecPrintf("------ png error %s\n", msg);
longjmp(png_jmpbuf(png_ptr), 1);
}
@@ -369,7 +369,7 @@
// FIXME: Could we use the return value of setjmp to specify the type of
// error?
if (setjmp(png_jmpbuf(fPng_ptr))) {
- SkDebugf("setjmp long jump!\n");
+ SkCodecPrintf("setjmp long jump!\n");
return kInvalidInput;
}
@@ -436,7 +436,7 @@
// FIXME: Could we use the return value of setjmp to specify the type of
// error?
if (setjmp(png_jmpbuf(fPng_ptr))) {
- SkDebugf("setjmp long jump!\n");
+ SkCodecPrintf("setjmp long jump!\n");
return kInvalidInput;
}
@@ -505,7 +505,7 @@
SkImageGenerator::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
- SkDebugf("setjmp long jump!\n");
+ SkCodecPrintf("setjmp long jump!\n");
return SkImageGenerator::kInvalidInput;
}
@@ -522,7 +522,7 @@
// FIXME: Could we use the return value of setjmp to specify the type of
// error?
if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
- SkDebugf("setjmp long jump!\n");
+ SkCodecPrintf("setjmp long jump!\n");
return SkImageGenerator::kInvalidInput;
}
@@ -552,7 +552,7 @@
}
if (!conversion_possible(dstInfo, this->getInfo())) {
- SkDebugf("no conversion possible\n");
+ SkCodecPrintf("no conversion possible\n");
return NULL;
}
@@ -563,7 +563,7 @@
// FIXME: Pass this in to getScanlineDecoder?
opts.fZeroInitialized = kNo_ZeroInitialized;
if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opts) != kSuccess) {
- SkDebugf("failed to initialize the swizzler.\n");
+ SkCodecPrintf("failed to initialize the swizzler.\n");
return NULL;
}
diff --git a/src/codec/SkMasks.cpp b/src/codec/SkMasks.cpp
index 1c542ce..4b32c61 100644
--- a/src/codec/SkMasks.cpp
+++ b/src/codec/SkMasks.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkCodecPriv.h"
#include "SkMasks.h"
#include "SkTypes.h"
@@ -106,7 +107,7 @@
}
// Check that the mask is continuous
if (tempMask != 0) {
- SkDebugf("Warning: Bit masks is not continuous.\n");
+ SkCodecPrintf("Warning: Bit masks is not continuous.\n");
}
// Truncate masks greater than 8 bits
if (size > 8) {