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

Side by Side Diff: cc/output/shader.cc

Issue 639773010: Prevent division by 0 in set_luminance shader function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjusting test error values 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 | « no previous file | cc/trees/layer_tree_host_pixeltest_blending.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/shader.h" 5 #include "cc/output/shader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 static const std::string kFunctionLum = SHADER0( 797 static const std::string kFunctionLum = SHADER0(
798 // clang-format on 798 // clang-format on
799 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } 799 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); }
800 800
801 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { 801 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) {
802 float diff = luminance(lumColor - hueSat); 802 float diff = luminance(lumColor - hueSat);
803 vec3 outColor = hueSat + diff; 803 vec3 outColor = hueSat + diff;
804 float outLum = luminance(outColor); 804 float outLum = luminance(outColor);
805 float minComp = min(min(outColor.r, outColor.g), outColor.b); 805 float minComp = min(min(outColor.r, outColor.g), outColor.b);
806 float maxComp = max(max(outColor.r, outColor.g), outColor.b); 806 float maxComp = max(max(outColor.r, outColor.g), outColor.b);
807 if (minComp < 0.0) { 807 if (minComp < 0.0 && outLum != minComp) {
808 outColor = outLum + 808 outColor = outLum +
809 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / 809 ((outColor - vec3(outLum, outLum, outLum)) * outLum) /
810 (outLum - minComp); 810 (outLum - minComp);
811 } 811 }
812 if (maxComp > alpha) { 812 if (maxComp > alpha && maxComp != outLum) {
813 outColor = 813 outColor =
814 outLum + 814 outLum +
815 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / 815 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) /
816 (maxComp - outLum); 816 (maxComp - outLum);
817 } 817 }
818 return outColor; 818 return outColor;
819 } 819 }
820 // clang-format off 820 // clang-format off
821 ); // NOLINT(whitespace/parens) 821 ); // NOLINT(whitespace/parens)
822 822
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1979 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1980 float picker = abs(coord.x - coord.y); // NOLINT 1980 float picker = abs(coord.x - coord.y); // NOLINT
1981 gl_FragColor = mix(color1, color2, picker) * alpha; 1981 gl_FragColor = mix(color1, color2, picker) * alpha;
1982 } 1982 }
1983 // clang-format off 1983 // clang-format off
1984 ); // NOLINT(whitespace/parens) 1984 ); // NOLINT(whitespace/parens)
1985 // clang-format on 1985 // clang-format on
1986 } 1986 }
1987 1987
1988 } // namespace cc 1988 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_pixeltest_blending.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698