2015-05-20 23:42:06 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#![crate_name = "canvas_traits"]
|
|
|
|
#![crate_type = "rlib"]
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
#![feature(core)]
|
2015-06-25 21:03:15 +03:00
|
|
|
#![feature(nonzero)]
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
extern crate core;
|
2015-05-20 23:42:06 +03:00
|
|
|
extern crate azure;
|
2015-06-19 05:50:22 +03:00
|
|
|
extern crate euclid;
|
2015-05-20 23:42:06 +03:00
|
|
|
extern crate cssparser;
|
|
|
|
extern crate gfx_traits;
|
2015-07-25 02:14:59 +03:00
|
|
|
extern crate ipc_channel;
|
2015-05-20 23:42:06 +03:00
|
|
|
extern crate layers;
|
2015-06-01 16:37:48 +03:00
|
|
|
extern crate offscreen_gl_context;
|
2015-05-20 23:42:06 +03:00
|
|
|
|
2015-06-12 12:27:07 +03:00
|
|
|
use azure::azure::{AzFloat, AzColor};
|
2015-05-20 23:42:06 +03:00
|
|
|
use azure::azure_hl::{DrawTarget, Pattern, ColorPattern};
|
|
|
|
use azure::azure_hl::{GradientStop, LinearGradientPattern, RadialGradientPattern, ExtendMode};
|
|
|
|
use azure::azure_hl::{JoinStyle, CapStyle, CompositionOp};
|
2015-06-13 10:49:50 +03:00
|
|
|
use azure::azure_hl::{SurfacePattern, SurfaceFormat};
|
2015-05-20 23:42:06 +03:00
|
|
|
use cssparser::RGBA;
|
2015-06-19 05:50:22 +03:00
|
|
|
use euclid::matrix2d::Matrix2D;
|
|
|
|
use euclid::point::Point2D;
|
|
|
|
use euclid::rect::Rect;
|
|
|
|
use euclid::size::Size2D;
|
2015-05-20 23:42:06 +03:00
|
|
|
use gfx_traits::color;
|
|
|
|
use std::sync::mpsc::{Sender};
|
|
|
|
use layers::platform::surface::NativeSurface;
|
2015-06-01 16:37:48 +03:00
|
|
|
use offscreen_gl_context::GLContextAttributes;
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
use core::nonzero::NonZero;
|
2015-07-25 02:14:59 +03:00
|
|
|
use ipc_channel::ipc::IpcSharedMemory;
|
2015-05-20 23:42:06 +03:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum CanvasMsg {
|
|
|
|
Canvas2d(Canvas2dMsg),
|
|
|
|
Common(CanvasCommonMsg),
|
|
|
|
WebGL(CanvasWebGLMsg),
|
|
|
|
}
|
|
|
|
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum CanvasCommonMsg {
|
|
|
|
Close,
|
|
|
|
Recreate(Size2D<i32>),
|
2015-07-25 02:14:59 +03:00
|
|
|
SendPixelContents(Sender<IpcSharedMemory>),
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
SendNativeSurface(Sender<NativeSurface>),
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:42:06 +03:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum Canvas2dMsg {
|
|
|
|
Arc(Point2D<f32>, f32, f32, f32, bool),
|
|
|
|
ArcTo(Point2D<f32>, Point2D<f32>, f32),
|
|
|
|
DrawImage(Vec<u8>, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
|
|
|
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
|
|
|
BeginPath,
|
|
|
|
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
|
|
|
ClearRect(Rect<f32>),
|
|
|
|
Clip,
|
|
|
|
ClosePath,
|
|
|
|
Fill,
|
|
|
|
FillRect(Rect<f32>),
|
|
|
|
GetImageData(Rect<f64>, Size2D<f64>, Sender<Vec<u8>>),
|
|
|
|
LineTo(Point2D<f32>),
|
|
|
|
MoveTo(Point2D<f32>),
|
|
|
|
PutImageData(Vec<u8>, Rect<f64>, Option<Rect<f64>>),
|
|
|
|
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
|
|
|
Rect(Rect<f32>),
|
|
|
|
RestoreContext,
|
|
|
|
SaveContext,
|
|
|
|
StrokeRect(Rect<f32>),
|
|
|
|
Stroke,
|
|
|
|
SetFillStyle(FillOrStrokeStyle),
|
|
|
|
SetStrokeStyle(FillOrStrokeStyle),
|
|
|
|
SetLineWidth(f32),
|
|
|
|
SetLineCap(LineCapStyle),
|
|
|
|
SetLineJoin(LineJoinStyle),
|
|
|
|
SetMiterLimit(f32),
|
|
|
|
SetGlobalAlpha(f32),
|
|
|
|
SetGlobalComposition(CompositionOrBlending),
|
|
|
|
SetTransform(Matrix2D<f32>),
|
2015-06-12 12:27:07 +03:00
|
|
|
SetShadowOffsetX(f64),
|
|
|
|
SetShadowOffsetY(f64),
|
|
|
|
SetShadowBlur(f64),
|
2015-06-12 19:22:54 +03:00
|
|
|
SetShadowColor(RGBA),
|
2015-05-20 23:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum CanvasWebGLMsg {
|
2015-06-01 16:37:48 +03:00
|
|
|
GetContextAttributes(Sender<GLContextAttributes>),
|
2015-06-14 00:05:08 +03:00
|
|
|
ActiveTexture(u32),
|
|
|
|
BlendColor(f32, f32, f32, f32),
|
|
|
|
BlendEquation(u32),
|
|
|
|
BlendEquationSeparate(u32, u32),
|
|
|
|
BlendFunc(u32, u32),
|
|
|
|
BlendFuncSeparate(u32, u32, u32, u32),
|
2015-05-20 23:42:06 +03:00
|
|
|
AttachShader(u32, u32),
|
|
|
|
BufferData(u32, Vec<f32>, u32),
|
|
|
|
Clear(u32),
|
|
|
|
ClearColor(f32, f32, f32, f32),
|
|
|
|
CompileShader(u32),
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
CreateBuffer(Sender<Option<NonZero<u32>>>),
|
|
|
|
CreateFramebuffer(Sender<Option<NonZero<u32>>>),
|
|
|
|
CreateRenderbuffer(Sender<Option<NonZero<u32>>>),
|
|
|
|
CreateTexture(Sender<Option<NonZero<u32>>>),
|
|
|
|
CreateProgram(Sender<Option<NonZero<u32>>>),
|
|
|
|
CreateShader(u32, Sender<Option<NonZero<u32>>>),
|
|
|
|
DeleteBuffer(u32),
|
|
|
|
DeleteFramebuffer(u32),
|
|
|
|
DeleteRenderbuffer(u32),
|
|
|
|
DeleteTexture(u32),
|
|
|
|
DeleteProgram(u32),
|
|
|
|
DeleteShader(u32),
|
|
|
|
BindBuffer(u32, u32),
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
BindFramebuffer(u32, WebGLFramebufferBindingRequest),
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
BindRenderbuffer(u32, u32),
|
|
|
|
BindTexture(u32, u32),
|
2015-05-20 23:42:06 +03:00
|
|
|
DrawArrays(u32, i32, i32),
|
|
|
|
EnableVertexAttribArray(u32),
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
GetShaderInfoLog(u32, Sender<Option<String>>),
|
|
|
|
GetShaderParameter(u32, u32, Sender<WebGLShaderParameter>),
|
|
|
|
GetAttribLocation(u32, String, Sender<Option<i32>>),
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
GetUniformLocation(u32, String, Sender<Option<i32>>),
|
2015-05-20 23:42:06 +03:00
|
|
|
LinkProgram(u32),
|
servo: Merge #6293 - Implement new WebGL interfaces and methods (from emilio:webgl-objects); r=nox
This commit implements:
* WebGLFramebuffer
* WebGLRenderbuffer
* WebGLTexture
And adds the following methods to `WebGLRenderingContext`:
* create{Texture,Framebuffer,Renderbuffer}
* bind{Texture,Framebuffer,Renderbuffer}
* destroy{Buffer,Texture,Framebuffer,Renderbuffer}
Fixes:
* WebGLUniform location shouldn't inherit from WebGLObject.
Known Issues:
* WebGL objects have to be destroyed on drop, we may want to keep a reference to the context, or maybe a clone of the renderer to achieve this
Also refactors a huge part of the current implementation, to allow
failing on creation of different WebGL objects.
Blocked on https://github.com/servo/gleam/pull/22
A reftest for most of the added functionality is not doable right now,
we need a few more functions in order to upload a texture, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: e09c555a41b0803388e54013ac8885fb789a0fa6
2015-06-09 18:06:37 +03:00
|
|
|
ShaderSource(u32, String),
|
|
|
|
Uniform4fv(i32, Vec<f32>),
|
2015-05-20 23:42:06 +03:00
|
|
|
UseProgram(u32),
|
|
|
|
VertexAttribPointer2f(u32, i32, bool, i32, i64),
|
|
|
|
Viewport(i32, i32, i32, i32),
|
2015-06-01 18:20:14 +03:00
|
|
|
DrawingBufferWidth(Sender<i32>),
|
|
|
|
DrawingBufferHeight(Sender<i32>),
|
2015-05-20 23:42:06 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
pub enum WebGLError {
|
|
|
|
InvalidEnum,
|
|
|
|
InvalidOperation,
|
|
|
|
InvalidValue,
|
|
|
|
OutOfMemory,
|
|
|
|
ContextLost,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type WebGLResult<T> = Result<T, WebGLError>;
|
|
|
|
|
2015-05-20 23:42:06 +03:00
|
|
|
#[derive(Clone)]
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
pub enum WebGLFramebufferBindingRequest {
|
|
|
|
Explicit(u32),
|
|
|
|
Default,
|
2015-05-20 23:42:06 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #6380 - Refactor WebGL implementation to move logic inside the DOM interfaces (from emilio:webgl-refactoring); r=jdm
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will probably want to keep track of them from the context before).
Some concerns:
**Trait method repetition**:
I'm aware that the traits `WebGL{Buffer,Renderbuffer,Framebuffer,Texture}Helpers` are basically the same, but `delete()` and `id()` methods are everywhere. I've thought something like:
```rust
pub trait WebGLIdentifiable {
type WebGLId; // id is sometimes i32 (see WebGLUniformLocation)
fn id(&self) -> Self::WebGLId;
}
pub trait WebGLBindable {
fn bind(&self);
}
pub trait WebGLDeletable {
fn delete(&self);
}
```
But I'd want to know your opinion first.
**`renderer` repetition**:
Thought of moving the field: `renderer: Sender<CanvasMsg>` to `WebGLObject`, but I think it makes it way more complicated to read, and also a bit unnecessary, at least IMO (`WebGLObject` will never interact with the field directly). It would also mean that all `WebGLObject`s should have one, which is true at this moment, but maybe not with WebGL 2, for example.
Source-Repo: https://github.com/servo/servo
Source-Revision: 0f8095b950dd144497919cfea65a1f154ed3ae9a
2015-07-06 18:12:59 +03:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum WebGLShaderParameter {
|
|
|
|
Int(i32),
|
|
|
|
Bool(bool),
|
|
|
|
Invalid,
|
|
|
|
}
|
2015-05-20 23:42:06 +03:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct CanvasGradientStop {
|
|
|
|
pub offset: f64,
|
|
|
|
pub color: RGBA,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct LinearGradientStyle {
|
|
|
|
pub x0: f64,
|
|
|
|
pub y0: f64,
|
|
|
|
pub x1: f64,
|
|
|
|
pub y1: f64,
|
|
|
|
pub stops: Vec<CanvasGradientStop>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LinearGradientStyle {
|
|
|
|
pub fn new(x0: f64, y0: f64, x1: f64, y1: f64, stops: Vec<CanvasGradientStop>)
|
|
|
|
-> LinearGradientStyle {
|
|
|
|
LinearGradientStyle {
|
|
|
|
x0: x0,
|
|
|
|
y0: y0,
|
|
|
|
x1: x1,
|
|
|
|
y1: y1,
|
|
|
|
stops: stops,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct RadialGradientStyle {
|
|
|
|
pub x0: f64,
|
|
|
|
pub y0: f64,
|
|
|
|
pub r0: f64,
|
|
|
|
pub x1: f64,
|
|
|
|
pub y1: f64,
|
|
|
|
pub r1: f64,
|
|
|
|
pub stops: Vec<CanvasGradientStop>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RadialGradientStyle {
|
|
|
|
pub fn new(x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64, stops: Vec<CanvasGradientStop>)
|
|
|
|
-> RadialGradientStyle {
|
|
|
|
RadialGradientStyle {
|
|
|
|
x0: x0,
|
|
|
|
y0: y0,
|
|
|
|
r0: r0,
|
|
|
|
x1: x1,
|
|
|
|
y1: y1,
|
|
|
|
r1: r1,
|
|
|
|
stops: stops,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 10:49:50 +03:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct SurfaceStyle {
|
|
|
|
pub surface_data: Vec<u8>,
|
|
|
|
pub surface_size: Size2D<i32>,
|
|
|
|
pub repeat_x: bool,
|
|
|
|
pub repeat_y: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SurfaceStyle {
|
|
|
|
pub fn new(surface_data: Vec<u8>, surface_size: Size2D<i32>, repeat_x: bool, repeat_y: bool)
|
|
|
|
-> SurfaceStyle {
|
|
|
|
SurfaceStyle {
|
|
|
|
surface_data: surface_data,
|
|
|
|
surface_size: surface_size,
|
|
|
|
repeat_x: repeat_x,
|
|
|
|
repeat_y: repeat_y,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-20 23:42:06 +03:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum FillOrStrokeStyle {
|
|
|
|
Color(RGBA),
|
|
|
|
LinearGradient(LinearGradientStyle),
|
|
|
|
RadialGradient(RadialGradientStyle),
|
2015-06-13 10:49:50 +03:00
|
|
|
Surface(SurfaceStyle),
|
2015-05-20 23:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FillOrStrokeStyle {
|
|
|
|
pub fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Pattern {
|
|
|
|
match *self {
|
|
|
|
FillOrStrokeStyle::Color(ref color) => {
|
|
|
|
Pattern::Color(ColorPattern::new(color::new(color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha)))
|
|
|
|
},
|
|
|
|
FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => {
|
|
|
|
let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| {
|
|
|
|
GradientStop {
|
|
|
|
offset: s.offset as AzFloat,
|
|
|
|
color: color::new(s.color.red, s.color.green, s.color.blue, s.color.alpha)
|
|
|
|
}
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
Pattern::LinearGradient(LinearGradientPattern::new(
|
2015-06-13 22:52:07 +03:00
|
|
|
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
|
|
|
|
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
|
2015-05-20 23:42:06 +03:00
|
|
|
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
|
|
|
&Matrix2D::identity()))
|
|
|
|
},
|
|
|
|
FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => {
|
|
|
|
let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| {
|
|
|
|
GradientStop {
|
|
|
|
offset: s.offset as AzFloat,
|
|
|
|
color: color::new(s.color.red, s.color.green, s.color.blue, s.color.alpha)
|
|
|
|
}
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
Pattern::RadialGradient(RadialGradientPattern::new(
|
2015-06-13 22:52:07 +03:00
|
|
|
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
|
|
|
|
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
|
2015-05-20 23:42:06 +03:00
|
|
|
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
|
|
|
|
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
|
|
|
&Matrix2D::identity()))
|
2015-06-13 10:49:50 +03:00
|
|
|
},
|
|
|
|
FillOrStrokeStyle::Surface(ref surface_style) => {
|
|
|
|
let source_surface = drawtarget.create_source_surface_from_data(
|
|
|
|
&surface_style.surface_data,
|
|
|
|
surface_style.surface_size,
|
|
|
|
surface_style.surface_size.width * 4,
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
|
|
|
|
Pattern::Surface(SurfacePattern::new(
|
|
|
|
source_surface.azure_source_surface,
|
|
|
|
surface_style.repeat_x,
|
2015-07-07 14:42:07 +03:00
|
|
|
surface_style.repeat_y,
|
|
|
|
&Matrix2D::identity()))
|
2015-05-20 23:42:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum LineCapStyle {
|
|
|
|
Butt = 0,
|
|
|
|
Round = 1,
|
|
|
|
Square = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LineCapStyle {
|
|
|
|
pub fn to_azure_style(&self) -> CapStyle {
|
|
|
|
match *self {
|
|
|
|
LineCapStyle::Butt => CapStyle::Butt,
|
|
|
|
LineCapStyle::Round => CapStyle::Round,
|
|
|
|
LineCapStyle::Square => CapStyle::Square,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(string: &str) -> Option<LineCapStyle> {
|
|
|
|
match string {
|
|
|
|
"butt" => Some(LineCapStyle::Butt),
|
|
|
|
"round" => Some(LineCapStyle::Round),
|
|
|
|
"square" => Some(LineCapStyle::Square),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum LineJoinStyle {
|
|
|
|
Round = 0,
|
|
|
|
Bevel = 1,
|
|
|
|
Miter = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LineJoinStyle {
|
|
|
|
pub fn to_azure_style(&self) -> JoinStyle {
|
|
|
|
match *self {
|
|
|
|
LineJoinStyle::Round => JoinStyle::Round,
|
|
|
|
LineJoinStyle::Bevel => JoinStyle::Bevel,
|
|
|
|
LineJoinStyle::Miter => JoinStyle::Miter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(string: &str) -> Option<LineJoinStyle> {
|
|
|
|
match string {
|
|
|
|
"round" => Some(LineJoinStyle::Round),
|
|
|
|
"bevel" => Some(LineJoinStyle::Bevel),
|
|
|
|
"miter" => Some(LineJoinStyle::Miter),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 10:49:50 +03:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum RepetitionStyle {
|
|
|
|
Repeat,
|
|
|
|
RepeatX,
|
|
|
|
RepeatY,
|
|
|
|
NoRepeat,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RepetitionStyle {
|
|
|
|
pub fn from_str(string: &str) -> Option<RepetitionStyle> {
|
|
|
|
match string {
|
|
|
|
"repeat" => Some(RepetitionStyle::Repeat),
|
|
|
|
"repeat-x" => Some(RepetitionStyle::RepeatX),
|
|
|
|
"repeat-y" => Some(RepetitionStyle::RepeatY),
|
|
|
|
"no-repeat" => Some(RepetitionStyle::NoRepeat),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:42:06 +03:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum CompositionStyle {
|
|
|
|
SrcIn,
|
|
|
|
SrcOut,
|
|
|
|
SrcOver,
|
|
|
|
SrcAtop,
|
|
|
|
DestIn,
|
|
|
|
DestOut,
|
|
|
|
DestOver,
|
|
|
|
DestAtop,
|
|
|
|
Copy,
|
|
|
|
Lighter,
|
|
|
|
Xor,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CompositionStyle {
|
|
|
|
pub fn to_azure_style(&self) -> CompositionOp {
|
|
|
|
match *self {
|
|
|
|
CompositionStyle::SrcIn => CompositionOp::In,
|
|
|
|
CompositionStyle::SrcOut => CompositionOp::Out,
|
|
|
|
CompositionStyle::SrcOver => CompositionOp::Over,
|
|
|
|
CompositionStyle::SrcAtop => CompositionOp::Atop,
|
|
|
|
CompositionStyle::DestIn => CompositionOp::DestIn,
|
|
|
|
CompositionStyle::DestOut => CompositionOp::DestOut,
|
|
|
|
CompositionStyle::DestOver => CompositionOp::DestOver,
|
|
|
|
CompositionStyle::DestAtop => CompositionOp::DestAtop,
|
|
|
|
CompositionStyle::Copy => CompositionOp::Source,
|
|
|
|
CompositionStyle::Lighter => CompositionOp::Add,
|
|
|
|
CompositionStyle::Xor => CompositionOp::Xor,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(string: &str) -> Option<CompositionStyle> {
|
|
|
|
match string {
|
|
|
|
"source-in" => Some(CompositionStyle::SrcIn),
|
|
|
|
"source-out" => Some(CompositionStyle::SrcOut),
|
|
|
|
"source-over" => Some(CompositionStyle::SrcOver),
|
|
|
|
"source-atop" => Some(CompositionStyle::SrcAtop),
|
|
|
|
"destination-in" => Some(CompositionStyle::DestIn),
|
|
|
|
"destination-out" => Some(CompositionStyle::DestOut),
|
|
|
|
"destination-over" => Some(CompositionStyle::DestOver),
|
|
|
|
"destination-atop" => Some(CompositionStyle::DestAtop),
|
|
|
|
"copy" => Some(CompositionStyle::Copy),
|
|
|
|
"lighter" => Some(CompositionStyle::Lighter),
|
|
|
|
"xor" => Some(CompositionStyle::Xor),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_str(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
CompositionStyle::SrcIn => "source-in",
|
|
|
|
CompositionStyle::SrcOut => "source-out",
|
|
|
|
CompositionStyle::SrcOver => "source-over",
|
|
|
|
CompositionStyle::SrcAtop => "source-atop",
|
|
|
|
CompositionStyle::DestIn => "destination-in",
|
|
|
|
CompositionStyle::DestOut => "destination-out",
|
|
|
|
CompositionStyle::DestOver => "destination-over",
|
|
|
|
CompositionStyle::DestAtop => "destination-atop",
|
|
|
|
CompositionStyle::Copy => "copy",
|
|
|
|
CompositionStyle::Lighter => "lighter",
|
|
|
|
CompositionStyle::Xor => "xor",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum BlendingStyle {
|
|
|
|
Multiply,
|
|
|
|
Screen,
|
|
|
|
Overlay,
|
|
|
|
Darken,
|
|
|
|
Lighten,
|
|
|
|
ColorDodge,
|
|
|
|
ColorBurn,
|
|
|
|
HardLight,
|
|
|
|
SoftLight,
|
|
|
|
Difference,
|
|
|
|
Exclusion,
|
|
|
|
Hue,
|
|
|
|
Saturation,
|
|
|
|
Color,
|
|
|
|
Luminosity,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BlendingStyle {
|
|
|
|
pub fn to_azure_style(&self) -> CompositionOp {
|
|
|
|
match *self {
|
|
|
|
BlendingStyle::Multiply => CompositionOp::Multiply,
|
|
|
|
BlendingStyle::Screen => CompositionOp::Screen,
|
|
|
|
BlendingStyle::Overlay => CompositionOp::Overlay,
|
|
|
|
BlendingStyle::Darken => CompositionOp::Darken,
|
|
|
|
BlendingStyle::Lighten => CompositionOp::Lighten,
|
|
|
|
BlendingStyle::ColorDodge => CompositionOp::ColorDodge,
|
|
|
|
BlendingStyle::ColorBurn => CompositionOp::ColorBurn,
|
|
|
|
BlendingStyle::HardLight => CompositionOp::HardLight,
|
|
|
|
BlendingStyle::SoftLight => CompositionOp::SoftLight,
|
|
|
|
BlendingStyle::Difference => CompositionOp::Difference,
|
|
|
|
BlendingStyle::Exclusion => CompositionOp::Exclusion,
|
|
|
|
BlendingStyle::Hue => CompositionOp::Hue,
|
|
|
|
BlendingStyle::Saturation => CompositionOp::Saturation,
|
|
|
|
BlendingStyle::Color => CompositionOp::Color,
|
|
|
|
BlendingStyle::Luminosity => CompositionOp::Luminosity,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(string: &str) -> Option<BlendingStyle> {
|
|
|
|
match string {
|
|
|
|
"multiply" => Some(BlendingStyle::Multiply),
|
|
|
|
"screen" => Some(BlendingStyle::Screen),
|
|
|
|
"overlay" => Some(BlendingStyle::Overlay),
|
|
|
|
"darken" => Some(BlendingStyle::Darken),
|
|
|
|
"lighten" => Some(BlendingStyle::Lighten),
|
|
|
|
"color-dodge" => Some(BlendingStyle::ColorDodge),
|
|
|
|
"color-burn" => Some(BlendingStyle::ColorBurn),
|
|
|
|
"hard-light" => Some(BlendingStyle::HardLight),
|
|
|
|
"soft-light" => Some(BlendingStyle::SoftLight),
|
|
|
|
"difference" => Some(BlendingStyle::Difference),
|
|
|
|
"exclusion" => Some(BlendingStyle::Exclusion),
|
|
|
|
"hue" => Some(BlendingStyle::Hue),
|
|
|
|
"saturation" => Some(BlendingStyle::Saturation),
|
|
|
|
"color" => Some(BlendingStyle::Color),
|
|
|
|
"luminosity" => Some(BlendingStyle::Luminosity),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_str(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
BlendingStyle::Multiply => "multiply",
|
|
|
|
BlendingStyle::Screen => "screen",
|
|
|
|
BlendingStyle::Overlay => "overlay",
|
|
|
|
BlendingStyle::Darken => "darken",
|
|
|
|
BlendingStyle::Lighten => "lighten",
|
|
|
|
BlendingStyle::ColorDodge => "color-dodge",
|
|
|
|
BlendingStyle::ColorBurn => "color-burn",
|
|
|
|
BlendingStyle::HardLight => "hard-light",
|
|
|
|
BlendingStyle::SoftLight => "soft-light",
|
|
|
|
BlendingStyle::Difference => "difference",
|
|
|
|
BlendingStyle::Exclusion => "exclusion",
|
|
|
|
BlendingStyle::Hue => "hue",
|
|
|
|
BlendingStyle::Saturation => "saturation",
|
|
|
|
BlendingStyle::Color => "color",
|
|
|
|
BlendingStyle::Luminosity => "luminosity",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum CompositionOrBlending {
|
|
|
|
Composition(CompositionStyle),
|
|
|
|
Blending(BlendingStyle),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CompositionOrBlending {
|
|
|
|
pub fn to_azure_style(&self) -> CompositionOp {
|
|
|
|
match *self {
|
|
|
|
CompositionOrBlending::Composition(op) => op.to_azure_style(),
|
|
|
|
CompositionOrBlending::Blending(op) => op.to_azure_style(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default() -> CompositionOrBlending {
|
|
|
|
CompositionOrBlending::Composition(CompositionStyle::SrcOver)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_str(string: &str) -> Option<CompositionOrBlending> {
|
|
|
|
if let Some(op) = CompositionStyle::from_str(string) {
|
|
|
|
return Some(CompositionOrBlending::Composition(op));
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(op) = BlendingStyle::from_str(string) {
|
|
|
|
return Some(CompositionOrBlending::Blending(op));
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2015-06-12 19:22:54 +03:00
|
|
|
|
|
|
|
pub trait ToAzColor {
|
|
|
|
fn to_azcolor(&self) -> AzColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToAzColor for RGBA {
|
|
|
|
fn to_azcolor(&self) -> AzColor {
|
|
|
|
color::rgba(self.red as AzFloat,
|
|
|
|
self.green as AzFloat,
|
|
|
|
self.blue as AzFloat,
|
|
|
|
self.alpha as AzFloat)
|
|
|
|
}
|
|
|
|
}
|