| OLD | NEW |
| (Empty) |
| 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 | |
| 8 #include "SkMatrix.h" | |
| 9 | |
| 10 #if SK_SUPPORT_GPU | |
| 11 #include "GrTexture.h" | |
| 12 #include "SkImageFilterUtils.h" | |
| 13 #include "SkBitmap.h" | |
| 14 #include "SkGrPixelRef.h" | |
| 15 #include "SkGr.h" | |
| 16 | |
| 17 bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height,
SkBitmap* result) { | |
| 18 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | |
| 19 result->setConfig(info); | |
| 20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | |
| 21 return true; | |
| 22 } | |
| 23 | |
| 24 bool SkImageFilterUtils::GetInputResultGPU(const SkImageFilter* filter, SkImageF
ilter::Proxy* proxy, | |
| 25 const SkBitmap& src, const SkMatrix&
ctm, | |
| 26 SkBitmap* result, SkIPoint* offset) { | |
| 27 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | |
| 28 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | |
| 29 // called are restored before we return to the caller. | |
| 30 GrContext* context = src.getTexture()->getContext(); | |
| 31 GrContext::AutoWideOpenIdentityDraw awoid(context, NULL); | |
| 32 if (!filter) { | |
| 33 offset->fX = offset->fY = 0; | |
| 34 *result = src; | |
| 35 return true; | |
| 36 } else if (filter->canFilterImageGPU()) { | |
| 37 return filter->filterImageGPU(proxy, src, ctm, result, offset); | |
| 38 } else { | |
| 39 if (filter->filterImage(proxy, src, ctm, result, offset)) { | |
| 40 if (!result->getTexture()) { | |
| 41 SkImageInfo info; | |
| 42 if (!result->asImageInfo(&info)) { | |
| 43 return false; | |
| 44 } | |
| 45 GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context,
*result, NULL); | |
| 46 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); | |
| 47 GrUnlockAndUnrefCachedBitmapTexture(resultTex); | |
| 48 } | |
| 49 return true; | |
| 50 } else { | |
| 51 return false; | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 #endif | |
| OLD | NEW |