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

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

Issue 669993003: use SkMaskCache inside SkBlurMaskFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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/effects/SkBlurMaskFilter.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 struct RRectBlurKey : public SkResourceCache::Key { 21 struct RRectBlurKey : public SkResourceCache::Key {
22 public: 22 public:
23 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality) 23 RRectBlurKey(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, SkBlur Quality quality)
24 : fSigma(sigma) 24 : fSigma(sigma)
25 , fStyle(style)
26 , fQuality(quality)
25 , fRRect(rrect) 27 , fRRect(rrect)
26 , fStyle(style) 28 {
27 , fQuality(quality) {
28 this->init(&gRRectBlurKeyNamespaceLabel, 29 this->init(&gRRectBlurKeyNamespaceLabel,
29 sizeof(fSigma) + sizeof(fRRect) + sizeof(fStyle) + sizeof(fQu ality)); 30 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f RRect));
30 } 31 }
31 32
32 SkScalar fSigma; 33 SkScalar fSigma;
33 SkRRect fRRect;
34 int32_t fStyle; 34 int32_t fStyle;
35 int32_t fQuality; 35 int32_t fQuality;
36 SkRRect fRRect;
36 }; 37 };
37 38
38 struct RRectBlurRec : public SkResourceCache::Rec { 39 struct RRectBlurRec : public SkResourceCache::Rec {
39 RRectBlurRec(RRectBlurKey key, const SkMask& mask, SkCachedData* data) 40 RRectBlurRec(RRectBlurKey key, const SkMask& mask, SkCachedData* data)
40 : fKey(key) 41 : fKey(key)
41 { 42 {
42 fValue.fMask = mask; 43 fValue.fMask = mask;
43 fValue.fData = data; 44 fValue.fData = data;
44 fValue.fData->attachToCacheAndRef(); 45 fValue.fData->attachToCacheAndRef();
45 } 46 }
(...skipping 16 matching lines...) Expand all
62 if (NULL == tmpData->data()) { 63 if (NULL == tmpData->data()) {
63 tmpData->unref(); 64 tmpData->unref();
64 return false; 65 return false;
65 } 66 }
66 *result = rec.fValue; 67 *result = rec.fValue;
67 return true; 68 return true;
68 } 69 }
69 }; 70 };
70 } // namespace 71 } // namespace
71 72
72 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, const SkRRect& rrect, SkBl urStyle style, 73 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ uality quality,
73 SkBlurQuality quality, SkMask* mask, 74 const SkRRect& rrect, SkMask* mask, SkResource Cache* localCache) {
74 SkResourceCache* localCache) {
75 MaskValue result; 75 MaskValue result;
76 RRectBlurKey key(sigma, rrect, style, quality); 76 RRectBlurKey key(sigma, rrect, style, quality);
77 if (!CHECK_LOCAL(localCache, find, Find, key, RRectBlurRec::Visitor, &result )) { 77 if (!CHECK_LOCAL(localCache, find, Find, key, RRectBlurRec::Visitor, &result )) {
78 return NULL; 78 return NULL;
79 } 79 }
80 80
81 *mask = result.fMask; 81 *mask = result.fMask;
82 mask->fImage = (uint8_t*)(result.fData->data()); 82 mask->fImage = (uint8_t*)(result.fData->data());
83 return result.fData; 83 return result.fData;
84 } 84 }
85 85
86 void SkMaskCache::Add(SkScalar sigma, const SkRRect& rrect, SkBlurStyle style, 86 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
87 SkBlurQuality quality, const SkMask& mask, SkCachedData* d ata, 87 const SkRRect& rrect, const SkMask& mask, SkCachedData* da ta,
88 SkResourceCache* localCache) { 88 SkResourceCache* localCache) {
89 RRectBlurKey key(sigma, rrect, style, quality); 89 RRectBlurKey key(sigma, rrect, style, quality);
90 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)));
91 } 91 }
92 92
93 //////////////////////////////////////////////////////////////////////////////// ////////// 93 //////////////////////////////////////////////////////////////////////////////// //////////
94 94
95 namespace { 95 namespace {
96 static unsigned gRectsBlurKeyNamespaceLabel; 96 static unsigned gRectsBlurKeyNamespaceLabel;
97 97
98 struct RectsBlurKey : public SkResourceCache::Key { 98 struct RectsBlurKey : public SkResourceCache::Key {
99 public: 99 public:
100 RectsBlurKey(SkScalar sigma, int count, const SkRect rects[], SkBlurStyle st yle) 100 RectsBlurKey(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
101 const SkRect rects[], int count)
101 : fSigma(sigma) 102 : fSigma(sigma)
102 , fRecCount(count) 103 , fStyle(style)
103 , fStyle(style){ 104 , fQuality(quality)
105 {
104 SkASSERT(1 == count || 2 == count); 106 SkASSERT(1 == count || 2 == count);
105 fRects[0] = SkRect::MakeEmpty(); 107 fRects[0] = SkRect::MakeEmpty();
106 fRects[1] = SkRect::MakeEmpty(); 108 fRects[1] = SkRect::MakeEmpty();
107 for (int i = 0; i < count; i++) { 109 for (int i = 0; i < count; i++) {
108 fRects[i] = rects[i]; 110 fRects[i] = rects[i];
109 } 111 }
110 this->init(&gRectsBlurKeyNamespaceLabel, 112 this->init(&gRectsBlurKeyNamespaceLabel,
111 sizeof(fSigma) + sizeof(fRecCount) + sizeof(fRects) + sizeof( fStyle)); 113 sizeof(fSigma) + sizeof(fStyle) + sizeof(fQuality) + sizeof(f Rects));
112 } 114 }
113 115
114 SkScalar fSigma; 116 SkScalar fSigma;
115 int fRecCount; 117 int32_t fStyle;
118 int32_t fQuality;
116 SkRect fRects[2]; 119 SkRect fRects[2];
117 int32_t fStyle;
118 }; 120 };
119 121
120 struct RectsBlurRec : public SkResourceCache::Rec { 122 struct RectsBlurRec : public SkResourceCache::Rec {
121 RectsBlurRec(RectsBlurKey key, const SkMask& mask, SkCachedData* data) 123 RectsBlurRec(RectsBlurKey key, const SkMask& mask, SkCachedData* data)
122 : fKey(key) 124 : fKey(key)
123 { 125 {
124 fValue.fMask = mask; 126 fValue.fMask = mask;
125 fValue.fData = data; 127 fValue.fData = data;
126 fValue.fData->attachToCacheAndRef(); 128 fValue.fData->attachToCacheAndRef();
127 } 129 }
(...skipping 16 matching lines...) Expand all
144 if (NULL == tmpData->data()) { 146 if (NULL == tmpData->data()) {
145 tmpData->unref(); 147 tmpData->unref();
146 return false; 148 return false;
147 } 149 }
148 *result = rec.fValue; 150 *result = rec.fValue;
149 return true; 151 return true;
150 } 152 }
151 }; 153 };
152 } // namespace 154 } // namespace
153 155
154 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, const SkRect rects[], int count, 156 SkCachedData* SkMaskCache::FindAndRef(SkScalar sigma, SkBlurStyle style, SkBlurQ uality quality,
155 SkBlurStyle style, SkMask* mask, 157 const SkRect rects[], int count, SkMask* m ask,
156 SkResourceCache* localCache) { 158 SkResourceCache* localCache) {
157 MaskValue result; 159 MaskValue result;
158 RectsBlurKey key(sigma, count, rects, style); 160 RectsBlurKey key(sigma, style, quality, rects, count);
159 if (!CHECK_LOCAL(localCache, find, Find, key, RectsBlurRec::Visitor, &result )) { 161 if (!CHECK_LOCAL(localCache, find, Find, key, RectsBlurRec::Visitor, &result )) {
160 return NULL; 162 return NULL;
161 } 163 }
162 164
163 *mask = result.fMask; 165 *mask = result.fMask;
164 mask->fImage = (uint8_t*)(result.fData->data()); 166 mask->fImage = (uint8_t*)(result.fData->data());
165 return result.fData; 167 return result.fData;
166 } 168 }
167 169
168 void SkMaskCache::Add(SkScalar sigma, const SkRect rects[], int count, SkBlurSty le style, 170 void SkMaskCache::Add(SkScalar sigma, SkBlurStyle style, SkBlurQuality quality,
169 const SkMask& mask, SkCachedData* data, 171 const SkRect rects[], int count, const SkMask& mask, SkCac hedData* data,
170 SkResourceCache* localCache) { 172 SkResourceCache* localCache) {
171 RectsBlurKey key(sigma, count, rects, style); 173 RectsBlurKey key(sigma, style, quality, rects, count);
172 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data))); 174 return CHECK_LOCAL(localCache, add, Add, SkNEW_ARGS(RectsBlurRec, (key, mask , data)));
173 } 175 }
OLDNEW
« no previous file with comments | « src/core/SkMaskCache.h ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698