2013-04-17 13:43:04 +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-04-17 13:43:04 +00:00
|
|
|
#include "SkDeferredCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkSurface.h"
|
2014-05-16 13:15:41 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrRenderTarget.h"
|
|
|
|
#endif
|
2013-04-17 13:43:04 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class DeferredSurfaceCopyBench : public Benchmark {
|
2013-04-17 13:43:04 +00:00
|
|
|
enum {
|
|
|
|
kSurfaceWidth = 1000,
|
|
|
|
kSurfaceHeight = 1000,
|
|
|
|
};
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DeferredSurfaceCopyBench(bool discardableContents) {
|
2013-04-17 13:43:04 +00:00
|
|
|
fDiscardableContents = discardableContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
const char* onGetName() SK_OVERRIDE {
|
2013-04-17 13:43:04 +00:00
|
|
|
return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
|
|
|
|
"DeferredSurfaceCopy_nonDiscardable";
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2013-04-17 13:43:04 +00:00
|
|
|
// The canvas is not actually used for this test except to provide
|
|
|
|
// configuration information: gpu, multisampling, size, etc?
|
2014-06-30 16:05:34 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHeight);
|
2013-04-17 13:43:04 +00:00
|
|
|
const SkRect fullCanvasRect = SkRect::MakeWH(
|
|
|
|
SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
|
2014-06-30 16:05:34 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
|
2014-10-02 19:58:48 +00:00
|
|
|
|
|
|
|
// 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?
|
|
|
|
}
|
|
|
|
|
2013-08-09 14:24:59 +00:00
|
|
|
SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
|
2013-04-17 13:43:04 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int iteration = 0; iteration < loops; iteration++) {
|
2013-05-28 17:39:08 +00:00
|
|
|
drawingCanvas->clear(0);
|
|
|
|
SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot());
|
2013-04-17 13:43:04 +00:00
|
|
|
SkPaint paint;
|
|
|
|
if (!fDiscardableContents) {
|
|
|
|
// If paint is not opaque, prior canvas contents are
|
|
|
|
// not discardable because they are needed for compositing.
|
|
|
|
paint.setAlpha(127);
|
|
|
|
}
|
2013-05-28 17:39:08 +00:00
|
|
|
drawingCanvas->drawRect(fullCanvasRect, paint);
|
2013-04-17 13:43:04 +00:00
|
|
|
// Trigger copy on write, which should be faster in the discardable case.
|
2013-05-28 17:39:08 +00:00
|
|
|
drawingCanvas->flush();
|
2013-04-17 13:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fDiscardableContents;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-17 13:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(false); )
|
|
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(true); )
|