Skip to content

Commit

Permalink
Update to gleam 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed May 5, 2018
1 parent 6960848 commit 0f91712
Show file tree
Hide file tree
Showing 18 changed files with 473 additions and 399 deletions.
71 changes: 36 additions & 35 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions components/canvas/Cargo.toml
Expand Up @@ -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"}
Expand Down
349 changes: 135 additions & 214 deletions components/canvas/webgl_thread.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion components/canvas_traits/Cargo.toml
Expand Up @@ -13,11 +13,12 @@ path = "lib.rs"
cssparser = "0.23.0"
euclid = "0.17"
ipc-channel = "0.10"
gleam = "0.5"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
nonzero = {path = "../nonzero"}
offscreen_gl_context = { version = "0.15", features = ["serde"] }
offscreen_gl_context = {version = "0.16", features = ["serde"]}
serde = "1.0"
serde_bytes = "0.10"
servo_config = {path = "../config"}
Expand Down
1 change: 1 addition & 0 deletions components/canvas_traits/lib.rs
Expand Up @@ -9,6 +9,7 @@

extern crate cssparser;
extern crate euclid;
extern crate gleam;
extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
extern crate malloc_size_of;
Expand Down
205 changes: 174 additions & 31 deletions components/canvas_traits/webgl.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use euclid::Size2D;
use gleam::gl;
use nonzero::NonZeroU32;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use serde_bytes::ByteBuf;
Expand Down Expand Up @@ -206,16 +207,12 @@ pub enum WebGLCommand {
FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>),
FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32),
GetExtensions(WebGLSender<String>),
GetParameter(u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetTexParameter(u32, u32, WebGLSender<i32>),
GetProgramParameter(WebGLProgramId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderParameter(WebGLShaderId, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<(i32, i32, i32)>),
GetActiveAttrib(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetActiveUniform(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetAttribLocation(WebGLProgramId, String, WebGLSender<Option<i32>>),
GetUniformLocation(WebGLProgramId, String, WebGLSender<Option<i32>>),
GetVertexAttrib(u32, u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetVertexAttribOffset(u32, u32, WebGLSender<isize>),
GetShaderInfoLog(WebGLShaderId, WebGLSender<String>),
GetProgramInfoLog(WebGLProgramId, WebGLSender<String>),
Expand Down Expand Up @@ -261,7 +258,6 @@ pub enum WebGLCommand {
VertexAttrib(u32, f32, f32, f32, f32),
VertexAttribPointer(u32, i32, u32, bool, i32, u32),
VertexAttribPointer2f(u32, i32, bool, i32, u32),
GetViewport(WebGLSender<(i32, i32, i32, i32)>),
SetViewport(i32, i32, i32, i32),
TexImage2D(u32, i32, i32, i32, i32, u32, u32, ByteBuf),
TexParameteri(u32, u32, i32),
Expand All @@ -275,8 +271,18 @@ pub enum WebGLCommand {
CreateVertexArray(WebGLSender<Option<WebGLVertexArrayId>>),
DeleteVertexArray(WebGLVertexArrayId),
BindVertexArray(Option<WebGLVertexArrayId>),
AliasedPointSizeRange(WebGLSender<(f32, f32)>),
AliasedLineWidthRange(WebGLSender<(f32, f32)>),
GetParameterBool(ParameterBool, WebGLSender<bool>),
GetParameterInt(ParameterInt, WebGLSender<i32>),
GetParameterInt4(ParameterInt4, WebGLSender<[i32; 4]>),
GetParameterFloat(ParameterFloat, WebGLSender<f32>),
GetParameterFloat2(ParameterFloat2, WebGLSender<[f32; 2]>),
GetProgramParameterBool(WebGLProgramId, ProgramParameterBool, WebGLSender<bool>),
GetProgramParameterInt(WebGLProgramId, ProgramParameterInt, WebGLSender<i32>),
GetShaderParameterBool(WebGLShaderId, ShaderParameterBool, WebGLSender<bool>),
GetShaderParameterInt(WebGLShaderId, ShaderParameterInt, WebGLSender<i32>),
GetVertexAttribBool(u32, VertexAttribBool, WebGLSender<WebGLResult<bool>>),
GetVertexAttribInt(u32, VertexAttribInt, WebGLSender<WebGLResult<i32>>),
GetVertexAttribFloat4(u32, VertexAttribFloat4, WebGLSender<WebGLResult<[f32; 4]>>),
}

macro_rules! define_resource_id_struct {
Expand Down Expand Up @@ -376,25 +382,8 @@ pub enum WebGLFramebufferBindingRequest {
Default,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebGLParameter {
Int(i32),
Bool(bool),
String(String),
Float(f32),
FloatArray(Vec<f32>),
Invalid,
}

pub type WebGLResult<T> = Result<T, WebGLError>;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebGLShaderParameter {
Int(i32),
Bool(bool),
Invalid,
}

pub type WebVRDeviceId = u32;

// WebVR commands that must be called in the WebGL render thread.
Expand Down Expand Up @@ -481,18 +470,14 @@ impl fmt::Debug for WebGLCommand {
FramebufferRenderbuffer(..) => "FramebufferRenderbuffer",
FramebufferTexture2D(..) => "FramebufferTexture2D",
GetExtensions(..) => "GetExtensions",
GetParameter(..) => "GetParameter",
GetTexParameter(..) => "GetTexParameter",
GetProgramParameter(..) => "GetProgramParameter",
GetShaderParameter(..) => "GetShaderParameter",
GetShaderPrecisionFormat(..) => "GetShaderPrecisionFormat",
GetActiveAttrib(..) => "GetActiveAttrib",
GetActiveUniform(..) => "GetActiveUniform",
GetAttribLocation(..) => "GetAttribLocation",
GetUniformLocation(..) => "GetUniformLocation",
GetShaderInfoLog(..) => "GetShaderInfoLog",
GetProgramInfoLog(..) => "GetProgramInfoLog",
GetVertexAttrib(..) => "GetVertexAttrib",
GetVertexAttribOffset(..) => "GetVertexAttribOffset",
GetFramebufferAttachmentParameter(..) => "GetFramebufferAttachmentParameter",
GetRenderbufferParameter(..) => "GetRenderbufferParameter",
Expand Down Expand Up @@ -536,7 +521,6 @@ impl fmt::Debug for WebGLCommand {
VertexAttrib(..) => "VertexAttrib",
VertexAttribPointer2f(..) => "VertexAttribPointer2f",
VertexAttribPointer(..) => "VertexAttribPointer",
GetViewport(..) => "GetViewport",
SetViewport(..) => "SetViewport",
TexImage2D(..) => "TexImage2D",
TexParameteri(..) => "TexParameteri",
Expand All @@ -550,10 +534,169 @@ impl fmt::Debug for WebGLCommand {
CreateVertexArray(..) => "CreateVertexArray",
DeleteVertexArray(..) => "DeleteVertexArray",
BindVertexArray(..) => "BindVertexArray",
AliasedPointSizeRange(..) => "AliasedPointSizeRange",
AliasedLineWidthRange(..) => "AliasedLineWidthRange",
GetParameterBool(..) => "GetParameterBool",
GetParameterInt(..) => "GetParameterInt",
GetParameterInt4(..) => "GetParameterInt4",
GetParameterFloat(..) => "GetParameterFloat",
GetParameterFloat2(..) => "GetParameterFloat2",
GetProgramParameterBool(..) => "GetProgramParameterBool",
GetProgramParameterInt(..) => "GetProgramParameterInt",
GetShaderParameterBool(..) => "GetShaderParameterBool",
GetShaderParameterInt(..) => "GetShaderParameterInt",
GetVertexAttribBool(..) => "GetVertexAttribBool",
GetVertexAttribInt(..) => "GetVertexAttribInt",
GetVertexAttribFloat4(..) => "GetVertexAttribFloat4",
};

write!(f, "CanvasWebGLMsg::{}(..)", name)
}
}

macro_rules! parameters {
($name:ident { $(
$variant:ident($kind:ident { $(
$param:ident = gl::$value:ident,
)+ }),
)+ }) => {
#[derive(Clone, Deserialize, Serialize)]
pub enum $name { $(
$variant($kind),
)+}

$(
#[derive(Clone, Deserialize, Serialize)]
#[repr(u32)]
pub enum $kind { $(
$param = gl::$value,
)+}
)+

impl $name {
pub fn from_u32(value: u32) -> WebGLResult<Self> {
match value {
$($(gl::$value => Ok($name::$variant($kind::$param)),)+)+
_ => Err(WebGLError::InvalidEnum)
}
}
}
}
}

parameters! {
Parameter {
Bool(ParameterBool {
Blend = gl::BLEND,
CullFace = gl::CULL_FACE,
DepthTest = gl::DEPTH_TEST,
DepthWritemask = gl::DEPTH_WRITEMASK,
Dither = gl::DITHER,
PolygonOffsetFill = gl::POLYGON_OFFSET_FILL,
SampleCoverageInvert = gl::SAMPLE_COVERAGE_INVERT,
StencilTest = gl::STENCIL_TEST,
}),
Int(ParameterInt {
ActiveTexture = gl::ACTIVE_TEXTURE,
AlphaBits = gl::ALPHA_BITS,
BlendDstAlpha = gl::BLEND_DST_ALPHA,
BlendDstRgb = gl::BLEND_DST_RGB,
BlendEquationAlpha = gl::BLEND_EQUATION_ALPHA,
BlendEquationRgb = gl::BLEND_EQUATION_RGB,
BlendSrcAlpha = gl::BLEND_SRC_ALPHA,
BlendSrcRgb = gl::BLEND_SRC_RGB,
BlueBits = gl::BLUE_BITS,
CullFaceMode = gl::CULL_FACE_MODE,
DepthBits = gl::DEPTH_BITS,
DepthFunc = gl::DEPTH_FUNC,
FrontFace = gl::FRONT_FACE,
GreenBits = gl::GREEN_BITS,
MaxCombinedTextureImageUnits = gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS,
MaxCubeMapTextureSize = gl::MAX_CUBE_MAP_TEXTURE_SIZE,
MaxRenderbufferSize = gl::MAX_RENDERBUFFER_SIZE,
MaxTextureImageUnits = gl::MAX_TEXTURE_IMAGE_UNITS,
MaxTextureSize = gl::MAX_TEXTURE_SIZE,
MaxVertexAttribs = gl::MAX_VERTEX_ATTRIBS,
MaxVertexTextureImageUnits = gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS,
PackAlignment = gl::PACK_ALIGNMENT,
RedBits = gl::RED_BITS,
SampleBuffers = gl::SAMPLE_BUFFERS,
Samples = gl::SAMPLES,
StencilBackFail = gl::STENCIL_BACK_FAIL,
StencilBackFunc = gl::STENCIL_BACK_FUNC,
StencilBackPassDepthFail = gl::STENCIL_BACK_PASS_DEPTH_FAIL,
StencilBackPassDepthPass = gl::STENCIL_BACK_PASS_DEPTH_PASS,
StencilBackRef = gl::STENCIL_BACK_REF,
StencilBackValueMask = gl::STENCIL_BACK_VALUE_MASK,
StencilBackWritemask = gl::STENCIL_BACK_WRITEMASK,
StencilBits = gl::STENCIL_BITS,
StencilClearValue = gl::STENCIL_CLEAR_VALUE,
StencilFail = gl::STENCIL_FAIL,
StencilFunc = gl::STENCIL_FUNC,
StencilPassDepthFail = gl::STENCIL_PASS_DEPTH_FAIL,
StencilPassDepthPass = gl::STENCIL_PASS_DEPTH_PASS,
StencilRef = gl::STENCIL_REF,
StencilValueMask = gl::STENCIL_VALUE_MASK,
StencilWritemask = gl::STENCIL_WRITEMASK,
SubpixelBits = gl::SUBPIXEL_BITS,
UnpackAlignment = gl::UNPACK_ALIGNMENT,
FragmentShaderDerivativeHint = gl::FRAGMENT_SHADER_DERIVATIVE_HINT,
}),
Int4(ParameterInt4 {
Viewport = gl::VIEWPORT,
}),
Float(ParameterFloat {
DepthClearValue = gl::DEPTH_CLEAR_VALUE,
LineWidth = gl::LINE_WIDTH,
PolygonOffsetFactor = gl::POLYGON_OFFSET_FACTOR,
PolygonOffsetUnits = gl::POLYGON_OFFSET_UNITS,
SampleCoverageValue = gl::SAMPLE_COVERAGE_VALUE,
}),
Float2(ParameterFloat2 {
AliasedPointSizeRange = gl::ALIASED_POINT_SIZE_RANGE,
AliasedLineWidthRange = gl::ALIASED_LINE_WIDTH_RANGE,
}),
}
}

parameters! {
ProgramParameter {
Bool(ProgramParameterBool {
DeleteStatus = gl::DELETE_STATUS,
LinkStatus = gl::LINK_STATUS,
ValidateStatus = gl::VALIDATE_STATUS,
}),
Int(ProgramParameterInt {
AttachedShaders = gl::ATTACHED_SHADERS,
ActiveAttributes = gl::ACTIVE_ATTRIBUTES,
ActiveUniforms = gl::ACTIVE_UNIFORMS,
}),
}
}

parameters! {
ShaderParameter {
Bool(ShaderParameterBool {
DeleteStatus = gl::DELETE_STATUS,
CompileStatus = gl::COMPILE_STATUS,
}),
Int(ShaderParameterInt {
ShaderType = gl::SHADER_TYPE,
}),
}
}

parameters! {
VertexAttrib {
Bool(VertexAttribBool {
VertexAttribArrayEnabled = gl::VERTEX_ATTRIB_ARRAY_ENABLED,
VertexAttribArrayNormalized = gl::VERTEX_ATTRIB_ARRAY_NORMALIZED,
}),
Int(VertexAttribInt {
VertexAttribArraySize = gl::VERTEX_ATTRIB_ARRAY_SIZE,
VertexAttribArrayStride = gl::VERTEX_ATTRIB_ARRAY_STRIDE,
VertexAttribArrayType = gl::VERTEX_ATTRIB_ARRAY_TYPE,
}),
Float4(VertexAttribFloat4 {
CurrentVertexAttrib = gl::CURRENT_VERTEX_ATTRIB,
}),
}
}
2 changes: 1 addition & 1 deletion components/compositing/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ default = []
[dependencies]
euclid = "0.17"
gfx_traits = {path = "../gfx_traits"}
gleam = { version = "0.4.34", optional = true }
gleam = {version = "0.5", optional = true}
image = "0.18"
ipc-channel = "0.10"
libc = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion components/compositing/compositor.rs
Expand Up @@ -276,7 +276,7 @@ impl webrender_api::RenderNotifier for RenderNotifier {
self.compositor_proxy.recomposite(CompositingReason::NewWebRenderFrame);
}

fn new_document_ready(
fn new_frame_ready(
&self,
_document_id: webrender_api::DocumentId,
scrolled: bool,
Expand Down
28 changes: 13 additions & 15 deletions components/layout/display_list/background.rs
Expand Up @@ -32,8 +32,8 @@ use style::values::generics::image::EndingShape as GenericEndingShape;
use style::values::generics::image::GradientItem as GenericGradientItem;
use style::values::specified::background::BackgroundRepeatKeyword;
use style::values::specified::position::{X, Y};
use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF, ExtendMode, ImageBorder};
use webrender_api::{GradientStop, LayoutSize, NinePatchDescriptor, NormalBorder};
use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF, ExtendMode, GradientStop};
use webrender_api::{LayoutSize, NinePatchBorder, NinePatchBorderSource, NormalBorder};

/// A helper data structure for gradients.
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -791,22 +791,20 @@ pub fn build_image_border_details(
let corners = &border_style_struct.border_image_slice.offsets;
let border_image_repeat = &border_style_struct.border_image_repeat;
if let Some(image_key) = webrender_image.key {
Some(BorderDetails::Image(ImageBorder {
image_key: image_key,
patch: NinePatchDescriptor {
width: webrender_image.width,
height: webrender_image.height,
slice: SideOffsets2D::new(
corners.0.resolve(webrender_image.height),
corners.1.resolve(webrender_image.width),
corners.2.resolve(webrender_image.height),
corners.3.resolve(webrender_image.width),
),
},
Some(BorderDetails::Image(NinePatchBorder {
source: NinePatchBorderSource::Image(image_key),
width: webrender_image.width,
height: webrender_image.height,
slice: SideOffsets2D::new(
corners.0.resolve(webrender_image.height),
corners.1.resolve(webrender_image.width),
corners.2.resolve(webrender_image.height),
corners.3.resolve(webrender_image.width),
),
fill: border_style_struct.border_image_slice.fill,
outset: outset,
repeat_horizontal: border_image_repeat.0.to_layout(),
repeat_vertical: border_image_repeat.1.to_layout(),
outset: outset,
}))
} else {
None
Expand Down

0 comments on commit 0f91712

Please sign in to comment.