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