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 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) {
     15     SkCanvas canvas;
     16 
     17     this->init(&canvas);
     18     for (;;) {
     19         SkPaint p(paint);
     20         if (this->next(&canvas, &p)) {
     21             p.setLooper(NULL);
     22             if (!p.canComputeFastBounds()) {
     23                 return false;
     24             }
     25         } else {
     26             break;
     27         }
     28     }
     29     return true;
     30 }
     31 
     32 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src,
     33                                      SkRect* dst) {
     34     SkCanvas canvas;
     35 
     36     *dst = src;   // catch case where there are no loops
     37     this->init(&canvas);
     38     for (bool firstTime = true;; firstTime = false) {
     39         SkPaint p(paint);
     40         if (this->next(&canvas, &p)) {
     41             SkRect r(src);
     42 
     43             p.setLooper(NULL);
     44             p.computeFastBounds(r, &r);
     45             canvas.getTotalMatrix().mapRect(&r);
     46 
     47             if (firstTime) {
     48                 *dst = r;
     49             } else {
     50                 dst->join(r);
     51             }
     52         } else {
     53             break;
     54         }
     55     }
     56 }
     57