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

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

Issue 196353021: Revert "Implement support for expanding crop rects in image filters" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | « src/effects/SkColorFilterImageFilter.cpp ('k') | src/effects/SkDropShadowImageFilter.cpp » ('j') | 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 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, ctx, &color, &colorO ffset)) || 204 if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorO ffset)) ||
205 (displInput && !displInput->filterImage(proxy, src, ctx, &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
213 SkAutoLockPixels alp_displacement(displ), alp_color(color);
214 if (!displ.getPixels() || !color.getPixels()) {
215 return false;
216 }
212 SkIRect bounds; 217 SkIRect bounds;
213 // Since computeDisplacement does bounds checking on color pixel access, we don't need to pad 218 color.getBounds(&bounds);
214 // the color bitmap to bounds here. 219 bounds.offset(colorOffset);
215 if (!this->applyCropRect(ctx, color, colorOffset, &bounds)) { 220 if (!this->applyCropRect(&bounds, ctx.ctm())) {
216 return false; 221 return false;
217 } 222 }
218 SkIRect displBounds; 223 SkIRect displBounds;
219 if (!this->applyCropRect(ctx, proxy, displ, &displOffset, &displBounds, &dis pl)) { 224 displ.getBounds(&displBounds);
225 displBounds.offset(displOffset);
226 if (!this->applyCropRect(&displBounds, ctx.ctm())) {
220 return false; 227 return false;
221 } 228 }
222 if (!bounds.intersect(displBounds)) { 229 if (!bounds.intersect(displBounds)) {
223 return false; 230 return false;
224 } 231 }
225 SkAutoLockPixels alp_displacement(displ), alp_color(color);
226 if (!displ.getPixels() || !color.getPixels()) {
227 return false;
228 }
229 232
230 dst->setConfig(color.config(), bounds.width(), bounds.height()); 233 dst->setConfig(color.config(), bounds.width(), bounds.height());
231 if (!dst->allocPixels()) { 234 if (!dst->allocPixels()) {
232 return false; 235 return false;
233 } 236 }
234 237
235 SkVector scale = SkVector::Make(fScale, fScale); 238 SkVector scale = SkVector::Make(fScale, fScale);
236 ctx.ctm().mapVectors(&scale, 1); 239 ctx.ctm().mapVectors(&scale, 1);
237 SkIRect colorBounds = bounds; 240 SkIRect colorBounds = bounds;
238 colorBounds.offset(-colorOffset); 241 colorBounds.offset(-colorOffset);
239 242
240 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst, 243 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst,
241 &displ, colorOffset - displOffset, &color, colorBounds); 244 &displ, colorOffset - displOffset, &color, colorBounds);
242 245
243 offset->fX = bounds.left(); 246 offset->fX = bounds.left();
244 offset->fY = bounds.top(); 247 offset->fY = bounds.top();
245 return true; 248 return true;
246 } 249 }
247 250
248 void SkDisplacementMapEffect::computeFastBounds(const SkRect& src, SkRect* dst) const { 251 void SkDisplacementMapEffect::computeFastBounds(const SkRect& src, SkRect* dst) const {
249 if (getColorInput()) { 252 if (getColorInput()) {
250 getColorInput()->computeFastBounds(src, dst); 253 getColorInput()->computeFastBounds(src, dst);
251 } else { 254 } else {
252 *dst = src; 255 *dst = src;
253 } 256 }
254 dst->outset(fScale * SK_ScalarHalf, fScale * SK_ScalarHalf);
255 } 257 }
256 258
257 bool SkDisplacementMapEffect::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, 259 bool SkDisplacementMapEffect::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
258 SkIRect* dst) const { 260 SkIRect* dst) const {
259 SkIRect bounds = src; 261 if (getColorInput()) {
260 if (getColorInput() && !getColorInput()->filterBounds(src, ctm, &bounds)) { 262 return getColorInput()->filterBounds(src, ctm, dst);
261 return false;
262 } 263 }
263 bounds.outset(SkScalarCeilToInt(fScale * SK_ScalarHalf), 264 *dst = src;
264 SkScalarCeilToInt(fScale * SK_ScalarHalf));
265 *dst = bounds;
266 return true; 265 return true;
267 } 266 }
268 267
269 /////////////////////////////////////////////////////////////////////////////// 268 ///////////////////////////////////////////////////////////////////////////////
270 269
271 #if SK_SUPPORT_GPU 270 #if SK_SUPPORT_GPU
272 class GrGLDisplacementMapEffect : public GrGLEffect { 271 class GrGLDisplacementMapEffect : public GrGLEffect {
273 public: 272 public:
274 GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory, 273 GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory,
275 const GrDrawEffect& drawEffect); 274 const GrDrawEffect& drawEffect);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 }; 349 };
351 350
352 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, 351 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
353 SkBitmap* result, SkIPoint* offset) const { 352 SkBitmap* result, SkIPoint* offset) const {
354 SkBitmap colorBM = src; 353 SkBitmap colorBM = src;
355 SkIPoint colorOffset = SkIPoint::Make(0, 0); 354 SkIPoint colorOffset = SkIPoint::Make(0, 0);
356 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, 355 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM,
357 &colorOffset)) { 356 &colorOffset)) {
358 return false; 357 return false;
359 } 358 }
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, ctx, &displacemen tBM, 363 !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacemen tBM,
364 &displacementOffset)) { 364 &displacementOffset)) {
365 return false; 365 return false;
366 } 366 }
367 SkIRect bounds;
368 // Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to
369 // pad the color bitmap to bounds here.
370 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) {
371 return false;
372 }
373 SkIRect displBounds;
374 if (!this->applyCropRect(ctx, proxy, displacementBM,
375 &displacementOffset, &displBounds, &displacementBM) ) {
376 return false;
377 }
378 if (!bounds.intersect(displBounds)) {
379 return false;
380 }
381 GrTexture* color = colorBM.getTexture();
382 GrTexture* displacement = displacementBM.getTexture(); 367 GrTexture* displacement = displacementBM.getTexture();
383 GrContext* context = color->getContext(); 368 GrContext* context = color->getContext();
384 369
385 GrTextureDesc desc; 370 GrTextureDesc desc;
386 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 371 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
387 desc.fWidth = colorBM.width(); 372 desc.fWidth = colorBM.width();
388 desc.fHeight = colorBM.height(); 373 desc.fHeight = colorBM.height();
389 desc.fConfig = kSkia8888_GrPixelConfig; 374 desc.fConfig = kSkia8888_GrPixelConfig;
390 375
391 GrAutoScratchTexture ast(context, desc); 376 GrAutoScratchTexture ast(context, desc);
392 SkAutoTUnref<GrTexture> dst(ast.detach()); 377 SkAutoTUnref<GrTexture> dst(ast.detach());
393 378
394 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); 379 GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
395 380
396 SkVector scale = SkVector::Make(fScale, fScale); 381 SkVector scale = SkVector::Make(fScale, fScale);
397 ctx.ctm().mapVectors(&scale, 1); 382 ctx.ctm().mapVectors(&scale, 1);
383 SkIRect bounds;
384 colorBM.getBounds(&bounds);
385 bounds.offset(colorOffset);
386 if (!this->applyCropRect(&bounds, ctx.ctm())) {
387 return false;
388 }
389 SkIRect displBounds;
390 displacementBM.getBounds(&displBounds);
391 displBounds.offset(displacementOffset);
392 if (!this->applyCropRect(&displBounds, ctx.ctm())) {
393 return false;
394 }
395 if (!bounds.intersect(displBounds)) {
396 return false;
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));
403 403
404 paint.addColorEffect( 404 paint.addColorEffect(
405 GrDisplacementMapEffect::Create(fXChannelSelector, 405 GrDisplacementMapEffect::Create(fXChannelSelector,
406 fYChannelSelector, 406 fYChannelSelector,
407 scale, 407 scale,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « src/effects/SkColorFilterImageFilter.cpp ('k') | src/effects/SkDropShadowImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698