| 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 #ifndef WrappedBenchmark_DEFINED | 8 #ifndef WrappedBenchmark_DEFINED |
| 9 #define WrappedBenchmark_DEFINED | 9 #define WrappedBenchmark_DEFINED |
| 10 | 10 |
| 11 #include "Benchmark.h" | 11 #include "Benchmark.h" |
| 12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
| 13 #include "GrContext.h" | 13 #include "GrContext.h" |
| 14 #include "GrDrawContext.h" |
| 14 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 15 | 16 |
| 16 // Wrap some other benchmark to allow specialization to either | 17 // Wrap some other benchmark to allow specialization to either |
| 17 // cpu or gpu backends. The derived class will override 'setupOffScreen' | 18 // cpu or gpu backends. The derived class will override 'setupOffScreen' |
| 18 // to create an offscreen surface in which the actual rendering will occur. | 19 // to create an offscreen surface in which the actual rendering will occur. |
| 19 class WrappedBenchmark : public Benchmark { | 20 class WrappedBenchmark : public Benchmark { |
| 20 public: | 21 public: |
| 21 // Takes ownership of caller's ref on `bench`. | 22 // Takes ownership of caller's ref on `bench`. |
| 22 explicit WrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* ben
ch) | 23 explicit WrappedBenchmark(const SkSurfaceProps& surfaceProps, Benchmark* ben
ch) |
| 23 : fSurfaceProps(surfaceProps) | 24 : fSurfaceProps(surfaceProps) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void setupOffScreen(SkCanvas* canvas) override { | 106 void setupOffScreen(SkCanvas* canvas) override { |
| 106 fOffScreen = SkSurface::MakeRenderTarget(canvas->getGrContext(), | 107 fOffScreen = SkSurface::MakeRenderTarget(canvas->getGrContext(), |
| 107 SkBudgeted::kNo, | 108 SkBudgeted::kNo, |
| 108 canvas->imageInfo(), | 109 canvas->imageInfo(), |
| 109 fNumSamples, | 110 fNumSamples, |
| 110 &this->surfaceProps()); | 111 &this->surfaceProps()); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void onBlitToScreen(SkCanvas* canvas, int w, int h) override { | 114 void onBlitToScreen(SkCanvas* canvas, int w, int h) override { |
| 114 // We call copySurface directly on the underlying GPU surfaces for a mor
e efficient blit. | 115 // We call copySurface directly on the underlying GPU surfaces for a mor
e efficient blit. |
| 115 GrRenderTarget* dst = canvas->internal_private_accessTopLayerRenderTarge
t(); | 116 GrDrawContext* dstDC = canvas->internal_private_accessTopLayerDrawContex
t(); |
| 116 SkASSERT(dst); | 117 SkASSERT(dstDC); |
| 117 | 118 |
| 118 GrRenderTarget* src = fOffScreen->getCanvas()->internal_private_accessTo
pLayerRenderTarget(); | 119 GrDrawContext* srcDC = |
| 120 fOffScreen->getCanvas()->internal_private_accessTopL
ayerDrawContext(); |
| 121 SkASSERT(srcDC); |
| 122 GrRenderTarget* src = srcDC->accessRenderTarget(); |
| 119 SkASSERT(src); | 123 SkASSERT(src); |
| 120 | 124 |
| 121 SkASSERT(dst->getContext() == src->getContext()); | 125 SkASSERT(canvas->getGrContext() == fOffScreen->getCanvas()->getGrContext
()); |
| 122 | 126 |
| 123 dst->getContext()->copySurface(dst, src, SkIRect::MakeWH(w, h), SkIPoint
::Make(0, 0)); | 127 dstDC->copySurface(src, SkIRect::MakeWH(w, h), SkIPoint::Make(0, 0)); |
| 124 } | 128 } |
| 125 | 129 |
| 126 int fNumSamples; | 130 int fNumSamples; |
| 127 typedef WrappedBenchmark INHERITED; | 131 typedef WrappedBenchmark INHERITED; |
| 128 }; | 132 }; |
| 129 | 133 |
| 130 #endif //WrappedBenchmark_DEFINED | 134 #endif //WrappedBenchmark_DEFINED |
| OLD | NEW |