| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 bool SkImageFilter::canFilterImageGPU() const { | 322 bool SkImageFilter::canFilterImageGPU() const { |
| 323 return this->asFragmentProcessor(nullptr, nullptr, SkMatrix::I(), SkIRect())
; | 323 return this->asFragmentProcessor(nullptr, nullptr, SkMatrix::I(), SkIRect())
; |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
ext& ctx, | 326 bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
ext& ctx, |
| 327 SkBitmap* result, SkIPoint* offset) const { | 327 SkBitmap* result, SkIPoint* offset) const { |
| 328 #if SK_SUPPORT_GPU | 328 #if SK_SUPPORT_GPU |
| 329 SkBitmap input = src; | 329 SkBitmap input = src; |
| 330 SkASSERT(fInputCount == 1); | 330 SkASSERT(fInputCount == 1); |
| 331 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 331 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 332 if (this->getInput(0) && | 332 if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) { |
| 333 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffse
t)) { | |
| 334 return false; | 333 return false; |
| 335 } | 334 } |
| 336 GrTexture* srcTexture = input.getTexture(); | 335 GrTexture* srcTexture = input.getTexture(); |
| 337 SkIRect bounds; | 336 SkIRect bounds; |
| 338 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { | 337 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { |
| 339 return false; | 338 return false; |
| 340 } | 339 } |
| 341 SkRect srcRect = SkRect::Make(bounds); | 340 SkRect srcRect = SkRect::Make(bounds); |
| 342 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 341 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 343 GrContext* context = srcTexture->getContext(); | 342 GrContext* context = srcTexture->getContext(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 458 } |
| 460 | 459 |
| 461 #if SK_SUPPORT_GPU | 460 #if SK_SUPPORT_GPU |
| 462 | 461 |
| 463 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { | 462 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { |
| 464 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 463 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 465 result->setInfo(info); | 464 result->setInfo(info); |
| 466 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); | 465 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
| 467 } | 466 } |
| 468 | 467 |
| 469 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, | 468 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy, |
| 470 const SkBitmap& src, const Context& ctx, | 469 const SkBitmap& src, const Context& ctx, |
| 471 SkBitmap* result, SkIPoint* offset) const
{ | 470 SkBitmap* result, SkIPoint* offset) const { |
| 471 SkImageFilter* input = this->getInput(index); |
| 472 if (!input) { |
| 473 return true; |
| 474 } |
| 472 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | 475 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity |
| 473 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | 476 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was |
| 474 // called are restored before we return to the caller. | 477 // called are restored before we return to the caller. |
| 475 GrContext* context = src.getTexture()->getContext(); | 478 GrContext* context = src.getTexture()->getContext(); |
| 476 | 479 |
| 477 if (this->canFilterImageGPU()) { | 480 if (input->canFilterImageGPU()) { |
| 478 return this->filterImageGPU(proxy, src, ctx, result, offset); | 481 return input->filterImageGPU(proxy, src, ctx, result, offset); |
| 479 } else { | 482 } else { |
| 480 if (this->filterImage(proxy, src, ctx, result, offset)) { | 483 if (input->filterImage(proxy, src, ctx, result, offset)) { |
| 481 if (!result->getTexture()) { | 484 if (!result->getTexture()) { |
| 482 const SkImageInfo info = result->info(); | 485 const SkImageInfo info = result->info(); |
| 483 if (kUnknown_SkColorType == info.colorType()) { | 486 if (kUnknown_SkColorType == info.colorType()) { |
| 484 return false; | 487 return false; |
| 485 } | 488 } |
| 486 SkAutoTUnref<GrTexture> resultTex( | 489 SkAutoTUnref<GrTexture> resultTex( |
| 487 GrRefCachedBitmapTexture(context, *result,GrTextureParams::C
lampNoFilter())); | 490 GrRefCachedBitmapTexture(context, *result,GrTextureParams::C
lampNoFilter())); |
| 488 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); | 491 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); |
| 489 } | 492 } |
| 490 return true; | 493 return true; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } | 613 } |
| 611 return dev; | 614 return dev; |
| 612 } | 615 } |
| 613 | 616 |
| 614 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 617 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
| 615 const SkImageFilter::Context& ctx, | 618 const SkImageFilter::Context& ctx, |
| 616 SkBitmap* result, SkIPoint* offset) { | 619 SkBitmap* result, SkIPoint* offset) { |
| 617 return fDevice->filterImage(filter, src, ctx, result, offset); | 620 return fDevice->filterImage(filter, src, ctx, result, offset); |
| 618 } | 621 } |
| 619 | 622 |
| OLD | NEW |