Split webgl into separate crate (#36718)

canvas crate was home for both webgl and 2dcanvas impl, but it makes
more sense to separate these two, by splitting webgl into standalone
crate (like we already have for webgpu).

Testing: Rust for fearless refactoring (but there are WPT tests just in
case)

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-04-30 07:27:44 +02:00 committed by GitHub
parent 0c0ee04b8e
commit 955149b194
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 79 additions and 33 deletions

34
Cargo.lock generated
View file

@ -784,18 +784,13 @@ name = "canvas"
version = "0.0.1"
dependencies = [
"app_units",
"bitflags 2.9.0",
"byteorder",
"canvas_traits",
"compositing_traits",
"crossbeam-channel",
"cssparser",
"euclid",
"fnv",
"font-kit",
"fonts",
"glow",
"half",
"ipc-channel",
"log",
"lyon_geom",
@ -807,12 +802,8 @@ dependencies = [
"servo_arc",
"snapshot",
"stylo",
"surfman",
"unicode-script",
"webrender",
"webrender_api",
"webxr",
"webxr-api",
]
[[package]]
@ -4334,6 +4325,7 @@ dependencies = [
"tracing",
"url",
"webdriver_server",
"webgl",
"webgpu",
"webrender",
"webrender_api",
@ -8489,6 +8481,30 @@ dependencies = [
"webdriver",
]
[[package]]
name = "webgl"
version = "0.0.1"
dependencies = [
"bitflags 2.9.0",
"byteorder",
"canvas_traits",
"compositing_traits",
"crossbeam-channel",
"euclid",
"fnv",
"glow",
"half",
"ipc-channel",
"log",
"pixels",
"snapshot",
"surfman",
"webrender",
"webrender_api",
"webxr",
"webxr-api",
]
[[package]]
name = "webgpu"
version = "0.0.1"

View file

@ -11,24 +11,15 @@ rust-version.workspace = true
name = "canvas"
path = "lib.rs"
[features]
webgl_backtrace = ["canvas_traits/webgl_backtrace"]
webxr = ["dep:webxr", "dep:webxr-api"]
[dependencies]
app_units = { workspace = true }
bitflags = { workspace = true }
byteorder = { workspace = true }
canvas_traits = { workspace = true }
compositing_traits = { workspace = true }
crossbeam-channel = { workspace = true }
cssparser = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
font-kit = "0.14"
fonts = { path = "../fonts" }
glow = { workspace = true }
half = "2"
ipc-channel = { workspace = true }
log = { workspace = true }
lyon_geom = "1.0.4"
@ -40,9 +31,5 @@ raqote = "0.8.5"
servo_arc = { workspace = true }
snapshot = { workspace = true }
stylo = { workspace = true }
surfman = { workspace = true }
unicode-script = { workspace = true }
webrender = { workspace = true }
webrender_api = { workspace = true }
webxr = { path = "../webxr", features = ["ipc"], optional = true }
webxr-api = { workspace = true, features = ["ipc"], optional = true }

View file

@ -6,12 +6,5 @@
mod raqote_backend;
pub use webgl_mode::WebGLComm;
pub mod canvas_data;
pub mod canvas_paint_thread;
mod webgl_limits;
mod webgl_mode;
pub mod webgl_thread;
#[cfg(feature = "webxr")]
mod webxr;

View file

@ -46,14 +46,14 @@ tracing = [
webdriver = ["webdriver_server"]
webgl_backtrace = [
"script/webgl_backtrace",
"canvas/webgl_backtrace",
"webgl/webgl_backtrace",
"canvas_traits/webgl_backtrace",
]
webxr = [
"dep:webxr",
"dep:webxr-api",
"compositing/webxr",
"canvas/webxr",
"webgl/webxr",
"script/webxr",
]
webgpu = [
@ -68,7 +68,8 @@ base = { workspace = true }
bincode = { workspace = true }
bluetooth = { path = "../bluetooth", optional = true }
bluetooth_traits = { workspace = true, optional = true }
canvas = { path = "../canvas", default-features = false }
canvas = { path = "../canvas" }
webgl = { path = "../webgl", default-features = false }
canvas_traits = { workspace = true }
cfg-if = { workspace = true }
compositing = { path = "../compositing" }

View file

@ -38,7 +38,6 @@ use base::id::{PipelineNamespace, PipelineNamespaceId};
use bluetooth::BluetoothThreadFactory;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest;
use canvas::WebGLComm;
use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas_traits::webgl::{GlType, WebGLThreads};
use clipboard_delegate::StringRequest;
@ -99,6 +98,7 @@ use servo_delegate::DefaultServoDelegate;
use servo_media::ServoMedia;
use servo_media::player::context::GlContext;
use servo_url::ServoUrl;
use webgl::WebGLComm;
#[cfg(feature = "webgpu")]
pub use webgpu;
#[cfg(feature = "webgpu")]

View file

@ -0,0 +1,36 @@
[package]
name = "webgl"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
[lib]
name = "webgl"
path = "lib.rs"
[features]
webgl_backtrace = ["canvas_traits/webgl_backtrace"]
webxr = ["dep:webxr", "dep:webxr-api"]
[dependencies]
bitflags = { workspace = true }
byteorder = { workspace = true }
canvas_traits = { workspace = true }
compositing_traits = { workspace = true }
crossbeam-channel = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
glow = { workspace = true }
half = "2"
ipc-channel = { workspace = true }
log = { workspace = true }
pixels = { path = "../pixels" }
snapshot = { workspace = true }
surfman = { workspace = true }
webrender = { workspace = true }
webrender_api = { workspace = true }
webxr = { path = "../webxr", features = ["ipc"], optional = true }
webxr-api = { workspace = true, features = ["ipc"], optional = true }

13
components/webgl/lib.rs Normal file
View file

@ -0,0 +1,13 @@
/* 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 https://mozilla.org/MPL/2.0/. */
#![deny(unsafe_code)]
pub use webgl_mode::WebGLComm;
mod webgl_limits;
mod webgl_mode;
pub mod webgl_thread;
#[cfg(feature = "webxr")]
mod webxr;