forked from servo/webrender
-
Notifications
You must be signed in to change notification settings - Fork 3
/
internal_types.rs
293 lines (259 loc) · 7.06 KB
/
internal_types.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* 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 http://mozilla.org/MPL/2.0/. */
use device::TextureFilter;
use fxhash::FxHasher;
use profiler::BackendProfileCounters;
use std::collections::{HashMap, HashSet};
use std::f32;
use std::hash::BuildHasherDefault;
use std::{i32, usize};
use std::path::PathBuf;
use std::sync::Arc;
use tiling;
use renderer::BlendMode;
use api::{ClipId, ColorU, DevicePoint, DeviceUintRect, DocumentId, Epoch};
use api::{ExternalImageData, ExternalImageId};
use api::{ImageData, ImageFormat, PipelineId};
pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FastHashSet<K> = HashSet<K, BuildHasherDefault<FxHasher>>;
// An ID for a texture that is owned by the
// texture cache module. This can include atlases
// or standalone textures allocated via the
// texture cache (e.g. if an image is too large
// to be added to an atlas). The texture cache
// manages the allocation and freeing of these
// IDs, and the rendering thread maintains a
// map from cache texture ID to native texture.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct CacheTextureId(pub usize);
// Represents the source for a texture.
// These are passed from throughout the
// pipeline until they reach the rendering
// thread, where they are resolved to a
// native texture ID.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum SourceTexture {
Invalid,
TextureCache(CacheTextureId),
External(ExternalImageData),
#[cfg_attr(not(feature = "webgl"), allow(dead_code))]
/// This is actually a gl::GLuint, with the shared texture id between the
/// main context and the WebGL context.
WebGL(u32),
}
pub const ORTHO_NEAR_PLANE: f32 = -1000000.0;
pub const ORTHO_FAR_PLANE: f32 = 1000000.0;
#[derive(Debug, PartialEq, Eq)]
pub enum TextureSampler {
Color0,
Color1,
Color2,
CacheA8,
CacheRGBA8,
ResourceCache,
Layers,
RenderTasks,
Dither,
}
impl TextureSampler {
pub fn color(n: usize) -> TextureSampler {
match n {
0 => TextureSampler::Color0,
1 => TextureSampler::Color1,
2 => TextureSampler::Color2,
_ => {
panic!("There are only 3 color samplers.");
}
}
}
}
/// Optional textures that can be used as a source in the shaders.
/// Textures that are not used by the batch are equal to TextureId::invalid().
#[derive(Copy, Clone, Debug)]
pub struct BatchTextures {
pub colors: [SourceTexture; 3],
}
impl BatchTextures {
pub fn no_texture() -> Self {
BatchTextures {
colors: [SourceTexture::Invalid; 3],
}
}
}
// In some places we need to temporarily bind a texture to any slot.
pub const DEFAULT_TEXTURE: TextureSampler = TextureSampler::Color0;
#[derive(Clone, Copy, Debug)]
pub enum VertexAttribute {
// vertex-frequency basic attributes
Position,
Color,
ColorTexCoord,
// instance-frequency primitive attributes
Data0,
Data1,
}
#[derive(Clone, Copy, Debug)]
pub enum BlurAttribute {
// vertex frequency
Position,
// instance frequency
RenderTaskIndex,
SourceTaskIndex,
Direction,
}
#[derive(Clone, Copy, Debug)]
pub enum ClipAttribute {
// vertex frequency
Position,
// instance frequency
RenderTaskIndex,
LayerIndex,
DataIndex,
SegmentIndex,
ResourceAddress,
}
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct PackedVertex {
pub pos: [f32; 2],
}
#[derive(Debug)]
#[repr(C)]
pub struct DebugFontVertex {
pub x: f32,
pub y: f32,
pub color: ColorU,
pub u: f32,
pub v: f32,
}
impl DebugFontVertex {
pub fn new(x: f32, y: f32, u: f32, v: f32, color: ColorU) -> DebugFontVertex {
DebugFontVertex {
x,
y,
color,
u,
v,
}
}
}
#[repr(C)]
pub struct DebugColorVertex {
pub x: f32,
pub y: f32,
pub color: ColorU,
}
impl DebugColorVertex {
pub fn new(x: f32, y: f32, color: ColorU) -> DebugColorVertex {
DebugColorVertex {
x,
y,
color,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum RenderTargetMode {
None,
SimpleRenderTarget,
LayerRenderTarget(i32), // Number of texture layers
}
#[derive(Debug)]
pub enum TextureUpdateOp {
Create {
width: u32,
height: u32,
format: ImageFormat,
filter: TextureFilter,
mode: RenderTargetMode,
data: Option<ImageData>,
},
Update {
page_pos_x: u32, // the texture page position which we want to upload
page_pos_y: u32,
width: u32,
height: u32,
data: Arc<Vec<u8>>,
stride: Option<u32>,
offset: u32,
},
UpdateForExternalBuffer {
rect: DeviceUintRect,
id: ExternalImageId,
channel_index: u8,
stride: Option<u32>,
offset: u32,
},
Grow {
width: u32,
height: u32,
format: ImageFormat,
filter: TextureFilter,
mode: RenderTargetMode,
},
Free,
}
#[derive(Debug)]
pub struct TextureUpdate {
pub id: CacheTextureId,
pub op: TextureUpdateOp,
}
pub struct TextureUpdateList {
pub updates: Vec<TextureUpdate>,
}
impl TextureUpdateList {
pub fn new() -> TextureUpdateList {
TextureUpdateList {
updates: Vec::new(),
}
}
#[inline]
pub fn push(&mut self, update: TextureUpdate) {
self.updates.push(update);
}
}
/// Mostly wraps a tiling::Frame, adding a bit of extra information.
pub struct RendererFrame {
/// The last rendered epoch for each pipeline present in the frame.
/// This information is used to know if a certain transformation on the layout has
/// been rendered, which is necessary for reftests.
pub pipeline_epoch_map: FastHashMap<PipelineId, Epoch>,
/// The layers that are currently affected by the over-scrolling animation.
pub layers_bouncing_back: FastHashSet<ClipId>,
pub frame: Option<tiling::Frame>,
}
impl RendererFrame {
pub fn new(pipeline_epoch_map: FastHashMap<PipelineId, Epoch>,
layers_bouncing_back: FastHashSet<ClipId>,
frame: Option<tiling::Frame>)
-> RendererFrame {
RendererFrame {
pipeline_epoch_map,
layers_bouncing_back,
frame,
}
}
}
pub enum ResultMsg {
RefreshShader(PathBuf),
NewFrame(DocumentId, RendererFrame, TextureUpdateList, BackendProfileCounters),
}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub struct StackingContextIndex(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct UvRect {
pub uv0: DevicePoint,
pub uv1: DevicePoint,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum HardwareCompositeOp {
PremultipliedAlpha,
}
impl HardwareCompositeOp {
pub fn to_blend_mode(&self) -> BlendMode {
match *self {
HardwareCompositeOp::PremultipliedAlpha => BlendMode::PremultipliedAlpha,
}
}
}