2015-06-09 20:56:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-09-22 18:56:16 +00:00
|
|
|
#include "CodecBenchPriv.h"
|
2015-06-09 20:56:10 +00:00
|
|
|
#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,
|
|
|
|
bool useCodec)
|
|
|
|
: fColorType(colorType)
|
|
|
|
, fSubsetWidth(subsetWidth)
|
|
|
|
, fSubsetHeight(subsetHeight)
|
|
|
|
, fOffsetLeft(offsetLeft)
|
|
|
|
, fOffsetTop(offsetTop)
|
|
|
|
, fUseCodec(useCodec)
|
|
|
|
{
|
|
|
|
// Parse the filename
|
|
|
|
SkString baseName = SkOSPath::Basename(path.c_str());
|
|
|
|
|
|
|
|
// Choose an informative color name
|
2015-09-22 18:56:16 +00:00
|
|
|
const char* colorName = color_type_to_str(fColorType);
|
2015-06-09 20:56:10 +00:00
|
|
|
|
|
|
|
fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Image", 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;
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) {
|
2015-06-09 20:56:10 +00:00
|
|
|
// 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];
|
|
|
|
if (fUseCodec) {
|
|
|
|
for (int count = 0; count < n; count++) {
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
|
|
|
|
const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
|
2015-10-08 19:01:39 +00:00
|
|
|
|
|
|
|
SkDEBUGCODE(SkCodec::Result result =)
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
codec->startScanlineDecode(info, nullptr, colors, &colorCount);
|
2015-10-08 19:01:39 +00:00
|
|
|
SkASSERT(result == SkCodec::kSuccess);
|
2015-06-09 20:56:10 +00:00
|
|
|
|
|
|
|
SkBitmap bitmap;
|
2015-06-30 20:29:37 +00:00
|
|
|
SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
|
|
|
|
alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
|
2015-06-09 20:56:10 +00:00
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
SkDEBUGCODE(int lines = ) codec->skipScanlines(fOffsetTop);
|
|
|
|
SkASSERT((uint32_t) lines == fOffsetTop);
|
2015-10-08 19:01:39 +00:00
|
|
|
|
|
|
|
const uint32_t bpp = info.bytesPerPixel();
|
|
|
|
|
|
|
|
switch (codec->getScanlineOrder()) {
|
|
|
|
case SkCodec::kTopDown_SkScanlineOrder: {
|
|
|
|
SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
|
|
|
|
for (uint32_t y = 0; y < fSubsetHeight; y++) {
|
2015-10-09 18:07:34 +00:00
|
|
|
SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0);
|
|
|
|
SkASSERT(lines == 1);
|
2015-10-08 19:01:39 +00:00
|
|
|
|
|
|
|
memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp,
|
|
|
|
fSubsetWidth * bpp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkCodec::kNone_SkScanlineOrder: {
|
|
|
|
// decode all scanlines that intersect the subset, and copy the subset
|
|
|
|
// into the output.
|
|
|
|
SkImageInfo stripeInfo = info.makeWH(info.width(), fSubsetHeight);
|
|
|
|
SkBitmap stripeBm;
|
|
|
|
alloc_pixels(&stripeBm, stripeInfo, colors, colorCount);
|
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPixels(), fSubsetHeight,
|
2015-10-08 19:01:39 +00:00
|
|
|
stripeBm.rowBytes());
|
2015-10-09 18:07:34 +00:00
|
|
|
SkASSERT((uint32_t) lines == fSubsetHeight);
|
2015-10-08 19:01:39 +00:00
|
|
|
|
|
|
|
for (uint32_t y = 0; y < fSubsetHeight; y++) {
|
|
|
|
memcpy(bitmap.getAddr(0, y), stripeBm.getAddr(fOffsetLeft, y),
|
|
|
|
fSubsetWidth * bpp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// We currently are only testing kTopDown and kNone, which are the only
|
|
|
|
// two used by the subsets we care about. skbug.com/4428
|
|
|
|
SkASSERT(false);
|
|
|
|
|
2015-06-09 20:56:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int count = 0; count < n; count++) {
|
|
|
|
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
|
|
|
|
int width, height;
|
2015-10-08 19:01:39 +00:00
|
|
|
SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
|
2015-06-09 20:56:10 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWidth,
|
|
|
|
fSubsetHeight);
|
2015-10-08 19:01:39 +00:00
|
|
|
SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
|
2015-06-09 20:56:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|