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 "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (NULL == mutex) { | 77 if (NULL == mutex) { |
78 mutex = get_default_mutex(); | 78 mutex = get_default_mutex(); |
79 } | 79 } |
80 fMutex = mutex; | 80 fMutex = mutex; |
81 } | 81 } |
82 | 82 |
83 // just need a > 0 value, so pick a funny one to aid in debugging | 83 // just need a > 0 value, so pick a funny one to aid in debugging |
84 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 | 84 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 |
85 | 85 |
86 SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { | 86 SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { |
| 87 SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaTy
pe(), |
| 88 const_cast<SkAlphaType*>(&fInfo.
fAlphaType))); |
| 89 |
87 this->setMutex(NULL); | 90 this->setMutex(NULL); |
88 fRec.zero(); | 91 fRec.zero(); |
89 fLockCount = 0; | 92 fLockCount = 0; |
90 this->needsNewGenID(); | 93 this->needsNewGenID(); |
91 fIsImmutable = false; | 94 fIsImmutable = false; |
92 fPreLocked = false; | 95 fPreLocked = false; |
93 } | 96 } |
94 | 97 |
95 | 98 |
96 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info
) { | 99 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info
) { |
| 100 SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaTy
pe(), |
| 101 const_cast<SkAlphaType*>(&fInfo.
fAlphaType))); |
| 102 |
97 this->setMutex(mutex); | 103 this->setMutex(mutex); |
98 fRec.zero(); | 104 fRec.zero(); |
99 fLockCount = 0; | 105 fLockCount = 0; |
100 this->needsNewGenID(); | 106 this->needsNewGenID(); |
101 fIsImmutable = false; | 107 fIsImmutable = false; |
102 fPreLocked = false; | 108 fPreLocked = false; |
103 } | 109 } |
104 | 110 |
105 static SkImageInfo read_info(SkReadBuffer& buffer) { | 111 static SkImageInfo read_info(SkReadBuffer& buffer) { |
106 SkImageInfo info; | 112 SkImageInfo info; |
107 info.unflatten(buffer); | 113 info.unflatten(buffer); |
108 return info; | 114 return info; |
109 } | 115 } |
110 | 116 |
111 SkPixelRef::SkPixelRef(SkReadBuffer& buffer, SkBaseMutex* mutex) | 117 SkPixelRef::SkPixelRef(SkReadBuffer& buffer, SkBaseMutex* mutex) |
112 : INHERITED(buffer) | 118 : INHERITED(buffer) |
113 , fInfo(read_info(buffer)) | 119 , fInfo(read_info(buffer)) |
114 { | 120 { |
| 121 SkDEBUGCODE(SkAlphaType alphaType;) |
| 122 SkASSERT(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaType(),
&alphaType)); |
| 123 SkASSERT(fInfo.fAlphaType == alphaType); |
| 124 |
115 this->setMutex(mutex); | 125 this->setMutex(mutex); |
116 fRec.zero(); | 126 fRec.zero(); |
117 fLockCount = 0; | 127 fLockCount = 0; |
118 fIsImmutable = buffer.readBool(); | 128 fIsImmutable = buffer.readBool(); |
119 fGenerationID = buffer.readUInt(); | 129 fGenerationID = buffer.readUInt(); |
120 fUniqueGenerationID = false; // Conservatively assuming the original still
exists. | 130 fUniqueGenerationID = false; // Conservatively assuming the original still
exists. |
121 fPreLocked = false; | 131 fPreLocked = false; |
122 } | 132 } |
123 | 133 |
124 SkPixelRef::~SkPixelRef() { | 134 SkPixelRef::~SkPixelRef() { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 303 |
294 #ifdef SK_BUILD_FOR_ANDROID | 304 #ifdef SK_BUILD_FOR_ANDROID |
295 void SkPixelRef::globalRef(void* data) { | 305 void SkPixelRef::globalRef(void* data) { |
296 this->ref(); | 306 this->ref(); |
297 } | 307 } |
298 | 308 |
299 void SkPixelRef::globalUnref() { | 309 void SkPixelRef::globalUnref() { |
300 this->unref(); | 310 this->unref(); |
301 } | 311 } |
302 #endif | 312 #endif |
OLD | NEW |