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

Side by Side Diff: include/core/SkImageFilter.h

Issue 1894573002: Move SkImageFilter over to storing sk_sps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more clean up Created 4 years, 8 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/core/SkImageFilter.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 2011 Google Inc. 2 * Copyright 2011 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 #ifndef SkImageFilter_DEFINED 8 #ifndef SkImageFilter_DEFINED
9 #define SkImageFilter_DEFINED 9 #define SkImageFilter_DEFINED
10 10
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 * Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely 227 * Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely
228 * replaced by the returned colorfilter. i.e. the two effects will affect d rawing in the 228 * replaced by the returned colorfilter. i.e. the two effects will affect d rawing in the
229 * same way. 229 * same way.
230 */ 230 */
231 bool asAColorFilter(SkColorFilter** filterPtr) const; 231 bool asAColorFilter(SkColorFilter** filterPtr) const;
232 232
233 /** 233 /**
234 * Returns the number of inputs this filter will accept (some inputs can 234 * Returns the number of inputs this filter will accept (some inputs can
235 * be NULL). 235 * be NULL).
236 */ 236 */
237 int countInputs() const { return fInputCount; } 237 int countInputs() const { return fInputs.count(); }
238 238
239 /** 239 /**
240 * Returns the input filter at a given index, or NULL if no input is 240 * Returns the input filter at a given index, or NULL if no input is
241 * connected. The indices used are filter-specific. 241 * connected. The indices used are filter-specific.
242 */ 242 */
243 SkImageFilter* getInput(int i) const { 243 SkImageFilter* getInput(int i) const {
244 SkASSERT(i < fInputCount); 244 SkASSERT(i < fInputs.count());
245 return fInputs[i]; 245 return fInputs[i].get();
246 } 246 }
247 247
248 /** 248 /**
249 * Returns whether any edges of the crop rect have been set. The crop 249 * Returns whether any edges of the crop rect have been set. The crop
250 * rect is set at construction time, and determines which pixels from the 250 * rect is set at construction time, and determines which pixels from the
251 * input image will be processed, and which pixels in the output image will be allowed. 251 * input image will be processed, and which pixels in the output image will be allowed.
252 * The size of the crop rect should be 252 * The size of the crop rect should be
253 * used as the size of the destination image. The origin of this rect 253 * used as the size of the destination image. The origin of this rect
254 * should be used to offset access to the input images, and should also 254 * should be used to offset access to the input images, and should also
255 * be added to the "offset" parameter in onFilterImage and 255 * be added to the "offset" parameter in onFilterImage and
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 * be left uninitialized. 323 * be left uninitialized.
324 * If this returns true, then inputCount() is the number of found input filters, each 324 * If this returns true, then inputCount() is the number of found input filters, each
325 * of which may be NULL or a valid imagefilter. 325 * of which may be NULL or a valid imagefilter.
326 */ 326 */
327 bool unflatten(SkReadBuffer&, int expectedInputs); 327 bool unflatten(SkReadBuffer&, int expectedInputs);
328 328
329 const CropRect& cropRect() const { return fCropRect; } 329 const CropRect& cropRect() const { return fCropRect; }
330 int inputCount() const { return fInputs.count(); } 330 int inputCount() const { return fInputs.count(); }
331 sk_sp<SkImageFilter>* inputs() const { return fInputs.get(); } 331 sk_sp<SkImageFilter>* inputs() const { return fInputs.get(); }
332 332
333 sk_sp<SkImageFilter> getInput(int index) const { return fInputs[index]; } 333 sk_sp<SkImageFilter> getInput(int index) const { return fInputs[index]; }
reed1 2016/04/15 16:33:43 why does this getInput return sp, and the earlier
robertphillips 2016/04/15 16:56:04 Callers of this method intend to take a ref on the
334 334
335 // If the caller wants a copy of the inputs, call this and it will trans fer ownership
336 // of the unflattened input filters to the caller. This is just a short- cut for copying
337 // the inputs, calling ref() on each, and then waiting for Common's dest ructor to call
338 // unref() on each.
339 void detachInputs(SkImageFilter** inputs);
340
341 private: 335 private:
342 CropRect fCropRect; 336 CropRect fCropRect;
343 // most filters accept at most 2 input-filters 337 // most filters accept at most 2 input-filters
344 SkAutoSTArray<2, sk_sp<SkImageFilter>> fInputs; 338 SkAutoSTArray<2, sk_sp<SkImageFilter>> fInputs;
345 339
346 void allocInputs(int count); 340 void allocInputs(int count);
347 }; 341 };
348 342
349 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = nullptr);
350
351 SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect); 343 SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
352 344
353 virtual ~SkImageFilter(); 345 virtual ~SkImageFilter();
354 346
355 /** 347 /**
356 * Constructs a new SkImageFilter read from an SkReadBuffer object. 348 * Constructs a new SkImageFilter read from an SkReadBuffer object.
357 * 349 *
358 * @param inputCount The exact number of inputs expected for this SkImag eFilter object. 350 * @param inputCount The exact number of inputs expected for this SkImag eFilter object.
359 * -1 can be used if the filter accepts any number of inputs. 351 * -1 can be used if the filter accepts any number of inputs.
360 * @param rb SkReadBuffer object from which the SkImageFilter is read. 352 * @param rb SkReadBuffer object from which the SkImageFilter is read.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 * The clip bounds are adjusted to accommodate any margins that this 451 * The clip bounds are adjusted to accommodate any margins that this
460 * filter requires by calling this node's 452 * filter requires by calling this node's
461 * onFilterNodeBounds(..., kReverse_MapDirection). 453 * onFilterNodeBounds(..., kReverse_MapDirection).
462 */ 454 */
463 Context mapContext(const Context& ctx) const; 455 Context mapContext(const Context& ctx) const;
464 456
465 private: 457 private:
466 friend class SkGraphics; 458 friend class SkGraphics;
467 static void PurgeCache(); 459 static void PurgeCache();
468 460
461 void init(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* crop Rect);
469 bool filterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, 462 bool filterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
470 SkBitmap* result, SkIPoint* offset) const; 463 SkBitmap* result, SkIPoint* offset) const;
471 464
472 bool usesSrcInput() const { return fUsesSrcInput; } 465 bool usesSrcInput() const { return fUsesSrcInput; }
473 virtual bool affectsTransparentBlack() const { return false; } 466 virtual bool affectsTransparentBlack() const { return false; }
474 467
475 typedef SkFlattenable INHERITED; 468 SkAutoSTArray<2, sk_sp<SkImageFilter>> fInputs;
476 int fInputCount; 469
477 SkImageFilter** fInputs;
478 bool fUsesSrcInput; 470 bool fUsesSrcInput;
479 CropRect fCropRect; 471 CropRect fCropRect;
480 uint32_t fUniqueID; // Globally unique 472 uint32_t fUniqueID; // Globally unique
481 mutable SkTArray<Cache::Key> fCacheKeys; 473 mutable SkTArray<Cache::Key> fCacheKeys;
482 mutable SkMutex fMutex; 474 mutable SkMutex fMutex;
475 typedef SkFlattenable INHERITED;
483 }; 476 };
484 477
485 /** 478 /**
486 * Helper to unflatten the common data, and return NULL if we fail. 479 * Helper to unflatten the common data, and return NULL if we fail.
487 */ 480 */
488 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \ 481 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \
489 Common localVar; \ 482 Common localVar; \
490 do { \ 483 do { \
491 if (!localVar.unflatten(buffer, expectedCount)) { \ 484 if (!localVar.unflatten(buffer, expectedCount)) { \
492 return NULL; \ 485 return NULL; \
493 } \ 486 } \
494 } while (0) 487 } while (0)
495 488
496 #endif 489 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698