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

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: static allocation of DrawContext; update rest of code. 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::canComputeFastBounds(const SkPaint& paint) { 14 bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) {
15 SkCanvas canvas; 15 SkCanvas canvas;
16 uint32_t storage[kDrawLooperContextStorageLongCount];
16 17
17 this->init(&canvas); 18 SkDrawLooper::DrawContext* context =
19 this->init(&canvas, storage, sizeof(storage));
18 for (;;) { 20 for (;;) {
19 SkPaint p(paint); 21 SkPaint p(paint);
20 if (this->next(&canvas, &p)) { 22 if (context->next(&canvas, &p)) {
21 p.setLooper(NULL); 23 p.setLooper(NULL);
22 if (!p.canComputeFastBounds()) { 24 if (!p.canComputeFastBounds()) {
25 context->cleanup(storage);
23 return false; 26 return false;
24 } 27 }
25 } else { 28 } else {
26 break; 29 break;
27 } 30 }
28 } 31 }
32 context->cleanup(storage);
29 return true; 33 return true;
30 } 34 }
31 35
32 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, 36 void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src,
33 SkRect* dst) { 37 SkRect* dst) {
34 SkCanvas canvas; 38 SkCanvas canvas;
39 uint32_t storage[kDrawLooperContextStorageLongCount];
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::DrawContext* context = this->init(
43 &canvas, storage, sizeof(storage));
38 for (bool firstTime = true;; firstTime = false) { 44 for (bool firstTime = true;; firstTime = false) {
39 SkPaint p(paint); 45 SkPaint p(paint);
40 if (this->next(&canvas, &p)) { 46 if (context->next(&canvas, &p)) {
41 SkRect r(src); 47 SkRect r(src);
42 48
43 p.setLooper(NULL); 49 p.setLooper(NULL);
44 p.computeFastBounds(r, &r); 50 p.computeFastBounds(r, &r);
45 canvas.getTotalMatrix().mapRect(&r); 51 canvas.getTotalMatrix().mapRect(&r);
46 52
47 if (firstTime) { 53 if (firstTime) {
48 *dst = r; 54 *dst = r;
49 } else { 55 } else {
50 dst->join(r); 56 dst->join(r);
51 } 57 }
52 } else { 58 } else {
53 break; 59 break;
54 } 60 }
55 } 61 }
62 context->cleanup(storage);
56 } 63 }
64
65 void SkDrawLooper::DrawContext::cleanup(void* storage) {
66 if ((void*)this == storage) {
67 this->~DrawContext();
68 } else {
69 SkDELETE(this);
70 }
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698