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