OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 #include "nanobench.h" | 10 #include "nanobench.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 51 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
52 #include "nanobenchAndroid.h" | 52 #include "nanobenchAndroid.h" |
53 #endif | 53 #endif |
54 | 54 |
55 #if SK_SUPPORT_GPU | 55 #if SK_SUPPORT_GPU |
56 #include "gl/GrGLDefines.h" | 56 #include "gl/GrGLDefines.h" |
57 #include "GrCaps.h" | 57 #include "GrCaps.h" |
58 #include "GrContextFactory.h" | 58 #include "GrContextFactory.h" |
59 #include "gl/GrGLUtil.h" | 59 #include "gl/GrGLUtil.h" |
60 using sk_gpu_test::GrContextFactory; | 60 using sk_gpu_test::GrContextFactory; |
61 using sk_gpu_test::GLTestContext; | 61 using sk_gpu_test::TestContext; |
62 SkAutoTDelete<GrContextFactory> gGrFactory; | 62 SkAutoTDelete<GrContextFactory> gGrFactory; |
63 #endif | 63 #endif |
64 | 64 |
65 struct GrContextOptions; | 65 struct GrContextOptions; |
66 | 66 |
67 __SK_FORCE_IMAGE_DECODER_LINKING; | 67 __SK_FORCE_IMAGE_DECODER_LINKING; |
68 | 68 |
69 static const int kAutoTuneLoops = 0; | 69 static const int kAutoTuneLoops = 0; |
70 | 70 |
71 static const int kDefaultLoops = | 71 static const int kDefaultLoops = |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 bmp->setInfo(canvas->imageInfo()); | 150 bmp->setInfo(canvas->imageInfo()); |
151 if (!canvas->readPixels(bmp, 0, 0)) { | 151 if (!canvas->readPixels(bmp, 0, 0)) { |
152 SkDebugf("Can't read canvas pixels.\n"); | 152 SkDebugf("Can't read canvas pixels.\n"); |
153 return false; | 153 return false; |
154 } | 154 } |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 #if SK_SUPPORT_GPU | 158 #if SK_SUPPORT_GPU |
159 struct GPUTarget : public Target { | 159 struct GPUTarget : public Target { |
160 explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { } | 160 explicit GPUTarget(const Config& c) : Target(c), context(nullptr) { } |
161 GLTestContext* gl; | 161 TestContext* context; |
162 | 162 |
163 void setup() override { | 163 void setup() override { |
164 this->gl->makeCurrent(); | 164 this->context->makeCurrent(); |
165 // Make sure we're done with whatever came before. | 165 // Make sure we're done with whatever came before. |
166 GR_GL_CALL(this->gl->gl(), Finish()); | 166 this->context->finish(); |
167 } | 167 } |
168 void endTiming() override { | 168 void endTiming() override { |
169 if (this->gl) { | 169 if (this->context) { |
170 GR_GL_CALL(this->gl->gl(), Flush()); | 170 this->context->waitOnSyncOrSwap(); |
171 this->gl->waitOnSyncOrSwap(); | |
172 } | 171 } |
173 } | 172 } |
174 void fence() override { | 173 void fence() override { |
175 GR_GL_CALL(this->gl->gl(), Finish()); | 174 this->context->finish(); |
176 } | 175 } |
177 | 176 |
178 bool needsFrameTiming(int* maxFrameLag) const override { | 177 bool needsFrameTiming(int* maxFrameLag) const override { |
179 if (!this->gl->getMaxGpuFrameLag(maxFrameLag)) { | 178 if (!this->context->getMaxGpuFrameLag(maxFrameLag)) { |
180 // Frame lag is unknown. | 179 // Frame lag is unknown. |
181 *maxFrameLag = FLAGS_gpuFrameLag; | 180 *maxFrameLag = FLAGS_gpuFrameLag; |
182 } | 181 } |
183 return true; | 182 return true; |
184 } | 183 } |
185 bool init(SkImageInfo info, Benchmark* bench) override { | 184 bool init(SkImageInfo info, Benchmark* bench) override { |
186 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceInde
pendentFonts_Flag : | 185 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceInde
pendentFonts_Flag : |
187 0; | 186 0; |
188 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 187 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
189 this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config
.ctxType, | 188 this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config
.ctxType, |
190 this->config
.ctxOptions), | 189 this->config
.ctxOptions), |
191 SkBudgeted::kNo, info, | 190 SkBudgeted::kNo, info, |
192 this->config.samples, &
props); | 191 this->config.samples, &
props); |
193 this->gl = gGrFactory->getContextInfo(this->config.ctxType, | 192 this->context = gGrFactory->getContextInfo(this->config.ctxType, |
194 this->config.ctxOptions).glContext
(); | 193 this->config.ctxOptions).test
Context(); |
195 if (!this->surface.get()) { | 194 if (!this->surface.get()) { |
196 return false; | 195 return false; |
197 } | 196 } |
198 if (!this->gl->fenceSyncSupport()) { | 197 if (!this->context->fenceSyncSupport()) { |
199 SkDebugf("WARNING: GL context for config \"%s\" does not support fen
ce sync. " | 198 SkDebugf("WARNING: GL context for config \"%s\" does not support fen
ce sync. " |
200 "Timings might not be accurate.\n", this->config.name.c_str
()); | 199 "Timings might not be accurate.\n", this->config.name.c_str
()); |
201 } | 200 } |
202 return true; | 201 return true; |
203 } | 202 } |
204 void fillOptions(ResultsWriter* log) override { | 203 void fillOptions(ResultsWriter* log) override { |
205 const GrGLubyte* version; | 204 const GrGLubyte* version; |
206 GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VERSION)); | 205 if (this->context->backend() == kOpenGL_GrBackend) { |
207 log->configOption("GL_VERSION", (const char*)(version)); | 206 const GrGLInterface* gl = |
| 207 reinterpret_cast<const GrGLInterface*>(this->context->backen
dContext()); |
| 208 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION)); |
| 209 log->configOption("GL_VERSION", (const char*)(version)); |
208 | 210 |
209 GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_RENDERER)); | 211 GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER)); |
210 log->configOption("GL_RENDERER", (const char*) version); | 212 log->configOption("GL_RENDERER", (const char*) version); |
211 | 213 |
212 GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VENDOR)); | 214 GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR)); |
213 log->configOption("GL_VENDOR", (const char*) version); | 215 log->configOption("GL_VENDOR", (const char*) version); |
214 | 216 |
215 GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_SHADING_LANGUAGE
_VERSION)); | 217 GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION
)); |
216 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | 218 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) versi
on); |
| 219 } |
217 } | 220 } |
218 }; | 221 }; |
219 | 222 |
220 #endif | 223 #endif |
221 | 224 |
222 static double time(int loops, Benchmark* bench, Target* target) { | 225 static double time(int loops, Benchmark* bench, Target* target) { |
223 SkCanvas* canvas = target->getCanvas(); | 226 SkCanvas* canvas = target->getCanvas(); |
224 if (canvas) { | 227 if (canvas) { |
225 canvas->clear(SK_ColorWHITE); | 228 canvas->clear(SK_ColorWHITE); |
226 } | 229 } |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 | 1286 |
1284 return 0; | 1287 return 0; |
1285 } | 1288 } |
1286 | 1289 |
1287 #if !defined SK_BUILD_FOR_IOS | 1290 #if !defined SK_BUILD_FOR_IOS |
1288 int main(int argc, char** argv) { | 1291 int main(int argc, char** argv) { |
1289 SkCommandLineFlags::Parse(argc, argv); | 1292 SkCommandLineFlags::Parse(argc, argv); |
1290 return nanobench_main(); | 1293 return nanobench_main(); |
1291 } | 1294 } |
1292 #endif | 1295 #endif |
OLD | NEW |