Source code

Revision control

Other Tools

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
/*!
6
A GPU based renderer for the web.
7
8
It serves as an experimental render backend for [Servo](https://servo.org/),
9
but it can also be used as such in a standalone application.
10
11
# External dependencies
12
WebRender currently depends on [FreeType](https://www.freetype.org/)
13
14
# Api Structure
15
The main entry point to WebRender is the [`crate::Renderer`].
16
17
By calling [`Renderer::new(...)`](crate::Renderer::new) you get a [`Renderer`], as well as
18
a [`RenderApiSender`](api::RenderApiSender). Your [`Renderer`] is responsible to render the
19
previously processed frames onto the screen.
20
21
By calling [`yourRenderApiSender.create_api()`](api::RenderApiSender::create_api), you'll
22
get a [`RenderApi`](api::RenderApi) instance, which is responsible for managing resources
23
and documents. A worker thread is used internally to untie the workload from the application
24
thread and therefore be able to make better use of multicore systems.
25
26
## Frame
27
28
What is referred to as a `frame`, is the current geometry on the screen.
29
A new Frame is created by calling [`set_display_list()`](api::Transaction::set_display_list)
30
on the [`RenderApi`](api::RenderApi). When the geometry is processed, the application will be
31
informed via a [`RenderNotifier`](api::RenderNotifier), a callback which you pass to
32
[`Renderer::new`].
33
More 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
38
doesn't only contain trivial geometry, it can also store another
39
[`StackingContext`](api::StackingContext), as they're nestable.
40
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.
48
macro_rules! matches {
49
($expression:expr, $($pattern:tt)+) => {
50
match $expression {
51
$($pattern)+ => true,
52
_ => false
53
}
54
}
55
}
56
57
#[macro_use]
58
extern crate bitflags;
59
#[macro_use]
60
extern crate cfg_if;
61
#[macro_use]
62
extern crate cstr;
63
#[macro_use]
64
extern crate lazy_static;
65
#[macro_use]
66
extern crate log;
67
#[macro_use]
68
extern crate malloc_size_of_derive;
69
#[cfg(any(feature = "serde"))]
70
#[macro_use]
71
extern crate serde;
72
#[macro_use]
73
extern crate tracy_rs;
74
75
extern crate malloc_size_of;
76
extern crate svg_fmt;
77
78
#[macro_use]
79
mod profiler;
80
81
mod batch;
82
mod border;
83
mod box_shadow;
84
#[cfg(any(feature = "capture", feature = "replay"))]
85
mod capture;
86
mod clip;
87
mod spatial_tree;
88
mod composite;
89
mod debug_colors;
90
mod debug_font_data;
91
mod debug_render;
92
#[cfg(feature = "debugger")]
93
mod debug_server;
94
mod device;
95
mod ellipse;
96
mod filterdata;
97
mod frame_builder;
98
mod freelist;
99
#[cfg(any(target_os = "macos", target_os = "windows"))]
100
mod gamma_lut;
101
mod glyph_cache;
102
mod glyph_rasterizer;
103
mod gpu_cache;
104
mod gpu_types;
105
mod hit_test;
106
mod image;
107
mod intern;
108
mod internal_types;
109
mod picture;
110
mod prim_store;
111
mod print_tree;
112
mod record;
113
mod render_backend;
114
mod render_target;
115
mod render_task_graph;
116
mod render_task_cache;
117
mod render_task;
118
mod renderer;
119
mod resource_cache;
120
mod scene;
121
mod scene_builder_thread;
122
mod scene_building;
123
mod screen_capture;
124
mod segment;
125
mod shade;
126
mod spatial_node;
127
mod storage;
128
mod texture_allocator;
129
mod texture_cache;
130
mod util;
131
132
mod shader_source {
133
include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
134
}
135
136
pub use crate::record::{ApiRecordingReceiver, BinaryRecorder, WEBRENDER_RECORDING_HEADER};
137
138
mod platform {
139
#[cfg(target_os = "macos")]
140
pub use crate::platform::macos::font;
141
#[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))]
142
pub use crate::platform::unix::font;
143
#[cfg(target_os = "windows")]
144
pub use crate::platform::windows::font;
145
146
#[cfg(target_os = "macos")]
147
pub mod macos {
148
pub mod font;
149
}
150
#[cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))]
151
pub mod unix {
152
pub mod font;
153
}
154
#[cfg(target_os = "windows")]
155
pub mod windows {
156
pub mod font;
157
}
158
}
159
160
#[cfg(target_os = "macos")]
161
extern crate core_foundation;
162
#[cfg(target_os = "macos")]
163
extern crate core_graphics;
164
#[cfg(target_os = "macos")]
165
extern crate core_text;
166
167
#[cfg(all(unix, not(target_os = "macos")))]
168
extern crate freetype;
169
#[cfg(all(unix, not(target_os = "macos")))]
170
extern crate libc;
171
172
#[cfg(target_os = "windows")]
173
extern crate dwrote;
174
175
extern crate bincode;
176
extern crate byteorder;
177
pub extern crate euclid;
178
extern crate fxhash;
179
extern crate gleam;
180
extern crate num_traits;
181
extern crate plane_split;
182
extern crate rayon;
183
#[cfg(feature = "ron")]
184
extern crate ron;
185
#[cfg(feature = "debugger")]
186
extern crate serde_json;
187
#[macro_use]
188
extern crate smallvec;
189
extern crate time;
190
#[cfg(feature = "debugger")]
191
extern crate ws;
192
#[cfg(feature = "debugger")]
193
extern crate image_loader;
194
#[cfg(feature = "debugger")]
195
extern crate base64;
196
#[cfg(all(feature = "capture", feature = "png"))]
197
extern crate png;
198
#[cfg(test)]
199
extern crate rand;
200
201
#[macro_use]
202
pub extern crate api;
203
extern crate webrender_build;
204
205
#[doc(hidden)]
206
pub use crate::composite::{CompositorConfig, Compositor, CompositorCapabilities};
207
pub use crate::composite::{NativeSurfaceId, NativeTileId, NativeSurfaceInfo};
208
pub use crate::device::{build_shader_strings, UploadMethod, VertexUsageHint, get_gl_target};
209
pub use crate::device::{ProgramBinary, ProgramCache, ProgramCacheObserver, FormatDesc};
210
pub use crate::device::Device;
211
pub use crate::frame_builder::ChasePrimitive;
212
pub use crate::prim_store::PrimitiveDebugId;
213
pub use crate::profiler::{ProfilerHooks, set_profiler_hooks};
214
pub use crate::renderer::{
215
AsyncPropertySampler, CpuProfile, DebugFlags, RendererKind, GpuProfile, GraphicsApi,
216
GraphicsApiInfo, PipelineInfo, Renderer, RendererError, RendererOptions, RenderResults,
217
RendererStats, SceneBuilderHooks, ThreadListener, ShaderPrecacheFlags,
218
MAX_VERTEX_TEXTURE_WIDTH,
219
};
220
pub use crate::hit_test::SharedHitTester;
221
pub use crate::internal_types::FastHashMap;
222
pub use crate::screen_capture::{AsyncScreenshotHandle, RecordedFrameHandle};
223
pub use crate::shade::{Shaders, WrShaders};
224
pub use api as webrender_api;
225
pub use webrender_build::shader::ProgramSourceDigest;
226
pub use crate::picture::{TileDescriptor, TileId, InvalidationReason};
227
pub use crate::picture::{PrimitiveCompareResult, PrimitiveCompareResultDetail, CompareHelperResult};
228
pub use crate::picture::{TileNode, TileNodeKind, TileSerializer, TileCacheInstanceSerializer, TileOffset, TileCacheLoggerUpdateLists};
229
pub use crate::intern::ItemUid;