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 freelist;
104mod glyph_cache;
105mod gpu_cache;
106mod gpu_types;
107mod hit_test;
108mod internal_types;
109mod lru_cache;
110mod pattern;
111mod picture;
112mod picture_graph;
113mod prepare;
114mod prim_store;
115mod print_tree;
116mod quad;
117mod render_backend;
118mod render_target;
119mod render_task_graph;
120mod render_task_cache;
121mod render_task;
122mod renderer;
123mod resource_cache;
124mod scene;
125mod scene_builder_thread;
126mod scene_building;
127mod screen_capture;
128mod segment;
129mod spatial_node;
130mod surface;
131mod texture_pack;
132mod texture_cache;
133mod tile_cache;
134mod util;
135mod visibility;
136mod api_resources;
137mod image_tiling;
138mod image_source;
139mod rectangle_occlusion;
140mod picture_textures;
141mod frame_allocator;
142mod bump_allocator;
143
144///
145pub mod intern;
146///
147pub mod render_api;
148
149pub mod shader_source {
150    include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
151}
152
153extern crate bincode;
154extern crate byteorder;
155pub extern crate euclid;
156extern crate rustc_hash;
157extern crate gleam;
158extern crate num_traits;
159extern crate plane_split;
160extern crate rayon;
161#[cfg(feature = "ron")]
162extern crate ron;
163#[macro_use]
164extern crate smallvec;
165#[cfg(all(feature = "capture", feature = "png"))]
166extern crate png;
167#[cfg(test)]
168extern crate rand;
169
170pub extern crate api;
171extern crate webrender_build;
172
173#[doc(hidden)]
174pub use crate::composite::{LayerCompositor, CompositorInputConfig, CompositorSurfaceUsage, ClipRadius};
175pub use crate::composite::{CompositorConfig, Compositor, CompositorCapabilities, CompositorSurfaceTransform};
176pub use crate::composite::{NativeSurfaceId, NativeTileId, NativeSurfaceInfo, PartialPresentCompositor};
177pub use crate::composite::{MappableCompositor, MappedTileInfo, SWGLCompositeSurfaceInfo, WindowVisibility, WindowProperties};
178pub use crate::device::{UploadMethod, VertexUsageHint, get_gl_target, get_unoptimized_shader_source};
179pub use crate::device::{ProgramBinary, ProgramCache, ProgramCacheObserver, FormatDesc, ShaderError};
180pub use crate::device::Device;
181pub use crate::profiler::{ProfilerHooks, set_profiler_hooks};
182pub use crate::renderer::{
183    CpuProfile, DebugFlags, GpuProfile, GraphicsApi,
184    GraphicsApiInfo, PendingShadersToPrecache, PipelineInfo, Renderer, RendererError, RenderResults,
185    RendererStats, Shaders, SharedShaders, ShaderPrecacheFlags,
186    MAX_VERTEX_TEXTURE_WIDTH,
187};
188pub use crate::renderer::init::{WebRenderOptions, create_webrender_instance, AsyncPropertySampler, SceneBuilderHooks, RenderBackendHooks, ONE_TIME_USAGE_HINT};
189pub use crate::hit_test::SharedHitTester;
190pub use crate::internal_types::FastHashMap;
191pub use crate::screen_capture::{AsyncScreenshotHandle, RecordedFrameHandle};
192pub use crate::texture_cache::TextureCacheConfig;
193pub use api as webrender_api;
194pub use webrender_build::shader::{ProgramSourceDigest, ShaderKind};
195pub use crate::picture::{TileDescriptor, TileId, InvalidationReason};
196pub use crate::picture::{PrimitiveCompareResult, CompareHelperResult};
197pub use crate::picture::{TileNode, TileNodeKind, TileOffset};
198pub use crate::intern::ItemUid;
199pub use crate::render_api::*;
200pub use crate::tile_cache::{PictureCacheDebugInfo, DirtyTileDebugInfo, TileDebugInfo, SliceDebugInfo};
201pub use crate::util::FastTransform;
202pub use glyph_rasterizer;
203pub use bump_allocator::ChunkPool;
204
205#[cfg(feature = "sw_compositor")]
206pub use crate::compositor::sw_compositor;
207
208#[cfg(feature = "debugger")]
209mod debugger;