Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f78c01d

Browse files
author
bors-servo
authoredFeb 19, 2020
Auto merge of #3868 - moz-gfx:github-sync, r=auto
Sync changes from mozilla-central gfx/wr Fixes #3864,
2 parents 308740b + 0d042e8 commit f78c01d

File tree

6 files changed

+186
-133
lines changed

6 files changed

+186
-133
lines changed
 

‎webrender/res/brush.glsl

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,12 @@ void main(void) {
164164

165165
// Write the normal vertex information out.
166166
if (transform.is_axis_aligned) {
167+
168+
// Select the corner of the local rect that we are processing.
169+
vec2 local_pos = segment_rect.p0 + segment_rect.size * aPosition.xy;
170+
167171
vi = write_vertex(
168-
segment_rect,
172+
local_pos,
169173
ph.local_clip_rect,
170174
ph.z,
171175
transform,

‎webrender/res/prim_shared.glsl

+1-5
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,11 @@ struct VertexInfo {
109109
vec4 world_pos;
110110
};
111111

112-
VertexInfo write_vertex(RectWithSize instance_rect,
112+
VertexInfo write_vertex(vec2 local_pos,
113113
RectWithSize local_clip_rect,
114114
float z,
115115
Transform transform,
116116
PictureTask task) {
117-
118-
// Select the corner of the local rect that we are processing.
119-
vec2 local_pos = instance_rect.p0 + instance_rect.size * aPosition.xy;
120-
121117
// Clamp to the two local clip rects.
122118
vec2 clamped_local_pos = clamp_rect(local_pos, local_clip_rect);
123119

‎webrender/res/ps_text_run.glsl

+33-38
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ TextRun fetch_text_run(int address) {
9090
return TextRun(data[0], data[1]);
9191
}
9292

93+
vec2 get_snap_bias(int subpx_dir) {
94+
// In subpixel mode, the subpixel offset has already been
95+
// accounted for while rasterizing the glyph. However, we
96+
// must still round with a subpixel bias rather than rounding
97+
// to the nearest whole pixel, depending on subpixel direciton.
98+
switch (subpx_dir) {
99+
case SUBPX_DIR_NONE:
100+
default:
101+
return vec2(0.5);
102+
case SUBPX_DIR_HORIZONTAL:
103+
// Glyphs positioned [-0.125, 0.125] get a
104+
// subpx position of zero. So include that
105+
// offset in the glyph position to ensure
106+
// we round to the correct whole position.
107+
return vec2(0.125, 0.5);
108+
case SUBPX_DIR_VERTICAL:
109+
return vec2(0.5, 0.125);
110+
case SUBPX_DIR_MIXED:
111+
return vec2(0.125);
112+
}
113+
}
114+
93115
void main(void) {
94116
Instance instance = decode_instance_attributes();
95117

@@ -118,30 +140,7 @@ void main(void) {
118140

119141
GlyphResource res = fetch_glyph_resource(instance.resource_address);
120142

121-
vec2 snap_bias;
122-
// In subpixel mode, the subpixel offset has already been
123-
// accounted for while rasterizing the glyph. However, we
124-
// must still round with a subpixel bias rather than rounding
125-
// to the nearest whole pixel, depending on subpixel direciton.
126-
switch (subpx_dir) {
127-
case SUBPX_DIR_NONE:
128-
default:
129-
snap_bias = vec2(0.5);
130-
break;
131-
case SUBPX_DIR_HORIZONTAL:
132-
// Glyphs positioned [-0.125, 0.125] get a
133-
// subpx position of zero. So include that
134-
// offset in the glyph position to ensure
135-
// we round to the correct whole position.
136-
snap_bias = vec2(0.125, 0.5);
137-
break;
138-
case SUBPX_DIR_VERTICAL:
139-
snap_bias = vec2(0.5, 0.125);
140-
break;
141-
case SUBPX_DIR_MIXED:
142-
snap_bias = vec2(0.125);
143-
break;
144-
}
143+
vec2 snap_bias = get_snap_bias(subpx_dir);
145144

146145
// Glyph space refers to the pixel space used by glyph rasterization during frame
147146
// building. If a non-identity transform was used, WR_FEATURE_GLYPH_TRANSFORM will
@@ -220,26 +219,22 @@ void main(void) {
220219
vec2 local_pos = glyph_rect.p0 + glyph_rect.size * aPosition.xy;
221220
#endif
222221

223-
// Clamp to the local clip rect.
224-
local_pos = clamp_rect(local_pos, ph.local_clip_rect);
225-
226-
// Map the clamped local space corner into device space.
227-
vec4 world_pos = transform.m * vec4(local_pos, 0.0, 1.0);
228-
vec2 device_pos = world_pos.xy * task.device_pixel_scale;
229-
230-
// Apply offsets for the render task to get correct screen location.
231-
vec2 final_offset = -task.content_origin + task.common_data.task_rect.p0;
232-
233-
gl_Position = uTransform * vec4(device_pos + final_offset * world_pos.w, ph.z * world_pos.w, world_pos.w);
222+
VertexInfo vi = write_vertex(
223+
local_pos,
224+
ph.local_clip_rect,
225+
ph.z,
226+
transform,
227+
task
228+
);
234229

235230
#ifdef WR_FEATURE_GLYPH_TRANSFORM
236-
vec2 f = (glyph_transform * local_pos - glyph_rect.p0) / glyph_rect.size;
231+
vec2 f = (glyph_transform * vi.local_pos - glyph_rect.p0) / glyph_rect.size;
237232
V_UV_CLIP = vec4(f, 1.0 - f);
238233
#else
239-
vec2 f = (local_pos - glyph_rect.p0) / glyph_rect.size;
234+
vec2 f = (vi.local_pos - glyph_rect.p0) / glyph_rect.size;
240235
#endif
241236

242-
write_clip(world_pos, clip_area);
237+
write_clip(vi.world_pos, clip_area);
243238

244239
switch (color_mode) {
245240
case COLOR_MODE_ALPHA:

‎webrender/src/batch.rs

+100-82
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::gpu_types::{BrushFlags, BrushInstance, PrimitiveHeaders, ZBufferId, Z
1414
use crate::gpu_types::{ClipMaskInstance, SplitCompositeInstance, BrushShaderKind};
1515
use crate::gpu_types::{PrimitiveInstanceData, RasterizationSpace, GlyphInstance};
1616
use crate::gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, TransformPalette};
17+
use crate::gpu_types::{ImageBrushData, get_shader_opacity};
1718
use crate::internal_types::{FastHashMap, SavedTargetIndex, Swizzle, TextureSource, Filter};
1819
use crate::picture::{Picture3DContext, PictureCompositeMode, PicturePrimitive};
1920
use crate::prim_store::{DeferredResolve, EdgeAaSegmentMask, PrimitiveInstanceKind, PrimitiveVisibilityIndex, PrimitiveVisibilityMask};
@@ -849,12 +850,12 @@ impl BatchBuilder {
849850

850851
let batch_params = BrushBatchParameters::instanced(
851852
BrushBatchKind::Image(ImageBufferKind::Texture2DArray),
852-
[
853-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
854-
RasterizationSpace::Local as i32,
855-
get_shader_opacity(1.0),
856-
0,
857-
],
853+
ImageBrushData {
854+
color_mode: ShaderColorMode::Image,
855+
alpha_type: AlphaType::PremultipliedAlpha,
856+
raster_space: RasterizationSpace::Local,
857+
opacity: 1.0,
858+
}.encode(),
858859
segment_data,
859860
);
860861

@@ -1004,12 +1005,12 @@ impl BatchBuilder {
10041005

10051006
for glyph in glyphs {
10061007
batch.push(base_instance.build(
1007-
((render_task_address.0 as i32) << 16)
1008-
| clip_task_address.unwrap().0 as i32,
1009-
(subpx_dir as u32 as i32) << 24
1010-
| (color_mode as u32 as i32) << 16
1011-
| glyph.index_in_text_run,
1012-
glyph.uv_rect_address.as_int(),
1008+
render_task_address,
1009+
clip_task_address.unwrap(),
1010+
subpx_dir,
1011+
glyph.index_in_text_run,
1012+
glyph.uv_rect_address,
1013+
color_mode,
10131014
));
10141015
}
10151016
}
@@ -1035,12 +1036,12 @@ impl BatchBuilder {
10351036
(
10361037
BrushBatchKind::Image(get_buffer_kind(cache_item.texture_id)),
10371038
textures,
1038-
[
1039-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1040-
RasterizationSpace::Local as i32,
1041-
get_shader_opacity(1.0),
1042-
0,
1043-
],
1039+
ImageBrushData {
1040+
color_mode: ShaderColorMode::Image,
1041+
alpha_type: AlphaType::PremultipliedAlpha,
1042+
raster_space: RasterizationSpace::Local,
1043+
opacity: 1.0,
1044+
}.encode(),
10441045
cache_item.uv_rect_handle.as_int(gpu_cache),
10451046
)
10461047
}
@@ -1248,12 +1249,16 @@ impl BatchBuilder {
12481249
non_segmented_blend_mode,
12491250
textures,
12501251
);
1251-
let prim_header_index = prim_headers.push(&prim_header, z_id, [
1252-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1253-
RasterizationSpace::Screen as i32,
1254-
get_shader_opacity(1.0),
1255-
0,
1256-
]);
1252+
let prim_header_index = prim_headers.push(
1253+
&prim_header,
1254+
z_id,
1255+
ImageBrushData {
1256+
color_mode: ShaderColorMode::Image,
1257+
alpha_type: AlphaType::PremultipliedAlpha,
1258+
raster_space: RasterizationSpace::Screen,
1259+
opacity: 1.0,
1260+
}.encode(),
1261+
);
12571262

12581263
self.add_brush_instance_to_batches(
12591264
key,
@@ -1323,12 +1328,16 @@ impl BatchBuilder {
13231328
..prim_header
13241329
};
13251330

1326-
let shadow_prim_header_index = prim_headers.push(&shadow_prim_header, z_id, [
1327-
ShaderColorMode::Alpha as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1328-
RasterizationSpace::Screen as i32,
1329-
get_shader_opacity(1.0),
1330-
0,
1331-
]);
1331+
let shadow_prim_header_index = prim_headers.push(
1332+
&shadow_prim_header,
1333+
z_id,
1334+
ImageBrushData {
1335+
color_mode: ShaderColorMode::Alpha,
1336+
alpha_type: AlphaType::PremultipliedAlpha,
1337+
raster_space: RasterizationSpace::Screen,
1338+
opacity: 1.0,
1339+
}.encode(),
1340+
);
13321341

13331342
self.add_brush_instance_to_batches(
13341343
shadow_key,
@@ -1346,12 +1355,16 @@ impl BatchBuilder {
13461355
}
13471356
let z_id_content = z_generator.next();
13481357

1349-
let content_prim_header_index = prim_headers.push(&prim_header, z_id_content, [
1350-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1351-
RasterizationSpace::Screen as i32,
1352-
get_shader_opacity(1.0),
1353-
0,
1354-
]);
1358+
let content_prim_header_index = prim_headers.push(
1359+
&prim_header,
1360+
z_id_content,
1361+
ImageBrushData {
1362+
color_mode: ShaderColorMode::Image,
1363+
alpha_type: AlphaType::PremultipliedAlpha,
1364+
raster_space: RasterizationSpace::Screen,
1365+
opacity: 1.0,
1366+
}.encode(),
1367+
);
13551368

13561369
self.add_brush_instance_to_batches(
13571370
content_key,
@@ -1525,12 +1538,16 @@ impl BatchBuilder {
15251538
BlendMode::Advanced(mode),
15261539
textures,
15271540
);
1528-
let prim_header_index = prim_headers.push(&prim_header, z_id, [
1529-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1530-
RasterizationSpace::Local as i32,
1531-
get_shader_opacity(1.0),
1532-
0,
1533-
]);
1541+
let prim_header_index = prim_headers.push(
1542+
&prim_header,
1543+
z_id,
1544+
ImageBrushData {
1545+
color_mode: ShaderColorMode::Image,
1546+
alpha_type: AlphaType::PremultipliedAlpha,
1547+
raster_space: RasterizationSpace::Local,
1548+
opacity: 1.0,
1549+
}.encode(),
1550+
);
15341551

15351552
self.add_brush_instance_to_batches(
15361553
key,
@@ -1607,12 +1624,12 @@ impl BatchBuilder {
16071624
let batch_params = BrushBatchParameters::shared(
16081625
BrushBatchKind::Image(ImageBufferKind::Texture2DArray),
16091626
textures,
1610-
[
1611-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1612-
RasterizationSpace::Screen as i32,
1613-
get_shader_opacity(1.0),
1614-
0,
1615-
],
1627+
ImageBrushData {
1628+
color_mode: ShaderColorMode::Image,
1629+
alpha_type: AlphaType::PremultipliedAlpha,
1630+
raster_space: RasterizationSpace::Screen,
1631+
opacity: 1.0,
1632+
}.encode(),
16161633
uv_rect_address,
16171634
);
16181635

@@ -1680,12 +1697,16 @@ impl BatchBuilder {
16801697
non_segmented_blend_mode,
16811698
textures,
16821699
);
1683-
let prim_header_index = prim_headers.push(&prim_header, z_id, [
1684-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1685-
RasterizationSpace::Screen as i32,
1686-
get_shader_opacity(1.0),
1687-
0,
1688-
]);
1700+
let prim_header_index = prim_headers.push(
1701+
&prim_header,
1702+
z_id,
1703+
ImageBrushData {
1704+
color_mode: ShaderColorMode::Image,
1705+
alpha_type: AlphaType::PremultipliedAlpha,
1706+
raster_space: RasterizationSpace::Screen,
1707+
opacity: 1.0,
1708+
}.encode(),
1709+
);
16891710

16901711
self.add_brush_instance_to_batches(
16911712
key,
@@ -1759,12 +1780,12 @@ impl BatchBuilder {
17591780
let batch_params = BrushBatchParameters::shared(
17601781
BrushBatchKind::Image(get_buffer_kind(cache_item.texture_id)),
17611782
textures,
1762-
[
1763-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
1764-
RasterizationSpace::Local as i32,
1765-
get_shader_opacity(1.0),
1766-
0,
1767-
],
1783+
ImageBrushData {
1784+
color_mode: ShaderColorMode::Image,
1785+
alpha_type: AlphaType::PremultipliedAlpha,
1786+
raster_space: RasterizationSpace::Local,
1787+
opacity: 1.0,
1788+
}.encode(),
17681789
cache_item.uv_rect_handle.as_int(gpu_cache),
17691790
);
17701791

@@ -1976,12 +1997,12 @@ impl BatchBuilder {
19761997
rendering: image_data.image_rendering,
19771998
tile: None,
19781999
};
1979-
let prim_user_data = [
1980-
ShaderColorMode::Image as i32 | ((image_data.alpha_type as i32) << 16),
1981-
RasterizationSpace::Local as i32,
1982-
get_shader_opacity(opacity_binding),
1983-
0,
1984-
];
2000+
let prim_user_data = ImageBrushData {
2001+
color_mode: ShaderColorMode::Image,
2002+
alpha_type: image_data.alpha_type,
2003+
raster_space: RasterizationSpace::Local,
2004+
opacity: opacity_binding,
2005+
}.encode();
19852006

19862007
if image_instance.visible_tiles.is_empty() {
19872008
let cache_item = match image_data.source {
@@ -2156,12 +2177,13 @@ impl BatchBuilder {
21562177

21572178
let textures = BatchTextures::color(cache_item.texture_id);
21582179
let batch_kind = BrushBatchKind::Image(get_buffer_kind(cache_item.texture_id));
2159-
let prim_user_data = [
2160-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
2161-
RasterizationSpace::Local as i32,
2162-
get_shader_opacity(1.0),
2163-
0,
2164-
];
2180+
let prim_user_data = ImageBrushData {
2181+
color_mode: ShaderColorMode::Image,
2182+
alpha_type: AlphaType::PremultipliedAlpha,
2183+
raster_space: RasterizationSpace::Local,
2184+
opacity: 1.0,
2185+
}.encode();
2186+
21652187
let specific_resource_address = cache_item.uv_rect_handle.as_int(gpu_cache);
21662188
prim_header.specific_prim_address = gpu_cache.get_address(&ctx.globals.default_image_handle);
21672189

@@ -2451,12 +2473,12 @@ impl BatchBuilder {
24512473
let prim_header_index = prim_headers.push(
24522474
&prim_header,
24532475
z_id,
2454-
[
2455-
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
2456-
RasterizationSpace::Screen as i32,
2457-
get_shader_opacity(1.0),
2458-
0
2459-
],
2476+
ImageBrushData {
2477+
color_mode: ShaderColorMode::Image,
2478+
alpha_type: AlphaType::PremultipliedAlpha,
2479+
raster_space: RasterizationSpace::Screen,
2480+
opacity: 1.0,
2481+
}.encode(),
24602482
);
24612483

24622484
self.add_brush_instance_to_batches(
@@ -3219,10 +3241,6 @@ fn get_buffer_kind(texture: TextureSource) -> ImageBufferKind {
32193241
}
32203242
}
32213243

3222-
fn get_shader_opacity(opacity: f32) -> i32 {
3223-
(opacity * 65535.0).round() as i32
3224-
}
3225-
32263244
impl<'a, 'rc> RenderTargetContext<'a, 'rc> {
32273245
/// Retrieve the GPU task address for a given clip task instance.
32283246
/// Returns None if the segment was completely clipped out.

‎webrender/src/gpu_types.rs

+43-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use api::{DocumentLayer, PremultipliedColorF};
5+
use api::{DocumentLayer, PremultipliedColorF, AlphaType};
66
use api::units::*;
77
use crate::spatial_tree::{SpatialTree, ROOT_SPATIAL_NODE_INDEX, SpatialNodeIndex};
88
use crate::gpu_cache::{GpuCacheAddress, GpuDataRequest};
99
use crate::internal_types::FastHashMap;
1010
use crate::prim_store::EdgeAaSegmentMask;
1111
use crate::render_task::RenderTaskAddress;
12+
use crate::renderer::ShaderColorMode;
1213
use std::i32;
1314
use crate::util::{TransformedRectKind, MatrixHelpers};
15+
use crate::glyph_rasterizer::SubpixelDirection;
1416

1517
// Contains type that must exactly match the same structures declared in GLSL.
1618

@@ -364,13 +366,24 @@ impl GlyphInstance {
364366
// TODO(gw): Some of these fields can be moved to the primitive
365367
// header since they are constant, and some can be
366368
// compressed to a smaller size.
367-
pub fn build(&self, data0: i32, data1: i32, resource_address: i32) -> PrimitiveInstanceData {
369+
pub fn build(&self,
370+
render_task: RenderTaskAddress,
371+
clip_task: RenderTaskAddress,
372+
subpx_dir: SubpixelDirection,
373+
glyph_index_in_text_run: i32,
374+
glyph_uv_rect: GpuCacheAddress,
375+
color_mode: ShaderColorMode,
376+
) -> PrimitiveInstanceData {
368377
PrimitiveInstanceData {
369378
data: [
370379
self.prim_header_index.0 as i32,
371-
data0,
372-
data1,
373-
resource_address | ((BrushShaderKind::Text as i32) << 24),
380+
((render_task.0 as i32) << 16)
381+
| clip_task.0 as i32,
382+
(subpx_dir as u32 as i32) << 24
383+
| (color_mode as u32 as i32) << 16
384+
| glyph_index_in_text_run,
385+
glyph_uv_rect.as_int()
386+
| ((BrushShaderKind::Text as i32) << 24),
374387
],
375388
}
376389
}
@@ -452,6 +465,27 @@ impl From<BrushInstance> for PrimitiveInstanceData {
452465
}
453466
}
454467

468+
/// Convenience structure to encode into the image brush's user data.
469+
#[derive(Copy, Clone, Debug)]
470+
pub struct ImageBrushData {
471+
pub color_mode: ShaderColorMode,
472+
pub alpha_type: AlphaType,
473+
pub raster_space: RasterizationSpace,
474+
pub opacity: f32,
475+
}
476+
477+
impl ImageBrushData {
478+
#[inline]
479+
pub fn encode(&self) -> [i32; 4] {
480+
[
481+
self.color_mode as i32 | ((self.alpha_type as i32) << 16),
482+
self.raster_space as i32,
483+
get_shader_opacity(self.opacity),
484+
0,
485+
]
486+
}
487+
}
488+
455489
// Represents the information about a transform palette
456490
// entry that is passed to shaders. It includes an index
457491
// into the transform palette, and a set of flags. The
@@ -720,3 +754,7 @@ fn register_transform(
720754
index
721755
}
722756
}
757+
758+
pub fn get_shader_opacity(opacity: f32) -> i32 {
759+
(opacity * 65535.0).round() as i32
760+
}

‎webrender/src/renderer.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,10 @@ impl Renderer {
19691969
shaders: Option<&mut WrShaders>,
19701970
start_size: DeviceIntSize,
19711971
) -> Result<(Self, RenderApiSender), RendererError> {
1972+
if !wr_has_been_initialized() {
1973+
register_thread_with_profiler("Compositor".to_owned());
1974+
}
1975+
19721976
HAS_BEEN_INITIALIZED.store(true, Ordering::SeqCst);
19731977

19741978
let (api_tx, api_rx) = channel::msg_channel()?;
@@ -2028,8 +2032,6 @@ impl Renderer {
20282032
let max_texture_size = device.max_texture_size();
20292033
let max_texture_layers = device.max_texture_layers();
20302034

2031-
register_thread_with_profiler("Compositor".to_owned());
2032-
20332035
device.begin_frame();
20342036

20352037
let shaders = match shaders {

0 commit comments

Comments
 (0)
Please sign in to comment.