Bug 1929208 - Use std::clamp instead of min/max chain in dom/canvas r=aosmond,jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D227932
This commit is contained in:
@@ -239,7 +239,7 @@ bool WebGLContext::ValidateStencilParamsForDrawCall() const {
|
||||
|
||||
const auto fnMask = [&](const uint32_t x) { return x & stencilMax; };
|
||||
const auto fnClamp = [&](const int32_t x) {
|
||||
return std::max(0, std::min(x, (int32_t)stencilMax));
|
||||
return std::clamp(x, 0, (int32_t)stencilMax);
|
||||
};
|
||||
|
||||
bool ok = true;
|
||||
|
||||
@@ -1555,8 +1555,8 @@ void WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl, GLint _srcX0,
|
||||
}
|
||||
|
||||
// Clamp the rect points
|
||||
const auto srcQ0 = srcP0f.ClampMinMax(zero2f, srcSizef);
|
||||
const auto srcQ1 = srcP1f.ClampMinMax(zero2f, srcSizef);
|
||||
const auto srcQ0 = srcP0f.Clamp(zero2f, srcSizef);
|
||||
const auto srcQ1 = srcP1f.Clamp(zero2f, srcSizef);
|
||||
|
||||
// Normalized to the [0,1] abstact copy rect
|
||||
const auto srcQ0Norm = (srcQ0 - srcP0f) / srcRectDiff;
|
||||
@@ -1567,8 +1567,8 @@ void WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl, GLint _srcX0,
|
||||
const auto srcQ1InDst = dstP0f + srcQ1Norm * dstRectDiff;
|
||||
|
||||
// Clamp the rect points
|
||||
const auto dstQ0 = srcQ0InDst.ClampMinMax(zero2f, dstSizef);
|
||||
const auto dstQ1 = srcQ1InDst.ClampMinMax(zero2f, dstSizef);
|
||||
const auto dstQ0 = srcQ0InDst.Clamp(zero2f, dstSizef);
|
||||
const auto dstQ1 = srcQ1InDst.Clamp(zero2f, dstSizef);
|
||||
|
||||
// Alright, time to go back to src!
|
||||
// Normalized to the [0,1] abstact copy rect
|
||||
@@ -1579,8 +1579,8 @@ void WebGLFramebuffer::BlitFramebuffer(WebGLContext* webgl, GLint _srcX0,
|
||||
const auto dstQ0InSrc = srcP0f + dstQ0Norm * srcRectDiff;
|
||||
const auto dstQ1InSrc = srcP0f + dstQ1Norm * srcRectDiff;
|
||||
|
||||
const auto srcQ0Constrained = dstQ0InSrc.ClampMinMax(zero2f, srcSizef);
|
||||
const auto srcQ1Constrained = dstQ1InSrc.ClampMinMax(zero2f, srcSizef);
|
||||
const auto srcQ0Constrained = dstQ0InSrc.Clamp(zero2f, srcSizef);
|
||||
const auto srcQ1Constrained = dstQ1InSrc.Clamp(zero2f, srcSizef);
|
||||
|
||||
// Round, don't floor:
|
||||
srcP0 = (srcQ0Constrained + 0.5).StaticCast<ivec2>();
|
||||
|
||||
@@ -662,13 +662,6 @@ static bool ZeroTextureData(const WebGLContext* webgl, GLuint tex,
|
||||
return !error;
|
||||
}
|
||||
|
||||
template <typename T, typename R>
|
||||
static constexpr R Clamp(const T val, const R min, const R max) {
|
||||
if (val < min) return min;
|
||||
if (val > max) return max;
|
||||
return static_cast<R>(val);
|
||||
}
|
||||
|
||||
void WebGLTexture::ClampLevelBaseAndMax() {
|
||||
if (!mImmutable) return;
|
||||
|
||||
@@ -680,9 +673,10 @@ void WebGLTexture::ClampLevelBaseAndMax() {
|
||||
MOZ_ASSERT(mImmutableLevelCount > 0);
|
||||
const auto oldBase = mBaseMipmapLevel;
|
||||
const auto oldMax = mMaxMipmapLevel;
|
||||
mBaseMipmapLevel = Clamp(mBaseMipmapLevel, 0u, mImmutableLevelCount - 1u);
|
||||
mBaseMipmapLevel =
|
||||
std::clamp(mBaseMipmapLevel, 0u, mImmutableLevelCount - 1u);
|
||||
mMaxMipmapLevel =
|
||||
Clamp(mMaxMipmapLevel, mBaseMipmapLevel, mImmutableLevelCount - 1u);
|
||||
std::clamp(mMaxMipmapLevel, mBaseMipmapLevel, mImmutableLevelCount - 1u);
|
||||
if (oldBase != mBaseMipmapLevel &&
|
||||
mBaseMipmapLevelState != MIPMAP_LEVEL_DEFAULT) {
|
||||
mBaseMipmapLevelState = MIPMAP_LEVEL_DIRTY;
|
||||
@@ -732,7 +726,8 @@ bool WebGLTexture::BindTexture(TexTarget texTarget) {
|
||||
}
|
||||
|
||||
static constexpr GLint ClampMipmapLevelForDriver(uint32_t level) {
|
||||
return Clamp(level, uint8_t{0}, WebGLTexture::kMaxLevelCount);
|
||||
return static_cast<GLint>(
|
||||
std::clamp(level, 0u, (uint32_t)WebGLTexture::kMaxLevelCount));
|
||||
}
|
||||
|
||||
void WebGLTexture::GenerateMipmap() {
|
||||
|
||||
@@ -175,7 +175,7 @@ class WebGLTexture final : public WebGLContextBoundObject,
|
||||
const auto level_immut = mImmutableLevelCount;
|
||||
|
||||
if (!mImmutable) return level_prime_max;
|
||||
return std::min(std::max(level_base, level_prime_max), level_immut - 1u);
|
||||
return std::clamp(level_base, level_prime_max, level_immut - 1u);
|
||||
}
|
||||
|
||||
// GLES 3.0.5 p158: `q`
|
||||
|
||||
@@ -478,16 +478,7 @@ struct avec2 {
|
||||
#undef _
|
||||
|
||||
avec2 Clamp(const avec2& min, const avec2& max) const {
|
||||
return {mozilla::Clamp(x, min.x, max.x), mozilla::Clamp(y, min.y, max.y)};
|
||||
}
|
||||
|
||||
// mozilla::Clamp doesn't work on floats, so be clear that this is a min+max
|
||||
// helper.
|
||||
avec2 ClampMinMax(const avec2& min, const avec2& max) const {
|
||||
const auto ClampScalar = [](const T v, const T min, const T max) {
|
||||
return std::max(min, std::min(v, max));
|
||||
};
|
||||
return {ClampScalar(x, min.x, max.x), ClampScalar(y, min.y, max.y)};
|
||||
return {std::clamp(x, min.x, max.x), std::clamp(y, min.y, max.y)};
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
|
||||
Reference in New Issue
Block a user