Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: src/core/SkDrawLooper.cpp

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make methods const. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13
14 bool SkDrawLooper::next(SkCanvas* canvas, SkPaint* paint,
15 DrawContext* context) const {
16 bool ret = next_internal(canvas, paint, context);
scroggo 2014/02/06 17:57:13 this->next_internal (or onNext)
17 if (!ret)
18 delete context;
scroggo 2014/02/06 17:57:13 SkDELETE
19 return ret;
20 }
21
14 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) { 22 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) {
15 SkCanvas canvas; 23 SkCanvas canvas;
16 24
17 this->init(&canvas); 25 SkDrawLooper::DrawContext* context = this->init(&canvas);
18 for (;;) { 26 for (;;) {
19 SkPaint p(paint); 27 SkPaint p(paint);
20 if (this->next(&canvas, &p)) { 28 if (this->next(&canvas, &p, context)) {
21 p.setLooper(NULL); 29 p.setLooper(NULL);
22 if (!p.canComputeFastBounds()) { 30 if (!p.canComputeFastBounds()) {
23 return false; 31 return false;
24 } 32 }
25 } else { 33 } else {
26 break; 34 break;
27 } 35 }
28 } 36 }
29 return true; 37 return true;
30 } 38 }
31 39
32 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, 40 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src,
33 SkRect* dst) { 41 SkRect* dst) {
34 SkCanvas canvas; 42 SkCanvas canvas;
35 43
36 *dst = src; // catch case where there are no loops 44 *dst = src; // catch case where there are no loops
37 this->init(&canvas); 45 SkDrawLooper::DrawContext* context = this->init(&canvas);
38 for (bool firstTime = true;; firstTime = false) { 46 for (bool firstTime = true;; firstTime = false) {
39 SkPaint p(paint); 47 SkPaint p(paint);
40 if (this->next(&canvas, &p)) { 48 if (this->next(&canvas, &p, context)) {
41 SkRect r(src); 49 SkRect r(src);
42 50
43 p.setLooper(NULL); 51 p.setLooper(NULL);
44 p.computeFastBounds(r, &r); 52 p.computeFastBounds(r, &r);
45 canvas.getTotalMatrix().mapRect(&r); 53 canvas.getTotalMatrix().mapRect(&r);
46 54
47 if (firstTime) { 55 if (firstTime) {
48 *dst = r; 56 *dst = r;
49 } else { 57 } else {
50 dst->join(r); 58 dst->join(r);
51 } 59 }
52 } else { 60 } else {
53 break; 61 break;
54 } 62 }
55 } 63 }
56 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698