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

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

Issue 112603003: Reverting r12665 & r12666 (Remove duplicate impl for SkImageInfo flattening) due to Chromium/Blink … (Closed) Base URL: http://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(const SkImageInfo& info, SkBaseMutex* mutex) {
86 this->setMutex(NULL); 86 this->setMutex(mutex);
87 fInfo = info; 87 fInfo = info;
88 fRec.zero(); 88 fPixels = NULL;
89 fColorTable = NULL; // we do not track ownership of this
89 fLockCount = 0; 90 fLockCount = 0;
90 this->needsNewGenID(); 91 this->needsNewGenID();
91 fIsImmutable = false; 92 fIsImmutable = false;
92 fPreLocked = false; 93 fPreLocked = false;
93 } 94 }
94 95
95 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) { 96 SkPixelRef::SkPixelRef(const SkImageInfo& info) {
96 this->setMutex(mutex); 97 this->setMutex(NULL);
97 fInfo = info; 98 fInfo = info;
98 fRec.zero(); 99 fPixels = NULL;
100 fColorTable = NULL; // we do not track ownership of this
99 fLockCount = 0; 101 fLockCount = 0;
100 this->needsNewGenID(); 102 this->needsNewGenID();
101 fIsImmutable = false; 103 fIsImmutable = false;
102 fPreLocked = false; 104 fPreLocked = false;
103 } 105 }
104 106
107 #ifdef SK_SUPPORT_LEGACY_PIXELREF_CONSTRUCTOR
108 // THIS GUY IS DEPRECATED -- don't use me!
109 SkPixelRef::SkPixelRef(SkBaseMutex* mutex) {
110 this->setMutex(mutex);
111 // Fill with dummy values.
112 sk_bzero(&fInfo, sizeof(fInfo));
113 fPixels = NULL;
114 fColorTable = NULL; // we do not track ownership of this
115 fLockCount = 0;
116 this->needsNewGenID();
117 fIsImmutable = false;
118 fPreLocked = false;
119 }
120 #endif
121
105 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) 122 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
106 : INHERITED(buffer) { 123 : INHERITED(buffer) {
107 this->setMutex(mutex); 124 this->setMutex(mutex);
108 125 fPixels = NULL;
109 fInfo.unflatten(buffer); 126 fColorTable = NULL; // we do not track ownership of this
110 fRec.zero();
111 fLockCount = 0; 127 fLockCount = 0;
112 fIsImmutable = buffer.readBool(); 128 fIsImmutable = buffer.readBool();
113 fGenerationID = buffer.readUInt(); 129 fGenerationID = buffer.readUInt();
114 fUniqueGenerationID = false; // Conservatively assuming the original still exists. 130 fUniqueGenerationID = false; // Conservatively assuming the original still exists.
115 fPreLocked = false; 131 fPreLocked = false;
116 } 132 }
117 133
118 SkPixelRef::~SkPixelRef() { 134 SkPixelRef::~SkPixelRef() {
119 this->callGenIDChangeListeners(); 135 this->callGenIDChangeListeners();
120 } 136 }
121 137
122 void SkPixelRef::needsNewGenID() { 138 void SkPixelRef::needsNewGenID() {
123 fGenerationID = 0; 139 fGenerationID = 0;
124 fUniqueGenerationID = false; 140 fUniqueGenerationID = false;
125 } 141 }
126 142
127 void SkPixelRef::cloneGenID(const SkPixelRef& that) { 143 void SkPixelRef::cloneGenID(const SkPixelRef& that) {
128 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0. 144 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0.
129 this->fGenerationID = that.getGenerationID(); 145 this->fGenerationID = that.getGenerationID();
130 this->fUniqueGenerationID = false; 146 this->fUniqueGenerationID = false;
131 that.fUniqueGenerationID = false; 147 that.fUniqueGenerationID = false;
132 } 148 }
133 149
134 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) { 150 void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) {
135 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED 151 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED
136 // only call me in your constructor, otherwise fLockCount tracking can get 152 // only call me in your constructor, otherwise fLockCount tracking can get
137 // out of sync. 153 // out of sync.
138 fRec.fPixels = pixels; 154 fPixels = pixels;
139 fRec.fColorTable = ctable; 155 fColorTable = ctable;
140 fRec.fRowBytes = rowBytes;
141 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 156 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
142 fPreLocked = true; 157 fPreLocked = true;
143 #endif 158 #endif
144 } 159 }
145 160
146 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { 161 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
147 this->INHERITED::flatten(buffer); 162 this->INHERITED::flatten(buffer);
148
149 fInfo.flatten(buffer);
150 buffer.writeBool(fIsImmutable); 163 buffer.writeBool(fIsImmutable);
151 // We write the gen ID into the picture for within-process recording. This 164 // 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 165 // 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" 166 // pixels (barring overflow). However, each process has its own "namespace"
154 // of genIDs. So for cross-process recording we write a zero which will 167 // of genIDs. So for cross-process recording we write a zero which will
155 // trigger assignment of a new genID in playback. 168 // trigger assignment of a new genID in playback.
156 if (buffer.isCrossProcess()) { 169 if (buffer.isCrossProcess()) {
157 buffer.writeUInt(0); 170 buffer.writeUInt(0);
158 } else { 171 } else {
159 buffer.writeUInt(fGenerationID); 172 buffer.writeUInt(fGenerationID);
160 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist. 173 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist.
161 } 174 }
162 } 175 }
163 176
164 bool SkPixelRef::lockPixels(LockRec* rec) { 177 void SkPixelRef::lockPixels() {
165 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 178 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
166 179
167 if (!fPreLocked) { 180 if (!fPreLocked) {
168 SkAutoMutexAcquire ac(*fMutex); 181 SkAutoMutexAcquire ac(*fMutex);
169 182
170 if (1 == ++fLockCount) { 183 if (1 == ++fLockCount) {
171 SkASSERT(fRec.isZero()); 184 fPixels = this->onLockPixels(&fColorTable);
172 185 // If onLockPixels failed, it will return NULL
173 LockRec rec; 186 if (NULL == fPixels) {
174 if (!this->onNewLockPixels(&rec)) { 187 fColorTable = NULL;
175 return false;
176 } 188 }
177 SkASSERT(!rec.isZero()); // else why did onNewLock return true?
178 fRec = rec;
179 } 189 }
180 } 190 }
181 *rec = fRec;
182 return true;
183 }
184
185 bool SkPixelRef::lockPixels() {
186 LockRec rec;
187 return this->lockPixels(&rec);
188 } 191 }
189 192
190 void SkPixelRef::unlockPixels() { 193 void SkPixelRef::unlockPixels() {
191 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 194 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
192 195
193 if (!fPreLocked) { 196 if (!fPreLocked) {
194 SkAutoMutexAcquire ac(*fMutex); 197 SkAutoMutexAcquire ac(*fMutex);
195 198
196 SkASSERT(fLockCount > 0); 199 SkASSERT(fLockCount > 0);
197 if (0 == --fLockCount) { 200 if (0 == --fLockCount) {
198 // don't call onUnlockPixels unless onLockPixels succeeded 201 // don't call onUnlockPixels unless onLockPixels succeeded
199 if (fRec.fPixels) { 202 if (fPixels) {
200 this->onUnlockPixels(); 203 this->onUnlockPixels();
201 fRec.zero(); 204 fPixels = NULL;
205 fColorTable = NULL;
202 } else { 206 } else {
203 SkASSERT(fRec.isZero()); 207 SkASSERT(NULL == fColorTable);
204 } 208 }
205 } 209 }
206 } 210 }
207 } 211 }
208 212
209 bool SkPixelRef::lockPixelsAreWritable() const { 213 bool SkPixelRef::lockPixelsAreWritable() const {
210 return this->onLockPixelsAreWritable(); 214 return this->onLockPixelsAreWritable();
211 } 215 }
212 216
213 bool SkPixelRef::onLockPixelsAreWritable() const { 217 bool SkPixelRef::onLockPixelsAreWritable() const {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 SkData* SkPixelRef::onRefEncodedData() { 279 SkData* SkPixelRef::onRefEncodedData() {
276 return NULL; 280 return NULL;
277 } 281 }
278 282
279 size_t SkPixelRef::getAllocatedSizeInBytes() const { 283 size_t SkPixelRef::getAllocatedSizeInBytes() const {
280 return 0; 284 return 0;
281 } 285 }
282 286
283 /////////////////////////////////////////////////////////////////////////////// 287 ///////////////////////////////////////////////////////////////////////////////
284 288
285 #ifdef SK_SUPPORT_LEGACY_ONLOCKPIXELS
286
287 void* SkPixelRef::onLockPixels(SkColorTable** ctable) {
288 return NULL;
289 }
290
291 bool SkPixelRef::onNewLockPixels(LockRec* rec) {
292 SkColorTable* ctable;
293 void* pixels = this->onLockPixels(&ctable);
294 if (!pixels) {
295 return false;
296 }
297
298 rec->fPixels = pixels;
299 rec->fColorTable = ctable;
300 rec->fRowBytes = 0; // callers don't currently need this (thank goodness)
301 return true;
302 }
303
304 #endif
305
306 ///////////////////////////////////////////////////////////////////////////////
307
308 #ifdef SK_BUILD_FOR_ANDROID 289 #ifdef SK_BUILD_FOR_ANDROID
309 void SkPixelRef::globalRef(void* data) { 290 void SkPixelRef::globalRef(void* data) {
310 this->ref(); 291 this->ref();
311 } 292 }
312 293
313 void SkPixelRef::globalUnref() { 294 void SkPixelRef::globalUnref() {
314 this->unref(); 295 this->unref();
315 } 296 }
316 #endif 297 #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