blob: bac2d969c0505d318fe7881c638c1a4750544fd3 [file] [log] [blame]
commit-bot@chromium.org8b790282013-05-24 14:57:53 +00001/*
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
commit-bot@chromium.org8b790282013-05-24 14:57:53 +000014bool 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
32void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src,
33 SkRect* dst) {
34 SkCanvas canvas;
35
robertphillips@google.com135ece12013-06-03 16:58:58 +000036 *dst = src; // catch case where there are no loops
commit-bot@chromium.org8b790282013-05-24 14:57:53 +000037 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}