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

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

Issue 320873003: change pixelref to not inherit from SkFlattenable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 5 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
« no previous file with comments | « src/core/SkMallocPixelRef.cpp ('k') | src/core/SkScaledImageCache.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 "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const_cast<SkAlphaType*>(&fInfo. fAlphaType))); 101 const_cast<SkAlphaType*>(&fInfo. fAlphaType)));
102 102
103 this->setMutex(mutex); 103 this->setMutex(mutex);
104 fRec.zero(); 104 fRec.zero();
105 fLockCount = 0; 105 fLockCount = 0;
106 this->needsNewGenID(); 106 this->needsNewGenID();
107 fIsImmutable = false; 107 fIsImmutable = false;
108 fPreLocked = false; 108 fPreLocked = false;
109 } 109 }
110 110
111 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
111 static SkImageInfo read_info(SkReadBuffer& buffer) { 112 static SkImageInfo read_info(SkReadBuffer& buffer) {
112 SkImageInfo info; 113 SkImageInfo info;
113 info.unflatten(buffer); 114 info.unflatten(buffer);
114 return info; 115 return info;
115 } 116 }
116 117
117 SkPixelRef::SkPixelRef(SkReadBuffer& buffer, SkBaseMutex* mutex) 118 SkPixelRef::SkPixelRef(SkReadBuffer& buffer, SkBaseMutex* mutex)
118 : INHERITED(buffer) 119 : INHERITED(buffer)
119 , fInfo(read_info(buffer)) 120 , fInfo(read_info(buffer))
120 { 121 {
121 SkDEBUGCODE(SkAlphaType alphaType;) 122 SkDEBUGCODE(SkAlphaType alphaType;)
122 SkASSERT(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaType(), &alphaType)); 123 SkASSERT(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaType(), &alphaType));
123 SkASSERT(fInfo.fAlphaType == alphaType); 124 SkASSERT(fInfo.fAlphaType == alphaType);
124 125
125 this->setMutex(mutex); 126 this->setMutex(mutex);
126 fRec.zero(); 127 fRec.zero();
127 fLockCount = 0; 128 fLockCount = 0;
128 fIsImmutable = buffer.readBool(); 129 fIsImmutable = buffer.readBool();
129 fGenerationID = buffer.readUInt(); 130 fGenerationID = buffer.readUInt();
130 fUniqueGenerationID = false; // Conservatively assuming the original still exists. 131 fUniqueGenerationID = false; // Conservatively assuming the original still exists.
131 fPreLocked = false; 132 fPreLocked = false;
132 } 133 }
134 #endif
133 135
134 SkPixelRef::~SkPixelRef() { 136 SkPixelRef::~SkPixelRef() {
135 this->callGenIDChangeListeners(); 137 this->callGenIDChangeListeners();
136 } 138 }
137 139
138 void SkPixelRef::needsNewGenID() { 140 void SkPixelRef::needsNewGenID() {
139 fGenerationID = 0; 141 fGenerationID = 0;
140 fUniqueGenerationID = false; 142 fUniqueGenerationID = false;
141 } 143 }
142 144
143 void SkPixelRef::cloneGenID(const SkPixelRef& that) { 145 void SkPixelRef::cloneGenID(const SkPixelRef& that) {
144 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0. 146 // This is subtle. We must call that.getGenerationID() to make sure its gen ID isn't 0.
145 this->fGenerationID = that.getGenerationID(); 147 this->fGenerationID = that.getGenerationID();
146 this->fUniqueGenerationID = false; 148 this->fUniqueGenerationID = false;
147 that.fUniqueGenerationID = false; 149 that.fUniqueGenerationID = false;
148 } 150 }
149 151
150 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) { 152 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl e) {
151 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED 153 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED
152 // only call me in your constructor, otherwise fLockCount tracking can get 154 // only call me in your constructor, otherwise fLockCount tracking can get
153 // out of sync. 155 // out of sync.
154 fRec.fPixels = pixels; 156 fRec.fPixels = pixels;
155 fRec.fColorTable = ctable; 157 fRec.fColorTable = ctable;
156 fRec.fRowBytes = rowBytes; 158 fRec.fRowBytes = rowBytes;
157 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; 159 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT;
158 fPreLocked = true; 160 fPreLocked = true;
159 #endif 161 #endif
160 } 162 }
161 163
162 void SkPixelRef::flatten(SkWriteBuffer& buffer) const {
163 this->INHERITED::flatten(buffer);
164 fInfo.flatten(buffer);
165 buffer.writeBool(fIsImmutable);
166 // We write the gen ID into the picture for within-process recording. This
167 // is safe since the same genID will never refer to two different sets of
168 // pixels (barring overflow). However, each process has its own "namespace"
169 // of genIDs. So for cross-process recording we write a zero which will
170 // trigger assignment of a new genID in playback.
171 if (buffer.isCrossProcess()) {
172 buffer.writeUInt(0);
173 } else {
174 buffer.writeUInt(fGenerationID);
175 fUniqueGenerationID = false; // Conservative, a copy is probably about to exist.
176 }
177 }
178
179 bool SkPixelRef::lockPixels(LockRec* rec) { 164 bool SkPixelRef::lockPixels(LockRec* rec) {
180 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 165 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
181 166
182 if (!fPreLocked) { 167 if (!fPreLocked) {
183 SkAutoMutexAcquire ac(*fMutex); 168 SkAutoMutexAcquire ac(*fMutex);
184 169
185 if (1 == ++fLockCount) { 170 if (1 == ++fLockCount) {
186 SkASSERT(fRec.isZero()); 171 SkASSERT(fRec.isZero());
187 172
188 LockRec rec; 173 LockRec rec;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 288
304 #ifdef SK_BUILD_FOR_ANDROID 289 #ifdef SK_BUILD_FOR_ANDROID
305 void SkPixelRef::globalRef(void* data) { 290 void SkPixelRef::globalRef(void* data) {
306 this->ref(); 291 this->ref();
307 } 292 }
308 293
309 void SkPixelRef::globalUnref() { 294 void SkPixelRef::globalUnref() {
310 this->unref(); 295 this->unref();
311 } 296 }
312 #endif 297 #endif
OLDNEW
« no previous file with comments | « src/core/SkMallocPixelRef.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698