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

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

Issue 108993002: Revert "Revert "Revert "PixelRef now returns (nearly) everything that is currently in SkBitmap. The… (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 | « src/core/SkMaskFilter.cpp ('k') | src/effects/gradients/SkGradientShader.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkPixelRef.h" 8 #include "SkPixelRef.h"
9 #include "SkFlattenableBuffers.h" 9 #include "SkFlattenableBuffers.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 void SkPixelRef::setMutex(SkBaseMutex* mutex) { 75 void SkPixelRef::setMutex(SkBaseMutex* mutex) {
76 if (NULL == mutex) { 76 if (NULL == mutex) {
77 mutex = get_default_mutex(); 77 mutex = get_default_mutex();
78 } 78 }
79 fMutex = mutex; 79 fMutex = mutex;
80 } 80 }
81 81
82 // just need a > 0 value, so pick a funny one to aid in debugging 82 // just need a > 0 value, so pick a funny one to aid in debugging
83 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 83 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789
84 84
85 SkPixelRef::SkPixelRef(const SkImageInfo& info) { 85 SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
86 this->setMutex(NULL); 86 this->setMutex(mutex);
87 fInfo = info; 87 fPixels = NULL;
88 fRec.zero(); 88 fColorTable = NULL; // we do not track ownership of this
89 fLockCount = 0; 89 fLockCount = 0;
90 this->needsNewGenID(); 90 this->needsNewGenID();
91 fIsImmutable = false; 91 fIsImmutable = false;
92 fPreLocked = false;
93 }
94
95 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) {
96 this->setMutex(mutex);
97 fInfo = info;
98 fRec.zero();
99 fLockCount = 0;
100 this->needsNewGenID();
101 fIsImmutable = false;
102 fPreLocked = false; 92 fPreLocked = false;
103 } 93 }
104 94
105 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) 95 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
106 : INHERITED(buffer) { 96 : INHERITED(buffer) {
107 this->setMutex(mutex); 97 this->setMutex(mutex);
108 98 fPixels = NULL;
109 fInfo.unflatten(buffer); 99 fColorTable = NULL; // we do not track ownership of this
110 fRec.zero();
111 fLockCount = 0; 100 fLockCount = 0;
112 fIsImmutable = buffer.readBool(); 101 fIsImmutable = buffer.readBool();
113 fGenerationID = buffer.readUInt(); 102 fGenerationID = buffer.readUInt();
114 fUniqueGenerationID = false; // Conservatively assuming the original still exists. 103 fUniqueGenerationID = false; // Conservatively assuming the original still exists.
115 fPreLocked = false; 104 fPreLocked = false;
116 } 105 }
117 106
118 SkPixelRef::~SkPixelRef() { 107 SkPixelRef::~SkPixelRef() {
119 this->callGenIDChangeListeners(); 108 this->callGenIDChangeListeners();
120 } 109 }
121 110
122 void SkPixelRef::needsNewGenID() { 111 void SkPixelRef::needsNewGenID() {
123 fGenerationID = 0; 112 fGenerationID = 0;
124 fUniqueGenerationID = false; 113 fUniqueGenerationID = false;
125 } 114 }
126 115
127 void SkPixelRef::cloneGenID(const SkPixelRef& that) { 116 void SkPixelRef::cloneGenID(const SkPixelRef& that) {
128 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0. 117 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0.
129 this->fGenerationID = that.getGenerationID(); 118 this->fGenerationID = that.getGenerationID();
130 this->fUniqueGenerationID = false; 119 this->fUniqueGenerationID = false;
131 that.fUniqueGenerationID = false; 120 that.fUniqueGenerationID = false;
132 } 121 }
133 122
134 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) { 123 void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) {
135 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED 124 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED
136 // only call me in your constructor, otherwise fLockCount tracking can get 125 // only call me in your constructor, otherwise fLockCount tracking can get
137 // out of sync. 126 // out of sync.
138 fRec.fPixels = pixels; 127 fPixels = pixels;
139 fRec.fColorTable = ctable; 128 fColorTable = ctable;
140 fRec.fRowBytes = rowBytes;
141 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 129 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
142 fPreLocked = true; 130 fPreLocked = true;
143 #endif 131 #endif
144 } 132 }
145 133
146 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { 134 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
147 this->INHERITED::flatten(buffer); 135 this->INHERITED::flatten(buffer);
148
149 fInfo.flatten(buffer);
150 buffer.writeBool(fIsImmutable); 136 buffer.writeBool(fIsImmutable);
151 // We write the gen ID into the picture for within-process recording. This 137 // We write the gen ID into the picture for within-process recording. This
152 // is safe since the same genID will never refer to two different sets of 138 // is safe since the same genID will never refer to two different sets of
153 // pixels (barring overflow). However, each process has its own "namespace" 139 // pixels (barring overflow). However, each process has its own "namespace"
154 // of genIDs. So for cross-process recording we write a zero which will 140 // of genIDs. So for cross-process recording we write a zero which will
155 // trigger assignment of a new genID in playback. 141 // trigger assignment of a new genID in playback.
156 if (buffer.isCrossProcess()) { 142 if (buffer.isCrossProcess()) {
157 buffer.writeUInt(0); 143 buffer.writeUInt(0);
158 } else { 144 } else {
159 buffer.writeUInt(fGenerationID); 145 buffer.writeUInt(fGenerationID);
160 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist. 146 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist.
161 } 147 }
162 } 148 }
163 149
164 bool SkPixelRef::lockPixels(LockRec* rec) { 150 void SkPixelRef::lockPixels() {
165 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 151 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
166 152
167 if (!fPreLocked) { 153 if (!fPreLocked) {
168 SkAutoMutexAcquire ac(*fMutex); 154 SkAutoMutexAcquire ac(*fMutex);
169 155
170 if (1 == ++fLockCount) { 156 if (1 == ++fLockCount) {
171 LockRec rec; 157 fPixels = this->onLockPixels(&fColorTable);
172 if (!this->onNewLockPixels(&rec)) {
173 return false;
174 }
175 fRec = rec;
176 } 158 }
177 } 159 }
178 *rec = fRec;
179 return true;
180 }
181
182 bool SkPixelRef::lockPixels() {
183 LockRec rec;
184 return this->lockPixels(&rec);
185 } 160 }
186 161
187 void SkPixelRef::unlockPixels() { 162 void SkPixelRef::unlockPixels() {
188 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 163 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
189 164
190 if (!fPreLocked) { 165 if (!fPreLocked) {
191 SkAutoMutexAcquire ac(*fMutex); 166 SkAutoMutexAcquire ac(*fMutex);
192 167
193 SkASSERT(fLockCount > 0); 168 SkASSERT(fLockCount > 0);
194 if (0 == --fLockCount) { 169 if (0 == --fLockCount) {
195 this->onUnlockPixels(); 170 this->onUnlockPixels();
196 fRec.zero(); 171 fPixels = NULL;
172 fColorTable = NULL;
197 } 173 }
198 } 174 }
199 } 175 }
200 176
201 bool SkPixelRef::lockPixelsAreWritable() const { 177 bool SkPixelRef::lockPixelsAreWritable() const {
202 return this->onLockPixelsAreWritable(); 178 return this->onLockPixelsAreWritable();
203 } 179 }
204 180
205 bool SkPixelRef::onLockPixelsAreWritable() const { 181 bool SkPixelRef::onLockPixelsAreWritable() const {
206 return true; 182 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 SkData* SkPixelRef::onRefEncodedData() { 243 SkData* SkPixelRef::onRefEncodedData() {
268 return NULL; 244 return NULL;
269 } 245 }
270 246
271 size_t SkPixelRef::getAllocatedSizeInBytes() const { 247 size_t SkPixelRef::getAllocatedSizeInBytes() const {
272 return 0; 248 return 0;
273 } 249 }
274 250
275 /////////////////////////////////////////////////////////////////////////////// 251 ///////////////////////////////////////////////////////////////////////////////
276 252
277 #ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS
278
279 void* SkPixelRef::onLockPixels(SkColorTable** ctable) {
280 return NULL;
281 }
282
283 bool SkPixelRef::onNewLockPixels(LockRec* rec) {
284 SkColorTable* ctable;
285 void* pixels = this->onLockPixels(&ctable);
286 if (!pixels) {
287 return false;
288 }
289
290 rec->fPixels = pixels;
291 rec->fColorTable = ctable;
292 rec->fRowBytes = 0; // callers don't currently need this (thank goodness)
293 return true;
294 }
295
296 #endif
297
298 ///////////////////////////////////////////////////////////////////////////////
299
300 #ifdef SK_BUILD_FOR_ANDROID 253 #ifdef SK_BUILD_FOR_ANDROID
301 void SkPixelRef::globalRef(void* data) { 254 void SkPixelRef::globalRef(void* data) {
302 this->ref(); 255 this->ref();
303 } 256 }
304 257
305 void SkPixelRef::globalUnref() { 258 void SkPixelRef::globalUnref() {
306 this->unref(); 259 this->unref();
307 } 260 }
308 #endif 261 #endif
OLDNEW
« no previous file with comments | « src/core/SkMaskFilter.cpp ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698