28fcae2ec7
Reason for revert: Want to reland the original CL. Original issue's description: > Revert of Rename kPMColor_SkColorType to kN32_SkColorType. (https://codereview.chromium.org/227433009/) > > Reason for revert: > breaking the Chrome deps roll. > http://build.chromium.org/p/chromium.linux/builders/Linux%20GN%20%28dbg%29/builds/839/steps/compile/logs/stdio > > Original issue's description: > > Rename kPMColor_SkColorType to kN32_SkColorType. > > > > The new name better represents what this flag means. > > > > BUG=skia:2384 > > > > Committed: http://code.google.com/p/skia/source/detail?r=14117 > > TBR=reed@google.com,scroggo@google.com > NOTREECHECKS=true > NOTRY=true > BUG=skia:2384 > > Committed: http://code.google.com/p/skia/source/detail?r=14144 R=reed@google.com, bensong@google.com TBR=bensong@google.com, reed@google.com NOTREECHECKS=true NOTRY=true BUG=skia:2384 Author: scroggo@google.com Review URL: https://codereview.chromium.org/235523003 git-svn-id: http://skia.googlecode.com/svn/trunk@14156 2bbb7eff-a529-9590-31e7-b0007b416f81
83 lines
2.7 KiB
C++
83 lines
2.7 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.
|
|
*/
|
|
|
|
#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:
|
|
DeferredSurfaceCopyBench(bool discardableContents) {
|
|
fDiscardableContents = discardableContents;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
|
|
"DeferredSurfaceCopy_nonDiscardable";
|
|
}
|
|
|
|
virtual 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;
|
|
info.fWidth = kSurfaceWidth;
|
|
info.fHeight = kSurfaceHeight;
|
|
info.fColorType = kN32_SkColorType;
|
|
info.fAlphaType = kPremul_SkAlphaType;
|
|
const SkRect fullCanvasRect = SkRect::MakeWH(
|
|
SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
|
|
SkSurface* surface;
|
|
#if SK_SUPPORT_GPU
|
|
GrRenderTarget* rt = reinterpret_cast<GrRenderTarget*>(
|
|
canvas->getDevice()->accessRenderTarget());
|
|
if (NULL != rt) {
|
|
surface = SkSurface::NewRenderTarget(rt->getContext(), info, rt->numSamples());
|
|
} else
|
|
#endif
|
|
{
|
|
surface = SkSurface::NewRaster(info);
|
|
}
|
|
SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
|
|
surface->unref();
|
|
|
|
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 SkBenchmark INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(false); )
|
|
DEF_BENCH( return new DeferredSurfaceCopyBench(true); )
|