OLD | NEW |
| (Empty) |
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 | |
11 #if SK_SUPPORT_GPU | |
12 #include "GrContext.h" | |
13 #endif | |
14 | |
15 VisualSKPBench::VisualSKPBench(const char* name, const SkPicture* pic) | |
16 : fPic(SkRef(pic)) | |
17 , fCullRect(fPic->cullRect().roundOut()) | |
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 | |
34 SkIPoint VisualSKPBench::onGetSize() { | |
35 return SkIPoint::Make(fCullRect.width(), fCullRect.height()); | |
36 } | |
37 | |
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 | |
45 for (int i = 0; i < loops; i++) { | |
46 canvas->drawPicture(fPic); | |
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 | |
53 } | |
54 | |
55 if (isOffset) { | |
56 canvas->restore(); | |
57 } | |
58 } | |
OLD | NEW |