OLD | NEW |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 fMutex = mutex; | 82 fMutex = mutex; |
83 } | 83 } |
84 | 84 |
85 // just need a > 0 value, so pick a funny one to aid in debugging | 85 // just need a > 0 value, so pick a funny one to aid in debugging |
86 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 | 86 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 |
87 | 87 |
88 SkPixelRef::SkPixelRef(SkBaseMutex* mutex) { | 88 SkPixelRef::SkPixelRef(SkBaseMutex* mutex) { |
89 this->setMutex(mutex); | 89 this->setMutex(mutex); |
90 fPixels = NULL; | 90 fPixels = NULL; |
91 fColorTable = NULL; // we do not track ownership of this | 91 fColorTable = NULL; // we do not track ownership of this |
| 92 fRowBytes = 0; |
92 fLockCount = 0; | 93 fLockCount = 0; |
93 this->needsNewGenID(); | 94 this->needsNewGenID(); |
94 fIsImmutable = false; | 95 fIsImmutable = false; |
95 fPreLocked = false; | 96 fPreLocked = false; |
96 } | 97 } |
97 | 98 |
98 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) | 99 SkPixelRef::SkPixelRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) |
99 : INHERITED(buffer) { | 100 : INHERITED(buffer) { |
100 this->setMutex(mutex); | 101 this->setMutex(mutex); |
101 fPixels = NULL; | 102 fPixels = NULL; |
102 fColorTable = NULL; // we do not track ownership of this | 103 fColorTable = NULL; // we do not track ownership of this |
| 104 fRowBytes = 0; |
103 fLockCount = 0; | 105 fLockCount = 0; |
104 fIsImmutable = buffer.readBool(); | 106 fIsImmutable = buffer.readBool(); |
105 fGenerationID = buffer.readUInt(); | 107 fGenerationID = buffer.readUInt(); |
106 fUniqueGenerationID = false; // Conservatively assuming the original still
exists. | 108 fUniqueGenerationID = false; // Conservatively assuming the original still
exists. |
107 fPreLocked = false; | 109 fPreLocked = false; |
108 } | 110 } |
109 | 111 |
110 SkPixelRef::~SkPixelRef() { | 112 SkPixelRef::~SkPixelRef() { |
111 this->callGenIDChangeListeners(); | 113 this->callGenIDChangeListeners(); |
112 } | 114 } |
113 | 115 |
114 void SkPixelRef::needsNewGenID() { | 116 void SkPixelRef::needsNewGenID() { |
115 fGenerationID = 0; | 117 fGenerationID = 0; |
116 fUniqueGenerationID = false; | 118 fUniqueGenerationID = false; |
117 } | 119 } |
118 | 120 |
119 void SkPixelRef::cloneGenID(const SkPixelRef& that) { | 121 void SkPixelRef::cloneGenID(const SkPixelRef& that) { |
120 // This is subtle. We must call that.getGenerationID() to make sure its gen
ID isn't 0. | 122 // This is subtle. We must call that.getGenerationID() to make sure its gen
ID isn't 0. |
121 this->fGenerationID = that.getGenerationID(); | 123 this->fGenerationID = that.getGenerationID(); |
122 this->fUniqueGenerationID = false; | 124 this->fUniqueGenerationID = false; |
123 that.fUniqueGenerationID = false; | 125 that.fUniqueGenerationID = false; |
124 } | 126 } |
125 | 127 |
126 void SkPixelRef::setPreLocked(void* pixels, SkColorTable* ctable) { | 128 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl
e) { |
127 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED | 129 #ifndef SK_IGNORE_PIXELREF_SETPRELOCKED |
128 // only call me in your constructor, otherwise fLockCount tracking can get | 130 // only call me in your constructor, otherwise fLockCount tracking can get |
129 // out of sync. | 131 // out of sync. |
130 fPixels = pixels; | 132 fPixels = pixels; |
131 fColorTable = ctable; | 133 fColorTable = ctable; |
| 134 fRowBytes = rowBytes; |
132 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; | 135 fLockCount = SKPIXELREF_PRELOCKED_LOCKCOUNT; |
133 fPreLocked = true; | 136 fPreLocked = true; |
134 #endif | 137 #endif |
135 } | 138 } |
136 | 139 |
137 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { | 140 void SkPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
138 this->INHERITED::flatten(buffer); | 141 this->INHERITED::flatten(buffer); |
139 buffer.writeBool(fIsImmutable); | 142 buffer.writeBool(fIsImmutable); |
140 // We write the gen ID into the picture for within-process recording. This | 143 // We write the gen ID into the picture for within-process recording. This |
141 // is safe since the same genID will never refer to two different sets of | 144 // is safe since the same genID will never refer to two different sets of |
142 // pixels (barring overflow). However, each process has its own "namespace" | 145 // pixels (barring overflow). However, each process has its own "namespace" |
143 // of genIDs. So for cross-process recording we write a zero which will | 146 // of genIDs. So for cross-process recording we write a zero which will |
144 // trigger assignment of a new genID in playback. | 147 // trigger assignment of a new genID in playback. |
145 if (buffer.isCrossProcess()) { | 148 if (buffer.isCrossProcess()) { |
146 buffer.writeUInt(0); | 149 buffer.writeUInt(0); |
147 } else { | 150 } else { |
148 buffer.writeUInt(fGenerationID); | 151 buffer.writeUInt(fGenerationID); |
149 fUniqueGenerationID = false; // Conservative, a copy is probably about
to exist. | 152 fUniqueGenerationID = false; // Conservative, a copy is probably about
to exist. |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
153 void SkPixelRef::lockPixels() { | 156 void SkPixelRef::lockPixels() { |
154 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); | 157 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
155 | 158 |
156 if (!fPreLocked) { | 159 if (!fPreLocked) { |
157 SkAutoMutexAcquire ac(*fMutex); | 160 SkAutoMutexAcquire ac(*fMutex); |
158 | 161 |
159 if (1 == ++fLockCount) { | 162 if (1 == ++fLockCount) { |
160 fPixels = this->onLockPixels(&fColorTable); | 163 SkImageInfo info; |
| 164 fPixels = this->onLockPixels(&info, &fRowBytes, &fColorTable); |
161 } | 165 } |
162 } | 166 } |
163 } | 167 } |
164 | 168 |
165 void SkPixelRef::unlockPixels() { | 169 void SkPixelRef::unlockPixels() { |
166 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); | 170 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
167 | 171 |
168 if (!fPreLocked) { | 172 if (!fPreLocked) { |
169 SkAutoMutexAcquire ac(*fMutex); | 173 SkAutoMutexAcquire ac(*fMutex); |
170 | 174 |
171 SkASSERT(fLockCount > 0); | 175 SkASSERT(fLockCount > 0); |
172 if (0 == --fLockCount) { | 176 if (0 == --fLockCount) { |
173 this->onUnlockPixels(); | 177 this->onUnlockPixels(); |
174 fPixels = NULL; | 178 fPixels = NULL; |
175 fColorTable = NULL; | 179 fColorTable = NULL; |
| 180 fRowBytes = 0; |
176 } | 181 } |
177 } | 182 } |
178 } | 183 } |
179 | 184 |
180 bool SkPixelRef::lockPixelsAreWritable() const { | 185 bool SkPixelRef::lockPixelsAreWritable() const { |
181 return this->onLockPixelsAreWritable(); | 186 return this->onLockPixelsAreWritable(); |
182 } | 187 } |
183 | 188 |
184 bool SkPixelRef::onLockPixelsAreWritable() const { | 189 bool SkPixelRef::onLockPixelsAreWritable() const { |
185 return true; | 190 return true; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 256 |
252 #ifdef SK_BUILD_FOR_ANDROID | 257 #ifdef SK_BUILD_FOR_ANDROID |
253 void SkPixelRef::globalRef(void* data) { | 258 void SkPixelRef::globalRef(void* data) { |
254 this->ref(); | 259 this->ref(); |
255 } | 260 } |
256 | 261 |
257 void SkPixelRef::globalUnref() { | 262 void SkPixelRef::globalUnref() { |
258 this->unref(); | 263 this->unref(); |
259 } | 264 } |
260 #endif | 265 #endif |
OLD | NEW |