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

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

Issue 340613005: Add scale param to SkAlphaThresholdFilter. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Use SkMatrix for scale Created 6 years, 5 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 | « include/effects/SkAlphaThresholdFilter.h ('k') | no next file » | 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 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 #include "SkRegion.h" 12 #include "SkRegion.h"
13 13
14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { 14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter {
15 public: 15 public:
16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, SkScalar outerThreshold); 16 SkAlphaThresholdFilterImpl(const SkRegion& region, const SkMatrix& scale,
17 SkScalar innerThreshold, SkScalar outerThreshold) ;
17 18
18 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl) 19 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm pl)
19 20
20 protected: 21 protected:
21 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); 22 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer);
22 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 23 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
23 24
24 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 25 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
25 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE; 26 SkBitmap* result, SkIPoint* offset) const SK_OVER RIDE;
26 #if SK_SUPPORT_GPU 27 #if SK_SUPPORT_GPU
27 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, 28 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture,
28 const SkMatrix& matrix, const SkIRect& bounds) cons t SK_OVERRIDE; 29 const SkMatrix& matrix, const SkIRect& bounds) cons t SK_OVERRIDE;
29 #endif 30 #endif
30 31
31 private: 32 private:
32 SkRegion fRegion; 33 SkRegion fRegion;
34 SkMatrix fScale;
33 SkScalar fInnerThreshold; 35 SkScalar fInnerThreshold;
34 SkScalar fOuterThreshold; 36 SkScalar fOuterThreshold;
35 typedef SkImageFilter INHERITED; 37 typedef SkImageFilter INHERITED;
36 }; 38 };
37 39
38 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, 40 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
39 SkScalar innerThreshold, 41 SkScalar innerThreshold,
40 SkScalar outerThreshold) { 42 SkScalar outerThreshold) {
41 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, innerThreshold, outer Threshold)); 43 SkMatrix scale;
44 scale.setScale(1.f, 1.f);
bsalomon 2014/07/11 13:00:25 SkMatrix has a reset() function that will set it t
garykac 2014/07/11 19:10:59 Done.
45 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, scale, innerThreshold , outerThreshold));
46 }
47
48 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region,
49 const SkMatrix& scale,
50 SkScalar innerThreshold,
51 SkScalar outerThreshold) {
52 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, scale, innerThreshold , outerThreshold));
42 } 53 }
43 54
44 #if SK_SUPPORT_GPU 55 #if SK_SUPPORT_GPU
45 #include "GrContext.h" 56 #include "GrContext.h"
46 #include "GrCoordTransform.h" 57 #include "GrCoordTransform.h"
47 #include "GrEffect.h" 58 #include "GrEffect.h"
48 #include "gl/GrGLEffect.h" 59 #include "gl/GrGLEffect.h"
49 #include "GrTBackendEffectFactory.h" 60 #include "GrTBackendEffectFactory.h"
50 #include "GrTextureAccess.h" 61 #include "GrTextureAccess.h"
51 62
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 *validFlags = kA_GrColorComponentFlag; 237 *validFlags = kA_GrColorComponentFlag;
227 } else { 238 } else {
228 *validFlags = 0; 239 *validFlags = 0;
229 } 240 }
230 } 241 }
231 242
232 #endif 243 #endif
233 244
234 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) 245 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer)
235 : INHERITED(1, buffer) { 246 : INHERITED(1, buffer) {
247 buffer.readMatrix(&fScale);
236 fInnerThreshold = buffer.readScalar(); 248 fInnerThreshold = buffer.readScalar();
237 fOuterThreshold = buffer.readScalar(); 249 fOuterThreshold = buffer.readScalar();
238 buffer.readRegion(&fRegion); 250 buffer.readRegion(&fRegion);
239 } 251 }
240 252
241 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, 253 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region,
254 const SkMatrix& scale,
242 SkScalar innerThreshold, 255 SkScalar innerThreshold,
243 SkScalar outerThreshold) 256 SkScalar outerThreshold)
244 : INHERITED(0) 257 : INHERITED(0)
245 , fRegion(region) 258 , fRegion(region)
259 , fScale(scale)
246 , fInnerThreshold(innerThreshold) 260 , fInnerThreshold(innerThreshold)
247 , fOuterThreshold(outerThreshold) { 261 , fOuterThreshold(outerThreshold) {
248 } 262 }
249 263
250 #if SK_SUPPORT_GPU 264 #if SK_SUPPORT_GPU
251 bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffectRef** effect, GrTexture* te xture, 265 bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffectRef** effect, GrTexture* te xture,
252 const SkMatrix& in_matrix, const Sk IRect&) const { 266 const SkMatrix& in_matrix, const Sk IRect&) const {
253 if (effect) { 267 if (effect) {
254 GrContext* context = texture->getContext(); 268 GrContext* context = texture->getContext();
255 GrTextureDesc maskDesc; 269 GrTextureDesc maskDesc;
(...skipping 15 matching lines...) Expand all
271 285
272 { 286 {
273 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarg et()); 287 GrContext::AutoRenderTarget art(context, ast.texture()->asRenderTarg et());
274 GrPaint grPaint; 288 GrPaint grPaint;
275 grPaint.setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff); 289 grPaint.setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff);
276 SkRegion::Iterator iter(fRegion); 290 SkRegion::Iterator iter(fRegion);
277 context->clear(NULL, 0x0, true); 291 context->clear(NULL, 0x0, true);
278 292
279 SkMatrix old_matrix = context->getMatrix(); 293 SkMatrix old_matrix = context->getMatrix();
280 context->setMatrix(in_matrix); 294 context->setMatrix(in_matrix);
295 context->concatMatrix(fScale);
281 296
282 while (!iter.done()) { 297 while (!iter.done()) {
283 SkRect rect = SkRect::Make(iter.rect()); 298 SkRect rect = SkRect::Make(iter.rect());
284 context->drawRect(grPaint, rect); 299 context->drawRect(grPaint, rect);
285 iter.next(); 300 iter.next();
286 } 301 }
287 context->setMatrix(old_matrix); 302 context->setMatrix(old_matrix);
288 } 303 }
289 304
290 *effect = AlphaThresholdEffect::Create(texture, 305 *effect = AlphaThresholdEffect::Create(texture,
291 maskTexture, 306 maskTexture,
292 fInnerThreshold, 307 fInnerThreshold,
293 fOuterThreshold); 308 fOuterThreshold);
294 } 309 }
295 return true; 310 return true;
296 } 311 }
297 #endif 312 #endif
298 313
299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 314 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
300 this->INHERITED::flatten(buffer); 315 this->INHERITED::flatten(buffer);
316 buffer.writeMatrix(fScale);
301 buffer.writeScalar(fInnerThreshold); 317 buffer.writeScalar(fInnerThreshold);
302 buffer.writeScalar(fOuterThreshold); 318 buffer.writeScalar(fOuterThreshold);
303 buffer.writeRegion(fRegion); 319 buffer.writeRegion(fRegion);
304 } 320 }
305 321
306 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, 322 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
307 const Context& ctx, SkBitmap* dst , 323 const Context& ctx, SkBitmap* dst ,
308 SkIPoint* offset) const { 324 SkIPoint* offset) const {
309 SkASSERT(src.colorType() == kN32_SkColorType); 325 SkASSERT(src.colorType() == kN32_SkColorType);
310 326
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 (U8CPU)(SkColorGetG(source) * scale), 373 (U8CPU)(SkColorGetG(source) * scale),
358 (U8CPU)(SkColorGetB(source) * scale)); 374 (U8CPU)(SkColorGetB(source) * scale));
359 } 375 }
360 } 376 }
361 dptr[y * dst->width() + x] = output_color; 377 dptr[y * dst->width() + x] = output_color;
362 } 378 }
363 } 379 }
364 380
365 return true; 381 return true;
366 } 382 }
OLDNEW
« no previous file with comments | « include/effects/SkAlphaThresholdFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698