aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-11-17 11:35:35 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2018-11-20 10:14:50 +0100
commit5f9e3d8bb999b29f7b9092a31552e47ceed7da02 (patch)
tree301a2b3f74e0fdaf76924266d167161b65ac5601 /components/script/dom/webglrenderingcontext.rs
parent2a5539caeffcc7db910e8eb3e29365a028e86a44 (diff)
downloadservo-5f9e3d8bb999b29f7b9092a31552e47ceed7da02.tar.gz
servo-5f9e3d8bb999b29f7b9092a31552e47ceed7da02.zip
Move prepare_pixels to canvas_traits::webgl
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs131
1 files changed, 40 insertions, 91 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index bbd9a12538b..1435c9133c9 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -638,55 +638,6 @@ impl WebGLRenderingContext {
}
}
- fn prepare_pixels(
- &self,
- internal_format: TexFormat,
- data_type: TexDataType,
- size: Size2D<u32>,
- unpacking_alignment: u32,
- alpha_treatment: Option<AlphaTreatment>,
- y_axis_treatment: YAxisTreatment,
- tex_source: TexSource,
- mut pixels: Vec<u8>,
- ) -> Vec<u8> {
- match alpha_treatment {
- Some(AlphaTreatment::Premultiply) => {
- if tex_source == TexSource::FromHtmlElement {
- webgl::premultiply_inplace(
- TexFormat::RGBA,
- TexDataType::UnsignedByte,
- &mut pixels,
- );
- } else {
- webgl::premultiply_inplace(internal_format, data_type, &mut pixels);
- }
- },
- Some(AlphaTreatment::Unmultiply) => {
- assert_eq!(tex_source, TexSource::FromHtmlElement);
- webgl::unmultiply_inplace(&mut pixels);
- },
- None => {},
- }
-
- if tex_source == TexSource::FromHtmlElement {
- pixels = webgl::rgba8_image_to_tex_image_data(internal_format, data_type, pixels);
- }
-
- if y_axis_treatment == YAxisTreatment::Flipped {
- // FINISHME: Consider doing premultiply and flip in a single mutable Vec.
- pixels = webgl::flip_pixels_y(
- internal_format,
- data_type,
- size.width as usize,
- size.height as usize,
- unpacking_alignment as usize,
- pixels,
- );
- }
-
- pixels
- }
-
fn tex_image_2d(
&self,
texture: &WebGLTexture,
@@ -699,6 +650,20 @@ impl WebGLRenderingContext {
tex_source: TexSource,
pixels: TexPixels,
) {
+ // TexImage2D depth is always equal to 1.
+ handle_potential_webgl_error!(
+ self,
+ texture.initialize(
+ target,
+ pixels.size.width,
+ pixels.size.height,
+ 1,
+ internal_format,
+ level,
+ Some(data_type)
+ )
+ );
+
let settings = self.texture_unpacking_settings.get();
let dest_premultiplied = settings.contains(TextureUnpacking::PREMULTIPLY_ALPHA);
@@ -714,7 +679,7 @@ impl WebGLRenderingContext {
YAxisTreatment::AsIs
};
- let buff = self.prepare_pixels(
+ let buff = webgl::prepare_pixels(
internal_format,
data_type,
pixels.size,
@@ -725,20 +690,6 @@ impl WebGLRenderingContext {
pixels.data,
);
- // TexImage2D depth is always equal to 1
- handle_potential_webgl_error!(
- self,
- texture.initialize(
- target,
- pixels.size.width,
- pixels.size.height,
- 1,
- internal_format,
- level,
- Some(data_type)
- )
- );
-
let format = internal_format.as_gl_constant();
let data_type = data_type.as_gl_constant();
let internal_format = self
@@ -777,12 +728,32 @@ impl WebGLRenderingContext {
tex_source: TexSource,
pixels: TexPixels,
) {
+ // We have already validated level
+ let image_info = texture.image_info_for_target(&target, level);
+
+ // GL_INVALID_VALUE is generated if:
+ // - xoffset or yoffset is less than 0
+ // - x offset plus the width is greater than the texture width
+ // - y offset plus the height is greater than the texture height
+ if xoffset < 0 ||
+ (xoffset as u32 + pixels.size.width) > image_info.width() ||
+ yoffset < 0 ||
+ (yoffset as u32 + pixels.size.height) > image_info.height()
+ {
+ return self.webgl_error(InvalidValue);
+ }
+
+ // NB: format and internal_format must match.
+ if format != image_info.internal_format().unwrap() ||
+ data_type != image_info.data_type().unwrap()
+ {
+ return self.webgl_error(InvalidOperation);
+ }
+
let settings = self.texture_unpacking_settings.get();
+ let dest_premultiplied = settings.contains(TextureUnpacking::PREMULTIPLY_ALPHA);
- let alpha_treatment = match (
- pixels.premultiplied,
- settings.contains(TextureUnpacking::PREMULTIPLY_ALPHA),
- ) {
+ let alpha_treatment = match (pixels.premultiplied, dest_premultiplied) {
(true, false) => Some(AlphaTreatment::Unmultiply),
(false, true) => Some(AlphaTreatment::Premultiply),
_ => None,
@@ -794,7 +765,7 @@ impl WebGLRenderingContext {
YAxisTreatment::AsIs
};
- let buff = self.prepare_pixels(
+ let buff = webgl::prepare_pixels(
format,
data_type,
pixels.size,
@@ -805,28 +776,6 @@ impl WebGLRenderingContext {
pixels.data,
);
- // We have already validated level
- let image_info = texture.image_info_for_target(&target, level);
-
- // GL_INVALID_VALUE is generated if:
- // - xoffset or yoffset is less than 0
- // - x offset plus the width is greater than the texture width
- // - y offset plus the height is greater than the texture height
- if xoffset < 0 ||
- (xoffset as u32 + pixels.size.width) > image_info.width() ||
- yoffset < 0 ||
- (yoffset as u32 + pixels.size.height) > image_info.height()
- {
- return self.webgl_error(InvalidValue);
- }
-
- // NB: format and internal_format must match.
- if format != image_info.internal_format().unwrap() ||
- data_type != image_info.data_type().unwrap()
- {
- return self.webgl_error(InvalidOperation);
- }
-
// TODO(emilio): convert colorspace if requested
let (sender, receiver) = ipc::bytes_channel().unwrap();
self.send_command(WebGLCommand::TexSubImage2D {