mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Update to gleam 0.5
This commit is contained in:
parent
696084863c
commit
0f91712800
18 changed files with 473 additions and 399 deletions
|
@ -16,11 +16,11 @@ compositing = {path = "../compositing"}
|
|||
cssparser = "0.23.0"
|
||||
euclid = "0.17"
|
||||
fnv = "1.0"
|
||||
gleam = "0.4.34"
|
||||
gleam = "0.5"
|
||||
ipc-channel = "0.10"
|
||||
log = "0.4"
|
||||
num-traits = "0.1.32"
|
||||
offscreen_gl_context = { version = "0.15", features = ["serde", "osmesa"] }
|
||||
offscreen_gl_context = {version = "0.16", features = ["serde", "osmesa"]}
|
||||
serde_bytes = "0.10"
|
||||
servo_config = {path = "../config"}
|
||||
webrender = {git = "https://github.com/servo/webrender"}
|
||||
|
|
|
@ -648,6 +648,7 @@ struct DOMToTextureData {
|
|||
pub struct WebGLImpl;
|
||||
|
||||
impl WebGLImpl {
|
||||
#[allow(unsafe_code)]
|
||||
pub fn apply<Native: NativeGLContextMethods>(ctx: &GLContext<Native>, command: WebGLCommand) {
|
||||
match command {
|
||||
WebGLCommand::GetContextAttributes(sender) =>
|
||||
|
@ -758,18 +759,11 @@ impl WebGLImpl {
|
|||
Self::get_renderbuffer_parameter(ctx.gl(), target, pname, chan),
|
||||
WebGLCommand::GetFramebufferAttachmentParameter(target, attachment, pname, chan) =>
|
||||
Self::get_framebuffer_attachment_parameter(ctx.gl(), target, attachment, pname, chan),
|
||||
WebGLCommand::GetVertexAttrib(index, pname, chan) =>
|
||||
Self::vertex_attrib(ctx.gl(), index, pname, chan),
|
||||
WebGLCommand::GetVertexAttribOffset(index, pname, chan) =>
|
||||
Self::vertex_attrib_offset(ctx.gl(), index, pname, chan),
|
||||
WebGLCommand::GetParameter(param_id, chan) =>
|
||||
Self::parameter(ctx.gl(), param_id, chan),
|
||||
WebGLCommand::GetTexParameter(target, pname, chan) =>
|
||||
Self::get_tex_parameter(ctx.gl(), target, pname, chan),
|
||||
WebGLCommand::GetProgramParameter(program_id, param_id, chan) =>
|
||||
Self::program_parameter(ctx.gl(), program_id, param_id, chan),
|
||||
WebGLCommand::GetShaderParameter(shader_id, param_id, chan) =>
|
||||
Self::shader_parameter(ctx.gl(), shader_id, param_id, chan),
|
||||
WebGLCommand::GetTexParameter(target, pname, chan) => {
|
||||
chan.send(ctx.gl().get_tex_parameter_iv(target, pname)).unwrap();
|
||||
}
|
||||
WebGLCommand::GetShaderPrecisionFormat(shader_type, precision_type, chan) =>
|
||||
Self::shader_precision_format(ctx.gl(), shader_type, precision_type, chan),
|
||||
WebGLCommand::GetExtensions(chan) =>
|
||||
|
@ -864,9 +858,6 @@ impl WebGLImpl {
|
|||
ctx.gl().vertex_attrib_pointer_f32(attrib_id, size, normalized, stride, offset),
|
||||
WebGLCommand::VertexAttribPointer(attrib_id, size, data_type, normalized, stride, offset) =>
|
||||
ctx.gl().vertex_attrib_pointer(attrib_id, size, data_type, normalized, stride, offset),
|
||||
WebGLCommand::GetViewport(sender) => {
|
||||
sender.send(ctx.gl().get_viewport()).unwrap();
|
||||
}
|
||||
WebGLCommand::SetViewport(x, y, width, height) => {
|
||||
ctx.gl().viewport(x, y, width, height);
|
||||
}
|
||||
|
@ -895,10 +886,119 @@ impl WebGLImpl {
|
|||
ctx.gl().delete_vertex_arrays(&[id.get()]),
|
||||
WebGLCommand::BindVertexArray(id) =>
|
||||
ctx.gl().bind_vertex_array(id.map_or(0, WebGLVertexArrayId::get)),
|
||||
WebGLCommand::AliasedPointSizeRange(sender) =>
|
||||
sender.send(ctx.gl().alias_point_size_range()).unwrap(),
|
||||
WebGLCommand::AliasedLineWidthRange(sender) => {
|
||||
sender.send(ctx.gl().alias_line_width_range()).unwrap()
|
||||
WebGLCommand::GetParameterBool(param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_boolean_v(param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0] != 0).unwrap()
|
||||
}
|
||||
WebGLCommand::GetParameterInt(param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_integer_v(param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0]).unwrap()
|
||||
}
|
||||
WebGLCommand::GetParameterInt4(param, sender) => {
|
||||
let mut value = [0; 4];
|
||||
unsafe {
|
||||
ctx.gl().get_integer_v(param as u32, &mut value);
|
||||
}
|
||||
sender.send(value).unwrap()
|
||||
}
|
||||
WebGLCommand::GetParameterFloat(param, sender) => {
|
||||
let mut value = [0.];
|
||||
unsafe {
|
||||
ctx.gl().get_float_v(param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0]).unwrap()
|
||||
}
|
||||
WebGLCommand::GetParameterFloat2(param, sender) => {
|
||||
let mut value = [0.; 2];
|
||||
unsafe {
|
||||
ctx.gl().get_float_v(param as u32, &mut value);
|
||||
}
|
||||
sender.send(value).unwrap()
|
||||
}
|
||||
WebGLCommand::GetProgramParameterBool(program, param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_program_iv(program.get(), param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0] != 0).unwrap()
|
||||
}
|
||||
WebGLCommand::GetProgramParameterInt(program, param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_program_iv(program.get(), param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0]).unwrap()
|
||||
}
|
||||
WebGLCommand::GetShaderParameterBool(shader, param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_shader_iv(shader.get(), param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0] != 0).unwrap()
|
||||
}
|
||||
WebGLCommand::GetShaderParameterInt(shader, param, sender) => {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_shader_iv(shader.get(), param as u32, &mut value);
|
||||
}
|
||||
sender.send(value[0]).unwrap()
|
||||
}
|
||||
WebGLCommand::GetVertexAttribBool(index, param, sender) => {
|
||||
// FIXME(nox): https://github.com/servo/servo/issues/20608
|
||||
let mut max = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_integer_v(gl::MAX_VERTEX_ATTRIBS, &mut max);
|
||||
}
|
||||
let result = if index >= max[0] as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_vertex_attrib_iv(index, param as u32, &mut value);
|
||||
}
|
||||
Ok(value[0] != 0)
|
||||
};
|
||||
sender.send(result).unwrap();
|
||||
}
|
||||
WebGLCommand::GetVertexAttribInt(index, param, sender) => {
|
||||
// FIXME(nox): https://github.com/servo/servo/issues/20608
|
||||
let mut max = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_integer_v(gl::MAX_VERTEX_ATTRIBS, &mut max);
|
||||
}
|
||||
let result = if index >= max[0] as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
let mut value = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_vertex_attrib_iv(index, param as u32, &mut value);
|
||||
}
|
||||
Ok(value[0])
|
||||
};
|
||||
sender.send(result).unwrap();
|
||||
}
|
||||
WebGLCommand::GetVertexAttribFloat4(index, param, sender) => {
|
||||
// FIXME(nox): https://github.com/servo/servo/issues/20608
|
||||
let mut max = [0];
|
||||
unsafe {
|
||||
ctx.gl().get_integer_v(gl::MAX_VERTEX_ATTRIBS, &mut max);
|
||||
}
|
||||
let result = if index >= max[0] as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
let mut value = [0.; 4];
|
||||
unsafe {
|
||||
ctx.gl().get_vertex_attrib_fv(index, param as u32, &mut value);
|
||||
}
|
||||
Ok(value)
|
||||
};
|
||||
sender.send(result).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -923,11 +1023,18 @@ impl WebGLImpl {
|
|||
chan.send(result.into()).unwrap()
|
||||
}
|
||||
|
||||
fn active_attrib(gl: &gl::Gl,
|
||||
program_id: WebGLProgramId,
|
||||
index: u32,
|
||||
chan: WebGLSender<WebGLResult<(i32, u32, String)>>) {
|
||||
let result = if index >= gl.get_program_iv(program_id.get(), gl::ACTIVE_ATTRIBUTES) as u32 {
|
||||
#[allow(unsafe_code)]
|
||||
fn active_attrib(
|
||||
gl: &gl::Gl,
|
||||
program_id: WebGLProgramId,
|
||||
index: u32,
|
||||
chan: WebGLSender<WebGLResult<(i32, u32, String)>>,
|
||||
) {
|
||||
let mut max = [0];
|
||||
unsafe {
|
||||
gl.get_program_iv(program_id.get(), gl::ACTIVE_ATTRIBUTES, &mut max);
|
||||
}
|
||||
let result = if index >= max[0] as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
Ok(gl.get_active_attrib(program_id.get(), index))
|
||||
|
@ -935,11 +1042,16 @@ impl WebGLImpl {
|
|||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn active_uniform(gl: &gl::Gl,
|
||||
program_id: WebGLProgramId,
|
||||
index: u32,
|
||||
chan: WebGLSender<WebGLResult<(i32, u32, String)>>) {
|
||||
let result = if index >= gl.get_program_iv(program_id.get(), gl::ACTIVE_UNIFORMS) as u32 {
|
||||
let mut max = [0];
|
||||
unsafe {
|
||||
gl.get_program_iv(program_id.get(), gl::ACTIVE_UNIFORMS, &mut max);
|
||||
}
|
||||
let result = if index >= max[0] as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
Ok(gl.get_active_uniform(program_id.get(), index))
|
||||
|
@ -962,167 +1074,11 @@ impl WebGLImpl {
|
|||
chan.send(attrib_location).unwrap();
|
||||
}
|
||||
|
||||
fn parameter(gl: &gl::Gl,
|
||||
param_id: u32,
|
||||
chan: WebGLSender<WebGLResult<WebGLParameter>>) {
|
||||
let result = match param_id {
|
||||
gl::ACTIVE_TEXTURE |
|
||||
gl::ALPHA_BITS |
|
||||
gl::BLEND_DST_ALPHA |
|
||||
gl::BLEND_DST_RGB |
|
||||
gl::BLEND_EQUATION_ALPHA |
|
||||
gl::BLEND_EQUATION_RGB |
|
||||
gl::BLEND_SRC_ALPHA |
|
||||
gl::BLEND_SRC_RGB |
|
||||
gl::BLUE_BITS |
|
||||
gl::CULL_FACE_MODE |
|
||||
gl::DEPTH_BITS |
|
||||
gl::DEPTH_FUNC |
|
||||
gl::FRONT_FACE |
|
||||
//gl::GENERATE_MIPMAP_HINT |
|
||||
gl::GREEN_BITS |
|
||||
//gl::IMPLEMENTATION_COLOR_READ_FORMAT |
|
||||
//gl::IMPLEMENTATION_COLOR_READ_TYPE |
|
||||
gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS |
|
||||
gl::MAX_CUBE_MAP_TEXTURE_SIZE |
|
||||
//gl::MAX_FRAGMENT_UNIFORM_VECTORS |
|
||||
gl::MAX_RENDERBUFFER_SIZE |
|
||||
gl::MAX_TEXTURE_IMAGE_UNITS |
|
||||
gl::MAX_TEXTURE_SIZE |
|
||||
//gl::MAX_VARYING_VECTORS |
|
||||
gl::MAX_VERTEX_ATTRIBS |
|
||||
gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS |
|
||||
//gl::MAX_VERTEX_UNIFORM_VECTORS |
|
||||
gl::PACK_ALIGNMENT |
|
||||
gl::RED_BITS |
|
||||
gl::SAMPLE_BUFFERS |
|
||||
gl::SAMPLES |
|
||||
gl::STENCIL_BACK_FAIL |
|
||||
gl::STENCIL_BACK_FUNC |
|
||||
gl::STENCIL_BACK_PASS_DEPTH_FAIL |
|
||||
gl::STENCIL_BACK_PASS_DEPTH_PASS |
|
||||
gl::STENCIL_BACK_REF |
|
||||
gl::STENCIL_BACK_VALUE_MASK |
|
||||
gl::STENCIL_BACK_WRITEMASK |
|
||||
gl::STENCIL_BITS |
|
||||
gl::STENCIL_CLEAR_VALUE |
|
||||
gl::STENCIL_FAIL |
|
||||
gl::STENCIL_FUNC |
|
||||
gl::STENCIL_PASS_DEPTH_FAIL |
|
||||
gl::STENCIL_PASS_DEPTH_PASS |
|
||||
gl::STENCIL_REF |
|
||||
gl::STENCIL_VALUE_MASK |
|
||||
gl::STENCIL_WRITEMASK |
|
||||
gl::SUBPIXEL_BITS |
|
||||
gl::UNPACK_ALIGNMENT |
|
||||
gl::FRAGMENT_SHADER_DERIVATIVE_HINT =>
|
||||
//gl::UNPACK_COLORSPACE_CONVERSION_WEBGL =>
|
||||
Ok(WebGLParameter::Int(gl.get_integer_v(param_id))),
|
||||
|
||||
gl::BLEND |
|
||||
gl::CULL_FACE |
|
||||
gl::DEPTH_TEST |
|
||||
gl::DEPTH_WRITEMASK |
|
||||
gl::DITHER |
|
||||
gl::POLYGON_OFFSET_FILL |
|
||||
gl::SAMPLE_COVERAGE_INVERT |
|
||||
gl::STENCIL_TEST =>
|
||||
//gl::UNPACK_FLIP_Y_WEBGL |
|
||||
//gl::UNPACK_PREMULTIPLY_ALPHA_WEBGL =>
|
||||
Ok(WebGLParameter::Bool(gl.get_boolean_v(param_id) != 0)),
|
||||
|
||||
gl::DEPTH_CLEAR_VALUE |
|
||||
gl::LINE_WIDTH |
|
||||
gl::POLYGON_OFFSET_FACTOR |
|
||||
gl::POLYGON_OFFSET_UNITS |
|
||||
gl::SAMPLE_COVERAGE_VALUE =>
|
||||
Ok(WebGLParameter::Float(gl.get_float_v(param_id))),
|
||||
|
||||
gl::VERSION => Ok(WebGLParameter::String("WebGL 1.0".to_owned())),
|
||||
gl::RENDERER |
|
||||
gl::VENDOR => Ok(WebGLParameter::String("Mozilla/Servo".to_owned())),
|
||||
gl::SHADING_LANGUAGE_VERSION => Ok(WebGLParameter::String("WebGL GLSL ES 1.0".to_owned())),
|
||||
|
||||
// TODO(zbarsky, emilio): Implement support for the following valid parameters
|
||||
// Float32Array
|
||||
gl::ALIASED_LINE_WIDTH_RANGE |
|
||||
//gl::ALIASED_POINT_SIZE_RANGE |
|
||||
//gl::BLEND_COLOR |
|
||||
gl::COLOR_CLEAR_VALUE |
|
||||
gl::DEPTH_RANGE |
|
||||
|
||||
// WebGLBuffer
|
||||
gl::ARRAY_BUFFER_BINDING |
|
||||
gl::ELEMENT_ARRAY_BUFFER_BINDING |
|
||||
|
||||
// WebGLFrameBuffer
|
||||
gl::FRAMEBUFFER_BINDING |
|
||||
|
||||
// WebGLRenderBuffer
|
||||
gl::RENDERBUFFER_BINDING |
|
||||
|
||||
// WebGLProgram
|
||||
gl::CURRENT_PROGRAM |
|
||||
|
||||
// WebGLTexture
|
||||
gl::TEXTURE_BINDING_2D |
|
||||
gl::TEXTURE_BINDING_CUBE_MAP |
|
||||
|
||||
// sequence<GlBoolean>
|
||||
gl::COLOR_WRITEMASK |
|
||||
|
||||
// Uint32Array
|
||||
gl::COMPRESSED_TEXTURE_FORMATS |
|
||||
|
||||
// Int32Array
|
||||
gl::MAX_VIEWPORT_DIMS |
|
||||
gl::SCISSOR_BOX => Err(WebGLError::InvalidEnum),
|
||||
|
||||
// Invalid parameters
|
||||
_ => Err(WebGLError::InvalidEnum)
|
||||
};
|
||||
|
||||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn get_tex_parameter(gl: &gl::Gl,
|
||||
target: u32,
|
||||
pname: u32,
|
||||
chan: WebGLSender<i32> ) {
|
||||
let result = gl.get_tex_parameter_iv(target, pname);
|
||||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn finish(gl: &gl::Gl, chan: WebGLSender<()>) {
|
||||
gl.finish();
|
||||
chan.send(()).unwrap();
|
||||
}
|
||||
|
||||
fn vertex_attrib(gl: &gl::Gl,
|
||||
index: u32,
|
||||
pname: u32,
|
||||
chan: WebGLSender<WebGLResult<WebGLParameter>>) {
|
||||
let result = if index >= gl.get_integer_v(gl::MAX_VERTEX_ATTRIBS) as u32 {
|
||||
Err(WebGLError::InvalidValue)
|
||||
} else {
|
||||
match pname {
|
||||
gl::VERTEX_ATTRIB_ARRAY_ENABLED |
|
||||
gl::VERTEX_ATTRIB_ARRAY_NORMALIZED =>
|
||||
Ok(WebGLParameter::Bool(gl.get_vertex_attrib_iv(index, pname) != 0)),
|
||||
gl::VERTEX_ATTRIB_ARRAY_SIZE |
|
||||
gl::VERTEX_ATTRIB_ARRAY_STRIDE |
|
||||
gl::VERTEX_ATTRIB_ARRAY_TYPE =>
|
||||
Ok(WebGLParameter::Int(gl.get_vertex_attrib_iv(index, pname))),
|
||||
gl::CURRENT_VERTEX_ATTRIB =>
|
||||
Ok(WebGLParameter::FloatArray(gl.get_vertex_attrib_fv(index, pname))),
|
||||
// gl::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING should return WebGLBuffer
|
||||
_ => Err(WebGLError::InvalidEnum),
|
||||
}
|
||||
};
|
||||
|
||||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn vertex_attrib_offset(gl: &gl::Gl,
|
||||
index: u32,
|
||||
pname: u32,
|
||||
|
@ -1131,41 +1087,6 @@ impl WebGLImpl {
|
|||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn program_parameter(gl: &gl::Gl,
|
||||
program_id: WebGLProgramId,
|
||||
param_id: u32,
|
||||
chan: WebGLSender<WebGLResult<WebGLParameter>>) {
|
||||
let result = match param_id {
|
||||
gl::DELETE_STATUS |
|
||||
gl::LINK_STATUS |
|
||||
gl::VALIDATE_STATUS =>
|
||||
Ok(WebGLParameter::Bool(gl.get_program_iv(program_id.get(), param_id) != 0)),
|
||||
gl::ATTACHED_SHADERS |
|
||||
gl::ACTIVE_ATTRIBUTES |
|
||||
gl::ACTIVE_UNIFORMS =>
|
||||
Ok(WebGLParameter::Int(gl.get_program_iv(program_id.get(), param_id))),
|
||||
_ => Err(WebGLError::InvalidEnum),
|
||||
};
|
||||
|
||||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn shader_parameter(gl: &gl::Gl,
|
||||
shader_id: WebGLShaderId,
|
||||
param_id: u32,
|
||||
chan: WebGLSender<WebGLResult<WebGLParameter>>) {
|
||||
let result = match param_id {
|
||||
gl::SHADER_TYPE =>
|
||||
Ok(WebGLParameter::Int(gl.get_shader_iv(shader_id.get(), param_id))),
|
||||
gl::DELETE_STATUS |
|
||||
gl::COMPILE_STATUS =>
|
||||
Ok(WebGLParameter::Bool(gl.get_shader_iv(shader_id.get(), param_id) != 0)),
|
||||
_ => Err(WebGLError::InvalidEnum),
|
||||
};
|
||||
|
||||
chan.send(result).unwrap();
|
||||
}
|
||||
|
||||
fn shader_precision_format(gl: &gl::Gl,
|
||||
shader_type: u32,
|
||||
precision_type: u32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue