summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/platform/graphics
diff options
context:
space:
mode:
authorbratell <bratell@opera.com>2015-12-22 02:58:39 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-22 10:59:27 +0000
commit881b6566ecacfe9154e1f115c588e76cec8a513a (patch)
tree9d930e81c593d978af79354278134d91271009a5 /third_party/WebKit/Source/platform/graphics
parenta86c5dbbd265eba83cda96805fea8ecdf1d8c36d (diff)
downloadchromium_src-881b6566ecacfe9154e1f115c588e76cec8a513a.zip
chromium_src-881b6566ecacfe9154e1f115c588e76cec8a513a.tar.gz
chromium_src-881b6566ecacfe9154e1f115c588e76cec8a513a.tar.bz2
Use clampTo instead of chaining std::max(std::min(...))
It's common to make a value end up between two other values by using std::min and std::max but we have a clampTo function that will make the code much easier to read so we should use it. The performance is the same (both end up doing inline comparisons and value selection) but not having to include <algorithm> can bring a very slight compilation speed boost. BUG=563433 Review URL: https://codereview.chromium.org/1530723004 Cr-Commit-Position: refs/heads/master@{#366585}
Diffstat (limited to 'third_party/WebKit/Source/platform/graphics')
-rw-r--r--third_party/WebKit/Source/platform/graphics/Color.cpp6
-rw-r--r--third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp5
-rw-r--r--third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp10
-rw-r--r--third_party/WebKit/Source/platform/graphics/filters/FELighting.cpp2
-rw-r--r--third_party/WebKit/Source/platform/graphics/filters/FESpecularLighting.cpp4
-rw-r--r--third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.cpp4
-rw-r--r--third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.h4
7 files changed, 21 insertions, 14 deletions
diff --git a/third_party/WebKit/Source/platform/graphics/Color.cpp b/third_party/WebKit/Source/platform/graphics/Color.cpp
index 5f2f51a..dc9364e 100644
--- a/third_party/WebKit/Source/platform/graphics/Color.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Color.cpp
@@ -50,17 +50,17 @@ static const RGBA32 darkenedWhite = 0xFFABABAB;
RGBA32 makeRGB(int r, int g, int b)
{
- return 0xFF000000 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
+ return 0xFF000000 | clampTo(r, 0, 255) << 16 | clampTo(g, 0, 255) << 8 | clampTo(b, 0, 255);
}
RGBA32 makeRGBA(int r, int g, int b, int a)
{
- return std::max(0, std::min(a, 255)) << 24 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
+ return clampTo(a, 0, 255) << 24 | clampTo(r, 0, 255) << 16 | clampTo(g, 0, 255) << 8 | clampTo(b, 0, 255);
}
static int colorFloatToRGBAByte(float f)
{
- return std::max(0, std::min(static_cast<int>(lroundf(255.0f * f)), 255));
+ return clampTo(static_cast<int>(lroundf(255.0f * f)), 0, 255);
}
RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a)
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
index 3c57538..eefb444 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
@@ -57,9 +57,12 @@
#include "wtf/CurrentTime.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
+#include "wtf/MathExtras.h"
#include "wtf/text/StringUTF8Adaptor.h"
#include "wtf/text/WTFString.h"
#include <algorithm>
+#include <cmath>
+#include <utility>
#ifndef NDEBUG
#include <stdio.h>
@@ -987,7 +990,7 @@ void GraphicsLayer::setBackfaceVisibility(bool visible)
void GraphicsLayer::setOpacity(float opacity)
{
- float clampedOpacity = std::max(std::min(opacity, 1.0f), 0.0f);
+ float clampedOpacity = clampTo(opacity, 0.0f, 1.0f);
m_opacity = clampedOpacity;
platformLayer()->setOpacity(opacity);
}
diff --git a/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp b/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp
index 2b372e3..a921035 100644
--- a/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp
@@ -28,6 +28,8 @@
#include "SkTableColorFilter.h"
#include "platform/graphics/filters/SkiaImageFilterBuilder.h"
#include "platform/text/TextStream.h"
+#include "wtf/MathExtras.h"
+#include <algorithm>
namespace blink {
@@ -65,7 +67,7 @@ static void table(unsigned char* values, const ComponentTransferFunction& transf
double v1 = tableValues[k];
double v2 = tableValues[std::min((k + 1), (n - 1))];
double val = 255.0 * (v1 + (c * (n - 1) - k) * (v2 - v1));
- val = std::max(0.0, std::min(255.0, val));
+ val = clampTo(val, 0.0, 255.0);
values[i] = static_cast<unsigned char>(val);
}
}
@@ -80,7 +82,7 @@ static void discrete(unsigned char* values, const ComponentTransferFunction& tra
unsigned k = static_cast<unsigned>((i * n) / 255.0);
k = std::min(k, n - 1);
double val = 255 * tableValues[k];
- val = std::max(0.0, std::min(255.0, val));
+ val = clampTo(val, 0.0, 255.0);
values[i] = static_cast<unsigned char>(val);
}
}
@@ -89,7 +91,7 @@ static void linear(unsigned char* values, const ComponentTransferFunction& trans
{
for (unsigned i = 0; i < 256; ++i) {
double val = transferFunction.slope * i + 255 * transferFunction.intercept;
- val = std::max(0.0, std::min(255.0, val));
+ val = clampTo(val, 0.0, 255.0);
values[i] = static_cast<unsigned char>(val);
}
}
@@ -99,7 +101,7 @@ static void gamma(unsigned char* values, const ComponentTransferFunction& transf
for (unsigned i = 0; i < 256; ++i) {
double exponent = transferFunction.exponent; // RCVT doesn't like passing a double and a float to pow, so promote this to double
double val = 255.0 * (transferFunction.amplitude * pow((i / 255.0), exponent) + transferFunction.offset);
- val = std::max(0.0, std::min(255.0, val));
+ val = clampTo(val, 0.0, 255.0);
values[i] = static_cast<unsigned char>(val);
}
}
diff --git a/third_party/WebKit/Source/platform/graphics/filters/FELighting.cpp b/third_party/WebKit/Source/platform/graphics/filters/FELighting.cpp
index 53d164f..680b43e 100644
--- a/third_party/WebKit/Source/platform/graphics/filters/FELighting.cpp
+++ b/third_party/WebKit/Source/platform/graphics/filters/FELighting.cpp
@@ -46,7 +46,7 @@ FELighting::FELighting(Filter* filter, LightingType lightingType, const Color& l
, m_surfaceScale(surfaceScale)
, m_diffuseConstant(std::max(diffuseConstant, 0.0f))
, m_specularConstant(std::max(specularConstant, 0.0f))
- , m_specularExponent(std::min(std::max(specularExponent, 1.0f), 128.0f))
+ , m_specularExponent(clampTo(specularExponent, 1.0f, 128.0f))
{
}
diff --git a/third_party/WebKit/Source/platform/graphics/filters/FESpecularLighting.cpp b/third_party/WebKit/Source/platform/graphics/filters/FESpecularLighting.cpp
index 29962d2..b4cc656 100644
--- a/third_party/WebKit/Source/platform/graphics/filters/FESpecularLighting.cpp
+++ b/third_party/WebKit/Source/platform/graphics/filters/FESpecularLighting.cpp
@@ -24,6 +24,8 @@
#include "platform/graphics/filters/LightSource.h"
#include "platform/text/TextStream.h"
+#include "wtf/MathExtras.h"
+#include <algorithm>
namespace blink {
@@ -91,7 +93,7 @@ float FESpecularLighting::specularExponent() const
bool FESpecularLighting::setSpecularExponent(float specularExponent)
{
- specularExponent = std::min(std::max(specularExponent, 1.0f), 128.0f);
+ specularExponent = clampTo(specularExponent, 1.0f, 128.0f);
if (m_specularExponent == specularExponent)
return false;
m_specularExponent = specularExponent;
diff --git a/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.cpp b/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.cpp
index 6b0b613..004ac41 100644
--- a/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.cpp
+++ b/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.cpp
@@ -32,7 +32,7 @@
#include "platform/graphics/filters/SpotLightSource.h"
#include "platform/text/TextStream.h"
-#include <algorithm>
+#include "wtf/MathExtras.h"
namespace blink {
@@ -54,7 +54,7 @@ bool SpotLightSource::setPointsAt(const FloatPoint3D& direction)
bool SpotLightSource::setSpecularExponent(float specularExponent)
{
- specularExponent = std::min(std::max(specularExponent, 1.0f), 128.0f);
+ specularExponent = clampTo(specularExponent, 1.0f, 128.0f);
if (m_specularExponent == specularExponent)
return false;
m_specularExponent = specularExponent;
diff --git a/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.h b/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.h
index 6de25ff..e005460 100644
--- a/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.h
+++ b/third_party/WebKit/Source/platform/graphics/filters/SpotLightSource.h
@@ -24,7 +24,7 @@
#define SpotLightSource_h
#include "platform/graphics/filters/LightSource.h"
-#include <algorithm>
+#include "wtf/MathExtras.h"
namespace blink {
@@ -55,7 +55,7 @@ private:
: LightSource(LS_SPOT)
, m_position(position)
, m_direction(direction)
- , m_specularExponent(std::min(std::max(specularExponent, 1.0f), 128.0f))
+ , m_specularExponent(clampTo(specularExponent, 1.0f, 128.0f))
, m_limitingConeAngle(limitingConeAngle)
{
}