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

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

Issue 729463002: Cache blur mask for rects which can not break into nine-patch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: handle clipped path 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
21 struct RRectBlurKey : public SkResourceCache::Key { 43 struct RRectBlurKey : public SkResourceCache::Key {
22 public: 44 public:
23 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality) 45 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality)
24 : fSigma(sigma) 46 : fSigma(sigma)
25 , fStyle(style) 47 , fStyle(style)
26 , fQuality(quality) 48 , fQuality(quality)
27 , fRRect(rrect) 49 , fRRect(rrect)
28 { 50 {
29 this->init(&gRRectBlurKeyNamespaceLabel, 51 this->init(&gRRectBlurKeyNamespaceLabel,
30 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f RRect)); 52 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f RRect));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return result.fData; 105 return result.fData;
84 } 106 }
85 107
86 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 108 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
87 const SkRRect& rrect, const SkMask& mask, SkCachedData* da ta, 109 const SkRRect& rrect, const SkMask& mask, SkCachedData* da ta,
88 SkResourceCache* localCache) { 110 SkResourceCache* localCache) {
89 RRectBlurKey key(sigma, rrect, style, quality); 111 RRectBlurKey key(sigma, rrect, style, quality);
90 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RRectBlurRec, (key, mask , data))); 112 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RRectBlurRec, (key, mask , data)));
91 } 113 }
92 114
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
93 //////////////////////////////////////////////////////////////////////////////// ////////// 129 //////////////////////////////////////////////////////////////////////////////// //////////
94 130
95 namespace { 131 namespace {
96 static unsigned gRectsBlurKeyNamespaceLabel; 132 static unsigned gRectsBlurKeyNamespaceLabel;
97 133
98 struct RectsBlurKey : public SkResourceCache::Key { 134 struct RectsBlurKey : public SkResourceCache::Key {
99 public: 135 public:
100 RectsBlurKey(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 136 RectsBlurKey(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
101 const SkRect rects[], int count) 137 const SkRect rects[], int count)
102 : fSigma(sigma) 138 : fSigma(sigma)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 mask->fImage = (uint8_t*)(result.fData->data()); 210 mask->fImage = (uint8_t*)(result.fData->data());
175 return result.fData; 211 return result.fData;
176 } 212 }
177 213
178 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, 214 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
179 const SkRect rects[], int count, const SkMask& mask, SkCac hedData* data, 215 const SkRect rects[], int count, const SkMask& mask, SkCac hedData* data,
180 SkResourceCache* localCache) { 216 SkResourceCache* localCache) {
181 RectsBlurKey key(sigma, style, quality, rects, count); 217 RectsBlurKey key(sigma, style, quality, rects, count);
182 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data))); 218 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data)));
183 } 219 }
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