senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
robertphillips@google.com | c3ecf65 | 2013-01-31 02:33:09 +0000 | [diff] [blame] | 8 | #include "SkMatrix.h" |
| 9 | |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 10 | #if SK_SUPPORT_GPU |
| 11 | #include "GrTexture.h" |
| 12 | #include "SkImageFilterUtils.h" |
| 13 | #include "SkBitmap.h" |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 14 | #include "SkGrPixelRef.h" |
| 15 | #include "SkGr.h" |
| 16 | |
| 17 | bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) { |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 18 | result->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 19 | result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); |
| 20 | return true; |
| 21 | } |
| 22 | |
commit-bot@chromium.org | 7b32070 | 2013-07-10 21:22:18 +0000 | [diff] [blame] | 23 | bool SkImageFilterUtils::GetInputResultGPU(SkImageFilter* filter, SkImageFilter::Proxy* proxy, |
commit-bot@chromium.org | 1aa54bf | 2013-08-05 16:53:50 +0000 | [diff] [blame] | 24 | const SkBitmap& src, const SkMatrix& ctm, |
| 25 | SkBitmap* result, SkIPoint* offset) { |
commit-bot@chromium.org | bbfe454 | 2013-10-24 01:46:11 +0000 | [diff] [blame^] | 26 | // Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity |
| 27 | // matrix with no clip and that the matrix, clip, and render target set before this function was |
| 28 | // called are restored before we return to the caller. |
| 29 | GrContext* context = src.getTexture()->getContext(); |
| 30 | GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 31 | if (!filter) { |
| 32 | *result = src; |
| 33 | return true; |
| 34 | } else if (filter->canFilterImageGPU()) { |
commit-bot@chromium.org | 1aa54bf | 2013-08-05 16:53:50 +0000 | [diff] [blame] | 35 | return filter->filterImageGPU(proxy, src, ctm, result, offset); |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 36 | } else { |
commit-bot@chromium.org | 1aa54bf | 2013-08-05 16:53:50 +0000 | [diff] [blame] | 37 | if (filter->filterImage(proxy, src, ctm, result, offset)) { |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 38 | if (!result->getTexture()) { |
commit-bot@chromium.org | bbfe454 | 2013-10-24 01:46:11 +0000 | [diff] [blame^] | 39 | GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL); |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 40 | result->setPixelRef(new SkGrPixelRef(resultTex))->unref(); |
| 41 | GrUnlockAndUnrefCachedBitmapTexture(resultTex); |
| 42 | } |
| 43 | return true; |
| 44 | } else { |
| 45 | return false; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | #endif |