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

Side by Side Diff: src/lazy/SkDiscardableMemoryPool.cpp

Issue 114673002: be sure to unlock the discardablememory before deleting it (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/lazy/SkDiscardablePixelRef.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 "SkDiscardableMemoryPool.h" 8 #include "SkDiscardableMemoryPool.h"
9 #include "SkOnce.h" 9 #include "SkOnce.h"
10 10
(...skipping 29 matching lines...) Expand all
40 , fLocked(true) 40 , fLocked(true)
41 , fPointer(pointer) 41 , fPointer(pointer)
42 , fBytes(bytes) { 42 , fBytes(bytes) {
43 SkASSERT(fPool != NULL); 43 SkASSERT(fPool != NULL);
44 SkASSERT(fPointer != NULL); 44 SkASSERT(fPointer != NULL);
45 SkASSERT(fBytes > 0); 45 SkASSERT(fBytes > 0);
46 fPool->ref(); 46 fPool->ref();
47 } 47 }
48 48
49 SkPoolDiscardableMemory::~SkPoolDiscardableMemory() { 49 SkPoolDiscardableMemory::~SkPoolDiscardableMemory() {
50 SkASSERT(!fLocked); // contract for SkDiscardableMemory
50 fPool->free(this); 51 fPool->free(this);
51 fPool->unref(); 52 fPool->unref();
52 } 53 }
53 54
54 bool SkPoolDiscardableMemory::lock() { 55 bool SkPoolDiscardableMemory::lock() {
56 SkASSERT(!fLocked); // contract for SkDiscardableMemory
55 return fPool->lock(this); 57 return fPool->lock(this);
56 } 58 }
57 59
58 void* SkPoolDiscardableMemory::data() { 60 void* SkPoolDiscardableMemory::data() {
59 return fLocked ? fPointer : NULL; 61 SkASSERT(fLocked); // contract for SkDiscardableMemory
62 return fPointer;
60 } 63 }
61 64
62 void SkPoolDiscardableMemory::unlock() { 65 void SkPoolDiscardableMemory::unlock() {
66 SkASSERT(fLocked); // contract for SkDiscardableMemory
63 fPool->unlock(this); 67 fPool->unlock(this);
64 } 68 }
65 69
66 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
67 71
68 SkDiscardableMemoryPool::SkDiscardableMemoryPool(size_t budget, 72 SkDiscardableMemoryPool::SkDiscardableMemoryPool(size_t budget,
69 SkBaseMutex* mutex) 73 SkBaseMutex* mutex)
70 : fMutex(mutex) 74 : fMutex(mutex)
71 , fBudget(budget) 75 , fBudget(budget)
72 , fUsed(0) { 76 , fUsed(0) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 198 }
195 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { 199 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() {
196 static SkDiscardableMemoryPool* gPool(NULL); 200 static SkDiscardableMemoryPool* gPool(NULL);
197 SK_DECLARE_STATIC_ONCE(create_pool_once); 201 SK_DECLARE_STATIC_ONCE(create_pool_once);
198 SkOnce(&create_pool_once, create_pool, &gPool); 202 SkOnce(&create_pool_once, create_pool, &gPool);
199 SkASSERT(NULL != gPool); 203 SkASSERT(NULL != gPool);
200 return gPool; 204 return gPool;
201 } 205 }
202 206
203 //////////////////////////////////////////////////////////////////////////////// 207 ////////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « no previous file | src/lazy/SkDiscardablePixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698