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

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

Issue 2514543002: Defer more renderTargetContexts in the GPU image filter paths - take 2 (Closed)
Patch Set: Add more bullet proofing Created 4 years, 1 month 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/SkBlurMaskFilter.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"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkSpecialImage.h" 12 #include "SkSpecialImage.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkRegion.h" 14 #include "SkRegion.h"
15 15
16 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
17 #include "GrAlphaThresholdFragmentProcessor.h" 17 #include "GrAlphaThresholdFragmentProcessor.h"
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "GrFixedClip.h"
19 #include "GrRenderTargetContext.h" 20 #include "GrRenderTargetContext.h"
20 #include "GrFixedClip.h" 21 #include "GrTextureProxy.h"
21 #endif 22 #endif
22 23
23 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { 24 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter {
24 public: 25 public:
25 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, 26 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
26 SkScalar outerThreshold, sk_sp<SkImageFilter> inp ut, 27 SkScalar outerThreshold, sk_sp<SkImageFilter> inp ut,
27 const CropRect* cropRect = nullptr); 28 const CropRect* cropRect = nullptr);
28 29
29 SK_TO_STRING_OVERRIDE() 30 SK_TO_STRING_OVERRIDE()
30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl) 31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl)
31 friend void SkAlphaThresholdFilter::InitializeFlattenables(); 32 friend void SkAlphaThresholdFilter::InitializeFlattenables();
32 33
33 protected: 34 protected:
34 void flatten(SkWriteBuffer&) const override; 35 void flatten(SkWriteBuffer&) const override;
35 36
36 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, 37 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
37 SkIPoint* offset) const override; 38 SkIPoint* offset) const override;
38 39
39 #if SK_SUPPORT_GPU 40 #if SK_SUPPORT_GPU
40 sk_sp<GrTexture> createMaskTexture(GrContext*, const SkMatrix&, const SkIRec t& bounds) const; 41 sk_sp<GrTextureProxy> createMaskTexture(GrContext*,
42 const SkMatrix&,
43 const SkIRect& bounds) const;
41 #endif 44 #endif
42 45
43 private: 46 private:
44 SkRegion fRegion; 47 SkRegion fRegion;
45 SkScalar fInnerThreshold; 48 SkScalar fInnerThreshold;
46 SkScalar fOuterThreshold; 49 SkScalar fOuterThreshold;
47 typedef SkImageFilter INHERITED; 50 typedef SkImageFilter INHERITED;
48 }; 51 };
49 52
50 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter) 53 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkAlphaThresholdFilter)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 SkScalar outerThreshold, 89 SkScalar outerThreshold,
87 sk_sp<SkImageFilter> inpu t, 90 sk_sp<SkImageFilter> inpu t,
88 const CropRect* cropRect) 91 const CropRect* cropRect)
89 : INHERITED(&input, 1, cropRect) 92 : INHERITED(&input, 1, cropRect)
90 , fRegion(region) 93 , fRegion(region)
91 , fInnerThreshold(innerThreshold) 94 , fInnerThreshold(innerThreshold)
92 , fOuterThreshold(outerThreshold) { 95 , fOuterThreshold(outerThreshold) {
93 } 96 }
94 97
95 #if SK_SUPPORT_GPU 98 #if SK_SUPPORT_GPU
96 sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex t, 99 sk_sp<GrTextureProxy> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* c ontext,
97 const SkMatrix& i nMatrix, 100 const SkMatr ix& inMatrix,
98 const SkIRect& bo unds) const { 101 const SkIRec t& bounds) const {
99 102
100 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetCo ntextWithFallback( 103 sk_sp<GrRenderTargetContext> rtContext(context->makeDeferredRenderTargetCont extWithFallback(
101 SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixel Config, nullptr)); 104 SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixel Config, nullptr));
102 if (!renderTargetContext) { 105 if (!rtContext) {
103 return nullptr; 106 return nullptr;
104 } 107 }
105 108
106 GrPaint grPaint; 109 GrPaint grPaint;
107 grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); 110 grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc);
108 SkRegion::Iterator iter(fRegion); 111 SkRegion::Iterator iter(fRegion);
109 renderTargetContext->clear(nullptr, 0x0, true); 112 rtContext->clear(nullptr, 0x0, true);
110 113
111 GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height())); 114 GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height()));
112 while (!iter.done()) { 115 while (!iter.done()) {
113 SkRect rect = SkRect::Make(iter.rect()); 116 SkRect rect = SkRect::Make(iter.rect());
114 renderTargetContext->drawRect(clip, grPaint, inMatrix, rect); 117 rtContext->drawRect(clip, grPaint, inMatrix, rect);
115 iter.next(); 118 iter.next();
116 } 119 }
117 120
118 return renderTargetContext->asTexture(); 121 return sk_ref_sp(rtContext->asDeferredTexture());
119 } 122 }
120 #endif 123 #endif
121 124
122 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 125 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
123 this->INHERITED::flatten(buffer); 126 this->INHERITED::flatten(buffer);
124 buffer.writeScalar(fInnerThreshold); 127 buffer.writeScalar(fInnerThreshold);
125 buffer.writeScalar(fOuterThreshold); 128 buffer.writeScalar(fOuterThreshold);
126 buffer.writeRegion(fRegion); 129 buffer.writeRegion(fRegion);
127 } 130 }
128 131
(...skipping 22 matching lines...) Expand all
151 SkASSERT(inputTexture); 154 SkASSERT(inputTexture);
152 155
153 offset->fX = bounds.left(); 156 offset->fX = bounds.left();
154 offset->fY = bounds.top(); 157 offset->fY = bounds.top();
155 158
156 bounds.offset(-inputOffset); 159 bounds.offset(-inputOffset);
157 160
158 SkMatrix matrix(ctx.ctm()); 161 SkMatrix matrix(ctx.ctm());
159 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bound s.top())); 162 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bound s.top()));
160 163
161 sk_sp<GrTexture> maskTexture(this->createMaskTexture(context, matrix, bo unds)); 164 sk_sp<GrTextureProxy> maskProxy(this->createMaskTexture(context, matrix, bounds));
162 if (!maskTexture) { 165 if (!maskProxy) {
163 return nullptr; 166 return nullptr;
164 } 167 }
165 168
166 const OutputProperties& outProps = ctx.outputProperties(); 169 const OutputProperties& outProps = ctx.outputProperties();
167 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input ->getColorSpace(), 170 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input ->getColorSpace(),
168 outPr ops.colorSpace()); 171 outPr ops.colorSpace());
172
173 GrTexture* maskTex = maskProxy->instantiate(context->textureProvider());
174 if (!maskTex) {
175 return nullptr;
176 }
169 sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make( 177 sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make(
170 inputTe xture.get(), 178 inputTexture.get(),
171 std::mo ve(colorSpaceXform), 179 std::move(colorSpaceXform),
172 maskTex ture.get(), 180 maskTex,
173 fInnerT hreshold, 181 fInnerThreshold,
174 fOuterT hreshold, 182 fOuterThreshold,
175 bounds) ); 183 bounds));
176 if (!fp) { 184 if (!fp) {
177 return nullptr; 185 return nullptr;
178 } 186 }
179 187
180 return DrawWithFP(context, std::move(fp), bounds, outProps); 188 return DrawWithFP(context, std::move(fp), bounds, outProps);
181 } 189 }
182 #endif 190 #endif
183 191
184 SkBitmap inputBM; 192 SkBitmap inputBM;
185 193
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 dst); 264 dst);
257 } 265 }
258 266
259 #ifndef SK_IGNORE_TO_STRING 267 #ifndef SK_IGNORE_TO_STRING
260 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 268 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
261 str->appendf("SkAlphaThresholdImageFilter: ("); 269 str->appendf("SkAlphaThresholdImageFilter: (");
262 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 270 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
263 str->append(")"); 271 str->append(")");
264 } 272 }
265 #endif 273 #endif
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698