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 #include "SkSmallAllocator.h" | 13 #include "SkSmallAllocator.h" |
14 | 14 |
15 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const { | 15 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const { |
16 SkCanvas canvas; | 16 SkCanvas canvas; |
17 SkSmallAllocator<1, 32> allocator; | 17 SkSmallAllocator<1, 32> allocator; |
| 18 void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()
); |
18 | 19 |
19 SkDrawLooper::Context* context = allocator.createWithIniter( | 20 SkDrawLooper::Context* context = this->createContext(&canvas, buffer); |
20 this->contextSize(), | |
21 [&](void* buffer) { | |
22 return this->createContext(&canvas, buffer); | |
23 }); | |
24 for (;;) { | 21 for (;;) { |
25 SkPaint p(paint); | 22 SkPaint p(paint); |
26 if (context->next(&canvas, &p)) { | 23 if (context->next(&canvas, &p)) { |
27 p.setLooper(nullptr); | 24 p.setLooper(nullptr); |
28 if (!p.canComputeFastBounds()) { | 25 if (!p.canComputeFastBounds()) { |
29 return false; | 26 return false; |
30 } | 27 } |
31 } else { | 28 } else { |
32 break; | 29 break; |
33 } | 30 } |
34 } | 31 } |
35 return true; | 32 return true; |
36 } | 33 } |
37 | 34 |
38 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& s, | 35 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& s, |
39 SkRect* dst) const { | 36 SkRect* dst) const { |
40 // src and dst rects may alias and we need to keep the original src, so copy
it. | 37 // src and dst rects may alias and we need to keep the original src, so copy
it. |
41 const SkRect src = s; | 38 const SkRect src = s; |
42 | 39 |
43 SkCanvas canvas; | 40 SkCanvas canvas; |
44 SkSmallAllocator<1, 32> allocator; | 41 SkSmallAllocator<1, 32> allocator; |
| 42 void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()
); |
45 | 43 |
46 *dst = src; // catch case where there are no loops | 44 *dst = src; // catch case where there are no loops |
47 SkDrawLooper::Context* context = allocator.createWithIniter( | 45 SkDrawLooper::Context* context = this->createContext(&canvas, buffer); |
48 this->contextSize(), | |
49 [&](void* buffer) { | |
50 return this->createContext(&canvas, buffer); | |
51 }); | |
52 for (bool firstTime = true;; firstTime = false) { | 46 for (bool firstTime = true;; firstTime = false) { |
53 SkPaint p(paint); | 47 SkPaint p(paint); |
54 if (context->next(&canvas, &p)) { | 48 if (context->next(&canvas, &p)) { |
55 SkRect r(src); | 49 SkRect r(src); |
56 | 50 |
57 p.setLooper(nullptr); | 51 p.setLooper(nullptr); |
58 p.computeFastBounds(r, &r); | 52 p.computeFastBounds(r, &r); |
59 canvas.getTotalMatrix().mapRect(&r); | 53 canvas.getTotalMatrix().mapRect(&r); |
60 | 54 |
61 if (firstTime) { | 55 if (firstTime) { |
62 *dst = r; | 56 *dst = r; |
63 } else { | 57 } else { |
64 dst->join(r); | 58 dst->join(r); |
65 } | 59 } |
66 } else { | 60 } else { |
67 break; | 61 break; |
68 } | 62 } |
69 } | 63 } |
70 } | 64 } |
71 | 65 |
72 bool SkDrawLooper::asABlurShadow(BlurShadowRec*) const { | 66 bool SkDrawLooper::asABlurShadow(BlurShadowRec*) const { |
73 return false; | 67 return false; |
74 } | 68 } |
OLD | NEW |