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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 desc.fFlags = kRenderTarget_GrSurfaceFlag, | 249 desc.fFlags = kRenderTarget_GrSurfaceFlag, |
250 desc.fWidth = bounds.width(); | 250 desc.fWidth = bounds.width(); |
251 desc.fHeight = bounds.height(); | 251 desc.fHeight = bounds.height(); |
252 desc.fConfig = kRGBA_8888_GrPixelConfig; | 252 desc.fConfig = kRGBA_8888_GrPixelConfig; |
253 | 253 |
254 SkAutoTUnref<GrTexture> dst( | 254 SkAutoTUnref<GrTexture> dst( |
255 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | 255 context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
256 if (!dst) { | 256 if (!dst) { |
257 return false; | 257 return false; |
258 } | 258 } |
259 GrContext::AutoRenderTarget art(context, dst->asRenderTarget()); | 259 |
260 GrContext::AutoClip acs(context, dstRect); | 260 GrContext::AutoClip acs(context, dstRect); |
261 GrFragmentProcessor* fp; | 261 GrFragmentProcessor* fp; |
262 offset->fX = bounds.left(); | 262 offset->fX = bounds.left(); |
263 offset->fY = bounds.top(); | 263 offset->fY = bounds.top(); |
264 bounds.offset(-srcOffset); | 264 bounds.offset(-srcOffset); |
265 SkMatrix matrix(ctx.ctm()); | 265 SkMatrix matrix(ctx.ctm()); |
266 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 266 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
267 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { | 267 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { |
268 SkASSERT(fp); | 268 SkASSERT(fp); |
269 GrPaint paint; | 269 GrPaint paint; |
270 paint.addColorProcessor(fp)->unref(); | 270 paint.addColorProcessor(fp)->unref(); |
271 context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); | 271 context->drawNonAARectToRect(dst->asRenderTarget(), paint, SkMatrix::I()
, dstRect, srcRect); |
272 | 272 |
273 WrapTexture(dst, bounds.width(), bounds.height(), result); | 273 WrapTexture(dst, bounds.width(), bounds.height(), result); |
274 return true; | 274 return true; |
275 } | 275 } |
276 #endif | 276 #endif |
277 return false; | 277 return false; |
278 } | 278 } |
279 | 279 |
280 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, | 280 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, |
281 const SkIPoint& srcOffset, SkIRect* bounds) co
nst { | 281 const SkIPoint& srcOffset, SkIRect* bounds) co
nst { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 375 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
376 } | 376 } |
377 | 377 |
378 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, | 378 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, |
379 const SkBitmap& src, const Context& ctx, | 379 const SkBitmap& src, const Context& ctx, |
380 SkBitmap* result, SkIPoint* offset) const
{ | 380 SkBitmap* result, SkIPoint* offset) const
{ |
381 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | 381 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity |
382 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | 382 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was |
383 // called are restored before we return to the caller. | 383 // called are restored before we return to the caller. |
384 GrContext* context = src.getTexture()->getContext(); | 384 GrContext* context = src.getTexture()->getContext(); |
385 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); | 385 GrContext::AutoWideOpenIdentityDraw awoid(context); |
386 if (this->canFilterImageGPU()) { | 386 if (this->canFilterImageGPU()) { |
387 return this->filterImageGPU(proxy, src, ctx, result, offset); | 387 return this->filterImageGPU(proxy, src, ctx, result, offset); |
388 } else { | 388 } else { |
389 if (this->filterImage(proxy, src, ctx, result, offset)) { | 389 if (this->filterImage(proxy, src, ctx, result, offset)) { |
390 if (!result->getTexture()) { | 390 if (!result->getTexture()) { |
391 const SkImageInfo info = result->info(); | 391 const SkImageInfo info = result->info(); |
392 if (kUnknown_SkColorType == info.colorType()) { | 392 if (kUnknown_SkColorType == info.colorType()) { |
393 return false; | 393 return false; |
394 } | 394 } |
395 SkAutoTUnref<GrTexture> resultTex(GrRefCachedBitmapTexture(conte
xt, *result, NULL)); | 395 SkAutoTUnref<GrTexture> resultTex(GrRefCachedBitmapTexture(conte
xt, *result, NULL)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 486 |
487 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { | 487 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { |
488 return SkNEW_ARGS(CacheImpl, (maxBytes)); | 488 return SkNEW_ARGS(CacheImpl, (maxBytes)); |
489 } | 489 } |
490 | 490 |
491 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); | 491 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); |
492 | 492 |
493 SkImageFilter::Cache* SkImageFilter::Cache::Get() { | 493 SkImageFilter::Cache* SkImageFilter::Cache::Get() { |
494 return cache.get(); | 494 return cache.get(); |
495 } | 495 } |
OLD | NEW |