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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 this->onFilterImage(proxy, src, context, result, offset)) { | 256 this->onFilterImage(proxy, src, context, result, offset)) { |
257 if (context.cache()) { | 257 if (context.cache()) { |
258 context.cache()->set(key, *result, *offset); | 258 context.cache()->set(key, *result, *offset); |
259 } | 259 } |
260 return true; | 260 return true; |
261 } | 261 } |
262 return false; | 262 return false; |
263 } | 263 } |
264 | 264 |
265 bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src, | 265 bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src, |
266 const Context& context, | 266 const Context& origCtx, |
267 SkBitmap* result, SkIPoint* offset) const { | 267 SkBitmap* result, SkIPoint* offset, |
| 268 bool relaxSizeConstraint) const { |
268 SkImageFilter* input = this->getInput(index); | 269 SkImageFilter* input = this->getInput(index); |
269 return !input || input->filterImage(proxy, src, context, result, offset); | 270 if (!input) { |
| 271 return true; |
| 272 } |
| 273 |
| 274 SizeConstraint constraint = origCtx.sizeConstraint(); |
| 275 if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) { |
| 276 constraint = kApprox_SizeConstraint; |
| 277 } |
| 278 Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint
); |
| 279 |
| 280 return input->filterImage(proxy, src, ctx, result, offset); |
270 } | 281 } |
271 | 282 |
272 bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, | 283 bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, |
273 SkIRect* dst) const { | 284 SkIRect* dst) const { |
274 SkASSERT(dst); | 285 SkASSERT(dst); |
275 return this->onFilterBounds(src, ctm, dst); | 286 return this->onFilterBounds(src, ctm, dst); |
276 } | 287 } |
277 | 288 |
278 void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { | 289 void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |
279 if (0 == fInputCount) { | 290 if (0 == fInputCount) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 SkRect srcRect = SkRect::Make(bounds); | 351 SkRect srcRect = SkRect::Make(bounds); |
341 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 352 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
342 GrContext* context = srcTexture->getContext(); | 353 GrContext* context = srcTexture->getContext(); |
343 | 354 |
344 GrSurfaceDesc desc; | 355 GrSurfaceDesc desc; |
345 desc.fFlags = kRenderTarget_GrSurfaceFlag, | 356 desc.fFlags = kRenderTarget_GrSurfaceFlag, |
346 desc.fWidth = bounds.width(); | 357 desc.fWidth = bounds.width(); |
347 desc.fHeight = bounds.height(); | 358 desc.fHeight = bounds.height(); |
348 desc.fConfig = kRGBA_8888_GrPixelConfig; | 359 desc.fConfig = kRGBA_8888_GrPixelConfig; |
349 | 360 |
350 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 361 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc, |
| 362 GrTextureProvider::FromImageFilter(ctx.siz
eConstraint()))); |
351 if (!dst) { | 363 if (!dst) { |
352 return false; | 364 return false; |
353 } | 365 } |
354 | 366 |
355 // setup new clip | 367 // setup new clip |
356 GrClip clip(dstRect); | 368 GrClip clip(dstRect); |
357 | 369 |
358 GrFragmentProcessor* fp; | 370 GrFragmentProcessor* fp; |
359 offset->fX = bounds.left(); | 371 offset->fX = bounds.left(); |
360 offset->fY = bounds.top(); | 372 offset->fY = bounds.top(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 471 |
460 #if SK_SUPPORT_GPU | 472 #if SK_SUPPORT_GPU |
461 | 473 |
462 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { | 474 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { |
463 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 475 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
464 result->setInfo(info); | 476 result->setInfo(info); |
465 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); | 477 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
466 } | 478 } |
467 | 479 |
468 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy, | 480 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy, |
469 const SkBitmap& src, const Context& ctx, | 481 const SkBitmap& src, const Context& origCtx, |
470 SkBitmap* result, SkIPoint* offset) const { | 482 SkBitmap* result, SkIPoint* offset, |
| 483 bool relaxSizeConstraint) const { |
471 SkImageFilter* input = this->getInput(index); | 484 SkImageFilter* input = this->getInput(index); |
472 if (!input) { | 485 if (!input) { |
473 return true; | 486 return true; |
474 } | 487 } |
475 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | 488 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity |
476 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | 489 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was |
477 // called are restored before we return to the caller. | 490 // called are restored before we return to the caller. |
478 GrContext* context = src.getTexture()->getContext(); | 491 GrContext* context = src.getTexture()->getContext(); |
479 | 492 |
| 493 SizeConstraint constraint = origCtx.sizeConstraint(); |
| 494 if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) { |
| 495 constraint = kApprox_SizeConstraint; |
| 496 } |
| 497 Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint
); |
| 498 |
480 if (input->canFilterImageGPU()) { | 499 if (input->canFilterImageGPU()) { |
481 return input->filterImageGPU(proxy, src, ctx, result, offset); | 500 return input->filterImageGPU(proxy, src, ctx, result, offset); |
482 } else { | 501 } else { |
483 if (input->filterImage(proxy, src, ctx, result, offset)) { | 502 if (input->filterImage(proxy, src, ctx, result, offset)) { |
484 if (!result->getTexture()) { | 503 if (!result->getTexture()) { |
485 const SkImageInfo info = result->info(); | 504 const SkImageInfo info = result->info(); |
486 if (kUnknown_SkColorType == info.colorType()) { | 505 if (kUnknown_SkColorType == info.colorType()) { |
487 return false; | 506 return false; |
488 } | 507 } |
489 SkAutoTUnref<GrTexture> resultTex( | 508 SkAutoTUnref<GrTexture> resultTex( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 } | 632 } |
614 return dev; | 633 return dev; |
615 } | 634 } |
616 | 635 |
617 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 636 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
618 const SkImageFilter::Context& ctx, | 637 const SkImageFilter::Context& ctx, |
619 SkBitmap* result, SkIPoint* offset) { | 638 SkBitmap* result, SkIPoint* offset) { |
620 return fDevice->filterImage(filter, src, ctx, result, offset); | 639 return fDevice->filterImage(filter, src, ctx, result, offset); |
621 } | 640 } |
622 | 641 |
OLD | NEW |