Skip to content

Commit ea8f4a9

Browse files
author
bors-servo
authored
Auto merge of #3353 - gw3583:intern-last-2, r=kvark
Port radial gradients to interning, remove all legacy prim structures. This ports the last legacy primitive to be interned (radial gradients), and removes all old primitive structures. It also removes PrimitiveContainer, which is no longer needed. <!-- 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/3353) <!-- Reviewable:end -->
2 parents 604c69a + 5f88090 commit ea8f4a9

File tree

11 files changed

+474
-833
lines changed

11 files changed

+474
-833
lines changed

webrender/src/batch.rs

+87-124
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use gpu_types::{PrimitiveInstanceData, RasterizationSpace, GlyphInstance};
1515
use gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, TransformPalette};
1616
use internal_types::{FastHashMap, SavedTargetIndex, TextureSource};
1717
use picture::{Picture3DContext, PictureCompositeMode, PicturePrimitive, PictureSurface};
18-
use prim_store::{BrushKind, BrushPrimitive, DeferredResolve, PrimitiveTemplateKind, PrimitiveDataStore};
18+
use prim_store::{DeferredResolve, PrimitiveTemplateKind, PrimitiveDataStore};
1919
use prim_store::{EdgeAaSegmentMask, ImageSource, PrimitiveInstanceKind};
2020
use prim_store::{VisibleGradientTile, PrimitiveInstance, PrimitiveOpacity, SegmentInstanceIndex};
21-
use prim_store::{BrushSegment, ClipMaskKind, ClipTaskIndex, PrimitiveDetails};
21+
use prim_store::{BrushSegment, ClipMaskKind, ClipTaskIndex};
2222
use render_task::{RenderTaskAddress, RenderTaskId, RenderTaskTree};
2323
use renderer::{BlendMode, ImageBufferKind, ShaderColorMode};
2424
use renderer::BLOCKS_PER_UV_RECT;
@@ -902,13 +902,13 @@ impl AlphaBatchBuilder {
902902
PrimitiveInstanceKind::Picture { pic_index } => pic_index,
903903
PrimitiveInstanceKind::LineDecoration { .. } |
904904
PrimitiveInstanceKind::TextRun { .. } |
905-
PrimitiveInstanceKind::LegacyPrimitive { .. } |
906905
PrimitiveInstanceKind::NormalBorder { .. } |
907906
PrimitiveInstanceKind::ImageBorder { .. } |
908907
PrimitiveInstanceKind::Rectangle { .. } |
909908
PrimitiveInstanceKind::YuvImage { .. } |
910909
PrimitiveInstanceKind::Image { .. } |
911910
PrimitiveInstanceKind::LinearGradient { .. } |
911+
PrimitiveInstanceKind::RadialGradient { .. } |
912912
PrimitiveInstanceKind::Clear => {
913913
unreachable!();
914914
}
@@ -1400,104 +1400,6 @@ impl AlphaBatchBuilder {
14001400
}
14011401
}
14021402
}
1403-
(
1404-
PrimitiveInstanceKind::LegacyPrimitive { prim_index },
1405-
PrimitiveTemplateKind::Unused,
1406-
) => {
1407-
let prim = &ctx.prim_store.primitives[prim_index.0];
1408-
1409-
// If the primitive is internally decomposed into multiple sub-primitives we may not
1410-
// use some of the per-primitive data and get it from each sub-primitive instead.
1411-
let is_multiple_primitives = match prim.details {
1412-
PrimitiveDetails::Brush(ref brush) => {
1413-
match brush.kind {
1414-
BrushKind::RadialGradient { visible_tiles_range, .. } => !visible_tiles_range.is_empty(),
1415-
}
1416-
}
1417-
};
1418-
1419-
let specified_blend_mode = BlendMode::PremultipliedAlpha;
1420-
1421-
match prim.details {
1422-
PrimitiveDetails::Brush(ref brush) => {
1423-
let non_segmented_blend_mode = if !brush.opacity.is_opaque ||
1424-
prim_instance.clip_task_index != ClipTaskIndex::INVALID ||
1425-
transform_kind == TransformedRectKind::Complex
1426-
{
1427-
specified_blend_mode
1428-
} else {
1429-
BlendMode::None
1430-
};
1431-
1432-
let prim_cache_address = if is_multiple_primitives {
1433-
GpuCacheAddress::invalid()
1434-
} else {
1435-
gpu_cache.get_address(&brush.gpu_location)
1436-
};
1437-
1438-
let prim_header = PrimitiveHeader {
1439-
local_rect: prim.local_rect,
1440-
local_clip_rect: prim_instance.combined_local_clip_rect,
1441-
task_address,
1442-
specific_prim_address: prim_cache_address,
1443-
clip_task_address,
1444-
transform_id,
1445-
};
1446-
1447-
if prim_instance.is_chased() {
1448-
println!("\ttask target {:?}", self.target_rect);
1449-
println!("\t{:?}", prim_header);
1450-
}
1451-
1452-
match brush.kind {
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-
1456-
add_gradient_tiles(
1457-
visible_tiles,
1458-
stops_handle,
1459-
BrushBatchKind::RadialGradient,
1460-
specified_blend_mode,
1461-
bounding_rect,
1462-
clip_task_address,
1463-
gpu_cache,
1464-
&mut self.batch_list,
1465-
&prim_header,
1466-
prim_headers,
1467-
z_id,
1468-
);
1469-
}
1470-
_ => {
1471-
if let Some(params) = brush.get_batch_params(
1472-
gpu_cache,
1473-
) {
1474-
let prim_header_index = prim_headers.push(&prim_header, z_id, params.prim_user_data);
1475-
if prim_instance.is_chased() {
1476-
println!("\t{:?} {:?}, task relative bounds {:?}",
1477-
params.batch_kind, prim_header_index, bounding_rect);
1478-
}
1479-
1480-
self.add_segmented_prim_to_batch(
1481-
brush.segment_desc.as_ref().map(|desc| desc.segments.as_slice()),
1482-
brush.opacity,
1483-
&params,
1484-
specified_blend_mode,
1485-
non_segmented_blend_mode,
1486-
prim_header_index,
1487-
clip_task_address,
1488-
bounding_rect,
1489-
transform_kind,
1490-
render_tasks,
1491-
z_id,
1492-
prim_instance.clip_task_index,
1493-
ctx,
1494-
);
1495-
}
1496-
}
1497-
}
1498-
}
1499-
}
1500-
}
15011403
(
15021404
PrimitiveInstanceKind::ImageBorder { .. },
15031405
PrimitiveTemplateKind::ImageBorder { request, brush_segments, .. }
@@ -1964,6 +1866,89 @@ impl AlphaBatchBuilder {
19641866
);
19651867
}
19661868
}
1869+
(
1870+
PrimitiveInstanceKind::RadialGradient { visible_tiles_range, .. },
1871+
PrimitiveTemplateKind::RadialGradient { stops_handle, ref brush_segments, .. }
1872+
) => {
1873+
let specified_blend_mode = BlendMode::PremultipliedAlpha;
1874+
1875+
let mut prim_header = PrimitiveHeader {
1876+
local_rect: prim_data.prim_rect,
1877+
local_clip_rect: prim_instance.combined_local_clip_rect,
1878+
task_address,
1879+
specific_prim_address: GpuCacheAddress::invalid(),
1880+
clip_task_address,
1881+
transform_id,
1882+
};
1883+
1884+
if visible_tiles_range.is_empty() {
1885+
let non_segmented_blend_mode = if !prim_data.opacity.is_opaque ||
1886+
prim_instance.clip_task_index != ClipTaskIndex::INVALID ||
1887+
transform_kind == TransformedRectKind::Complex
1888+
{
1889+
specified_blend_mode
1890+
} else {
1891+
BlendMode::None
1892+
};
1893+
1894+
let batch_params = BrushBatchParameters::shared(
1895+
BrushBatchKind::RadialGradient,
1896+
BatchTextures::no_texture(),
1897+
[
1898+
stops_handle.as_int(gpu_cache),
1899+
0,
1900+
0,
1901+
],
1902+
0,
1903+
);
1904+
1905+
prim_header.specific_prim_address = gpu_cache.get_address(&prim_data.gpu_cache_handle);
1906+
1907+
let prim_header_index = prim_headers.push(
1908+
&prim_header,
1909+
z_id,
1910+
batch_params.prim_user_data,
1911+
);
1912+
1913+
let segments = if brush_segments.is_empty() {
1914+
None
1915+
} else {
1916+
Some(brush_segments.as_slice())
1917+
};
1918+
1919+
self.add_segmented_prim_to_batch(
1920+
segments,
1921+
prim_data.opacity,
1922+
&batch_params,
1923+
specified_blend_mode,
1924+
non_segmented_blend_mode,
1925+
prim_header_index,
1926+
clip_task_address,
1927+
bounding_rect,
1928+
transform_kind,
1929+
render_tasks,
1930+
z_id,
1931+
prim_instance.clip_task_index,
1932+
ctx,
1933+
);
1934+
} else {
1935+
let visible_tiles = &ctx.scratch.gradient_tiles[*visible_tiles_range];
1936+
1937+
add_gradient_tiles(
1938+
visible_tiles,
1939+
stops_handle,
1940+
BrushBatchKind::RadialGradient,
1941+
specified_blend_mode,
1942+
bounding_rect,
1943+
clip_task_address,
1944+
gpu_cache,
1945+
&mut self.batch_list,
1946+
&prim_header,
1947+
prim_headers,
1948+
z_id,
1949+
);
1950+
}
1951+
}
19671952
_ => {
19681953
unreachable!();
19691954
}
@@ -2295,28 +2280,6 @@ impl BrushBatchParameters {
22952280
}
22962281
}
22972282

