2013-06-14 15:33:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkData.h"
|
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ImageDecodeBench : public Benchmark {
|
2013-06-14 15:33:20 +00:00
|
|
|
public:
|
|
|
|
ImageDecodeBench(void* p, const char* filename)
|
2013-09-13 19:52:27 +00:00
|
|
|
: fName("image_decode_")
|
2013-06-14 15:33:20 +00:00
|
|
|
, fFilename(filename)
|
|
|
|
, fStream()
|
|
|
|
, fValid(false) {
|
2014-07-29 02:26:58 +00:00
|
|
|
fName.append(SkOSPath::Basename(filename));
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2013-06-14 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onPreDraw() SK_OVERRIDE {
|
|
|
|
SkFILEStream fileStream(fFilename.c_str());
|
|
|
|
fValid = fileStream.isValid() && fileStream.getLength() > 0;
|
|
|
|
if (fValid) {
|
|
|
|
const size_t size = fileStream.getLength();
|
|
|
|
void* data = sk_malloc_throw(size);
|
|
|
|
if (fileStream.read(data, size) < size) {
|
|
|
|
fValid = false;
|
|
|
|
} else {
|
|
|
|
SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size));
|
|
|
|
fStream.setData(skdata.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
|
2013-06-14 15:33:20 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
if (!fValid) {
|
|
|
|
SkDebugf("stream was invalid: %s\n", fName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Decode a bunch of times
|
|
|
|
SkBitmap bm;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-06-14 15:33:20 +00:00
|
|
|
SkDEBUGCODE(bool success =) SkImageDecoder::DecodeStream(&fStream, &bm);
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("failed to decode %s\n", fName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
SkDEBUGCODE(success =) fStream.rewind();
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("failed to rewind %s\n", fName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
const SkString fFilename;
|
|
|
|
SkMemoryStream fStream;
|
|
|
|
bool fValid;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-06-14 15:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// These are files which call decodePalette
|
2013-09-13 19:52:27 +00:00
|
|
|
//DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scroggo/Downloads/images/hal_163x90.png")); )
|
|
|
|
//DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scroggo/Downloads/images/box_19_top-left.png")); )
|