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

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

Issue 203203003: SkPaint: eliminate some dead bytes in 64-bit build. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tighter Created 6 years, 9 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 | « include/core/SkPaint.h ('k') | tests/PaintTest.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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 8
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 #ifdef SK_BUILD_FOR_ANDROID 63 #ifdef SK_BUILD_FOR_ANDROID
64 #define GEN_ID_INC fGenerationID++ 64 #define GEN_ID_INC fGenerationID++
65 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; } 65 #define GEN_ID_INC_EVAL(expression) if (expression) { fGenerationID++; }
66 #else 66 #else
67 #define GEN_ID_INC 67 #define GEN_ID_INC
68 #define GEN_ID_INC_EVAL(expression) 68 #define GEN_ID_INC_EVAL(expression)
69 #endif 69 #endif
70 70
71 SkPaint::SkPaint() { 71 SkPaint::SkPaint() {
72 // since we may have padding, we zero everything so that our memcmp() call
73 // in operator== will work correctly.
74 // with this, we can skip 0 and null individual initializations
75 sk_bzero(this, sizeof(*this));
76
77 #if 0 // not needed with the bzero call above
78 fTypeface = NULL; 72 fTypeface = NULL;
79 fTextSkewX = 0;
80 fPathEffect = NULL; 73 fPathEffect = NULL;
81 fShader = NULL; 74 fShader = NULL;
82 fXfermode = NULL; 75 fXfermode = NULL;
83 fMaskFilter = NULL; 76 fMaskFilter = NULL;
84 fColorFilter = NULL; 77 fColorFilter = NULL;
85 fRasterizer = NULL; 78 fRasterizer = NULL;
86 fLooper = NULL; 79 fLooper = NULL;
87 fImageFilter = NULL; 80 fImageFilter = NULL;
88 fAnnotation = NULL; 81 fAnnotation = NULL;
89 fWidth = 0;
90 fDirtyBits = 0;
91 #endif
92 82
93 fTextSize = SkPaintDefaults_TextSize; 83 fTextSize = SkPaintDefaults_TextSize;
94 fTextScaleX = SK_Scalar1; 84 fTextScaleX = SK_Scalar1;
95 fColor = SK_ColorBLACK; 85 fTextSkewX = 0;
96 fMiterLimit = SkPaintDefaults_MiterLimit; 86 fColor = SK_ColorBLACK;
97 fFlags = SkPaintDefaults_Flags; 87 fWidth = 0;
98 fCapType = kDefault_Cap; 88 fMiterLimit = SkPaintDefaults_MiterLimit;
99 fJoinType = kDefault_Join; 89
100 fTextAlign = kLeft_Align; 90 // Zero all bitfields, then set some non-zero defaults.
101 fStyle = kFill_Style; 91 fBitfields = 0;
92 fFlags = SkPaintDefaults_Flags;
93 fCapType = kDefault_Cap;
94 fJoinType = kDefault_Join;
95 fTextAlign = kLeft_Align;
96 fStyle = kFill_Style;
102 fTextEncoding = kUTF8_TextEncoding; 97 fTextEncoding = kUTF8_TextEncoding;
103 fHinting = SkPaintDefaults_Hinting; 98 fHinting = SkPaintDefaults_Hinting;
99
100 fDirtyBits = 0;
104 #ifdef SK_BUILD_FOR_ANDROID 101 #ifdef SK_BUILD_FOR_ANDROID
105 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid; 102 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid;
106 fGenerationID = 0; 103 fGenerationID = 0;
107 #endif 104 #endif
108 } 105 }
109 106
110 SkPaint::SkPaint(const SkPaint& src) { 107 SkPaint::SkPaint(const SkPaint& src) {
111 memcpy(this, &src, sizeof(src)); 108 #define COPY(field) field = src.field
109 #define REF_COPY(field) field = SkSafeRef(src.field)
112 110
113 SkSafeRef(fTypeface); 111 REF_COPY(fTypeface);
114 SkSafeRef(fPathEffect); 112 REF_COPY(fPathEffect);
115 SkSafeRef(fShader); 113 REF_COPY(fShader);
116 SkSafeRef(fXfermode); 114 REF_COPY(fXfermode);
117 SkSafeRef(fMaskFilter); 115 REF_COPY(fMaskFilter);
118 SkSafeRef(fColorFilter); 116 REF_COPY(fColorFilter);
119 SkSafeRef(fRasterizer); 117 REF_COPY(fRasterizer);
120 SkSafeRef(fLooper); 118 REF_COPY(fLooper);
121 SkSafeRef(fImageFilter); 119 REF_COPY(fImageFilter);
122 SkSafeRef(fAnnotation); 120 REF_COPY(fAnnotation);
121
122 COPY(fTextSize);
123 COPY(fTextScaleX);
124 COPY(fTextSkewX);
125 COPY(fColor);
126 COPY(fWidth);
127 COPY(fMiterLimit);
128 COPY(fBitfields);
129 COPY(fDirtyBits);
123 130
124 #ifdef SK_BUILD_FOR_ANDROID 131 #ifdef SK_BUILD_FOR_ANDROID
125 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); 132 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid);
133 COPY(fGenerationID);
126 #endif 134 #endif
135
136 #undef COPY
137 #undef REF_COPY
127 } 138 }
128 139
129 SkPaint::~SkPaint() { 140 SkPaint::~SkPaint() {
130 SkSafeUnref(fTypeface); 141 SkSafeUnref(fTypeface);
131 SkSafeUnref(fPathEffect); 142 SkSafeUnref(fPathEffect);
132 SkSafeUnref(fShader); 143 SkSafeUnref(fShader);
133 SkSafeUnref(fXfermode); 144 SkSafeUnref(fXfermode);
134 SkSafeUnref(fMaskFilter); 145 SkSafeUnref(fMaskFilter);
135 SkSafeUnref(fColorFilter); 146 SkSafeUnref(fColorFilter);
136 SkSafeUnref(fRasterizer); 147 SkSafeUnref(fRasterizer);
137 SkSafeUnref(fLooper); 148 SkSafeUnref(fLooper);
138 SkSafeUnref(fImageFilter); 149 SkSafeUnref(fImageFilter);
139 SkSafeUnref(fAnnotation); 150 SkSafeUnref(fAnnotation);
140 } 151 }
141 152
142 SkPaint& SkPaint::operator=(const SkPaint& src) { 153 SkPaint& SkPaint::operator=(const SkPaint& src) {
154 #define COPY(field) field = src.field
155 #define REF_COPY(field) SkSafeUnref(field); field = SkSafeRef(src.field)
156
143 SkASSERT(&src); 157 SkASSERT(&src);
144 158
145 SkSafeRef(src.fTypeface); 159 REF_COPY(fTypeface);
146 SkSafeRef(src.fPathEffect); 160 REF_COPY(fPathEffect);
147 SkSafeRef(src.fShader); 161 REF_COPY(fShader);
148 SkSafeRef(src.fXfermode); 162 REF_COPY(fXfermode);
149 SkSafeRef(src.fMaskFilter); 163 REF_COPY(fMaskFilter);
150 SkSafeRef(src.fColorFilter); 164 REF_COPY(fColorFilter);
151 SkSafeRef(src.fRasterizer); 165 REF_COPY(fRasterizer);
152 SkSafeRef(src.fLooper); 166 REF_COPY(fLooper);
153 SkSafeRef(src.fImageFilter); 167 REF_COPY(fImageFilter);
154 SkSafeRef(src.fAnnotation); 168 REF_COPY(fAnnotation);
155 169
156 SkSafeUnref(fTypeface); 170 COPY(fTextSize);
157 SkSafeUnref(fPathEffect); 171 COPY(fTextScaleX);
158 SkSafeUnref(fShader); 172 COPY(fTextSkewX);
159 SkSafeUnref(fXfermode); 173 COPY(fColor);
160 SkSafeUnref(fMaskFilter); 174 COPY(fWidth);
161 SkSafeUnref(fColorFilter); 175 COPY(fMiterLimit);
162 SkSafeUnref(fRasterizer); 176 COPY(fBitfields);
163 SkSafeUnref(fLooper); 177 COPY(fDirtyBits);
164 SkSafeUnref(fImageFilter);
165 SkSafeUnref(fAnnotation);
166 178
167 #ifdef SK_BUILD_FOR_ANDROID 179 #ifdef SK_BUILD_FOR_ANDROID
168 fPaintOptionsAndroid.~SkPaintOptionsAndroid(); 180 fPaintOptionsAndroid.~SkPaintOptionsAndroid();
169
170 uint32_t oldGenerationID = fGenerationID;
171 #endif
172 memcpy(this, &src, sizeof(src));
173 #ifdef SK_BUILD_FOR_ANDROID
174 fGenerationID = oldGenerationID + 1;
175
176 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid); 181 new (&fPaintOptionsAndroid) SkPaintOptionsAndroid(src.fPaintOptionsAndroid);
182 ++fGenerationID;
177 #endif 183 #endif
178 184
179 return *this; 185 return *this;
186
187 #undef COPY
188 #undef REF_COPY
180 } 189 }
181 190
182 bool operator==(const SkPaint& a, const SkPaint& b) { 191 bool operator==(const SkPaint& a, const SkPaint& b) {
192 #define EQUAL(field) (a.field == b.field)
193 // Don't check fGenerationID or fDirtyBits, which can be different for logic ally equal paints.
194 return EQUAL(fTypeface)
195 && EQUAL(fPathEffect)
196 && EQUAL(fShader)
197 && EQUAL(fXfermode)
198 && EQUAL(fMaskFilter)
199 && EQUAL(fColorFilter)
200 && EQUAL(fRasterizer)
201 && EQUAL(fLooper)
202 && EQUAL(fImageFilter)
203 && EQUAL(fAnnotation)
204 && EQUAL(fTextSize)
205 && EQUAL(fTextScaleX)
206 && EQUAL(fTextSkewX)
207 && EQUAL(fColor)
208 && EQUAL(fWidth)
209 && EQUAL(fMiterLimit)
210 && EQUAL(fBitfields)
183 #ifdef SK_BUILD_FOR_ANDROID 211 #ifdef SK_BUILD_FOR_ANDROID
184 //assumes that fGenerationID is the last field in the struct 212 && EQUAL(fPaintOptionsAndroid)
185 return !memcmp(&a, &b, SK_OFFSETOF(SkPaint, fGenerationID));
186 #else
187 return !memcmp(&a, &b, sizeof(a));
188 #endif 213 #endif
214 ;
215 #undef EQUAL
189 } 216 }
190 217
191 void SkPaint::reset() { 218 void SkPaint::reset() {
192 SkPaint init; 219 SkPaint init;
193 220
194 #ifdef SK_BUILD_FOR_ANDROID 221 #ifdef SK_BUILD_FOR_ANDROID
195 uint32_t oldGenerationID = fGenerationID; 222 uint32_t oldGenerationID = fGenerationID;
196 #endif 223 #endif
197 *this = init; 224 *this = init;
198 #ifdef SK_BUILD_FOR_ANDROID 225 #ifdef SK_BUILD_FOR_ANDROID
(...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 } 2684 }
2658 #ifdef SK_BUILD_FOR_ANDROID 2685 #ifdef SK_BUILD_FOR_ANDROID
2659 if (dirty & kPaintOptionsAndroid_DirtyBit) { 2686 if (dirty & kPaintOptionsAndroid_DirtyBit) {
2660 SkPaintOptionsAndroid options; 2687 SkPaintOptionsAndroid options;
2661 options.unflatten(buffer); 2688 options.unflatten(buffer);
2662 paint->setPaintOptionsAndroid(options); 2689 paint->setPaintOptionsAndroid(options);
2663 } 2690 }
2664 #endif 2691 #endif
2665 SkASSERT(dirty == paint->fDirtyBits); 2692 SkASSERT(dirty == paint->fDirtyBits);
2666 } 2693 }
OLDNEW
« no previous file with comments | « include/core/SkPaint.h ('k') | tests/PaintTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698