OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 : INHERITED(&input, 1, cropRect) | 88 : INHERITED(&input, 1, cropRect) |
89 , fRegion(region) | 89 , fRegion(region) |
90 , fInnerThreshold(innerThreshold) | 90 , fInnerThreshold(innerThreshold) |
91 , fOuterThreshold(outerThreshold) { | 91 , fOuterThreshold(outerThreshold) { |
92 } | 92 } |
93 | 93 |
94 #if SK_SUPPORT_GPU | 94 #if SK_SUPPORT_GPU |
95 sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex
t, | 95 sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex
t, |
96 const SkMatrix& i
nMatrix, | 96 const SkMatrix& i
nMatrix, |
97 const SkIRect& bo
unds) const { | 97 const SkIRect& bo
unds) const { |
98 GrSurfaceDesc maskDesc; | 98 GrPixelConfig config; |
99 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { | 99 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { |
100 maskDesc.fConfig = kAlpha_8_GrPixelConfig; | 100 config = kAlpha_8_GrPixelConfig; |
101 } else { | 101 } else { |
102 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; | 102 config = kRGBA_8888_GrPixelConfig; |
103 } | |
104 maskDesc.fFlags = kRenderTarget_GrSurfaceFlag; | |
105 // Add one pixel of border to ensure that clamp mode will be all zeros | |
106 // the outside. | |
107 maskDesc.fWidth = bounds.width(); | |
108 maskDesc.fHeight = bounds.height(); | |
109 sk_sp<GrTexture> maskTexture(context->textureProvider()->createApproxTexture
(maskDesc)); | |
110 if (!maskTexture) { | |
111 return nullptr; | |
112 } | 103 } |
113 | 104 |
114 sk_sp<GrDrawContext> drawContext( | 105 sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_B
ackingFit, |
115 context->drawContext(sk_ref_sp(maskTexture->asRe
nderTarget()))); | 106 bounds.width(), bou
nds.height(), |
| 107 config)); |
116 if (!drawContext) { | 108 if (!drawContext) { |
117 return nullptr; | 109 return nullptr; |
118 } | 110 } |
119 | 111 |
120 GrPaint grPaint; | 112 GrPaint grPaint; |
121 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 113 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
122 SkRegion::Iterator iter(fRegion); | 114 SkRegion::Iterator iter(fRegion); |
123 drawContext->clear(nullptr, 0x0, true); | 115 drawContext->clear(nullptr, 0x0, true); |
124 | 116 |
125 GrClip clip(SkRect::Make(SkIRect::MakeWH(bounds.width(), bounds.height()))); | 117 GrClip clip(SkRect::Make(SkIRect::MakeWH(bounds.width(), bounds.height()))); |
126 while (!iter.done()) { | 118 while (!iter.done()) { |
127 SkRect rect = SkRect::Make(iter.rect()); | 119 SkRect rect = SkRect::Make(iter.rect()); |
128 drawContext->drawRect(clip, grPaint, inMatrix, rect); | 120 drawContext->drawRect(clip, grPaint, inMatrix, rect); |
129 iter.next(); | 121 iter.next(); |
130 } | 122 } |
131 | 123 |
132 return maskTexture; | 124 return drawContext->asTexture(); |
133 } | 125 } |
134 #endif | 126 #endif |
135 | 127 |
136 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { | 128 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
137 this->INHERITED::flatten(buffer); | 129 this->INHERITED::flatten(buffer); |
138 buffer.writeScalar(fInnerThreshold); | 130 buffer.writeScalar(fInnerThreshold); |
139 buffer.writeScalar(fOuterThreshold); | 131 buffer.writeScalar(fOuterThreshold); |
140 buffer.writeRegion(fRegion); | 132 buffer.writeRegion(fRegion); |
141 } | 133 } |
142 | 134 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 dst); | 259 dst); |
268 } | 260 } |
269 | 261 |
270 #ifndef SK_IGNORE_TO_STRING | 262 #ifndef SK_IGNORE_TO_STRING |
271 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 263 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
272 str->appendf("SkAlphaThresholdImageFilter: ("); | 264 str->appendf("SkAlphaThresholdImageFilter: ("); |
273 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 265 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
274 str->append(")"); | 266 str->append(")"); |
275 } | 267 } |
276 #endif | 268 #endif |
OLD | NEW |