| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 SkRect srcRect = SkRect::Make(bounds); | 248 SkRect srcRect = SkRect::Make(bounds); |
| 249 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 249 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 250 GrContext* context = srcTexture->getContext(); | 250 GrContext* context = srcTexture->getContext(); |
| 251 | 251 |
| 252 GrTextureDesc desc; | 252 GrTextureDesc desc; |
| 253 desc.fFlags = kRenderTarget_GrTextureFlagBit, | 253 desc.fFlags = kRenderTarget_GrTextureFlagBit, |
| 254 desc.fWidth = bounds.width(); | 254 desc.fWidth = bounds.width(); |
| 255 desc.fHeight = bounds.height(); | 255 desc.fHeight = bounds.height(); |
| 256 desc.fConfig = kRGBA_8888_GrPixelConfig; | 256 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 257 | 257 |
| 258 GrAutoScratchTexture dst(context, desc); | 258 SkAutoTUnref<GrTexture> dst( |
| 259 if (NULL == dst.texture()) { | 259 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
| 260 if (!dst) { |
| 260 return false; | 261 return false; |
| 261 } | 262 } |
| 262 GrContext::AutoMatrix am; | 263 GrContext::AutoMatrix am; |
| 263 am.setIdentity(context); | 264 am.setIdentity(context); |
| 264 GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget()); | 265 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); |
| 265 GrContext::AutoClip acs(context, dstRect); | 266 GrContext::AutoClip acs(context, dstRect); |
| 266 GrFragmentProcessor* fp; | 267 GrFragmentProcessor* fp; |
| 267 offset->fX = bounds.left(); | 268 offset->fX = bounds.left(); |
| 268 offset->fY = bounds.top(); | 269 offset->fY = bounds.top(); |
| 269 bounds.offset(-srcOffset); | 270 bounds.offset(-srcOffset); |
| 270 SkMatrix matrix(ctx.ctm()); | 271 SkMatrix matrix(ctx.ctm()); |
| 271 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 272 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
| 272 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { | 273 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { |
| 273 SkASSERT(fp); | 274 SkASSERT(fp); |
| 274 GrPaint paint; | 275 GrPaint paint; |
| 275 paint.addColorProcessor(fp)->unref(); | 276 paint.addColorProcessor(fp)->unref(); |
| 276 context->drawRectToRect(paint, dstRect, srcRect); | 277 context->drawRectToRect(paint, dstRect, srcRect); |
| 277 | 278 |
| 278 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | 279 WrapTexture(dst, bounds.width(), bounds.height(), result); |
| 279 WrapTexture(resultTex, bounds.width(), bounds.height(), result); | |
| 280 return true; | 280 return true; |
| 281 } | 281 } |
| 282 #endif | 282 #endif |
| 283 return false; | 283 return false; |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, | 286 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, |
| 287 const SkIPoint& srcOffset, SkIRect* bounds) co
nst { | 287 const SkIPoint& srcOffset, SkIRect* bounds) co
nst { |
| 288 SkIRect srcBounds; | 288 SkIRect srcBounds; |
| 289 src.getBounds(&srcBounds); | 289 src.getBounds(&srcBounds); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { | 494 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { |
| 495 return SkNEW_ARGS(CacheImpl, (maxBytes)); | 495 return SkNEW_ARGS(CacheImpl, (maxBytes)); |
| 496 } | 496 } |
| 497 | 497 |
| 498 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); | 498 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); |
| 499 | 499 |
| 500 SkImageFilter::Cache* SkImageFilter::Cache::Get() { | 500 SkImageFilter::Cache* SkImageFilter::Cache::Get() { |
| 501 return cache.get(); | 501 return cache.get(); |
| 502 } | 502 } |
| OLD | NEW |