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

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

Issue 2215323003: Start using RenderTargetProxy (omnibus) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update 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/effects/GrAlphaThresholdFragmentProcessor.h ('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 "GrRenderTargetContext.h" 19 #include "GrRenderTargetContext.h"
20 #include "GrFixedClip.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
100 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetCo ntextWithFallback( 102 sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetCo ntextWithFallback(
101 SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixel Config, nullptr)); 103 SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixel Config, nullptr));
102 if (!renderTargetContext) { 104 if (!renderTargetContext) {
103 return nullptr; 105 return nullptr;
104 } 106 }
105 107
106 GrPaint grPaint; 108 GrPaint grPaint;
107 grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc); 109 grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc);
108 SkRegion::Iterator iter(fRegion); 110 SkRegion::Iterator iter(fRegion);
109 renderTargetContext->clear(nullptr, 0x0, true); 111 renderTargetContext->clear(nullptr, 0x0, true);
110 112
111 GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height())); 113 GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height()));
112 while (!iter.done()) { 114 while (!iter.done()) {
113 SkRect rect = SkRect::Make(iter.rect()); 115 SkRect rect = SkRect::Make(iter.rect());
114 renderTargetContext->drawRect(clip, grPaint, inMatrix, rect); 116 renderTargetContext->drawRect(clip, grPaint, inMatrix, rect);
115 iter.next(); 117 iter.next();
116 } 118 }
117 119
118 return renderTargetContext->asTexture(); 120 return renderTargetContext->asDeferredTexture();
119 } 121 }
120 #endif 122 #endif
121 123
122 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 124 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
123 this->INHERITED::flatten(buffer); 125 this->INHERITED::flatten(buffer);
124 buffer.writeScalar(fInnerThreshold); 126 buffer.writeScalar(fInnerThreshold);
125 buffer.writeScalar(fOuterThreshold); 127 buffer.writeScalar(fOuterThreshold);
126 buffer.writeRegion(fRegion); 128 buffer.writeRegion(fRegion);
127 } 129 }
128 130
(...skipping 11 matching lines...) Expand all
140 142
141 SkIRect bounds; 143 SkIRect bounds;
142 if (!this->applyCropRect(ctx, inputBounds, &bounds)) { 144 if (!this->applyCropRect(ctx, inputBounds, &bounds)) {
143 return nullptr; 145 return nullptr;
144 } 146 }
145 147
146 #if SK_SUPPORT_GPU 148 #if SK_SUPPORT_GPU
147 if (source->isTextureBacked()) { 149 if (source->isTextureBacked()) {
148 GrContext* context = source->getContext(); 150 GrContext* context = source->getContext();
149 151
150 sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); 152 sk_sp<GrTextureProxy> inputTexture(input->asTextureProxy(context));
151 SkASSERT(inputTexture); 153 SkASSERT(inputTexture);
152 154
153 offset->fX = bounds.left(); 155 offset->fX = bounds.left();
154 offset->fY = bounds.top(); 156 offset->fY = bounds.top();
155 157
156 bounds.offset(-inputOffset); 158 bounds.offset(-inputOffset);
157 159
158 SkMatrix matrix(ctx.ctm()); 160 SkMatrix matrix(ctx.ctm());
159 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bound s.top())); 161 matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bound s.top()));
160 162
161 sk_sp<GrTexture> maskTexture(this->createMaskTexture(context, matrix, bo unds)); 163 sk_sp<GrTextureProxy> maskTexture(this->createMaskTexture(context, matri x, bounds));
162 if (!maskTexture) { 164 if (!maskTexture) {
163 return nullptr; 165 return nullptr;
164 } 166 }
165 167
166 const OutputProperties& outProps = ctx.outputProperties(); 168 const OutputProperties& outProps = ctx.outputProperties();
167 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input ->getColorSpace(), 169 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input ->getColorSpace(),
168 outPr ops.colorSpace()); 170 outPr ops.colorSpace());
169 sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make( 171 sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make(
170 inputTe xture.get(), 172 inputTe xture.get(),
171 std::mo ve(colorSpaceXform), 173 std::mo ve(colorSpaceXform),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 dst); 258 dst);
257 } 259 }
258 260
259 #ifndef SK_IGNORE_TO_STRING 261 #ifndef SK_IGNORE_TO_STRING
260 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 262 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
261 str->appendf("SkAlphaThresholdImageFilter: ("); 263 str->appendf("SkAlphaThresholdImageFilter: (");
262 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 264 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
263 str->append(")"); 265 str->append(")");
264 } 266 }
265 #endif 267 #endif
OLDNEW
« no previous file with comments | « src/effects/GrAlphaThresholdFragmentProcessor.h ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698