| 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 21 matching lines...) Expand all Loading... |
| 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.reset(surface->newImageSnapshot()); |
| 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 { |
| 43 // Release the image and raster surface here to prevent out of order des
truction |
| 44 // between these and the gpu interface. |
| 45 fRasterSurface.reset(nullptr); |
| 46 fImage.reset(nullptr); |
| 47 } |
| 48 |
| 42 void onDraw(int loops, SkCanvas*) override { | 49 void onDraw(int loops, SkCanvas*) override { |
| 43 for (int i = 0; i < loops; i++) { | 50 for (int i = 0; i < loops; i++) { |
| 44 for (int inner = 0; inner < 10; ++inner) { | 51 for (int inner = 0; inner < 10; ++inner) { |
| 45 fRasterSurface->getCanvas()->drawImage(fImage, 0, 0); | 52 fRasterSurface->getCanvas()->drawImage(fImage, 0, 0); |
| 46 } | 53 } |
| 47 } | 54 } |
| 48 } | 55 } |
| 49 | 56 |
| 50 private: | 57 private: |
| 51 SkString fName; | 58 SkString fName; |
| 52 SkAutoTUnref<SkImage> fImage; | 59 SkAutoTUnref<SkImage> fImage; |
| 53 SkAutoTUnref<SkSurface> fRasterSurface; | 60 SkAutoTUnref<SkSurface> fRasterSurface; |
| 54 | 61 |
| 55 typedef Benchmark INHERITED; | 62 typedef Benchmark INHERITED; |
| 56 }; | 63 }; |
| 57 | 64 |
| 58 | 65 |
| 59 DEF_BENCH( return new Image2RasterBench; ) | 66 DEF_BENCH( return new Image2RasterBench; ) |
| OLD | NEW |