aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/BitmapRegionDecoderBench.cpp3
-rw-r--r--bench/nanobench.cpp207
-rw-r--r--bench/subset/SubsetSingleBench.cpp58
-rw-r--r--bench/subset/SubsetSingleBench.h4
-rw-r--r--bench/subset/SubsetTranslateBench.cpp112
-rw-r--r--bench/subset/SubsetTranslateBench.h4
-rw-r--r--bench/subset/SubsetZoomBench.cpp113
-rw-r--r--bench/subset/SubsetZoomBench.h4
8 files changed, 176 insertions, 329 deletions
diff --git a/bench/BitmapRegionDecoderBench.cpp b/bench/BitmapRegionDecoderBench.cpp
index 1d2a0b91f7..4d9dec03aa 100644
--- a/bench/BitmapRegionDecoderBench.cpp
+++ b/bench/BitmapRegionDecoderBench.cpp
@@ -24,9 +24,6 @@ BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData*
// Choose a useful name for the region decoding strategy
const char* strategyName;
switch (strategy) {
- case SkBitmapRegionDecoder::kOriginal_Strategy:
- strategyName = "Original";
- break;
case SkBitmapRegionDecoder::kCanvas_Strategy:
strategyName = "Canvas";
break;
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 95d017c6da..0987cb7cfe 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -107,8 +107,6 @@ DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
-DEFINE_bool(pngBuildTileIndex, false, "If supported, use png buildTileIndex/decodeSubset.");
-DEFINE_bool(jpgBuildTileIndex, false, "If supported, use jpg buildTileIndex/decodeSubset.");
static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
@@ -499,35 +497,22 @@ static Target* is_enabled(Benchmark* bench, const Config& config) {
/*
* We only run our subset benches on files that are supported by BitmapRegionDecoder:
- * i.e. PNG, JPEG, and WEBP. We do *not* test WEBP when using codec, since we do not
- * have a scanline decoder for WEBP, which is necessary for running the subset bench.
- * (Another bench must be used to test WEBP, which decodes subsets natively.)
+ * i.e. PNG, JPEG, and WEBP. We do *not* test WEBP, since we do not have a scanline
+ * decoder for WEBP, which is necessary for running the subset bench. (Another bench
+ * must be used to test WEBP, which decodes subsets natively.)
*/
-static bool run_subset_bench(const SkString& path, bool useCodec) {
+static bool run_subset_bench(const SkString& path) {
static const char* const exts[] = {
- "jpg", "jpeg",
- "JPG", "JPEG",
+ "jpg", "jpeg", "png",
+ "JPG", "JPEG", "PNG",
};
- if (useCodec || FLAGS_jpgBuildTileIndex) {
- for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
- if (path.endsWith(exts[i])) {
- return true;
- }
+ for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
+ if (path.endsWith(exts[i])) {
+ return true;
}
}
- // Test png in SkCodec, and optionally on SkImageDecoder. SkImageDecoder is
- // disabled by default because it leaks memory.
- // https://bug.skia.org/4360
- if ((useCodec || FLAGS_pngBuildTileIndex) && (path.endsWith("png") || path.endsWith("PNG"))) {
- return true;
- }
-
- if (!useCodec && (path.endsWith("webp") || path.endsWith("WEBP"))) {
- return true;
- }
-
return false;
}
@@ -535,49 +520,31 @@ static bool run_subset_bench(const SkString& path, bool useCodec) {
* Returns true if set up for a subset decode succeeds, false otherwise
* If the set-up succeeds, the width and height parameters will be set
*/
-static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec,
+static bool valid_subset_bench(const SkString& path, SkColorType colorType,
int* width, int* height) {
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
- // Check that we can create a codec or image decoder.
- if (useCodec) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
- if (nullptr == codec) {
- SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str());
- return false;
- }
+ // Check that we can create a codec.
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
+ if (nullptr == codec) {
+ SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str());
+ return false;
+ }
- // These will be initialized by SkCodec if the color type is kIndex8 and
- // unused otherwise.
- SkPMColor colors[256];
- int colorCount;
- const SkImageInfo info = codec->getInfo().makeColorType(colorType);
- if (codec->startScanlineDecode(info, nullptr, colors, &colorCount) != SkCodec::kSuccess)
- {
- SkDebugf("Could not create scanline decoder for %s with color type %s. "
- "Skipping bench.\n", path.c_str(), color_type_to_str(colorType));
- return false;
- }
- *width = info.width();
- *height = info.height();
- } else {
- SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
- if (nullptr == decoder) {
- SkDebugf("Could not create decoder for %s. Skipping bench.\n", path.c_str());
- return false;
- }
- //FIXME: See https://bug.skia.org/3921
- if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) {
- SkDebugf("Cannot use image subset decoder for %s with color type %s. "
- "Skipping bench.\n", path.c_str(), color_type_to_str(colorType));
- return false;
- }
- if (!decoder->buildTileIndex(stream.detach(), width, height)) {
- SkDebugf("Could not build tile index for %s. Skipping bench.\n", path.c_str());
- return false;
- }
+ // These will be initialized by SkCodec if the color type is kIndex8 and
+ // unused otherwise.
+ SkPMColor colors[256];
+ int colorCount;
+ const SkImageInfo info = codec->getInfo().makeColorType(colorType);
+ if (codec->startScanlineDecode(info, nullptr, colors, &colorCount) != SkCodec::kSuccess)
+ {
+ SkDebugf("Could not create scanline decoder for %s with color type %s. "
+ "Skipping bench.\n", path.c_str(), color_type_to_str(colorType));
+ return false;
}
+ *width = info.width();
+ *height = info.height();
// Check if the image is large enough for a meaningful subset benchmark.
if (*width <= 512 && *height <= 512) {
@@ -603,11 +570,6 @@ static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy str
1, colorType, false)) {
return false;
}
- if (colorType != bitmap.colorType()) {
- // This indicates that conversion to the requested color type is not supported for the
- // particular image.
- return false;
- }
if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize >
(uint32_t) brd->height()) {
@@ -648,7 +610,6 @@ public:
, fCurrentBRDImage(0)
, fCurrentColorType(0)
, fCurrentSubsetType(0)
- , fUseCodec(0)
, fCurrentBRDStrategy(0)
, fCurrentBRDSampleSize(0)
, fCurrentAnimSKP(0) {
@@ -898,69 +859,60 @@ public:
}
// Run the SubsetBenches
- bool useCodecOpts[] = { true, false };
- while (fUseCodec < 2) {
- bool useCodec = useCodecOpts[fUseCodec];
+ while (fCurrentSubsetImage < fImages.count()) {
fSourceType = "image";
- fBenchType = useCodec ? "skcodec" : "skimagedecoder";
- while (fCurrentSubsetImage < fImages.count()) {
- const SkString& path = fImages[fCurrentSubsetImage];
- if (!run_subset_bench(path, useCodec)) {
- fCurrentSubsetImage++;
- continue;
- }
- while (fCurrentColorType < fColorTypes.count()) {
- SkColorType colorType = fColorTypes[fCurrentColorType];
- while (fCurrentSubsetType <= kLast_SubsetType) {
- int width = 0;
- int height = 0;
- int currentSubsetType = fCurrentSubsetType++;
- if (valid_subset_bench(path, colorType, useCodec, &width, &height)) {
- switch (currentSubsetType) {
- case kTopLeft_SubsetType:
- return new SubsetSingleBench(path, colorType, width/3,
- height/3, 0, 0, useCodec);
- case kTopRight_SubsetType:
- return new SubsetSingleBench(path, colorType, width/3,
- height/3, 2*width/3, 0, useCodec);
- case kMiddle_SubsetType:
- return new SubsetSingleBench(path, colorType, width/3,
- height/3, width/3, height/3, useCodec);
- case kBottomLeft_SubsetType:
- return new SubsetSingleBench(path, colorType, width/3,
- height/3, 0, 2*height/3, useCodec);
- case kBottomRight_SubsetType:
- return new SubsetSingleBench(path, colorType, width/3,
- height/3, 2*width/3, 2*height/3, useCodec);
- case kTranslate_SubsetType:
- return new SubsetTranslateBench(path, colorType, 512, 512,
- useCodec);
- case kZoom_SubsetType:
- return new SubsetZoomBench(path, colorType, 512, 512,
- useCodec);
- }
- } else {
- break;
+ fBenchType = "skcodec";
+ const SkString& path = fImages[fCurrentSubsetImage];
+ if (!run_subset_bench(path)) {
+ fCurrentSubsetImage++;
+ continue;
+ }
+ while (fCurrentColorType < fColorTypes.count()) {
+ SkColorType colorType = fColorTypes[fCurrentColorType];
+ while (fCurrentSubsetType <= kLast_SubsetType) {
+ int width = 0;
+ int height = 0;
+ int currentSubsetType = fCurrentSubsetType++;
+ if (valid_subset_bench(path, colorType, &width, &height)) {
+ switch (currentSubsetType) {
+ case kTopLeft_SubsetType:
+ return new SubsetSingleBench(path, colorType, width/3,
+ height/3, 0, 0);
+ case kTopRight_SubsetType:
+ return new SubsetSingleBench(path, colorType, width/3,
+ height/3, 2*width/3, 0);
+ case kMiddle_SubsetType:
+ return new SubsetSingleBench(path, colorType, width/3,
+ height/3, width/3, height/3);
+ case kBottomLeft_SubsetType:
+ return new SubsetSingleBench(path, colorType, width/3,
+ height/3, 0, 2*height/3);
+ case kBottomRight_SubsetType:
+ return new SubsetSingleBench(path, colorType, width/3,
+ height/3, 2*width/3, 2*height/3);
+ case kTranslate_SubsetType:
+ return new SubsetTranslateBench(path, colorType, 512, 512);
+ case kZoom_SubsetType:
+ return new SubsetZoomBench(path, colorType, 512, 512);
}
+ } else {
+ break;
}
- fCurrentSubsetType = 0;
- fCurrentColorType++;
}
- fCurrentColorType = 0;
- fCurrentSubsetImage++;
+ fCurrentSubsetType = 0;
+ fCurrentColorType++;
}
- fCurrentSubsetImage = 0;
- fUseCodec++;
+ fCurrentColorType = 0;
+ fCurrentSubsetImage++;
}
// Run the BRDBenches
// We will benchmark multiple BRD strategies.
static const struct {
SkBitmapRegionDecoder::Strategy fStrategy;
- const char* fName;
+ const char* fName;
} strategies[] = {
- { SkBitmapRegionDecoder::kOriginal_Strategy, "BRD" },
- { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" },
+ { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" },
{ SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec" },
};
@@ -989,24 +941,6 @@ public:
const SkBitmapRegionDecoder::Strategy strategy =
strategies[fCurrentBRDStrategy].fStrategy;
- if (SkBitmapRegionDecoder::kOriginal_Strategy == strategy) {
- // Disable png and jpeg for SkImageDecoder:
- if (!FLAGS_jpgBuildTileIndex) {
- if (path.endsWith("JPEG") || path.endsWith("JPG") ||
- path.endsWith("jpeg") || path.endsWith("jpg"))
- {
- fCurrentBRDStrategy++;
- continue;
- }
- }
- if (!FLAGS_pngBuildTileIndex) {
- if (path.endsWith("PNG") || path.endsWith("png")) {
- fCurrentBRDStrategy++;
- continue;
- }
- }
- }
-
while (fCurrentColorType < fColorTypes.count()) {
while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) {
while (fCurrentSubsetType <= kLastSingle_SubsetType) {
@@ -1133,7 +1067,6 @@ private:
int fCurrentBRDImage;
int fCurrentColorType;
int fCurrentSubsetType;
- int fUseCodec;
int fCurrentBRDStrategy;
int fCurrentBRDSampleSize;
int fCurrentAnimSKP;
diff --git a/bench/subset/SubsetSingleBench.cpp b/bench/subset/SubsetSingleBench.cpp
index 47a897fd83..e30dd51e78 100644
--- a/bench/subset/SubsetSingleBench.cpp
+++ b/bench/subset/SubsetSingleBench.cpp
@@ -26,14 +26,12 @@ SubsetSingleBench::SubsetSingleBench(const SkString& path,
uint32_t subsetWidth,
uint32_t subsetHeight,
uint32_t offsetLeft,
- uint32_t offsetTop,
- bool useCodec)
+ uint32_t offsetTop)
: fColorType(colorType)
, fSubsetWidth(subsetWidth)
, fSubsetHeight(subsetHeight)
, fOffsetLeft(offsetLeft)
, fOffsetTop(offsetTop)
- , fUseCodec(useCodec)
{
// Parse the filename
SkString baseName = SkOSPath::Basename(path.c_str());
@@ -41,7 +39,7 @@ SubsetSingleBench::SubsetSingleBench(const SkString& path,
// Choose an informative color name
const char* colorName = color_type_to_str(fColorType);
- fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth,
+ fName.printf("CodecSubsetSingle_%dx%d +%d_+%d_%s_%s", fSubsetWidth,
fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName);
// Perform the decode setup
@@ -62,42 +60,30 @@ void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) {
// used, it will be initialized by the codec.
int colorCount;
SkPMColor colors[256];
- if (fUseCodec) {
- for (int count = 0; count < n; count++) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
- SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
- const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
+ SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
+ const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
- // The scanline decoder will handle subsetting in the x-dimension.
- SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth,
- codec->getInfo().height());
- SkCodec::Options options;
- options.fSubset = &subset;
+ // The scanline decoder will handle subsetting in the x-dimension.
+ SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth,
+ codec->getInfo().height());
+ SkCodec::Options options;
+ options.fSubset = &subset;
- SkDEBUGCODE(SkCodec::Result result =)
- codec->startScanlineDecode(info, &options, colors, &colorCount);
- SkASSERT(result == SkCodec::kSuccess);
+ SkDEBUGCODE(SkCodec::Result result =)
+ codec->startScanlineDecode(info, &options, colors, &colorCount);
+ SkASSERT(result == SkCodec::kSuccess);
- SkBitmap bitmap;
- SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
- alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
+ SkBitmap bitmap;
+ SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
- SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop);
- SkASSERT(success);
+ SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop);
+ SkASSERT(success);
- SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(), fSubsetHeight,
- bitmap.rowBytes());
- SkASSERT(lines == fSubsetHeight);
- }
- } else {
- for (int count = 0; count < n; count++) {
- SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
- int width, height;
- SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
- SkBitmap bitmap;
- SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWidth,
- fSubsetHeight);
- SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
- }
+ SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(), fSubsetHeight,
+ bitmap.rowBytes());
+ SkASSERT(lines == fSubsetHeight);
}
}
diff --git a/bench/subset/SubsetSingleBench.h b/bench/subset/SubsetSingleBench.h
index 62e281ad67..da325ac429 100644
--- a/bench/subset/SubsetSingleBench.h
+++ b/bench/subset/SubsetSingleBench.h
@@ -25,8 +25,7 @@ public:
uint32_t subsetWidth,
uint32_t subsetHeight,
uint32_t offsetLeft,
- uint32_t offsetTop,
- bool useCodec);
+ uint32_t offsetTop);
protected:
const char* onGetName() override;
@@ -40,7 +39,6 @@ private:
const uint32_t fSubsetHeight;
const uint32_t fOffsetLeft;
const uint32_t fOffsetTop;
- const bool fUseCodec;
SkAutoTDelete<SkMemoryStream> fStream;
typedef Benchmark INHERITED;
};
diff --git a/bench/subset/SubsetTranslateBench.cpp b/bench/subset/SubsetTranslateBench.cpp
index d8da6db566..bcf1227454 100644
--- a/bench/subset/SubsetTranslateBench.cpp
+++ b/bench/subset/SubsetTranslateBench.cpp
@@ -24,12 +24,10 @@
SubsetTranslateBench::SubsetTranslateBench(const SkString& path,
SkColorType colorType,
uint32_t subsetWidth,
- uint32_t subsetHeight,
- bool useCodec)
+ uint32_t subsetHeight)
: fColorType(colorType)
, fSubsetWidth(subsetWidth)
, fSubsetHeight(subsetHeight)
- , fUseCodec(useCodec)
{
// Parse the filename
SkString baseName = SkOSPath::Basename(path.c_str());
@@ -37,7 +35,7 @@ SubsetTranslateBench::SubsetTranslateBench(const SkString& path,
// Choose an informative color name
const char* colorName = color_type_to_str(fColorType);
- fName.printf("%sSubsetTranslate_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth,
+ fName.printf("CodecSubsetTranslate_%dx%d_%s_%s", fSubsetWidth,
fSubsetHeight, baseName.c_str(), colorName);
// Perform the decode setup
@@ -68,76 +66,42 @@ void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) {
// used, it will be initialized by the codec.
int colorCount = 256;
SkPMColor colors[256];
- if (fUseCodec) {
- for (int count = 0; count < n; count++) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
- SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
- const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
-
- SkBitmap bitmap;
- // Note that we use the same bitmap for all of the subsets.
- // It might be larger than necessary for the end subsets.
- SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
- alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
-
- for (int x = 0; x < info.width(); x += fSubsetWidth) {
- for (int y = 0; y < info.height(); y += fSubsetHeight) {
- const uint32_t currSubsetWidth =
- x + (int) fSubsetWidth > info.width() ?
- info.width() - x : fSubsetWidth;
- const uint32_t currSubsetHeight =
- y + (int) fSubsetHeight > info.height() ?
- info.height() - y : fSubsetHeight;
-
- // The scanline decoder will handle subsetting in the x-dimension.
- SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth,
- codec->getInfo().height());
- SkCodec::Options options;
- options.fSubset = &subset;
-
- SkDEBUGCODE(SkCodec::Result result =)
- codec->startScanlineDecode(info, &options, get_colors(&bitmap), &colorCount);
- SkASSERT(SkCodec::kSuccess == result);
-
- SkDEBUGCODE(bool success =) codec->skipScanlines(y);
- SkASSERT(success);
-
- SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.getPixels(),
- currSubsetHeight, bitmap.rowBytes());
- SkASSERT(currSubsetHeight == lines);
- }
- }
- }
- } else {
- // We create a color table here to satisfy allocPixels() when the output
- // type is kIndex8. It's okay that this is uninitialized since we never
- // use it.
- SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 0));
- for (int count = 0; count < n; count++) {
- int width, height;
- SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
- SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
- SkBitmap bitmap;
- // Note that we use the same bitmap for all of the subsets.
- // It might be larger than necessary for the end subsets.
- // If we do not include this step, decodeSubset() would allocate space
- // for the pixels automatically, but this would not allow us to reuse the
- // same bitmap as the other subsets. We want to reuse the same bitmap
- // because it gives a more fair comparison with SkCodec and is a common
- // use case of BitmapRegionDecoder.
- bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight,
- fColorType, kOpaque_SkAlphaType), nullptr, colorTable);
-
- for (int x = 0; x < width; x += fSubsetWidth) {
- for (int y = 0; y < height; y += fSubsetHeight) {
- const uint32_t currSubsetWidth = x + (int) fSubsetWidth > width ?
- width - x : fSubsetWidth;
- const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ?
- height - y : fSubsetHeight;
- SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth,
- currSubsetHeight);
- SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
- }
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
+ SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
+ const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
+
+ SkBitmap bitmap;
+ // Note that we use the same bitmap for all of the subsets.
+ // It might be larger than necessary for the end subsets.
+ SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
+
+ for (int x = 0; x < info.width(); x += fSubsetWidth) {
+ for (int y = 0; y < info.height(); y += fSubsetHeight) {
+ const uint32_t currSubsetWidth =
+ x + (int) fSubsetWidth > info.width() ?
+ info.width() - x : fSubsetWidth;
+ const uint32_t currSubsetHeight =
+ y + (int) fSubsetHeight > info.height() ?
+ info.height() - y : fSubsetHeight;
+
+ // The scanline decoder will handle subsetting in the x-dimension.
+ SkIRect subset = SkIRect::MakeXYWH(x, 0, currSubsetWidth,
+ codec->getInfo().height());
+ SkCodec::Options options;
+ options.fSubset = &subset;
+
+ SkDEBUGCODE(SkCodec::Result result =)
+ codec->startScanlineDecode(info, &options, get_colors(&bitmap), &colorCount);
+ SkASSERT(SkCodec::kSuccess == result);
+
+ SkDEBUGCODE(bool success =) codec->skipScanlines(y);
+ SkASSERT(success);
+
+ SkDEBUGCODE(uint32_t lines =) codec->getScanlines(bitmap.getPixels(),
+ currSubsetHeight, bitmap.rowBytes());
+ SkASSERT(currSubsetHeight == lines);
}
}
}
diff --git a/bench/subset/SubsetTranslateBench.h b/bench/subset/SubsetTranslateBench.h
index 298732c851..49682d37c7 100644
--- a/bench/subset/SubsetTranslateBench.h
+++ b/bench/subset/SubsetTranslateBench.h
@@ -23,8 +23,7 @@ public:
SubsetTranslateBench(const SkString& path,
SkColorType colorType,
uint32_t subsetWidth,
- uint32_t subsetHeight,
- bool useCodec);
+ uint32_t subsetHeight);
protected:
const char* onGetName() override;
@@ -36,7 +35,6 @@ private:
SkColorType fColorType;
const uint32_t fSubsetWidth;
const uint32_t fSubsetHeight;
- const bool fUseCodec;
SkAutoTDelete<SkMemoryStream> fStream;
typedef Benchmark INHERITED;
};
diff --git a/bench/subset/SubsetZoomBench.cpp b/bench/subset/SubsetZoomBench.cpp
index f17a97c26b..1712595d7a 100644
--- a/bench/subset/SubsetZoomBench.cpp
+++ b/bench/subset/SubsetZoomBench.cpp
@@ -24,12 +24,10 @@
SubsetZoomBench::SubsetZoomBench(const SkString& path,
SkColorType colorType,
uint32_t subsetWidth,
- uint32_t subsetHeight,
- bool useCodec)
+ uint32_t subsetHeight)
: fColorType(colorType)
, fSubsetWidth(subsetWidth)
, fSubsetHeight(subsetHeight)
- , fUseCodec(useCodec)
{
// Parse the filename
SkString baseName = SkOSPath::Basename(path.c_str());
@@ -37,7 +35,7 @@ SubsetZoomBench::SubsetZoomBench(const SkString& path,
// Choose an informative color name
const char* colorName = color_type_to_str(fColorType);
- fName.printf("%sSubsetZoom_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth,
+ fName.printf("CodecSubsetZoom_%dx%d_%s_%s", fSubsetWidth,
fSubsetHeight, baseName.c_str(), colorName);
// Perform the decode setup
@@ -58,71 +56,46 @@ void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) {
// used, it will be initialized by the codec.
int colorCount;
SkPMColor colors[256];
- if (fUseCodec) {
- for (int count = 0; count < n; count++) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
- SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
- const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
-
- const int centerX = info.width() / 2;
- const int centerY = info.height() / 2;
- int w = fSubsetWidth;
- int h = fSubsetHeight;
- do {
- const int subsetStartX = SkTMax(0, centerX - w / 2);
- const int subsetStartY = SkTMax(0, centerY - h / 2);
- const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
- const int subsetHeight = SkTMin(h, info.height() - subsetStartY);
-
- // The scanline decoder will handle subsetting in the x-dimension.
- SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth,
- codec->getInfo().height());
- SkCodec::Options options;
- options.fSubset = &subset;
-
- SkDEBUGCODE(SkCodec::Result result = )
- codec->startScanlineDecode(info, &options, colors, &colorCount);
- SkASSERT(SkCodec::kSuccess == result);
-
- // Note that if we subsetted and scaled in a single step, we could use the
- // same bitmap - as is often done in actual use cases.
- SkBitmap bitmap;
- SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
- alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
-
- SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY);
- SkASSERT(success);
-
- SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(),
- subsetHeight, bitmap.rowBytes());
- SkASSERT(subsetHeight == lines);
-
- w <<= 1;
- h <<= 1;
- } while (w < 2 * info.width() || h < 2 * info.height());
- }
- } else {
- for (int count = 0; count < n; count++) {
- int width, height;
- SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
- SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
-
- const int centerX = width / 2;
- const int centerY = height / 2;
- int w = fSubsetWidth;
- int h = fSubsetHeight;
- do {
- const int subsetStartX = SkTMax(0, centerX - w / 2);
- const int subsetStartY = SkTMax(0, centerY - h / 2);
- const int subsetWidth = SkTMin(w, width - subsetStartX);
- const int subsetHeight = SkTMin(h, height - subsetStartY);
- SkBitmap bitmap;
- SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, subsetWidth,
- subsetHeight);
- SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
- w <<= 1;
- h <<= 1;
- } while (w < 2 * width || h < 2 * height);
- }
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
+ SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder());
+ const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
+
+ const int centerX = info.width() / 2;
+ const int centerY = info.height() / 2;
+ int w = fSubsetWidth;
+ int h = fSubsetHeight;
+ do {
+ const int subsetStartX = SkTMax(0, centerX - w / 2);
+ const int subsetStartY = SkTMax(0, centerY - h / 2);
+ const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
+ const int subsetHeight = SkTMin(h, info.height() - subsetStartY);
+
+ // The scanline decoder will handle subsetting in the x-dimension.
+ SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth,
+ codec->getInfo().height());
+ SkCodec::Options options;
+ options.fSubset = &subset;
+
+ SkDEBUGCODE(SkCodec::Result result = )
+ codec->startScanlineDecode(info, &options, colors, &colorCount);
+ SkASSERT(SkCodec::kSuccess == result);
+
+ // Note that if we subsetted and scaled in a single step, we could use the
+ // same bitmap - as is often done in actual use cases.
+ SkBitmap bitmap;
+ SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
+
+ SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY);
+ SkASSERT(success);
+
+ SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(),
+ subsetHeight, bitmap.rowBytes());
+ SkASSERT(subsetHeight == lines);
+
+ w <<= 1;
+ h <<= 1;
+ } while (w < 2 * info.width() || h < 2 * info.height());
}
}
diff --git a/bench/subset/SubsetZoomBench.h b/bench/subset/SubsetZoomBench.h
index 7fba4af940..96e2eb1fc1 100644
--- a/bench/subset/SubsetZoomBench.h
+++ b/bench/subset/SubsetZoomBench.h
@@ -23,8 +23,7 @@ public:
SubsetZoomBench(const SkString& path,
SkColorType colorType,
uint32_t subsetWidth,
- uint32_t subsetHeight,
- bool useCodec);
+ uint32_t subsetHeight);
protected:
const char* onGetName() override;
@@ -36,7 +35,6 @@ private:
SkColorType fColorType;
const uint32_t fSubsetWidth;
const uint32_t fSubsetHeight;
- const bool fUseCodec;
SkAutoTDelete<SkMemoryStream> fStream;
typedef Benchmark INHERITED;
};