diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2018-11-15 10:01:19 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2018-11-16 12:37:31 +0100 |
commit | adf363a2085f8af08a38046fae148131d0cbdd06 (patch) | |
tree | 88e63bdc02984770df7b39c699625a2bdcc53aa1 /components/script/dom/webgl_validations | |
parent | 86987ed75d94ddf8079dccf405073ee3a70bb1e6 (diff) | |
download | servo-adf363a2085f8af08a38046fae148131d0cbdd06.tar.gz servo-adf363a2085f8af08a38046fae148131d0cbdd06.zip |
Move prepare_pixels helper functions to canvas_traits
Diffstat (limited to 'components/script/dom/webgl_validations')
-rw-r--r-- | components/script/dom/webgl_validations/tex_image_2d.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webgl_validations/types.rs | 111 |
2 files changed, 14 insertions, 101 deletions
diff --git a/components/script/dom/webgl_validations/tex_image_2d.rs b/components/script/dom/webgl_validations/tex_image_2d.rs index 125ff4918a8..09a96d37a1b 100644 --- a/components/script/dom/webgl_validations/tex_image_2d.rs +++ b/components/script/dom/webgl_validations/tex_image_2d.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use super::types::{TexDataType, TexFormat, TexImageTarget}; +use super::types::TexImageTarget; use super::WebGLValidator; -use canvas_traits::webgl::WebGLError::*; +use canvas_traits::webgl::{TexDataType, TexFormat, WebGLError::*}; use crate::dom::bindings::root::DomRoot; use crate::dom::webglrenderingcontext::WebGLRenderingContext; use crate::dom::webgltexture::WebGLTexture; diff --git a/components/script/dom/webgl_validations/types.rs b/components/script/dom/webgl_validations/types.rs index adcc51bf1ff..5ff239ed898 100644 --- a/components/script/dom/webgl_validations/types.rs +++ b/components/script/dom/webgl_validations/types.rs @@ -2,47 +2,21 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use crate::dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants; -use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; - -/// This macro creates type-safe wrappers for WebGL types, associating variants -/// with gl constants. -macro_rules! type_safe_wrapper { - ($name: ident, $($variant:ident => $mod:ident::$constant:ident, )+) => { - #[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, MallocSizeOf, PartialEq)] - #[repr(u32)] - pub enum $name { - $( - $variant = $mod::$constant, - )+ - } - - impl $name { - pub fn from_gl_constant(constant: u32) -> Option<Self> { - Some(match constant { - $($mod::$constant => $name::$variant, )+ - _ => return None, - }) - } - - #[inline] - pub fn as_gl_constant(&self) -> u32 { - *self as u32 - } - } +use canvas_traits::gl_enums; +use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants; + +gl_enums! { + pub enum TexImageTarget { + Texture2D = WebGLRenderingContextConstants::TEXTURE_2D, + CubeMapPositiveX = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_POSITIVE_X, + CubeMapNegativeX = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_NEGATIVE_X, + CubeMapPositiveY = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_POSITIVE_Y, + CubeMapNegativeY = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_NEGATIVE_Y, + CubeMapPositiveZ = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_POSITIVE_Z, + CubeMapNegativeZ = WebGLRenderingContextConstants::TEXTURE_CUBE_MAP_NEGATIVE_Z, } } -type_safe_wrapper! { TexImageTarget, - Texture2D => constants::TEXTURE_2D, - CubeMapPositiveX => constants::TEXTURE_CUBE_MAP_POSITIVE_X, - CubeMapNegativeX => constants::TEXTURE_CUBE_MAP_NEGATIVE_X, - CubeMapPositiveY => constants::TEXTURE_CUBE_MAP_POSITIVE_Y, - CubeMapNegativeY => constants::TEXTURE_CUBE_MAP_NEGATIVE_Y, - CubeMapPositiveZ => constants::TEXTURE_CUBE_MAP_POSITIVE_Z, - CubeMapNegativeZ => constants::TEXTURE_CUBE_MAP_NEGATIVE_Z, -} - impl TexImageTarget { pub fn is_cubic(&self) -> bool { match *self { @@ -51,64 +25,3 @@ impl TexImageTarget { } } } - -type_safe_wrapper! { TexDataType, - UnsignedByte => constants::UNSIGNED_BYTE, - UnsignedShort4444 => constants::UNSIGNED_SHORT_4_4_4_4, - UnsignedShort5551 => constants::UNSIGNED_SHORT_5_5_5_1, - UnsignedShort565 => constants::UNSIGNED_SHORT_5_6_5, - Float => constants::FLOAT, - HalfFloat => OESTextureHalfFloatConstants::HALF_FLOAT_OES, -} - -impl TexDataType { - /// Returns the size in bytes of each element of data. - pub fn element_size(&self) -> u32 { - use self::TexDataType::*; - match *self { - UnsignedByte => 1, - UnsignedShort4444 | UnsignedShort5551 | UnsignedShort565 => 2, - Float => 4, - HalfFloat => 2, - } - } - - /// Returns how many components a single element may hold. For example, a - /// UnsignedShort4444 holds four components, each with 4 bits of data. - pub fn components_per_element(&self) -> u32 { - use self::TexDataType::*; - match *self { - UnsignedByte => 1, - UnsignedShort565 => 3, - UnsignedShort5551 => 4, - UnsignedShort4444 => 4, - Float => 1, - HalfFloat => 1, - } - } -} - -type_safe_wrapper! { TexFormat, - DepthComponent => constants::DEPTH_COMPONENT, - Alpha => constants::ALPHA, - RGB => constants::RGB, - RGBA => constants::RGBA, - Luminance => constants::LUMINANCE, - LuminanceAlpha => constants::LUMINANCE_ALPHA, -} - -impl TexFormat { - /// Returns how many components does this format need. For example, RGBA - /// needs 4 components, while RGB requires 3. - pub fn components(&self) -> u32 { - use self::TexFormat::*; - match *self { - DepthComponent => 1, - Alpha => 1, - Luminance => 1, - LuminanceAlpha => 2, - RGB => 3, - RGBA => 4, - } - } -} |