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

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

Issue 1074983003: add SkPixmap and external locking to bitmaps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkPixelRef.h" 9 #include "SkPixelRef.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // only call me in your constructor, otherwise fLockCount tracking can get 145 // only call me in your constructor, otherwise fLockCount tracking can get
146 // out of sync. 146 // out of sync.
147 fRec.fPixels = pixels; 147 fRec.fPixels = pixels;
148 fRec.fColorTable = ctable; 148 fRec.fColorTable = ctable;
149 fRec.fRowBytes = rowBytes; 149 fRec.fRowBytes = rowBytes;
150 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 150 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
151 fPreLocked = true; 151 fPreLocked = true;
152 #endif 152 #endif
153 } 153 }
154 154
155 bool SkPixelRef::lockPixelsInsideMutex(LockRec* rec) {
scroggo 2015/05/19 20:11:42 fMutex->assertHeld();
reed1 2015/05/21 20:59:35 Done.
156 if (1 == ++fLockCount) {
157 SkASSERT(fRec.isZero());
158
159 LockRec rec;
160 if (!this->onNewLockPixels(&rec)) {
161 return false;
162 }
163 SkASSERT(!rec.isZero()); // else why did onNewLock return true?
164 fRec = rec;
165 }
166 *rec = fRec;
167 return true;
168 }
169
155 bool SkPixelRef::lockPixels(LockRec* rec) { 170 bool SkPixelRef::lockPixels(LockRec* rec) {
156 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 171 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
157 172
158 if (!fPreLocked) { 173 if (fPreLocked) {
174 *rec = fRec;
175 return true;
176 } else {
159 TRACE_EVENT_BEGIN0("skia", "SkPixelRef::lockPixelsMutex"); 177 TRACE_EVENT_BEGIN0("skia", "SkPixelRef::lockPixelsMutex");
160 SkAutoMutexAcquire ac(*fMutex); 178 SkAutoMutexAcquire ac(*fMutex);
161 TRACE_EVENT_END0("skia", "SkPixelRef::lockPixelsMutex"); 179 TRACE_EVENT_END0("skia", "SkPixelRef::lockPixelsMutex");
162 180 return this->lockPixelsInsideMutex(rec);
163 if (1 == ++fLockCount) {
164 SkASSERT(fRec.isZero());
165
166 LockRec rec;
167 if (!this->onNewLockPixels(&rec)) {
168 return false;
169 }
170 SkASSERT(!rec.isZero()); // else why did onNewLock return true?
171 fRec = rec;
172 }
173 } 181 }
174 *rec = fRec;
175 return true;
176 } 182 }
177 183
178 bool SkPixelRef::lockPixels() { 184 bool SkPixelRef::lockPixels() {
179 LockRec rec; 185 LockRec rec;
180 return this->lockPixels(&rec); 186 return this->lockPixels(&rec);
181 } 187 }
182 188
183 void SkPixelRef::unlockPixels() { 189 void SkPixelRef::unlockPixels() {
184 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 190 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
185 191
186 if (!fPreLocked) { 192 if (!fPreLocked) {
187 SkAutoMutexAcquire ac(*fMutex); 193 SkAutoMutexAcquire ac(*fMutex);
188 194
189 SkASSERT(fLockCount > 0); 195 SkASSERT(fLockCount > 0);
190 if (0 == --fLockCount) { 196 if (0 == --fLockCount) {
191 // don't call onUnlockPixels unless onLockPixels succeeded 197 // don't call onUnlockPixels unless onLockPixels succeeded
192 if (fRec.fPixels) { 198 if (fRec.fPixels) {
193 this->onUnlockPixels(); 199 this->onUnlockPixels();
194 fRec.zero(); 200 fRec.zero();
195 } else { 201 } else {
196 SkASSERT(fRec.isZero()); 202 SkASSERT(fRec.isZero());
197 } 203 }
198 } 204 }
199 } 205 }
200 } 206 }
201 207
208 bool SkPixelRef::requestLock(const LockRequest& request, LockResult* result) {
209 SkASSERT(result);
210 if (request.fSize.isEmpty()) {
211 return false;
212 }
213
214 if (fPreLocked) {
215 result->fUnlockProc = NULL;
216 result->fUnlockContext = NULL;
217 result->fCTable = fRec.fColorTable;
218 result->fPixels = fRec.fPixels;
219 result->fRowBytes = fRec.fRowBytes;
220 result->fSize.set(fInfo.width(), fInfo.height());
221 return true;
222 } else {
223 SkAutoMutexAcquire ac(*fMutex);
224 return this->onRequestLock(request, result);
225 }
226 }
227
202 bool SkPixelRef::lockPixelsAreWritable() const { 228 bool SkPixelRef::lockPixelsAreWritable() const {
203 return this->onLockPixelsAreWritable(); 229 return this->onLockPixelsAreWritable();
204 } 230 }
205 231
206 bool SkPixelRef::onLockPixelsAreWritable() const { 232 bool SkPixelRef::onLockPixelsAreWritable() const {
207 return true; 233 return true;
208 } 234 }
209 235
210 uint32_t SkPixelRef::getGenerationID() const { 236 uint32_t SkPixelRef::getGenerationID() const {
211 uint32_t id = fTaggedGenID.load(); 237 uint32_t id = fTaggedGenID.load();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 290 }
265 291
266 void SkPixelRef::setImmutable() { 292 void SkPixelRef::setImmutable() {
267 fIsImmutable = true; 293 fIsImmutable = true;
268 } 294 }
269 295
270 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { 296 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) {
271 return this->onReadPixels(dst, subset); 297 return this->onReadPixels(dst, subset);
272 } 298 }
273 299
300 //////////////////////////////////////////////////////////////////////////////// ///////////////////
301
274 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { 302 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
275 return false; 303 return false;
276 } 304 }
277 305
278 SkData* SkPixelRef::onRefEncodedData() { 306 SkData* SkPixelRef::onRefEncodedData() {
279 return NULL; 307 return NULL;
280 } 308 }
281 309
282 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3], 310 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy tes[3],
283 SkYUVColorSpace* colorSpace) { 311 SkYUVColorSpace* colorSpace) {
284 return false; 312 return false;
285 } 313 }
286 314
287 size_t SkPixelRef::getAllocatedSizeInBytes() const { 315 size_t SkPixelRef::getAllocatedSizeInBytes() const {
288 return 0; 316 return 0;
289 } 317 }
290 318
319 static void unlock_legacy_result(void* ctx) {
320 SkPixelRef* pr = (SkPixelRef*)ctx;
321 pr->unlockPixels();
322 }
323
324 bool SkPixelRef::onRequestLock(const LockRequest& request, LockResult* result) {
325 LockRec rec;
326 if (!this->lockPixelsInsideMutex(&rec)) {
327 return false;
328 }
329
330 result->fUnlockProc = unlock_legacy_result;
331 result->fUnlockContext = SkRef(this);
332 result->fCTable = rec.fColorTable;
333 result->fPixels = rec.fPixels;
334 result->fRowBytes = rec.fRowBytes;
335 result->fSize.set(fInfo.width(), fInfo.height());
336 return true;
337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698