Skip to main content

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#![allow(
45    clippy::unreadable_literal,
46    clippy::new_without_default,
47    clippy::too_many_arguments,
48    unknown_lints,
49    mismatched_lifetime_syntaxes
50)]
51
52
53// Cribbed from the |matches| crate, for simplicity.
54macro_rules! matches {
55    ($expression:expr, $($pattern:tt)+) => {
56        match $expression {
57            $($pattern)+ => true,
58            _ => false
59        }
60    }
61}
62
63#[macro_use]
64extern crate bitflags;
65#[macro_use]
66extern crate lazy_static;
67#[macro_use]
68extern crate log;
69#[macro_use]
70extern crate malloc_size_of_derive;
71#[cfg(any(feature = "serde"))]
72#[macro_use]
73extern crate serde;
74#[macro_use]
75extern crate tracy_rs;
76#[macro_use]
77extern crate derive_more;
78extern crate malloc_size_of;
79extern crate svg_fmt;
80
81#[macro_use]
82mod profiler;
83mod telemetry;
84
85mod batch;
86mod border;
87mod box_shadow;
88#[cfg(any(feature = "capture", feature = "replay"))]
89mod capture;
90mod clip;
91mod space;
92mod spatial_tree;
93mod command_buffer;
94mod composite;
95mod compositor;
96mod debug_colors;
97mod debug_font_data;
98mod debug_item;
99mod device;
100mod ellipse;
101mod filterdata;
102mod frame_builder;
103mod frame_snap;
104mod freelist;
105mod glyph_cache;
106mod gpu_types;
107mod hit_test;
108mod internal_types;
109mod lru_cache;
110mod pattern;
111mod picture;
112mod picture_composite_mode;
113mod picture_graph;
114mod invalidation;
115mod prepare;
116mod prim_store;
117mod print_tree;
118mod quad;
119mod render_backend;
120mod render_target;
121mod render_task_graph;
122mod render_task_cache;
123mod render_task;
124mod renderer;
125mod resource_cache;
126pub mod scene;
127mod scene_builder_thread;
128mod scene_building;
129mod screen_capture;
130mod segment;
131mod spatial_node;
132mod surface;
133mod texture_pack;
134mod texture_cache;
135mod transform;
136mod tile_cache;
137mod util;
138mod visibility;
139mod api_resources;
140mod image_tiling;
141mod image_source;
142mod rectangle_occlusion;
143mod picture_textures;
144mod frame_allocator;
145mod bump_allocator;
146mod svg_filter;
147
148///
149pub mod intern;
150///
151pub mod render_api;
152
153pub mod shader_source {
154    include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
155}
156
157extern crate bincode;
158extern crate byteorder;
159pub extern crate euclid;
160extern crate rustc_hash;
161extern crate gleam;
162extern crate num_traits;
163extern crate plane_split;
164extern crate rayon;
165#[cfg(feature = "ron")]
166extern crate ron;
167#[macro_use]
168extern crate smallvec;
169#[cfg(all(feature = "capture", feature = "png"))]
170extern crate png;
171#[cfg(test)]
172extern crate rand;
173
174pub extern crate api;
175extern crate webrender_build;
176
177#[doc(hidden)]
178pub use crate::composite::{LayerCompositor, CompositorInputConfig, CompositorSurfaceUsage, ClipRadius};
179pub use crate::composite::{CompositorConfig, Compositor, CompositorCapabilities, CompositorSurfaceTransform};
180pub use crate::composite::{NativeSurfaceId, NativeTileId, NativeSurfaceInfo, PartialPresentCompositor};
181pub use crate::composite::{MappableCompositor, MappedTileInfo, SWGLCompositeSurfaceInfo, WindowVisibility, WindowProperties};
182pub use crate::device::{UploadMethod, VertexUsageHint, get_gl_target, get_unoptimized_shader_source};
183pub use crate::device::{ProgramBinary, ProgramCache, ProgramCacheObserver, FormatDesc, ShaderError};
184pub use crate::device::Device;
185pub use crate::profiler::{ProfilerHooks, set_profiler_hooks};
186pub use crate::renderer::{
187    CpuProfile, DebugFlags, GpuProfile, GraphicsApi,
188    GraphicsApiInfo, PendingShadersToPrecache, PipelineInfo, Renderer, RendererError, RenderResults,
189    RendererStats, Shaders, SharedShaders, ShaderPrecacheFlags,
190    MAX_VERTEX_TEXTURE_WIDTH,
191};
192pub use crate::renderer::init::{WebRenderOptions, create_webrender_instance, AsyncPropertySampler, SceneBuilderHooks, RenderBackendHooks, ONE_TIME_USAGE_HINT};
193pub use crate::hit_test::SharedHitTester;
194pub use crate::internal_types::FastHashMap;
195pub use crate::screen_capture::{AsyncScreenshotHandle, RecordedFrameHandle};
196pub use crate::texture_cache::TextureCacheConfig;
197pub use api as webrender_api;
198pub use webrender_build::shader::{ProgramSourceDigest, ShaderKind};
199pub use crate::tile_cache::TileOffset;
200pub use crate::intern::ItemUid;
201pub use crate::render_api::*;
202pub use crate::tile_cache::{PictureCacheDebugInfo, DirtyTileDebugInfo, TileDebugInfo, SliceDebugInfo, CompositorClipDebugInfo};
203pub use crate::util::FastTransform;
204pub use glyph_rasterizer;
205pub use bump_allocator::ChunkPool;
206
207#[cfg(feature = "sw_compositor")]
208pub use crate::compositor::sw_compositor;
209
210#[cfg(feature = "debugger")]
211mod debugger;