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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 259 |
260 // setup new clip | 260 GrContext::AutoClip acs(context, dstRect); |
261 GrClip clip(dstRect); | |
262 | |
263 GrFragmentProcessor* fp; | 261 GrFragmentProcessor* fp; |
264 offset->fX = bounds.left(); | 262 offset->fX = bounds.left(); |
265 offset->fY = bounds.top(); | 263 offset->fY = bounds.top(); |
266 bounds.offset(-srcOffset); | 264 bounds.offset(-srcOffset); |
267 SkMatrix matrix(ctx.ctm()); | 265 SkMatrix matrix(ctx.ctm()); |
268 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); | 266 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.to
p())); |
269 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { | 267 if (this->asFragmentProcessor(&fp, srcTexture, matrix, bounds)) { |
270 SkASSERT(fp); | 268 SkASSERT(fp); |
271 GrPaint paint; | 269 GrPaint paint; |
272 paint.addColorProcessor(fp)->unref(); | 270 paint.addColorProcessor(fp)->unref(); |
273 context->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri
x::I(), dstRect, | 271 context->drawNonAARectToRect(dst->asRenderTarget(), paint, SkMatrix::I()
, dstRect, srcRect); |
274 srcRect); | |
275 | 272 |
276 WrapTexture(dst, bounds.width(), bounds.height(), result); | 273 WrapTexture(dst, bounds.width(), bounds.height(), result); |
277 return true; | 274 return true; |
278 } | 275 } |
279 #endif | 276 #endif |
280 return false; | 277 return false; |
281 } | 278 } |
282 | 279 |
283 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, | 280 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, |
284 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... |
378 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 375 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
379 } | 376 } |
380 | 377 |
381 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, | 378 bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, |
382 const SkBitmap& src, const Context& ctx, | 379 const SkBitmap& src, const Context& ctx, |
383 SkBitmap* result, SkIPoint* offset) const
{ | 380 SkBitmap* result, SkIPoint* offset) const
{ |
384 // 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 |
385 // 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 |
386 // called are restored before we return to the caller. | 383 // called are restored before we return to the caller. |
387 GrContext* context = src.getTexture()->getContext(); | 384 GrContext* context = src.getTexture()->getContext(); |
388 | 385 GrContext::AutoWideOpenIdentityDraw awoid(context); |
389 if (this->canFilterImageGPU()) { | 386 if (this->canFilterImageGPU()) { |
390 return this->filterImageGPU(proxy, src, ctx, result, offset); | 387 return this->filterImageGPU(proxy, src, ctx, result, offset); |
391 } else { | 388 } else { |
392 if (this->filterImage(proxy, src, ctx, result, offset)) { | 389 if (this->filterImage(proxy, src, ctx, result, offset)) { |
393 if (!result->getTexture()) { | 390 if (!result->getTexture()) { |
394 const SkImageInfo info = result->info(); | 391 const SkImageInfo info = result->info(); |
395 if (kUnknown_SkColorType == info.colorType()) { | 392 if (kUnknown_SkColorType == info.colorType()) { |
396 return false; | 393 return false; |
397 } | 394 } |
398 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... |
489 | 486 |
490 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { | 487 SkImageFilter::Cache* SkImageFilter::Cache::Create(size_t maxBytes) { |
491 return SkNEW_ARGS(CacheImpl, (maxBytes)); | 488 return SkNEW_ARGS(CacheImpl, (maxBytes)); |
492 } | 489 } |
493 | 490 |
494 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); | 491 SK_DECLARE_STATIC_LAZY_PTR(SkImageFilter::Cache, cache, CreateCache); |
495 | 492 |
496 SkImageFilter::Cache* SkImageFilter::Cache::Get() { | 493 SkImageFilter::Cache* SkImageFilter::Cache::Get() { |
497 return cache.get(); | 494 return cache.get(); |
498 } | 495 } |
OLD | NEW |