aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorKosov Eugene <claprix@yandex.ru>2016-05-27 10:15:37 +0300
committerKosov Eugene <claprix@yandex.ru>2016-05-27 10:15:37 +0300
commit94ad5aef62dcce01dd25b206e2fb1714e4b6e6c2 (patch)
treec340713187d6bc5e2ad6c4a945546e1433addb80 /components/script/dom/webglrenderingcontext.rs
parent4dcb05ca4f521b2c5eb12000678be035465e092b (diff)
downloadservo-94ad5aef62dcce01dd25b206e2fb1714e4b6e6c2.tar.gz
servo-94ad5aef62dcce01dd25b206e2fb1714e4b6e6c2.zip
add log2(u32) and use it to prevent casting to and from float to int
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 3e57bae5a6e..cc3dff56f94 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -87,6 +87,10 @@ pub struct WebGLRenderingContext {
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
}
+fn log2(n: u32) -> u32 {
+ 31 - n.leading_zeros()
+}
+
impl WebGLRenderingContext {
fn new_inherited(global: GlobalRef,
canvas: &HTMLCanvasElement,
@@ -402,7 +406,7 @@ impl WebGLRenderingContext {
// the returned value of GL_MAX_TEXTURE_SIZE when
// target is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE
// when target is not GL_TEXTURE_2D.
- if level > (max as f32).log2() as i32 {
+ if level > log2(max) as i32 {
self.webgl_error(InvalidValue);
return false;
}