OLD | NEW |
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 "SkColorFilterImageFilter.h" | 8 #include "SkColorFilterImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 buffer.writeFlattenable(fColorFilter); | 93 buffer.writeFlattenable(fColorFilter); |
94 } | 94 } |
95 | 95 |
96 SkColorFilterImageFilter::~SkColorFilterImageFilter() { | 96 SkColorFilterImageFilter::~SkColorFilterImageFilter() { |
97 SkSafeUnref(fColorFilter); | 97 SkSafeUnref(fColorFilter); |
98 } | 98 } |
99 | 99 |
100 bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc
e, | 100 bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc
e, |
101 const SkMatrix& matrix, | 101 const SkMatrix& matrix, |
102 SkBitmap* result, | 102 SkBitmap* result, |
103 SkIPoint* loc) { | 103 SkIPoint* offset) { |
104 SkBitmap src = source; | 104 SkBitmap src = source; |
105 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, lo
c)) { | 105 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 106 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s
rcOffset)) { |
106 return false; | 107 return false; |
107 } | 108 } |
108 | 109 |
109 SkIRect bounds; | 110 SkIRect bounds; |
110 src.getBounds(&bounds); | 111 src.getBounds(&bounds); |
| 112 bounds.offset(srcOffset); |
111 if (!this->applyCropRect(&bounds, matrix)) { | 113 if (!this->applyCropRect(&bounds, matrix)) { |
112 return false; | 114 return false; |
113 } | 115 } |
114 | 116 |
115 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 117 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
116 if (NULL == device.get()) { | 118 if (NULL == device.get()) { |
117 return false; | 119 return false; |
118 } | 120 } |
119 SkCanvas canvas(device.get()); | 121 SkCanvas canvas(device.get()); |
120 SkPaint paint; | 122 SkPaint paint; |
121 | 123 |
122 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 124 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
123 paint.setColorFilter(fColorFilter); | 125 paint.setColorFilter(fColorFilter); |
124 canvas.drawSprite(src, -bounds.fLeft, -bounds.fTop, &paint); | 126 canvas.drawSprite(src, srcOffset.fX - bounds.fLeft, srcOffset.fY - bounds.fT
op, &paint); |
125 | 127 |
126 *result = device.get()->accessBitmap(false); | 128 *result = device.get()->accessBitmap(false); |
127 loc->fX += bounds.fLeft; | 129 offset->fX = bounds.fLeft; |
128 loc->fY += bounds.fTop; | 130 offset->fY = bounds.fTop; |
129 return true; | 131 return true; |
130 } | 132 } |
131 | 133 |
132 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { | 134 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { |
133 if (!cropRectIsSet()) { | 135 if (!cropRectIsSet()) { |
134 if (filter) { | 136 if (filter) { |
135 *filter = fColorFilter; | 137 *filter = fColorFilter; |
136 fColorFilter->ref(); | 138 fColorFilter->ref(); |
137 } | 139 } |
138 return true; | 140 return true; |
139 } | 141 } |
140 return false; | 142 return false; |
141 } | 143 } |
OLD | NEW |