Skip to content

Commit 45b7a89

Browse files
authored
Add feature gates to reduce binary size (#562)
* add feature gates for d3d9, d3d11, ui and debug * don't ship resources that are not needed * fix errors from resource builder
1 parent 6ef6ccb commit 45b7a89

14 files changed

+291
-144
lines changed

renderer/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ license = "MIT OR Apache-2.0"
88
repository = "https://github.com/servo/pathfinder"
99
homepage = "https://github.com/servo/pathfinder"
1010

11+
[features]
12+
d3d9 = []
13+
d3d11 = []
14+
ui = ["pathfinder_ui", "debug"]
15+
debug = []
16+
default = ["d3d9", "d3d11", "ui"]
17+
1118
[dependencies]
1219
bitflags = "1.0"
1320
byte-slice-cast = "0.3"
@@ -54,6 +61,7 @@ version = "0.5"
5461
[dependencies.pathfinder_ui]
5562
path = "../ui"
5663
version = "0.5"
64+
optional = true
5765

5866
[dev-dependencies]
5967
quickcheck = "0.9"

renderer/src/builder.rs

+56-23
Original file line numberDiff line numberDiff line change
@@ -186,29 +186,33 @@ impl<'a, 'b, 'c, 'd> SceneBuilder<'a, 'b, 'c, 'd> {
186186
PrepareMode::GPU { .. } => None,
187187
};
188188

189-
// TODO(pcwalton): Do this earlier?
190-
let scene_is_dirty = match (&prepare_mode, &self.sink.last_scene) {
191-
(&PrepareMode::GPU { .. }, &None) => true,
192-
(&PrepareMode::GPU { .. }, &Some(LastSceneInfo {
193-
scene_id: ref last_scene_id,
194-
scene_epoch: ref last_scene_epoch,
195-
..
196-
})) => *last_scene_id != self.scene.id() || *last_scene_epoch != self.scene.epoch(),
197-
_ => false,
198-
};
199189

200-
if scene_is_dirty {
201-
let built_segments = BuiltSegments::from_scene(&self.scene);
202-
self.sink.listener.send(RenderCommand::UploadSceneD3D11 {
203-
draw_segments: built_segments.draw_segments,
204-
clip_segments: built_segments.clip_segments,
205-
});
206-
self.sink.last_scene = Some(LastSceneInfo {
207-
scene_id: self.scene.id(),
208-
scene_epoch: self.scene.epoch(),
209-
draw_segment_ranges: built_segments.draw_segment_ranges,
210-
clip_segment_ranges: built_segments.clip_segment_ranges,
211-
});
190+
#[cfg(feature="d3d11")]
191+
{
192+
// TODO(pcwalton): Do this earlier?
193+
let scene_is_dirty = match (&prepare_mode, &self.sink.last_scene) {
194+
(&PrepareMode::GPU { .. }, &None) => true,
195+
(&PrepareMode::GPU { .. }, &Some(LastSceneInfo {
196+
scene_id: ref last_scene_id,
197+
scene_epoch: ref last_scene_epoch,
198+
..
199+
})) => *last_scene_id != self.scene.id() || *last_scene_epoch != self.scene.epoch(),
200+
_ => false,
201+
};
202+
203+
if scene_is_dirty {
204+
let built_segments = BuiltSegments::from_scene(&self.scene);
205+
self.sink.listener.send(RenderCommand::UploadSceneD3D11 {
206+
draw_segments: built_segments.draw_segments,
207+
clip_segments: built_segments.clip_segments,
208+
});
209+
self.sink.last_scene = Some(LastSceneInfo {
210+
scene_id: self.scene.id(),
211+
scene_epoch: self.scene.epoch(),
212+
draw_segment_ranges: built_segments.draw_segment_ranges,
213+
clip_segment_ranges: built_segments.clip_segment_ranges,
214+
});
215+
}
212216
}
213217

214218
self.finish_building(&paint_metadata, built_paths, &prepare_mode);
@@ -314,6 +318,7 @@ impl<'a, 'b, 'c, 'd> SceneBuilder<'a, 'b, 'c, 'd> {
314318
}
315319

316320
fn send_fills(&self, fills: Vec<Fill>) {
321+
#[cfg(feature="d3d9")]
317322
if !fills.is_empty() {
318323
self.sink.listener.send(RenderCommand::AddFillsD3D9(fills));
319324
}
@@ -356,8 +361,9 @@ impl<'a, 'b, 'c, 'd> SceneBuilder<'a, 'b, 'c, 'd> {
356361
built_paths: Option<BuiltPaths>,
357362
prepare_mode: &PrepareMode) {
358363
match self.sink.renderer_level {
364+
#[cfg(feature="d3d9")]
359365
RendererLevel::D3D9 => self.sink.listener.send(RenderCommand::FlushFillsD3D9),
360-
RendererLevel::D3D11 => {}
366+
_ => {}
361367
}
362368

363369
self.build_tile_batches(paint_metadata, prepare_mode, built_paths);
@@ -837,13 +843,16 @@ impl SegmentsD3D11 {
837843
struct TileBatchBuilder {
838844
prepare_commands: Vec<RenderCommand>,
839845
draw_commands: Vec<RenderCommand>,
846+
#[cfg(feature="d3d11")]
840847
clip_batches_d3d11: Option<ClipBatchesD3D11>,
841848
next_batch_id: TileBatchId,
842849
level: TileBatchBuilderLevel,
843850
}
844851

845852
enum TileBatchBuilderLevel {
853+
#[cfg(feature="d3d9")]
846854
D3D9 { built_paths: BuiltPaths },
855+
#[cfg(feature="d3d11")]
847856
D3D11,
848857
}
849858

@@ -853,6 +862,7 @@ impl TileBatchBuilder {
853862
prepare_commands: vec![],
854863
draw_commands: vec![],
855864
next_batch_id: TileBatchId(MAX_CLIP_BATCHES),
865+
#[cfg(feature="d3d11")]
856866
clip_batches_d3d11: match built_paths {
857867
None => {
858868
Some(ClipBatchesD3D11 {
@@ -863,8 +873,12 @@ impl TileBatchBuilder {
863873
Some(_) => None,
864874
},
865875
level: match built_paths {
876+
#[cfg(feature="d3d11")]
866877
None => TileBatchBuilderLevel::D3D11,
878+
#[cfg(feature="d3d9")]
867879
Some(built_paths) => TileBatchBuilderLevel::D3D9 { built_paths },
880+
#[allow(unreachable_patterns)]
881+
_ => unreachable!()
868882
},
869883
}
870884
}
@@ -880,6 +894,7 @@ impl TileBatchBuilder {
880894
for draw_path_id in draw_path_id_range.start.0..draw_path_id_range.end.0 {
881895
let draw_path_id = DrawPathId(draw_path_id);
882896
let draw_path = match self.level {
897+
#[cfg(feature="d3d11")]
883898
TileBatchBuilderLevel::D3D11 { .. } => {
884899
match self.prepare_draw_path_for_gpu_binning(scene,
885900
built_options,
@@ -890,17 +905,20 @@ impl TileBatchBuilder {
890905
Some(built_draw_path) => Cow::Owned(built_draw_path),
891906
}
892907
}
908+
#[cfg(feature="d3d9")]
893909
TileBatchBuilderLevel::D3D9 { ref built_paths } => {
894910
Cow::Borrowed(&built_paths.draw[draw_path_id.0 as usize])
895911
}
896912
};
897913

898914
// Try to reuse the current batch if we can.
899915
let flush_needed = match draw_tile_batch {
916+
#[cfg(feature="d3d11")]
900917
Some(DrawTileBatch::D3D11(ref mut existing_batch)) => {
901918
!fixup_batch_for_new_path_if_possible(&mut existing_batch.color_texture,
902919
&draw_path)
903920
}
921+
#[cfg(feature="d3d9")]
904922
Some(DrawTileBatch::D3D9(ref mut existing_batch)) => {
905923
!fixup_batch_for_new_path_if_possible(&mut existing_batch.color_texture,
906924
&draw_path)
@@ -911,9 +929,11 @@ impl TileBatchBuilder {
911929
// If we couldn't reuse the batch, flush it.
912930
if flush_needed {
913931
match draw_tile_batch.take() {
932+
#[cfg(feature="d3d11")]
914933
Some(DrawTileBatch::D3D11(batch_to_flush)) => {
915934
self.draw_commands.push(RenderCommand::DrawTilesD3D11(batch_to_flush));
916935
}
936+
#[cfg(feature="d3d9")]
917937
Some(DrawTileBatch::D3D9(batch_to_flush)) => {
918938
self.draw_commands.push(RenderCommand::DrawTilesD3D9(batch_to_flush));
919939
}
@@ -924,6 +944,7 @@ impl TileBatchBuilder {
924944
// Create a new batch if necessary.
925945
if draw_tile_batch.is_none() {
926946
draw_tile_batch = match self.level {
947+
#[cfg(feature="d3d9")]
927948
TileBatchBuilderLevel::D3D9 { .. } => {
928949
let tile_bounds = tiles::round_rect_out_to_tile_bounds(scene.view_box());
929950
Some(DrawTileBatch::D3D9(DrawTileBatchD3D9 {
@@ -935,6 +956,7 @@ impl TileBatchBuilder {
935956
blend_mode: draw_path.blend_mode,
936957
}))
937958
}
959+
#[cfg(feature="d3d11")]
938960
TileBatchBuilderLevel::D3D11 { .. } => {
939961
Some(DrawTileBatch::D3D11(DrawTileBatchD3D11 {
940962
tile_batch_data: TileBatchDataD3D11::new(self.next_batch_id,
@@ -948,6 +970,7 @@ impl TileBatchBuilder {
948970
}
949971

950972
// Add clip path if necessary.
973+
#[cfg(feature="d3d11")]
951974
let clip_path = match self.clip_batches_d3d11 {
952975
None => None,
953976
Some(ref mut clip_batches_d3d11) => {
@@ -963,16 +986,20 @@ impl TileBatchBuilder {
963986

964987
let draw_tile_batch = draw_tile_batch.as_mut().unwrap();
965988
match *draw_tile_batch {
989+
#[cfg(feature="d3d11")]
966990
DrawTileBatch::D3D11(ref mut draw_tile_batch) => {
967991
draw_tile_batch.tile_batch_data.push(&draw_path.path,
968992
draw_path_id.to_path_id(),
969993
clip_path,
970994
draw_path.occludes,
971995
sink);
972996
}
997+
#[cfg(feature="d3d9")]
973998
DrawTileBatch::D3D9(ref mut draw_tile_batch) => {
974999
let built_paths = match self.level {
1000+
#[cfg(feature="d3d9")]
9751001
TileBatchBuilderLevel::D3D9 { ref built_paths } => built_paths,
1002+
#[cfg(feature="d3d11")]
9761003
TileBatchBuilderLevel::D3D11 { .. } => unreachable!(),
9771004
};
9781005

@@ -1016,9 +1043,11 @@ impl TileBatchBuilder {
10161043
}
10171044

10181045
match draw_tile_batch {
1046+
#[cfg(feature="d3d11")]
10191047
Some(DrawTileBatch::D3D11(draw_tile_batch)) => {
10201048
self.draw_commands.push(RenderCommand::DrawTilesD3D11(draw_tile_batch));
10211049
}
1050+
#[cfg(feature="d3d9")]
10221051
Some(DrawTileBatch::D3D9(draw_tile_batch)) => {
10231052
self.draw_commands.push(RenderCommand::DrawTilesD3D9(draw_tile_batch));
10241053
}
@@ -1066,6 +1095,7 @@ impl TileBatchBuilder {
10661095
}
10671096

10681097
fn send_to(self, sink: &SceneSink) {
1098+
#[cfg(feature="d3d11")]
10691099
if let Some(clip_batches_d3d11) = self.clip_batches_d3d11 {
10701100
for prepare_batch in clip_batches_d3d11.prepare_batches.into_iter().rev() {
10711101
if prepare_batch.path_count > 0 {
@@ -1083,12 +1113,14 @@ impl TileBatchBuilder {
10831113
}
10841114
}
10851115

1116+
#[cfg(feature="d3d11")]
10861117
struct ClipBatchesD3D11 {
10871118
// Will be submitted in reverse (LIFO) order.
10881119
prepare_batches: Vec<TileBatchDataD3D11>,
10891120
clip_id_to_path_batch_index: FxHashMap<ClipPathId, PathBatchIndex>,
10901121
}
10911122

1123+
#[cfg(feature="d3d11")]
10921124
fn add_clip_path_to_batch(scene: &Scene,
10931125
sink: &SceneSink,
10941126
built_options: &PreparedBuildOptions,
@@ -1145,6 +1177,7 @@ fn add_clip_path_to_batch(scene: &Scene,
11451177
}
11461178
}
11471179

1180+
#[cfg(feature="d3d11")]
11481181
fn prepare_clip_path_for_gpu_binning(scene: &Scene,
11491182
sink: &SceneSink,
11501183
built_options: &PreparedBuildOptions,

renderer/src/gpu/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
//! The GPU renderer for Pathfinder 3.
1212
13+
#[cfg(feature="d3d9")]
1314
pub mod d3d9;
15+
#[cfg(feature="d3d11")]
1416
pub mod d3d11;
17+
#[cfg(feature="debug")]
1518
pub mod debug;
1619
pub mod options;
1720
pub mod perf;

0 commit comments

Comments
 (0)