OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkMaskCache.h" | 8 #include "SkMaskCache.h" |
9 | 9 |
10 #define CHECK_LOCAL(localCache, localName, globalName, ...) \ | 10 #define CHECK_LOCAL(localCache, localName, globalName, ...) \ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { | 57 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { |
58 return fValue.fData->diagnostic_only_getDiscardable(); | 58 return fValue.fData->diagnostic_only_getDiscardable(); |
59 } | 59 } |
60 | 60 |
61 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextData)
{ | 61 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextData)
{ |
62 const RRectBlurRec& rec = static_cast<const RRectBlurRec&>(baseRec); | 62 const RRectBlurRec& rec = static_cast<const RRectBlurRec&>(baseRec); |
63 MaskValue* result = (MaskValue*)contextData; | 63 MaskValue* result = (MaskValue*)contextData; |
64 | 64 |
65 SkCachedData* tmpData = rec.fValue.fData; | 65 SkCachedData* tmpData = rec.fValue.fData; |
66 tmpData->ref(); | 66 tmpData->ref(); |
67 if (NULL == tmpData->data()) { | 67 if (nullptr == tmpData->data()) { |
68 tmpData->unref(); | 68 tmpData->unref(); |
69 return false; | 69 return false; |
70 } | 70 } |
71 *result = rec.fValue; | 71 *result = rec.fValue; |
72 return true; | 72 return true; |
73 } | 73 } |
74 }; | 74 }; |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ
uality quality, | 77 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ
uality quality, |
78 const SkRRect& rrect, SkMask* mask, SkResource
Cache* localCache) { | 78 const SkRRect& rrect, SkMask* mask, SkResource
Cache* localCache) { |
79 MaskValue result; | 79 MaskValue result; |
80 RRectBlurKey key(sigma, rrect, style, quality); | 80 RRectBlurKey key(sigma, rrect, style, quality); |
81 if (!CHECK_LOCAL(localCache, find, Find, key, RRectBlurRec::Visitor, &result
)) { | 81 if (!CHECK_LOCAL(localCache, find, Find, key, RRectBlurRec::Visitor, &result
)) { |
82 return NULL; | 82 return nullptr; |
83 } | 83 } |
84 | 84 |
85 *mask = result.fMask; | 85 *mask = result.fMask; |
86 mask->fImage = (uint8_t*)(result.fData->data()); | 86 mask->fImage = (uint8_t*)(result.fData->data()); |
87 return result.fData; | 87 return result.fData; |
88 } | 88 } |
89 | 89 |
90 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, | 90 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, |
91 const SkRRect& rrect, const SkMask& mask, SkCachedData* da
ta, | 91 const SkRRect& rrect, const SkMask& mask, SkCachedData* da
ta, |
92 SkResourceCache* localCache) { | 92 SkResourceCache* localCache) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { | 152 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { |
153 return fValue.fData->diagnostic_only_getDiscardable(); | 153 return fValue.fData->diagnostic_only_getDiscardable(); |
154 } | 154 } |
155 | 155 |
156 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextData)
{ | 156 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextData)
{ |
157 const RectsBlurRec& rec = static_cast<const RectsBlurRec&>(baseRec); | 157 const RectsBlurRec& rec = static_cast<const RectsBlurRec&>(baseRec); |
158 MaskValue* result = static_cast<MaskValue*>(contextData); | 158 MaskValue* result = static_cast<MaskValue*>(contextData); |
159 | 159 |
160 SkCachedData* tmpData = rec.fValue.fData; | 160 SkCachedData* tmpData = rec.fValue.fData; |
161 tmpData->ref(); | 161 tmpData->ref(); |
162 if (NULL == tmpData->data()) { | 162 if (nullptr == tmpData->data()) { |
163 tmpData->unref(); | 163 tmpData->unref(); |
164 return false; | 164 return false; |
165 } | 165 } |
166 *result = rec.fValue; | 166 *result = rec.fValue; |
167 return true; | 167 return true; |
168 } | 168 } |
169 }; | 169 }; |
170 } // namespace | 170 } // namespace |
171 | 171 |
172 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ
uality quality, | 172 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ
uality quality, |
173 const SkRect rects[], int count, SkMask* m
ask, | 173 const SkRect rects[], int count, SkMask* m
ask, |
174 SkResourceCache* localCache) { | 174 SkResourceCache* localCache) { |
175 MaskValue result; | 175 MaskValue result; |
176 RectsBlurKey key(sigma, style, quality, rects, count); | 176 RectsBlurKey key(sigma, style, quality, rects, count); |
177 if (!CHECK_LOCAL(localCache, find, Find, key, RectsBlurRec::Visitor, &result
)) { | 177 if (!CHECK_LOCAL(localCache, find, Find, key, RectsBlurRec::Visitor, &result
)) { |
178 return NULL; | 178 return nullptr; |
179 } | 179 } |
180 | 180 |
181 *mask = result.fMask; | 181 *mask = result.fMask; |
182 mask->fImage = (uint8_t*)(result.fData->data()); | 182 mask->fImage = (uint8_t*)(result.fData->data()); |
183 return result.fData; | 183 return result.fData; |
184 } | 184 } |
185 | 185 |
186 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, | 186 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, |
187 const SkRect rects[], int count, const SkMask& mask, SkCac
hedData* data, | 187 const SkRect rects[], int count, const SkMask& mask, SkCac
hedData* data, |
188 SkResourceCache* localCache) { | 188 SkResourceCache* localCache) { |
189 RectsBlurKey key(sigma, style, quality, rects, count); | 189 RectsBlurKey key(sigma, style, quality, rects, count); |
190 return CHECK_LOCAL(localCache, add, Add, new RectsBlurRec(key, mask, data)); | 190 return CHECK_LOCAL(localCache, add, Add, new RectsBlurRec(key, mask, data)); |
191 } | 191 } |
OLD | NEW |