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

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 769953002: Remove SK_SUPPORT_LEGACY_DEEPFLATTENING. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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/effects/SkXfermodeImageFilter.cpp ('k') | src/effects/gradients/SkLinearGradient.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkGradientShaderPriv.h" 8 #include "SkGradientShaderPriv.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRadialGradient.h" 10 #include "SkRadialGradient.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 SkASSERT(2 == fColorCount); 192 SkASSERT(2 == fColorCount);
193 fOrigPos[0] = SkScalarPin(desc.fPos[0], 0, 1); 193 fOrigPos[0] = SkScalarPin(desc.fPos[0], 0, 1);
194 fOrigPos[1] = SkScalarPin(desc.fPos[1], fOrigPos[0], 1); 194 fOrigPos[1] = SkScalarPin(desc.fPos[1], fOrigPos[0], 1);
195 if (0 == fOrigPos[0] && 1 == fOrigPos[1]) { 195 if (0 == fOrigPos[0] && 1 == fOrigPos[1]) {
196 fOrigPos = NULL; 196 fOrigPos = NULL;
197 } 197 }
198 } 198 }
199 this->initCommon(); 199 this->initCommon();
200 } 200 }
201 201
202 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
203 static SkShader::TileMode unpack_mode(uint32_t packed) {
204 return (SkShader::TileMode)(packed & 0xF);
205 }
206
207 static uint32_t unpack_flags(uint32_t packed) {
208 return packed >> 4;
209 }
210
211 SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buf fer) {
212 int colorCount = fColorCount = buffer.getArrayCount();
213 if (colorCount > kColorStorageCount) {
214 size_t allocSize = (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) * colorCount;
215 if (buffer.validateAvailable(allocSize)) {
216 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize)) ;
217 } else {
218 fOrigColors = NULL;
219 colorCount = fColorCount = 0;
220 }
221 } else {
222 fOrigColors = fStorage;
223 }
224 buffer.readColorArray(fOrigColors, colorCount);
225
226 fOrigPos = (SkScalar*)(fOrigColors + colorCount);
227
228 {
229 uint32_t packed = buffer.readUInt();
230 fGradFlags = SkToU8(unpack_flags(packed));
231 fTileMode = unpack_mode(packed);
232 }
233 fTileProc = gTileProcs[fTileMode];
234 fRecs = (Rec*)(fOrigPos + colorCount);
235 if (colorCount > 2) {
236 Rec* recs = fRecs;
237 recs[0].fPos = 0;
238 fOrigPos[0] = 0;
239 for (int i = 1; i < colorCount; i++) {
240 recs[i].fPos = buffer.readInt();
241 recs[i].fScale = buffer.readUInt();
242 fOrigPos[i] = SkFixedToScalar(recs[i].fPos);
243 }
244 } else {
245 fOrigPos = NULL;
246 }
247 buffer.readMatrix(&fPtsToUnit);
248 this->initCommon();
249 }
250 #endif
251
252 SkGradientShaderBase::~SkGradientShaderBase() { 202 SkGradientShaderBase::~SkGradientShaderBase() {
253 if (fOrigColors != fStorage) { 203 if (fOrigColors != fStorage) {
254 sk_free(fOrigColors); 204 sk_free(fOrigColors);
255 } 205 }
256 } 206 }
257 207
258 void SkGradientShaderBase::initCommon() { 208 void SkGradientShaderBase::initCommon() {
259 unsigned colorAlpha = 0xFF; 209 unsigned colorAlpha = 0xFF;
260 for (int i = 0; i < fColorCount; i++) { 210 for (int i = 0; i < fColorCount; i++) {
261 colorAlpha &= SkColorGetA(fOrigColors[i]); 211 colorAlpha &= SkColorGetA(fOrigColors[i]);
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 (*stops)[i] = stop; 1176 (*stops)[i] = stop;
1227 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1177 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1228 } 1178 }
1229 } 1179 }
1230 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1180 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1231 1181
1232 return outColors; 1182 return outColors;
1233 } 1183 }
1234 1184
1235 #endif 1185 #endif
OLDNEW
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698