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

Side by Side Diff: src/core/SkBlurImageFilter.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 | « include/private/GrTextureProxy.h ('k') | src/core/SkGpuBlurUtils.h » ('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 2011 The Android Open Source Project 2 * Copyright 2011 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 "SkAutoPixmapStorage.h" 8 #include "SkAutoPixmapStorage.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkGpuBlurUtils.h" 10 #include "SkGpuBlurUtils.h"
11 #include "SkOpts.h" 11 #include "SkOpts.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h" 13 #include "SkSpecialImage.h"
14 #include "SkWriteBuffer.h" 14 #include "SkWriteBuffer.h"
15 15
16 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
17 #include "GrContext.h" 17 #include "GrContext.h"
18 #include "GrTextureProxy.h"
18 #include "SkGr.h" 19 #include "SkGr.h"
19 #endif 20 #endif
20 21
21 class SkBlurImageFilterImpl : public SkImageFilter { 22 class SkBlurImageFilterImpl : public SkImageFilter {
22 public: 23 public:
23 SkBlurImageFilterImpl(SkScalar sigmaX, 24 SkBlurImageFilterImpl(SkScalar sigmaX,
24 SkScalar sigmaY, 25 SkScalar sigmaY,
25 sk_sp<SkImageFilter> input, 26 sk_sp<SkImageFilter> input,
26 const CropRect* cropRect); 27 const CropRect* cropRect);
27 28
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 *lowOffset = *highOffset = (d - 1) / 2; 104 *lowOffset = *highOffset = (d - 1) / 2;
104 *kernelSize3 = d; 105 *kernelSize3 = d;
105 } else { 106 } else {
106 *highOffset = d / 2; 107 *highOffset = d / 2;
107 *lowOffset = *highOffset - 1; 108 *lowOffset = *highOffset - 1;
108 *kernelSize3 = d + 1; 109 *kernelSize3 = d + 1;
109 } 110 }
110 } 111 }
111 112
112 sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc e, 113 sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc e,
113 const Context& ctx, 114 const Context& ctx,
114 SkIPoint* offset) const { 115 SkIPoint* offset) con st {
115 SkIPoint inputOffset = SkIPoint::Make(0, 0); 116 SkIPoint inputOffset = SkIPoint::Make(0, 0);
116 117
117 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ; 118 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
118 if (!input) { 119 if (!input) {
119 return nullptr; 120 return nullptr;
120 } 121 }
121 122
122 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY, 123 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY,
123 input->width(), input->height()); 124 input->width(), input->height());
124 125
125 SkIRect dstBounds; 126 SkIRect dstBounds;
126 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { 127 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) {
127 return nullptr; 128 return nullptr;
128 } 129 }
129 if (!inputBounds.intersect(dstBounds)) { 130 if (!inputBounds.intersect(dstBounds)) {
130 return nullptr; 131 return nullptr;
131 } 132 }
132 133
133 const SkVector sigma = map_sigma(fSigma, ctx.ctm()); 134 const SkVector sigma = map_sigma(fSigma, ctx.ctm());
134 135
135 #if SK_SUPPORT_GPU 136 #if SK_SUPPORT_GPU
136 if (source->isTextureBacked()) { 137 if (source->isTextureBacked()) {
137 GrContext* context = source->getContext(); 138 GrContext* context = source->getContext();
138 sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); 139 sk_sp<GrTextureProxy> inputTexture(input->asTextureProxy(context));
139 SkASSERT(inputTexture); 140 SkASSERT(inputTexture);
140 141
141 if (0 == sigma.x() && 0 == sigma.y()) { 142 if (0 == sigma.x() && 0 == sigma.y()) {
142 offset->fX = inputBounds.x(); 143 offset->fX = inputBounds.x();
143 offset->fY = inputBounds.y(); 144 offset->fY = inputBounds.y();
144 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), 145 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(),
145 -inputOffset.y())); 146 -inputOffset.y()));
146 } 147 }
147 148
148 offset->fX = dstBounds.fLeft; 149 offset->fX = dstBounds.fLeft;
149 offset->fY = dstBounds.fTop; 150 offset->fY = dstBounds.fTop;
150 inputBounds.offset(-inputOffset); 151 inputBounds.offset(-inputOffset);
151 dstBounds.offset(-inputOffset); 152 dstBounds.offset(-inputOffset);
152 // We intentionally use the source's color space, not the destination's (from ctx). We 153 // We intentionally use the source's color space, not the destination's (from ctx). We
153 // always blur in the source's config, so we need a compatible color spa ce. We also want to 154 // always blur in the source's config, so we need a compatible color spa ce. We also want to
154 // avoid doing gamut conversion on every fetch of the texture. 155 // avoid doing gamut conversion on every fetch of the texture.
155 sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::Gaussia nBlur( 156 sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::Gaussia nBlur(
156 context, 157 context,
157 inputTexture.get (), 158 inputTexture.get (),
158 sk_ref_sp(source ->getColorSpace()), 159 sk_ref_sp(source ->getColorSpace()),
159 dstBounds, 160 dstBounds,
160 &inputBounds, 161 &inputBounds,
161 sigma.x(), 162 sigma.x(),
162 sigma.y())); 163 sigma.y()));
163 if (!renderTargetContext) { 164 if (!renderTargetContext) {
164 return nullptr; 165 return nullptr;
165 } 166 }
166 167
167 // TODO: Get the colorSpace from the renderTargetContext (once it has on e) 168 // TODO: Get the colorSpace from the renderTargetContext (once it has on e)
168 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(dstBounds.width(), ds tBounds.height()), 169 return SkSpecialImage::MakeDeferredFromGpu(SkIRect::MakeWH(dstBounds.wid th(),
169 kNeedNewImageUniqueID_SpecialImage, 170 dstBounds.hei ght()),
170 renderTargetContext->asTexture(), 171 kNeedNewImageUniqueID_Special Image,
171 sk_ref_sp(input->getColorSpace()), &s ource->props()); 172 renderTargetContext->asDeferr edTexture(),
173 sk_ref_sp(input->getColorSpac e()),
174 &source->props());
172 } 175 }
173 #endif 176 #endif
174 177
175 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; 178 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
176 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; 179 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
177 get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOf fsetX); 180 get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOf fsetX);
178 get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOf fsetY); 181 get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOf fsetY);
179 182
180 if (kernelSizeX < 0 || kernelSizeY < 0) { 183 if (kernelSizeX < 0 || kernelSizeY < 0) {
181 return nullptr; 184 return nullptr;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 str->appendf("SkBlurImageFilterImpl: ("); 285 str->appendf("SkBlurImageFilterImpl: (");
283 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); 286 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight);
284 287
285 if (this->getInput(0)) { 288 if (this->getInput(0)) {
286 this->getInput(0)->toString(str); 289 this->getInput(0)->toString(str);
287 } 290 }
288 291
289 str->append("))"); 292 str->append("))");
290 } 293 }
291 #endif 294 #endif
OLDNEW
« no previous file with comments | « include/private/GrTextureProxy.h ('k') | src/core/SkGpuBlurUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698