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 "SkDevice.h" | |
13 #include "SkSurface.h" | 12 #include "SkSurface.h" |
14 #include "GrContext.h" | 13 #include "GrContext.h" |
15 #include "GrRenderTarget.h" | 14 #include "GrRenderTarget.h" |
16 | 15 |
17 // Wrap some other benchmark to allow specialization to either | 16 // Wrap some other benchmark to allow specialization to either |
18 // cpu or gpu backends. The derived class will override 'setupOffScreen' | 17 // cpu or gpu backends. The derived class will override 'setupOffScreen' |
19 // to create an offscreen surface in which the actual rendering will occur. | 18 // to create an offscreen surface in which the actual rendering will occur. |
20 class WrappedBenchmark : public Benchmark { | 19 class WrappedBenchmark : public Benchmark { |
21 public: | 20 public: |
22 // Takes ownership of caller's ref on `bench`. | 21 // Takes ownership of caller's ref on `bench`. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void setupOffScreen(SkCanvas* canvas) override { | 105 void setupOffScreen(SkCanvas* canvas) override { |
107 fOffScreen = SkSurface::MakeRenderTarget(canvas->getGrContext(), | 106 fOffScreen = SkSurface::MakeRenderTarget(canvas->getGrContext(), |
108 SkBudgeted::kNo, | 107 SkBudgeted::kNo, |
109 canvas->imageInfo(), | 108 canvas->imageInfo(), |
110 fNumSamples, | 109 fNumSamples, |
111 &this->surfaceProps()); | 110 &this->surfaceProps()); |
112 } | 111 } |
113 | 112 |
114 void onBlitToScreen(SkCanvas* canvas, int w, int h) override { | 113 void onBlitToScreen(SkCanvas* canvas, int w, int h) override { |
115 // We call copySurface directly on the underlying GPU surfaces for a mor
e efficient blit. | 114 // We call copySurface directly on the underlying GPU surfaces for a mor
e efficient blit. |
116 GrRenderTarget* dst, *src; | 115 GrRenderTarget* dst = canvas->internal_private_accessTopLayerRenderTarge
t(); |
| 116 SkASSERT(dst); |
117 | 117 |
118 SkCanvas::LayerIter canvasIter(canvas, false); | 118 GrRenderTarget* src = fOffScreen->getCanvas()->internal_private_accessTo
pLayerRenderTarget(); |
119 SkAssertResult((dst = canvasIter.device()->accessRenderTarget())); | 119 SkASSERT(src); |
120 | |
121 SkCanvas::LayerIter offscreenIter(fOffScreen->getCanvas(), false); | |
122 SkAssertResult((src = offscreenIter.device()->accessRenderTarget())); | |
123 | 120 |
124 SkASSERT(dst->getContext() == src->getContext()); | 121 SkASSERT(dst->getContext() == src->getContext()); |
125 | 122 |
126 dst->getContext()->copySurface(dst, src, SkIRect::MakeWH(w, h), SkIPoint
::Make(0, 0)); | 123 dst->getContext()->copySurface(dst, src, SkIRect::MakeWH(w, h), SkIPoint
::Make(0, 0)); |
127 | |
128 #ifdef SK_DEBUG | |
129 // This method should not be called while layers are saved. | |
130 canvasIter.next(); | |
131 SkASSERT(canvasIter.done()); | |
132 | |
133 offscreenIter.next(); | |
134 SkASSERT(offscreenIter.done()); | |
135 #endif | |
136 } | 124 } |
137 | 125 |
138 int fNumSamples; | 126 int fNumSamples; |
139 typedef WrappedBenchmark INHERITED; | 127 typedef WrappedBenchmark INHERITED; |
140 }; | 128 }; |
141 | 129 |
142 #endif //WrappedBenchmark_DEFINED | 130 #endif //WrappedBenchmark_DEFINED |
OLD | NEW |