| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 delete[] fInputs; | 197 delete[] fInputs; |
| 198 } | 198 } |
| 199 | 199 |
| 200 SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) | 200 SkImageFilter::SkImageFilter(int inputCount, SkReadBuffer& buffer) |
| 201 : fUsesSrcInput(false) | 201 : fUsesSrcInput(false) |
| 202 , fUniqueID(next_image_filter_unique_id()) { | 202 , fUniqueID(next_image_filter_unique_id()) { |
| 203 Common common; | 203 Common common; |
| 204 if (common.unflatten(buffer, inputCount)) { | 204 if (common.unflatten(buffer, inputCount)) { |
| 205 fCropRect = common.cropRect(); | 205 fCropRect = common.cropRect(); |
| 206 fInputCount = common.inputCount(); | 206 fInputCount = common.inputCount(); |
| 207 fInputs = SkNEW_ARRAY(SkImageFilter*, fInputCount); | 207 fInputs = new SkImageFilter* [fInputCount]; |
| 208 common.detachInputs(fInputs); | 208 common.detachInputs(fInputs); |
| 209 for (int i = 0; i < fInputCount; ++i) { | 209 for (int i = 0; i < fInputCount; ++i) { |
| 210 if (NULL == fInputs[i] || fInputs[i]->usesSrcInput()) { | 210 if (NULL == fInputs[i] || fInputs[i]->usesSrcInput()) { |
| 211 fUsesSrcInput = true; | 211 fUsesSrcInput = true; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } else { | 214 } else { |
| 215 fInputCount = 0; | 215 fInputCount = 0; |
| 216 fInputs = NULL; | 216 fInputs = NULL; |
| 217 } | 217 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 SkFilterQuality filterQuality, | 437 SkFilterQuality filterQuality, |
| 438 SkImageFilter* input) { | 438 SkImageFilter* input) { |
| 439 return SkMatrixImageFilter::Create(matrix, filterQuality, input); | 439 return SkMatrixImageFilter::Create(matrix, filterQuality, input); |
| 440 } | 440 } |
| 441 | 441 |
| 442 #if SK_SUPPORT_GPU | 442 #if SK_SUPPORT_GPU |
| 443 | 443 |
| 444 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { | 444 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { |
| 445 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 445 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 446 result->setInfo(info); | 446 result->setInfo(info); |
| 447 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 447 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, | 450 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, |
| 451 const SkBitmap& src, const Context& ctx, | 451 const SkBitmap& src, const Context& ctx, |
| 452 SkBitmap* result, SkIPoint* offset) const
{ | 452 SkBitmap* result, SkIPoint* offset) const
{ |
| 453 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | 453 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity |
| 454 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | 454 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was |
| 455 // called are restored before we return to the caller. | 455 // called are restored before we return to the caller. |
| 456 GrContext* context = src.getTexture()->getContext(); | 456 GrContext* context = src.getTexture()->getContext(); |
| 457 | 457 |
| 458 if (this->canFilterImageGPU()) { | 458 if (this->canFilterImageGPU()) { |
| 459 return this->filterImageGPU(proxy, src, ctx, result, offset); | 459 return this->filterImageGPU(proxy, src, ctx, result, offset); |
| 460 } else { | 460 } else { |
| 461 if (this->filterImage(proxy, src, ctx, result, offset)) { | 461 if (this->filterImage(proxy, src, ctx, result, offset)) { |
| 462 if (!result->getTexture()) { | 462 if (!result->getTexture()) { |
| 463 const SkImageInfo info = result->info(); | 463 const SkImageInfo info = result->info(); |
| 464 if (kUnknown_SkColorType == info.colorType()) { | 464 if (kUnknown_SkColorType == info.colorType()) { |
| 465 return false; | 465 return false; |
| 466 } | 466 } |
| 467 SkAutoTUnref<GrTexture> resultTex(GrRefCachedBitmapTexture(conte
xt, *result, NULL)); | 467 SkAutoTUnref<GrTexture> resultTex(GrRefCachedBitmapTexture(conte
xt, *result, NULL)); |
| 468 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, resultTex)))
->unref(); | 468 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); |
| 469 } | 469 } |
| 470 return true; | 470 return true; |
| 471 } else { | 471 } else { |
| 472 return false; | 472 return false; |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 #endif | 476 #endif |
| 477 | 477 |
| 478 namespace { | 478 namespace { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 mutable SkMutex fMutex; | 560 mutable SkMutex fMutex; |
| 561 }; | 561 }; |
| 562 | 562 |
| 563 SkImageFilter::Cache* CreateCache() { | 563 SkImageFilter::Cache* CreateCache() { |
| 564 return SkImageFilter::Cache::Create(kDefaultCacheSize); | 564 return SkImageFilter::Cache::Create(kDefaultCacheSize); |
| 565 } | 565 } |
| 566 | 566 |
| 567 } // namespace | 567 } // namespace |
| 568 | 568 |
| 569 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { | 569 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { |
| 570 return SkNEW_ARGS(CacheImpl, (maxBytes)); | 570 return new CacheImpl(maxBytes); |
| 571 } | 571 } |
| 572 | 572 |
| 573 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); | 573 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); |
| 574 | 574 |
| 575 SkImageFilter::Cache* SkImageFilter::Cache::Get() { | 575 SkImageFilter::Cache* SkImageFilter::Cache::Get() { |
| 576 return cache.get(); | 576 return cache.get(); |
| 577 } | 577 } |
| 578 | 578 |
| 579 void SkImageFilter::PurgeCache() { | 579 void SkImageFilter::PurgeCache() { |
| 580 cache.get()->purge(); | 580 cache.get()->purge(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 595 } | 595 } |
| 596 return dev; | 596 return dev; |
| 597 } | 597 } |
| 598 | 598 |
| 599 bool SkImageFilter::Proxy::filterImage(const SkImageFilter* filter, const SkBitm
ap& src, | 599 bool SkImageFilter::Proxy::filterImage(const SkImageFilter* filter, const SkBitm
ap& src, |
| 600 const SkImageFilter::Context& ctx, | 600 const SkImageFilter::Context& ctx, |
| 601 SkBitmap* result, SkIPoint* offset) { | 601 SkBitmap* result, SkIPoint* offset) { |
| 602 return fDevice->filterImage(filter, src, ctx, result, offset); | 602 return fDevice->filterImage(filter, src, ctx, result, offset); |
| 603 } | 603 } |
| 604 | 604 |
| OLD | NEW |