skia2/bench/DeferredSurfaceCopyBench.cpp

75 lines
2.5 KiB
C++
Raw Normal View History

/*
* Copyright 2013 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 "SkDeferredCanvas.h"
#include "SkDevice.h"
#include "SkImage.h"
#include "SkSurface.h"
Generate bench/Android.mk from gyp. For now, remove json functionality and do not depend on json. This allows us to build and run until solving skbug.com/2448. bench/DeferredSurfaceCopyBench.cpp: Include GrRenderTarget last, so SK_SUPPORT_GPU will be set properly. bench/ResultsWriter.h: bench/benchmain.cpp: Remove JSONResultsWriter when SK_BUILD_JSON_WRITER is not defined, which is the case for the Android framework build. gyp/bench.gyp: Depend on skia and cutils (for android_atomic_inc etc). gyp/common_conditions.gypi: Define SK_BUILD_JSON_WRITER when skia_build_json_writer is set. gyp/common_variables.gypi: Add a flag for skia_build_json_writer, and set it only when skia_android_framework is not set. gyp/jsoncpp.gyp: Do not build jsoncpp when skia_build_json_writer is not defined. include/utils/SkJSONCPP.h: Do not include json headers when SK_BUILD_JSON_WRITER is not defined. platform_tools/android/bin/gyp_to_android.py: Generate bench/Android.mk. platform_tools/android/gyp_gen/gypd_parser.py: Skip dest_dir when checking for include_dirs. platform_tools/android/gyp_gen/makefile_writer.py: Build bench/Android.mk when building external/skia. platform_tools/android/gyp_gen/tool_makefile_writer.py: Add a parameter for putting the binary into /data/local/tmp. BUG=skia:2447 BUG=skia:2448 R=halcanary@google.com, reed@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/282053002 git-svn-id: http://skia.googlecode.com/svn/trunk@14760 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-05-16 13:15:41 +00:00
#if SK_SUPPORT_GPU
#include "GrRenderTarget.h"
#endif
class DeferredSurfaceCopyBench : public Benchmark {
enum {
kSurfaceWidth = 1000,
kSurfaceHeight = 1000,
};
public:
DeferredSurfaceCopyBench(bool discardableContents) {
fDiscardableContents = discardableContents;
}
protected:
const char* onGetName() SK_OVERRIDE {
return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
"DeferredSurfaceCopy_nonDiscardable";
}
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
// The canvas is not actually used for this test except to provide
// configuration information: gpu, multisampling, size, etc?
SkImageInfo info = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHeight);
const SkRect fullCanvasRect = SkRect::MakeWH(
SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
// newSurface() can return NULL for several reasons, so we need to check
if (NULL == surface.get()) {
SkDebugf("DeferredSurfaceCopyBench newSurface failed, bench results are meaningless\n");
return; // should we signal the caller that we hit an error?
}
SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
for (int iteration = 0; iteration < loops; iteration++) {
drawingCanvas->clear(0);
SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot());
SkPaint paint;
if (!fDiscardableContents) {
// If paint is not opaque, prior canvas contents are
// not discardable because they are needed for compositing.
paint.setAlpha(127);
}
drawingCanvas->drawRect(fullCanvasRect, paint);
// Trigger copy on write, which should be faster in the discardable case.
drawingCanvas->flush();
}
}
private:
bool fDiscardableContents;
typedef Benchmark INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return new DeferredSurfaceCopyBench(false); )
DEF_BENCH( return new DeferredSurfaceCopyBench(true); )