blob: cbf98ec8a195c313835d3ebd2b1e552dc3ab2c75 [file] [log] [blame]
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
tfarinaf168b862014-06-19 12:32:29 -07009#include "Benchmark.h"
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000010#include "SkDeferredCanvas.h"
11#include "SkDevice.h"
12#include "SkImage.h"
13#include "SkSurface.h"
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +000014#if SK_SUPPORT_GPU
15#include "GrRenderTarget.h"
16#endif
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000017
tfarinaf168b862014-06-19 12:32:29 -070018class DeferredSurfaceCopyBench : public Benchmark {
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000019 enum {
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000020 kSurfaceWidth = 1000,
21 kSurfaceHeight = 1000,
22 };
23public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000024 DeferredSurfaceCopyBench(bool discardableContents) {
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000025 fDiscardableContents = discardableContents;
26 }
27
28protected:
29 virtual const char* onGetName() SK_OVERRIDE {
30 return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
31 "DeferredSurfaceCopy_nonDiscardable";
32 }
33
commit-bot@chromium.org33614712013-12-03 18:17:16 +000034 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000035 // The canvas is not actually used for this test except to provide
36 // configuration information: gpu, multisampling, size, etc?
reed52d9ac62014-06-30 09:05:34 -070037 SkImageInfo info = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHeight);
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000038 const SkRect fullCanvasRect = SkRect::MakeWH(
39 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
reed52d9ac62014-06-30 09:05:34 -070040 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
commit-bot@chromium.orgcb622242013-08-09 14:24:59 +000041 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(surface));
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000042
commit-bot@chromium.org33614712013-12-03 18:17:16 +000043 for (int iteration = 0; iteration < loops; iteration++) {
junov@chromium.org66070a52013-05-28 17:39:08 +000044 drawingCanvas->clear(0);
45 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot());
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000046 SkPaint paint;
47 if (!fDiscardableContents) {
48 // If paint is not opaque, prior canvas contents are
49 // not discardable because they are needed for compositing.
50 paint.setAlpha(127);
51 }
junov@chromium.org66070a52013-05-28 17:39:08 +000052 drawingCanvas->drawRect(fullCanvasRect, paint);
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000053 // Trigger copy on write, which should be faster in the discardable case.
junov@chromium.org66070a52013-05-28 17:39:08 +000054 drawingCanvas->flush();
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000055 }
56 }
57
58private:
59 bool fDiscardableContents;
60
tfarinaf168b862014-06-19 12:32:29 -070061 typedef Benchmark INHERITED;
junov@chromium.orgd61ba6e2013-04-17 13:43:04 +000062};
63
64//////////////////////////////////////////////////////////////////////////////
65
mtklein@google.com410e6e82013-09-13 19:52:27 +000066DEF_BENCH( return new DeferredSurfaceCopyBench(false); )
67DEF_BENCH( return new DeferredSurfaceCopyBench(true); )