| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkImage.h" | 10 #include "SkImage.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 // We explicitly want to bench drawing a Image [cpu or gpu backed] into a ra
ster target, | 28 // We explicitly want to bench drawing a Image [cpu or gpu backed] into a ra
ster target, |
| 29 // to ensure that we can cache the read-back in the case of gpu -> raster | 29 // to ensure that we can cache the read-back in the case of gpu -> raster |
| 30 // | 30 // |
| 31 void onPerCanvasPreDraw(SkCanvas* canvas) override { | 31 void onPerCanvasPreDraw(SkCanvas* canvas) override { |
| 32 // create an Image reflecting the canvas (gpu or cpu) | 32 // create an Image reflecting the canvas (gpu or cpu) |
| 33 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 33 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 34 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); | 34 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
| 35 canvas->drawColor(SK_ColorRED); | 35 canvas->drawColor(SK_ColorRED); |
| 36 fImage.reset(surface->newImageSnapshot()); | 36 fImage = surface->makeImageSnapshot(); |
| 37 | 37 |
| 38 // create a cpu-backed Surface | 38 // create a cpu-backed Surface |
| 39 fRasterSurface.reset(SkSurface::NewRaster(info)); | 39 fRasterSurface.reset(SkSurface::NewRaster(info)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void onPerCanvasPostDraw(SkCanvas*) override { | 42 void onPerCanvasPostDraw(SkCanvas*) override { |
| 43 // Release the image and raster surface here to prevent out of order des
truction | 43 // Release the image and raster surface here to prevent out of order des
truction |
| 44 // between these and the gpu interface. | 44 // between these and the gpu interface. |
| 45 fRasterSurface.reset(nullptr); | 45 fRasterSurface.reset(nullptr); |
| 46 fImage.reset(nullptr); | 46 fImage.reset(nullptr); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void onDraw(int loops, SkCanvas*) override { | 49 void onDraw(int loops, SkCanvas*) override { |
| 50 for (int i = 0; i < loops; i++) { | 50 for (int i = 0; i < loops; i++) { |
| 51 for (int inner = 0; inner < 10; ++inner) { | 51 for (int inner = 0; inner < 10; ++inner) { |
| 52 fRasterSurface->getCanvas()->drawImage(fImage, 0, 0); | 52 fRasterSurface->getCanvas()->drawImage(fImage.get(), 0, 0); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 SkString fName; | 58 SkString fName; |
| 59 SkAutoTUnref<SkImage> fImage; | 59 sk_sp<SkImage> fImage; |
| 60 SkAutoTUnref<SkSurface> fRasterSurface; | 60 SkAutoTUnref<SkSurface> fRasterSurface; |
| 61 | 61 |
| 62 typedef Benchmark INHERITED; | 62 typedef Benchmark INHERITED; |
| 63 }; | 63 }; |
| 64 DEF_BENCH( return new Image2RasterBench; ) | 64 DEF_BENCH( return new Image2RasterBench; ) |
| OLD | NEW |