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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#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
|
|
|
|
|
|
|
class DeferredSurfaceCopyBench : public SkBenchmark {
|
|
|
|
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:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
|
|
|
|
"DeferredSurfaceCopy_nonDiscardable";
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual 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?
|
2013-11-01 13:46:54 +00:00
|
|
|
SkImageInfo info;
|
2013-04-17 13:43:04 +00:00
|
|
|
info.fWidth = kSurfaceWidth;
|
|
|
|
info.fHeight = kSurfaceHeight;
|
2014-04-11 17:15:40 +00:00
|
|
|
info.fColorType = kN32_SkColorType;
|
2013-09-20 19:33:52 +00:00
|
|
|
info.fAlphaType = kPremul_SkAlphaType;
|
2013-04-17 13:43:04 +00:00
|
|
|
const SkRect fullCanvasRect = SkRect::MakeWH(
|
|
|
|
SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
|
|
|
|
SkSurface* surface;
|
|
|
|
#if SK_SUPPORT_GPU
|
2013-04-17 13:55:45 +00:00
|
|
|
GrRenderTarget* rt = reinterpret_cast<GrRenderTarget*>(
|
|
|
|
canvas->getDevice()->accessRenderTarget());
|
2013-04-17 13:43:04 +00:00
|
|
|
if (NULL != rt) {
|
|
|
|
surface = SkSurface::NewRenderTarget(rt->getContext(), info, rt->numSamples());
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
surface = SkSurface::NewRaster(info);
|
|
|
|
}
|
2013-08-09 14:24:59 +00:00
|
|
|
SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
|
2013-04-17 13:43:04 +00:00
|
|
|
surface->unref();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(false); )
|
|
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(true); )
|