Home | History | Annotate | Download | only in core
      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 "SkDrawLooper.h"
      9 #include "SkCanvas.h"
     10 #include "SkMatrix.h"
     11 #include "SkPaint.h"
     12 #include "SkRect.h"
     13 
     14 SK_DEFINE_INST_COUNT(SkDrawLooper)
     15 
     16 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) {
     17     SkCanvas canvas;
     18 
     19     this->init(&canvas);
     20     for (;;) {
     21         SkPaint p(paint);
     22         if (this->next(&canvas, &p)) {
     23             p.setLooper(NULL);
     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& src,
     35                                      SkRect* dst) {
     36     SkCanvas canvas;
     37 
     38     *dst = src;   // catch case where there are no loops
     39     this->init(&canvas);
     40     for (bool firstTime = true;; firstTime = false) {
     41         SkPaint p(paint);
     42         if (this->next(&canvas, &p)) {
     43             SkRect r(src);
     44 
     45             p.setLooper(NULL);
     46             p.computeFastBounds(r, &r);
     47             canvas.getTotalMatrix().mapRect(&r);
     48 
     49             if (firstTime) {
     50                 *dst = r;
     51             } else {
     52                 dst->join(r);
     53             }
     54         } else {
     55             break;
     56         }
     57     }
     58 }
     59