Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: src/effects/SkAlphaThresholdFilter.cpp

Issue 1929833004: Revert of Refactor drawContext/RenderTarget creation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 GrPixelConfig config; 98 GrSurfaceDesc maskDesc;
99 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { 99 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
100 config = kAlpha_8_GrPixelConfig; 100 maskDesc.fConfig = kAlpha_8_GrPixelConfig;
101 } else { 101 } else {
102 config = kRGBA_8888_GrPixelConfig; 102 maskDesc.fConfig = 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;
103 } 112 }
104 113
105 sk_sp<GrDrawContext> drawContext(context->newDrawContext(GrContext::kLoose_B ackingFit, 114 sk_sp<GrDrawContext> drawContext(
106 bounds.width(), bou nds.height(), 115 context->drawContext(sk_ref_sp(maskTexture->asRe nderTarget())));
107 config));
108 if (!drawContext) { 116 if (!drawContext) {
109 return nullptr; 117 return nullptr;
110 } 118 }
111 119
112 GrPaint grPaint; 120 GrPaint grPaint;
113 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 121 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
114 SkRegion::Iterator iter(fRegion); 122 SkRegion::Iterator iter(fRegion);
115 drawContext->clear(nullptr, 0x0, true); 123 drawContext->clear(nullptr, 0x0, true);
116 124
117 GrClip clip(SkRect::Make(SkIRect::MakeWH(bounds.width(), bounds.height()))); 125 GrClip clip(SkRect::Make(SkIRect::MakeWH(bounds.width(), bounds.height())));
118 while (!iter.done()) { 126 while (!iter.done()) {
119 SkRect rect = SkRect::Make(iter.rect()); 127 SkRect rect = SkRect::Make(iter.rect());
120 drawContext->drawRect(clip, grPaint, inMatrix, rect); 128 drawContext->drawRect(clip, grPaint, inMatrix, rect);
121 iter.next(); 129 iter.next();
122 } 130 }
123 131
124 return drawContext->asTexture(); 132 return maskTexture;
125 } 133 }
126 #endif 134 #endif
127 135
128 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 136 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
129 this->INHERITED::flatten(buffer); 137 this->INHERITED::flatten(buffer);
130 buffer.writeScalar(fInnerThreshold); 138 buffer.writeScalar(fInnerThreshold);
131 buffer.writeScalar(fOuterThreshold); 139 buffer.writeScalar(fOuterThreshold);
132 buffer.writeRegion(fRegion); 140 buffer.writeRegion(fRegion);
133 } 141 }
134 142
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 dst); 267 dst);
260 } 268 }
261 269
262 #ifndef SK_IGNORE_TO_STRING 270 #ifndef SK_IGNORE_TO_STRING
263 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 271 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
264 str->appendf("SkAlphaThresholdImageFilter: ("); 272 str->appendf("SkAlphaThresholdImageFilter: (");
265 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 273 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
266 str->append(")"); 274 str->append(")");
267 } 275 }
268 #endif 276 #endif
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698