Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: src/core/SkMaskCache.cpp

Issue 844673002: Revert of Cache blur mask for rects which can not break into nine-patch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkMaskCache.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, ...) \
11 ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::global Name(__VA_ARGS__)) 11 ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::global Name(__VA_ARGS__))
12 12
13 struct MaskValue { 13 struct MaskValue {
14 SkMask fMask; 14 SkMask fMask;
15 SkCachedData* fData; 15 SkCachedData* fData;
16 }; 16 };
17 17
18 namespace { 18 namespace {
19 static unsigned gRRectBlurKeyNamespaceLabel; 19 static unsigned gRRectBlurKeyNamespaceLabel;
20 20
21 static bool copy_cacheddata_to_mask(SkCachedData* data, SkMask* mask) {
22 const size_t size = data->size();
23 SkASSERT(mask->computeTotalImageSize() <= size);
24
25 mask->fImage = SkMask::AllocImage(size);
26 if (mask->fImage) {
27 memcpy(mask->fImage, data->data(), size);
28 return true;
29 }
30 return false;
31 }
32
33 static SkCachedData* copy_mask_to_cacheddata(const SkMask& mask) {
34 const size_t size = mask.computeTotalImageSize();
35 SkCachedData* data = SkResourceCache::NewCachedData(size);
36 if (data) {
37 memcpy(data->writable_data(), mask.fImage, size);
38 return data;
39 }
40 return NULL;
41 }
42
43 struct RRectBlurKey : public SkResourceCache::Key { 21 struct RRectBlurKey : public SkResourceCache::Key {
44 public: 22 public:
45 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality) 23 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality)
46 : fSigma(sigma) 24 : fSigma(sigma)
47 , fStyle(style) 25 , fStyle(style)
48 , fQuality(quality) 26 , fQuality(quality)
49 , fRRect(rrect) 27 , fRRect(rrect)
50 { 28 {
51 this->init(&gRRectBlurKeyNamespaceLabel, 29 this->init(&gRRectBlurKeyNamespaceLabel,
52 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f RRect)); 30 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f RRect));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return result.fData; 83 return result.fData;
106 } 84 }
107 85
108 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 86 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
109 const SkRRect& rrect, const SkMask& mask, SkCachedData* da ta, 87 const SkRRect& rrect, const SkMask& mask, SkCachedData* da ta,
110 SkResourceCache* localCache) { 88 SkResourceCache* localCache) {
111 RRectBlurKey key(sigma, rrect, style, quality); 89 RRectBlurKey key(sigma, rrect, style, quality);
112 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RRectBlurRec, (key, mask , data))); 90 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RRectBlurRec, (key, mask , data)));
113 } 91 }
114 92
115 bool SkMaskCache::FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality q uality,
116 const SkRRect& rrect, SkMask* mask) {
117 SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, qualit y, rrect, mask));
118 return data.get() && copy_cacheddata_to_mask(data, mask);
119 }
120
121 void SkMaskCache::AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality qu ality,
122 const SkRRect& rrect, const SkMask& mask) {
123 SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask));
124 if (data.get()) {
125 SkMaskCache::Add(sigma, style, quality, rrect, mask, data);
126 }
127 }
128
129 //////////////////////////////////////////////////////////////////////////////// ////////// 93 //////////////////////////////////////////////////////////////////////////////// //////////
130 94
131 namespace { 95 namespace {
132 static unsigned gRectsBlurKeyNamespaceLabel; 96 static unsigned gRectsBlurKeyNamespaceLabel;
133 97
134 struct RectsBlurKey : public SkResourceCache::Key { 98 struct RectsBlurKey : public SkResourceCache::Key {
135 public: 99 public:
136 RectsBlurKey(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 100 RectsBlurKey(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
137 const SkRect rects[], int count) 101 const SkRect rects[], int count)
138 : fSigma(sigma) 102 : fSigma(sigma)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 mask->fImage = (uint8_t*)(result.fData->data()); 174 mask->fImage = (uint8_t*)(result.fData->data());
211 return result.fData; 175 return result.fData;
212 } 176 }
213 177
214 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 178 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
215 const SkRect rects[], int count, const SkMask& mask, SkCac hedData* data, 179 const SkRect rects[], int count, const SkMask& mask, SkCac hedData* data,
216 SkResourceCache* localCache) { 180 SkResourceCache* localCache) {
217 RectsBlurKey key(sigma, style, quality, rects, count); 181 RectsBlurKey key(sigma, style, quality, rects, count);
218 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data))); 182 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data)));
219 } 183 }
220
221 bool SkMaskCache::FindAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality q uality,
222 const SkRect rects[], int count, SkMask* mask) {
223 SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, qualit y, rects, count, mask));
224 return data.get() && copy_cacheddata_to_mask(data, mask);
225 }
226
227 void SkMaskCache::AddAndCopy(SkScalar sigma, SkBlurStyle style, SkBlurQuality qu ality,
228 const SkRect rects[], int count, const SkMask& mask ) {
229 SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask));
230 if (data.get()) {
231 SkMaskCache::Add(sigma, style, quality, rects, count, mask, data);
232 }
233 }
OLDNEW
« no previous file with comments | « src/core/SkMaskCache.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698