#include "RecordingBench.h"
#include "SKPAnimationBench.h"
#include "SKPBench.h"
-#include "SubsetSingleBench.h"
-#include "SubsetTranslateBench.h"
-#include "SubsetZoomBench.h"
#include "Stats.h"
#include "SkBitmapRegionDecoder.h"
return target;
}
-/*
- * We only run our subset benches on files that are supported by BitmapRegionDecoder:
- * 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) {
- static const char* const exts[] = {
- "jpg", "jpeg", "png",
- "JPG", "JPEG", "PNG",
- };
-
- for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
- if (path.endsWith(exts[i])) {
- return true;
- }
- }
-
- return false;
-}
-
-/*
- * 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,
- 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.
- 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();
-
- // Check if the image is large enough for a meaningful subset benchmark.
- if (*width <= 512 && *height <= 512) {
- // This should not print a message since it is not an error.
- return false;
- }
-
- return true;
-}
-
static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy strategy,
SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int* width,
int* height) {
, fCurrentUseMPD(0)
, fCurrentCodec(0)
, fCurrentImage(0)
- , fCurrentSubsetImage(0)
, fCurrentBRDImage(0)
, fCurrentColorType(0)
, fCurrentSubsetType(0)
fCurrentImage++;
}
- // Run the SubsetBenches
- while (fCurrentSubsetImage < fImages.count()) {
- fSourceType = "image";
- 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++;
- }
-
// Run the BRDBenches
// We will benchmark multiple BRD strategies.
static const struct {
int fCurrentUseMPD;
int fCurrentCodec;
int fCurrentImage;
- int fCurrentSubsetImage;
int fCurrentBRDImage;
int fCurrentColorType;
int fCurrentSubsetType;
+++ /dev/null
-/*
- * Copyright 2015 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SubsetBenchPriv_DEFINED
-#define SubsetBenchPriv_DEFINED
-
-#include "SkCodec.h"
-#include "SkData.h"
-#include "SkImageGenerator.h"
-
-/*
- * If we plan to decode to kIndex8, we must create a color table and pass it to the
- * bitmap when we allocate pixels. Otherwise, we simply allocate pixels using the
- * decode info.
- */
-static inline void alloc_pixels(SkBitmap* bitmap, const SkImageInfo& info, SkPMColor* colors,
- int colorCount) {
- if (kIndex_8_SkColorType == info.colorType()) {
- SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, colorCount));
- bitmap->allocPixels(info, nullptr, colorTable);
- } else {
- bitmap->allocPixels(info);
- }
-}
-
-#endif // SubsetBenchPriv_DEFINED
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "CodecBenchPriv.h"
-#include "SubsetSingleBench.h"
-#include "SubsetBenchPriv.h"
-#include "SkData.h"
-#include "SkCodec.h"
-#include "SkImageDecoder.h"
-#include "SkOSFile.h"
-#include "SkStream.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * It uses an input width, height, left, and top to decode a single subset.
- *
- */
-
-SubsetSingleBench::SubsetSingleBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight,
- uint32_t offsetLeft,
- uint32_t offsetTop)
- : fColorType(colorType)
- , fSubsetWidth(subsetWidth)
- , fSubsetHeight(subsetHeight)
- , fOffsetLeft(offsetLeft)
- , fOffsetTop(offsetTop)
-{
- // Parse the filename
- SkString baseName = SkOSPath::Basename(path.c_str());
-
- // Choose an informative color name
- const char* colorName = color_type_to_str(fColorType);
-
- fName.printf("CodecSubsetSingle_%dx%d +%d_+%d_%s_%s", fSubsetWidth,
- fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName);
-
- // Perform the decode setup
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
- fStream.reset(new SkMemoryStream(encoded));
-}
-
-const char* SubsetSingleBench::onGetName() {
- return fName.c_str();
-}
-
-bool SubsetSingleBench::isSuitableFor(Backend backend) {
- return kNonRendering_Backend == backend;
-}
-
-void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) {
- // When the color type is kIndex8, we will need to store the color table. If it is
- // used, it will be initialized by the codec.
- int colorCount;
- SkPMColor colors[256];
- 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 = ⊂
-
- 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);
-
- SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop);
- SkASSERT(success);
-
- SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(), fSubsetHeight,
- bitmap.rowBytes());
- SkASSERT(lines == fSubsetHeight);
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkImageDecoder.h"
-#include "SkImageInfo.h"
-#include "SkStream.h"
-#include "SkString.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * It uses an input width, height, left, and top to decode a single subset.
- *
- */
-class SubsetSingleBench : public Benchmark {
-public:
-
- SubsetSingleBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight,
- uint32_t offsetLeft,
- uint32_t offsetTop);
-
-protected:
- const char* onGetName() override;
- bool isSuitableFor(Backend backend) override;
- void onDraw(int n, SkCanvas* canvas) override;
-
-private:
- SkString fName;
- SkColorType fColorType;
- const uint32_t fSubsetWidth;
- const uint32_t fSubsetHeight;
- const uint32_t fOffsetLeft;
- const uint32_t fOffsetTop;
- SkAutoTDelete<SkMemoryStream> fStream;
- typedef Benchmark INHERITED;
-};
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "CodecBenchPriv.h"
-#include "SubsetTranslateBench.h"
-#include "SubsetBenchPriv.h"
-#include "SkData.h"
-#include "SkCodec.h"
-#include "SkImageDecoder.h"
-#include "SkOSFile.h"
-#include "SkStream.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * It uses input dimensions to decode the entire image where each block is susbetW x subsetH.
- *
- */
-
-SubsetTranslateBench::SubsetTranslateBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight)
- : fColorType(colorType)
- , fSubsetWidth(subsetWidth)
- , fSubsetHeight(subsetHeight)
-{
- // Parse the filename
- SkString baseName = SkOSPath::Basename(path.c_str());
-
- // Choose an informative color name
- const char* colorName = color_type_to_str(fColorType);
-
- fName.printf("CodecSubsetTranslate_%dx%d_%s_%s", fSubsetWidth,
- fSubsetHeight, baseName.c_str(), colorName);
-
- // Perform the decode setup
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
- fStream.reset(new SkMemoryStream(encoded));
-}
-
-const char* SubsetTranslateBench::onGetName() {
- return fName.c_str();
-}
-
-bool SubsetTranslateBench::isSuitableFor(Backend backend) {
- return kNonRendering_Backend == backend;
-}
-
-// Allows allocating the bitmap first, and then writing to them later (in startScanlineDecode)
-static SkPMColor* get_colors(SkBitmap* bm) {
- SkColorTable* ct = bm->getColorTable();
- if (!ct) {
- return nullptr;
- }
-
- return const_cast<SkPMColor*>(ct->readColors());
-}
-
-void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) {
- // When the color type is kIndex8, we will need to store the color table. If it is
- // used, it will be initialized by the codec.
- int colorCount = 256;
- SkPMColor colors[256];
- 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 = ⊂
-
- 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);
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkImageDecoder.h"
-#include "SkImageInfo.h"
-#include "SkStream.h"
-#include "SkString.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * It uses input dimensions to decode the entire image where each block is susbetW x subsetH.
- *
- */
-class SubsetTranslateBench : public Benchmark {
-public:
-
- SubsetTranslateBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight);
-
-protected:
- const char* onGetName() override;
- bool isSuitableFor(Backend backend) override;
- void onDraw(int n, SkCanvas* canvas) override;
-
-private:
- SkString fName;
- SkColorType fColorType;
- const uint32_t fSubsetWidth;
- const uint32_t fSubsetHeight;
- SkAutoTDelete<SkMemoryStream> fStream;
- typedef Benchmark INHERITED;
-};
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "CodecBenchPriv.h"
-#include "SubsetZoomBench.h"
-#include "SubsetBenchPriv.h"
-#include "SkData.h"
-#include "SkCodec.h"
-#include "SkImageDecoder.h"
-#include "SkOSFile.h"
-#include "SkStream.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * Choose subsets to mimic a user zooming in or out on a photo.
- *
- */
-
-SubsetZoomBench::SubsetZoomBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight)
- : fColorType(colorType)
- , fSubsetWidth(subsetWidth)
- , fSubsetHeight(subsetHeight)
-{
- // Parse the filename
- SkString baseName = SkOSPath::Basename(path.c_str());
-
- // Choose an informative color name
- const char* colorName = color_type_to_str(fColorType);
-
- fName.printf("CodecSubsetZoom_%dx%d_%s_%s", fSubsetWidth,
- fSubsetHeight, baseName.c_str(), colorName);
-
- // Perform the decode setup
- SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
- fStream.reset(new SkMemoryStream(encoded));
-}
-
-const char* SubsetZoomBench::onGetName() {
- return fName.c_str();
-}
-
-bool SubsetZoomBench::isSuitableFor(Backend backend) {
- return kNonRendering_Backend == backend;
-}
-
-void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) {
- // When the color type is kIndex8, we will need to store the color table. If it is
- // used, it will be initialized by the codec.
- int colorCount;
- SkPMColor colors[256];
- 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 = ⊂
-
- 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());
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkImageDecoder.h"
-#include "SkImageInfo.h"
-#include "SkStream.h"
-#include "SkString.h"
-
-/*
- *
- * This benchmark is designed to test the performance of subset decoding.
- * Choose subsets to mimic a user zooming in or out on a photo.
- *
- */
-class SubsetZoomBench : public Benchmark {
-public:
-
- SubsetZoomBench(const SkString& path,
- SkColorType colorType,
- uint32_t subsetWidth,
- uint32_t subsetHeight);
-
-protected:
- const char* onGetName() override;
- bool isSuitableFor(Backend backend) override;
- void onDraw(int n, SkCanvas* canvas) override;
-
-private:
- SkString fName;
- SkColorType fColorType;
- const uint32_t fSubsetWidth;
- const uint32_t fSubsetHeight;
- SkAutoTDelete<SkMemoryStream> fStream;
- typedef Benchmark INHERITED;
-};