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

Side by Side Diff: src/core/SkImageFilter.cpp

Issue 378643003: Remove ability for Release code to call getRefCnt() or getWeakRefCnt(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Just SkImageFilter changes 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/core/SkImageFilter.h ('k') | tools/tsan.supp » ('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 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkImageFilter.h" 8 #include "SkImageFilter.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 hash *= 0x85ebca6b; 354 hash *= 0x85ebca6b;
355 hash ^= hash >> 13; 355 hash ^= hash >> 13;
356 hash *= 0xc2b2ae35; 356 hash *= 0xc2b2ae35;
357 hash ^= hash >> 16; 357 hash ^= hash >> 16;
358 358
359 return hash; 359 return hash;
360 } 360 }
361 361
362 class CacheImpl : public SkImageFilter::Cache { 362 class CacheImpl : public SkImageFilter::Cache {
363 public: 363 public:
364 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {} 364 explicit CacheImpl(int minChildren) : fMinChildren(minChildren) {
365 SkASSERT(fMinChildren <= 2);
366 }
367
365 virtual ~CacheImpl(); 368 virtual ~CacheImpl();
366 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV ERRIDE; 369 bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) SK_OV ERRIDE;
367 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o ffset) SK_OVERRIDE; 370 void set(const SkImageFilter* key, const SkBitmap& result, const SkIPoint& o ffset) SK_OVERRIDE;
368 void remove(const SkImageFilter* key) SK_OVERRIDE; 371 void remove(const SkImageFilter* key) SK_OVERRIDE;
369 private: 372 private:
370 typedef const SkImageFilter* Key; 373 typedef const SkImageFilter* Key;
371 struct Value { 374 struct Value {
372 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset) 375 Value(Key key, const SkBitmap& bitmap, const SkIPoint& offset)
373 : fKey(key), fBitmap(bitmap), fOffset(offset) {} 376 : fKey(key), fBitmap(bitmap), fOffset(offset) {}
374 Key fKey; 377 Key fKey;
(...skipping 22 matching lines...) Expand all
397 400
398 void CacheImpl::remove(const SkImageFilter* key) { 401 void CacheImpl::remove(const SkImageFilter* key) {
399 Value* v = fData.find(key); 402 Value* v = fData.find(key);
400 if (v) { 403 if (v) {
401 fData.remove(key); 404 fData.remove(key);
402 delete v; 405 delete v;
403 } 406 }
404 } 407 }
405 408
406 void CacheImpl::set(const SkImageFilter* key, const SkBitmap& result, const SkIP oint& offset) { 409 void CacheImpl::set(const SkImageFilter* key, const SkBitmap& result, const SkIP oint& offset) {
407 if (key->getRefCnt() >= fMinChildren) { 410 if (fMinChildren < 2 || !key->unique()) {
411 // We take !key->unique() as a signal that there are probably at least 2 refs on the key,
412 // meaning this filter probably has at least two children and is worth c aching when
413 // fMinChildren is 2. If fMinChildren is less than two, we'll just alwa ys cache.
408 fData.add(new Value(key, result, offset)); 414 fData.add(new Value(key, result, offset));
409 } 415 }
410 } 416 }
411 417
412 SkImageFilter::Cache* SkImageFilter::Cache::Create(int minChildren) { 418 SkImageFilter::Cache* SkImageFilter::Cache::Create(int minChildren) {
413 return new CacheImpl(minChildren); 419 return new CacheImpl(minChildren);
414 } 420 }
415 421
416 CacheImpl::~CacheImpl() { 422 CacheImpl::~CacheImpl() {
417 SkTDynamicHash<Value, Key>::Iter iter(&fData); 423 SkTDynamicHash<Value, Key>::Iter iter(&fData);
418 424
419 while (!iter.done()) { 425 while (!iter.done()) {
420 Value* v = &*iter; 426 Value* v = &*iter;
421 ++iter; 427 ++iter;
422 delete v; 428 delete v;
423 } 429 }
424 } 430 }
OLDNEW
« no previous file with comments | « include/core/SkImageFilter.h ('k') | tools/tsan.supp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698