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

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

Issue 1414843003: Image filters: Replace all use of tryAllocPixels() with createDevice(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix morphology: don't allocate dest or temp until we need them Created 5 years, 2 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 | « no previous file | src/effects/SkBlurImageFilter.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 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkDevice.h"
10 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
12 #include "SkRegion.h" 13 #include "SkRegion.h"
13 #if SK_SUPPORT_GPU 14 #if SK_SUPPORT_GPU
14 #include "GrDrawContext.h" 15 #include "GrDrawContext.h"
15 #endif 16 #endif
16 17
17 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { 18 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter {
18 public: 19 public:
19 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, 20 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 297 }
297 #endif 298 #endif
298 299
299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { 300 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
300 this->INHERITED::flatten(buffer); 301 this->INHERITED::flatten(buffer);
301 buffer.writeScalar(fInnerThreshold); 302 buffer.writeScalar(fInnerThreshold);
302 buffer.writeScalar(fOuterThreshold); 303 buffer.writeScalar(fOuterThreshold);
303 buffer.writeRegion(fRegion); 304 buffer.writeRegion(fRegion);
304 } 305 }
305 306
306 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, 307 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy* proxy, const SkBitmap& src ,
307 const Context& ctx, SkBitmap* dst , 308 const Context& ctx, SkBitmap* dst ,
308 SkIPoint* offset) const { 309 SkIPoint* offset) const {
309 SkASSERT(src.colorType() == kN32_SkColorType); 310 SkASSERT(src.colorType() == kN32_SkColorType);
310 311
311 if (src.colorType() != kN32_SkColorType) { 312 if (src.colorType() != kN32_SkColorType) {
312 return false; 313 return false;
313 } 314 }
314 315
315 SkMatrix localInverse; 316 SkMatrix localInverse;
316 if (!ctx.ctm().invert(&localInverse)) { 317 if (!ctx.ctm().invert(&localInverse)) {
317 return false; 318 return false;
318 } 319 }
319 320
320 SkAutoLockPixels alp(src); 321 SkAutoLockPixels alp(src);
321 SkASSERT(src.getPixels()); 322 SkASSERT(src.getPixels());
322 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) { 323 if (!src.getPixels() || src.width() <= 0 || src.height() <= 0) {
323 return false; 324 return false;
324 } 325 }
325 326
326 if (!dst->tryAllocPixels(src.info())) { 327 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.heigh t()));
328 if (!device) {
327 return false; 329 return false;
328 } 330 }
331 *dst = device->accessBitmap(false);
332 SkAutoLockPixels alp_dst(*dst);
329 333
330 U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF); 334 U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF);
331 U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF); 335 U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF);
332 SkColor* sptr = src.getAddr32(0, 0); 336 SkColor* sptr = src.getAddr32(0, 0);
333 SkColor* dptr = dst->getAddr32(0, 0); 337 SkColor* dptr = dst->getAddr32(0, 0);
334 int width = src.width(), height = src.height(); 338 int width = src.width(), height = src.height();
335 for (int y = 0; y < height; ++y) { 339 for (int y = 0; y < height; ++y) {
336 for (int x = 0; x < width; ++x) { 340 for (int x = 0; x < width; ++x) {
337 const SkColor& source = sptr[y * width + x]; 341 const SkColor& source = sptr[y * width + x];
338 SkColor output_color(source); 342 SkColor output_color(source);
(...skipping 27 matching lines...) Expand all
366 } 370 }
367 371
368 #ifndef SK_IGNORE_TO_STRING 372 #ifndef SK_IGNORE_TO_STRING
369 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
370 str->appendf("SkAlphaThresholdImageFilter: ("); 374 str->appendf("SkAlphaThresholdImageFilter: (");
371 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
372 str->append(")"); 376 str->append(")");
373 } 377 }
374 #endif 378 #endif
375 379
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkBlurImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698