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