OLD | NEW |
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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const { | 188 void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const { |
189 this->INHERITED::flatten(buffer); | 189 this->INHERITED::flatten(buffer); |
190 buffer.writeInt((int) fXChannelSelector); | 190 buffer.writeInt((int) fXChannelSelector); |
191 buffer.writeInt((int) fYChannelSelector); | 191 buffer.writeInt((int) fYChannelSelector); |
192 buffer.writeScalar(fScale); | 192 buffer.writeScalar(fScale); |
193 } | 193 } |
194 | 194 |
195 bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, | 195 bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, |
196 const SkBitmap& src, | 196 const SkBitmap& src, |
197 const SkMatrix& ctm, | 197 const Context& ctx, |
198 SkBitmap* dst, | 198 SkBitmap* dst, |
199 SkIPoint* offset) const { | 199 SkIPoint* offset) const { |
200 SkBitmap displ = src, color = src; | 200 SkBitmap displ = src, color = src; |
201 const SkImageFilter* colorInput = getColorInput(); | 201 const SkImageFilter* colorInput = getColorInput(); |
202 const SkImageFilter* displInput = getDisplacementInput(); | 202 const SkImageFilter* displInput = getDisplacementInput(); |
203 SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0,
0); | 203 SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0,
0); |
204 if ((colorInput && !colorInput->filterImage(proxy, src, ctm, &color, &colorO
ffset)) || | 204 if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorO
ffset)) || |
205 (displInput && !displInput->filterImage(proxy, src, ctm, &displ, &displO
ffset))) { | 205 (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displO
ffset))) { |
206 return false; | 206 return false; |
207 } | 207 } |
208 if ((displ.colorType() != kPMColor_SkColorType) || | 208 if ((displ.colorType() != kPMColor_SkColorType) || |
209 (color.colorType() != kPMColor_SkColorType)) { | 209 (color.colorType() != kPMColor_SkColorType)) { |
210 return false; | 210 return false; |
211 } | 211 } |
212 | 212 |
213 SkAutoLockPixels alp_displacement(displ), alp_color(color); | 213 SkAutoLockPixels alp_displacement(displ), alp_color(color); |
214 if (!displ.getPixels() || !color.getPixels()) { | 214 if (!displ.getPixels() || !color.getPixels()) { |
215 return false; | 215 return false; |
216 } | 216 } |
217 SkIRect bounds; | 217 SkIRect bounds; |
218 color.getBounds(&bounds); | 218 color.getBounds(&bounds); |
219 bounds.offset(colorOffset); | 219 bounds.offset(colorOffset); |
220 if (!this->applyCropRect(&bounds, ctm)) { | 220 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
221 return false; | 221 return false; |
222 } | 222 } |
223 SkIRect displBounds; | 223 SkIRect displBounds; |
224 displ.getBounds(&displBounds); | 224 displ.getBounds(&displBounds); |
225 displBounds.offset(displOffset); | 225 displBounds.offset(displOffset); |
226 if (!this->applyCropRect(&displBounds, ctm)) { | 226 if (!this->applyCropRect(&displBounds, ctx.ctm())) { |
227 return false; | 227 return false; |
228 } | 228 } |
229 if (!bounds.intersect(displBounds)) { | 229 if (!bounds.intersect(displBounds)) { |
230 return false; | 230 return false; |
231 } | 231 } |
232 | 232 |
233 dst->setConfig(color.config(), bounds.width(), bounds.height()); | 233 dst->setConfig(color.config(), bounds.width(), bounds.height()); |
234 if (!dst->allocPixels()) { | 234 if (!dst->allocPixels()) { |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
238 SkVector scale = SkVector::Make(fScale, fScale); | 238 SkVector scale = SkVector::Make(fScale, fScale); |
239 ctm.mapVectors(&scale, 1); | 239 ctx.ctm().mapVectors(&scale, 1); |
240 SkIRect colorBounds = bounds; | 240 SkIRect colorBounds = bounds; |
241 colorBounds.offset(-colorOffset); | 241 colorBounds.offset(-colorOffset); |
242 | 242 |
243 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst, | 243 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst, |
244 &displ, colorOffset - displOffset, &color, colorBounds); | 244 &displ, colorOffset - displOffset, &color, colorBounds); |
245 | 245 |
246 offset->fX = bounds.left(); | 246 offset->fX = bounds.left(); |
247 offset->fY = bounds.top(); | 247 offset->fY = bounds.top(); |
248 return true; | 248 return true; |
249 } | 249 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 GrTextureAccess fDisplacementAccess; | 341 GrTextureAccess fDisplacementAccess; |
342 GrCoordTransform fColorTransform; | 342 GrCoordTransform fColorTransform; |
343 GrTextureAccess fColorAccess; | 343 GrTextureAccess fColorAccess; |
344 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 344 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
345 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 345 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
346 SkVector fScale; | 346 SkVector fScale; |
347 | 347 |
348 typedef GrEffect INHERITED; | 348 typedef GrEffect INHERITED; |
349 }; | 349 }; |
350 | 350 |
351 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const SkMatrix& ctm, | 351 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const Context& ctx, |
352 SkBitmap* result, SkIPoint* offset)
const { | 352 SkBitmap* result, SkIPoint* offset)
const { |
353 SkBitmap colorBM = src; | 353 SkBitmap colorBM = src; |
354 SkIPoint colorOffset = SkIPoint::Make(0, 0); | 354 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
355 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctm,
&colorBM, | 355 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx,
&colorBM, |
356 &colorOffset)) { | 356 &colorOffset)) { |
357 return false; | 357 return false; |
358 } | 358 } |
359 GrTexture* color = colorBM.getTexture(); | 359 GrTexture* color = colorBM.getTexture(); |
360 SkBitmap displacementBM = src; | 360 SkBitmap displacementBM = src; |
361 SkIPoint displacementOffset = SkIPoint::Make(0, 0); | 361 SkIPoint displacementOffset = SkIPoint::Make(0, 0); |
362 if (getDisplacementInput() && | 362 if (getDisplacementInput() && |
363 !getDisplacementInput()->getInputResultGPU(proxy, src, ctm, &displacemen
tBM, | 363 !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacemen
tBM, |
364 &displacementOffset)) { | 364 &displacementOffset)) { |
365 return false; | 365 return false; |
366 } | 366 } |
367 GrTexture* displacement = displacementBM.getTexture(); | 367 GrTexture* displacement = displacementBM.getTexture(); |
368 GrContext* context = color->getContext(); | 368 GrContext* context = color->getContext(); |
369 | 369 |
370 GrTextureDesc desc; | 370 GrTextureDesc desc; |
371 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 371 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
372 desc.fWidth = colorBM.width(); | 372 desc.fWidth = colorBM.width(); |
373 desc.fHeight = colorBM.height(); | 373 desc.fHeight = colorBM.height(); |
374 desc.fConfig = kSkia8888_GrPixelConfig; | 374 desc.fConfig = kSkia8888_GrPixelConfig; |
375 | 375 |
376 GrAutoScratchTexture ast(context, desc); | 376 GrAutoScratchTexture ast(context, desc); |
377 SkAutoTUnref<GrTexture> dst(ast.detach()); | 377 SkAutoTUnref<GrTexture> dst(ast.detach()); |
378 | 378 |
379 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); | 379 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); |
380 | 380 |
381 SkVector scale = SkVector::Make(fScale, fScale); | 381 SkVector scale = SkVector::Make(fScale, fScale); |
382 ctm.mapVectors(&scale, 1); | 382 ctx.ctm().mapVectors(&scale, 1); |
383 SkIRect bounds; | 383 SkIRect bounds; |
384 colorBM.getBounds(&bounds); | 384 colorBM.getBounds(&bounds); |
385 bounds.offset(colorOffset); | 385 bounds.offset(colorOffset); |
386 if (!this->applyCropRect(&bounds, ctm)) { | 386 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
387 return false; | 387 return false; |
388 } | 388 } |
389 SkIRect displBounds; | 389 SkIRect displBounds; |
390 displacementBM.getBounds(&displBounds); | 390 displacementBM.getBounds(&displBounds); |
391 displBounds.offset(displacementOffset); | 391 displBounds.offset(displacementOffset); |
392 if (!this->applyCropRect(&displBounds, ctm)) { | 392 if (!this->applyCropRect(&displBounds, ctx.ctm())) { |
393 return false; | 393 return false; |
394 } | 394 } |
395 if (!bounds.intersect(displBounds)) { | 395 if (!bounds.intersect(displBounds)) { |
396 return false; | 396 return false; |
397 } | 397 } |
398 | 398 |
399 GrPaint paint; | 399 GrPaint paint; |
400 SkMatrix offsetMatrix = GrEffect::MakeDivByTextureWHMatrix(displacement); | 400 SkMatrix offsetMatrix = GrEffect::MakeDivByTextureWHMatrix(displacement); |
401 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), | 401 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.
fX), |
402 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); | 402 SkIntToScalar(colorOffset.fY - displacementOffset.
fY)); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 const GrGLCaps&) { | 602 const GrGLCaps&) { |
603 const GrDisplacementMapEffect& displacementMap = | 603 const GrDisplacementMapEffect& displacementMap = |
604 drawEffect.castEffect<GrDisplacementMapEffect>(); | 604 drawEffect.castEffect<GrDisplacementMapEffect>(); |
605 | 605 |
606 EffectKey xKey = displacementMap.xChannelSelector(); | 606 EffectKey xKey = displacementMap.xChannelSelector(); |
607 EffectKey yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBi
ts; | 607 EffectKey yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBi
ts; |
608 | 608 |
609 return xKey | yKey; | 609 return xKey | yKey; |
610 } | 610 } |
611 #endif | 611 #endif |
OLD | NEW |