Chromium Code Reviews| 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 return; // should we signal the caller that we hit an error? | |
|
mtklein
2014/10/02 19:43:08
Can't hurt to at least log it?
SkDebugf("Surface
reed1
2014/10/02 19:53:27
Done.
| |
| 45 } | |
| 46 | |
| 41 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su rface)); | 47 SkAutoTUnref<SkDeferredCanvas> drawingCanvas(SkDeferredCanvas::Create(su rface)); |
| 42 | 48 |
| 43 for (int iteration = 0; iteration < loops; iteration++) { | 49 for (int iteration = 0; iteration < loops; iteration++) { |
| 44 drawingCanvas->clear(0); | 50 drawingCanvas->clear(0); |
| 45 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); | 51 SkAutoTUnref<SkImage> image(drawingCanvas->newImageSnapshot()); |
| 46 SkPaint paint; | 52 SkPaint paint; |
| 47 if (!fDiscardableContents) { | 53 if (!fDiscardableContents) { |
| 48 // If paint is not opaque, prior canvas contents are | 54 // If paint is not opaque, prior canvas contents are |
| 49 // not discardable because they are needed for compositing. | 55 // not discardable because they are needed for compositing. |
| 50 paint.setAlpha(127); | 56 paint.setAlpha(127); |
| 51 } | 57 } |
| 52 drawingCanvas->drawRect(fullCanvasRect, paint); | 58 drawingCanvas->drawRect(fullCanvasRect, paint); |
| 53 // Trigger copy on write, which should be faster in the discardable case. | 59 // Trigger copy on write, which should be faster in the discardable case. |
| 54 drawingCanvas->flush(); | 60 drawingCanvas->flush(); |
| 55 } | 61 } |
| 56 } | 62 } |
| 57 | 63 |
| 58 private: | 64 private: |
| 59 bool fDiscardableContents; | 65 bool fDiscardableContents; |
| 60 | 66 |
| 61 typedef Benchmark INHERITED; | 67 typedef Benchmark INHERITED; |
| 62 }; | 68 }; |
| 63 | 69 |
| 64 ////////////////////////////////////////////////////////////////////////////// | 70 ////////////////////////////////////////////////////////////////////////////// |
| 65 | 71 |
| 66 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) | 72 DEF_BENCH( return new DeferredSurfaceCopyBench(false); ) |
| 67 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) | 73 DEF_BENCH( return new DeferredSurfaceCopyBench(true); ) |
| OLD | NEW |