Bug 1520678 - Use macros to reduce boilerplate. r=kamidphish
authorBobby Holley <bobbyholley@gmail.com>
Fri, 18 Jan 2019 00:45:27 +0000
changeset 514375 b79c6b00e3c0e2e8160096c7066e5471019705c7
parent 514374 aa5836f97faf2535d4f579cd798aad0ba620406a
child 514376 32476b4042f7fbcd6c201e03affd8284db01caad
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1520678
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1520678 - Use macros to reduce boilerplate. r=kamidphish Depends on D16779 Differential Revision: https://phabricator.services.mozilla.com/D16780
gfx/wr/webrender/src/profiler.rs
gfx/wr/webrender/src/render_backend.rs
gfx/wr/webrender/src/scene_builder.rs
--- a/gfx/wr/webrender/src/profiler.rs
+++ b/gfx/wr/webrender/src/profiler.rs
@@ -396,31 +396,48 @@ pub struct ResourceProfileCounters {
 pub struct IpcProfileCounters {
     pub build_time: TimeProfileCounter,
     pub consume_time: TimeProfileCounter,
     pub send_time: TimeProfileCounter,
     pub total_time: TimeProfileCounter,
     pub display_lists: ResourceProfileCounter,
 }
 
-#[derive(Clone)]
-pub struct InternProfileCounters {
-    pub prims: ResourceProfileCounter,
-    pub images: ResourceProfileCounter,
-    pub image_borders: ResourceProfileCounter,
-    pub line_decs: ResourceProfileCounter,
-    pub linear_gradients: ResourceProfileCounter,
-    pub normal_borders: ResourceProfileCounter,
-    pub pictures: ResourceProfileCounter,
-    pub radial_gradients: ResourceProfileCounter,
-    pub text_runs: ResourceProfileCounter,
-    pub yuv_images: ResourceProfileCounter,
-    pub clips: ResourceProfileCounter,
+macro_rules! declare_intern_profile_counters {
+    ( $( { $name: ident, $x: ident, $y: ident } )+ ) => {
+        #[derive(Clone)]
+        pub struct InternProfileCounters {
+            $(
+                pub $name: ResourceProfileCounter,
+            )+
+        }
+
+        impl InternProfileCounters {
+            fn draw(
+                &self,
+                debug_renderer: &mut DebugRenderer,
+                draw_state: &mut DrawState,
+            ) {
+                Profiler::draw_counters(
+                    &[
+                        $(
+                            &self.$name,
+                        )+
+                    ],
+                    debug_renderer,
+                    true,
+                    draw_state,
+                );
+            }
+        }
+    }
 }
 
+enumerate_interners!(declare_intern_profile_counters);
+
 impl IpcProfileCounters {
     pub fn set(
         &mut self,
         build_start: u64,
         build_end: u64,
         send_start: u64,
         consume_start: u64,
         consume_end: u64,
@@ -450,27 +467,27 @@ impl BackendProfileCounters {
             ipc: IpcProfileCounters {
                 build_time: TimeProfileCounter::new("Display List Build Time", false),
                 consume_time: TimeProfileCounter::new("Display List Consume Time", false),
                 send_time: TimeProfileCounter::new("Display List Send Time", false),
                 total_time: TimeProfileCounter::new("Total Display List Time", false),
                 display_lists: ResourceProfileCounter::new("Display Lists Sent"),
             },
             intern: InternProfileCounters {
-                prims: ResourceProfileCounter::new("Interned primitives"),
-                images: ResourceProfileCounter::new("Interned images"),
-                image_borders: ResourceProfileCounter::new("Interned image borders"),
-                line_decs: ResourceProfileCounter::new("Interned line decorations"),
-                linear_gradients: ResourceProfileCounter::new("Interned linear gradients"),
-                normal_borders: ResourceProfileCounter::new("Interned normal borders"),
-                pictures: ResourceProfileCounter::new("Interned pictures"),
-                radial_gradients: ResourceProfileCounter::new("Interned radial gradients"),
-                text_runs: ResourceProfileCounter::new("Interned text runs"),
-                yuv_images: ResourceProfileCounter::new("Interned YUV images"),
-                clips: ResourceProfileCounter::new("Interned clips"),
+                prim: ResourceProfileCounter::new("Interned primitives"),
+                image: ResourceProfileCounter::new("Interned images"),
+                image_border: ResourceProfileCounter::new("Interned image borders"),
+                line_decoration: ResourceProfileCounter::new("Interned line decorations"),
+                linear_grad: ResourceProfileCounter::new("Interned linear gradients"),
+                normal_border: ResourceProfileCounter::new("Interned normal borders"),
+                picture: ResourceProfileCounter::new("Interned pictures"),
+                radial_grad: ResourceProfileCounter::new("Interned radial gradients"),
+                text_run: ResourceProfileCounter::new("Interned text runs"),
+                yuv_image: ResourceProfileCounter::new("Interned YUV images"),
+                clip: ResourceProfileCounter::new("Interned clips"),
             },
         }
     }
 
     pub fn reset(&mut self) {
         self.total_time.reset();
         self.ipc.total_time.reset();
         self.ipc.build_time.reset();
@@ -1106,34 +1123,17 @@ impl Profiler {
                 &backend_profile.resources.font_templates,
                 &backend_profile.resources.image_templates,
             ],
             debug_renderer,
             true,
             &mut self.draw_state
         );
 
-        Profiler::draw_counters(
-            &[
-                &backend_profile.intern.clips,
-                &backend_profile.intern.prims,
-                &backend_profile.intern.images,
-                &backend_profile.intern.image_borders,
-                &backend_profile.intern.line_decs,
-                &backend_profile.intern.linear_gradients,
-                &backend_profile.intern.normal_borders,
-                &backend_profile.intern.pictures,
-                &backend_profile.intern.radial_gradients,
-                &backend_profile.intern.text_runs,
-                &backend_profile.intern.yuv_images,
-            ],
-            debug_renderer,
-            true,
-            &mut self.draw_state
-        );
+        backend_profile.intern.draw(debug_renderer, &mut self.draw_state);
 
         Profiler::draw_counters(
             &[
                 &backend_profile.resources.texture_cache.pages_a8_linear,
                 &backend_profile.resources.texture_cache.pages_rgba8_linear,
                 &backend_profile.resources.texture_cache.pages_rgba8_nearest,
                 &backend_profile.ipc.display_lists,
             ],
--- a/gfx/wr/webrender/src/render_backend.rs
+++ b/gfx/wr/webrender/src/render_backend.rs
@@ -223,16 +223,29 @@ macro_rules! declare_frame_resources {
 
         impl FrameResources {
             /// Reports CPU heap usage.
             fn report_memory(&self, ops: &mut MallocSizeOfOps, r: &mut MemoryReport) {
                 $(
                     r.interning.$datastore_ident += self.$datastore_ident.size_of(ops);
                 )+
             }
+
+            fn apply_updates(
+                &mut self,
+                updates: DocumentResourceUpdates,
+                profile_counters: &mut BackendProfileCounters,
+            ) {
+                $(
+                    self.$datastore_ident.apply_updates(
+                        updates.$name,
+                        &mut profile_counters.intern.$name,
+                    );
+                )+
+            }
         }
     }
 }
 
 enumerate_interners!(declare_frame_resources);
 
 impl FrameResources {
     pub fn as_common_data(
@@ -1287,60 +1300,17 @@ impl RenderBackend {
         }
 
         let doc = self.documents.get_mut(&document_id).unwrap();
         doc.has_built_scene |= has_built_scene;
 
         // If there are any additions or removals of clip modes
         // during the scene build, apply them to the data store now.
         if let Some(updates) = doc_resource_updates {
-            doc.resources.clip_data_store.apply_updates(
-                updates.clip_updates,
-                &mut profile_counters.intern.clips,
-            );
-            doc.resources.prim_data_store.apply_updates(
-                updates.prim_updates,
-                &mut profile_counters.intern.prims,
-            );
-            doc.resources.image_data_store.apply_updates(
-                updates.image_updates,
-                &mut profile_counters.intern.images,
-            );
-            doc.resources.image_border_data_store.apply_updates(
-                updates.image_border_updates,
-                &mut profile_counters.intern.image_borders,
-            );
-            doc.resources.line_decoration_data_store.apply_updates(
-                updates.line_decoration_updates,
-                &mut profile_counters.intern.line_decs,
-            );
-            doc.resources.linear_grad_data_store.apply_updates(
-                updates.linear_grad_updates,
-                &mut profile_counters.intern.linear_gradients,
-            );
-            doc.resources.normal_border_data_store.apply_updates(
-                updates.normal_border_updates,
-                &mut profile_counters.intern.normal_borders,
-            );
-            doc.resources.picture_data_store.apply_updates(
-                updates.picture_updates,
-                &mut profile_counters.intern.pictures,
-            );
-            doc.resources.radial_grad_data_store.apply_updates(
-                updates.radial_grad_updates,
-                &mut profile_counters.intern.radial_gradients,
-            );
-            doc.resources.text_run_data_store.apply_updates(
-                updates.text_run_updates,
-                &mut profile_counters.intern.text_runs,
-            );
-            doc.resources.yuv_image_data_store.apply_updates(
-                updates.yuv_image_updates,
-                &mut profile_counters.intern.yuv_images,
-            );
+            doc.resources.apply_updates(updates, profile_counters);
         }
 
         // TODO: this scroll variable doesn't necessarily mean we scrolled. It is only used
         // for something wrench specific and we should remove it.
         let mut scroll = false;
         for frame_msg in frame_ops {
             let _timer = profile_counters.total_time.timer();
             let op = doc.process_frame_msg(frame_msg);
--- a/gfx/wr/webrender/src/scene_builder.rs
+++ b/gfx/wr/webrender/src/scene_builder.rs
@@ -30,30 +30,16 @@ use renderer::{PipelineInfo, SceneBuilde
 use scene::Scene;
 use std::sync::mpsc::{channel, Receiver, Sender};
 use std::mem::replace;
 use time::precise_time_ns;
 use util::drain_filter;
 use std::thread;
 use std::time::Duration;
 
-pub struct DocumentResourceUpdates {
-    pub clip_updates: ::intern_types::clip::UpdateList,
-    pub prim_updates: ::intern_types::prim::UpdateList,
-    pub image_updates: ::intern_types::image::UpdateList,
-    pub image_border_updates: ::intern_types::image_border::UpdateList,
-    pub line_decoration_updates: ::intern_types::line_decoration::UpdateList,
-    pub linear_grad_updates: ::intern_types::linear_grad::UpdateList,
-    pub normal_border_updates: ::intern_types::normal_border::UpdateList,
-    pub picture_updates: ::intern_types::picture::UpdateList,
-    pub radial_grad_updates: ::intern_types::radial_grad::UpdateList,
-    pub text_run_updates: ::intern_types::text_run::UpdateList,
-    pub yuv_image_updates: ::intern_types::yuv_image::UpdateList,
-}
-
 /// Represents the work associated to a transaction before scene building.
 pub struct Transaction {
     pub document_id: DocumentId,
     pub display_list_updates: Vec<DisplayListUpdate>,
     pub removed_pipelines: Vec<PipelineId>,
     pub epoch_updates: Vec<(PipelineId, Epoch)>,
     pub request_scene_build: Option<SceneRequest>,
     pub blob_requests: Vec<BlobImageParams>,
@@ -195,54 +181,68 @@ macro_rules! declare_document_resources 
         #[cfg_attr(feature = "replay", derive(Deserialize))]
         #[derive(Default)]
         pub struct DocumentResources {
             $(
                 pub $interner_ident: intern_types::$name::Interner,
             )+
         }
 
+        pub struct DocumentResourceUpdates {
+            $(
+                pub $name: intern_types::$name::UpdateList,
+            )+
+        }
+
         impl DocumentResources {
             /// Reports CPU heap memory used by the interners.
             fn report_memory(
                 &self,
                 ops: &mut MallocSizeOfOps,
                 r: &mut MemoryReport,
             ) {
                 $(
                     r.interning.$interner_ident += self.$interner_ident.size_of(ops);
                 )+
             }
+
+            fn end_frame_and_get_pending_updates(&mut self) -> DocumentResourceUpdates {
+                DocumentResourceUpdates {
+                    $(
+                        $name: self.$interner_ident.end_frame_and_get_pending_updates(),
+                    )+
+                }
+            }
         }
     }
 }
 
 enumerate_interners!(declare_document_resources);
 
 // Access to `DocumentResources` interners by `Internable`
 pub trait InternerMut<I: Internable>
 {
     fn interner_mut(&mut self) -> &mut Interner<I::Source, I::InternData, I::Marker>;
 }
 
-macro_rules! impl_internet_mut {
+macro_rules! impl_interner_mut {
     ($($ty:ident: $mem:ident,)*) => {
         $(impl InternerMut<$ty> for DocumentResources {
             fn interner_mut(&mut self) -> &mut Interner<
                 <$ty as Internable>::Source,
                 <$ty as Internable>::InternData,
                 <$ty as Internable>::Marker
             > {
                 &mut self.$mem
             }
         })*
     }
 }
 
-impl_internet_mut! {
+impl_interner_mut! {
     Image: image_interner,
     ImageBorder: image_border_interner,
     LineDecoration: line_decoration_interner,
     LinearGradient: linear_grad_interner,
     NormalBorderPrim: normal_border_interner,
     Picture: picture_interner,
     PrimitiveKeyKind: prim_interner,
     RadialGradient: radial_grad_interner,
@@ -410,87 +410,18 @@ impl SceneBuilder {
                     &item.view,
                     &item.output_pipelines,
                     &self.config,
                     &mut new_scene,
                     &mut item.doc_resources,
                     &PrimitiveStoreStats::empty(),
                 );
 
-                // TODO(djg): Can we do better than this?  Use a #[derive] to
-                // write the code for us, or unify updates into one enum/list?
-                let clip_updates = item
-                    .doc_resources
-                    .clip_interner
-                    .end_frame_and_get_pending_updates();
-
-                let prim_updates = item
-                    .doc_resources
-                    .prim_interner
-                    .end_frame_and_get_pending_updates();
-
-                let image_updates = item
-                    .doc_resources
-                    .image_interner
-                    .end_frame_and_get_pending_updates();
-
-                let image_border_updates = item
-                    .doc_resources
-                    .image_border_interner
-                    .end_frame_and_get_pending_updates();
-
-                let line_decoration_updates = item
-                    .doc_resources
-                    .line_decoration_interner
-                    .end_frame_and_get_pending_updates();
-
-                let linear_grad_updates = item
-                    .doc_resources
-                    .linear_grad_interner
-                    .end_frame_and_get_pending_updates();
-
-                let normal_border_updates = item
-                    .doc_resources
-                    .normal_border_interner
-                    .end_frame_and_get_pending_updates();
-
-                let picture_updates = item
-                    .doc_resources
-                    .picture_interner
-                    .end_frame_and_get_pending_updates();
-
-                let radial_grad_updates = item
-                    .doc_resources
-                    .radial_grad_interner
-                    .end_frame_and_get_pending_updates();
-
-                let text_run_updates = item
-                    .doc_resources
-                    .text_run_interner
-                    .end_frame_and_get_pending_updates();
-
-                let yuv_image_updates = item
-                    .doc_resources
-                    .yuv_image_interner
-                    .end_frame_and_get_pending_updates();
-
                 doc_resource_updates = Some(
-                    DocumentResourceUpdates {
-                        clip_updates,
-                        prim_updates,
-                        image_updates,
-                        image_border_updates,
-                        line_decoration_updates,
-                        linear_grad_updates,
-                        normal_border_updates,
-                        picture_updates,
-                        radial_grad_updates,
-                        text_run_updates,
-                        yuv_image_updates,
-                    }
+                    item.doc_resources.end_frame_and_get_pending_updates()
                 );
 
                 built_scene = Some(BuiltScene {
                     scene: new_scene,
                     frame_builder,
                     clip_scroll_tree,
                 });
             }
@@ -578,85 +509,18 @@ impl SceneBuilder {
                     &mut doc.resources,
                     &doc.prim_store_stats,
                 );
 
                 // Update the allocation stats for next scene
                 doc.prim_store_stats = frame_builder.prim_store.get_stats();
 
                 // Retrieve the list of updates from the clip interner.
-                let clip_updates = doc
-                    .resources
-                    .clip_interner
-                    .end_frame_and_get_pending_updates();
-
-                let prim_updates = doc
-                    .resources
-                    .prim_interner
-                    .end_frame_and_get_pending_updates();
-
-                let image_updates = doc
-                    .resources
-                    .image_interner
-                    .end_frame_and_get_pending_updates();
-
-                let image_border_updates = doc
-                    .resources
-                    .image_border_interner
-                    .end_frame_and_get_pending_updates();
-
-                let line_decoration_updates = doc
-                    .resources
-                    .line_decoration_interner
-                    .end_frame_and_get_pending_updates();
-
-                let linear_grad_updates = doc
-                    .resources
-                    .linear_grad_interner
-                    .end_frame_and_get_pending_updates();
-
-                let normal_border_updates = doc
-                    .resources
-                    .normal_border_interner
-                    .end_frame_and_get_pending_updates();
-
-                let picture_updates = doc
-                    .resources
-                    .picture_interner
-                    .end_frame_and_get_pending_updates();
-
-                let radial_grad_updates = doc
-                    .resources
-                    .radial_grad_interner
-                    .end_frame_and_get_pending_updates();
-
-                let text_run_updates = doc
-                    .resources
-                    .text_run_interner
-                    .end_frame_and_get_pending_updates();
-
-                let yuv_image_updates = doc
-                    .resources
-                    .yuv_image_interner
-                    .end_frame_and_get_pending_updates();
-
                 doc_resource_updates = Some(
-                    DocumentResourceUpdates {
-                        clip_updates,
-                        prim_updates,
-                        image_updates,
-                        image_border_updates,
-                        line_decoration_updates,
-                        linear_grad_updates,
-                        normal_border_updates,
-                        picture_updates,
-                        radial_grad_updates,
-                        text_run_updates,
-                        yuv_image_updates,
-                    }
+                    doc.resources.end_frame_and_get_pending_updates()
                 );
 
                 built_scene = Some(BuiltScene {
                     scene: new_scene,
                     frame_builder,
                     clip_scroll_tree,
                 });
             }