2298-
impl BrushPrimitive {
2299-
fn get_batch_params(
2300-
&self,
2301-
gpu_cache: &mut GpuCache,
2302-
) -> Option<BrushBatchParameters> {
2303-
match self.kind {
2304-
BrushKind::RadialGradient { ref stops_handle, .. } => {
2305-
Some(BrushBatchParameters::shared(
2306-
BrushBatchKind::RadialGradient,
2307-
BatchTextures::no_texture(),
2308-
[
2309-
stops_handle.as_int(gpu_cache),
2310-
0,
2311-
0,
2312-
],
2313-
0,
2314-
))
2315-
}
2316-
}
2317-
}
2318-
}
2319-
23202283
impl PrimitiveInstance {
23212284
pub fn is_cacheable(
23222285
&self,
@@ -2337,14 +2300,14 @@ impl PrimitiveInstance {
23372300
_ => unreachable!(),
23382301
}
23392302
}
2340-
PrimitiveInstanceKind::LegacyPrimitive { .. } |
23412303
PrimitiveInstanceKind::Picture { .. } |
23422304
PrimitiveInstanceKind::TextRun { .. } |
23432305
PrimitiveInstanceKind::LineDecoration { .. } |
23442306
PrimitiveInstanceKind::NormalBorder { .. } |
23452307
PrimitiveInstanceKind::ImageBorder { .. } |
23462308
PrimitiveInstanceKind::Rectangle { .. } |
23472309
PrimitiveInstanceKind::LinearGradient { .. } |
2310+
PrimitiveInstanceKind::RadialGradient { .. } |
23482311
PrimitiveInstanceKind::Clear => {
23492312
return true;
23502313
}

webrender/src/border.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use euclid::vec2;
1111
use display_list_flattener::DisplayListFlattener;
1212
use gpu_types::{BorderInstance, BorderSegment, BrushFlags};
1313
use prim_store::{BorderSegmentInfo, BrushSegment, NinePatchDescriptor};
14-
use prim_store::{EdgeAaSegmentMask, PrimitiveContainer, ScrollNodeAndClipChain};
14+
use prim_store::{EdgeAaSegmentMask, ScrollNodeAndClipChain, PrimitiveKeyKind};
1515
use util::{lerp, RectHelpers};
1616

1717
// Using 2048 as the maximum radius in device space before which we
@@ -117,6 +117,18 @@ pub struct NormalBorderAu {
117117
pub do_aa: bool,
118118
}
119119

120+
impl NormalBorderAu {
121+
// Construct a border based upon self with color
122+
pub fn with_color(&self, color: ColorU) -> Self {
123+
let mut b = self.clone();
124+
b.left.color = color;
125+
b.right.color = color;
126+
b.top.color = color;
127+
b.bottom.color = color;
128+
b
129+
}
130+
}
131+
120132
impl From<NormalBorder> for NormalBorderAu {
121133
fn from(border: NormalBorder) -> Self {
122134
NormalBorderAu {
@@ -217,9 +229,9 @@ impl<'a> DisplayListFlattener<'a> {
217229
clip_and_scroll,
218230
info,
219231
Vec::new(),
220-
PrimitiveContainer::NormalBorder {
221-
border,
222-
widths,
232+
PrimitiveKeyKind::NormalBorder {
233+
border: border.into(),
234+
widths: widths.to_au(),
223235
},
224236
);
225237
}

webrender/src/box_shadow.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use clip::ClipItemKey;
88
use display_list_flattener::DisplayListFlattener;
99
use gpu_cache::GpuCacheHandle;
1010
use gpu_types::BoxShadowStretchMode;
11-
use prim_store::PrimitiveContainer;
12-
use prim_store::ScrollNodeAndClipChain;
11+
use prim_store::{ScrollNodeAndClipChain, PrimitiveKeyKind};
1312
use render_task::RenderTaskCacheEntryHandle;
1413
use util::RectHelpers;
1514

@@ -73,7 +72,7 @@ impl<'a> DisplayListFlattener<'a> {
7372
clip_and_scroll: ScrollNodeAndClipChain,
7473
prim_info: &LayoutPrimitiveInfo,
7574
box_offset: &LayoutVector2D,
76-
color: &ColorF,
75+
color: ColorF,
7776
mut blur_radius: f32,
7877
spread_radius: f32,
7978
border_radius: BorderRadius,
@@ -149,8 +148,8 @@ impl<'a> DisplayListFlattener<'a> {
149148
clip_and_scroll,
150149
&LayoutPrimitiveInfo::with_clip_rect(final_prim_rect, prim_info.clip_rect),
151150
clips,
152-
PrimitiveContainer::Rectangle {
153-
color: *color,
151+
PrimitiveKeyKind::Rectangle {
152+
color: color.into(),
154153
},
155154
);
156155
} else {
@@ -172,8 +171,8 @@ impl<'a> DisplayListFlattener<'a> {
172171

173172
// Draw the box-shadow as a solid rect, using a box-shadow
174173
// clip mask item.
175-
let prim = PrimitiveContainer::Rectangle {
176-
color: *color,
174+
let prim = PrimitiveKeyKind::Rectangle {
175+
color: color.into(),
177176
};
178177

179178
// Create the box-shadow clip item.

0 commit comments

Comments
 (0)