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 void* SkImageRef_ashmem::onLockPixels(SkColorTable** ct) { | 162 bool SkImageRef_ashmem::onNewLockPixels(LockRec* rec) { |
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 null result for failure | 188 return false; |
189 if (ct) { | |
190 *ct = NULL; | |
191 } | |
192 return NULL; | |
193 } | 189 } |
194 } else { | 190 } else { |
195 // no FD, will create an ashmem region in allocator | 191 // no FD, will create an ashmem region in allocator |
196 } | 192 } |
197 | 193 |
198 return this->INHERITED::onLockPixels(ct); | 194 return this->INHERITED::onNewLockPixels(rec); |
199 } | 195 } |
200 | 196 |
201 void SkImageRef_ashmem::onUnlockPixels() { | 197 void SkImageRef_ashmem::onUnlockPixels() { |
202 this->INHERITED::onUnlockPixels(); | 198 this->INHERITED::onUnlockPixels(); |
203 | 199 |
204 if (-1 != fRec.fFD) { | 200 if (-1 != fRec.fFD) { |
205 SkASSERT(fRec.fAddr); | 201 SkASSERT(fRec.fAddr); |
206 SkASSERT(fRec.fPinned); | 202 SkASSERT(fRec.fPinned); |
207 | 203 |
208 ashmem_unpin_region(fRec.fFD, 0, 0); | 204 ashmem_unpin_region(fRec.fFD, 0, 0); |
(...skipping 15 matching lines...) Expand all Loading... |
224 fRec.fFD = -1; | 220 fRec.fFD = -1; |
225 fRec.fAddr = NULL; | 221 fRec.fAddr = NULL; |
226 fRec.fSize = 0; | 222 fRec.fSize = 0; |
227 fRec.fPinned = false; | 223 fRec.fPinned = false; |
228 fCT = NULL; | 224 fCT = NULL; |
229 | 225 |
230 SkString uri; | 226 SkString uri; |
231 buffer.readString(&uri); | 227 buffer.readString(&uri); |
232 this->setURI(uri); | 228 this->setURI(uri); |
233 } | 229 } |
OLD | NEW |