OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDrawLooper.h" | 8 #include "SkDrawLooper.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkMatrix.h" | 10 #include "SkMatrix.h" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 | 13 |
14 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) { | 14 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) { |
15 SkCanvas canvas; | 15 SkCanvas canvas; |
| 16 ContextAllocator allocator; |
16 | 17 |
17 this->init(&canvas); | 18 SkDrawLooper::Context* context = this->init(&canvas, &allocator); |
18 for (;;) { | 19 for (;;) { |
19 SkPaint p(paint); | 20 SkPaint p(paint); |
20 if (this->next(&canvas, &p)) { | 21 if (context->next(&canvas, &p)) { |
21 p.setLooper(NULL); | 22 p.setLooper(NULL); |
22 if (!p.canComputeFastBounds()) { | 23 if (!p.canComputeFastBounds()) { |
23 return false; | 24 return false; |
24 } | 25 } |
25 } else { | 26 } else { |
26 break; | 27 break; |
27 } | 28 } |
28 } | 29 } |
29 return true; | 30 return true; |
30 } | 31 } |
31 | 32 |
32 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, | 33 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, |
33 SkRect* dst) { | 34 SkRect* dst) { |
34 SkCanvas canvas; | 35 SkCanvas canvas; |
| 36 ContextAllocator allocator; |
35 | 37 |
36 *dst = src; // catch case where there are no loops | 38 *dst = src; // catch case where there are no loops |
37 this->init(&canvas); | 39 SkDrawLooper::Context* context = this->init(&canvas, &allocator); |
38 for (bool firstTime = true;; firstTime = false) { | 40 for (bool firstTime = true;; firstTime = false) { |
39 SkPaint p(paint); | 41 SkPaint p(paint); |
40 if (this->next(&canvas, &p)) { | 42 if (context->next(&canvas, &p)) { |
41 SkRect r(src); | 43 SkRect r(src); |
42 | 44 |
43 p.setLooper(NULL); | 45 p.setLooper(NULL); |
44 p.computeFastBounds(r, &r); | 46 p.computeFastBounds(r, &r); |
45 canvas.getTotalMatrix().mapRect(&r); | 47 canvas.getTotalMatrix().mapRect(&r); |
46 | 48 |
47 if (firstTime) { | 49 if (firstTime) { |
48 *dst = r; | 50 *dst = r; |
49 } else { | 51 } else { |
50 dst->join(r); | 52 dst->join(r); |
51 } | 53 } |
52 } else { | 54 } else { |
53 break; | 55 break; |
54 } | 56 } |
55 } | 57 } |
56 } | 58 } |
OLD | NEW |