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 | 8 |
9 #include "VisualSKPBench.h" | 9 #include "VisualSKPBench.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #endif | 13 #endif |
14 | 14 |
15 VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic) | 15 VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic) |
16 : fPic(SkRef(pic)) | 16 : fPic(SkRef(pic)) |
| 17 , fCullRect(fPic->cullRect().roundOut()) |
17 , fName(name) { | 18 , fName(name) { |
18 fUniqueName.printf("%s", name); | 19 fUniqueName.printf("%s", name); |
19 } | 20 } |
20 | 21 |
21 const char* VisualSKPBench::onGetName() { | 22 const char* VisualSKPBench::onGetName() { |
22 return fName.c_str(); | 23 return fName.c_str(); |
23 } | 24 } |
24 | 25 |
25 const char* VisualSKPBench::onGetUniqueName() { | 26 const char* VisualSKPBench::onGetUniqueName() { |
26 return fUniqueName.c_str(); | 27 return fUniqueName.c_str(); |
27 } | 28 } |
28 | 29 |
29 bool VisualSKPBench::isSuitableFor(Backend backend) { | 30 bool VisualSKPBench::isSuitableFor(Backend backend) { |
30 return backend != kNonRendering_Backend; | 31 return backend != kNonRendering_Backend; |
31 } | 32 } |
32 | 33 |
| 34 SkIPoint VisualSKPBench::onGetSize() { |
| 35 return SkIPoint::Make(fCullRect.width(), fCullRect.height()); |
| 36 } |
| 37 |
33 void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) { | 38 void VisualSKPBench::onDraw(int loops, SkCanvas* canvas) { |
| 39 bool isOffset = SkToBool(fCullRect.left() | fCullRect.top()); |
| 40 if (isOffset) { |
| 41 canvas->save(); |
| 42 canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCull
Rect.top())); |
| 43 } |
| 44 |
34 for (int i = 0; i < loops; i++) { | 45 for (int i = 0; i < loops; i++) { |
35 canvas->drawPicture(fPic); | 46 canvas->drawPicture(fPic); |
36 #if SK_SUPPORT_GPU | 47 #if SK_SUPPORT_GPU |
37 // Ensure the GrContext doesn't batch across draw loops. | 48 // Ensure the GrContext doesn't batch across draw loops. |
38 if (GrContext* context = canvas->getGrContext()) { | 49 if (GrContext* context = canvas->getGrContext()) { |
39 context->flush(); | 50 context->flush(); |
40 } | 51 } |
41 #endif | 52 #endif |
42 } | 53 } |
| 54 |
| 55 if (isOffset) { |
| 56 canvas->restore(); |
| 57 } |
43 } | 58 } |
OLD | NEW |