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 "SkXfermodeImageFilter.h" | 8 #include "SkXfermodeImageFilter.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 #include "SkXfermode.h" | 14 #include "SkXfermode.h" |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #include "effects/GrSimpleTextureEffect.h" | 17 #include "effects/GrSimpleTextureEffect.h" |
18 #include "SkGr.h" | 18 #include "SkGr.h" |
19 #include "SkImageFilterUtils.h" | |
20 #endif | 19 #endif |
21 | 20 |
22 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
23 | 22 |
24 SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode, | 23 SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode, |
25 SkImageFilter* background, | 24 SkImageFilter* background, |
26 SkImageFilter* foreground, | 25 SkImageFilter* foreground, |
27 const CropRect* cropRect) | 26 const CropRect* cropRect) |
28 : INHERITED(background, foreground, cropRect), fMode(mode) { | 27 : INHERITED(background, foreground, cropRect), fMode(mode) { |
29 SkSafeRef(fMode); | 28 SkSafeRef(fMode); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return true; | 93 return true; |
95 } | 94 } |
96 | 95 |
97 #if SK_SUPPORT_GPU | 96 #if SK_SUPPORT_GPU |
98 | 97 |
99 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, | 98 bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy, |
100 const SkBitmap& src, | 99 const SkBitmap& src, |
101 const SkMatrix& ctm, | 100 const SkMatrix& ctm, |
102 SkBitmap* result, | 101 SkBitmap* result, |
103 SkIPoint* offset) const { | 102 SkIPoint* offset) const { |
104 SkBitmap background; | 103 SkBitmap background = src; |
105 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); | 104 SkIPoint backgroundOffset = SkIPoint::Make(0, 0); |
106 if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &ba
ckground, | 105 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &backgro
und, |
107 &backgroundOffset)) { | 106 &backgroundOffset)) { |
108 return false; | 107 return false; |
109 } | 108 } |
110 GrTexture* backgroundTex = background.getTexture(); | 109 GrTexture* backgroundTex = background.getTexture(); |
111 SkBitmap foreground; | 110 SkBitmap foreground = src; |
112 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); | 111 SkIPoint foregroundOffset = SkIPoint::Make(0, 0); |
113 if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, ctm, &fo
reground, | 112 if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctm, &foregro
und, |
114 &foregroundOffset)) { | 113 &foregroundOffset)) { |
115 return false; | 114 return false; |
116 } | 115 } |
117 GrTexture* foregroundTex = foreground.getTexture(); | 116 GrTexture* foregroundTex = foreground.getTexture(); |
118 GrContext* context = foregroundTex->getContext(); | 117 GrContext* context = foregroundTex->getContext(); |
119 | 118 |
120 GrEffectRef* xferEffect = NULL; | 119 GrEffectRef* xferEffect = NULL; |
121 | 120 |
122 GrTextureDesc desc; | 121 GrTextureDesc desc; |
123 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
124 desc.fWidth = src.width(); | 123 desc.fWidth = src.width(); |
(...skipping 28 matching lines...) Expand all Loading... |
153 backgroundPaint.addColorTextureEffect(backgroundTex, backgroundMatrix); | 152 backgroundPaint.addColorTextureEffect(backgroundTex, backgroundMatrix); |
154 context->drawRect(backgroundPaint, srcRect); | 153 context->drawRect(backgroundPaint, srcRect); |
155 | 154 |
156 GrPaint foregroundPaint; | 155 GrPaint foregroundPaint; |
157 foregroundPaint.setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblen
d(dm)); | 156 foregroundPaint.setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblen
d(dm)); |
158 foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix); | 157 foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix); |
159 context->drawRect(foregroundPaint, srcRect); | 158 context->drawRect(foregroundPaint, srcRect); |
160 } | 159 } |
161 offset->fX = backgroundOffset.fX; | 160 offset->fX = backgroundOffset.fX; |
162 offset->fY = backgroundOffset.fY; | 161 offset->fY = backgroundOffset.fY; |
163 return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), resul
t); | 162 WrapTexture(dst, src.width(), src.height(), result); |
| 163 return true; |
164 } | 164 } |
165 | 165 |
166 #endif | 166 #endif |
OLD | NEW |