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

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

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: undo mod to GpuBitmapCopy test, and change bitmapdevice to not ask for alloc w/ kNo_Config 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(SkBaseMutex* mutex) { 85 SkPixelRef::SkPixelRef(const SkImageInfo& info) {
86 this->setMutex(mutex); 86 this->setMutex(NULL);
87 fPixels = NULL; 87 fInfo = info;
88 fColorTable = NULL; // we do not track ownership of this 88 fRec.zero();
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;
92 fPreLocked = false; 102 fPreLocked = false;
93 } 103 }
94 104
95 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) 105 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex)
96 : INHERITED(buffer) { 106 : INHERITED(buffer) {
97 this->setMutex(mutex); 107 this->setMutex(mutex);
98 fPixels = NULL; 108
99 fColorTable = NULL; // we do not track ownership of this 109 fInfo.unflatten(buffer);
110 fRec.zero();
100 fLockCount = 0; 111 fLockCount = 0;
101 fIsImmutable = buffer.readBool(); 112 fIsImmutable = buffer.readBool();
102 fGenerationID = buffer.readUInt(); 113 fGenerationID = buffer.readUInt();
103 fUniqueGenerationID = false; // Conservatively assuming the original still exists. 114 fUniqueGenerationID = false; // Conservatively assuming the original still exists.
104 fPreLocked = false; 115 fPreLocked = false;
105 } 116 }
106 117
107 SkPixelRef::~SkPixelRef() { 118 SkPixelRef::~SkPixelRef() {
108 this->callGenIDChangeListeners(); 119 this->callGenIDChangeListeners();
109 } 120 }
110 121
111 void SkPixelRef::needsNewGenID() { 122 void SkPixelRef::needsNewGenID() {
112 fGenerationID = 0; 123 fGenerationID = 0;
113 fUniqueGenerationID = false; 124 fUniqueGenerationID = false;
114 } 125 }
115 126
116 void SkPixelRef::cloneGenID(const SkPixelRef& that) { 127 void SkPixelRef::cloneGenID(const SkPixelRef& that) {
117 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0. 128 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0.
118 this->fGenerationID = that.getGenerationID(); 129 this->fGenerationID = that.getGenerationID();
119 this->fUniqueGenerationID = false; 130 this->fUniqueGenerationID = false;
120 that.fUniqueGenerationID = false; 131 that.fUniqueGenerationID = false;
121 } 132 }
122 133
123 void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) { 134 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) {
124 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED 135 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED
125 // only call me in your constructor, otherwise fLockCount tracking can get 136 // only call me in your constructor, otherwise fLockCount tracking can get
126 // out of sync. 137 // out of sync.
127 fPixels = pixels; 138 fRec.fPixels = pixels;
128 fColorTable = ctable; 139 fRec.fColorTable = ctable;
140 fRec.fRowBytes = rowBytes;
129 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 141 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
130 fPreLocked = true; 142 fPreLocked = true;
131 #endif 143 #endif
132 } 144 }
133 145
134 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { 146 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
135 this->INHERITED::flatten(buffer); 147 this->INHERITED::flatten(buffer);
148
149 fInfo.flatten(buffer);
136 buffer.writeBool(fIsImmutable); 150 buffer.writeBool(fIsImmutable);
137 // We write the gen ID into the picture for within-process recording. This 151 // We write the gen ID into the picture for within-process recording. This
138 // is safe since the same genID will never refer to two different sets of 152 // is safe since the same genID will never refer to two different sets of
139 // pixels (barring overflow). However, each process has its own "namespace" 153 // pixels (barring overflow). However, each process has its own "namespace"
140 // of genIDs. So for cross-process recording we write a zero which will 154 // of genIDs. So for cross-process recording we write a zero which will
141 // trigger assignment of a new genID in playback. 155 // trigger assignment of a new genID in playback.
142 if (buffer.isCrossProcess()) { 156 if (buffer.isCrossProcess()) {
143 buffer.writeUInt(0); 157 buffer.writeUInt(0);
144 } else { 158 } else {
145 buffer.writeUInt(fGenerationID); 159 buffer.writeUInt(fGenerationID);
146 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist. 160 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist.
147 } 161 }
148 } 162 }
149 163
150 void SkPixelRef::lockPixels() { 164 bool SkPixelRef::lockPixels(LockRec* rec) {
151 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 165 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
152 166
153 if (!fPreLocked) { 167 if (!fPreLocked) {
154 SkAutoMutexAcquire ac(*fMutex); 168 SkAutoMutexAcquire ac(*fMutex);
155 169
156 if (1 == ++fLockCount) { 170 if (1 == ++fLockCount) {
157 fPixels = this->onLockPixels(&fColorTable); 171 LockRec rec;
172 if (!this->onNewLockPixels(&rec)) {
173 return false;
174 }
175 fRec = rec;
158 } 176 }
159 } 177 }
178 *rec = fRec;
179 return true;
180 }
181
182 bool SkPixelRef::lockPixels() {
183 LockRec rec;
184 return this->lockPixels(&rec);
160 } 185 }
161 186
162 void SkPixelRef::unlockPixels() { 187 void SkPixelRef::unlockPixels() {
163 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 188 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
164 189
165 if (!fPreLocked) { 190 if (!fPreLocked) {
166 SkAutoMutexAcquire ac(*fMutex); 191 SkAutoMutexAcquire ac(*fMutex);
167 192
168 SkASSERT(fLockCount > 0); 193 SkASSERT(fLockCount > 0);
169 if (0 == --fLockCount) { 194 if (0 == --fLockCount) {
170 this->onUnlockPixels(); 195 this->onUnlockPixels();
171 fPixels = NULL; 196 fRec.zero();
172 fColorTable = NULL;
173 } 197 }
174 } 198 }
175 } 199 }
176 200
177 bool SkPixelRef::lockPixelsAreWritable() const { 201 bool SkPixelRef::lockPixelsAreWritable() const {
178 return this->onLockPixelsAreWritable(); 202 return this->onLockPixelsAreWritable();
179 } 203 }
180 204
181 bool SkPixelRef::onLockPixelsAreWritable() const { 205 bool SkPixelRef::onLockPixelsAreWritable() const {
182 return true; 206 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 SkData* SkPixelRef::onRefEncodedData() { 267 SkData* SkPixelRef::onRefEncodedData() {
244 return NULL; 268 return NULL;
245 } 269 }
246 270
247 size_t SkPixelRef::getAllocatedSizeInBytes() const { 271 size_t SkPixelRef::getAllocatedSizeInBytes() const {
248 return 0; 272 return 0;
249 } 273 }
250 274
251 /////////////////////////////////////////////////////////////////////////////// 275 ///////////////////////////////////////////////////////////////////////////////
252 276
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
253 #ifdef SK_BUILD_FOR_ANDROID 300 #ifdef SK_BUILD_FOR_ANDROID
254 void SkPixelRef::globalRef(void* data) { 301 void SkPixelRef::globalRef(void* data) {
255 this->ref(); 302 this->ref();
256 } 303 }
257 304
258 void SkPixelRef::globalUnref() { 305 void SkPixelRef::globalUnref() {
259 this->unref(); 306 this->unref();
260 } 307 }
261 #endif 308 #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