| 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 "SkImageFilter.h" | 8 #include "SkImageFilter.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 SkASSERT(fInputCount == 1); | 327 SkASSERT(fInputCount == 1); |
| 328 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 328 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 329 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { | 329 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { |
| 330 return false; | 330 return false; |
| 331 } | 331 } |
| 332 GrTexture* srcTexture = input.getTexture(); | 332 GrTexture* srcTexture = input.getTexture(); |
| 333 SkIRect bounds; | 333 SkIRect bounds; |
| 334 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { | 334 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 SkRect srcRect = SkRect::Make(bounds); | |
| 338 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | |
| 339 GrContext* context = srcTexture->getContext(); | 337 GrContext* context = srcTexture->getContext(); |
| 340 | 338 |
| 341 GrSurfaceDesc desc; | 339 GrSurfaceDesc desc; |
| 342 desc.fFlags = kRenderTarget_GrSurfaceFlag, | 340 desc.fFlags = kRenderTarget_GrSurfaceFlag, |
| 343 desc.fWidth = bounds.width(); | 341 desc.fWidth = bounds.width(); |
| 344 desc.fHeight = bounds.height(); | 342 desc.fHeight = bounds.height(); |
| 345 desc.fConfig = kRGBA_8888_GrPixelConfig; | 343 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 346 | 344 |
| 347 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 345 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
| 348 if (!dst) { | 346 if (!dst) { |
| 349 return false; | 347 return false; |
| 350 } | 348 } |
| 351 | 349 |
| 352 // setup new clip | |
| 353 GrClip clip(dstRect); | |
| 354 | |
| 355 GrFragmentProcessor* fp; | 350 GrFragmentProcessor* fp; |
| 356 offset->fX = bounds.left(); | 351 offset->fX = bounds.left(); |
| 357 offset->fY = bounds.top(); | 352 offset->fY = bounds.top(); |
| 358 bounds.offset(-srcOffset); | 353 bounds.offset(-srcOffset); |
| 359 SkMatrix matrix(ctx.ctm()); | 354 SkMatrix matrix(ctx.ctm()); |
| 360 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 355 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
| 361 GrPaint paint; | 356 GrPaint paint; |
| 362 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { | 357 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { |
| 363 SkASSERT(fp); | 358 SkASSERT(fp); |
| 364 paint.addColorFragmentProcessor(fp)->unref(); | 359 paint.addColorFragmentProcessor(fp)->unref(); |
| 365 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 360 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 366 | 361 |
| 367 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRend
erTarget())); | 362 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRend
erTarget())); |
| 368 if (drawContext) { | 363 if (drawContext) { |
| 364 SkRect srcRect = SkRect::Make(bounds); |
| 365 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 366 GrClip clip(dstRect); |
| 369 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, src
Rect); | 367 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, src
Rect); |
| 370 | 368 |
| 371 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, r
esult); | 369 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, r
esult); |
| 372 return true; | 370 return true; |
| 373 } | 371 } |
| 374 } | 372 } |
| 375 #endif | 373 #endif |
| 376 return false; | 374 return false; |
| 377 } | 375 } |
| 378 | 376 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 658 } |
| 661 return dev; | 659 return dev; |
| 662 } | 660 } |
| 663 | 661 |
| 664 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 662 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
| 665 const SkImageFilter::Context& ctx, | 663 const SkImageFilter::Context& ctx, |
| 666 SkBitmap* result, SkIPoint* offset) { | 664 SkBitmap* result, SkIPoint* offset) { |
| 667 return fDevice->filterImage(filter, src, ctx, result, offset); | 665 return fDevice->filterImage(filter, src, ctx, result, offset); |
| 668 } | 666 } |
| 669 | 667 |
| OLD | NEW |