Skip to content

Commit 604c69a

Browse files
author
bors-servo
authored
Auto merge of #3352 - gw3583:intern-gradient-3, r=kvark
Port linear gradients to be interned primitives. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/3352) <!-- Reviewable:end -->
2 parents 2352730 + b9dda49 commit 604c69a

File tree

8 files changed

+735
-487
lines changed

8 files changed

+735
-487
lines changed

webrender/src/batch.rs

+89-30
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ impl AlphaBatchBuilder {
908908
PrimitiveInstanceKind::Rectangle { .. } |
909909
PrimitiveInstanceKind::YuvImage { .. } |
910910
PrimitiveInstanceKind::Image { .. } |
911+
PrimitiveInstanceKind::LinearGradient { .. } |
911912
PrimitiveInstanceKind::Clear => {
912913
unreachable!();
913914
}
@@ -1410,8 +1411,7 @@ impl AlphaBatchBuilder {
14101411
let is_multiple_primitives = match prim.details {
14111412
PrimitiveDetails::Brush(ref brush) => {
14121413
match brush.kind {
1413-
BrushKind::LinearGradient { ref visible_tiles, .. } => !visible_tiles.is_empty(),
1414-
BrushKind::RadialGradient { ref visible_tiles, .. } => !visible_tiles.is_empty(),
1414+
BrushKind::RadialGradient { visible_tiles_range, .. } => !visible_tiles_range.is_empty(),
14151415
}
14161416
}
14171417
};
@@ -1450,22 +1450,9 @@ impl AlphaBatchBuilder {
14501450
}
14511451

14521452
match brush.kind {
1453-
BrushKind::LinearGradient { ref stops_handle, ref visible_tiles, .. } if !visible_tiles.is_empty() => {
1454-
add_gradient_tiles(
1455-
visible_tiles,
1456-
stops_handle,
1457-
BrushBatchKind::LinearGradient,
1458-
specified_blend_mode,
1459-
bounding_rect,
1460-
clip_task_address,
1461-
gpu_cache,
1462-
&mut self.batch_list,
1463-
&prim_header,
1464-
prim_headers,
1465-
z_id,
1466-
);
1467-
}
1468-
BrushKind::RadialGradient { ref stops_handle, ref visible_tiles, .. } if !visible_tiles.is_empty() => {
1453+
BrushKind::RadialGradient { ref stops_handle, visible_tiles_range, .. } if !visible_tiles_range.is_empty() => {
1454+
let visible_tiles = &ctx.scratch.gradient_tiles[visible_tiles_range];
1455+
14691456
add_gradient_tiles(
14701457
visible_tiles,
14711458
stops_handle,
@@ -1894,6 +1881,89 @@ impl AlphaBatchBuilder {
18941881
}
18951882
}
18961883
}
1884+
(
1885+
PrimitiveInstanceKind::LinearGradient { visible_tiles_range, .. },
1886+
PrimitiveTemplateKind::LinearGradient { stops_handle, ref brush_segments, .. }
1887+
) => {
1888+
let specified_blend_mode = BlendMode::PremultipliedAlpha;
1889+
1890+
let mut prim_header = PrimitiveHeader {
1891+
local_rect: prim_data.prim_rect,
1892+
local_clip_rect: prim_instance.combined_local_clip_rect,
1893+
task_address,
1894+
specific_prim_address: GpuCacheAddress::invalid(),
1895+
clip_task_address,
1896+
transform_id,
1897+
};
1898+
1899+
if visible_tiles_range.is_empty() {
1900+
let non_segmented_blend_mode = if !prim_data.opacity.is_opaque ||
1901+
prim_instance.clip_task_index != ClipTaskIndex::INVALID ||
1902+
transform_kind == TransformedRectKind::Complex
1903+
{
1904+
specified_blend_mode
1905+
} else {
1906+
BlendMode::None
1907+
};
1908+
1909+
let batch_params = BrushBatchParameters::shared(
1910+
BrushBatchKind::LinearGradient,
1911+
BatchTextures::no_texture(),
1912+
[
1913+
stops_handle.as_int(gpu_cache),
1914+
0,
1915+
0,
1916+
],
1917+
0,
1918+
);
1919+
1920+
prim_header.specific_prim_address = gpu_cache.get_address(&prim_data.gpu_cache_handle);
1921+
1922+
let prim_header_index = prim_headers.push(
1923+
&prim_header,
1924+
z_id,
1925+
batch_params.prim_user_data,
1926+
);
1927+
1928+
let segments = if brush_segments.is_empty() {
1929+
None
1930+
} else {
1931+
Some(brush_segments.as_slice())
1932+
};
1933+
1934+
self.add_segmented_prim_to_batch(
1935+
segments,
1936+
prim_data.opacity,
1937+
&batch_params,
1938+
specified_blend_mode,
1939+
non_segmented_blend_mode,
1940+
prim_header_index,
1941+
clip_task_address,
1942+
bounding_rect,
1943+
transform_kind,
1944+
render_tasks,
1945+
z_id,
1946+
prim_instance.clip_task_index,
1947+
ctx,
1948+
);
1949+
} else {
1950+
let visible_tiles = &ctx.scratch.gradient_tiles[*visible_tiles_range];
1951+
1952+
add_gradient_tiles(
1953+
visible_tiles,
1954+
stops_handle,
1955+
BrushBatchKind::LinearGradient,
1956+
specified_blend_mode,
1957+
bounding_rect,
1958+
clip_task_address,
1959+
gpu_cache,
1960+
&mut self.batch_list,
1961+
&prim_header,
1962+
prim_headers,
1963+
z_id,
1964+
);
1965+
}
1966+
}
18971967
_ => {
18981968
unreachable!();
18991969
}
@@ -2243,18 +2313,6 @@ impl BrushPrimitive {
22432313
0,
22442314
))
22452315
}
2246-
BrushKind::LinearGradient { ref stops_handle, .. } => {
2247-
Some(BrushBatchParameters::shared(
2248-
BrushBatchKind::LinearGradient,
2249-
BatchTextures::no_texture(),
2250-
[
2251-
stops_handle.as_int(gpu_cache),
2252-
0,
2253-
0,
2254-
],
2255-
0,
2256-
))
2257-
}
22582316
}
22592317
}
22602318
}
@@ -2286,6 +2344,7 @@ impl PrimitiveInstance {
22862344
PrimitiveInstanceKind::NormalBorder { .. } |
22872345
PrimitiveInstanceKind::ImageBorder { .. } |
22882346
PrimitiveInstanceKind::Rectangle { .. } |
2347+
PrimitiveInstanceKind::LinearGradient { .. } |
22892348
PrimitiveInstanceKind::Clear => {
22902349
return true;
22912350
}

0 commit comments

Comments
 (0)