OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrCaps.h" | 8 #include "GrCaps.h" |
9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return false; | 211 return false; |
212 } | 212 } |
213 bmp->setInfo(canvas->imageInfo()); | 213 bmp->setInfo(canvas->imageInfo()); |
214 if (!canvas->readPixels(bmp, 0, 0)) { | 214 if (!canvas->readPixels(bmp, 0, 0)) { |
215 SkDebugf("Can't read canvas pixels.\n"); | 215 SkDebugf("Can't read canvas pixels.\n"); |
216 return false; | 216 return false; |
217 } | 217 } |
218 return true; | 218 return true; |
219 } | 219 } |
220 | 220 |
221 GLTestContext* gl() { return fGL; } | 221 GLContext* gl() { return fGL; } |
222 | 222 |
223 private: | 223 private: |
224 GLTestContext* fGL; | 224 GLContext* fGL; |
225 SkAutoTDelete<SkSurface> fSurface; | 225 SkAutoTDelete<SkSurface> fSurface; |
226 }; | 226 }; |
227 | 227 |
228 static bool write_canvas_png(GPUTarget* target, const SkString& filename) { | 228 static bool write_canvas_png(GPUTarget* target, const SkString& filename) { |
229 | 229 |
230 if (filename.isEmpty()) { | 230 if (filename.isEmpty()) { |
231 return false; | 231 return false; |
232 } | 232 } |
233 if (target->getCanvas() && | 233 if (target->getCanvas() && |
234 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { | 234 kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (loops > FLAGS_maxLoops) { | 275 if (loops > FLAGS_maxLoops) { |
276 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); | 276 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); |
277 return FLAGS_maxLoops; | 277 return FLAGS_maxLoops; |
278 } | 278 } |
279 return loops; | 279 return loops; |
280 } | 280 } |
281 | 281 |
282 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } | 282 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
283 | 283 |
284 struct TimingThread { | 284 struct TimingThread { |
285 TimingThread(GLTestContext* mainContext) | 285 TimingThread(GLContext* mainContext) |
286 : fFenceSync(mainContext->fenceSync()) | 286 : fFenceSync(mainContext->fenceSync()) |
287 , fMainContext(mainContext) | 287 , fMainContext(mainContext) |
288 , fDone(false) {} | 288 , fDone(false) {} |
289 | 289 |
290 static void Loop(void* data) { | 290 static void Loop(void* data) { |
291 TimingThread* timingThread = reinterpret_cast<TimingThread*>(data); | 291 TimingThread* timingThread = reinterpret_cast<TimingThread*>(data); |
292 timingThread->timingLoop(); | 292 timingThread->timingLoop(); |
293 } | 293 } |
294 | 294 |
295 // To ensure waiting for the sync actually does something, we check to make
sure the we exceed | 295 // To ensure waiting for the sync actually does something, we check to make
sure the we exceed |
296 // some small value | 296 // some small value |
297 const double kMinElapsed = 1e-6; | 297 const double kMinElapsed = 1e-6; |
298 bool sanity(double start) const { | 298 bool sanity(double start) const { |
299 double elapsed = now_ms() - start; | 299 double elapsed = now_ms() - start; |
300 return elapsed > kMinElapsed; | 300 return elapsed > kMinElapsed; |
301 } | 301 } |
302 | 302 |
303 void waitFence(SkPlatformGpuFence sync) { | 303 void waitFence(SkPlatformGpuFence sync) { |
304 SkDEBUGCODE(double start = now_ms()); | 304 SkDEBUGCODE(double start = now_ms()); |
305 fFenceSync->waitFence(sync, false); | 305 fFenceSync->waitFence(sync, false); |
306 SkASSERT(sanity(start)); | 306 SkASSERT(sanity(start)); |
307 } | 307 } |
308 | 308 |
309 void timingLoop() { | 309 void timingLoop() { |
310 // Create a context which shares display lists with the main thread | 310 // Create a context which shares display lists with the main thread |
311 SkAutoTDelete<GLTestContext> glContext(CreatePlatformGLTestContext(kNone
_GrGLStandard, | 311 SkAutoTDelete<GLContext> glContext(CreatePlatformGLContext(kNone_GrGLSta
ndard, |
312 fMain
Context)); | 312 fMainContext)
); |
313 glContext->makeCurrent(); | 313 glContext->makeCurrent(); |
314 | 314 |
315 // Basic timing methodology is: | 315 // Basic timing methodology is: |
316 // 1) Wait on semaphore until main thread indicates its time to start ti
ming the frame | 316 // 1) Wait on semaphore until main thread indicates its time to start ti
ming the frame |
317 // 2) Wait on frame start sync, record time. This is start of the frame
. | 317 // 2) Wait on frame start sync, record time. This is start of the frame
. |
318 // 3) Wait on semaphore until main thread indicates its time to finish t
iming the frame | 318 // 3) Wait on semaphore until main thread indicates its time to finish t
iming the frame |
319 // 4) Wait on frame end sync, record time. FrameEndTime - FrameStartTim
e = frame time | 319 // 4) Wait on frame end sync, record time. FrameEndTime - FrameStartTim
e = frame time |
320 // 5) Wait on semaphore until main thread indicates we should time the n
ext frame or quit | 320 // 5) Wait on semaphore until main thread indicates we should time the n
ext frame or quit |
321 while (true) { | 321 while (true) { |
322 fSemaphore.wait(); | 322 fSemaphore.wait(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 private: | 399 private: |
400 SkGpuFenceSync* fFenceSync; | 400 SkGpuFenceSync* fFenceSync; |
401 SkSemaphore fSemaphore; | 401 SkSemaphore fSemaphore; |
402 SkMutex fFrameStartSyncsMutex; | 402 SkMutex fFrameStartSyncsMutex; |
403 SyncQueue fFrameStartSyncs; | 403 SyncQueue fFrameStartSyncs; |
404 SkMutex fFrameEndSyncsMutex; | 404 SkMutex fFrameEndSyncsMutex; |
405 SyncQueue fFrameEndSyncs; | 405 SyncQueue fFrameEndSyncs; |
406 SkTArray<double> fTimings; | 406 SkTArray<double> fTimings; |
407 SkMutex fDoneMutex; | 407 SkMutex fDoneMutex; |
408 GLTestContext* fMainContext; | 408 GLContext* fMainContext; |
409 bool fDone; | 409 bool fDone; |
410 }; | 410 }; |
411 | 411 |
412 static double time(int loops, Benchmark* bench, GPUTarget* target, TimingThread*
timingThread) { | 412 static double time(int loops, Benchmark* bench, GPUTarget* target, TimingThread*
timingThread) { |
413 SkCanvas* canvas = target->getCanvas(); | 413 SkCanvas* canvas = target->getCanvas(); |
414 canvas->clear(SK_ColorWHITE); | 414 canvas->clear(SK_ColorWHITE); |
415 bench->preDraw(canvas); | 415 bench->preDraw(canvas); |
416 | 416 |
417 if (timingThread) { | 417 if (timingThread) { |
418 timingThread->pushStartSync(); | 418 timingThread->pushStartSync(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 648 } |
649 return 0; | 649 return 0; |
650 } | 650 } |
651 | 651 |
652 #if !defined SK_BUILD_FOR_IOS | 652 #if !defined SK_BUILD_FOR_IOS |
653 int main(int argc, char** argv) { | 653 int main(int argc, char** argv) { |
654 SkCommandLineFlags::Parse(argc, argv); | 654 SkCommandLineFlags::Parse(argc, argv); |
655 return kilobench_main(); | 655 return kilobench_main(); |
656 } | 656 } |
657 #endif | 657 #endif |
OLD | NEW |