OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 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 "SkXfermodeImageFilter.h" | 8 #include "SkXfermodeImageFilter.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 this->getInput(1)->toString(str); | 113 this->getInput(1)->toString(str); |
114 str->appendf(")"); | 114 str->appendf(")"); |
115 } | 115 } |
116 str->append(")"); | 116 str->append(")"); |
117 } | 117 } |
118 #endif | 118 #endif |
119 | 119 |
120 #if SK_SUPPORT_GPU | 120 #if SK_SUPPORT_GPU |
121 | 121 |
122 bool SkXfermodeImageFilter::canFilterImageGPU() const { | 122 bool SkXfermodeImageFilter::canFilterImageGPU() const { |
123 return fMode && fMode->asFragmentProcessor(nullptr, nullptr) && !cropRectIsS
et(); | 123 return fMode && fMode->asFragmentProcessor(nullptr, nullptr, NULL) && !cropR
ectIsSet(); |
124 } | 124 } |
125 | 125 |
126 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 126 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
127 const SkBitmap& src, | 127 const SkBitmap& src, |
128 const Context& ctx, | 128 const Context& ctx, |
129 SkBitmap* result, | 129 SkBitmap* result, SkIPoint* offset) c
onst { |
130 SkIPoint* offset) const { | |
131 SkBitmap background = src; | 130 SkBitmap background = src; |
132 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 131 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
133 if (!this->filterInputGPU(0, proxy, src, ctx, &background, &backgroundOffset
)) { | 132 if (!this->filterInputGPU(0, proxy, src, ctx, &background, &backgroundOffset
)) { |
134 return false; | 133 return false; |
135 } | 134 } |
136 | 135 |
137 GrTexture* backgroundTex = background.getTexture(); | 136 GrTexture* backgroundTex = background.getTexture(); |
138 if (nullptr == backgroundTex) { | 137 if (nullptr == backgroundTex) { |
139 SkASSERT(false); | 138 SkASSERT(false); |
140 return false; | 139 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
158 auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint()); | 157 auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint()); |
159 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc,
constraint)); | 158 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc,
constraint)); |
160 if (!dst) { | 159 if (!dst) { |
161 return false; | 160 return false; |
162 } | 161 } |
163 | 162 |
164 GrPaint paint; | 163 GrPaint paint; |
165 SkMatrix bgMatrix; | 164 SkMatrix bgMatrix; |
166 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); | 165 bgMatrix.setIDiv(backgroundTex->width(), backgroundTex->height()); |
167 SkAutoTUnref<const GrFragmentProcessor> bgFP( | 166 SkAutoTUnref<const GrFragmentProcessor> bgFP( |
168 GrSimpleTextureEffect::Create(backgroundTex, bgMatrix)); | 167 GrSimpleTextureEffect::Create(backgroundTex, bgMatrix, |
169 if (!fMode || !fMode->asFragmentProcessor(&xferFP, bgFP)) { | 168 kLocal_GrCoordSet, dst->asRenderTarget()))
; |
| 169 if (!fMode || !fMode->asFragmentProcessor(&xferFP, bgFP, dst->asRenderTarget
())) { |
170 // canFilterImageGPU() should've taken care of this | 170 // canFilterImageGPU() should've taken care of this |
171 SkASSERT(false); | 171 SkASSERT(false); |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
175 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); | 175 SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foreg
roundTex); |
176 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), | 176 foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOf
fset.fX), |
177 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); | 177 SkIntToScalar(backgroundOffset.fY-foregroundOf
fset.fY)); |
178 | 178 |
179 | 179 |
180 SkRect srcRect; | 180 SkRect srcRect; |
181 src.getBounds(&srcRect); | 181 src.getBounds(&srcRect); |
182 | 182 |
183 SkAutoTUnref<const GrFragmentProcessor> foregroundDomain(GrTextureDomainEffe
ct::Create( | 183 SkAutoTUnref<const GrFragmentProcessor> foregroundDomain(GrTextureDomainEffe
ct::Create( |
184 foregroundTex, foregroundMatrix, | 184 foregroundTex, foregroundMatrix, |
185 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), | 185 GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()), |
186 GrTextureDomain::kDecal_Mode, | 186 GrTextureDomain::kDecal_Mode, |
187 GrTextureParams::kNone_FilterMode) | 187 GrTextureParams::kNone_FilterMode, |
188 ); | 188 kLocal_GrCoordSet, |
| 189 dst->asRenderTarget())); |
189 | 190 |
190 paint.addColorFragmentProcessor(foregroundDomain.get()); | 191 paint.addColorFragmentProcessor(foregroundDomain.get()); |
191 if (xferFP) { | 192 if (xferFP) { |
192 paint.addColorFragmentProcessor(xferFP)->unref(); | 193 paint.addColorFragmentProcessor(xferFP)->unref(); |
193 } | 194 } |
194 | 195 |
195 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); | 196 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTa
rget())); |
196 if (!drawContext) { | 197 if (!drawContext) { |
197 return false; | 198 return false; |
198 } | 199 } |
199 | 200 |
200 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), srcRect); | 201 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), srcRect); |
201 | 202 |
202 offset->fX = backgroundOffset.fX; | 203 offset->fX = backgroundOffset.fX; |
203 offset->fY = backgroundOffset.fY; | 204 offset->fY = backgroundOffset.fY; |
204 WrapTexture(dst, src.width(), src.height(), result); | 205 WrapTexture(dst, src.width(), src.height(), result); |
205 return true; | 206 return true; |
206 } | 207 } |
207 | 208 |
208 #endif | 209 #endif |
209 | 210 |
OLD | NEW |