OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Benchmark.h" | 9 #include "Benchmark.h" |
10 #include "SkDeferredCanvas.h" | 10 #include "SkDeferredCanvas.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 protected: | 28 protected: |
29 virtual const char* onGetName() SK_OVERRIDE { | 29 virtual const char* onGetName() SK_OVERRIDE { |
30 return fDiscardableContents ? "DeferredSurfaceCopy_discardable" : | 30 return fDiscardableContents ? "DeferredSurfaceCopy_discardable" : |
31 "DeferredSurfaceCopy_nonDiscardable"; | 31 "DeferredSurfaceCopy_nonDiscardable"; |
32 } | 32 } |
33 | 33 |
34 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 34 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
35 // The canvas is not actually used for this test except to provide | 35 // The canvas is not actually used for this test except to provide |
36 // configuration information: gpu, multisampling, size, etc? | 36 // configuration information: gpu, multisampling, size, etc? |
37 SkImageInfo info; | 37 SkImageInfo info = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHei
ght); |
38 info.fWidth = kSurfaceWidth; | |
39 info.fHeight = kSurfaceHeight; | |
40 info.fColorType = kN32_SkColorType; | |
41 info.fAlphaType = kPremul_SkAlphaType; | |
42 const SkRect fullCanvasRect = SkRect::MakeWH( | 38 const SkRect fullCanvasRect = SkRect::MakeWH( |
43 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight)); | 39 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight)); |
44 SkSurface* surface; | 40 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
45 #if SK_SUPPORT_GPU | |
46 GrRenderTarget* rt = reinterpret_cast<GrRenderTarget*>( | |
47 canvas->getDevice()->accessRenderTarget()); | |
48 if (NULL != rt) { | |
49 surface = SkSurface::NewRenderTarget(rt->getContext(), info, rt->num
Samples()); | |
50 } else | |
51 #endif | |
52 { | |
53 surface = SkSurface::NewRaster(info); | |
54 } | |
55 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su
rface)); | 41 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su
rface)); |
56 surface->unref(); | |
57 | 42 |
58 for (int iteration = 0; iteration < loops; iteration++) { | 43 for (int iteration = 0; iteration < loops; iteration++) { |
59 drawingCanvas->clear(0); | 44 drawingCanvas->clear(0); |
60 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); | 45 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); |
61 SkPaint paint; | 46 SkPaint paint; |
62 if (!fDiscardableContents) { | 47 if (!fDiscardableContents) { |
63 // If paint is not opaque, prior canvas contents are | 48 // If paint is not opaque, prior canvas contents are |
64 // not discardable because they are needed for compositing. | 49 // not discardable because they are needed for compositing. |
65 paint.setAlpha(127); | 50 paint.setAlpha(127); |
66 } | 51 } |
67 drawingCanvas->drawRect(fullCanvasRect, paint); | 52 drawingCanvas->drawRect(fullCanvasRect, paint); |
68 // Trigger copy on write, which should be faster in the discardable
case. | 53 // Trigger copy on write, which should be faster in the discardable
case. |
69 drawingCanvas->flush(); | 54 drawingCanvas->flush(); |
70 } | 55 } |
71 } | 56 } |
72 | 57 |
73 private: | 58 private: |
74 bool fDiscardableContents; | 59 bool fDiscardableContents; |
75 | 60 |
76 typedef Benchmark INHERITED; | 61 typedef Benchmark INHERITED; |
77 }; | 62 }; |
78 | 63 |
79 ////////////////////////////////////////////////////////////////////////////// | 64 ////////////////////////////////////////////////////////////////////////////// |
80 | 65 |
81 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) | 66 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) |
82 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) | 67 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) |
OLD | NEW |