OLD | NEW |
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 "SkImageRef_ashmem.h" | 8 #include "SkImageRef_ashmem.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } else { | 152 } else { |
153 if (fRec.fPinned) { | 153 if (fRec.fPinned) { |
154 ashmem_unpin_region(fRec.fFD, 0, 0); | 154 ashmem_unpin_region(fRec.fFD, 0, 0); |
155 fRec.fPinned = false; | 155 fRec.fPinned = false; |
156 } | 156 } |
157 this->closeFD(); | 157 this->closeFD(); |
158 return false; | 158 return false; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 bool SkImageRef_ashmem::onNewLockPixels(LockRec* rec) { | 162 void* SkImageRef_ashmem::onLockPixels(SkColorTable** ct) { |
163 SkASSERT(fBitmap.getPixels() == NULL); | 163 SkASSERT(fBitmap.getPixels() == NULL); |
164 SkASSERT(fBitmap.getColorTable() == NULL); | 164 SkASSERT(fBitmap.getColorTable() == NULL); |
165 | 165 |
166 // fast case: check if we can just pin and get the cached data | 166 // fast case: check if we can just pin and get the cached data |
167 if (-1 != fRec.fFD) { | 167 if (-1 != fRec.fFD) { |
168 SkASSERT(fRec.fAddr); | 168 SkASSERT(fRec.fAddr); |
169 SkASSERT(!fRec.fPinned); | 169 SkASSERT(!fRec.fPinned); |
170 int pin = ashmem_pin_region(fRec.fFD, 0, 0); | 170 int pin = ashmem_pin_region(fRec.fFD, 0, 0); |
171 | 171 |
172 if (ASHMEM_NOT_PURGED == pin) { // yea, fast case! | 172 if (ASHMEM_NOT_PURGED == pin) { // yea, fast case! |
173 fBitmap.setPixels(fRec.fAddr, fCT); | 173 fBitmap.setPixels(fRec.fAddr, fCT); |
174 fRec.fPinned = true; | 174 fRec.fPinned = true; |
175 } else if (ASHMEM_WAS_PURGED == pin) { | 175 } else if (ASHMEM_WAS_PURGED == pin) { |
176 ashmem_unpin_region(fRec.fFD, 0, 0); | 176 ashmem_unpin_region(fRec.fFD, 0, 0); |
177 // let go of our colortable if we lost the pixels. Well get it back | 177 // let go of our colortable if we lost the pixels. Well get it back |
178 // again when we re-decode | 178 // again when we re-decode |
179 if (fCT) { | 179 if (fCT) { |
180 fCT->unref(); | 180 fCT->unref(); |
181 fCT = NULL; | 181 fCT = NULL; |
182 } | 182 } |
183 #if defined(DUMP_ASHMEM_LIFECYCLE) || defined(TRACE_ASH_PURGE) | 183 #if defined(DUMP_ASHMEM_LIFECYCLE) || defined(TRACE_ASH_PURGE) |
184 SkDebugf("===== ashmem purged %d\n", fBitmap.getSize()); | 184 SkDebugf("===== ashmem purged %d\n", fBitmap.getSize()); |
185 #endif | 185 #endif |
186 } else { | 186 } else { |
187 SkDebugf("===== ashmem pin_region(%d) returned %d\n", fRec.fFD, pin)
; | 187 SkDebugf("===== ashmem pin_region(%d) returned %d\n", fRec.fFD, pin)
; |
188 return false; | 188 // return null result for failure |
| 189 if (ct) { |
| 190 *ct = NULL; |
| 191 } |
| 192 return NULL; |
189 } | 193 } |
190 } else { | 194 } else { |
191 // no FD, will create an ashmem region in allocator | 195 // no FD, will create an ashmem region in allocator |
192 } | 196 } |
193 | 197 |
194 return this->INHERITED::onNewLockPixels(rec); | 198 return this->INHERITED::onLockPixels(ct); |
195 } | 199 } |
196 | 200 |
197 void SkImageRef_ashmem::onUnlockPixels() { | 201 void SkImageRef_ashmem::onUnlockPixels() { |
198 this->INHERITED::onUnlockPixels(); | 202 this->INHERITED::onUnlockPixels(); |
199 | 203 |
200 if (-1 != fRec.fFD) { | 204 if (-1 != fRec.fFD) { |
201 SkASSERT(fRec.fAddr); | 205 SkASSERT(fRec.fAddr); |
202 SkASSERT(fRec.fPinned); | 206 SkASSERT(fRec.fPinned); |
203 | 207 |
204 ashmem_unpin_region(fRec.fFD, 0, 0); | 208 ashmem_unpin_region(fRec.fFD, 0, 0); |
(...skipping 15 matching lines...) Expand all Loading... |
220 fRec.fFD = -1; | 224 fRec.fFD = -1; |
221 fRec.fAddr = NULL; | 225 fRec.fAddr = NULL; |
222 fRec.fSize = 0; | 226 fRec.fSize = 0; |
223 fRec.fPinned = false; | 227 fRec.fPinned = false; |
224 fCT = NULL; | 228 fCT = NULL; |
225 | 229 |
226 SkString uri; | 230 SkString uri; |
227 buffer.readString(&uri); | 231 buffer.readString(&uri); |
228 this->setURI(uri); | 232 this->setURI(uri); |
229 } | 233 } |
OLD | NEW |