azul_webrender/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5/*!
6A GPU based renderer for the web.
7
8It serves as an experimental render backend for [Servo](https://servo.org/),
9but it can also be used as such in a standalone application.
10
11# External dependencies
12WebRender currently depends on [FreeType](https://www.freetype.org/)
13
14# Api Structure
15The main entry point to WebRender is the [`crate::Renderer`].
16
17By calling [`Renderer::new(...)`](crate::Renderer::new) you get a [`Renderer`], as well as
18a [`RenderApiSender`](api::RenderApiSender). Your [`Renderer`] is responsible to render the
19previously processed frames onto the screen.
20
21By calling [`yourRenderApiSender.create_api()`](api::RenderApiSender::create_api), you'll
22get a [`RenderApi`](api::RenderApi) instance, which is responsible for managing resources
23and documents. A worker thread is used internally to untie the workload from the application
24thread and therefore be able to make better use of multicore systems.
25
26## Frame
27
28What is referred to as a `frame`, is the current geometry on the screen.
29A new Frame is created by calling [`set_display_list()`](api::Transaction::set_display_list)
30on the [`RenderApi`](api::RenderApi). When the geometry is processed, the application will be
31informed via a [`RenderNotifier`](api::RenderNotifier), a callback which you pass to
32[`Renderer::new`].
33More information about [stacking contexts][stacking_contexts].
34
35[`set_display_list()`](api::Transaction::set_display_list) also needs to be supplied with
36[`BuiltDisplayList`](api::BuiltDisplayList)s. These are obtained by finalizing a
37[`DisplayListBuilder`](api::DisplayListBuilder). These are used to draw your geometry. But it
38doesn't only contain trivial geometry, it can also store another
39[`StackingContext`](api::StackingContext), as they're nestable.
40
41[stacking_contexts]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
42*/
43
44#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal, clippy::new_without_default, clippy::too_many_arguments))]
45
46
47// Cribbed from the |matches| crate, for simplicity.
48macro_rules! matches {
49    ($expression:expr, $($pattern:tt)+) => {
50        match $expression {
51            $($pattern)+ => true,
52            _ => false
53        }
54    }
55}
56
57#[macro_use]
58extern crate bitflags;
59#[macro_use]
60extern crate cstr;
61#[macro_use]
62extern crate lazy_static;
63#[macro_use]
64extern crate log;
65#[macro_use]
66extern crate malloc_size_of_derive;
67#[cfg(any(feature = "serde"))]
68#[macro_use]
69extern crate serde;
70#[macro_use]
71extern crate tracy_rs;
72#[macro_use]
73extern crate derive_more;
74extern crate malloc_size_of;
75extern crate svg_fmt;
76
77#[macro_use]
78mod profiler;
79
80mod batch;
81mod border;
82mod box_shadow;
83#[cfg(any(feature = "capture", feature = "replay"))]
84mod capture;
85mod clip;
86mod space;
87mod spatial_tree;
88mod composite;
89mod compositor;
90mod debug_colors;
91mod debug_font_data;
92mod debug_item;
93mod device;
94mod ellipse;
95mod filterdata;
96mod frame_builder;
97mod freelist;
98#[cfg(any(target_os = "macos", target_os = "windows"))]
99mod gamma_lut;
100mod glyph_cache;
101mod glyph_rasterizer;
102mod gpu_cache;
103mod gpu_types;
104mod hit_test;
105mod internal_types;
106mod lru_cache;
107mod picture;
108mod prepare;
109mod prim_store;
110mod print_tree;
111mod render_backend;
112mod render_target;
113mod render_task_graph;
114mod render_task_cache;
115mod render_task;
116mod renderer;
117mod resource_cache;
118mod scene;
119mod scene_builder_thread;
120mod scene_building;
121mod screen_capture;
122mod segment;
123mod spatial_node;
124mod texture_pack;
125mod texture_cache;
126mod tile_cache;
127mod util;
128mod visibility;
129mod api_resources;
130mod image_tiling;
131mod image_source;
132mod rectangle_occlusion;
133
134///
135pub mod intern;
136///
137pub mod render_api;
138
139mod shader_source {
140    include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
141}
142
143mod platform {
144    #[cfg(target_os = "macos")]
145    pub use crate::platform::macos::font;
146    #[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))]
147    pub use crate::platform::unix::font;
148    #[cfg(target_os = "windows")]
149    pub use crate::platform::windows::font;
150
151    #[cfg(target_os = "macos")]
152    pub mod macos {
153        pub mod font;
154    }
155    #[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))]
156    pub mod unix {
157        pub mod font;
158    }
159    #[cfg(target_os = "windows")]
160    pub mod windows {
161        pub mod font;
162    }
163}
164
165#[cfg(target_os = "macos")]
166extern crate core_foundation;
167#[cfg(target_os = "macos")]
168extern crate core_graphics;
169#[cfg(target_os = "macos")]
170extern crate core_text;
171
172#[cfg(all(unix, not(target_os = "macos")))]
173extern crate freetype;
174#[cfg(all(unix, not(target_os = "macos")))]
175extern crate libc;
176
177#[cfg(target_os = "windows")]
178extern crate dwrote;
179
180extern crate bincode;
181extern crate byteorder;
182pub extern crate euclid;
183extern crate fxhash;
184extern crate num_traits;
185extern crate plane_split;
186extern crate rayon;
187#[cfg(feature = "ron")]
188extern crate ron;
189#[macro_use]
190extern crate smallvec;
191extern crate time;
192#[cfg(all(feature = "capture", feature = "png"))]
193extern crate png;
194#[cfg(test)]
195extern crate rand;
196
197pub extern crate api;
198extern crate webrender_build;
199
200#[doc(hidden)]
201pub use crate::composite::{CompositorConfig, Compositor, CompositorCapabilities, CompositorSurfaceTransform};
202pub use crate::composite::{NativeSurfaceId, NativeTileId, NativeSurfaceInfo, PartialPresentCompositor};
203pub use crate::composite::{MappableCompositor, MappedTileInfo, SWGLCompositeSurfaceInfo};
204pub use crate::device::{UploadMethod, VertexUsageHint, get_gl_target, get_unoptimized_shader_source};
205pub use crate::device::{ProgramBinary, ProgramCache, ProgramCacheObserver, FormatDesc};
206pub use crate::device::Device;
207pub use crate::frame_builder::ChasePrimitive;
208pub use crate::prim_store::PrimitiveDebugId;
209pub use crate::profiler::{ProfilerHooks, set_profiler_hooks};
210pub use crate::renderer::{
211    AsyncPropertySampler, CpuProfile, DebugFlags, GpuProfile, GraphicsApi,
212    GraphicsApiInfo, PipelineInfo, Renderer, RendererError, RendererOptions, RenderResults,
213    RendererStats, SceneBuilderHooks, Shaders, SharedShaders, ShaderPrecacheFlags,
214    MAX_VERTEX_TEXTURE_WIDTH, ONE_TIME_USAGE_HINT,
215};
216pub use crate::hit_test::SharedHitTester;
217pub use crate::internal_types::FastHashMap;
218pub use crate::screen_capture::{AsyncScreenshotHandle, RecordedFrameHandle};
219pub use crate::texture_cache::TextureCacheConfig;
220pub use api as webrender_api;
221pub use webrender_build::shader::ProgramSourceDigest;
222pub use crate::picture::{TileDescriptor, TileId, InvalidationReason};
223pub use crate::picture::{PrimitiveCompareResult, PrimitiveCompareResultDetail, CompareHelperResult};
224pub use crate::picture::{TileNode, TileNodeKind, TileSerializer, TileCacheInstanceSerializer, TileOffset, TileCacheLoggerUpdateLists};
225pub use crate::intern::ItemUid;
226pub use crate::render_api::*;
227pub use crate::tile_cache::{PictureCacheDebugInfo, DirtyTileDebugInfo, TileDebugInfo, SliceDebugInfo};
228
229#[cfg(feature = "sw_compositor")]
230pub use crate::compositor::sw_compositor;