| 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 20 matching lines...) Expand all Loading... |
| 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 = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHei
ght); | 37 SkImageInfo info = SkImageInfo::MakeN32Premul(kSurfaceWidth, kSurfaceHei
ght); |
| 38 const SkRect fullCanvasRect = SkRect::MakeWH( | 38 const SkRect fullCanvasRect = SkRect::MakeWH( |
| 39 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight)); | 39 SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight)); |
| 40 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); | 40 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
| 41 |
| 42 // newSurface() can return NULL for several reasons, so we need to check |
| 43 if (NULL == surface.get()) { |
| 44 SkDebugf("DeferredSurfaceCopyBench newSurface failed, bench results
are meaningless\n"); |
| 45 return; // should we signal the caller that we hit an error? |
| 46 } |
| 47 |
| 41 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su
rface)); | 48 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su
rface)); |
| 42 | 49 |
| 43 for (int iteration = 0; iteration < loops; iteration++) { | 50 for (int iteration = 0; iteration < loops; iteration++) { |
| 44 drawingCanvas->clear(0); | 51 drawingCanvas->clear(0); |
| 45 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); | 52 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); |
| 46 SkPaint paint; | 53 SkPaint paint; |
| 47 if (!fDiscardableContents) { | 54 if (!fDiscardableContents) { |
| 48 // If paint is not opaque, prior canvas contents are | 55 // If paint is not opaque, prior canvas contents are |
| 49 // not discardable because they are needed for compositing. | 56 // not discardable because they are needed for compositing. |
| 50 paint.setAlpha(127); | 57 paint.setAlpha(127); |
| 51 } | 58 } |
| 52 drawingCanvas->drawRect(fullCanvasRect, paint); | 59 drawingCanvas->drawRect(fullCanvasRect, paint); |
| 53 // Trigger copy on write, which should be faster in the discardable
case. | 60 // Trigger copy on write, which should be faster in the discardable
case. |
| 54 drawingCanvas->flush(); | 61 drawingCanvas->flush(); |
| 55 } | 62 } |
| 56 } | 63 } |
| 57 | 64 |
| 58 private: | 65 private: |
| 59 bool fDiscardableContents; | 66 bool fDiscardableContents; |
| 60 | 67 |
| 61 typedef Benchmark INHERITED; | 68 typedef Benchmark INHERITED; |
| 62 }; | 69 }; |
| 63 | 70 |
| 64 ////////////////////////////////////////////////////////////////////////////// | 71 ////////////////////////////////////////////////////////////////////////////// |
| 65 | 72 |
| 66 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) | 73 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) |
| 67 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) | 74 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) |
| OLD | NEW |