Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: bench/DeferredSurfaceCopyBench.cpp

Issue 14297008: Benchmark to measure SkSurface copy on write performance (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
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
9 #if SK_SUPPORT_GPU
10 #include "GrRenderTarget.h"
11 #endif
12 #include "SkBenchmark.h"
13 #include "SkDeferredCanvas.h"
14 #include "SkDevice.h"
15 #include "SkImage.h"
16 #include "SkSurface.h"
17
18 class DeferredSurfaceCopyBench : public SkBenchmark {
19 enum {
20 N = SkBENCHLOOP(5),
21 kSurfaceWidth = 1000,
22 kSurfaceHeight = 1000,
23 };
24 public:
25 DeferredSurfaceCopyBench(void* param, bool discardableContents) : SkBenchmar k(param) {
26 fDiscardableContents = discardableContents;
27 }
28
29 protected:
30 virtual const char* onGetName() SK_OVERRIDE {
31 return fDiscardableContents ? "DeferredSurfaceCopy_discardable" :
32 "DeferredSurfaceCopy_nonDiscardable";
33 }
34
35 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
36 // The canvas is not actually used for this test except to provide
37 // configuration information: gpu, multisampling, size, etc?
38 SkDevice* referenceDevice = canvas->getDevice();
39 SkImage::Info info;
40 info.fWidth = kSurfaceWidth;
41 info.fHeight = kSurfaceHeight;
42 info.fColorType = SkImage::kPMColor_ColorType;
43 info.fAlphaType = SkImage::kPremul_AlphaType;
44 const SkRect fullCanvasRect = SkRect::MakeWH(
45 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
46 SkSurface* surface;
47 #if SK_SUPPORT_GPU
48 GrRenderTarget* rt = reinterpret_cast<GrRenderTarget*>(referenceDevice-> accessRenderTarget());
49 if (NULL != rt) {
50 surface = SkSurface::NewRenderTarget(rt->getContext(), info, rt->num Samples());
51 } else
52 #endif
53 {
54 surface = SkSurface::NewRaster(info);
55 }
56 SkDeferredCanvas drawingCanvas(surface);
57 surface->unref();
58
59 for (int iteration = 0; iteration < N; iteration++) {
60 drawingCanvas.clear(0);
61 SkAutoTUnref<SkImage> image(drawingCanvas.newImageSnapshot());
62 SkPaint paint;
63 if (!fDiscardableContents) {
64 // If paint is not opaque, prior canvas contents are
65 // not discardable because they are needed for compositing.
66 paint.setAlpha(127);
67 }
68 drawingCanvas.drawRect(fullCanvasRect, paint);
69 // Trigger copy on write, which should be faster in the discardable case.
70 drawingCanvas.flush();
71 }
72 }
73
74 private:
75 bool fDiscardableContents;
76
77 typedef SkBenchmark INHERITED;
78 };
79
80 //////////////////////////////////////////////////////////////////////////////
81
82 static SkBenchmark* Fact0(void* p) { return new DeferredSurfaceCopyBench(p, fals e); }
83 static SkBenchmark* Fact1(void* p) { return new DeferredSurfaceCopyBench(p, true ); }
84
85 static BenchRegistry gReg0(Fact0);
86 static BenchRegistry gReg1(Fact1);
87
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698