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

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

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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 /* 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 "SkReadBuffer.h"
10 #include "SkWriteBuffer.h"
10 #include "SkThread.h" 11 #include "SkThread.h"
11 12
12 #ifdef SK_USE_POSIX_THREADS 13 #ifdef SK_USE_POSIX_THREADS
13 14
14 static SkBaseMutex gPixelRefMutexRing[] = { 15 static SkBaseMutex gPixelRefMutexRing[] = {
15 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, 16 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER },
16 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, 17 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER },
17 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, 18 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER },
18 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, 19 { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER },
19 20
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info ) { 96 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info ) {
96 this->setMutex(mutex); 97 this->setMutex(mutex);
97 fRec.zero(); 98 fRec.zero();
98 fLockCount = 0; 99 fLockCount = 0;
99 this->needsNewGenID(); 100 this->needsNewGenID();
100 fIsImmutable = false; 101 fIsImmutable = false;
101 fPreLocked = false; 102 fPreLocked = false;
102 } 103 }
103 104
104 static SkImageInfo read_info(SkFlattenableReadBuffer& buffer) { 105 static SkImageInfo read_info(SkReadBuffer& buffer) {
105 SkImageInfo info; 106 SkImageInfo info;
106 info.unflatten(buffer); 107 info.unflatten(buffer);
107 return info; 108 return info;
108 } 109 }
109 110
110 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) 111 SkPixelRef::SkPixelRef(SkReadBuffer& buffer, SkBaseMutex* mutex)
111 : INHERITED(buffer) 112 : INHERITED(buffer)
112 , fInfo(read_info(buffer)) 113 , fInfo(read_info(buffer))
113 { 114 {
114 this->setMutex(mutex); 115 this->setMutex(mutex);
115 fRec.zero(); 116 fRec.zero();
116 fLockCount = 0; 117 fLockCount = 0;
117 fIsImmutable = buffer.readBool(); 118 fIsImmutable = buffer.readBool();
118 fGenerationID = buffer.readUInt(); 119 fGenerationID = buffer.readUInt();
119 fUniqueGenerationID = false; // Conservatively assuming the original still exists. 120 fUniqueGenerationID = false; // Conservatively assuming the original still exists.
120 fPreLocked = false; 121 fPreLocked = false;
(...skipping 20 matching lines...) Expand all
141 // only call me in your constructor, otherwise fLockCount tracking can get 142 // only call me in your constructor, otherwise fLockCount tracking can get
142 // out of sync. 143 // out of sync.
143 fRec.fPixels = pixels; 144 fRec.fPixels = pixels;
144 fRec.fColorTable = ctable; 145 fRec.fColorTable = ctable;
145 fRec.fRowBytes = rowBytes; 146 fRec.fRowBytes = rowBytes;
146 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 147 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
147 fPreLocked = true; 148 fPreLocked = true;
148 #endif 149 #endif
149 } 150 }
150 151
151 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { 152 void SkPixelRef::flatten(SkWriteBuffer& buffer) const {
152 this->INHERITED::flatten(buffer); 153 this->INHERITED::flatten(buffer);
153 fInfo.flatten(buffer); 154 fInfo.flatten(buffer);
154 buffer.writeBool(fIsImmutable); 155 buffer.writeBool(fIsImmutable);
155 // We write the gen ID into the picture for within-process recording. This 156 // We write the gen ID into the picture for within-process recording. This
156 // is safe since the same genID will never refer to two different sets of 157 // is safe since the same genID will never refer to two different sets of
157 // pixels (barring overflow). However, each process has its own "namespace" 158 // pixels (barring overflow). However, each process has its own "namespace"
158 // of genIDs. So for cross-process recording we write a zero which will 159 // of genIDs. So for cross-process recording we write a zero which will
159 // trigger assignment of a new genID in playback. 160 // trigger assignment of a new genID in playback.
160 if (buffer.isCrossProcess()) { 161 if (buffer.isCrossProcess()) {
161 buffer.writeUInt(0); 162 buffer.writeUInt(0);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 316
316 #ifdef SK_BUILD_FOR_ANDROID 317 #ifdef SK_BUILD_FOR_ANDROID
317 void SkPixelRef::globalRef(void* data) { 318 void SkPixelRef::globalRef(void* data) {
318 this->ref(); 319 this->ref();
319 } 320 }
320 321
321 void SkPixelRef::globalUnref() { 322 void SkPixelRef::globalUnref() {
322 this->unref(); 323 this->unref();
323 } 324 }
324 #endif 325 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698