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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrRenderTarget.h"
|
|
|
|
#endif
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkDeferredCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
// The canvas is not actually used for this test except to provide
|
|
|
|
// configuration information: gpu, multisampling, size, etc?
|
|
|
|
SkImage::Info info;
|
|
|
|
info.fWidth = kSurfaceWidth;
|
|
|
|
info.fHeight = kSurfaceHeight;
|
|
|
|
info.fColorType = SkImage::kPMColor_ColorType;
|
|
|
|
info.fAlphaType = SkImage::kPremul_AlphaType;
|
|
|
|
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-09-10 19:23:38 +00:00
|
|
|
for (int iteration = 0; iteration < this->getLoops(); 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); )
|