mirror of
https://github.com/servo/servo.git
synced 2025-09-17 10:28:22 +01:00
script: Remove three duplicated log functions from webgl (#39227)
We have the standard library at our disposal, let's use it. Testing: Covered by existing tests Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
7a28fd786c
commit
406eab4ec2
3 changed files with 6 additions and 18 deletions
|
@ -85,10 +85,6 @@ impl fmt::Display for TexImageValidationError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log2(n: u32) -> u32 {
|
|
||||||
31 - n.leading_zeros()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct CommonTexImage2DValidator<'a> {
|
pub(crate) struct CommonTexImage2DValidator<'a> {
|
||||||
context: &'a WebGLRenderingContext,
|
context: &'a WebGLRenderingContext,
|
||||||
target: u32,
|
target: u32,
|
||||||
|
@ -204,7 +200,7 @@ impl WebGLValidator for CommonTexImage2DValidator<'_> {
|
||||||
// log_2(max), where max is the returned value of GL_MAX_TEXTURE_SIZE
|
// log_2(max), where max is the returned value of GL_MAX_TEXTURE_SIZE
|
||||||
// when target is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE when
|
// when target is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE when
|
||||||
// target is not GL_TEXTURE_2D.
|
// target is not GL_TEXTURE_2D.
|
||||||
if level > log2(max_size) {
|
if level > max_size.ilog2() {
|
||||||
self.context.webgl_error(InvalidValue);
|
self.context.webgl_error(InvalidValue);
|
||||||
return Err(TexImageValidationError::LevelTooHigh);
|
return Err(TexImageValidationError::LevelTooHigh);
|
||||||
}
|
}
|
||||||
|
@ -772,7 +768,7 @@ impl WebGLValidator for TexStorageValidator<'_> {
|
||||||
return Err(TexImageValidationError::InvalidTextureFormat);
|
return Err(TexImageValidationError::InvalidTextureFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
let max_level = log2(cmp::max(width, height)) + 1;
|
let max_level = cmp::max(width, height).ilog2() + 1;
|
||||||
if level > max_level {
|
if level > max_level {
|
||||||
context.webgl_error(InvalidOperation);
|
context.webgl_error(InvalidOperation);
|
||||||
return Err(TexImageValidationError::LevelTooHigh);
|
return Err(TexImageValidationError::LevelTooHigh);
|
||||||
|
|
|
@ -14,10 +14,6 @@ use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
|
use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
|
||||||
use crate::dom::webgl::webgltexture::WebGLTexture;
|
use crate::dom::webgl::webgltexture::WebGLTexture;
|
||||||
|
|
||||||
fn log2(n: u32) -> u32 {
|
|
||||||
31 - n.leading_zeros()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct CommonTexImage3DValidator<'a> {
|
pub(crate) struct CommonTexImage3DValidator<'a> {
|
||||||
context: &'a WebGLRenderingContext,
|
context: &'a WebGLRenderingContext,
|
||||||
target: u32,
|
target: u32,
|
||||||
|
@ -107,7 +103,7 @@ impl WebGLValidator for CommonTexImage3DValidator<'_> {
|
||||||
self.context.webgl_error(InvalidValue);
|
self.context.webgl_error(InvalidValue);
|
||||||
return Err(TexImageValidationError::NegativeLevel);
|
return Err(TexImageValidationError::NegativeLevel);
|
||||||
}
|
}
|
||||||
if level > log2(max_size) {
|
if level > max_size.ilog2() {
|
||||||
self.context.webgl_error(InvalidValue);
|
self.context.webgl_error(InvalidValue);
|
||||||
return Err(TexImageValidationError::LevelTooHigh);
|
return Err(TexImageValidationError::LevelTooHigh);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,6 @@ pub(crate) enum CompleteForRendering {
|
||||||
MissingColorAttachment,
|
MissingColorAttachment,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log2(n: u32) -> u32 {
|
|
||||||
31 - n.leading_zeros()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
|
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
|
||||||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||||
enum WebGLFramebufferAttachment {
|
enum WebGLFramebufferAttachment {
|
||||||
|
@ -786,7 +782,7 @@ impl WebGLFramebuffer {
|
||||||
} else {
|
} else {
|
||||||
context.limits().max_tex_size
|
context.limits().max_tex_size
|
||||||
};
|
};
|
||||||
if level < 0 || level as u32 > log2(max_tex_size) {
|
if level < 0 || level as u32 > max_tex_size.ilog2() {
|
||||||
return Err(WebGLError::InvalidValue);
|
return Err(WebGLError::InvalidValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,11 +852,11 @@ impl WebGLFramebuffer {
|
||||||
Some(texture) => {
|
Some(texture) => {
|
||||||
let (max_level, max_layer) = match texture.target() {
|
let (max_level, max_layer) = match texture.target() {
|
||||||
Some(constants::TEXTURE_3D) => (
|
Some(constants::TEXTURE_3D) => (
|
||||||
log2(context.limits().max_3d_texture_size),
|
context.limits().max_3d_texture_size.ilog2(),
|
||||||
context.limits().max_3d_texture_size - 1,
|
context.limits().max_3d_texture_size - 1,
|
||||||
),
|
),
|
||||||
Some(constants::TEXTURE_2D) => (
|
Some(constants::TEXTURE_2D) => (
|
||||||
log2(context.limits().max_tex_size),
|
context.limits().max_tex_size.ilog2(),
|
||||||
context.limits().max_array_texture_layers - 1,
|
context.limits().max_array_texture_layers - 1,
|
||||||
),
|
),
|
||||||
_ => return Err(WebGLError::InvalidOperation),
|
_ => return Err(WebGLError::InvalidOperation),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue