Bug 1587713 - Remove the late blob rasterization code. r=jrmuizel
authorNicolas Silva <nsilva@mozilla.com>
Thu, 16 Apr 2020 20:13:24 +0000
changeset 524486 aff8eef07d078b20be9c4b7d6dfb689998fb11fa
parent 524485 100387beceed5894fa594a07845a149cbddfb1b8
child 524487 65951cbe72774d0c2151f5d4b34c0ccbe6316ddb
push id37321
push userdluca@mozilla.com
push dateFri, 17 Apr 2020 09:38:52 +0000
treeherdermozilla-central@24537fed53e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1587713
milestone77.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 1587713 - Remove the late blob rasterization code. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D49186
gfx/wr/webrender/src/render_backend.rs
gfx/wr/webrender/src/resource_cache.rs
gfx/wr/webrender/src/scene_builder_thread.rs
gfx/wr/webrender_api/src/api.rs
--- a/gfx/wr/webrender/src/render_backend.rs
+++ b/gfx/wr/webrender/src/render_backend.rs
@@ -1000,19 +1000,16 @@ impl RenderBackend {
                                 }
                                 continue;
                             }
 
                             self.resource_cache.add_rasterized_blob_images(
                                 txn.rasterized_blobs.take(),
                                 &mut profile_counters.resources.texture_cache,
                             );
-                            if let Some((rasterizer, info)) = txn.blob_rasterizer.take() {
-                                self.resource_cache.set_blob_rasterizer(rasterizer, info);
-                            }
 
                             self.update_document(
                                 txn.document_id,
                                 txn.resource_updates.take(),
                                 txn.frame_ops.take(),
                                 txn.notifications.take(),
                                 txn.render_frame,
                                 txn.invalidate_rendered_frame,
--- a/gfx/wr/webrender/src/resource_cache.rs
+++ b/gfx/wr/webrender/src/resource_cache.rs
@@ -440,36 +440,16 @@ impl BlobImageResources for Resources {
 // We only use this to report glyph dimensions to the user of the API, so using
 // the font instance key should be enough. If we start using it to cache dimensions
 // for internal font instances we should change the hash key accordingly.
 pub type GlyphDimensionsCache = FastHashMap<(FontInstanceKey, GlyphIndex), Option<GlyphDimensions>>;
 
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub struct BlobImageRasterizerEpoch(usize);
 
-/// Stores parameters for clearing blob image tiles.
-///
-/// TODO(nical) this can be removed.
-#[derive(Clone, Copy, Debug)]
-pub struct BlobImageClearParams {
-    pub key: BlobImageKey,
-    /// Originally requested tile range to rasterize.
-    pub original_tile_range: TileRange,
-    /// Actual tile range that is requested to rasterize by
-    /// AsyncBlobImageRasterizer.
-    pub actual_tile_range: TileRange,
-}
-
-/// Information attached to AsyncBlobImageRasterizer.
-#[derive(Clone, Debug)]
-pub struct AsyncBlobImageInfo {
-    pub epoch: BlobImageRasterizerEpoch,
-    pub clear_requests: Vec<BlobImageClearParams>,
-}
-
 /// High-level container for resources managed by the `RenderBackend`.
 ///
 /// This includes a variety of things, including images, fonts, and glyphs,
 /// which may be stored as memory buffers, GPU textures, or handles to resources
 /// managed by the OS or other parts of WebRender.
 pub struct ResourceCache {
     cached_glyphs: GlyphCache,
     cached_images: ImageCache,
@@ -489,30 +469,16 @@ pub struct ResourceCache {
     /// and need to be rasterized and/or uploaded this frame. This includes
     /// both blobs and regular images.
     pending_image_requests: FastHashSet<ImageRequest>,
 
     blob_image_handler: Option<Box<dyn BlobImageHandler>>,
     rasterized_blob_images: FastHashMap<BlobImageKey, RasterizedBlob>,
     blob_image_templates: FastHashMap<BlobImageKey, BlobImageTemplate>,
 
-    /// If while building a frame we encounter blobs that we didn't already
-    /// rasterize, add them to this list and rasterize them synchronously.
-    missing_blob_images: Vec<BlobImageParams>,
-    /// The rasterizer associated with the current scene.
-    blob_image_rasterizer: Option<Box<dyn AsyncBlobImageRasterizer>>,
-    /// An epoch of the stored blob image rasterizer, used to skip the ones
-    /// coming from low-priority scene builds if the current one is newer.
-    /// This is to be removed when we get rid of the whole "missed" blob
-    /// images concept.
-    /// The produced one gets bumped whenever we produce a rasteriezer,
-    /// which then travels through the scene building and eventually gets
-    /// consumed back by us, bumping the consumed epoch.
-    blob_image_rasterizer_produced_epoch: BlobImageRasterizerEpoch,
-    blob_image_rasterizer_consumed_epoch: BlobImageRasterizerEpoch,
     /// A log of the last three frames worth of deleted image keys kept
     /// for debugging purposes.
     deleted_blob_keys: VecDeque<Vec<BlobImageKey>>,
 
     /// A list of queued compositor surface updates to apply next frame.
     pending_native_surface_updates: Vec<NativeSurfaceOperation>,
 }
 
@@ -532,20 +498,16 @@ impl ResourceCache {
             texture_cache,
             state: State::Idle,
             current_frame_id: FrameId::INVALID,
             pending_image_requests: FastHashSet::default(),
             glyph_rasterizer,
             blob_image_handler,
             rasterized_blob_images: FastHashMap::default(),
             blob_image_templates: FastHashMap::default(),
-            missing_blob_images: Vec::new(),
-            blob_image_rasterizer: None,
-            blob_image_rasterizer_produced_epoch: BlobImageRasterizerEpoch(0),
-            blob_image_rasterizer_consumed_epoch: BlobImageRasterizerEpoch(0),
             // We want to keep three frames worth of delete blob keys
             deleted_blob_keys: vec![Vec::new(), Vec::new(), Vec::new()].into(),
             pending_native_surface_updates: Vec::new(),
         }
     }
 
     pub fn max_texture_size(&self) -> i32 {
         self.texture_cache.max_texture_size()
@@ -729,26 +691,16 @@ impl ResourceCache {
                         instance.variations,
                     );
                 }
                 _ => { unreachable!(); }
             }
         );
     }
 
-    pub fn set_blob_rasterizer(
-        &mut self, rasterizer: Box<dyn AsyncBlobImageRasterizer>,
-        supp: AsyncBlobImageInfo,
-    ) {
-        if self.blob_image_rasterizer_consumed_epoch.0 < supp.epoch.0 {
-            self.blob_image_rasterizer = Some(rasterizer);
-            self.blob_image_rasterizer_consumed_epoch = supp.epoch;
-        }
-    }
-
     pub fn add_rasterized_blob_images(
         &mut self,
         images: Vec<(BlobImageRequest, BlobImageResult)>,
         texture_cache_profile: &mut TextureCacheProfileCounters,
     ) {
         for (request, result) in images {
             let data = match result {
                 Ok(data) => data,
@@ -1154,55 +1106,24 @@ impl ResourceCache {
 
         if template.data.is_blob() {
             let request: BlobImageRequest = request.into();
             let missing = match self.rasterized_blob_images.get(&request.key) {
                 Some(tiles) => !tiles.contains_key(&request.tile),
                 _ => true,
             };
 
-            // For some reason the blob image is missing. We'll fall back to
-            // rasterizing it on the render backend thread.
-            if missing {
-                let descriptor = BlobImageDescriptor {
-                    rect: match template.tiling {
-                        Some(tile_size) => {
-                            let tile = request.tile;
-                            blob_rect(compute_tile_rect(
-                                &template.visible_rect,
-                                tile_size,
-                                tile,
-                            ))
-                        }
-                        None => blob_size(template.visible_rect.size).into(),
-                    },
-                    format: template.descriptor.format,
-                };
-
-                assert!(!descriptor.rect.is_empty());
-
-                if !self.blob_image_templates.contains_key(&request.key) {
-                    panic!("already missing blob image key {:?} deleted: {:?}", request, self.deleted_blob_keys);
-                }
-
-                self.missing_blob_images.push(
-                    BlobImageParams {
-                        request,
-                        descriptor,
-                        dirty_rect: DirtyRect::All,
-                    }
-                );
-            }
+            assert!(!missing);
         }
     }
 
     pub fn create_blob_scene_builder_requests(
         &mut self,
         keys: &[BlobImageKey]
-    ) -> (Option<(Box<dyn AsyncBlobImageRasterizer>, AsyncBlobImageInfo)>, Vec<BlobImageParams>) {
+    ) -> (Option<Box<dyn AsyncBlobImageRasterizer>>, Vec<BlobImageParams>) {
         if self.blob_image_handler.is_none() || keys.is_empty() {
             return (None, Vec::new());
         }
 
         let mut blob_request_params = Vec::new();
         for key in keys {
             let template = self.blob_image_templates.get_mut(key).unwrap();
 
@@ -1264,24 +1185,20 @@ impl ResourceCache {
                         descriptor,
                         dirty_rect: DirtyRect::All,
                     }
                 );
             });
 
             template.valid_tiles_after_bounds_change = None;
         }
-        self.blob_image_rasterizer_produced_epoch.0 += 1;
-        let info = AsyncBlobImageInfo {
-            epoch: self.blob_image_rasterizer_produced_epoch,
-            clear_requests: Vec::new(),
-        };
+
         let handler = self.blob_image_handler.as_mut().unwrap();
         handler.prepare_resources(&self.resources, &blob_request_params);
-        (Some((handler.create_blob_rasterizer(), info)), blob_request_params)
+        (Some(handler.create_blob_rasterizer()), blob_request_params)
     }
 
     fn discard_tiles_outside_visible_area(
         &mut self,
         key: BlobImageKey,
         area: &DeviceIntRect
     ) {
         let template = match self.blob_image_templates.get(&key) {
@@ -1517,52 +1434,20 @@ impl ResourceCache {
             &mut self.cached_glyphs,
             &mut self.texture_cache,
             gpu_cache,
             &mut self.cached_render_tasks,
             render_tasks,
             texture_cache_profile,
         );
 
-        self.rasterize_missing_blob_images(texture_cache_profile);
-
         // Apply any updates of new / updated images (incl. blobs) to the texture cache.
         self.update_texture_cache(gpu_cache);
     }
 
-    fn rasterize_missing_blob_images(
-        &mut self,
-        texture_cache_profile: &mut TextureCacheProfileCounters,
-    ) {
-        if self.missing_blob_images.is_empty() {
-            return;
-        }
-
-        self.blob_image_handler
-            .as_mut()
-            .unwrap()
-            .prepare_resources(&self.resources, &self.missing_blob_images);
-
-
-        for blob_image in &self.missing_blob_images {
-            if !self.blob_image_templates.contains_key(&blob_image.request.key) {
-                panic!("missing blob image key {:?} deleted: {:?}", blob_image, self.deleted_blob_keys);
-            }
-        }
-        let is_low_priority = false;
-        let rasterized_blobs = self.blob_image_rasterizer
-            .as_mut()
-            .unwrap()
-            .rasterize(&self.missing_blob_images, is_low_priority);
-
-        self.add_rasterized_blob_images(rasterized_blobs, texture_cache_profile);
-
-        self.missing_blob_images.clear();
-    }
-
     fn update_texture_cache(&mut self, gpu_cache: &mut GpuCache) {
         for request in self.pending_image_requests.drain() {
             let image_template = self.resources.image_templates.get_mut(request.key).unwrap();
             debug_assert!(image_template.data.uses_texture_cache());
 
             let mut updates: SmallVec<[(CachedImageData, Option<DeviceIntRect>); 1]> = SmallVec::new();
 
             match image_template.data {
@@ -1761,19 +1646,16 @@ impl ResourceCache {
             self.cached_glyph_dimensions.clear();
         }
         if what.contains(ClearCache::RENDER_TASKS) {
             self.cached_render_tasks.clear();
         }
         if what.contains(ClearCache::TEXTURE_CACHE) {
             self.texture_cache.clear_all();
         }
-        if what.contains(ClearCache::RASTERIZED_BLOBS) {
-            self.rasterized_blob_images.clear();
-        }
     }
 
     pub fn clear_namespace(&mut self, namespace: IdNamespace) {
         self.clear_images(|k| k.0 == namespace);
 
         self.resources.font_instances
             .write()
             .unwrap()
--- a/gfx/wr/webrender/src/scene_builder_thread.rs
+++ b/gfx/wr/webrender/src/scene_builder_thread.rs
@@ -16,17 +16,17 @@ use crate::internal_types::{FastHashMap,
 use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
 use crate::prim_store::backdrop::Backdrop;
 use crate::prim_store::borders::{ImageBorder, NormalBorderPrim};
 use crate::prim_store::gradient::{LinearGradient, RadialGradient, ConicGradient};
 use crate::prim_store::image::{Image, YuvImage};
 use crate::prim_store::line_dec::LineDecoration;
 use crate::prim_store::picture::Picture;
 use crate::prim_store::text_run::TextRun;
-use crate::resource_cache::{AsyncBlobImageInfo, FontInstanceMap};
+use crate::resource_cache::FontInstanceMap;
 use crate::render_backend::DocumentView;
 use crate::renderer::{PipelineInfo, SceneBuilderHooks};
 use crate::scene::{Scene, BuiltScene, SceneStats};
 use std::iter;
 use std::sync::mpsc::{channel, Receiver, Sender};
 use std::mem::replace;
 use time::precise_time_ns;
 use crate::util::drain_filter;
@@ -53,17 +53,17 @@ pub struct TransactionTimings {
 /// 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, DocumentId)>,
     pub epoch_updates: Vec<(PipelineId, Epoch)>,
     pub request_scene_build: Option<SceneRequest>,
     pub blob_requests: Vec<BlobImageParams>,
-    pub blob_rasterizer: Option<(Box<dyn AsyncBlobImageRasterizer>, AsyncBlobImageInfo)>,
+    pub blob_rasterizer: Option<Box<dyn AsyncBlobImageRasterizer>>,
     pub rasterized_blobs: Vec<(BlobImageRequest, BlobImageResult)>,
     pub resource_updates: Vec<ResourceUpdate>,
     pub frame_ops: Vec<FrameMsg>,
     pub notifications: Vec<NotificationRequest>,
     pub set_root_pipeline: Option<PipelineId>,
     pub render_frame: bool,
     pub invalidate_rendered_frame: bool,
 }
@@ -79,17 +79,17 @@ impl Transaction {
     }
 
     pub fn should_build_scene(&self) -> bool {
         !self.display_list_updates.is_empty() ||
             self.set_root_pipeline.is_some()
     }
 
     fn rasterize_blobs(&mut self, is_low_priority: bool) {
-        if let Some((ref mut rasterizer, _)) = self.blob_rasterizer {
+        if let Some(ref mut rasterizer) = self.blob_rasterizer {
             let mut rasterized_blobs = rasterizer.rasterize(&self.blob_requests, is_low_priority);
             // try using the existing allocation if our current list is empty
             if self.rasterized_blobs.is_empty() {
                 self.rasterized_blobs = rasterized_blobs;
             } else {
                 self.rasterized_blobs.append(&mut rasterized_blobs);
             }
         }
@@ -98,17 +98,17 @@ impl Transaction {
 
 /// Represent the remaining work associated to a transaction after the scene building
 /// phase as well as the result of scene building itself if applicable.
 pub struct BuiltTransaction {
     pub document_id: DocumentId,
     pub built_scene: Option<BuiltScene>,
     pub resource_updates: Vec<ResourceUpdate>,
     pub rasterized_blobs: Vec<(BlobImageRequest, BlobImageResult)>,
-    pub blob_rasterizer: Option<(Box<dyn AsyncBlobImageRasterizer>, AsyncBlobImageInfo)>,
+    pub blob_rasterizer: Option<Box<dyn AsyncBlobImageRasterizer>>,
     pub frame_ops: Vec<FrameMsg>,
     pub removed_pipelines: Vec<(PipelineId, DocumentId)>,
     pub notifications: Vec<NotificationRequest>,
     pub interner_updates: Option<InternerUpdates>,
     pub scene_build_start_time: u64,
     pub scene_build_end_time: u64,
     pub render_frame: bool,
     pub invalidate_rendered_frame: bool,
--- a/gfx/wr/webrender_api/src/api.rs
+++ b/gfx/wr/webrender_api/src/api.rs
@@ -925,18 +925,16 @@ bitflags!{
         ///
         const GLYPHS = 0b01;
         ///
         const GLYPH_DIMENSIONS = 0b001;
         ///
         const RENDER_TASKS = 0b0001;
         ///
         const TEXTURE_CACHE = 0b00001;
-        ///
-        const RASTERIZED_BLOBS = 0b000001;
     }
 }
 
 /// Information about a loaded capture of each document
 /// that is returned by `RenderBackend`.
 #[derive(Clone, Debug, Deserialize, Serialize)]
 pub struct CapturedDocument {
     ///