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

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: comments Created 6 years, 9 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
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkSmallAllocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "SkSmallAllocator.h"
13 14
14 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) { 15 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const {
15 SkCanvas canvas; 16 SkCanvas canvas;
17 SkSmallAllocator<1, 32> allocator;
18 void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize() );
16 19
17 this->init(&canvas); 20 SkDrawLooper::Context* context = this->createContext(&canvas, buffer);
18 for (;;) { 21 for (;;) {
19 SkPaint p(paint); 22 SkPaint p(paint);
20 if (this->next(&canvas, &p)) { 23 if (context->next(&canvas, &p)) {
21 p.setLooper(NULL); 24 p.setLooper(NULL);
22 if (!p.canComputeFastBounds()) { 25 if (!p.canComputeFastBounds()) {
23 return false; 26 return false;
24 } 27 }
25 } else { 28 } else {
26 break; 29 break;
27 } 30 }
28 } 31 }
29 return true; 32 return true;
30 } 33 }
31 34
32 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, 35 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src,
33 SkRect* dst) { 36 SkRect* dst) const {
34 SkCanvas canvas; 37 SkCanvas canvas;
38 SkSmallAllocator<1, 32> allocator;
39 void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize() );
35 40
36 *dst = src; // catch case where there are no loops 41 *dst = src; // catch case where there are no loops
37 this->init(&canvas); 42 SkDrawLooper::Context* context = this->createContext(&canvas, buffer);
38 for (bool firstTime = true;; firstTime = false) { 43 for (bool firstTime = true;; firstTime = false) {
39 SkPaint p(paint); 44 SkPaint p(paint);
40 if (this->next(&canvas, &p)) { 45 if (context->next(&canvas, &p)) {
41 SkRect r(src); 46 SkRect r(src);
42 47
43 p.setLooper(NULL); 48 p.setLooper(NULL);
44 p.computeFastBounds(r, &r); 49 p.computeFastBounds(r, &r);
45 canvas.getTotalMatrix().mapRect(&r); 50 canvas.getTotalMatrix().mapRect(&r);
46 51
47 if (firstTime) { 52 if (firstTime) {
48 *dst = r; 53 *dst = r;
49 } else { 54 } else {
50 dst->join(r); 55 dst->join(r);
51 } 56 }
52 } else { 57 } else {
53 break; 58 break;
54 } 59 }
55 } 60 }
56 } 61 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkSmallAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698