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