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

Side by Side Diff: src/effects/SkMergeImageFilter.cpp

Issue 23600047: Implement crop rect support for the merge image filter. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove useless #include. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « include/effects/SkMergeImageFilter.h ('k') | no next file » | 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 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkMergeImageFilter.h" 8 #include "SkMergeImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 21 matching lines...) Expand all
32 int inputCount = countInputs(); 32 int inputCount = countInputs();
33 for (int i = 0; i < inputCount; ++i) { 33 for (int i = 0; i < inputCount; ++i) {
34 fModes[i] = SkToU8(modes[i]); 34 fModes[i] = SkToU8(modes[i]);
35 } 35 }
36 } else { 36 } else {
37 fModes = NULL; 37 fModes = NULL;
38 } 38 }
39 } 39 }
40 40
41 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* first, SkImageFilter* seco nd, 41 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* first, SkImageFilter* seco nd,
42 SkXfermode::Mode mode) : INHERITED(first, second) { 42 SkXfermode::Mode mode,
43 const SkIRect* cropRect) : INHERITED(firs t, second, cropRect) {
43 if (SkXfermode::kSrcOver_Mode != mode) { 44 if (SkXfermode::kSrcOver_Mode != mode) {
44 SkXfermode::Mode modes[] = { mode, mode }; 45 SkXfermode::Mode modes[] = { mode, mode };
45 this->initModes(modes); 46 this->initModes(modes);
46 } else { 47 } else {
47 fModes = NULL; 48 fModes = NULL;
48 } 49 }
49 } 50 }
50 51
51 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count, 52 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count,
52 const SkXfermode::Mode modes[]) : INHERIT ED(count, filters) { 53 const SkXfermode::Mode modes[],
54 const SkIRect* cropRect) : INHERITED(coun t, filters, cropRect) {
53 this->initModes(modes); 55 this->initModes(modes);
54 } 56 }
55 57
56 SkMergeImageFilter::~SkMergeImageFilter() { 58 SkMergeImageFilter::~SkMergeImageFilter() {
57 59
58 if (fModes != SkTCast<uint8_t*>(fStorage)) { 60 if (fModes != SkTCast<uint8_t*>(fStorage)) {
59 sk_free(fModes); 61 sk_free(fModes);
60 } 62 }
61 } 63 }
62 64
(...skipping 29 matching lines...) Expand all
92 return true; 94 return true;
93 } 95 }
94 96
95 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, 97 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
96 const SkMatrix& ctm, 98 const SkMatrix& ctm,
97 SkBitmap* result, SkIPoint* loc) { 99 SkBitmap* result, SkIPoint* loc) {
98 if (countInputs() < 1) { 100 if (countInputs() < 1) {
99 return false; 101 return false;
100 } 102 }
101 103
102 const SkIRect srcBounds = SkIRect::MakeXYWH(loc->x(), loc->y(),
103 src.width(), src.height());
104 SkIRect bounds; 104 SkIRect bounds;
105 if (!this->filterBounds(srcBounds, ctm, &bounds)) { 105 src.getBounds(&bounds);
106 if (!this->applyCropRect(&bounds, ctm)) {
106 return false; 107 return false;
107 } 108 }
108 109
109 const int x0 = bounds.left(); 110 const int x0 = bounds.left();
110 const int y0 = bounds.top(); 111 const int y0 = bounds.top();
111 112
112 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); 113 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight()));
113 if (NULL == dst) { 114 if (NULL == dst) {
114 return false; 115 return false;
115 } 116 }
116 SkCanvas canvas(dst); 117 SkCanvas canvas(dst);
117 SkPaint paint; 118 SkPaint paint;
118 119
119 int inputCount = countInputs(); 120 int inputCount = countInputs();
120 for (int i = 0; i < inputCount; ++i) { 121 for (int i = 0; i < inputCount; ++i) {
121 SkBitmap tmp; 122 SkBitmap tmp;
122 const SkBitmap* srcPtr; 123 const SkBitmap* srcPtr;
123 SkIPoint pos = *loc; 124 SkIPoint pos = SkIPoint::Make(0, 0);
124 SkImageFilter* filter = getInput(i); 125 SkImageFilter* filter = getInput(i);
125 if (filter) { 126 if (filter) {
126 if (!filter->filterImage(proxy, src, ctm, &tmp, &pos)) { 127 if (!filter->filterImage(proxy, src, ctm, &tmp, &pos)) {
127 return false; 128 return false;
128 } 129 }
129 srcPtr = &tmp; 130 srcPtr = &tmp;
130 } else { 131 } else {
131 srcPtr = &src; 132 srcPtr = &src;
132 } 133 }
133 134
134 if (fModes) { 135 if (fModes) {
135 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); 136 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
136 } else { 137 } else {
137 paint.setXfermode(NULL); 138 paint.setXfermode(NULL);
138 } 139 }
139 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint); 140 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint);
140 } 141 }
141 142
142 loc->set(bounds.left(), bounds.top()); 143 loc->fX += bounds.left();
144 loc->fY += bounds.top();
143 *result = dst->accessBitmap(false); 145 *result = dst->accessBitmap(false);
144 return true; 146 return true;
145 } 147 }
146 148
147 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { 149 void SkMergeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
148 this->INHERITED::flatten(buffer); 150 this->INHERITED::flatten(buffer);
149 151
150 buffer.writeBool(fModes != NULL); 152 buffer.writeBool(fModes != NULL);
151 if (fModes) { 153 if (fModes) {
152 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0])); 154 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0]));
153 } 155 }
154 } 156 }
155 157
156 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer) : INHERI TED(buffer) { 158 SkMergeImageFilter::SkMergeImageFilter(SkFlattenableReadBuffer& buffer) : INHERI TED(buffer) {
157 bool hasModes = buffer.readBool(); 159 bool hasModes = buffer.readBool();
158 if (hasModes) { 160 if (hasModes) {
159 this->initAllocModes(); 161 this->initAllocModes();
160 SkASSERT(buffer.getArrayCount() == countInputs() * sizeof(fModes[0])); 162 SkASSERT(buffer.getArrayCount() == countInputs() * sizeof(fModes[0]));
161 buffer.readByteArray(fModes); 163 buffer.readByteArray(fModes);
162 } else { 164 } else {
163 fModes = 0; 165 fModes = 0;
164 } 166 }
165 } 167 }
OLDNEW
« no previous file with comments | « include/effects/SkMergeImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698