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)) |
cdalton | 0f6cca8 | 2015-11-24 08:54:29 -0800 | [diff] [blame] | 17 | , fCullRect(fPic->cullRect().roundOut()) |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 18 | , fName(name) { |
| 19 | fUniqueName.printf("%s", name); |
| 20 | } |
| 21 | |
| 22 | const char* VisualSKPBench::onGetName() { |
| 23 | return fName.c_str(); |
| 24 | } |
| 25 | |
| 26 | const char* VisualSKPBench::onGetUniqueName() { |
| 27 | return fUniqueName.c_str(); |
| 28 | } |
| 29 | |
| 30 | bool VisualSKPBench::isSuitableFor(Backend backend) { |
| 31 | return backend != kNonRendering_Backend; |
| 32 | } |
| 33 | |
cdalton | 0f6cca8 | 2015-11-24 08:54:29 -0800 | [diff] [blame] | 34 | SkIPoint VisualSKPBench::onGetSize() { |
| 35 | return SkIPoint::Make(fCullRect.width(), fCullRect.height()); |
| 36 | } |
| 37 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 38 | void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) { |
cdalton | 0f6cca8 | 2015-11-24 08:54:29 -0800 | [diff] [blame] | 39 | bool isOffset = SkToBool(fCullRect.left() | fCullRect.top()); |
| 40 | if (isOffset) { |
| 41 | canvas->save(); |
| 42 | canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top())); |
| 43 | } |
| 44 | |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 45 | for (int i = 0; i < loops; i++) { |
| 46 | canvas->drawPicture(fPic); |
cdalton | e6d2024 | 2015-10-26 13:45:29 -0700 | [diff] [blame] | 47 | #if SK_SUPPORT_GPU |
| 48 | // Ensure the GrContext doesn't batch across draw loops. |
| 49 | if (GrContext* context = canvas->getGrContext()) { |
| 50 | context->flush(); |
| 51 | } |
| 52 | #endif |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 53 | } |
cdalton | 0f6cca8 | 2015-11-24 08:54:29 -0800 | [diff] [blame] | 54 | |
| 55 | if (isOffset) { |
| 56 | canvas->restore(); |
| 57 | } |
joshualitt | 962cc98 | 2015-06-30 07:43:14 -0700 | [diff] [blame] | 58 | } |