OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "Benchmark.h" |
| 9 #include "SkCanvas.h" |
| 10 #include "SkImage.h" |
| 11 #include "SkSurface.h" |
| 12 |
| 13 class GPU2RasterImageBench : public Benchmark { |
| 14 public: |
| 15 GPU2RasterImageBench() { |
| 16 fName.set("gpu2raster_image"); |
| 17 } |
| 18 |
| 19 bool isSuitableFor(Backend backend) override { |
| 20 return kGPU_Backend == backend; |
| 21 } |
| 22 |
| 23 protected: |
| 24 const char* onGetName() override { |
| 25 return fName.c_str(); |
| 26 } |
| 27 |
| 28 void onPerCanvasPreDraw(SkCanvas* canvas) override { |
| 29 // create a gpu-backed Image |
| 30 SkImageInfo info = SkImageInfo::MakeN32Premul(500, 500); |
| 31 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
| 32 canvas->drawColor(SK_ColorRED); |
| 33 fGpuImage.reset(surface->newImageSnapshot()); |
| 34 |
| 35 // create a cpu-backed Surface |
| 36 fRasterSurface.reset(SkSurface::NewRaster(info)); |
| 37 } |
| 38 |
| 39 void onDraw(const int loops, SkCanvas*) override { |
| 40 // Time drawing a gpu-image into a raster-surface |
| 41 for (int i = 0; i < loops; i++) { |
| 42 for (int inner = 0; inner < 10; ++inner) { |
| 43 fRasterSurface->getCanvas()->drawImage(fGpuImage, 0, 0); |
| 44 } |
| 45 } |
| 46 } |
| 47 |
| 48 private: |
| 49 SkString fName; |
| 50 SkAutoTUnref<SkImage> fGpuImage; |
| 51 SkAutoTUnref<SkSurface> fRasterSurface; |
| 52 |
| 53 typedef Benchmark INHERITED; |
| 54 }; |
| 55 |
| 56 |
| 57 DEF_BENCH( return new GPU2RasterImageBench; ) |
OLD | NEW |