| OLD | NEW |
| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 779 } |
| 780 | 780 |
| 781 if (SkScalarNearlyEqual(pos[0], 0.0f) && | 781 if (SkScalarNearlyEqual(pos[0], 0.0f) && |
| 782 SkScalarNearlyEqual(pos[1], 0.0f) && | 782 SkScalarNearlyEqual(pos[1], 0.0f) && |
| 783 SkScalarNearlyEqual(pos[2], 1.0f)) { | 783 SkScalarNearlyEqual(pos[2], 1.0f)) { |
| 784 | 784 |
| 785 if (SkShader::kRepeat_TileMode == mode || | 785 if (SkShader::kRepeat_TileMode == mode || |
| 786 SkShader::kMirror_TileMode == mode || | 786 SkShader::kMirror_TileMode == mode || |
| 787 colors[0] == colors[1]) { | 787 colors[0] == colors[1]) { |
| 788 | 788 |
| 789 fColorStorage[0] = colors[1]; | 789 // Ignore the leftmost color/pos. |
| 790 fColorStorage[1] = colors[2]; | 790 fColors += 1; |
| 791 fPosStorage[0] = 0.0f; | 791 fPos += 1; |
| 792 fPosStorage[1] = 1.0f; | 792 fCount = 2; |
| 793 | |
| 794 fColors = fColorStorage; | |
| 795 fPos = fPosStorage; | |
| 796 fCount = 2; | |
| 797 } | 793 } |
| 798 } else if (SkScalarNearlyEqual(pos[0], 0.0f) && | 794 } else if (SkScalarNearlyEqual(pos[0], 0.0f) && |
| 799 SkScalarNearlyEqual(pos[1], 1.0f) && | 795 SkScalarNearlyEqual(pos[1], 1.0f) && |
| 800 SkScalarNearlyEqual(pos[2], 1.0f)) { | 796 SkScalarNearlyEqual(pos[2], 1.0f)) { |
| 801 | 797 |
| 802 if (SkShader::kRepeat_TileMode == mode || | 798 if (SkShader::kRepeat_TileMode == mode || |
| 803 SkShader::kMirror_TileMode == mode || | 799 SkShader::kMirror_TileMode == mode || |
| 804 colors[1] == colors[2]) { | 800 colors[1] == colors[2]) { |
| 805 | 801 |
| 802 // Ignore the rightmost color/pos. |
| 806 fCount = 2; | 803 fCount = 2; |
| 807 } | 804 } |
| 808 } | 805 } |
| 809 } | 806 } |
| 810 | 807 |
| 811 const SkColor* fColors; | 808 const SkColor* fColors; |
| 812 const SkScalar* fPos; | 809 const SkScalar* fPos; |
| 813 int fCount; | 810 int fCount; |
| 814 | |
| 815 SkColor fColorStorage[2]; | |
| 816 SkScalar fPosStorage[2]; | |
| 817 }; | 811 }; |
| 818 | 812 |
| 819 sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2], | 813 sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2], |
| 820 const SkColor colors[], | 814 const SkColor colors[], |
| 821 const SkScalar pos[], int colorCoun
t, | 815 const SkScalar pos[], int colorCoun
t, |
| 822 SkShader::TileMode mode, | 816 SkShader::TileMode mode, |
| 823 uint32_t flags, | 817 uint32_t flags, |
| 824 const SkMatrix* localMatrix) { | 818 const SkMatrix* localMatrix) { |
| 825 if (!pts || !SkScalarIsFinite((pts[1] - pts[0]).length())) { | 819 if (!pts || !SkScalarIsFinite((pts[1] - pts[0]).length())) { |
| 826 return nullptr; | 820 return nullptr; |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 (*stops)[i] = stop; | 1485 (*stops)[i] = stop; |
| 1492 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1486 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1493 } | 1487 } |
| 1494 } | 1488 } |
| 1495 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1489 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1496 | 1490 |
| 1497 return outColors; | 1491 return outColors; |
| 1498 } | 1492 } |
| 1499 | 1493 |
| 1500 #endif | 1494 #endif |
| OLD | NEW |