joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 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 | |
| 9 | #include "VisualSKPBench.h" |
| 10 | |
cdalton | e6d2024 | 2015-10-26 13:45:29 -0700 | [diff] [blame] | 11 | #if SK_SUPPORT_GPU |
| 12 | #include "GrContext.h" |
| 13 | #endif |
| 14 | |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 15 | VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic) |
| 16 | : fPic(SkRef(pic)) |
| 17 | , fName(name) { |
| 18 | fUniqueName.printf("%s", name); |
| 19 | } |
| 20 | |
| 21 | const char* VisualSKPBench::onGetName() { |
| 22 | return fName.c_str(); |
| 23 | } |
| 24 | |
| 25 | const char* VisualSKPBench::onGetUniqueName() { |
| 26 | return fUniqueName.c_str(); |
| 27 | } |
| 28 | |
| 29 | bool VisualSKPBench::isSuitableFor(Backend backend) { |
| 30 | return backend != kNonRendering_Backend; |
| 31 | } |
| 32 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 33 | void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) { |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 34 | for (int i = 0; i < loops; i++) { |
| 35 | canvas->drawPicture(fPic); |
cdalton | e6d2024 | 2015-10-26 13:45:29 -0700 | [diff] [blame] | 36 | #if SK_SUPPORT_GPU |
| 37 | // Ensure the GrContext doesn't batch across draw loops. |
| 38 | if (GrContext* context = canvas->getGrContext()) { |
| 39 | context->flush(); |
| 40 | } |
| 41 | #endif |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 42 | } |
| 43 | } |