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

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

Issue 2234663002: Prevent degenerate linear gradient instantiation (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: add a regression test Created 4 years, 4 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 | « no previous file | tests/GradientTest.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 "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "SkGradientShaderPriv.h" 9 #include "SkGradientShaderPriv.h"
10 #include "SkLinearGradient.h" 10 #include "SkLinearGradient.h"
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 desc->fGradFlags = flags; 783 desc->fGradFlags = flags;
784 desc->fLocalMatrix = localMatrix; 784 desc->fLocalMatrix = localMatrix;
785 } 785 }
786 786
787 sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2], 787 sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2],
788 const SkColor colors[], 788 const SkColor colors[],
789 const SkScalar pos[], int colorCount, 789 const SkScalar pos[], int colorCount,
790 SkShader::TileMode mode, 790 SkShader::TileMode mode,
791 uint32_t flags, 791 uint32_t flags,
792 const SkMatrix* localMatrix) { 792 const SkMatrix* localMatrix) {
793 if (!pts) { 793 if (!pts || !SkScalarIsFinite((pts[1] - pts[0]).length())) {
794 return nullptr; 794 return nullptr;
795 } 795 }
796 if (!valid_grad(colors, pos, colorCount, mode)) { 796 if (!valid_grad(colors, pos, colorCount, mode)) {
797 return nullptr; 797 return nullptr;
798 } 798 }
799 EXPAND_1_COLOR(colorCount); 799 EXPAND_1_COLOR(colorCount);
800 800
801 SkGradientShaderBase::Descriptor desc; 801 SkGradientShaderBase::Descriptor desc;
802 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix); 802 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
803 return sk_make_sp<SkLinearGradient>(pts, desc); 803 return sk_make_sp<SkLinearGradient>(pts, desc);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 (*stops)[i] = stop; 1208 (*stops)[i] = stop;
1209 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1209 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1210 } 1210 }
1211 } 1211 }
1212 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1212 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1213 1213
1214 return outColors; 1214 return outColors;
1215 } 1215 }
1216 1216
1217 #endif 1217 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/GradientTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698