skia2/bench/DeferredSurfaceCopyBench.cpp
mtklein 72c9faab45 Fix up all the easy virtual ... SK_OVERRIDE cases.
This fixes every case where virtual and SK_OVERRIDE were on the same line,
which should be the bulk of cases.  We'll have to manually clean up the rest
over time unless I level up in regexes.

for f in (find . -type f); perl -p -i -e 's/virtual (.*)SK_OVERRIDE/\1SK_OVERRIDE/g' $f; end

BUG=skia:

Review URL: https://codereview.chromium.org/806653007
2015-01-09 10:06:40 -08:00

75 lines
2.5 KiB
C++

/*
* 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"
#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); )