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 "SkPixelRef.h" | 8 #include "SkPixelRef.h" |
9 #include "SkThread.h" | 9 #include "SkThread.h" |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void SkPixelRef::setMutex(SkBaseMutex* mutex) { | 74 void SkPixelRef::setMutex(SkBaseMutex* mutex) { |
75 if (NULL == mutex) { | 75 if (NULL == mutex) { |
76 mutex = get_default_mutex(); | 76 mutex = get_default_mutex(); |
77 } | 77 } |
78 fMutex = mutex; | 78 fMutex = mutex; |
79 } | 79 } |
80 | 80 |
81 // just need a > 0 value, so pick a funny one to aid in debugging | 81 // just need a > 0 value, so pick a funny one to aid in debugging |
82 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 | 82 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 |
83 | 83 |
84 SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { | 84 static SkImageInfo validate_info(const SkImageInfo& info) { |
85 SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaTy
pe(), | 85 SkAlphaType newAlphaType = info.alphaType(); |
86 const_cast<SkAlphaType*>(&fInfo.
fAlphaType))); | 86 SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType
(), &newAlphaType)); |
| 87 return info.makeAlphaType(newAlphaType); |
| 88 } |
87 | 89 |
| 90 SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(validate_info(info)) { |
88 this->setMutex(NULL); | 91 this->setMutex(NULL); |
89 fRec.zero(); | 92 fRec.zero(); |
90 fLockCount = 0; | 93 fLockCount = 0; |
91 this->needsNewGenID(); | 94 this->needsNewGenID(); |
92 fIsImmutable = false; | 95 fIsImmutable = false; |
93 fPreLocked = false; | 96 fPreLocked = false; |
94 } | 97 } |
95 | 98 |
96 | 99 |
97 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info
) { | 100 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(vali
date_info(info)) { |
98 SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaTy
pe(), | |
99 const_cast<SkAlphaType*>(&fInfo.
fAlphaType))); | |
100 | |
101 this->setMutex(mutex); | 101 this->setMutex(mutex); |
102 fRec.zero(); | 102 fRec.zero(); |
103 fLockCount = 0; | 103 fLockCount = 0; |
104 this->needsNewGenID(); | 104 this->needsNewGenID(); |
105 fIsImmutable = false; | 105 fIsImmutable = false; |
106 fPreLocked = false; | 106 fPreLocked = false; |
107 } | 107 } |
108 | 108 |
109 SkPixelRef::~SkPixelRef() { | 109 SkPixelRef::~SkPixelRef() { |
110 this->callGenIDChangeListeners(); | 110 this->callGenIDChangeListeners(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 #ifdef SK_DEBUG | 227 #ifdef SK_DEBUG |
228 if (fIsImmutable) { | 228 if (fIsImmutable) { |
229 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); | 229 SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); |
230 } | 230 } |
231 #endif | 231 #endif |
232 this->callGenIDChangeListeners(); | 232 this->callGenIDChangeListeners(); |
233 this->needsNewGenID(); | 233 this->needsNewGenID(); |
234 } | 234 } |
235 | 235 |
236 void SkPixelRef::changeAlphaType(SkAlphaType at) { | 236 void SkPixelRef::changeAlphaType(SkAlphaType at) { |
237 *const_cast<SkAlphaType*>(&fInfo.fAlphaType) = at; | 237 *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeAlphaType(at); |
238 } | 238 } |
239 | 239 |
240 void SkPixelRef::setImmutable() { | 240 void SkPixelRef::setImmutable() { |
241 fIsImmutable = true; | 241 fIsImmutable = true; |
242 } | 242 } |
243 | 243 |
244 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { | 244 bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { |
245 return this->onReadPixels(dst, subset); | 245 return this->onReadPixels(dst, subset); |
246 } | 246 } |
247 | 247 |
(...skipping 17 matching lines...) Expand all Loading... |
265 | 265 |
266 #ifdef SK_BUILD_FOR_ANDROID | 266 #ifdef SK_BUILD_FOR_ANDROID |
267 void SkPixelRef::globalRef(void* data) { | 267 void SkPixelRef::globalRef(void* data) { |
268 this->ref(); | 268 this->ref(); |
269 } | 269 } |
270 | 270 |
271 void SkPixelRef::globalUnref() { | 271 void SkPixelRef::globalUnref() { |
272 this->unref(); | 272 this->unref(); |
273 } | 273 } |
274 #endif | 274 #endif |
OLD | NEW |