From d1397c0b2032b51f6800f4fa0fede8faf5006ff6 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Tue, 14 May 2019 16:54:53 +0200 Subject: [PATCH 01/14] Add raqote to canvas' dependencies --- Cargo.lock | 192 ++++++++++++++++++++++++++++------- components/canvas/Cargo.toml | 1 + 2 files changed, 156 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce4e3ce8b6f..63ce2d499a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,7 +146,7 @@ version = "0.36.0" source = "git+https://github.com/servo/rust-azure#ca9cc643808f6f63576c5c2cd098e973406cc7f3" dependencies = [ "cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "servo-freetype-sys 4.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "servo-skia 0.30000021.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -424,7 +424,7 @@ dependencies = [ "canvas_traits 0.0.1", "compositing 0.0.1", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "half 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -433,6 +433,7 @@ dependencies = [ "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", "pixels 0.0.1", + "raqote 0.4.1-alpha.0 (git+https://github.com/jrmuizel/raqote)", "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", "webrender 0.60.0 (git+https://github.com/servo/webrender)", @@ -444,7 +445,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -621,7 +622,7 @@ version = "0.0.1" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "embedder_traits 0.0.1", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -662,7 +663,7 @@ dependencies = [ "debugger 0.0.1", "devtools_traits 0.0.1", "embedder_traits 0.0.1", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gaol 0.2.0 (git+https://github.com/servo/gaol)", "gfx 0.0.1", "gfx_traits 0.0.1", @@ -1091,6 +1092,18 @@ dependencies = [ "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dwrote" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dwrote" version = "0.8.0" @@ -1216,7 +1229,7 @@ dependencies = [ [[package]] name = "euclid" -version = "0.19.7" +version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1249,6 +1262,18 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1279,11 +1304,45 @@ dependencies = [ "miniz_oxide_c_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "float-ord" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "font-kit" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-fontconfig 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fontsan" version = "0.4.0" @@ -1309,7 +1368,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "freetype" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1408,10 +1467,10 @@ dependencies = [ "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fontsan 0.4.0 (git+https://github.com/servo/fontsan)", - "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "harfbuzz-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1896,7 +1955,7 @@ dependencies = [ "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2183,6 +2242,14 @@ dependencies = [ "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itertools" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.8.0" @@ -2266,7 +2333,7 @@ dependencies = [ "canvas_traits 0.0.1", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "embedder_traits 0.0.1", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", @@ -2312,7 +2379,7 @@ dependencies = [ "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "embedder_traits 0.0.1", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", @@ -2450,7 +2517,7 @@ dependencies = [ "devtools_traits 0.0.1", "embedder_traits 0.0.1", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gaol 0.2.0 (git+https://github.com/servo/gaol)", "gfx 0.0.1", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2538,6 +2605,24 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lyon_geom" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lyon_path" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lzw" version = "0.10.0" @@ -2571,7 +2656,7 @@ dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", "hyper 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3062,7 +3147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3256,7 +3341,7 @@ dependencies = [ name = "pixels" version = "0.0.1" dependencies = [ - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3273,7 +3358,7 @@ version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "binary-space-partition 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3501,6 +3586,19 @@ dependencies = [ "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "raqote" +version = "0.4.1-alpha.0" +source = "git+https://github.com/jrmuizel/raqote#f5a091c352118c9fff0aca99990ee10899d1ca08" +dependencies = [ + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", + "font-kit 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sw-composite 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "typed-arena 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rayon" version = "1.0.0" @@ -3594,7 +3692,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.49.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3700,7 +3798,7 @@ dependencies = [ "embedder_traits 0.0.1", "encoding_rs 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)", "enum-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "headers-core 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3778,7 +3876,7 @@ dependencies = [ "canvas_traits 0.0.1", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "html5ever 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3818,7 +3916,7 @@ dependencies = [ name = "script_tests" version = "0.0.1" dependencies = [ - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "servo_url 0.0.1", @@ -3834,7 +3932,7 @@ dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "embedder_traits 0.0.1", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "http 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3936,7 +4034,7 @@ dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4010,7 +4108,7 @@ source = "git+https://github.com/servo/media#2dabf1ab7e3b6d3b6764eebdf8855431367 dependencies = [ "boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "byte-slice-cast 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4127,7 +4225,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4172,7 +4270,7 @@ dependencies = [ "dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "embedder_traits 0.0.1", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4202,7 +4300,7 @@ name = "servo_geometry" version = "0.0.1" dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", @@ -4472,7 +4570,7 @@ dependencies = [ "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fallible 0.0.1", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", @@ -4538,7 +4636,7 @@ dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4561,7 +4659,7 @@ dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.25.5 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of 0.0.1", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4575,6 +4673,11 @@ dependencies = [ "webrender_api 0.60.0 (git+https://github.com/servo/webrender)", ] +[[package]] +name = "sw-composite" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "swapper" version = "0.1.0" @@ -4911,6 +5014,11 @@ name = "try-lock" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "typed-arena" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "typenum" version = "1.10.0" @@ -5166,7 +5274,7 @@ dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5202,7 +5310,7 @@ dependencies = [ "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cstr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5238,7 +5346,7 @@ dependencies = [ "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_size_of_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5262,7 +5370,7 @@ version = "0.0.1" dependencies = [ "canvas_traits 0.0.1", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5373,7 +5481,7 @@ version = "0.0.1" source = "git+https://github.com/servo/webrender#e53aae02728e155e555b8baa9d180d90dac3b86f" dependencies = [ "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5568,6 +5676,7 @@ dependencies = [ "checksum downcast-rs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "18df8ce4470c189d18aa926022da57544f31e154631eb4cfe796aea97051fe6c" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" "checksum dtoa-short 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe6f727b406462fd57c95fed84d1b0dbfb5f0136fcac005adba9ea0367c05cc8" +"checksum dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30a998e9ff70cd208ccdc4f864e998688bf61d7b897dccec8e17a884d17358bf" "checksum dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c31c624339dab99c223a4b26c2e803b7c248adaca91549ce654c76f39a03f5c8" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum encoding_rs 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ca20350a7cb5aab5b9034731123d6d412caf3e92d4985e739e411ba0955fd0eb" @@ -5580,18 +5689,21 @@ dependencies = [ "checksum enum-iterator-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "293ee6af5f9349c2594a7c867b7c89347fb939415508e6367a19bd246ffc08d8" "checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" -"checksum euclid 0.19.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8acd6a7f2740b7b936008acd58b1def492854254dc4af9d2b850ca01f4960e" +"checksum euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7a4719a544a67ed3fc33784c2bd2c6581663dfe83b719a6ae05c6dabc3b51c73" "checksum euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcb84c18ea5037a1c5a23039b4ff29403abce2e0d6b1daa11cf0bde2b30be15" "checksum expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" +"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909" +"checksum float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum font-kit 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5be0133b580e2920076afd5bd4b81dc172d10e5653bd1c516476718d52347859" "checksum fontsan 0.4.0 (git+https://github.com/servo/fontsan)" = "" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -"checksum freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b659e75b7a7338fe75afd7f909fc2b71937845cffb6ebe54ba2e50f13d8e903d" +"checksum freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "11926b2b410b469d0e9399eca4cbbe237a9ef02176c485803b29216307e8e028" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" @@ -5665,6 +5777,7 @@ dependencies = [ "checksum io-surface 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9a33981dff54baaff80f4decb487a65d148a3c00facc97820d0f09128f74dd" "checksum iovec 0.1.3 (git+https://github.com/servo/iovec.git?branch=servo)" = "" "checksum ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a369bb751cf24f18084aabb56995268ec1f68d2b69937aaf031d41690c1bef" +"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" "checksum jemalloc-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "479294d130502fada93c7a957e8d059b632b03d6204aca37af557dee947f30a9" @@ -5688,6 +5801,8 @@ dependencies = [ "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0ea0ba5f8d2d91d6d895aca54d1ec0d84ddfa4826f33fbfe8abb39f08f9e4153" +"checksum lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9dc8e0746b7cca11960b602f7fe037bb067746a01eab4aa502fed1494544843" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" "checksum mach 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1" @@ -5771,6 +5886,7 @@ dependencies = [ "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum raqote 0.4.1-alpha.0 (git+https://github.com/jrmuizel/raqote)" = "" "checksum rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "485541959c8ecc49865526fe6c4de9653dd6e60d829d6edf0be228167b60372d" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" @@ -5834,6 +5950,7 @@ dependencies = [ "checksum string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eea1eee654ef80933142157fdad9dd8bc43cf7c74e999e369263496f04ff4da" "checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum sw-composite 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "244e594da1b22e50c421a70f08e146e3ad60fe1fc975cfd47a85a169ccca17c5" "checksum swapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e454d048db5527d000bfddb77bd072bbf3a1e2ae785f16d9bd116e07c2ab45eb" "checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" @@ -5865,6 +5982,7 @@ dependencies = [ "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" "checksum truetype 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec30350633d6dac9dc1a625786b6cbe9150664be941aac2c35ad7199eab877" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +"checksum typed-arena 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c6c06a92aef38bb4dc5b0df00d68496fc31307c5344c867bb61678c6e1671ec5" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe4fa6e588762366f1eb4991ce59ad1b93651d0b769dfb4e4d1c5c4b943d1159" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index 20fa3300aae..c91302f02b3 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -27,6 +27,7 @@ ipc-channel = "0.11" log = "0.4" num-traits = "0.2" offscreen_gl_context = {version = "0.22", features = ["serde", "osmesa"]} +raqote = {git = "https://github.com/jrmuizel/raqote"} pixels = {path = "../pixels"} serde_bytes = "0.10" servo_config = {path = "../config"} From 7ad5149e503864e5e124b0d495d5d6631fc906aa Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Fri, 17 May 2019 19:33:26 +0200 Subject: [PATCH 02/14] Add GenericDrawTarget trait --- components/canvas/canvas_data.rs | 384 +++++++++++++++++++++++++------ 1 file changed, 308 insertions(+), 76 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index beb29242b5e..4f583b6d33b 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -2,14 +2,13 @@ * 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/. */ -use azure::azure::AzFloat; +use azure::azure::{AzFloat, AzGradientStop, AzIntSize}; +use azure::azure_hl; use azure::azure_hl::SurfacePattern; -use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, CompositionOp, JoinStyle}; -use azure::azure_hl::{ - BackendType, DrawOptions, DrawTarget, Pattern, StrokeOptions, SurfaceFormat, -}; -use azure::azure_hl::{Color, ColorPattern, DrawSurfaceOptions, Filter, Path, PathBuilder}; -use azure::azure_hl::{ExtendMode, GradientStop, LinearGradientPattern, RadialGradientPattern}; +use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle}; +use azure::azure_hl::{BackendType, DrawTarget}; +use azure::azure_hl::{ColorPattern, DrawSurfaceOptions, Filter, PathBuilder}; +use azure::azure_hl::{ExtendMode, LinearGradientPattern, RadialGradientPattern}; use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; @@ -37,7 +36,7 @@ enum PathState { /// Path in user-space. If a transform has been applied but /// but no further path operations have occurred, it is stored /// in the optional field. - UserSpacePath(Path, Option>), + UserSpacePath(azure_hl::Path, Option>), } impl PathState { @@ -48,7 +47,7 @@ impl PathState { } } - fn path(&self) -> &Path { + fn path(&self) -> &azure_hl::Path { match *self { PathState::UserSpacePath(ref p, _) => p, PathState::UserSpacePathBuilder(..) | PathState::DeviceSpacePathBuilder(..) => { @@ -160,6 +159,234 @@ impl<'a> PathBuilderRef<'a> { } } +// TODO(pylbrecht) +// This defines required methods for DrawTarget of azure and raqote +// The prototypes are derived from azure's methods. +trait GenericDrawTarget { + fn clear_rect(&self, rect: &Rect); + fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D); + fn create_gradient_stops( + &self, + gradient_stops: &[GradientStop], + extend_mode: ExtendMode, + ) -> GradientStops; + fn create_path_builder(&self); + fn create_similar_draw_target( + &self, + size: Size2D, + format: SurfaceFormat, + ) -> Box; + fn create_source_surface_from_data(&self); + fn draw_surface_with_shadow( + &self, + surface: SourceSurface, + dest: &Point2D, + color: &Color, + offset: Vector2D, + sigma: f32, + operator: CompositionOp, + ); + fn fill(&self, path: &Path, pattern: PatternRef, draw_options: &DrawOptions); + fn fill_rect(&self, rect: &Rect, pattern: PatternRef, draw_options: Option<&DrawOptions>); + fn get_format(&self) -> SurfaceFormat; + fn get_size(&self) -> IntSize; + fn get_transform(&self) -> Transform2D; + fn pop_clip(&self); + fn push_clip(&self, path: &Path); + fn set_transform(&self, matrix: &Transform2D); + fn snapshot(&self) -> SourceSurface; + fn stroke( + &self, + path: &Path, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ); + fn stroke_line( + &self, + start: Point2D, + end: Point2D, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ); + fn stroke_rect( + &self, + rect: &Rect, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ); +} + +enum GradientStop { + Azure(AzGradientStop), + Raqote(()), +} + +impl GradientStop { + fn as_azure(&self) -> &AzGradientStop { + match self { + GradientStop::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum GradientStops { + Azure(azure_hl::GradientStops), + Raqote(()), +} + +impl GradientStops { + fn as_azure(&self) -> &azure_hl::GradientStops { + match self { + GradientStops::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum Color { + Azure(azure_hl::Color), + Raqote(()), +} + +impl Color { + fn as_azure(&self) -> &azure_hl::Color { + match self { + Color::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum CompositionOp { + Azure(azure_hl::CompositionOp), + Raqote(()), +} + +impl CompositionOp { + fn as_azure(&self) -> &azure_hl::CompositionOp { + match self { + CompositionOp::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum SurfaceFormat { + Azure(azure_hl::SurfaceFormat), + Raqote(()), +} + +impl SurfaceFormat { + fn as_azure(&self) -> &azure_hl::SurfaceFormat { + match self { + SurfaceFormat::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum SourceSurface { + Azure(azure_hl::SourceSurface), + Raqote(()), +} + +impl SourceSurface { + fn as_azure(&self) -> &azure_hl::SourceSurface { + match self { + SourceSurface::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum IntSize { + Azure(AzIntSize), + Raqote(()), +} + +impl IntSize { + fn as_azure(&self) -> &AzIntSize { + match self { + IntSize::Azure(s) => s, + _ => unreachable!(), + } + } +} + +enum Path { + Azure(azure_hl::Path), + Raqote(()), +} + +impl Path { + fn as_azure(&self) -> &azure_hl::Path { + match self { + Path::Azure(p) => p, + _ => unreachable!(), + } + } +} + +enum Pattern { + Azure(azure_hl::Pattern), + Raqote(()), +} + +enum PatternRef<'a> { + Azure(azure_hl::PatternRef<'a>), + Raqote(()), +} + +impl<'a> PatternRef<'a> { + fn as_azure(&self) -> &azure_hl::PatternRef<'a> { + match self { + PatternRef::Azure(p) => p, + _ => unreachable!(), + } + } +} + +impl Pattern { + fn as_azure(&self) -> &azure_hl::Pattern { + match self { + Pattern::Azure(p) => p, + _ => unreachable!(), + } + } +} + +enum DrawOptions { + Azure(azure_hl::DrawOptions), + Raqote(()), +} + +impl DrawOptions { + fn as_azure(&self) -> &azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + _ => unreachable!(), + } + } +} + +enum StrokeOptions<'a> { + Azure(azure_hl::StrokeOptions<'a>), + Raqote(()), +} + +impl<'a> StrokeOptions<'a> { + fn as_azure_ref(&self) -> &azure_hl::StrokeOptions<'a> { + match self { + StrokeOptions::Azure(options) => options, + _ => unreachable!(), + } + } +} + pub struct CanvasData<'a> { drawtarget: DrawTarget, path_state: Option, @@ -264,7 +491,7 @@ impl<'a> CanvasData<'a> { let draw_rect = Rect::new( rect.origin, match self.state.fill_style { - Pattern::Surface(ref surface) => { + azure_hl::Pattern::Surface(ref surface) => { let surface_size = surface.size(); match (surface.repeat_x, surface.repeat_y) { (true, true) => rect.size, @@ -320,7 +547,7 @@ impl<'a> CanvasData<'a> { _ => CapStyle::Butt, }; - let stroke_opts = StrokeOptions::new( + let stroke_opts = azure_hl::StrokeOptions::new( self.state.stroke_opts.line_width, self.state.stroke_opts.line_join, cap, @@ -411,7 +638,7 @@ impl<'a> CanvasData<'a> { assert!(self.path_state.as_ref().unwrap().is_path()) } - fn path(&self) -> &Path { + fn path(&self) -> &azure_hl::Path { self.path_state .as_ref() .expect("Should have called ensure_path()") @@ -710,7 +937,11 @@ impl<'a> CanvasData<'a> { pub fn create(size: Size2D) -> DrawTarget { // FIXME(nox): Why is the size made of i32 values? - DrawTarget::new(BackendType::Skia, size.to_i32(), SurfaceFormat::B8G8R8A8) + DrawTarget::new( + BackendType::Skia, + size.to_i32(), + azure_hl::SurfaceFormat::B8G8R8A8, + ) } pub fn recreate(&mut self, size: Size2D) { @@ -793,7 +1024,7 @@ impl<'a> CanvasData<'a> { &imagedata, rect.size.to_i32(), rect.size.width as i32 * 4, - SurfaceFormat::B8G8R8A8, + azure_hl::SurfaceFormat::B8G8R8A8, ) .unwrap(); self.drawtarget.copy_surface( @@ -815,7 +1046,7 @@ impl<'a> CanvasData<'a> { self.state.shadow_blur = value; } - pub fn set_shadow_color(&mut self, value: Color) { + pub fn set_shadow_color(&mut self, value: azure_hl::Color) { self.state.shadow_color = value; } @@ -904,25 +1135,25 @@ impl<'a> Drop for CanvasData<'a> { #[derive(Clone)] struct CanvasPaintState<'a> { - draw_options: DrawOptions, - fill_style: Pattern, - stroke_style: Pattern, - stroke_opts: StrokeOptions<'a>, + draw_options: azure_hl::DrawOptions, + fill_style: azure_hl::Pattern, + stroke_style: azure_hl::Pattern, + stroke_opts: azure_hl::StrokeOptions<'a>, /// The current 2D transform matrix. transform: Transform2D, shadow_offset_x: f64, shadow_offset_y: f64, shadow_blur: f64, - shadow_color: Color, + shadow_color: azure_hl::Color, } impl<'a> CanvasPaintState<'a> { fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> { CanvasPaintState { - draw_options: DrawOptions::new(1.0, CompositionOp::Over, antialias), - fill_style: Pattern::Color(ColorPattern::new(Color::black())), - stroke_style: Pattern::Color(ColorPattern::new(Color::black())), - stroke_opts: StrokeOptions::new( + draw_options: azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias), + fill_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), + stroke_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), + stroke_opts: azure_hl::StrokeOptions::new( 1.0, JoinStyle::MiterOrBevel, CapStyle::Butt, @@ -933,13 +1164,13 @@ impl<'a> CanvasPaintState<'a> { shadow_offset_x: 0.0, shadow_offset_y: 0.0, shadow_blur: 0.0, - shadow_color: Color::transparent(), + shadow_color: azure_hl::Color::transparent(), } } } -fn is_zero_size_gradient(pattern: &Pattern) -> bool { - if let &Pattern::LinearGradient(ref gradient) = pattern { +fn is_zero_size_gradient(pattern: &azure_hl::Pattern) -> bool { + if let &azure_hl::Pattern::LinearGradient(ref gradient) = pattern { if gradient.is_zero_size() { return true; } @@ -959,7 +1190,7 @@ fn write_image( image_size: Size2D, dest_rect: Rect, smoothing_enabled: bool, - composition_op: CompositionOp, + composition_op: azure_hl::CompositionOp, global_alpha: f32, ) { if image_data.is_empty() { @@ -983,11 +1214,12 @@ fn write_image( &image_data, image_size, image_size.width * 4, - SurfaceFormat::B8G8R8A8, + azure_hl::SurfaceFormat::B8G8R8A8, ) .unwrap(); let draw_surface_options = DrawSurfaceOptions::new(filter, true); - let draw_options = DrawOptions::new(global_alpha, composition_op, AntialiasMode::None); + let draw_options = + azure_hl::DrawOptions::new(global_alpha, composition_op, AntialiasMode::None); draw_target.draw_surface( source_surface, dest_rect.to_azure_style(), @@ -1085,53 +1317,53 @@ impl ToAzureStyle for LineJoinStyle { } impl ToAzureStyle for CompositionStyle { - type Target = CompositionOp; + type Target = azure_hl::CompositionOp; - fn to_azure_style(self) -> CompositionOp { + fn to_azure_style(self) -> azure_hl::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, + CompositionStyle::SrcIn => azure_hl::CompositionOp::In, + CompositionStyle::SrcOut => azure_hl::CompositionOp::Out, + CompositionStyle::SrcOver => azure_hl::CompositionOp::Over, + CompositionStyle::SrcAtop => azure_hl::CompositionOp::Atop, + CompositionStyle::DestIn => azure_hl::CompositionOp::DestIn, + CompositionStyle::DestOut => azure_hl::CompositionOp::DestOut, + CompositionStyle::DestOver => azure_hl::CompositionOp::DestOver, + CompositionStyle::DestAtop => azure_hl::CompositionOp::DestAtop, + CompositionStyle::Copy => azure_hl::CompositionOp::Source, + CompositionStyle::Lighter => azure_hl::CompositionOp::Add, + CompositionStyle::Xor => azure_hl::CompositionOp::Xor, } } } impl ToAzureStyle for BlendingStyle { - type Target = CompositionOp; + type Target = azure_hl::CompositionOp; - fn to_azure_style(self) -> CompositionOp { + fn to_azure_style(self) -> azure_hl::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, + BlendingStyle::Multiply => azure_hl::CompositionOp::Multiply, + BlendingStyle::Screen => azure_hl::CompositionOp::Screen, + BlendingStyle::Overlay => azure_hl::CompositionOp::Overlay, + BlendingStyle::Darken => azure_hl::CompositionOp::Darken, + BlendingStyle::Lighten => azure_hl::CompositionOp::Lighten, + BlendingStyle::ColorDodge => azure_hl::CompositionOp::ColorDodge, + BlendingStyle::ColorBurn => azure_hl::CompositionOp::ColorBurn, + BlendingStyle::HardLight => azure_hl::CompositionOp::HardLight, + BlendingStyle::SoftLight => azure_hl::CompositionOp::SoftLight, + BlendingStyle::Difference => azure_hl::CompositionOp::Difference, + BlendingStyle::Exclusion => azure_hl::CompositionOp::Exclusion, + BlendingStyle::Hue => azure_hl::CompositionOp::Hue, + BlendingStyle::Saturation => azure_hl::CompositionOp::Saturation, + BlendingStyle::Color => azure_hl::CompositionOp::Color, + BlendingStyle::Luminosity => azure_hl::CompositionOp::Luminosity, } } } impl ToAzureStyle for CompositionOrBlending { - type Target = CompositionOp; + type Target = azure_hl::CompositionOp; - fn to_azure_style(self) -> CompositionOp { + fn to_azure_style(self) -> azure_hl::CompositionOp { match self { CompositionOrBlending::Composition(op) => op.to_azure_style(), CompositionOrBlending::Blending(op) => op.to_azure_style(), @@ -1140,26 +1372,26 @@ impl ToAzureStyle for CompositionOrBlending { } pub trait ToAzurePattern { - fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option; + fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option; } impl ToAzurePattern for FillOrStrokeStyle { - fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option { + fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option { Some(match *self { FillOrStrokeStyle::Color(ref color) => { - Pattern::Color(ColorPattern::new(color.to_azure_style())) + azure_hl::Pattern::Color(ColorPattern::new(color.to_azure_style())) }, FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => { - let gradient_stops: Vec = linear_gradient_style + let gradient_stops: Vec = linear_gradient_style .stops .iter() - .map(|s| GradientStop { + .map(|s| azure_hl::GradientStop { offset: s.offset as AzFloat, color: s.color.to_azure_style(), }) .collect(); - Pattern::LinearGradient(LinearGradientPattern::new( + azure_hl::Pattern::LinearGradient(LinearGradientPattern::new( &Point2D::new( linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat, @@ -1173,16 +1405,16 @@ impl ToAzurePattern for FillOrStrokeStyle { )) }, FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => { - let gradient_stops: Vec = radial_gradient_style + let gradient_stops: Vec = radial_gradient_style .stops .iter() - .map(|s| GradientStop { + .map(|s| azure_hl::GradientStop { offset: s.offset as AzFloat, color: s.color.to_azure_style(), }) .collect(); - Pattern::RadialGradient(RadialGradientPattern::new( + azure_hl::Pattern::RadialGradient(RadialGradientPattern::new( &Point2D::new( radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat, @@ -1203,9 +1435,9 @@ impl ToAzurePattern for FillOrStrokeStyle { // FIXME(nox): Why are those i32 values? surface_style.surface_size.to_i32(), surface_style.surface_size.width as i32 * 4, - SurfaceFormat::B8G8R8A8, + azure_hl::SurfaceFormat::B8G8R8A8, )?; - Pattern::Surface(SurfacePattern::new( + azure_hl::Pattern::Surface(SurfacePattern::new( source_surface.azure_source_surface, surface_style.repeat_x, surface_style.repeat_y, @@ -1217,10 +1449,10 @@ impl ToAzurePattern for FillOrStrokeStyle { } impl ToAzureStyle for RGBA { - type Target = Color; + type Target = azure_hl::Color; - fn to_azure_style(self) -> Color { - Color::rgba( + fn to_azure_style(self) -> azure_hl::Color { + azure_hl::Color::rgba( self.red_f32() as AzFloat, self.green_f32() as AzFloat, self.blue_f32() as AzFloat, From 7c6460443c773e3f0ce8d3135c729d4eb9e81829 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Sat, 18 May 2019 00:16:29 +0200 Subject: [PATCH 03/14] Implement GenericDrawTarget for azure_hl::DrawTarget --- components/canvas/canvas_data.rs | 208 +++++++++++++++++++++++++++++-- 1 file changed, 197 insertions(+), 11 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 4f583b6d33b..b33855b9038 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -8,7 +8,7 @@ use azure::azure_hl::SurfacePattern; use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle}; use azure::azure_hl::{BackendType, DrawTarget}; use azure::azure_hl::{ColorPattern, DrawSurfaceOptions, Filter, PathBuilder}; -use azure::azure_hl::{ExtendMode, LinearGradientPattern, RadialGradientPattern}; +use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; @@ -167,22 +167,28 @@ trait GenericDrawTarget { fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D); fn create_gradient_stops( &self, - gradient_stops: &[GradientStop], + gradient_stops: Vec, extend_mode: ExtendMode, ) -> GradientStops; fn create_path_builder(&self); fn create_similar_draw_target( &self, - size: Size2D, + size: &Size2D, format: SurfaceFormat, ) -> Box; - fn create_source_surface_from_data(&self); + fn create_source_surface_from_data( + &self, + data: &[u8], + size: Size2D, + stride: i32, + format: SurfaceFormat, + ); fn draw_surface_with_shadow( &self, surface: SourceSurface, dest: &Point2D, color: &Color, - offset: Vector2D, + offset: &Vector2D, sigma: f32, operator: CompositionOp, ); @@ -219,6 +225,165 @@ trait GenericDrawTarget { ); } +impl GenericDrawTarget for azure_hl::DrawTarget { + fn clear_rect(&self, rect: &Rect) { + self.clear_rect(rect as &Rect); + } + + fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D) { + self.copy_surface(surface.into_azure(), source, destination); + } + + fn create_gradient_stops( + &self, + gradient_stops: Vec, + extend_mode: ExtendMode, + ) -> GradientStops { + let gradient_stops: Vec = + gradient_stops.into_iter().map(|x| x.into_azure()).collect(); + GradientStops::Azure(self.create_gradient_stops(&gradient_stops, extend_mode.into_azure())) + } + + fn create_path_builder(&self) { + self.create_path_builder(); + } + + fn create_similar_draw_target( + &self, + size: &Size2D, + format: SurfaceFormat, + ) -> Box { + Box::new(self.create_similar_draw_target(size, format.into_azure())) + } + fn create_source_surface_from_data( + &self, + data: &[u8], + size: Size2D, + stride: i32, + format: SurfaceFormat, + ) { + self.create_source_surface_from_data(data, size, stride, format.into_azure()); + } + fn draw_surface_with_shadow( + &self, + surface: SourceSurface, + dest: &Point2D, + color: &Color, + offset: &Vector2D, + sigma: f32, + operator: CompositionOp, + ) { + self.draw_surface_with_shadow( + surface.into_azure(), + dest as &Point2D, + color.as_azure(), + offset as &Vector2D, + sigma as AzFloat, + operator.into_azure(), + ); + } + fn fill(&self, path: &Path, pattern: PatternRef, draw_options: &DrawOptions) { + self.fill( + path.as_azure(), + pattern.into_azure(), + draw_options.as_azure(), + ); + } + fn fill_rect(&self, rect: &Rect, pattern: PatternRef, draw_options: Option<&DrawOptions>) { + self.fill_rect( + rect as &Rect, + pattern.into_azure(), + draw_options.map(|x| x.as_azure()), + ); + } + fn get_format(&self) -> SurfaceFormat { + SurfaceFormat::Azure(self.get_format()) + } + fn get_size(&self) -> IntSize { + IntSize::Azure(self.get_size()) + } + fn get_transform(&self) -> Transform2D { + self.get_transform() as Transform2D + } + fn pop_clip(&self) { + self.pop_clip(); + } + fn push_clip(&self, path: &Path) { + self.push_clip(path.as_azure()); + } + fn set_transform(&self, matrix: &Transform2D) { + self.set_transform(matrix as &Transform2D); + } + fn snapshot(&self) -> SourceSurface { + SourceSurface::Azure(self.snapshot()) + } + fn stroke( + &self, + path: &Path, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + self.stroke( + path.as_azure(), + pattern.into_azure(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } + fn stroke_line( + &self, + start: Point2D, + end: Point2D, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + self.stroke_line( + start as Point2D, + end as Point2D, + pattern.into_azure(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } + fn stroke_rect( + &self, + rect: &Rect, + pattern: PatternRef, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + self.stroke_rect( + rect as &Rect, + pattern.into_azure(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } +} + +enum ExtendMode { + Azure(azure_hl::ExtendMode), + Raqote(()), +} + +impl ExtendMode { + fn as_azure(&self) -> &azure_hl::ExtendMode { + match self { + ExtendMode::Azure(m) => m, + _ => unreachable!(), + } + } + + fn into_azure(self) -> azure_hl::ExtendMode { + match self { + ExtendMode::Azure(m) => m, + _ => unreachable!(), + } + } +} + enum GradientStop { Azure(AzGradientStop), Raqote(()), @@ -231,6 +396,13 @@ impl GradientStop { _ => unreachable!(), } } + + fn into_azure(self) -> AzGradientStop { + match self { + GradientStop::Azure(s) => s, + _ => unreachable!(), + } + } } enum GradientStops { @@ -245,6 +417,13 @@ impl GradientStops { _ => unreachable!(), } } + + fn into_azure(self) -> azure_hl::GradientStops { + match self { + GradientStops::Azure(s) => s, + _ => unreachable!(), + } + } } enum Color { @@ -267,7 +446,7 @@ enum CompositionOp { } impl CompositionOp { - fn as_azure(&self) -> &azure_hl::CompositionOp { + fn into_azure(self) -> azure_hl::CompositionOp { match self { CompositionOp::Azure(s) => s, _ => unreachable!(), @@ -281,7 +460,7 @@ enum SurfaceFormat { } impl SurfaceFormat { - fn as_azure(&self) -> &azure_hl::SurfaceFormat { + fn into_azure(self) -> azure_hl::SurfaceFormat { match self { SurfaceFormat::Azure(s) => s, _ => unreachable!(), @@ -295,7 +474,7 @@ enum SourceSurface { } impl SourceSurface { - fn as_azure(&self) -> &azure_hl::SourceSurface { + fn into_azure(self) -> azure_hl::SourceSurface { match self { SourceSurface::Azure(s) => s, _ => unreachable!(), @@ -348,6 +527,13 @@ impl<'a> PatternRef<'a> { _ => unreachable!(), } } + + fn into_azure(self) -> azure_hl::PatternRef<'a> { + match self { + PatternRef::Azure(p) => p, + _ => unreachable!(), + } + } } impl Pattern { @@ -379,7 +565,7 @@ enum StrokeOptions<'a> { } impl<'a> StrokeOptions<'a> { - fn as_azure_ref(&self) -> &azure_hl::StrokeOptions<'a> { + fn as_azure(&self) -> &azure_hl::StrokeOptions<'a> { match self { StrokeOptions::Azure(options) => options, _ => unreachable!(), @@ -1400,7 +1586,7 @@ impl ToAzurePattern for FillOrStrokeStyle { linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat, ), - drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), + drawtarget.create_gradient_stops(&gradient_stops, azure_hl::ExtendMode::Clamp), &Transform2D::identity(), )) }, @@ -1425,7 +1611,7 @@ impl ToAzurePattern for FillOrStrokeStyle { ), radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat, - drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), + drawtarget.create_gradient_stops(&gradient_stops, azure_hl::ExtendMode::Clamp), &Transform2D::identity(), )) }, From 3182eba73be84dc18e460055a8cddea47f8be752 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Sat, 18 May 2019 08:43:58 +0200 Subject: [PATCH 04/14] Implement GenericPathBuilder for azure_hl::PathBuilder --- components/canvas/canvas_data.rs | 106 ++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index b33855b9038..6507f17589d 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -2,7 +2,7 @@ * 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/. */ -use azure::azure::{AzFloat, AzGradientStop, AzIntSize}; +use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint}; use azure::azure_hl; use azure::azure_hl::SurfacePattern; use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle}; @@ -57,6 +57,110 @@ impl PathState { } } +/// A generic PathBuilder that abstracts the interface for +/// azure's and raqote's PathBuilder. +trait GenericPathBuilder { + fn arc( + &self, + origin: Point2D, + radius: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ); + fn bezier_curve_to( + &self, + control_point1: &Point2D, + control_point2: &Point2D, + control_point3: &Point2D, + ); + fn close(&self); + fn ellipse( + &self, + origin: Point2D, + radius_x: f32, + radius_y: f32, + rotation_angle: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ); + fn get_current_point(&self) -> Point2D; + fn line_to(&self, point: Point2D); + fn move_to(&self, point: Point2D); + fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D); +} + +impl GenericPathBuilder for azure_hl::PathBuilder { + fn arc( + &self, + origin: Point2D, + radius: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ) { + self.arc( + origin as Point2D, + radius as AzFloat, + start_angle as AzFloat, + end_angle as AzFloat, + anticlockwise, + ); + } + fn bezier_curve_to( + &self, + control_point1: &Point2D, + control_point2: &Point2D, + control_point3: &Point2D, + ) { + self.bezier_curve_to( + control_point1 as &Point2D, + control_point2 as &Point2D, + control_point3 as &Point2D, + ); + } + fn close(&self) { + self.close(); + } + fn ellipse( + &self, + origin: Point2D, + radius_x: f32, + radius_y: f32, + rotation_angle: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ) { + self.ellipse( + origin as Point2D, + radius_x as AzFloat, + radius_y as AzFloat, + rotation_angle as AzFloat, + start_angle as AzFloat, + end_angle as AzFloat, + anticlockwise, + ); + } + fn get_current_point(&self) -> Point2D { + let AzPoint { x, y } = self.get_current_point(); + Point2D::new(x as f32, y as f32) + } + fn line_to(&self, point: Point2D) { + self.line_to(point as Point2D); + } + fn move_to(&self, point: Point2D) { + self.move_to(point as Point2D); + } + fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D) { + self.quadratic_curve_to( + control_point as &Point2D, + end_point as &Point2D, + ); + } +} + /// A wrapper around a stored PathBuilder and an optional transformation that should be /// applied to any points to ensure they are in the matching device space. struct PathBuilderRef<'a> { From 7ace517770b4f77a257cc54327b86771c29f2a9d Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Tue, 21 May 2019 19:32:55 +0200 Subject: [PATCH 05/14] Make CanvasPaintState generic --- components/canvas/canvas_data.rs | 79 ++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 6507f17589d..9de29b912e9 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -467,6 +467,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { } } +#[derive(Clone)] enum ExtendMode { Azure(azure_hl::ExtendMode), Raqote(()), @@ -488,6 +489,7 @@ impl ExtendMode { } } +#[derive(Clone)] enum GradientStop { Azure(AzGradientStop), Raqote(()), @@ -509,6 +511,7 @@ impl GradientStop { } } +#[derive(Clone)] enum GradientStops { Azure(azure_hl::GradientStops), Raqote(()), @@ -530,6 +533,7 @@ impl GradientStops { } } +#[derive(Clone)] enum Color { Azure(azure_hl::Color), Raqote(()), @@ -544,6 +548,7 @@ impl Color { } } +#[derive(Clone)] enum CompositionOp { Azure(azure_hl::CompositionOp), Raqote(()), @@ -558,6 +563,7 @@ impl CompositionOp { } } +#[derive(Clone)] enum SurfaceFormat { Azure(azure_hl::SurfaceFormat), Raqote(()), @@ -572,6 +578,7 @@ impl SurfaceFormat { } } +#[derive(Clone)] enum SourceSurface { Azure(azure_hl::SourceSurface), Raqote(()), @@ -586,6 +593,7 @@ impl SourceSurface { } } +#[derive(Clone)] enum IntSize { Azure(AzIntSize), Raqote(()), @@ -600,6 +608,7 @@ impl IntSize { } } +#[derive(Clone)] enum Path { Azure(azure_hl::Path), Raqote(()), @@ -614,11 +623,13 @@ impl Path { } } +#[derive(Clone)] enum Pattern { Azure(azure_hl::Pattern), Raqote(()), } +#[derive(Clone)] enum PatternRef<'a> { Azure(azure_hl::PatternRef<'a>), Raqote(()), @@ -649,6 +660,7 @@ impl Pattern { } } +#[derive(Clone)] enum DrawOptions { Azure(azure_hl::DrawOptions), Raqote(()), @@ -663,6 +675,7 @@ impl DrawOptions { } } +#[derive(Clone)] enum StrokeOptions<'a> { Azure(azure_hl::StrokeOptions<'a>), Raqote(()), @@ -703,7 +716,7 @@ impl<'a> CanvasData<'a> { CanvasData { drawtarget: draw_target, path_state: None, - state: CanvasPaintState::new(antialias), + state: CanvasPaintState::new(antialias, CanvasBackend::Azure), saved_states: vec![], webrender_api: webrender_api, image_key: None, @@ -1236,7 +1249,7 @@ impl<'a> CanvasData<'a> { pub fn recreate(&mut self, size: Size2D) { self.drawtarget = CanvasData::create(Size2D::new(size.width as u64, size.height as u64)); - self.state = CanvasPaintState::new(self.state.draw_options.antialias); + self.state = CanvasPaintState::new(self.state.draw_options.antialias, CanvasBackend::Azure); self.saved_states.clear(); // Webrender doesn't let images change size, so we clear the webrender image key. // TODO: there is an annying race condition here: the display list builder @@ -1423,38 +1436,56 @@ impl<'a> Drop for CanvasData<'a> { } } +enum CanvasBackend { + Azure, + Raqote, +} + #[derive(Clone)] struct CanvasPaintState<'a> { - draw_options: azure_hl::DrawOptions, - fill_style: azure_hl::Pattern, - stroke_style: azure_hl::Pattern, - stroke_opts: azure_hl::StrokeOptions<'a>, + draw_options: DrawOptions, + fill_style: Pattern, + stroke_style: Pattern, + stroke_opts: StrokeOptions<'a>, /// The current 2D transform matrix. transform: Transform2D, shadow_offset_x: f64, shadow_offset_y: f64, shadow_blur: f64, - shadow_color: azure_hl::Color, + shadow_color: Color, } impl<'a> CanvasPaintState<'a> { - fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> { - CanvasPaintState { - draw_options: azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias), - fill_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), - stroke_style: azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), - stroke_opts: azure_hl::StrokeOptions::new( - 1.0, - JoinStyle::MiterOrBevel, - CapStyle::Butt, - 10.0, - &[], - ), - transform: Transform2D::identity(), - shadow_offset_x: 0.0, - shadow_offset_y: 0.0, - shadow_blur: 0.0, - shadow_color: azure_hl::Color::transparent(), + fn new(antialias: AntialiasMode, backend: CanvasBackend) -> CanvasPaintState<'a> { + match backend { + CanvasBackend::Azure => CanvasPaintState { + draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias)), + fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), + stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), + stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new( + 1.0, + JoinStyle::MiterOrBevel, + CapStyle::Butt, + 10.0, + &[], + )), + transform: Transform2D::identity(), + shadow_offset_x: 0.0, + shadow_offset_y: 0.0, + shadow_blur: 0.0, + shadow_color: Color::Azure(azure_hl::Color::transparent()), + }, + CanvasBackend::Raqote => CanvasPaintState { + draw_options: DrawOptions::Raqote(()), + fill_style: Pattern::Raqote(()), + stroke_style: Pattern::Raqote(()), + stroke_opts: StrokeOptions::Raqote(()), + transform: Transform2D::identity(), + shadow_offset_x: 0.0, + shadow_offset_y: 0.0, + shadow_blur: 0.0, + shadow_color: Color::Raqote(()), + } } } } From 42bf1984be6498517e98b7942633ec0f57adaab1 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Fri, 24 May 2019 15:45:15 +0200 Subject: [PATCH 06/14] Make CanvasData use GenericDrawTarget --- components/canvas/canvas_data.rs | 393 +++++++++++++---------- components/canvas/canvas_paint_thread.rs | 2 +- 2 files changed, 223 insertions(+), 172 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 9de29b912e9..bb14e223149 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -7,7 +7,7 @@ use azure::azure_hl; use azure::azure_hl::SurfacePattern; use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle}; use azure::azure_hl::{BackendType, DrawTarget}; -use azure::azure_hl::{ColorPattern, DrawSurfaceOptions, Filter, PathBuilder}; +use azure::azure_hl::{ColorPattern, Filter}; use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; use canvas_traits::canvas::*; use cssparser::RGBA; @@ -30,13 +30,13 @@ enum PathState { /// Path builder in user-space. If a transform has been applied /// but no further path operations have occurred, it is stored /// in the optional field. - UserSpacePathBuilder(PathBuilder, Option>), + UserSpacePathBuilder(Box, Option>), /// Path builder in device-space. - DeviceSpacePathBuilder(PathBuilder), + DeviceSpacePathBuilder(Box), /// Path in user-space. If a transform has been applied but /// but no further path operations have occurred, it is stored /// in the optional field. - UserSpacePath(azure_hl::Path, Option>), + UserSpacePath(Path, Option>), } impl PathState { @@ -47,7 +47,7 @@ impl PathState { } } - fn path(&self) -> &azure_hl::Path { + fn path(&self) -> &Path { match *self { PathState::UserSpacePath(ref p, _) => p, PathState::UserSpacePathBuilder(..) | PathState::DeviceSpacePathBuilder(..) => { @@ -89,6 +89,7 @@ trait GenericPathBuilder { fn line_to(&self, point: Point2D); fn move_to(&self, point: Point2D); fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D); + fn finish(&self) -> Path; } impl GenericPathBuilder for azure_hl::PathBuilder { @@ -159,12 +160,15 @@ impl GenericPathBuilder for azure_hl::PathBuilder { end_point as &Point2D, ); } + fn finish(&self) -> Path { + Path::Azure(self.finish()) + } } /// A wrapper around a stored PathBuilder and an optional transformation that should be /// applied to any points to ensure they are in the matching device space. struct PathBuilderRef<'a> { - builder: &'a PathBuilder, + builder: &'a Box, transform: Transform2D, } @@ -274,7 +278,7 @@ trait GenericDrawTarget { gradient_stops: Vec, extend_mode: ExtendMode, ) -> GradientStops; - fn create_path_builder(&self); + fn create_path_builder(&self) -> Box; fn create_similar_draw_target( &self, size: &Size2D, @@ -286,6 +290,14 @@ trait GenericDrawTarget { size: Size2D, stride: i32, format: SurfaceFormat, + ) -> Option; + fn draw_surface( + &self, + surface: SourceSurface, + dest: Rect, + source: Rect, + surf_options: DrawSurfaceOptions, + options: DrawOptions, ); fn draw_surface_with_shadow( &self, @@ -296,8 +308,8 @@ trait GenericDrawTarget { sigma: f32, operator: CompositionOp, ); - fn fill(&self, path: &Path, pattern: PatternRef, draw_options: &DrawOptions); - fn fill_rect(&self, rect: &Rect, pattern: PatternRef, draw_options: Option<&DrawOptions>); + fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions); + fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>); fn get_format(&self) -> SurfaceFormat; fn get_size(&self) -> IntSize; fn get_transform(&self) -> Transform2D; @@ -308,7 +320,7 @@ trait GenericDrawTarget { fn stroke( &self, path: &Path, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); @@ -316,14 +328,14 @@ trait GenericDrawTarget { &self, start: Point2D, end: Point2D, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); fn stroke_rect( &self, rect: &Rect, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); @@ -348,8 +360,8 @@ impl GenericDrawTarget for azure_hl::DrawTarget { GradientStops::Azure(self.create_gradient_stops(&gradient_stops, extend_mode.into_azure())) } - fn create_path_builder(&self) { - self.create_path_builder(); + fn create_path_builder(&self) -> Box { + Box::new(self.create_path_builder()) } fn create_similar_draw_target( @@ -365,8 +377,24 @@ impl GenericDrawTarget for azure_hl::DrawTarget { size: Size2D, stride: i32, format: SurfaceFormat, + ) -> Option { + self.create_source_surface_from_data(data, size, stride, format.into_azure()).map(|s| SourceSurface::Azure(s)) + } + fn draw_surface( + &self, + surface: SourceSurface, + dest: Rect, + source: Rect, + surf_options: DrawSurfaceOptions, + options: DrawOptions, ) { - self.create_source_surface_from_data(data, size, stride, format.into_azure()); + self.draw_surface( + surface.into_azure(), + dest as Rect, + source as Rect, + surf_options.into_azure(), + options.into_azure(), + ); } fn draw_surface_with_shadow( &self, @@ -386,17 +414,17 @@ impl GenericDrawTarget for azure_hl::DrawTarget { operator.into_azure(), ); } - fn fill(&self, path: &Path, pattern: PatternRef, draw_options: &DrawOptions) { + fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { self.fill( path.as_azure(), - pattern.into_azure(), + pattern.as_azure().to_pattern_ref(), draw_options.as_azure(), ); } - fn fill_rect(&self, rect: &Rect, pattern: PatternRef, draw_options: Option<&DrawOptions>) { + fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>) { self.fill_rect( rect as &Rect, - pattern.into_azure(), + pattern.as_azure().to_pattern_ref(), draw_options.map(|x| x.as_azure()), ); } @@ -424,13 +452,13 @@ impl GenericDrawTarget for azure_hl::DrawTarget { fn stroke( &self, path: &Path, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ) { self.stroke( path.as_azure(), - pattern.into_azure(), + pattern.as_azure().to_pattern_ref(), stroke_options.as_azure(), draw_options.as_azure(), ); @@ -439,14 +467,14 @@ impl GenericDrawTarget for azure_hl::DrawTarget { &self, start: Point2D, end: Point2D, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ) { self.stroke_line( start as Point2D, end as Point2D, - pattern.into_azure(), + pattern.as_azure().to_pattern_ref(), stroke_options.as_azure(), draw_options.as_azure(), ); @@ -454,13 +482,13 @@ impl GenericDrawTarget for azure_hl::DrawTarget { fn stroke_rect( &self, rect: &Rect, - pattern: PatternRef, + pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ) { self.stroke_rect( rect as &Rect, - pattern.into_azure(), + pattern.as_azure().to_pattern_ref(), stroke_options.as_azure(), draw_options.as_azure(), ); @@ -474,13 +502,6 @@ enum ExtendMode { } impl ExtendMode { - fn as_azure(&self) -> &azure_hl::ExtendMode { - match self { - ExtendMode::Azure(m) => m, - _ => unreachable!(), - } - } - fn into_azure(self) -> azure_hl::ExtendMode { match self { ExtendMode::Azure(m) => m, @@ -489,20 +510,12 @@ impl ExtendMode { } } -#[derive(Clone)] enum GradientStop { Azure(AzGradientStop), Raqote(()), } impl GradientStop { - fn as_azure(&self) -> &AzGradientStop { - match self { - GradientStop::Azure(s) => s, - _ => unreachable!(), - } - } - fn into_azure(self) -> AzGradientStop { match self { GradientStop::Azure(s) => s, @@ -511,20 +524,12 @@ impl GradientStop { } } -#[derive(Clone)] enum GradientStops { Azure(azure_hl::GradientStops), Raqote(()), } impl GradientStops { - fn as_azure(&self) -> &azure_hl::GradientStops { - match self { - GradientStops::Azure(s) => s, - _ => unreachable!(), - } - } - fn into_azure(self) -> azure_hl::GradientStops { match self { GradientStops::Azure(s) => s, @@ -534,7 +539,7 @@ impl GradientStops { } #[derive(Clone)] -enum Color { +pub enum Color { Azure(azure_hl::Color), Raqote(()), } @@ -563,7 +568,6 @@ impl CompositionOp { } } -#[derive(Clone)] enum SurfaceFormat { Azure(azure_hl::SurfaceFormat), Raqote(()), @@ -593,14 +597,13 @@ impl SourceSurface { } } -#[derive(Clone)] enum IntSize { Azure(AzIntSize), Raqote(()), } impl IntSize { - fn as_azure(&self) -> &AzIntSize { + fn into_azure(self) -> AzIntSize { match self { IntSize::Azure(s) => s, _ => unreachable!(), @@ -608,7 +611,6 @@ impl IntSize { } } -#[derive(Clone)] enum Path { Azure(azure_hl::Path), Raqote(()), @@ -629,28 +631,6 @@ enum Pattern { Raqote(()), } -#[derive(Clone)] -enum PatternRef<'a> { - Azure(azure_hl::PatternRef<'a>), - Raqote(()), -} - -impl<'a> PatternRef<'a> { - fn as_azure(&self) -> &azure_hl::PatternRef<'a> { - match self { - PatternRef::Azure(p) => p, - _ => unreachable!(), - } - } - - fn into_azure(self) -> azure_hl::PatternRef<'a> { - match self { - PatternRef::Azure(p) => p, - _ => unreachable!(), - } - } -} - impl Pattern { fn as_azure(&self) -> &azure_hl::Pattern { match self { @@ -660,6 +640,20 @@ impl Pattern { } } +enum DrawSurfaceOptions { + Azure(azure_hl::DrawSurfaceOptions), + Raqote(()), +} + +impl DrawSurfaceOptions { + fn into_azure(self) -> azure_hl::DrawSurfaceOptions { + match self { + DrawSurfaceOptions::Azure(options) => options, + _ => unreachable!(), + } + } +} + #[derive(Clone)] enum DrawOptions { Azure(azure_hl::DrawOptions), @@ -673,6 +667,24 @@ impl DrawOptions { _ => unreachable!(), } } + fn as_azure_mut(&mut self) -> &mut azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + _ => unreachable!(), + } + } + fn into_azure(self) -> azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + _ => unreachable!(), + } + } + fn set_alpha(&mut self, val: f32) { + match self { + DrawOptions::Azure(options) => options.alpha = val as AzFloat, + _ => unreachable!(), + } + } } #[derive(Clone)] @@ -688,10 +700,34 @@ impl<'a> StrokeOptions<'a> { _ => unreachable!(), } } + fn set_line_width(&mut self, val: f32) { + match self { + StrokeOptions::Azure(options) => options.line_width = val as AzFloat, + _ => unreachable!(), + } + } + fn set_miter_limit(&mut self, val: f32) { + match self { + StrokeOptions::Azure(options) => options.miter_limit = val as AzFloat, + _ => unreachable!(), + } + } + fn set_line_join(&mut self, val: LineJoinStyle) { + match self { + StrokeOptions::Azure(options) => options.line_join = val.to_azure_style(), + _ => unreachable!(), + } + } + fn set_line_cap(&mut self, val: LineCapStyle) { + match self { + StrokeOptions::Azure(options) => options.line_cap = val.to_azure_style(), + _ => unreachable!(), + } + } } pub struct CanvasData<'a> { - drawtarget: DrawTarget, + drawtarget: Box, path_state: Option, state: CanvasPaintState<'a>, saved_states: Vec>, @@ -743,15 +779,17 @@ impl<'a> CanvasData<'a> { image_data.into() }; - let writer = |draw_target: &DrawTarget| { + + // TODO(pylbrecht) create another clousure for raqote + let writer = |draw_target: &GenericDrawTarget| { write_image( - &draw_target, + draw_target, image_data, source_rect.size, dest_rect, smoothing_enabled, - self.state.draw_options.composition, - self.state.draw_options.alpha, + CompositionOp::Azure(self.state.draw_options.as_azure().composition), + self.state.draw_options.as_azure().alpha, ); }; @@ -761,9 +799,10 @@ impl<'a> CanvasData<'a> { Size2D::new(dest_rect.size.width as f32, dest_rect.size.height as f32), ); + // TODO(pylbrecht) pass another closure for raqote self.draw_with_shadow(&rect, writer); } else { - writer(&self.drawtarget); + writer(&*self.drawtarget); } } @@ -793,34 +832,39 @@ impl<'a> CanvasData<'a> { let draw_rect = Rect::new( rect.origin, - match self.state.fill_style { - azure_hl::Pattern::Surface(ref surface) => { - let surface_size = surface.size(); - match (surface.repeat_x, surface.repeat_y) { - (true, true) => rect.size, - (true, false) => Size2D::new(rect.size.width, surface_size.height as f32), - (false, true) => Size2D::new(surface_size.width as f32, rect.size.height), - (false, false) => { - Size2D::new(surface_size.width as f32, surface_size.height as f32) - }, + match &self.state.fill_style { + Pattern::Azure(pattern) => { + match pattern { + azure_hl::Pattern::Surface(ref surface) => { + let surface_size = surface.size(); + match (surface.repeat_x, surface.repeat_y) { + (true, true) => rect.size, + (true, false) => Size2D::new(rect.size.width, surface_size.height as f32), + (false, true) => Size2D::new(surface_size.width as f32, rect.size.height), + (false, false) => { + Size2D::new(surface_size.width as f32, surface_size.height as f32) + }, + } + } + _ => rect.size, } }, - _ => rect.size, - }, + _ => unreachable!(), + } ); if self.need_to_draw_shadow() { - self.draw_with_shadow(&draw_rect, |new_draw_target: &DrawTarget| { + self.draw_with_shadow(&draw_rect, |new_draw_target: &GenericDrawTarget| { new_draw_target.fill_rect( &draw_rect, - self.state.fill_style.to_pattern_ref(), + self.state.fill_style.clone(), Some(&self.state.draw_options), ); }); } else { self.drawtarget.fill_rect( &draw_rect, - self.state.fill_style.to_pattern_ref(), + self.state.fill_style.clone(), Some(&self.state.draw_options), ); } @@ -836,38 +880,38 @@ impl<'a> CanvasData<'a> { } if self.need_to_draw_shadow() { - self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| { + self.draw_with_shadow(&rect, |new_draw_target: &GenericDrawTarget| { new_draw_target.stroke_rect( rect, - self.state.stroke_style.to_pattern_ref(), + self.state.stroke_style.clone(), &self.state.stroke_opts, &self.state.draw_options, ); }); } else if rect.size.width == 0. || rect.size.height == 0. { - let cap = match self.state.stroke_opts.line_join { + let cap = match self.state.stroke_opts.as_azure().line_join { JoinStyle::Round => CapStyle::Round, _ => CapStyle::Butt, }; - let stroke_opts = azure_hl::StrokeOptions::new( - self.state.stroke_opts.line_width, - self.state.stroke_opts.line_join, + let stroke_opts = StrokeOptions::Azure(azure_hl::StrokeOptions::new( + self.state.stroke_opts.as_azure().line_width, + self.state.stroke_opts.as_azure().line_join, cap, - self.state.stroke_opts.miter_limit, - self.state.stroke_opts.mDashPattern, - ); + self.state.stroke_opts.as_azure().miter_limit, + self.state.stroke_opts.as_azure().mDashPattern, + )); self.drawtarget.stroke_line( rect.origin, rect.bottom_right(), - self.state.stroke_style.to_pattern_ref(), + self.state.stroke_style.clone(), &stroke_opts, &self.state.draw_options, ); } else { self.drawtarget.stroke_rect( rect, - self.state.stroke_style.to_pattern_ref(), + self.state.stroke_style.clone(), &self.state.stroke_opts, &self.state.draw_options, ); @@ -907,7 +951,7 @@ impl<'a> CanvasData<'a> { // any transform is present. let new_state = match *self.path_state.as_ref().unwrap() { PathState::UserSpacePath(ref path, Some(ref transform)) => { - Some(path.transformed_copy_to_builder(transform)) + Some(Box::new(path.as_azure().transformed_copy_to_builder(transform))) }, PathState::UserSpacePath(..) | PathState::UserSpacePathBuilder(..) | @@ -929,8 +973,8 @@ impl<'a> CanvasData<'a> { return; }, }; - let builder = path.transformed_copy_to_builder(&inverse); - Some(builder.finish()) + let builder = Box::new(path.as_azure().transformed_copy_to_builder(&inverse)); + Some(Path::Azure(builder.finish())) }, PathState::UserSpacePathBuilder(..) | PathState::UserSpacePath(..) => None, }; @@ -941,7 +985,7 @@ impl<'a> CanvasData<'a> { assert!(self.path_state.as_ref().unwrap().is_path()) } - fn path(&self) -> &azure_hl::Path { + fn path(&self) -> &Path { self.path_state .as_ref() .expect("Should have called ensure_path()") @@ -956,7 +1000,7 @@ impl<'a> CanvasData<'a> { self.ensure_path(); self.drawtarget.fill( &self.path(), - self.state.fill_style.to_pattern_ref(), + self.state.fill_style.clone(), &self.state.draw_options, ); } @@ -969,7 +1013,7 @@ impl<'a> CanvasData<'a> { self.ensure_path(); self.drawtarget.stroke( &self.path(), - self.state.stroke_style.to_pattern_ref(), + self.state.stroke_style.clone(), &self.state.stroke_opts, &self.state.draw_options, ); @@ -992,7 +1036,7 @@ impl<'a> CanvasData<'a> { Some(PathState::UserSpacePath(ref path, ref transform)) => { let target_transform = self.drawtarget.get_transform(); let path_transform = transform.as_ref().unwrap_or(&target_transform); - path.contains_point(x, y, path_transform) + path.as_azure().contains_point(x, y, path_transform) }, Some(_) | None => false, }; @@ -1025,14 +1069,14 @@ impl<'a> CanvasData<'a> { &PathState::UserSpacePathBuilder(ref builder, Some(ref transform)) => { let path = builder.finish(); Some(PathState::DeviceSpacePathBuilder( - path.transformed_copy_to_builder(transform), + Box::new(path.as_azure().transformed_copy_to_builder(transform)), )) }, &PathState::UserSpacePath(ref path, Some(ref transform)) => Some( - PathState::DeviceSpacePathBuilder(path.transformed_copy_to_builder(transform)), + PathState::DeviceSpacePathBuilder(Box::new(path.as_azure().transformed_copy_to_builder(transform))), ), &PathState::UserSpacePath(ref path, None) => Some(PathState::UserSpacePathBuilder( - path.copy_to_builder(), + Box::new(path.as_azure().copy_to_builder()), None, )), } @@ -1185,31 +1229,31 @@ impl<'a> CanvasData<'a> { } pub fn set_fill_style(&mut self, style: FillOrStrokeStyle) { - if let Some(pattern) = style.to_azure_pattern(&self.drawtarget) { - self.state.fill_style = pattern + if let Some(pattern) = style.to_azure_pattern(&*self.drawtarget) { + self.state.fill_style = Pattern::Azure(pattern) } } pub fn set_stroke_style(&mut self, style: FillOrStrokeStyle) { - if let Some(pattern) = style.to_azure_pattern(&self.drawtarget) { - self.state.stroke_style = pattern + if let Some(pattern) = style.to_azure_pattern(&*self.drawtarget) { + self.state.stroke_style = Pattern::Azure(pattern) } } pub fn set_line_width(&mut self, width: f32) { - self.state.stroke_opts.line_width = width; + self.state.stroke_opts.set_line_width(width); } pub fn set_line_cap(&mut self, cap: LineCapStyle) { - self.state.stroke_opts.line_cap = cap.to_azure_style(); + self.state.stroke_opts.set_line_cap(cap); } pub fn set_line_join(&mut self, join: LineJoinStyle) { - self.state.stroke_opts.line_join = join.to_azure_style(); + self.state.stroke_opts.set_line_join(join); } pub fn set_miter_limit(&mut self, limit: f32) { - self.state.stroke_opts.miter_limit = limit; + self.state.stroke_opts.set_miter_limit(limit); } pub fn set_transform(&mut self, transform: &Transform2D) { @@ -1229,27 +1273,28 @@ impl<'a> CanvasData<'a> { } pub fn set_global_alpha(&mut self, alpha: f32) { - self.state.draw_options.alpha = alpha; + self.state.draw_options.set_alpha(alpha); } pub fn set_global_composition(&mut self, op: CompositionOrBlending) { self.state .draw_options + .as_azure_mut() .set_composition_op(op.to_azure_style()); } - pub fn create(size: Size2D) -> DrawTarget { + pub fn create(size: Size2D) -> Box { // FIXME(nox): Why is the size made of i32 values? - DrawTarget::new( + Box::new(DrawTarget::new( BackendType::Skia, size.to_i32(), azure_hl::SurfaceFormat::B8G8R8A8, - ) + )) } pub fn recreate(&mut self, size: Size2D) { self.drawtarget = CanvasData::create(Size2D::new(size.width as u64, size.height as u64)); - self.state = CanvasPaintState::new(self.state.draw_options.antialias, CanvasBackend::Azure); + self.state = CanvasPaintState::new(self.state.draw_options.as_azure().antialias, CanvasBackend::Azure); self.saved_states.clear(); // Webrender doesn't let images change size, so we clear the webrender image key. // TODO: there is an annying race condition here: the display list builder @@ -1267,14 +1312,14 @@ impl<'a> CanvasData<'a> { #[allow(unsafe_code)] pub fn send_pixels(&mut self, chan: IpcSender) { let data = IpcSharedMemory::from_bytes(unsafe { - self.drawtarget.snapshot().get_data_surface().data() + self.drawtarget.snapshot().into_azure().get_data_surface().data() }); chan.send(data).unwrap(); } #[allow(unsafe_code)] pub fn send_data(&mut self, chan: IpcSender) { - let size = self.drawtarget.get_size(); + let size = self.drawtarget.get_size().into_azure(); let descriptor = webrender_api::ImageDescriptor { size: webrender_api::DeviceIntSize::new(size.width, size.height), @@ -1285,7 +1330,7 @@ impl<'a> CanvasData<'a> { allow_mipmaps: false, }; let data = webrender_api::ImageData::Raw(Arc::new(unsafe { - self.drawtarget.snapshot().get_data_surface().data().into() + self.drawtarget.snapshot().into_azure().get_data_surface().data().into() })); let mut txn = webrender_api::Transaction::new(); @@ -1327,7 +1372,7 @@ impl<'a> CanvasData<'a> { &imagedata, rect.size.to_i32(), rect.size.width as i32 * 4, - azure_hl::SurfaceFormat::B8G8R8A8, + SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), ) .unwrap(); self.drawtarget.copy_surface( @@ -1349,19 +1394,19 @@ impl<'a> CanvasData<'a> { self.state.shadow_blur = value; } - pub fn set_shadow_color(&mut self, value: azure_hl::Color) { + pub fn set_shadow_color(&mut self, value: Color) { self.state.shadow_color = value; } // https://html.spec.whatwg.org/multipage/#when-shadows-are-drawn fn need_to_draw_shadow(&self) -> bool { - self.state.shadow_color.a != 0.0f32 && + self.state.shadow_color.as_azure().a != 0.0f32 && (self.state.shadow_offset_x != 0.0f64 || self.state.shadow_offset_y != 0.0f64 || self.state.shadow_blur != 0.0f64) } - fn create_draw_target_for_shadow(&self, source_rect: &Rect) -> DrawTarget { + fn create_draw_target_for_shadow(&self, source_rect: &Rect) -> Box { let draw_target = self.drawtarget.create_similar_draw_target( &Size2D::new( source_rect.size.width as i32, @@ -1378,11 +1423,11 @@ impl<'a> CanvasData<'a> { fn draw_with_shadow(&self, rect: &Rect, draw_shadow_source: F) where - F: FnOnce(&DrawTarget), + F: FnOnce(&GenericDrawTarget), { let shadow_src_rect = self.state.transform.transform_rect(rect); let new_draw_target = self.create_draw_target_for_shadow(&shadow_src_rect); - draw_shadow_source(&new_draw_target); + draw_shadow_source(&*new_draw_target); self.drawtarget.draw_surface_with_shadow( new_draw_target.snapshot(), &Point2D::new( @@ -1395,7 +1440,7 @@ impl<'a> CanvasData<'a> { self.state.shadow_offset_y as AzFloat, ), (self.state.shadow_blur / 2.0f64) as AzFloat, - self.state.draw_options.composition, + CompositionOp::Azure(self.state.draw_options.as_azure().composition), ); } @@ -1407,17 +1452,18 @@ impl<'a> CanvasData<'a> { let canvas_rect = Rect::from_size(canvas_size); if canvas_rect .intersection(&read_rect) - .map_or(true, |rect| rect.is_empty()) - { - return vec![]; - } - let data_surface = self.drawtarget.snapshot().get_data_surface(); + .map_or(true, |rect| rect.is_empty()) + { + return vec![]; + } + + let data_surface = self.drawtarget.snapshot().into_azure().get_data_surface(); pixels::rgba8_get_rect( unsafe { data_surface.data() }, canvas_size.to_u32(), read_rect.to_u32(), - ) - .into_owned() + ) + .into_owned() } } @@ -1490,13 +1536,18 @@ impl<'a> CanvasPaintState<'a> { } } -fn is_zero_size_gradient(pattern: &azure_hl::Pattern) -> bool { - if let &azure_hl::Pattern::LinearGradient(ref gradient) = pattern { - if gradient.is_zero_size() { - return true; - } +fn is_zero_size_gradient(pattern: &Pattern) -> bool { + match pattern { + Pattern::Azure(ref az_pattern) => { + if let azure_hl::Pattern::LinearGradient(ref gradient) = az_pattern { + if gradient.is_zero_size() { + return true; + } + } + false + }, + _ => unreachable!(), } - false } /// It writes an image to the destination target @@ -1506,12 +1557,12 @@ fn is_zero_size_gradient(pattern: &azure_hl::Pattern) -> bool { /// dest_rect: Area of the destination target where the pixels will be copied /// smoothing_enabled: It determines if smoothing is applied to the image result fn write_image( - draw_target: &DrawTarget, + draw_target: &GenericDrawTarget, image_data: Vec, image_size: Size2D, dest_rect: Rect, smoothing_enabled: bool, - composition_op: azure_hl::CompositionOp, + composition_op: CompositionOp, global_alpha: f32, ) { if image_data.is_empty() { @@ -1535,12 +1586,12 @@ fn write_image( &image_data, image_size, image_size.width * 4, - azure_hl::SurfaceFormat::B8G8R8A8, - ) + SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), + ) .unwrap(); - let draw_surface_options = DrawSurfaceOptions::new(filter, true); + let draw_surface_options = DrawSurfaceOptions::Azure(azure_hl::DrawSurfaceOptions::new(filter, true)); let draw_options = - azure_hl::DrawOptions::new(global_alpha, composition_op, AntialiasMode::None); + DrawOptions::Azure(azure_hl::DrawOptions::new(global_alpha, composition_op.into_azure(), AntialiasMode::None)); draw_target.draw_surface( source_surface, dest_rect.to_azure_style(), @@ -1693,23 +1744,23 @@ impl ToAzureStyle for CompositionOrBlending { } pub trait ToAzurePattern { - fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option; + fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option; } impl ToAzurePattern for FillOrStrokeStyle { - fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option { + fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option { Some(match *self { FillOrStrokeStyle::Color(ref color) => { azure_hl::Pattern::Color(ColorPattern::new(color.to_azure_style())) }, FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => { - let gradient_stops: Vec = linear_gradient_style + let gradient_stops: Vec = linear_gradient_style .stops .iter() - .map(|s| azure_hl::GradientStop { + .map(|s| GradientStop::Azure(azure_hl::GradientStop { offset: s.offset as AzFloat, color: s.color.to_azure_style(), - }) + })) .collect(); azure_hl::Pattern::LinearGradient(LinearGradientPattern::new( @@ -1721,18 +1772,18 @@ impl ToAzurePattern for FillOrStrokeStyle { linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat, ), - drawtarget.create_gradient_stops(&gradient_stops, azure_hl::ExtendMode::Clamp), + drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), &Transform2D::identity(), )) }, FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => { - let gradient_stops: Vec = radial_gradient_style + let gradient_stops: Vec = radial_gradient_style .stops .iter() - .map(|s| azure_hl::GradientStop { + .map(|s| GradientStop::Azure(azure_hl::GradientStop { offset: s.offset as AzFloat, color: s.color.to_azure_style(), - }) + })) .collect(); azure_hl::Pattern::RadialGradient(RadialGradientPattern::new( @@ -1746,7 +1797,7 @@ impl ToAzurePattern for FillOrStrokeStyle { ), radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat, - drawtarget.create_gradient_stops(&gradient_stops, azure_hl::ExtendMode::Clamp), + drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), &Transform2D::identity(), )) }, @@ -1756,8 +1807,8 @@ impl ToAzurePattern for FillOrStrokeStyle { // FIXME(nox): Why are those i32 values? surface_style.surface_size.to_i32(), surface_style.surface_size.width as i32 * 4, - azure_hl::SurfaceFormat::B8G8R8A8, - )?; + SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), + )?.into_azure(); azure_hl::Pattern::Surface(SurfacePattern::new( source_surface.azure_source_surface, surface_style.repeat_x, diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index b9e0a4fbd45..c69b35e7272 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -197,7 +197,7 @@ impl<'a> CanvasPaintThread<'a> { Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value), Canvas2dMsg::SetShadowColor(ref color) => self .canvas(canvas_id) - .set_shadow_color(color.to_azure_style()), + .set_shadow_color(Color::Azure(color.to_azure_style())), } } From 3243f1753bca71c5b14d9f43c34aad51e59a01a4 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 14:50:45 -0400 Subject: [PATCH 07/14] Add cargo feature to control canvas backend. --- Cargo.lock | 6 +- components/canvas/Cargo.toml | 7 +- components/canvas/azure_backend.rs | 744 +++++++++++++++++ components/canvas/canvas_data.rs | 967 ++++------------------- components/canvas/canvas_paint_thread.rs | 10 +- components/canvas/lib.rs | 6 + components/canvas/raqote_backend.rs | 124 +++ components/constellation/Cargo.toml | 6 +- components/servo/Cargo.toml | 10 +- ports/glutin/Cargo.toml | 10 +- python/servo/build_commands.py | 3 + 11 files changed, 1077 insertions(+), 816 deletions(-) create mode 100644 components/canvas/azure_backend.rs create mode 100644 components/canvas/raqote_backend.rs diff --git a/Cargo.lock b/Cargo.lock index 63ce2d499a0..62676c779a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1258,7 +1258,7 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1329,7 +1329,7 @@ dependencies = [ "dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5692,7 +5692,7 @@ dependencies = [ "checksum euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7a4719a544a67ed3fc33784c2bd2c6581663dfe83b719a6ae05c6dabc3b51c73" "checksum euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcb84c18ea5037a1c5a23039b4ff29403abce2e0d6b1daa11cf0bde2b30be15" "checksum expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" -"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" +"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index c91302f02b3..065ed01ca75 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -11,10 +11,13 @@ name = "canvas" path = "lib.rs" [features] +azure_backend = ["azure"] +default = ["azure_backend"] webgl_backtrace = ["canvas_traits/webgl_backtrace"] +raqote_backend = ["raqote"] [dependencies] -azure = {git = "https://github.com/servo/rust-azure"} +azure = {git = "https://github.com/servo/rust-azure", optional = true} byteorder = "1" canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing"} @@ -27,7 +30,7 @@ ipc-channel = "0.11" log = "0.4" num-traits = "0.2" offscreen_gl_context = {version = "0.22", features = ["serde", "osmesa"]} -raqote = {git = "https://github.com/jrmuizel/raqote"} +raqote = {git = "https://github.com/jrmuizel/raqote", optional = true} pixels = {path = "../pixels"} serde_bytes = "0.10" servo_config = {path = "../config"} diff --git a/components/canvas/azure_backend.rs b/components/canvas/azure_backend.rs new file mode 100644 index 00000000000..8727751d5a6 --- /dev/null +++ b/components/canvas/azure_backend.rs @@ -0,0 +1,744 @@ +/* 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/. */ + +use cssparser::RGBA; +use crate::canvas_data::{ + Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, + GenericPathBuilder, Path, Pattern, StrokeOptions, +}; +use crate::canvas_paint_thread::AntialiasMode; +use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint}; +use azure::azure_hl; +use azure::azure_hl::SurfacePattern; +use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle}; +use azure::azure_hl::{BackendType, ColorPattern, DrawTarget}; +use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; +use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; + +pub struct AzureBackend; + +impl Backend for AzureBackend { + fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp { + CompositionOp::Azure(opts.as_azure().composition) + } + + fn need_to_draw_shadow(&self, color: &Color) -> bool { + self.state.shadow_color.as_azure().a != 0.0f32 + } + + fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option> { + match pattern { + Pattern::Azure(azure_hl::Pattern::Surface(ref surface)) => { + let surface_size = surface.size(); + let size = match (surface.repeat_x, surface.repeat_y) { + (true, true) => rect.size, + (true, false) => Size2D::new(rect.size.width, surface_size.height as f32), + (false, true) => Size2D::new(surface_size.width as f32, rect.size.height), + (false, false) => { + Size2D::new(surface_size.width as f32, surface_size.height as f32) + }, + }; + Some(size) + } + Pattern::Azure(_) => None + } + } + + fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>) { + state.shadow_color = Color::Azure(color.to_azure_style()); + } + + fn set_fill_style<'a>( + &mut self, + style: FillOrStrokeStyle, + state: &mut CanvasPaintState<'a>, + drawtarget: &GenericDrawTarget, + ) { + if let Some(pattern) = style.to_azure_pattern(drawtarget) { + state.fill_style = Pattern::Azure(pattern) + } + } + + fn set_stroke_style<'a>( + &mut self, + style: FillOrStrokeStyle, + state: &mut CanvasPaintState<'a>, + drawtarget: &GenericDrawTarget) + { + if let Some(pattern) = style.to_azure_pattern(drawtarget) { + state.stroke_style = Pattern::Azure(pattern) + } + } + + fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>) { + state + .draw_options + .as_azure_mut() + .set_composition_op(op.to_azure_style()); + } + + fn create_drawtarget(&self, size: Size2D) -> Box { + // FIXME(nox): Why is the size made of i32 values? + Box::new(DrawTarget::new( + BackendType::Skia, + size.to_i32(), + azure_hl::SurfaceFormat::B8G8R8A8, + )) + } + + fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { + CanvasPaintState::new(AntialiasMode::from_azure( + self.state.draw_options.as_azure().antialias + )) + } +} + +impl<'a> CanvasPaintState<'a> { + pub fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> { + CanvasPaintState { + draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias.into_azure())), + fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), + stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), + stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new( + 1.0, + JoinStyle::MiterOrBevel, + CapStyle::Butt, + 10.0, + &[], + )), + transform: Transform2D::identity(), + shadow_offset_x: 0.0, + shadow_offset_y: 0.0, + shadow_blur: 0.0, + shadow_color: Color::Azure(azure_hl::Color::transparent()), + } + } +} + +impl GenericPathBuilder for azure_hl::PathBuilder { + fn arc( + &self, + origin: Point2D, + radius: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ) { + self.arc( + origin as Point2D, + radius as AzFloat, + start_angle as AzFloat, + end_angle as AzFloat, + anticlockwise, + ); + } + fn bezier_curve_to( + &self, + control_point1: &Point2D, + control_point2: &Point2D, + control_point3: &Point2D, + ) { + self.bezier_curve_to( + control_point1 as &Point2D, + control_point2 as &Point2D, + control_point3 as &Point2D, + ); + } + fn close(&self) { + self.close(); + } + fn ellipse( + &self, + origin: Point2D, + radius_x: f32, + radius_y: f32, + rotation_angle: f32, + start_angle: f32, + end_angle: f32, + anticlockwise: bool, + ) { + self.ellipse( + origin as Point2D, + radius_x as AzFloat, + radius_y as AzFloat, + rotation_angle as AzFloat, + start_angle as AzFloat, + end_angle as AzFloat, + anticlockwise, + ); + } + fn get_current_point(&self) -> Point2D { + let AzPoint { x, y } = self.get_current_point(); + Point2D::new(x as f32, y as f32) + } + fn line_to(&self, point: Point2D) { + self.line_to(point as Point2D); + } + fn move_to(&self, point: Point2D) { + self.move_to(point as Point2D); + } + fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D) { + self.quadratic_curve_to( + control_point as &Point2D, + end_point as &Point2D, + ); + } + fn finish(&self) -> Path { + Path::Azure(self.finish()) + } +} + +impl GenericDrawTarget for azure_hl::DrawTarget { + fn clear_rect(&self, rect: &Rect) { + self.clear_rect(rect as &Rect); + } + + fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D) { + self.copy_surface(surface.into_azure(), source, destination); + } + + fn create_gradient_stops( + &self, + gradient_stops: Vec, + extend_mode: ExtendMode, + ) -> GradientStops { + let gradient_stops: Vec = + gradient_stops.into_iter().map(|x| x.into_azure()).collect(); + GradientStops::Azure(self.create_gradient_stops(&gradient_stops, extend_mode.into_azure())) + } + + fn create_path_builder(&self) -> Box { + Box::new(self.create_path_builder()) + } + + fn create_similar_draw_target( + &self, + size: &Size2D, + format: SurfaceFormat, + ) -> Box { + Box::new(self.create_similar_draw_target(size, format.into_azure())) + } + fn create_source_surface_from_data( + &self, + data: &[u8], + size: Size2D, + stride: i32, + ) -> Option { + self.create_source_surface_from_data(data, size, stride, azure_hl::SurfaceFormat::B8G8R8A8) + .map(|s| SourceSurface::Azure(s)) + } + fn draw_surface( + &self, + surface: SourceSurface, + dest: Rect, + source: Rect, + filter: Filter, + draw_options: &DrawOptions, + ) { + let surf_options = azure_hl::DrawSurfaceOptions::new(filter.as_azure(), true); + let draw_options = azure_hl::DrawOptions::new( + draw_options.as_azure().alpha, + draw_options.as_azure().composition.into_azure(), + azure_hl::AntialiasMode::None + ); + self.draw_surface( + surface.into_azure(), + dest as Rect, + source as Rect, + surf_options.into_azure(), + options.into_azure(), + ); + } + fn draw_surface_with_shadow( + &self, + surface: SourceSurface, + dest: &Point2D, + color: &Color, + offset: &Vector2D, + sigma: f32, + operator: CompositionOp, + ) { + self.draw_surface_with_shadow( + surface.into_azure(), + dest as &Point2D, + color.as_azure(), + offset as &Vector2D, + sigma as AzFloat, + operator.into_azure(), + ); + } + fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { + self.fill( + path.as_azure(), + pattern.as_azure().to_pattern_ref(), + draw_options.as_azure(), + ); + } + fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>) { + self.fill_rect( + rect as &Rect, + pattern.as_azure().to_pattern_ref(), + draw_options.map(|x| x.as_azure()), + ); + } + fn get_format(&self) -> SurfaceFormat { + SurfaceFormat::Azure(self.get_format()) + } + fn get_size(&self) -> Size2D { + let size = self.get_size(); + Size2D::new(size.width, size.height) + } + fn get_transform(&self) -> Transform2D { + self.get_transform() as Transform2D + } + fn pop_clip(&self) { + self.pop_clip(); + } + fn push_clip(&self, path: &Path) { + self.push_clip(path.as_azure()); + } + fn set_transform(&self, matrix: &Transform2D) { + self.set_transform(matrix as &Transform2D); + } + fn snapshot(&self) -> SourceSurface { + SourceSurface::Azure(self.snapshot()) + } + fn stroke( + &self, + path: &Path, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + self.stroke( + path.as_azure(), + pattern.as_azure().to_pattern_ref(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } + fn stroke_line( + &self, + start: Point2D, + end: Point2D, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + let stroke_options = stroke_options.as_azure(); + let cap = match stroke_options.line_join { + JoinStyle::Round => CapStyle::Round, + _ => CapStyle::Butt, + }; + + let stroke_opts = azure_hl::StrokeOptions::new( + stroke_options.line_width, + stroke_options.line_join, + cap, + stroke_options.miter_limit, + stroke_options.mDashPattern, + ); + + self.stroke_line( + start, + end, + pattern.as_azure().to_pattern_ref(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } + fn stroke_rect( + &self, + rect: &Rect, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, + ) { + self.stroke_rect( + rect as &Rect, + pattern.as_azure().to_pattern_ref(), + stroke_options.as_azure(), + draw_options.as_azure(), + ); + } + + fn snapshot_data(&self) -> &[u8] { + unsafe { + self.snapshot().get_data_surface().data() + } + } +} + +impl AntialiasMode { + fn into_azure(self) -> azure_hl::AntialiasMode { + match self { + AntialiasMode::Default => azure_hl::AntialiasMode::Default, + AntialiasMode::None => azure_hl::AntialiasMode::None, + } + } + + fn from_azure(val: azure_hl::AntialiasMode) { + match val { + azure_hl::AntialiasMode::Default => AntialiasMode::Default, + azure_hl::AntialiasMode::None => AntialiasMode::None, + } + } +} + +impl ExtendMode { + fn into_azure(self) -> azure_hl::ExtendMode { + match self { + ExtendMode::Azure(m) => m, + } + } +} + +impl GradientStop { + fn into_azure(self) -> AzGradientStop { + match self { + GradientStop::Azure(s) => s, + } + } +} + +impl GradientStops { + fn into_azure(self) -> azure_hl::GradientStops { + match self { + GradientStops::Azure(s) => s, + } + } +} + +impl Color { + fn as_azure(&self) -> &azure_hl::Color { + match self { + Color::Azure(s) => s, + } + } +} + +impl CompositionOp { + fn into_azure(self) -> azure_hl::CompositionOp { + match self { + CompositionOp::Azure(s) => s, + } + } +} + +impl SurfaceFormat { + fn into_azure(self) -> azure_hl::SurfaceFormat { + match self { + SurfaceFormat::Azure(s) => s, + } + } +} + +impl SourceSurface { + fn into_azure(self) -> azure_hl::SourceSurface { + match self { + SourceSurface::Azure(s) => s, + } + } +} + +impl IntSize { + fn into_azure(self) -> AzIntSize { + match self { + IntSize::Azure(s) => s, + } + } +} + +impl Path { + fn as_azure(&self) -> &azure_hl::Path { + match self { + Path::Azure(p) => p, + } + } +} + +impl Pattern { + fn as_azure(&self) -> &azure_hl::Pattern { + match self { + Pattern::Azure(p) => p, + } + } +} + +impl DrawSurfaceOptions { + fn into_azure(self) -> azure_hl::DrawSurfaceOptions { + match self { + DrawSurfaceOptions::Azure(options) => options, + } + } +} + +impl DrawOptions { + fn as_azure(&self) -> &azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + } + } + fn as_azure_mut(&mut self) -> &mut azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + } + } + fn into_azure(self) -> azure_hl::DrawOptions { + match self { + DrawOptions::Azure(options) => options, + } + } + pub fn set_alpha(&mut self, val: f32) { + match self { + DrawOptions::Azure(options) => options.alpha = val as AzFloat, + } + } +} + +impl<'a> StrokeOptions<'a> { + pub fn as_azure(&self) -> &azure_hl::StrokeOptions<'a> { + match self { + StrokeOptions::Azure(options) => options, + } + } + pub fn set_line_width(&mut self, val: f32) { + match self { + StrokeOptions::Azure(options) => options.line_width = val as AzFloat, + } + } + pub fn set_miter_limit(&mut self, val: f32) { + match self { + StrokeOptions::Azure(options) => options.miter_limit = val as AzFloat, + } + } + pub fn set_line_join(&mut self, val: LineJoinStyle) { + match self { + StrokeOptions::Azure(options) => options.line_join = val.to_azure_style(), + } + } + pub fn set_line_cap(&mut self, val: LineCapStyle) { + match self { + StrokeOptions::Azure(options) => options.line_cap = val.to_azure_style(), + } + } +} + +pub trait ToAzureStyle { + type Target; + fn to_azure_style(self) -> Self::Target; +} + +impl ToAzureStyle for Rect { + type Target = Rect; + + fn to_azure_style(self) -> Rect { + Rect::new( + Point2D::new(self.origin.x as f32, self.origin.y as f32), + Size2D::new(self.size.width as f32, self.size.height as f32), + ) + } +} + +impl ToAzureStyle for LineCapStyle { + type Target = CapStyle; + + fn to_azure_style(self) -> CapStyle { + match self { + LineCapStyle::Butt => CapStyle::Butt, + LineCapStyle::Round => CapStyle::Round, + LineCapStyle::Square => CapStyle::Square, + } + } +} + +impl ToAzureStyle for LineJoinStyle { + type Target = JoinStyle; + + fn to_azure_style(self) -> JoinStyle { + match self { + LineJoinStyle::Round => JoinStyle::Round, + LineJoinStyle::Bevel => JoinStyle::Bevel, + LineJoinStyle::Miter => JoinStyle::Miter, + } + } +} + +impl ToAzureStyle for CompositionStyle { + type Target = azure_hl::CompositionOp; + + fn to_azure_style(self) -> azure_hl::CompositionOp { + match self { + CompositionStyle::SrcIn => azure_hl::CompositionOp::In, + CompositionStyle::SrcOut => azure_hl::CompositionOp::Out, + CompositionStyle::SrcOver => azure_hl::CompositionOp::Over, + CompositionStyle::SrcAtop => azure_hl::CompositionOp::Atop, + CompositionStyle::DestIn => azure_hl::CompositionOp::DestIn, + CompositionStyle::DestOut => azure_hl::CompositionOp::DestOut, + CompositionStyle::DestOver => azure_hl::CompositionOp::DestOver, + CompositionStyle::DestAtop => azure_hl::CompositionOp::DestAtop, + CompositionStyle::Copy => azure_hl::CompositionOp::Source, + CompositionStyle::Lighter => azure_hl::CompositionOp::Add, + CompositionStyle::Xor => azure_hl::CompositionOp::Xor, + } + } +} + +impl ToAzureStyle for BlendingStyle { + type Target = azure_hl::CompositionOp; + + fn to_azure_style(self) -> azure_hl::CompositionOp { + match self { + BlendingStyle::Multiply => azure_hl::CompositionOp::Multiply, + BlendingStyle::Screen => azure_hl::CompositionOp::Screen, + BlendingStyle::Overlay => azure_hl::CompositionOp::Overlay, + BlendingStyle::Darken => azure_hl::CompositionOp::Darken, + BlendingStyle::Lighten => azure_hl::CompositionOp::Lighten, + BlendingStyle::ColorDodge => azure_hl::CompositionOp::ColorDodge, + BlendingStyle::ColorBurn => azure_hl::CompositionOp::ColorBurn, + BlendingStyle::HardLight => azure_hl::CompositionOp::HardLight, + BlendingStyle::SoftLight => azure_hl::CompositionOp::SoftLight, + BlendingStyle::Difference => azure_hl::CompositionOp::Difference, + BlendingStyle::Exclusion => azure_hl::CompositionOp::Exclusion, + BlendingStyle::Hue => azure_hl::CompositionOp::Hue, + BlendingStyle::Saturation => azure_hl::CompositionOp::Saturation, + BlendingStyle::Color => azure_hl::CompositionOp::Color, + BlendingStyle::Luminosity => azure_hl::CompositionOp::Luminosity, + } + } +} + +impl ToAzureStyle for CompositionOrBlending { + type Target = azure_hl::CompositionOp; + + fn to_azure_style(self) -> azure_hl::CompositionOp { + match self { + CompositionOrBlending::Composition(op) => op.to_azure_style(), + CompositionOrBlending::Blending(op) => op.to_azure_style(), + } + } +} + +pub trait ToAzurePattern { + fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option; +} + +impl ToAzurePattern for FillOrStrokeStyle { + fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option { + Some(match *self { + FillOrStrokeStyle::Color(ref color) => { + azure_hl::Pattern::Color(ColorPattern::new(color.to_azure_style())) + }, + FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => { + let gradient_stops: Vec = linear_gradient_style + .stops + .iter() + .map(|s| GradientStop::Azure(azure_hl::GradientStop { + offset: s.offset as f32, + color: s.color.to_azure_style(), + })) + .collect(); + + azure_hl::Pattern::LinearGradient(LinearGradientPattern::new( + &Point2D::new( + linear_gradient_style.x0 as f32, + linear_gradient_style.y0 as f32, + ), + &Point2D::new( + linear_gradient_style.x1 as f32, + linear_gradient_style.y1 as f32, + ), + drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), + &Transform2D::identity(), + )) + }, + FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => { + let gradient_stops: Vec = radial_gradient_style + .stops + .iter() + .map(|s| GradientStop::Azure(azure_hl::GradientStop { + offset: s.offset as f32, + color: s.color.to_azure_style(), + })) + .collect(); + + azure_hl::Pattern::RadialGradient(RadialGradientPattern::new( + &Point2D::new( + radial_gradient_style.x0 as f32, + radial_gradient_style.y0 as f32, + ), + &Point2D::new( + radial_gradient_style.x1 as f32, + radial_gradient_style.y1 as f32, + ), + radial_gradient_style.r0 as f32, + radial_gradient_style.r1 as f32, + drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), + &Transform2D::identity(), + )) + }, + FillOrStrokeStyle::Surface(ref surface_style) => { + let source_surface = drawtarget.create_source_surface_from_data( + &surface_style.surface_data, + // FIXME(nox): Why are those i32 values? + surface_style.surface_size.to_i32(), + surface_style.surface_size.width as i32 * 4, + )?.into_azure(); + azure_hl::Pattern::Surface(SurfacePattern::new( + source_surface.azure_source_surface, + surface_style.repeat_x, + surface_style.repeat_y, + &Transform2D::identity(), + )) + }, + }) + } +} + +impl ToAzureStyle for RGBA { + type Target = azure_hl::Color; + + fn to_azure_style(self) -> azure_hl::Color { + azure_hl::Color::rgba( + self.red_f32() as f32, + self.green_f32() as f32, + self.blue_f32() as f32, + self.alpha_f32() as f32, + ) + } +} + +impl Pattern { + pub fn is_zero_size_gradient(&self) -> bool { + match *self { + Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => { + gradient.is_zero_size() + } + _ => false, + } + } +} + +impl Filter { + fn as_azure(&self) -> azure_hl::Filter { + match *self { + Filter::Linear => azure_hl::Filter::Linear, + Filter::Point => azure_hl::Filter::Point, + } + } +} + +impl Path { + pub fn transformed_copy_to_builder(&self, transform: &Transform2D) -> Box { + Box::new(self.as_azure().transformed_copy_to_builder(transform)) + } + + pub fn contains_point(&self, x: f64, y: f64, path_transform: &Transform2D) -> bool { + self.as_azure().contains_point(x, y, path_transform) + } + + pub fn copy_to_builder(&self) -> Box { + self.as_azure().copy_to_builder() + } +} diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index bb14e223149..a2312fea1ca 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -2,18 +2,13 @@ * 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/. */ -use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint}; -use azure::azure_hl; -use azure::azure_hl::SurfacePattern; -use azure::azure_hl::{AntialiasMode, AsAzurePoint, CapStyle, JoinStyle}; -use azure::azure_hl::{BackendType, DrawTarget}; -use azure::azure_hl::{ColorPattern, Filter}; -use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; +use crate::canvas_paint_thread::AntialiasMode; use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; use num_traits::ToPrimitive; +use std::marker::PhantomData; use std::mem; use std::sync::Arc; use webrender::api::DirtyRect; @@ -57,9 +52,21 @@ impl PathState { } } +pub trait Backend { + fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp; + fn need_to_draw_shadow(&self, color: &Color) -> bool; + fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>); + fn set_fill_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget); + fn set_stroke_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget); + fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>); + fn create_drawtarget(&self, size: Size2D) -> Box; + fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a>; + fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option>; +} + /// A generic PathBuilder that abstracts the interface for /// azure's and raqote's PathBuilder. -trait GenericPathBuilder { +pub trait GenericPathBuilder { fn arc( &self, origin: Point2D, @@ -92,93 +99,20 @@ trait GenericPathBuilder { fn finish(&self) -> Path; } -impl GenericPathBuilder for azure_hl::PathBuilder { - fn arc( - &self, - origin: Point2D, - radius: f32, - start_angle: f32, - end_angle: f32, - anticlockwise: bool, - ) { - self.arc( - origin as Point2D, - radius as AzFloat, - start_angle as AzFloat, - end_angle as AzFloat, - anticlockwise, - ); - } - fn bezier_curve_to( - &self, - control_point1: &Point2D, - control_point2: &Point2D, - control_point3: &Point2D, - ) { - self.bezier_curve_to( - control_point1 as &Point2D, - control_point2 as &Point2D, - control_point3 as &Point2D, - ); - } - fn close(&self) { - self.close(); - } - fn ellipse( - &self, - origin: Point2D, - radius_x: f32, - radius_y: f32, - rotation_angle: f32, - start_angle: f32, - end_angle: f32, - anticlockwise: bool, - ) { - self.ellipse( - origin as Point2D, - radius_x as AzFloat, - radius_y as AzFloat, - rotation_angle as AzFloat, - start_angle as AzFloat, - end_angle as AzFloat, - anticlockwise, - ); - } - fn get_current_point(&self) -> Point2D { - let AzPoint { x, y } = self.get_current_point(); - Point2D::new(x as f32, y as f32) - } - fn line_to(&self, point: Point2D) { - self.line_to(point as Point2D); - } - fn move_to(&self, point: Point2D) { - self.move_to(point as Point2D); - } - fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D) { - self.quadratic_curve_to( - control_point as &Point2D, - end_point as &Point2D, - ); - } - fn finish(&self) -> Path { - Path::Azure(self.finish()) - } -} - /// A wrapper around a stored PathBuilder and an optional transformation that should be /// applied to any points to ensure they are in the matching device space. struct PathBuilderRef<'a> { builder: &'a Box, - transform: Transform2D, + transform: Transform2D, } impl<'a> PathBuilderRef<'a> { - fn line_to(&self, pt: &Point2D) { + fn line_to(&self, pt: &Point2D) { let pt = self.transform.transform_point(pt); self.builder.line_to(pt); } - fn move_to(&self, pt: &Point2D) { + fn move_to(&self, pt: &Point2D) { let pt = self.transform.transform_point(pt); self.builder.move_to(pt); } @@ -202,7 +136,7 @@ impl<'a> PathBuilderRef<'a> { self.builder.close(); } - fn quadratic_curve_to(&self, cp: &Point2D, endpoint: &Point2D) { + fn quadratic_curve_to(&self, cp: &Point2D, endpoint: &Point2D) { self.builder.quadratic_curve_to( &self.transform.transform_point(cp), &self.transform.transform_point(endpoint), @@ -211,9 +145,9 @@ impl<'a> PathBuilderRef<'a> { fn bezier_curve_to( &self, - cp1: &Point2D, - cp2: &Point2D, - endpoint: &Point2D, + cp1: &Point2D, + cp2: &Point2D, + endpoint: &Point2D, ) { self.builder.bezier_curve_to( &self.transform.transform_point(cp1), @@ -224,10 +158,10 @@ impl<'a> PathBuilderRef<'a> { fn arc( &self, - center: &Point2D, - radius: AzFloat, - start_angle: AzFloat, - end_angle: AzFloat, + center: &Point2D, + radius: f32, + start_angle: f32, + end_angle: f32, ccw: bool, ) { let center = self.transform.transform_point(center); @@ -237,12 +171,12 @@ impl<'a> PathBuilderRef<'a> { pub fn ellipse( &self, - center: &Point2D, - radius_x: AzFloat, - radius_y: AzFloat, - rotation_angle: AzFloat, - start_angle: AzFloat, - end_angle: AzFloat, + center: &Point2D, + radius_x: f32, + radius_y: f32, + rotation_angle: f32, + start_angle: f32, + end_angle: f32, ccw: bool, ) { let center = self.transform.transform_point(center); @@ -257,7 +191,7 @@ impl<'a> PathBuilderRef<'a> { ); } - fn current_point(&self) -> Option> { + fn current_point(&self) -> Option> { let inverse = match self.transform.inverse() { Some(i) => i, None => return None, @@ -270,7 +204,7 @@ impl<'a> PathBuilderRef<'a> { // TODO(pylbrecht) // This defines required methods for DrawTarget of azure and raqote // The prototypes are derived from azure's methods. -trait GenericDrawTarget { +pub trait GenericDrawTarget { fn clear_rect(&self, rect: &Rect); fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D); fn create_gradient_stops( @@ -289,15 +223,14 @@ trait GenericDrawTarget { data: &[u8], size: Size2D, stride: i32, - format: SurfaceFormat, ) -> Option; fn draw_surface( &self, surface: SourceSurface, - dest: Rect, - source: Rect, - surf_options: DrawSurfaceOptions, - options: DrawOptions, + dest: Rect, + source: Rect, + filter: Filter, + draw_options: &DrawOptions, ); fn draw_surface_with_shadow( &self, @@ -311,7 +244,7 @@ trait GenericDrawTarget { fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions); fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>); fn get_format(&self) -> SurfaceFormat; - fn get_size(&self) -> IntSize; + fn get_size(&self) -> Size2D; fn get_transform(&self) -> Transform2D; fn pop_clip(&self); fn push_clip(&self, path: &Path); @@ -339,394 +272,109 @@ trait GenericDrawTarget { stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); -} - -impl GenericDrawTarget for azure_hl::DrawTarget { - fn clear_rect(&self, rect: &Rect) { - self.clear_rect(rect as &Rect); - } - - fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D) { - self.copy_surface(surface.into_azure(), source, destination); - } - - fn create_gradient_stops( - &self, - gradient_stops: Vec, - extend_mode: ExtendMode, - ) -> GradientStops { - let gradient_stops: Vec = - gradient_stops.into_iter().map(|x| x.into_azure()).collect(); - GradientStops::Azure(self.create_gradient_stops(&gradient_stops, extend_mode.into_azure())) - } - - fn create_path_builder(&self) -> Box { - Box::new(self.create_path_builder()) - } - - fn create_similar_draw_target( - &self, - size: &Size2D, - format: SurfaceFormat, - ) -> Box { - Box::new(self.create_similar_draw_target(size, format.into_azure())) - } - fn create_source_surface_from_data( - &self, - data: &[u8], - size: Size2D, - stride: i32, - format: SurfaceFormat, - ) -> Option { - self.create_source_surface_from_data(data, size, stride, format.into_azure()).map(|s| SourceSurface::Azure(s)) - } - fn draw_surface( - &self, - surface: SourceSurface, - dest: Rect, - source: Rect, - surf_options: DrawSurfaceOptions, - options: DrawOptions, - ) { - self.draw_surface( - surface.into_azure(), - dest as Rect, - source as Rect, - surf_options.into_azure(), - options.into_azure(), - ); - } - fn draw_surface_with_shadow( - &self, - surface: SourceSurface, - dest: &Point2D, - color: &Color, - offset: &Vector2D, - sigma: f32, - operator: CompositionOp, - ) { - self.draw_surface_with_shadow( - surface.into_azure(), - dest as &Point2D, - color.as_azure(), - offset as &Vector2D, - sigma as AzFloat, - operator.into_azure(), - ); - } - fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { - self.fill( - path.as_azure(), - pattern.as_azure().to_pattern_ref(), - draw_options.as_azure(), - ); - } - fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>) { - self.fill_rect( - rect as &Rect, - pattern.as_azure().to_pattern_ref(), - draw_options.map(|x| x.as_azure()), - ); - } - fn get_format(&self) -> SurfaceFormat { - SurfaceFormat::Azure(self.get_format()) - } - fn get_size(&self) -> IntSize { - IntSize::Azure(self.get_size()) - } - fn get_transform(&self) -> Transform2D { - self.get_transform() as Transform2D - } - fn pop_clip(&self) { - self.pop_clip(); - } - fn push_clip(&self, path: &Path) { - self.push_clip(path.as_azure()); - } - fn set_transform(&self, matrix: &Transform2D) { - self.set_transform(matrix as &Transform2D); - } - fn snapshot(&self) -> SourceSurface { - SourceSurface::Azure(self.snapshot()) - } - fn stroke( - &self, - path: &Path, - pattern: Pattern, - stroke_options: &StrokeOptions, - draw_options: &DrawOptions, - ) { - self.stroke( - path.as_azure(), - pattern.as_azure().to_pattern_ref(), - stroke_options.as_azure(), - draw_options.as_azure(), - ); - } - fn stroke_line( - &self, - start: Point2D, - end: Point2D, - pattern: Pattern, - stroke_options: &StrokeOptions, - draw_options: &DrawOptions, - ) { - self.stroke_line( - start as Point2D, - end as Point2D, - pattern.as_azure().to_pattern_ref(), - stroke_options.as_azure(), - draw_options.as_azure(), - ); - } - fn stroke_rect( - &self, - rect: &Rect, - pattern: Pattern, - stroke_options: &StrokeOptions, - draw_options: &DrawOptions, - ) { - self.stroke_rect( - rect as &Rect, - pattern.as_azure().to_pattern_ref(), - stroke_options.as_azure(), - draw_options.as_azure(), - ); - } + fn snapshot_data(&self) -> Vec; } #[derive(Clone)] -enum ExtendMode { +pub enum ExtendMode { + #[cfg(feature = "azure_backend")] Azure(azure_hl::ExtendMode), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl ExtendMode { - fn into_azure(self) -> azure_hl::ExtendMode { - match self { - ExtendMode::Azure(m) => m, - _ => unreachable!(), - } - } -} - -enum GradientStop { +pub enum GradientStop { + #[cfg(feature = "azure_backend")] Azure(AzGradientStop), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl GradientStop { - fn into_azure(self) -> AzGradientStop { - match self { - GradientStop::Azure(s) => s, - _ => unreachable!(), - } - } -} - -enum GradientStops { +pub enum GradientStops { + #[cfg(feature = "azure_backend")] Azure(azure_hl::GradientStops), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl GradientStops { - fn into_azure(self) -> azure_hl::GradientStops { - match self { - GradientStops::Azure(s) => s, - _ => unreachable!(), - } - } -} - #[derive(Clone)] pub enum Color { + #[cfg(feature = "azure_backend")] Azure(azure_hl::Color), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl Color { - fn as_azure(&self) -> &azure_hl::Color { - match self { - Color::Azure(s) => s, - _ => unreachable!(), - } - } -} #[derive(Clone)] -enum CompositionOp { +pub enum CompositionOp { + #[cfg(feature = "azure_backend")] Azure(azure_hl::CompositionOp), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl CompositionOp { - fn into_azure(self) -> azure_hl::CompositionOp { - match self { - CompositionOp::Azure(s) => s, - _ => unreachable!(), - } - } -} - -enum SurfaceFormat { +pub enum SurfaceFormat { + #[cfg(feature = "azure_backend")] Azure(azure_hl::SurfaceFormat), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl SurfaceFormat { - fn into_azure(self) -> azure_hl::SurfaceFormat { - match self { - SurfaceFormat::Azure(s) => s, - _ => unreachable!(), - } - } -} - #[derive(Clone)] -enum SourceSurface { +pub enum SourceSurface { + #[cfg(feature = "azure_backend")] Azure(azure_hl::SourceSurface), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl SourceSurface { - fn into_azure(self) -> azure_hl::SourceSurface { - match self { - SourceSurface::Azure(s) => s, - _ => unreachable!(), - } - } -} - -enum IntSize { - Azure(AzIntSize), - Raqote(()), -} - -impl IntSize { - fn into_azure(self) -> AzIntSize { - match self { - IntSize::Azure(s) => s, - _ => unreachable!(), - } - } -} - -enum Path { +pub enum Path { + #[cfg(feature = "azure_backend")] Azure(azure_hl::Path), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl Path { - fn as_azure(&self) -> &azure_hl::Path { - match self { - Path::Azure(p) => p, - _ => unreachable!(), - } - } -} - #[derive(Clone)] -enum Pattern { +pub enum Pattern { + #[cfg(feature = "azure_backend")] Azure(azure_hl::Pattern), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl Pattern { - fn as_azure(&self) -> &azure_hl::Pattern { - match self { - Pattern::Azure(p) => p, - _ => unreachable!(), - } - } -} - -enum DrawSurfaceOptions { +pub enum DrawSurfaceOptions { + #[cfg(feature = "azure_backend")] Azure(azure_hl::DrawSurfaceOptions), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl DrawSurfaceOptions { - fn into_azure(self) -> azure_hl::DrawSurfaceOptions { - match self { - DrawSurfaceOptions::Azure(options) => options, - _ => unreachable!(), - } - } -} - #[derive(Clone)] -enum DrawOptions { +pub enum DrawOptions { + #[cfg(feature = "azure_backend")] Azure(azure_hl::DrawOptions), + #[cfg(feature = "raqote_backend")] Raqote(()), } -impl DrawOptions { - fn as_azure(&self) -> &azure_hl::DrawOptions { - match self { - DrawOptions::Azure(options) => options, - _ => unreachable!(), - } - } - fn as_azure_mut(&mut self) -> &mut azure_hl::DrawOptions { - match self { - DrawOptions::Azure(options) => options, - _ => unreachable!(), - } - } - fn into_azure(self) -> azure_hl::DrawOptions { - match self { - DrawOptions::Azure(options) => options, - _ => unreachable!(), - } - } - fn set_alpha(&mut self, val: f32) { - match self { - DrawOptions::Azure(options) => options.alpha = val as AzFloat, - _ => unreachable!(), - } - } -} - #[derive(Clone)] -enum StrokeOptions<'a> { +pub enum StrokeOptions<'a> { + #[cfg(feature = "azure_backend")] Azure(azure_hl::StrokeOptions<'a>), - Raqote(()), + #[cfg(feature = "raqote_backend")] + Raqote(PhantomData<&'a ()>), } -impl<'a> StrokeOptions<'a> { - fn as_azure(&self) -> &azure_hl::StrokeOptions<'a> { - match self { - StrokeOptions::Azure(options) => options, - _ => unreachable!(), - } - } - fn set_line_width(&mut self, val: f32) { - match self { - StrokeOptions::Azure(options) => options.line_width = val as AzFloat, - _ => unreachable!(), - } - } - fn set_miter_limit(&mut self, val: f32) { - match self { - StrokeOptions::Azure(options) => options.miter_limit = val as AzFloat, - _ => unreachable!(), - } - } - fn set_line_join(&mut self, val: LineJoinStyle) { - match self { - StrokeOptions::Azure(options) => options.line_join = val.to_azure_style(), - _ => unreachable!(), - } - } - fn set_line_cap(&mut self, val: LineCapStyle) { - match self { - StrokeOptions::Azure(options) => options.line_cap = val.to_azure_style(), - _ => unreachable!(), - } - } +#[derive(Clone, Copy)] +pub enum Filter { + Linear, + Point, } pub struct CanvasData<'a> { + backend: Box, drawtarget: Box, path_state: Option, state: CanvasPaintState<'a>, @@ -740,6 +388,16 @@ pub struct CanvasData<'a> { pub canvas_id: CanvasId, } +#[cfg(feature = "azure_backend")] +fn create_backend() -> Box { + Box::new(crate::azure_backend::AzureBackend) +} + +#[cfg(feature = "raqote_backend")] +fn create_backend() -> Box { + Box::new(crate::raqote_backend::RaqoteBackend) +} + impl<'a> CanvasData<'a> { pub fn new( size: Size2D, @@ -747,12 +405,14 @@ impl<'a> CanvasData<'a> { antialias: AntialiasMode, canvas_id: CanvasId, ) -> CanvasData<'a> { - let draw_target = CanvasData::create(size); + let backend = create_backend(); + let draw_target = backend.create_drawtarget(size);; let webrender_api = webrender_api_sender.create_api(); CanvasData { + backend, drawtarget: draw_target, path_state: None, - state: CanvasPaintState::new(antialias, CanvasBackend::Azure), + state: CanvasPaintState::new(antialias), saved_states: vec![], webrender_api: webrender_api, image_key: None, @@ -780,7 +440,6 @@ impl<'a> CanvasData<'a> { }; - // TODO(pylbrecht) create another clousure for raqote let writer = |draw_target: &GenericDrawTarget| { write_image( draw_target, @@ -788,8 +447,7 @@ impl<'a> CanvasData<'a> { source_rect.size, dest_rect, smoothing_enabled, - CompositionOp::Azure(self.state.draw_options.as_azure().composition), - self.state.draw_options.as_azure().alpha, + &self.state.draw_options, ); }; @@ -826,31 +484,15 @@ impl<'a> CanvasData<'a> { } pub fn fill_rect(&self, rect: &Rect) { - if is_zero_size_gradient(&self.state.fill_style) { + if self.state.fill_style.is_zero_size_gradient() { return; // Paint nothing if gradient size is zero. } let draw_rect = Rect::new( rect.origin, - match &self.state.fill_style { - Pattern::Azure(pattern) => { - match pattern { - azure_hl::Pattern::Surface(ref surface) => { - let surface_size = surface.size(); - match (surface.repeat_x, surface.repeat_y) { - (true, true) => rect.size, - (true, false) => Size2D::new(rect.size.width, surface_size.height as f32), - (false, true) => Size2D::new(surface_size.width as f32, rect.size.height), - (false, false) => { - Size2D::new(surface_size.width as f32, surface_size.height as f32) - }, - } - } - _ => rect.size, - } - }, - _ => unreachable!(), - } + self.backend + .size_from_pattern(&rect, &self.state.fill_style) + .unwrap_or(rect.size), ); if self.need_to_draw_shadow() { @@ -875,7 +517,7 @@ impl<'a> CanvasData<'a> { } pub fn stroke_rect(&self, rect: &Rect) { - if is_zero_size_gradient(&self.state.stroke_style) { + if self.state.stroke_style.is_zero_size_gradient() { return; // Paint nothing if gradient size is zero. } @@ -889,23 +531,11 @@ impl<'a> CanvasData<'a> { ); }); } else if rect.size.width == 0. || rect.size.height == 0. { - let cap = match self.state.stroke_opts.as_azure().line_join { - JoinStyle::Round => CapStyle::Round, - _ => CapStyle::Butt, - }; - - let stroke_opts = StrokeOptions::Azure(azure_hl::StrokeOptions::new( - self.state.stroke_opts.as_azure().line_width, - self.state.stroke_opts.as_azure().line_join, - cap, - self.state.stroke_opts.as_azure().miter_limit, - self.state.stroke_opts.as_azure().mDashPattern, - )); self.drawtarget.stroke_line( rect.origin, rect.bottom_right(), self.state.stroke_style.clone(), - &stroke_opts, + &self.state.stroke_opts, &self.state.draw_options, ); } else { @@ -951,7 +581,7 @@ impl<'a> CanvasData<'a> { // any transform is present. let new_state = match *self.path_state.as_ref().unwrap() { PathState::UserSpacePath(ref path, Some(ref transform)) => { - Some(Box::new(path.as_azure().transformed_copy_to_builder(transform))) + Some(path.transformed_copy_to_builder(transform)) }, PathState::UserSpacePath(..) | PathState::UserSpacePathBuilder(..) | @@ -973,8 +603,8 @@ impl<'a> CanvasData<'a> { return; }, }; - let builder = Box::new(path.as_azure().transformed_copy_to_builder(&inverse)); - Some(Path::Azure(builder.finish())) + let builder = path.transformed_copy_to_builder(&inverse); + Some(builder.finish()) }, PathState::UserSpacePathBuilder(..) | PathState::UserSpacePath(..) => None, }; @@ -993,7 +623,7 @@ impl<'a> CanvasData<'a> { } pub fn fill(&mut self) { - if is_zero_size_gradient(&self.state.fill_style) { + if self.state.fill_style.is_zero_size_gradient() { return; // Paint nothing if gradient size is zero. } @@ -1006,7 +636,7 @@ impl<'a> CanvasData<'a> { } pub fn stroke(&mut self) { - if is_zero_size_gradient(&self.state.stroke_style) { + if self.state.stroke_style.is_zero_size_gradient() { return; // Paint nothing if gradient size is zero. } @@ -1036,18 +666,18 @@ impl<'a> CanvasData<'a> { Some(PathState::UserSpacePath(ref path, ref transform)) => { let target_transform = self.drawtarget.get_transform(); let path_transform = transform.as_ref().unwrap_or(&target_transform); - path.as_azure().contains_point(x, y, path_transform) + path.contains_point(x, y, path_transform) }, Some(_) | None => false, }; chan.send(result).unwrap(); } - pub fn move_to(&mut self, point: &Point2D) { + pub fn move_to(&mut self, point: &Point2D) { self.path_builder().move_to(point); } - pub fn line_to(&mut self, point: &Point2D) { + pub fn line_to(&mut self, point: &Point2D) { self.path_builder().line_to(point); } @@ -1069,14 +699,14 @@ impl<'a> CanvasData<'a> { &PathState::UserSpacePathBuilder(ref builder, Some(ref transform)) => { let path = builder.finish(); Some(PathState::DeviceSpacePathBuilder( - Box::new(path.as_azure().transformed_copy_to_builder(transform)), + path.transformed_copy_to_builder(transform), )) }, &PathState::UserSpacePath(ref path, Some(ref transform)) => Some( - PathState::DeviceSpacePathBuilder(Box::new(path.as_azure().transformed_copy_to_builder(transform))), + PathState::DeviceSpacePathBuilder(path.transformed_copy_to_builder(transform)), ), &PathState::UserSpacePath(ref path, None) => Some(PathState::UserSpacePathBuilder( - Box::new(path.as_azure().copy_to_builder()), + path.copy_to_builder(), None, )), } @@ -1119,34 +749,34 @@ impl<'a> CanvasData<'a> { self.path_builder().rect(rect); } - pub fn quadratic_curve_to(&mut self, cp: &Point2D, endpoint: &Point2D) { + pub fn quadratic_curve_to(&mut self, cp: &Point2D, endpoint: &Point2D) { self.path_builder().quadratic_curve_to(cp, endpoint); } pub fn bezier_curve_to( &mut self, - cp1: &Point2D, - cp2: &Point2D, - endpoint: &Point2D, + cp1: &Point2D, + cp2: &Point2D, + endpoint: &Point2D, ) { self.path_builder().bezier_curve_to(cp1, cp2, endpoint); } pub fn arc( &mut self, - center: &Point2D, - radius: AzFloat, - start_angle: AzFloat, - end_angle: AzFloat, + center: &Point2D, + radius: f32, + start_angle: f32, + end_angle: f32, ccw: bool, ) { self.path_builder() .arc(center, radius, start_angle, end_angle, ccw); } - pub fn arc_to(&mut self, cp1: &Point2D, cp2: &Point2D, radius: AzFloat) { + pub fn arc_to(&mut self, cp1: &Point2D, cp2: &Point2D, radius: f32) { let cp0 = match self.path_builder().current_point() { - Some(p) => p.as_azure_point(), + Some(p) => p, None => return, }; let cp1 = *cp1; @@ -1209,12 +839,12 @@ impl<'a> CanvasData<'a> { pub fn ellipse( &mut self, - center: &Point2D, - radius_x: AzFloat, - radius_y: AzFloat, - rotation_angle: AzFloat, - start_angle: AzFloat, - end_angle: AzFloat, + center: &Point2D, + radius_x: f32, + radius_y: f32, + rotation_angle: f32, + start_angle: f32, + end_angle: f32, ccw: bool, ) { self.path_builder().ellipse( @@ -1229,15 +859,11 @@ impl<'a> CanvasData<'a> { } pub fn set_fill_style(&mut self, style: FillOrStrokeStyle) { - if let Some(pattern) = style.to_azure_pattern(&*self.drawtarget) { - self.state.fill_style = Pattern::Azure(pattern) - } + self.backend.set_fill_style(style, &mut self.state, &*self.drawtarget); } pub fn set_stroke_style(&mut self, style: FillOrStrokeStyle) { - if let Some(pattern) = style.to_azure_pattern(&*self.drawtarget) { - self.state.stroke_style = Pattern::Azure(pattern) - } + self.backend.set_stroke_style(style, &mut self.state, &*self.drawtarget); } pub fn set_line_width(&mut self, width: f32) { @@ -1277,24 +903,12 @@ impl<'a> CanvasData<'a> { } pub fn set_global_composition(&mut self, op: CompositionOrBlending) { - self.state - .draw_options - .as_azure_mut() - .set_composition_op(op.to_azure_style()); - } - - pub fn create(size: Size2D) -> Box { - // FIXME(nox): Why is the size made of i32 values? - Box::new(DrawTarget::new( - BackendType::Skia, - size.to_i32(), - azure_hl::SurfaceFormat::B8G8R8A8, - )) + self.backend.set_global_composition(op, &mut self.state); } pub fn recreate(&mut self, size: Size2D) { - self.drawtarget = CanvasData::create(Size2D::new(size.width as u64, size.height as u64)); - self.state = CanvasPaintState::new(self.state.draw_options.as_azure().antialias, CanvasBackend::Azure); + self.drawtarget = self.backend.create_drawtarget(Size2D::new(size.width as u64, size.height as u64)); + self.state = self.backend.recreate_paint_state(&self.state); self.saved_states.clear(); // Webrender doesn't let images change size, so we clear the webrender image key. // TODO: there is an annying race condition here: the display list builder @@ -1311,15 +925,15 @@ impl<'a> CanvasData<'a> { #[allow(unsafe_code)] pub fn send_pixels(&mut self, chan: IpcSender) { - let data = IpcSharedMemory::from_bytes(unsafe { - self.drawtarget.snapshot().into_azure().get_data_surface().data() - }); + let data = IpcSharedMemory::from_bytes( + &self.drawtarget.snapshot_data() + ); chan.send(data).unwrap(); } #[allow(unsafe_code)] pub fn send_data(&mut self, chan: IpcSender) { - let size = self.drawtarget.get_size().into_azure(); + let size = self.drawtarget.get_size(); let descriptor = webrender_api::ImageDescriptor { size: webrender_api::DeviceIntSize::new(size.width, size.height), @@ -1329,9 +943,9 @@ impl<'a> CanvasData<'a> { is_opaque: false, allow_mipmaps: false, }; - let data = webrender_api::ImageData::Raw(Arc::new(unsafe { - self.drawtarget.snapshot().into_azure().get_data_surface().data().into() - })); + let data = webrender_api::ImageData::Raw(Arc::new( + self.drawtarget.snapshot_data().into() + )); let mut txn = webrender_api::Transaction::new(); @@ -1372,7 +986,6 @@ impl<'a> CanvasData<'a> { &imagedata, rect.size.to_i32(), rect.size.width as i32 * 4, - SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), ) .unwrap(); self.drawtarget.copy_surface( @@ -1394,13 +1007,13 @@ impl<'a> CanvasData<'a> { self.state.shadow_blur = value; } - pub fn set_shadow_color(&mut self, value: Color) { - self.state.shadow_color = value; + pub fn set_shadow_color(&mut self, value: RGBA) { + self.backend.set_shadow_color(value, &mut self.state); } // https://html.spec.whatwg.org/multipage/#when-shadows-are-drawn fn need_to_draw_shadow(&self) -> bool { - self.state.shadow_color.as_azure().a != 0.0f32 && + self.backend.need_to_draw_shadow(&self.state.shadow_color) && (self.state.shadow_offset_x != 0.0f64 || self.state.shadow_offset_y != 0.0f64 || self.state.shadow_blur != 0.0f64) @@ -1431,16 +1044,16 @@ impl<'a> CanvasData<'a> { self.drawtarget.draw_surface_with_shadow( new_draw_target.snapshot(), &Point2D::new( - shadow_src_rect.origin.x as AzFloat, - shadow_src_rect.origin.y as AzFloat, + shadow_src_rect.origin.x as f32, + shadow_src_rect.origin.y as f32, ), &self.state.shadow_color, &Vector2D::new( - self.state.shadow_offset_x as AzFloat, - self.state.shadow_offset_y as AzFloat, + self.state.shadow_offset_x as f32, + self.state.shadow_offset_y as f32, ), - (self.state.shadow_blur / 2.0f64) as AzFloat, - CompositionOp::Azure(self.state.draw_options.as_azure().composition), + (self.state.shadow_blur / 2.0f64) as f32, + self.backend.get_composition_op(&self.state.draw_options), ); } @@ -1457,12 +1070,11 @@ impl<'a> CanvasData<'a> { return vec![]; } - let data_surface = self.drawtarget.snapshot().into_azure().get_data_surface(); pixels::rgba8_get_rect( - unsafe { data_surface.data() }, + &self.drawtarget.snapshot_data(), canvas_size.to_u32(), read_rect.to_u32(), - ) + ) .into_owned() } } @@ -1482,72 +1094,18 @@ impl<'a> Drop for CanvasData<'a> { } } -enum CanvasBackend { - Azure, - Raqote, -} - #[derive(Clone)] -struct CanvasPaintState<'a> { - draw_options: DrawOptions, - fill_style: Pattern, - stroke_style: Pattern, - stroke_opts: StrokeOptions<'a>, +pub struct CanvasPaintState<'a> { + pub draw_options: DrawOptions, + pub fill_style: Pattern, + pub stroke_style: Pattern, + pub stroke_opts: StrokeOptions<'a>, /// The current 2D transform matrix. - transform: Transform2D, - shadow_offset_x: f64, - shadow_offset_y: f64, - shadow_blur: f64, - shadow_color: Color, -} - -impl<'a> CanvasPaintState<'a> { - fn new(antialias: AntialiasMode, backend: CanvasBackend) -> CanvasPaintState<'a> { - match backend { - CanvasBackend::Azure => CanvasPaintState { - draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias)), - fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), - stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), - stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new( - 1.0, - JoinStyle::MiterOrBevel, - CapStyle::Butt, - 10.0, - &[], - )), - transform: Transform2D::identity(), - shadow_offset_x: 0.0, - shadow_offset_y: 0.0, - shadow_blur: 0.0, - shadow_color: Color::Azure(azure_hl::Color::transparent()), - }, - CanvasBackend::Raqote => CanvasPaintState { - draw_options: DrawOptions::Raqote(()), - fill_style: Pattern::Raqote(()), - stroke_style: Pattern::Raqote(()), - stroke_opts: StrokeOptions::Raqote(()), - transform: Transform2D::identity(), - shadow_offset_x: 0.0, - shadow_offset_y: 0.0, - shadow_blur: 0.0, - shadow_color: Color::Raqote(()), - } - } - } -} - -fn is_zero_size_gradient(pattern: &Pattern) -> bool { - match pattern { - Pattern::Azure(ref az_pattern) => { - if let azure_hl::Pattern::LinearGradient(ref gradient) = az_pattern { - if gradient.is_zero_size() { - return true; - } - } - false - }, - _ => unreachable!(), - } + pub transform: Transform2D, + pub shadow_offset_x: f64, + pub shadow_offset_y: f64, + pub shadow_blur: f64, + pub shadow_color: Color, } /// It writes an image to the destination target @@ -1562,8 +1120,7 @@ fn write_image( image_size: Size2D, dest_rect: Rect, smoothing_enabled: bool, - composition_op: CompositionOp, - global_alpha: f32, + draw_options: &DrawOptions, ) { if image_data.is_empty() { return; @@ -1586,17 +1143,14 @@ fn write_image( &image_data, image_size, image_size.width * 4, - SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), - ) + ) .unwrap(); - let draw_surface_options = DrawSurfaceOptions::Azure(azure_hl::DrawSurfaceOptions::new(filter, true)); - let draw_options = - DrawOptions::Azure(azure_hl::DrawOptions::new(global_alpha, composition_op.into_azure(), AntialiasMode::None)); + draw_target.draw_surface( source_surface, - dest_rect.to_azure_style(), - image_rect.to_azure_style(), - draw_surface_options, + dest_rect, + image_rect, + filter, draw_options, ); } @@ -1647,188 +1201,3 @@ impl RectToi32 for Rect { ) } } - -pub trait ToAzureStyle { - type Target; - fn to_azure_style(self) -> Self::Target; -} - -impl ToAzureStyle for Rect { - type Target = Rect; - - fn to_azure_style(self) -> Rect { - Rect::new( - Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat), - Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat), - ) - } -} - -impl ToAzureStyle for LineCapStyle { - type Target = CapStyle; - - fn to_azure_style(self) -> CapStyle { - match self { - LineCapStyle::Butt => CapStyle::Butt, - LineCapStyle::Round => CapStyle::Round, - LineCapStyle::Square => CapStyle::Square, - } - } -} - -impl ToAzureStyle for LineJoinStyle { - type Target = JoinStyle; - - fn to_azure_style(self) -> JoinStyle { - match self { - LineJoinStyle::Round => JoinStyle::Round, - LineJoinStyle::Bevel => JoinStyle::Bevel, - LineJoinStyle::Miter => JoinStyle::Miter, - } - } -} - -impl ToAzureStyle for CompositionStyle { - type Target = azure_hl::CompositionOp; - - fn to_azure_style(self) -> azure_hl::CompositionOp { - match self { - CompositionStyle::SrcIn => azure_hl::CompositionOp::In, - CompositionStyle::SrcOut => azure_hl::CompositionOp::Out, - CompositionStyle::SrcOver => azure_hl::CompositionOp::Over, - CompositionStyle::SrcAtop => azure_hl::CompositionOp::Atop, - CompositionStyle::DestIn => azure_hl::CompositionOp::DestIn, - CompositionStyle::DestOut => azure_hl::CompositionOp::DestOut, - CompositionStyle::DestOver => azure_hl::CompositionOp::DestOver, - CompositionStyle::DestAtop => azure_hl::CompositionOp::DestAtop, - CompositionStyle::Copy => azure_hl::CompositionOp::Source, - CompositionStyle::Lighter => azure_hl::CompositionOp::Add, - CompositionStyle::Xor => azure_hl::CompositionOp::Xor, - } - } -} - -impl ToAzureStyle for BlendingStyle { - type Target = azure_hl::CompositionOp; - - fn to_azure_style(self) -> azure_hl::CompositionOp { - match self { - BlendingStyle::Multiply => azure_hl::CompositionOp::Multiply, - BlendingStyle::Screen => azure_hl::CompositionOp::Screen, - BlendingStyle::Overlay => azure_hl::CompositionOp::Overlay, - BlendingStyle::Darken => azure_hl::CompositionOp::Darken, - BlendingStyle::Lighten => azure_hl::CompositionOp::Lighten, - BlendingStyle::ColorDodge => azure_hl::CompositionOp::ColorDodge, - BlendingStyle::ColorBurn => azure_hl::CompositionOp::ColorBurn, - BlendingStyle::HardLight => azure_hl::CompositionOp::HardLight, - BlendingStyle::SoftLight => azure_hl::CompositionOp::SoftLight, - BlendingStyle::Difference => azure_hl::CompositionOp::Difference, - BlendingStyle::Exclusion => azure_hl::CompositionOp::Exclusion, - BlendingStyle::Hue => azure_hl::CompositionOp::Hue, - BlendingStyle::Saturation => azure_hl::CompositionOp::Saturation, - BlendingStyle::Color => azure_hl::CompositionOp::Color, - BlendingStyle::Luminosity => azure_hl::CompositionOp::Luminosity, - } - } -} - -impl ToAzureStyle for CompositionOrBlending { - type Target = azure_hl::CompositionOp; - - fn to_azure_style(self) -> azure_hl::CompositionOp { - match self { - CompositionOrBlending::Composition(op) => op.to_azure_style(), - CompositionOrBlending::Blending(op) => op.to_azure_style(), - } - } -} - -pub trait ToAzurePattern { - fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option; -} - -impl ToAzurePattern for FillOrStrokeStyle { - fn to_azure_pattern(&self, drawtarget: &GenericDrawTarget) -> Option { - Some(match *self { - FillOrStrokeStyle::Color(ref color) => { - azure_hl::Pattern::Color(ColorPattern::new(color.to_azure_style())) - }, - FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => { - let gradient_stops: Vec = linear_gradient_style - .stops - .iter() - .map(|s| GradientStop::Azure(azure_hl::GradientStop { - offset: s.offset as AzFloat, - color: s.color.to_azure_style(), - })) - .collect(); - - azure_hl::Pattern::LinearGradient(LinearGradientPattern::new( - &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, - ), - drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), - &Transform2D::identity(), - )) - }, - FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => { - let gradient_stops: Vec = radial_gradient_style - .stops - .iter() - .map(|s| GradientStop::Azure(azure_hl::GradientStop { - offset: s.offset as AzFloat, - color: s.color.to_azure_style(), - })) - .collect(); - - azure_hl::Pattern::RadialGradient(RadialGradientPattern::new( - &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, - ), - radial_gradient_style.r0 as AzFloat, - radial_gradient_style.r1 as AzFloat, - drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), - &Transform2D::identity(), - )) - }, - FillOrStrokeStyle::Surface(ref surface_style) => { - let source_surface = drawtarget.create_source_surface_from_data( - &surface_style.surface_data, - // FIXME(nox): Why are those i32 values? - surface_style.surface_size.to_i32(), - surface_style.surface_size.width as i32 * 4, - SurfaceFormat::Azure(azure_hl::SurfaceFormat::B8G8R8A8), - )?.into_azure(); - azure_hl::Pattern::Surface(SurfacePattern::new( - source_surface.azure_source_surface, - surface_style.repeat_x, - surface_style.repeat_y, - &Transform2D::identity(), - )) - }, - }) - } -} - -impl ToAzureStyle for RGBA { - type Target = azure_hl::Color; - - fn to_azure_style(self) -> azure_hl::Color { - azure_hl::Color::rgba( - self.red_f32() as AzFloat, - self.green_f32() as AzFloat, - self.blue_f32() as AzFloat, - self.alpha_f32() as AzFloat, - ) - } -} diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index c69b35e7272..afaa9f49d6a 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::canvas_data::*; -use azure::azure_hl::AntialiasMode; use canvas_traits::canvas::*; use euclid::Size2D; use ipc_channel::ipc::{self, IpcSender}; @@ -11,6 +10,11 @@ use std::borrow::ToOwned; use std::collections::HashMap; use std::thread; +pub enum AntialiasMode { + Default, + None, +} + pub struct CanvasPaintThread<'a> { canvases: HashMap>, next_canvas_id: CanvasId, @@ -195,9 +199,9 @@ impl<'a> CanvasPaintThread<'a> { self.canvas(canvas_id).set_shadow_offset_y(value) }, Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value), - Canvas2dMsg::SetShadowColor(ref color) => self + Canvas2dMsg::SetShadowColor(color) => self .canvas(canvas_id) - .set_shadow_color(Color::Azure(color.to_azure_style())), + .set_shadow_color(color), } } diff --git a/components/canvas/lib.rs b/components/canvas/lib.rs index cb6fe50f8d8..28dd1e04f5d 100644 --- a/components/canvas/lib.rs +++ b/components/canvas/lib.rs @@ -7,6 +7,12 @@ #[macro_use] extern crate log; +#[cfg(feature = "azure_backend")] +mod azure_backend; + +#[cfg(feature = "raqote_backend")] +mod raqote_backend; + pub mod canvas_data; pub mod canvas_paint_thread; pub mod gl_context; diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs new file mode 100644 index 00000000000..2d51c7f4493 --- /dev/null +++ b/components/canvas/raqote_backend.rs @@ -0,0 +1,124 @@ +/* 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/. */ + +use cssparser::RGBA; +use crate::canvas_data::{ + Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, + GenericPathBuilder, Path, Pattern, StrokeOptions, +}; +use crate::canvas_paint_thread::AntialiasMode; +use canvas_traits::canvas::*; +use euclid::{Rect, Size2D, Transform2D}; +use std::marker::PhantomData; + +pub struct RaqoteBackend; + +impl Backend for RaqoteBackend { + fn get_composition_op(&self, _opts: &DrawOptions) -> CompositionOp { + unimplemented!() + } + + fn need_to_draw_shadow(&self, _color: &Color) -> bool { + unimplemented!() + } + + fn size_from_pattern(&self, _rect: &Rect, _pattern: &Pattern) -> Option> { + unimplemented!() + } + + fn set_shadow_color<'a>(&mut self, _color: RGBA, _state: &mut CanvasPaintState<'a>) { + unimplemented!() + } + + fn set_fill_style<'a>( + &mut self, + _style: FillOrStrokeStyle, + _state: &mut CanvasPaintState<'a>, + _drawtarget: &GenericDrawTarget, + ) { + unimplemented!() + } + + fn set_stroke_style<'a>( + &mut self, + _style: FillOrStrokeStyle, + _state: &mut CanvasPaintState<'a>, + _drawtarget: &GenericDrawTarget) + { + unimplemented!() + } + + fn set_global_composition<'a>(&mut self, _op: CompositionOrBlending, _state: &mut CanvasPaintState<'a>) { + unimplemented!() + } + + fn create_drawtarget(&self, _size: Size2D) -> Box { + unimplemented!() + } + + fn recreate_paint_state<'a>(&self, _state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { + CanvasPaintState::new(AntialiasMode::Default) + } +} + +impl<'a> CanvasPaintState<'a> { + pub fn new(_antialias: AntialiasMode) -> CanvasPaintState<'a> { + CanvasPaintState { + draw_options: DrawOptions::Raqote(()), + fill_style: Pattern::Raqote(()), + stroke_style: Pattern::Raqote(()), + stroke_opts: StrokeOptions::Raqote(PhantomData), + transform: Transform2D::identity(), + shadow_offset_x: 0.0, + shadow_offset_y: 0.0, + shadow_blur: 0.0, + shadow_color: Color::Raqote(()), + } + } +} + +impl Pattern { + pub fn is_zero_size_gradient(&self) -> bool { + match *self { + Pattern::Raqote(()) => unimplemented!(), + } + } +} + +impl<'a> StrokeOptions<'a> { + pub fn set_line_width(&mut self, _val: f32) { + unimplemented!() + } + pub fn set_miter_limit(&mut self, _val: f32) { + unimplemented!() + } + pub fn set_line_join(&mut self, _val: LineJoinStyle) { + unimplemented!() + } + pub fn set_line_cap(&mut self, _val: LineCapStyle) { + unimplemented!() + } +} + +impl DrawOptions { + pub fn set_alpha(&mut self, _val: f32) { + match self { + DrawOptions::Raqote(()) => unimplemented!(), + } + } +} + +impl Path { + pub fn transformed_copy_to_builder(&self, _transform: &Transform2D) -> Box { + unimplemented!() + } + + pub fn contains_point(&self, _x: f64, _y: f64, _path_transform: &Transform2D) -> bool { + unimplemented!() + } + + pub fn copy_to_builder(&self) -> Box { + unimplemented!() + } +} diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index 795a1c5921e..fc2021d3af3 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -10,11 +10,15 @@ publish = false name = "constellation" path = "lib.rs" +[features] +azure_backend = ["canvas/azure_backend"] +raqote_backend = ["canvas/raqote_backend"] + [dependencies] background_hang_monitor = { path = "../background_hang_monitor"} backtrace = "0.3" bluetooth_traits = { path = "../bluetooth_traits" } -canvas = {path = "../canvas"} +canvas = {path = "../canvas", default-features = false} clipboard = "0.5" canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing"} diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index a81954f885f..86e5f0852a6 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -12,14 +12,15 @@ path = "lib.rs" crate-type = ["rlib"] [features] -max_log_level = ["log/release_max_level_info"] -webdriver = ["webdriver_server"] -energy-profiling = ["profile_traits/energy-profiling"] +azure_backend = ["canvas/azure_backend"] debugmozjs = ["script/debugmozjs"] +energy-profiling = ["profile_traits/energy-profiling"] profilemozjs = ["script/profilemozjs"] googlevr = ["webvr/googlevr"] js_backtrace = ["script/js_backtrace"] +max_log_level = ["log/release_max_level_info"] native-bluetooth = ["bluetooth/native-bluetooth"] +raqote_backend = ["canvas/raqote_backend"] webrender_debugger = ["webrender/debugger"] no_static_freetype = ["webrender/no_static_freetype"] oculusvr = ["webvr/oculusvr"] @@ -28,6 +29,7 @@ unstable = [ "profile/unstable", "script/unstable", ] +webdriver = ["webdriver_server"] webgl_backtrace = [ "script/webgl_backtrace", "canvas/webgl_backtrace", @@ -38,7 +40,7 @@ webgl_backtrace = [ background_hang_monitor = {path = "../background_hang_monitor"} bluetooth_traits = {path = "../bluetooth_traits"} bluetooth = {path = "../bluetooth"} -canvas = {path = "../canvas"} +canvas = {path = "../canvas", default-features = false} canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing", features = ["gl"]} constellation = {path = "../constellation"} diff --git a/ports/glutin/Cargo.toml b/ports/glutin/Cargo.toml index 41fbf47d734..534abcbf351 100644 --- a/ports/glutin/Cargo.toml +++ b/ports/glutin/Cargo.toml @@ -27,18 +27,20 @@ OriginalFilename = "servo.exe" ProductName = "Servo" [features] +azure_backend = ["libservo/azure_backend"] default = ["unstable", "default-except-unstable"] default-except-unstable = ["webdriver", "max_log_level"] -native-bluetooth = ["libservo/native-bluetooth"] -max_log_level = ["log/release_max_level_info"] -webdriver = ["libservo/webdriver"] energy-profiling = ["libservo/energy-profiling"] debugmozjs = ["libservo/debugmozjs"] +js_backtrace = ["libservo/js_backtrace"] +max_log_level = ["log/release_max_level_info"] +native-bluetooth = ["libservo/native-bluetooth"] profilemozjs = ["libservo/profilemozjs"] +raqote_backend = ["libservo/raqote_backend"] unstable = ["libservo/unstable"] +webdriver = ["libservo/webdriver"] webgl_backtrace = ["libservo/webgl_backtrace"] webrender_debugger = ["libservo/webrender_debugger"] -js_backtrace = ["libservo/js_backtrace"] [target.'cfg(not(target_os = "android"))'.dependencies] backtrace = "0.3" diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py index 1a00d8be97d..292879b52ea 100644 --- a/python/servo/build_commands.py +++ b/python/servo/build_commands.py @@ -296,6 +296,9 @@ class MachCommands(CommandBase): if self.config["build"]["dom-backtrace"]: features += ["dom-backtrace"] + if "raqote_backend" not in features: + features += ["azure_backend"] + if features: opts += ["--features", "%s" % ' '.join(features)] From 97f5dacc2904cdc1ff799ce7919993743a5ae954 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 14:51:23 -0400 Subject: [PATCH 08/14] Update raqote. --- Cargo.lock | 103 ++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62676c779a3..55fa4e9840c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -723,7 +723,7 @@ dependencies = [ [[package]] name = "core-text" -version = "13.1.0" +version = "13.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1092,18 +1092,6 @@ dependencies = [ "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "dwrote" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "dwrote" version = "0.8.0" @@ -1116,6 +1104,16 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dwrote" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "either" version = "1.1.0" @@ -1262,18 +1260,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "failure_derive" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1316,25 +1302,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "font-kit" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dwrote 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1465,7 +1446,7 @@ dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1953,7 +1934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2242,14 +2223,6 @@ dependencies = [ "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "itertools" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "itertools" version = "0.8.0" @@ -2607,7 +2580,7 @@ dependencies = [ [[package]] name = "lyon_geom" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2620,7 +2593,7 @@ name = "lyon_path" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon_geom 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2720,6 +2693,15 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memmap" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memmap" version = "0.7.0" @@ -3589,13 +3571,13 @@ dependencies = [ [[package]] name = "raqote" version = "0.4.1-alpha.0" -source = "git+https://github.com/jrmuizel/raqote#f5a091c352118c9fff0aca99990ee10899d1ca08" +source = "git+https://github.com/jrmuizel/raqote#15748d146466bc1db09699fe149cc760b81cdf60" dependencies = [ "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", - "font-kit 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", + "font-kit 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lyon_geom 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)", "png 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sw-composite 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sw-composite 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "typed-arena 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4675,7 +4657,7 @@ dependencies = [ [[package]] name = "sw-composite" -version = "0.2.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -5307,7 +5289,7 @@ dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", - "core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-text 13.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cstr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "freetype 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5404,7 +5386,7 @@ name = "which" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5646,7 +5628,7 @@ dependencies = [ "checksum core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "58667b9a618a37ea8c4c4cb5298703e5dfadcd3698c79f54fc43e6a2e94733ea" "checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" "checksum core-graphics 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" -"checksum core-text 13.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6705907bc253cee90b8551017836ce50904be305c99fec5ea74a8d72d799e58" +"checksum core-text 13.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d95a72b5e50e549969dd88eff3047495fe5b8c6f028635442c2b708be707e669" "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" "checksum crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192" "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" @@ -5676,8 +5658,8 @@ dependencies = [ "checksum downcast-rs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "18df8ce4470c189d18aa926022da57544f31e154631eb4cfe796aea97051fe6c" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" "checksum dtoa-short 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe6f727b406462fd57c95fed84d1b0dbfb5f0136fcac005adba9ea0367c05cc8" -"checksum dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30a998e9ff70cd208ccdc4f864e998688bf61d7b897dccec8e17a884d17358bf" "checksum dwrote 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c31c624339dab99c223a4b26c2e803b7c248adaca91549ce654c76f39a03f5c8" +"checksum dwrote 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0bd1369e02db5e9b842a9b67bce8a2fcc043beafb2ae8a799dd482d46ea1ff0d" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum encoding_rs 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ca20350a7cb5aab5b9034731123d6d412caf3e92d4985e739e411ba0955fd0eb" "checksum energy-monitor 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe872d0664f1cc60db36349af245d892ee67d3c8f78055df0ebc43271fd4e05c" @@ -5693,13 +5675,12 @@ dependencies = [ "checksum euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcb84c18ea5037a1c5a23039b4ff29403abce2e0d6b1daa11cf0bde2b30be15" "checksum expat-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" -"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909" "checksum float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" -"checksum font-kit 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5be0133b580e2920076afd5bd4b81dc172d10e5653bd1c516476718d52347859" +"checksum font-kit 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c5b784f7a48d718df8d9ee28f81f8afa0a7ffdd61038957cba1ec6837a836d46" "checksum fontsan 0.4.0 (git+https://github.com/servo/fontsan)" = "" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" @@ -5777,7 +5758,6 @@ dependencies = [ "checksum io-surface 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9a33981dff54baaff80f4decb487a65d148a3c00facc97820d0f09128f74dd" "checksum iovec 0.1.3 (git+https://github.com/servo/iovec.git?branch=servo)" = "" "checksum ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a369bb751cf24f18084aabb56995268ec1f68d2b69937aaf031d41690c1bef" -"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" "checksum jemalloc-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "479294d130502fada93c7a957e8d059b632b03d6204aca37af557dee947f30a9" @@ -5801,7 +5781,7 @@ dependencies = [ "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -"checksum lyon_geom 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0ea0ba5f8d2d91d6d895aca54d1ec0d84ddfa4826f33fbfe8abb39f08f9e4153" +"checksum lyon_geom 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0638070e85f0e8b5da3909d8c5c0a66785b18da96a1e8dc30acb0aea9770529a" "checksum lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9dc8e0746b7cca11960b602f7fe037bb067746a01eab4aa502fed1494544843" "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" "checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" @@ -5811,6 +5791,7 @@ dependencies = [ "checksum markup5ever 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f1af46a727284117e09780d05038b1ce6fc9c76cc6df183c3dae5a8955a25e21" "checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425" @@ -5950,7 +5931,7 @@ dependencies = [ "checksum string_cache_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eea1eee654ef80933142157fdad9dd8bc43cf7c74e999e369263496f04ff4da" "checksum string_cache_shared 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum sw-composite 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "244e594da1b22e50c421a70f08e146e3ad60fe1fc975cfd47a85a169ccca17c5" +"checksum sw-composite 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1638f200d9594cad22e9e58baf046382d8f5a38d40878db1705dcaeae239093" "checksum swapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e454d048db5527d000bfddb77bd072bbf3a1e2ae785f16d9bd116e07c2ab45eb" "checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" From db362184fdaf6e4ab3deca8f0bd7e5b5cb45e79a Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 15:35:18 -0400 Subject: [PATCH 09/14] Fix formatting. --- components/canvas/azure_backend.rs | 97 +++++++++++++++--------- components/canvas/canvas_data.rs | 82 +++++++++----------- components/canvas/canvas_paint_thread.rs | 4 +- components/canvas/raqote_backend.rs | 21 +++-- servo-tidy.toml | 2 + 5 files changed, 116 insertions(+), 90 deletions(-) diff --git a/components/canvas/azure_backend.rs b/components/canvas/azure_backend.rs index 8727751d5a6..a99429e7769 100644 --- a/components/canvas/azure_backend.rs +++ b/components/canvas/azure_backend.rs @@ -2,7 +2,6 @@ * 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/. */ -use cssparser::RGBA; use crate::canvas_data::{ Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, GenericPathBuilder, Path, Pattern, StrokeOptions, @@ -14,6 +13,7 @@ use azure::azure_hl::SurfacePattern; use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle}; use azure::azure_hl::{BackendType, ColorPattern, DrawTarget}; use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; +use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; pub struct AzureBackend; @@ -40,8 +40,8 @@ impl Backend for AzureBackend { }, }; Some(size) - } - Pattern::Azure(_) => None + }, + Pattern::Azure(_) => None, } } @@ -64,14 +64,18 @@ impl Backend for AzureBackend { &mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, - drawtarget: &GenericDrawTarget) - { + drawtarget: &GenericDrawTarget, + ) { if let Some(pattern) = style.to_azure_pattern(drawtarget) { state.stroke_style = Pattern::Azure(pattern) } } - fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>) { + fn set_global_composition<'a>( + &mut self, + op: CompositionOrBlending, + state: &mut CanvasPaintState<'a>, + ) { state .draw_options .as_azure_mut() @@ -89,7 +93,7 @@ impl Backend for AzureBackend { fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { CanvasPaintState::new(AntialiasMode::from_azure( - self.state.draw_options.as_azure().antialias + self.state.draw_options.as_azure().antialias, )) } } @@ -97,9 +101,17 @@ impl Backend for AzureBackend { impl<'a> CanvasPaintState<'a> { pub fn new(antialias: AntialiasMode) -> CanvasPaintState<'a> { CanvasPaintState { - draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new(1.0, azure_hl::CompositionOp::Over, antialias.into_azure())), - fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), - stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black()))), + draw_options: DrawOptions::Azure(azure_hl::DrawOptions::new( + 1.0, + azure_hl::CompositionOp::Over, + antialias.into_azure(), + )), + fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new( + azure_hl::Color::black(), + ))), + stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new( + azure_hl::Color::black(), + ))), stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new( 1.0, JoinStyle::MiterOrBevel, @@ -112,7 +124,7 @@ impl<'a> CanvasPaintState<'a> { shadow_offset_y: 0.0, shadow_blur: 0.0, shadow_color: Color::Azure(azure_hl::Color::transparent()), - } + } } } @@ -240,7 +252,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { let draw_options = azure_hl::DrawOptions::new( draw_options.as_azure().alpha, draw_options.as_azure().composition.into_azure(), - azure_hl::AntialiasMode::None + azure_hl::AntialiasMode::None, ); self.draw_surface( surface.into_azure(), @@ -364,9 +376,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { } fn snapshot_data(&self) -> &[u8] { - unsafe { - self.snapshot().get_data_surface().data() - } + unsafe { self.snapshot().get_data_surface().data() } } } @@ -634,10 +644,12 @@ impl ToAzurePattern for FillOrStrokeStyle { let gradient_stops: Vec = linear_gradient_style .stops .iter() - .map(|s| GradientStop::Azure(azure_hl::GradientStop { - offset: s.offset as f32, - color: s.color.to_azure_style(), - })) + .map(|s| { + GradientStop::Azure(azure_hl::GradientStop { + offset: s.offset as f32, + color: s.color.to_azure_style(), + }) + }) .collect(); azure_hl::Pattern::LinearGradient(LinearGradientPattern::new( @@ -649,7 +661,12 @@ impl ToAzurePattern for FillOrStrokeStyle { linear_gradient_style.x1 as f32, linear_gradient_style.y1 as f32, ), - drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), + drawtarget + .create_gradient_stops( + gradient_stops, + ExtendMode::Azure(azure_hl::ExtendMode::Clamp), + ) + .into_azure(), &Transform2D::identity(), )) }, @@ -657,10 +674,12 @@ impl ToAzurePattern for FillOrStrokeStyle { let gradient_stops: Vec = radial_gradient_style .stops .iter() - .map(|s| GradientStop::Azure(azure_hl::GradientStop { - offset: s.offset as f32, - color: s.color.to_azure_style(), - })) + .map(|s| { + GradientStop::Azure(azure_hl::GradientStop { + offset: s.offset as f32, + color: s.color.to_azure_style(), + }) + }) .collect(); azure_hl::Pattern::RadialGradient(RadialGradientPattern::new( @@ -674,17 +693,24 @@ impl ToAzurePattern for FillOrStrokeStyle { ), radial_gradient_style.r0 as f32, radial_gradient_style.r1 as f32, - drawtarget.create_gradient_stops(gradient_stops, ExtendMode::Azure(azure_hl::ExtendMode::Clamp)).into_azure(), + drawtarget + .create_gradient_stops( + gradient_stops, + ExtendMode::Azure(azure_hl::ExtendMode::Clamp), + ) + .into_azure(), &Transform2D::identity(), )) }, FillOrStrokeStyle::Surface(ref surface_style) => { - let source_surface = drawtarget.create_source_surface_from_data( - &surface_style.surface_data, - // FIXME(nox): Why are those i32 values? - surface_style.surface_size.to_i32(), - surface_style.surface_size.width as i32 * 4, - )?.into_azure(); + let source_surface = drawtarget + .create_source_surface_from_data( + &surface_style.surface_data, + // FIXME(nox): Why are those i32 values? + surface_style.surface_size.to_i32(), + surface_style.surface_size.width as i32 * 4, + )? + .into_azure(); azure_hl::Pattern::Surface(SurfacePattern::new( source_surface.azure_source_surface, surface_style.repeat_x, @@ -711,10 +737,10 @@ impl ToAzureStyle for RGBA { impl Pattern { pub fn is_zero_size_gradient(&self) -> bool { - match *self { + match *self { Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => { gradient.is_zero_size() - } + }, _ => false, } } @@ -730,7 +756,10 @@ impl Filter { } impl Path { - pub fn transformed_copy_to_builder(&self, transform: &Transform2D) -> Box { + pub fn transformed_copy_to_builder( + &self, + transform: &Transform2D, + ) -> Box { Box::new(self.as_azure().transformed_copy_to_builder(transform)) } diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index a2312fea1ca..7792e9ed902 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -56,9 +56,23 @@ pub trait Backend { fn get_composition_op(&self, opts: &DrawOptions) -> CompositionOp; fn need_to_draw_shadow(&self, color: &Color) -> bool; fn set_shadow_color<'a>(&mut self, color: RGBA, state: &mut CanvasPaintState<'a>); - fn set_fill_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget); - fn set_stroke_style<'a>(&mut self, style: FillOrStrokeStyle, state: &mut CanvasPaintState<'a>, drawtarget: &GenericDrawTarget); - fn set_global_composition<'a>(&mut self, op: CompositionOrBlending, state: &mut CanvasPaintState<'a>); + fn set_fill_style<'a>( + &mut self, + style: FillOrStrokeStyle, + state: &mut CanvasPaintState<'a>, + drawtarget: &GenericDrawTarget, + ); + fn set_stroke_style<'a>( + &mut self, + style: FillOrStrokeStyle, + state: &mut CanvasPaintState<'a>, + drawtarget: &GenericDrawTarget, + ); + fn set_global_composition<'a>( + &mut self, + op: CompositionOrBlending, + state: &mut CanvasPaintState<'a>, + ); fn create_drawtarget(&self, size: Size2D) -> Box; fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a>; fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option>; @@ -143,12 +157,7 @@ impl<'a> PathBuilderRef<'a> { ) } - fn bezier_curve_to( - &self, - cp1: &Point2D, - cp2: &Point2D, - endpoint: &Point2D, - ) { + fn bezier_curve_to(&self, cp1: &Point2D, cp2: &Point2D, endpoint: &Point2D) { self.builder.bezier_curve_to( &self.transform.transform_point(cp1), &self.transform.transform_point(cp2), @@ -156,14 +165,7 @@ impl<'a> PathBuilderRef<'a> { ) } - fn arc( - &self, - center: &Point2D, - radius: f32, - start_angle: f32, - end_angle: f32, - ccw: bool, - ) { + fn arc(&self, center: &Point2D, radius: f32, start_angle: f32, end_angle: f32, ccw: bool) { let center = self.transform.transform_point(center); self.builder .arc(center, radius, start_angle, end_angle, ccw); @@ -305,7 +307,6 @@ pub enum Color { Raqote(()), } - #[derive(Clone)] pub enum CompositionOp { #[cfg(feature = "azure_backend")] @@ -439,7 +440,6 @@ impl<'a> CanvasData<'a> { image_data.into() }; - let writer = |draw_target: &GenericDrawTarget| { write_image( draw_target, @@ -859,11 +859,13 @@ impl<'a> CanvasData<'a> { } pub fn set_fill_style(&mut self, style: FillOrStrokeStyle) { - self.backend.set_fill_style(style, &mut self.state, &*self.drawtarget); + self.backend + .set_fill_style(style, &mut self.state, &*self.drawtarget); } pub fn set_stroke_style(&mut self, style: FillOrStrokeStyle) { - self.backend.set_stroke_style(style, &mut self.state, &*self.drawtarget); + self.backend + .set_stroke_style(style, &mut self.state, &*self.drawtarget); } pub fn set_line_width(&mut self, width: f32) { @@ -907,7 +909,9 @@ impl<'a> CanvasData<'a> { } pub fn recreate(&mut self, size: Size2D) { - self.drawtarget = self.backend.create_drawtarget(Size2D::new(size.width as u64, size.height as u64)); + self.drawtarget = self + .backend + .create_drawtarget(Size2D::new(size.width as u64, size.height as u64)); self.state = self.backend.recreate_paint_state(&self.state); self.saved_states.clear(); // Webrender doesn't let images change size, so we clear the webrender image key. @@ -925,9 +929,7 @@ impl<'a> CanvasData<'a> { #[allow(unsafe_code)] pub fn send_pixels(&mut self, chan: IpcSender) { - let data = IpcSharedMemory::from_bytes( - &self.drawtarget.snapshot_data() - ); + let data = IpcSharedMemory::from_bytes(&self.drawtarget.snapshot_data()); chan.send(data).unwrap(); } @@ -943,9 +945,7 @@ impl<'a> CanvasData<'a> { is_opaque: false, allow_mipmaps: false, }; - let data = webrender_api::ImageData::Raw(Arc::new( - self.drawtarget.snapshot_data().into() - )); + let data = webrender_api::ImageData::Raw(Arc::new(self.drawtarget.snapshot_data().into())); let mut txn = webrender_api::Transaction::new(); @@ -1065,17 +1065,17 @@ impl<'a> CanvasData<'a> { let canvas_rect = Rect::from_size(canvas_size); if canvas_rect .intersection(&read_rect) - .map_or(true, |rect| rect.is_empty()) - { - return vec![]; - } + .map_or(true, |rect| rect.is_empty()) + { + return vec![]; + } pixels::rgba8_get_rect( &self.drawtarget.snapshot_data(), canvas_size.to_u32(), read_rect.to_u32(), ) - .into_owned() + .into_owned() } } @@ -1139,20 +1139,10 @@ fn write_image( let image_size = image_size.to_i32(); let source_surface = draw_target - .create_source_surface_from_data( - &image_data, - image_size, - image_size.width * 4, - ) + .create_source_surface_from_data(&image_data, image_size, image_size.width * 4) .unwrap(); - - draw_target.draw_surface( - source_surface, - dest_rect, - image_rect, - filter, - draw_options, - ); + + draw_target.draw_surface(source_surface, dest_rect, image_rect, filter, draw_options); } pub trait PointToi32 { diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index afaa9f49d6a..f026311f2ee 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -199,9 +199,7 @@ impl<'a> CanvasPaintThread<'a> { self.canvas(canvas_id).set_shadow_offset_y(value) }, Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value), - Canvas2dMsg::SetShadowColor(color) => self - .canvas(canvas_id) - .set_shadow_color(color), + Canvas2dMsg::SetShadowColor(color) => self.canvas(canvas_id).set_shadow_color(color), } } diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 2d51c7f4493..95062410c1d 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -2,13 +2,13 @@ * 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/. */ -use cssparser::RGBA; use crate::canvas_data::{ Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, GenericPathBuilder, Path, Pattern, StrokeOptions, }; use crate::canvas_paint_thread::AntialiasMode; use canvas_traits::canvas::*; +use cssparser::RGBA; use euclid::{Rect, Size2D, Transform2D}; use std::marker::PhantomData; @@ -44,12 +44,16 @@ impl Backend for RaqoteBackend { &mut self, _style: FillOrStrokeStyle, _state: &mut CanvasPaintState<'a>, - _drawtarget: &GenericDrawTarget) - { + _drawtarget: &GenericDrawTarget, + ) { unimplemented!() } - fn set_global_composition<'a>(&mut self, _op: CompositionOrBlending, _state: &mut CanvasPaintState<'a>) { + fn set_global_composition<'a>( + &mut self, + _op: CompositionOrBlending, + _state: &mut CanvasPaintState<'a>, + ) { unimplemented!() } @@ -74,13 +78,13 @@ impl<'a> CanvasPaintState<'a> { shadow_offset_y: 0.0, shadow_blur: 0.0, shadow_color: Color::Raqote(()), - } + } } } impl Pattern { pub fn is_zero_size_gradient(&self) -> bool { - match *self { + match *self { Pattern::Raqote(()) => unimplemented!(), } } @@ -110,7 +114,10 @@ impl DrawOptions { } impl Path { - pub fn transformed_copy_to_builder(&self, _transform: &Transform2D) -> Box { + pub fn transformed_copy_to_builder( + &self, + _transform: &Transform2D, + ) -> Box { unimplemented!() } diff --git a/servo-tidy.toml b/servo-tidy.toml index 5ad6a7fc3ad..3af80740c70 100644 --- a/servo-tidy.toml +++ b/servo-tidy.toml @@ -39,9 +39,11 @@ packages = [ "crossbeam-epoch", "crossbeam-utils", "digest", + "dwrote", "generic-array", "gl_generator", # https://github.com/servo/servo/pull/23288#issuecomment-494687746 "lock_api", + "memmap", "nix", # https://github.com/servo/servo/issues/23189#issuecomment-487512605 "parking_lot", "parking_lot_core", From 3539c029f111cc9ee6ecba570bc898b8c601b71c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 15:49:33 -0400 Subject: [PATCH 10/14] Most basic raqote draw target stubs. --- components/canvas/raqote_backend.rs | 129 ++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 5 deletions(-) diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 95062410c1d..79a09ac29da 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -3,13 +3,14 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::canvas_data::{ - Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, - GenericPathBuilder, Path, Pattern, StrokeOptions, + Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, ExtendMode, Filter, + GenericDrawTarget, GenericPathBuilder, GradientStop, GradientStops, Path, Pattern, + SourceSurface, StrokeOptions, SurfaceFormat, }; use crate::canvas_paint_thread::AntialiasMode; use canvas_traits::canvas::*; use cssparser::RGBA; -use euclid::{Rect, Size2D, Transform2D}; +use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use std::marker::PhantomData; pub struct RaqoteBackend; @@ -57,8 +58,8 @@ impl Backend for RaqoteBackend { unimplemented!() } - fn create_drawtarget(&self, _size: Size2D) -> Box { - unimplemented!() + fn create_drawtarget(&self, size: Size2D) -> Box { + Box::new(raqote::DrawTarget::new(size.width as i32, size.height as i32)) } fn recreate_paint_state<'a>(&self, _state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { @@ -129,3 +130,121 @@ impl Path { unimplemented!() } } + +impl GenericDrawTarget for raqote::DrawTarget { + fn clear_rect(&self, _rect: &Rect) { + unimplemented!() + } + + fn copy_surface(&self, _surface: SourceSurface, _source: Rect, _destination: Point2D) { + unimplemented!() + } + + fn create_gradient_stops( + &self, + _gradient_stops: Vec, + _extend_mode: ExtendMode, + ) -> GradientStops { + unimplemented!() + } + + fn create_path_builder(&self) -> Box { + unimplemented!() + } + + fn create_similar_draw_target( + &self, + _size: &Size2D, + _format: SurfaceFormat, + ) -> Box { + unimplemented!() + } + fn create_source_surface_from_data( + &self, + _data: &[u8], + _size: Size2D, + _stride: i32, + ) -> Option { + unimplemented!() + } + fn draw_surface( + &self, + _surface: SourceSurface, + _dest: Rect, + _source: Rect, + _filter: Filter, + _draw_options: &DrawOptions, + ) { + unimplemented!() + } + fn draw_surface_with_shadow( + &self, + _surface: SourceSurface, + _dest: &Point2D, + _color: &Color, + _offset: &Vector2D, + _sigma: f32, + _operator: CompositionOp, + ) { + unimplemented!() + } + fn fill(&self, _path: &Path, _pattern: Pattern, _draw_options: &DrawOptions) { + unimplemented!() + } + fn fill_rect(&self, _rect: &Rect, _pattern: Pattern, _draw_options: Option<&DrawOptions>) { + unimplemented!() + } + fn get_format(&self) -> SurfaceFormat { + unimplemented!() + } + fn get_size(&self) -> Size2D { + unimplemented!() + } + fn get_transform(&self) -> Transform2D { + unimplemented!() + } + fn pop_clip(&self) { + unimplemented!() + } + fn push_clip(&self, _path: &Path) { + unimplemented!() + } + fn set_transform(&self, _matrix: &Transform2D) { + unimplemented!() + } + fn snapshot(&self) -> SourceSurface { + unimplemented!() + } + fn stroke( + &self, + _path: &Path, + _pattern: Pattern, + _stroke_options: &StrokeOptions, + _draw_options: &DrawOptions, + ) { + unimplemented!() + } + fn stroke_line( + &self, + _start: Point2D, + _end: Point2D, + _pattern: Pattern, + _stroke_options: &StrokeOptions, + _draw_options: &DrawOptions, + ) { + unimplemented!() + } + fn stroke_rect( + &self, + _rect: &Rect, + _pattern: Pattern, + _stroke_options: &StrokeOptions, + _draw_options: &DrawOptions, + ) { + unimplemented!() + } + + fn snapshot_data(&self) -> Vec { + unimplemented!() + } +} From ce18636aef6447a2b06fbfd2a5b884d14cf040d7 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 16:24:27 -0400 Subject: [PATCH 11/14] Make Azure backend build again. --- components/canvas/azure_backend.rs | 64 ++++++++++++----------------- components/canvas/canvas_data.rs | 49 +++++++++++----------- components/canvas/raqote_backend.rs | 18 ++++++-- 3 files changed, 66 insertions(+), 65 deletions(-) diff --git a/components/canvas/azure_backend.rs b/components/canvas/azure_backend.rs index a99429e7769..037809b5a05 100644 --- a/components/canvas/azure_backend.rs +++ b/components/canvas/azure_backend.rs @@ -3,16 +3,18 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::canvas_data::{ - Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, GenericDrawTarget, - GenericPathBuilder, Path, Pattern, StrokeOptions, + Backend, CanvasPaintState, Color, CompositionOp, DrawOptions, ExtendMode, Filter, + GenericDrawTarget, GenericPathBuilder, GradientStop, GradientStops, Path, Pattern, + SourceSurface, StrokeOptions, SurfaceFormat, }; use crate::canvas_paint_thread::AntialiasMode; -use azure::azure::{AzFloat, AzGradientStop, AzIntSize, AzPoint}; +use azure::azure::{AzFloat, AzGradientStop, AzPoint}; use azure::azure_hl; use azure::azure_hl::SurfacePattern; -use azure::azure_hl::{AsAzurePoint, CapStyle, JoinStyle}; use azure::azure_hl::{BackendType, ColorPattern, DrawTarget}; +use azure::azure_hl::{CapStyle, JoinStyle}; use azure::azure_hl::{LinearGradientPattern, RadialGradientPattern}; +use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; @@ -24,7 +26,7 @@ impl Backend for AzureBackend { } fn need_to_draw_shadow(&self, color: &Color) -> bool { - self.state.shadow_color.as_azure().a != 0.0f32 + color.as_azure().a != 0.0f32 } fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option> { @@ -93,7 +95,7 @@ impl Backend for AzureBackend { fn recreate_paint_state<'a>(&self, state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { CanvasPaintState::new(AntialiasMode::from_azure( - self.state.draw_options.as_azure().antialias, + state.draw_options.as_azure().antialias, )) } } @@ -251,15 +253,15 @@ impl GenericDrawTarget for azure_hl::DrawTarget { let surf_options = azure_hl::DrawSurfaceOptions::new(filter.as_azure(), true); let draw_options = azure_hl::DrawOptions::new( draw_options.as_azure().alpha, - draw_options.as_azure().composition.into_azure(), + draw_options.as_azure().composition, azure_hl::AntialiasMode::None, ); self.draw_surface( surface.into_azure(), - dest as Rect, - source as Rect, - surf_options.into_azure(), - options.into_azure(), + dest.to_azure_style(), + source.to_azure_style(), + surf_options, + draw_options, ); } fn draw_surface_with_shadow( @@ -356,7 +358,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { start, end, pattern.as_azure().to_pattern_ref(), - stroke_options.as_azure(), + &stroke_opts, draw_options.as_azure(), ); } @@ -375,8 +377,14 @@ impl GenericDrawTarget for azure_hl::DrawTarget { ); } - fn snapshot_data(&self) -> &[u8] { - unsafe { self.snapshot().get_data_surface().data() } + #[allow(unsafe_code)] + fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec) -> Vec { + unsafe { f(self.snapshot().get_data_surface().data()) } + } + + #[allow(unsafe_code)] + fn snapshot_data_owned(&self) -> Vec { + unsafe { self.snapshot().get_data_surface().data().into() } } } @@ -388,10 +396,11 @@ impl AntialiasMode { } } - fn from_azure(val: azure_hl::AntialiasMode) { + fn from_azure(val: azure_hl::AntialiasMode) -> AntialiasMode { match val { azure_hl::AntialiasMode::Default => AntialiasMode::Default, azure_hl::AntialiasMode::None => AntialiasMode::None, + v => unimplemented!("{:?} is unsupported", v), } } } @@ -452,14 +461,6 @@ impl SourceSurface { } } -impl IntSize { - fn into_azure(self) -> AzIntSize { - match self { - IntSize::Azure(s) => s, - } - } -} - impl Path { fn as_azure(&self) -> &azure_hl::Path { match self { @@ -476,14 +477,6 @@ impl Pattern { } } -impl DrawSurfaceOptions { - fn into_azure(self) -> azure_hl::DrawSurfaceOptions { - match self { - DrawSurfaceOptions::Azure(options) => options, - } - } -} - impl DrawOptions { fn as_azure(&self) -> &azure_hl::DrawOptions { match self { @@ -495,11 +488,6 @@ impl DrawOptions { DrawOptions::Azure(options) => options, } } - fn into_azure(self) -> azure_hl::DrawOptions { - match self { - DrawOptions::Azure(options) => options, - } - } pub fn set_alpha(&mut self, val: f32) { match self { DrawOptions::Azure(options) => options.alpha = val as AzFloat, @@ -738,7 +726,7 @@ impl ToAzureStyle for RGBA { impl Pattern { pub fn is_zero_size_gradient(&self) -> bool { match *self { - Pattern::Azure(azure_hl::Pattern::LinearGradient(ref az_pattern)) => { + Pattern::Azure(azure_hl::Pattern::LinearGradient(ref gradient)) => { gradient.is_zero_size() }, _ => false, @@ -768,6 +756,6 @@ impl Path { } pub fn copy_to_builder(&self) -> Box { - self.as_azure().copy_to_builder() + Box::new(self.as_azure().copy_to_builder()) } } diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 7792e9ed902..6b65f75117a 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -8,6 +8,7 @@ use cssparser::RGBA; use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D}; use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; use num_traits::ToPrimitive; +#[allow(unused_imports)] use std::marker::PhantomData; use std::mem; use std::sync::Arc; @@ -274,27 +275,28 @@ pub trait GenericDrawTarget { stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); - fn snapshot_data(&self) -> Vec; + fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec) -> Vec; + fn snapshot_data_owned(&self) -> Vec; } #[derive(Clone)] pub enum ExtendMode { #[cfg(feature = "azure_backend")] - Azure(azure_hl::ExtendMode), + Azure(azure::azure_hl::ExtendMode), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum GradientStop { #[cfg(feature = "azure_backend")] - Azure(AzGradientStop), + Azure(azure::AzGradientStop), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum GradientStops { #[cfg(feature = "azure_backend")] - Azure(azure_hl::GradientStops), + Azure(azure::azure_hl::GradientStops), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -302,7 +304,7 @@ pub enum GradientStops { #[derive(Clone)] pub enum Color { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Color), + Azure(azure::azure_hl::Color), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -310,14 +312,14 @@ pub enum Color { #[derive(Clone)] pub enum CompositionOp { #[cfg(feature = "azure_backend")] - Azure(azure_hl::CompositionOp), + Azure(azure::azure_hl::CompositionOp), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum SurfaceFormat { #[cfg(feature = "azure_backend")] - Azure(azure_hl::SurfaceFormat), + Azure(azure::azure_hl::SurfaceFormat), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -325,14 +327,14 @@ pub enum SurfaceFormat { #[derive(Clone)] pub enum SourceSurface { #[cfg(feature = "azure_backend")] - Azure(azure_hl::SourceSurface), + Azure(azure::azure_hl::SourceSurface), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum Path { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Path), + Azure(azure::azure_hl::Path), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -340,14 +342,14 @@ pub enum Path { #[derive(Clone)] pub enum Pattern { #[cfg(feature = "azure_backend")] - Azure(azure_hl::Pattern), + Azure(azure::azure_hl::Pattern), #[cfg(feature = "raqote_backend")] Raqote(()), } pub enum DrawSurfaceOptions { #[cfg(feature = "azure_backend")] - Azure(azure_hl::DrawSurfaceOptions), + Azure(azure::azure_hl::DrawSurfaceOptions), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -355,7 +357,7 @@ pub enum DrawSurfaceOptions { #[derive(Clone)] pub enum DrawOptions { #[cfg(feature = "azure_backend")] - Azure(azure_hl::DrawOptions), + Azure(azure::azure_hl::DrawOptions), #[cfg(feature = "raqote_backend")] Raqote(()), } @@ -363,7 +365,7 @@ pub enum DrawOptions { #[derive(Clone)] pub enum StrokeOptions<'a> { #[cfg(feature = "azure_backend")] - Azure(azure_hl::StrokeOptions<'a>), + Azure(azure::azure_hl::StrokeOptions<'a>), #[cfg(feature = "raqote_backend")] Raqote(PhantomData<&'a ()>), } @@ -927,13 +929,14 @@ impl<'a> CanvasData<'a> { } } - #[allow(unsafe_code)] pub fn send_pixels(&mut self, chan: IpcSender) { - let data = IpcSharedMemory::from_bytes(&self.drawtarget.snapshot_data()); - chan.send(data).unwrap(); + self.drawtarget.snapshot_data(&|bytes| { + let data = IpcSharedMemory::from_bytes(bytes); + chan.send(data).unwrap(); + vec![] + }); } - #[allow(unsafe_code)] pub fn send_data(&mut self, chan: IpcSender) { let size = self.drawtarget.get_size(); @@ -945,7 +948,8 @@ impl<'a> CanvasData<'a> { is_opaque: false, allow_mipmaps: false, }; - let data = webrender_api::ImageData::Raw(Arc::new(self.drawtarget.snapshot_data().into())); + let data = self.drawtarget.snapshot_data_owned(); + let data = webrender_api::ImageData::Raw(Arc::new(data)); let mut txn = webrender_api::Transaction::new(); @@ -1070,12 +1074,9 @@ impl<'a> CanvasData<'a> { return vec![]; } - pixels::rgba8_get_rect( - &self.drawtarget.snapshot_data(), - canvas_size.to_u32(), - read_rect.to_u32(), - ) - .into_owned() + self.drawtarget.snapshot_data(&|bytes| { + pixels::rgba8_get_rect(bytes, canvas_size.to_u32(), read_rect.to_u32()).into_owned() + }) } } diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 79a09ac29da..6e49026606e 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -59,7 +59,10 @@ impl Backend for RaqoteBackend { } fn create_drawtarget(&self, size: Size2D) -> Box { - Box::new(raqote::DrawTarget::new(size.width as i32, size.height as i32)) + Box::new(raqote::DrawTarget::new( + size.width as i32, + size.height as i32, + )) } fn recreate_paint_state<'a>(&self, _state: &CanvasPaintState<'a>) -> CanvasPaintState<'a> { @@ -136,7 +139,12 @@ impl GenericDrawTarget for raqote::DrawTarget { unimplemented!() } - fn copy_surface(&self, _surface: SourceSurface, _source: Rect, _destination: Point2D) { + fn copy_surface( + &self, + _surface: SourceSurface, + _source: Rect, + _destination: Point2D, + ) { unimplemented!() } @@ -244,7 +252,11 @@ impl GenericDrawTarget for raqote::DrawTarget { unimplemented!() } - fn snapshot_data(&self) -> Vec { + fn snapshot_data(&self, _f: &Fn(&[u8]) -> Vec) -> Vec { + unimplemented!() + } + + fn snapshot_data_owned(&self) -> Vec { unimplemented!() } } From 5a550e236c4e62ebc40dfc6b86d56af9fa853517 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 16:30:09 -0400 Subject: [PATCH 12/14] Build raqote backend on CI. --- etc/taskcluster/decision_task.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/taskcluster/decision_task.py b/etc/taskcluster/decision_task.py index bbe797bc4f0..6de1fce4db9 100644 --- a/etc/taskcluster/decision_task.py +++ b/etc/taskcluster/decision_task.py @@ -175,6 +175,7 @@ def linux_tidy_unit_docs(): ./mach build --dev ./mach test-unit ./mach package --dev + ./mach build --dev --features raqote_backend ./mach build --dev --libsimpleservo ./mach build --dev --no-default-features --features default-except-unstable ./mach test-tidy --no-progress --self-test From 193013f6bb45c810532158e16aa4a03ec6ab2035 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 29 May 2019 16:34:39 -0400 Subject: [PATCH 13/14] Add cargo features for canvas backend to other ports. --- ports/libmlservo/Cargo.toml | 4 ++++ ports/libsimpleservo/api/Cargo.toml | 16 +++++++++------- ports/libsimpleservo/capi/Cargo.toml | 16 +++++++++------- ports/libsimpleservo/jniapi/Cargo.toml | 16 +++++++++------- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/ports/libmlservo/Cargo.toml b/ports/libmlservo/Cargo.toml index 2534dbe4a9d..b2e3d900285 100644 --- a/ports/libmlservo/Cargo.toml +++ b/ports/libmlservo/Cargo.toml @@ -12,6 +12,10 @@ crate-type = ["staticlib"] test = false bench = false +[features] +azure_backend = ["simpleservo/azure_backend"] +raqote_backend = ["simpleservo/raqote_backend"] + [dependencies] libservo = { path = "../../components/servo", features = ["no_static_freetype"] } simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype"] } diff --git a/ports/libsimpleservo/api/Cargo.toml b/ports/libsimpleservo/api/Cargo.toml index 0556947d7da..7c48fa4de21 100644 --- a/ports/libsimpleservo/api/Cargo.toml +++ b/ports/libsimpleservo/api/Cargo.toml @@ -26,16 +26,18 @@ libloading = "0.5" gl_generator = "0.11" [features] +azure_backend = ["libservo/azure_backend"] default = ["unstable", "default-except-unstable"] default-except-unstable = ["webdriver", "max_log_level"] -max_log_level = ["log/release_max_level_info"] -webdriver = ["libservo/webdriver"] -energy-profiling = ["libservo/energy-profiling"] debugmozjs = ["libservo/debugmozjs"] -unstable = ["libservo/unstable"] +energy-profiling = ["libservo/energy-profiling"] googlevr = ["libservo/googlevr"] -oculusvr = ["libservo/oculusvr"] -native-bluetooth = ["libservo/native-bluetooth"] -webgl_backtrace = ["libservo/webgl_backtrace"] js_backtrace = ["libservo/js_backtrace"] +max_log_level = ["log/release_max_level_info"] +native-bluetooth = ["libservo/native-bluetooth"] no_static_freetype = ["libservo/no_static_freetype"] +oculusvr = ["libservo/oculusvr"] +raqote_backend = ["libservo/raqote_backend"] +webdriver = ["libservo/webdriver"] +unstable = ["libservo/unstable"] +webgl_backtrace = ["libservo/webgl_backtrace"] diff --git a/ports/libsimpleservo/capi/Cargo.toml b/ports/libsimpleservo/capi/Cargo.toml index c114f87083d..7764f3fe71b 100644 --- a/ports/libsimpleservo/capi/Cargo.toml +++ b/ports/libsimpleservo/capi/Cargo.toml @@ -21,15 +21,17 @@ env_logger = "0.6" cbindgen = "0.8" [features] +azure_backend = ["simpleservo/azure_backend"] +debugmozjs = ["simpleservo/debugmozjs"] default = ["unstable", "default-except-unstable"] default-except-unstable = ["webdriver", "max_log_level"] -max_log_level = ["simpleservo/max_log_level"] -webdriver = ["simpleservo/webdriver"] energy-profiling = ["simpleservo/energy-profiling"] -debugmozjs = ["simpleservo/debugmozjs"] -unstable = ["simpleservo/unstable"] googlevr = ["simpleservo/googlevr"] -oculusvr = ["simpleservo/oculusvr"] -native-bluetooth = ["simpleservo/native-bluetooth"] -webgl_backtrace = ["simpleservo/webgl_backtrace"] js_backtrace = ["simpleservo/js_backtrace"] +max_log_level = ["simpleservo/max_log_level"] +native-bluetooth = ["simpleservo/native-bluetooth"] +oculusvr = ["simpleservo/oculusvr"] +raqote_backend = ["simpleservo/raqote_backend"] +unstable = ["simpleservo/unstable"] +webdriver = ["simpleservo/webdriver"] +webgl_backtrace = ["simpleservo/webgl_backtrace"] diff --git a/ports/libsimpleservo/jniapi/Cargo.toml b/ports/libsimpleservo/jniapi/Cargo.toml index d2fafd86dc2..95a841770a0 100644 --- a/ports/libsimpleservo/jniapi/Cargo.toml +++ b/ports/libsimpleservo/jniapi/Cargo.toml @@ -26,15 +26,17 @@ simpleservo = { path = "../api" } cc = "1.0" [features] +azure_backend = ["simpleservo/azure_backend"] +debugmozjs = ["simpleservo/debugmozjs"] default = ["unstable", "default-except-unstable"] default-except-unstable = ["webdriver", "max_log_level"] -max_log_level = ["simpleservo/max_log_level"] -webdriver = ["simpleservo/webdriver"] energy-profiling = ["simpleservo/energy-profiling"] -debugmozjs = ["simpleservo/debugmozjs"] -unstable = ["simpleservo/unstable"] googlevr = ["simpleservo/googlevr"] -oculusvr = ["simpleservo/oculusvr"] -native-bluetooth = ["simpleservo/native-bluetooth"] -webgl_backtrace = ["simpleservo/webgl_backtrace"] js_backtrace = ["simpleservo/js_backtrace"] +max_log_level = ["simpleservo/max_log_level"] +native-bluetooth = ["simpleservo/native-bluetooth"] +oculusvr = ["simpleservo/oculusvr"] +raqote_backend = ["simpleservo/raqote_backend"] +unstable = ["simpleservo/unstable"] +webdriver = ["simpleservo/webdriver"] +webgl_backtrace = ["simpleservo/webgl_backtrace"] From 8467c00cf3c1865b7ce6a4274b35501f81493c40 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 3 Jun 2019 01:47:22 -0400 Subject: [PATCH 14/14] Fix docs. --- python/servo/post_build_commands.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/servo/post_build_commands.py b/python/servo/post_build_commands.py index 4d27475f74b..42e2ad84cb4 100644 --- a/python/servo/post_build_commands.py +++ b/python/servo/post_build_commands.py @@ -264,6 +264,8 @@ class PostBuildCommands(CommandBase): else: copy2(full_name, destination) + params += ["--features", "azure_backend"] + returncode = self.call_rustup_run( ["cargo", "doc", "--manifest-path", self.ports_glutin_manifest()] + params, env=self.build_env())