diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-04-17 15:56:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 15:56:30 -0400 |
commit | c9480c8e07a89c1bd40b29438f90e76dd8757edc (patch) | |
tree | 7aa0d74d54408eab95961e61c0ae4048f2b36208 /components/layout_2020/context.rs | |
parent | aa37904bbdb3c17d80a1b39f315977295d636d0f (diff) | |
parent | d4e85f9a904d4469b65bf73f7e465464eddb5cec (diff) | |
download | servo-c9480c8e07a89c1bd40b29438f90e76dd8757edc.tar.gz servo-c9480c8e07a89c1bd40b29438f90e76dd8757edc.zip |
Auto merge of #23661 - julientregoat:i-21289, r=jdm
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}
<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).
As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289 (GitHub issue number if applicable)
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
Diffstat (limited to 'components/layout_2020/context.rs')
-rw-r--r-- | components/layout_2020/context.rs | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/components/layout_2020/context.rs b/components/layout_2020/context.rs index dc894e65766..117a02e0940 100644 --- a/components/layout_2020/context.rs +++ b/components/layout_2020/context.rs @@ -3,11 +3,12 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::display_list::WebRenderImageInfo; +use crate::opaque_node::OpaqueNodeMethods; use fnv::FnvHashMap; use gfx::font_cache_thread::FontCacheThread; use gfx::font_context::FontContext; use msg::constellation_msg::PipelineId; -use net_traits::image_cache::{CanRequestImages, ImageCache, ImageState}; +use net_traits::image_cache::{CanRequestImages, ImageCache, ImageCacheResult}; use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder}; use parking_lot::RwLock; use script_layout_interface::{PendingImage, PendingImageState}; @@ -70,51 +71,52 @@ impl<'a> LayoutContext<'a> { CanRequestImages::No }; - // See if the image is already available - let result = self.image_cache.find_image_or_metadata( + // Check for available image or start tracking. + let cache_result = self.image_cache.get_cached_image_status( url.clone(), self.origin.clone(), None, use_placeholder, can_request, ); - match result { - Ok(image_or_metadata) => Some(image_or_metadata), - // Image failed to load, so just return nothing - Err(ImageState::LoadError) => None, - // Not yet requested - request image or metadata from the cache - Err(ImageState::NotRequested(id)) => { - let image = PendingImage { - state: PendingImageState::Unrequested(url), - node: node.into(), - id: id, - origin: self.origin.clone(), - }; - self.pending_images - .as_ref() - .unwrap() - .lock() - .unwrap() - .push(image); - None - }, + + match cache_result { + ImageCacheResult::Available(img_or_meta) => Some(img_or_meta), // Image has been requested, is still pending. Return no image for this paint loop. // When the image loads it will trigger a reflow and/or repaint. - Err(ImageState::Pending(id)) => { + ImageCacheResult::Pending(id) => { //XXXjdm if self.pending_images is not available, we should make sure that // this node gets marked dirty again so it gets a script-initiated // reflow that deals with this properly. if let Some(ref pending_images) = self.pending_images { let image = PendingImage { state: PendingImageState::PendingResponse, - node: node.into(), - id: id, + node: node.to_untrusted_node_address(), + id, origin: self.origin.clone(), }; pending_images.lock().unwrap().push(image); } None }, + // Not yet requested - request image or metadata from the cache + ImageCacheResult::ReadyForRequest(id) => { + let image = PendingImage { + state: PendingImageState::Unrequested(url), + node: node.to_untrusted_node_address(), + id, + origin: self.origin.clone(), + }; + self.pending_images + .as_ref() + .unwrap() + .lock() + .unwrap() + .push(image); + None + }, + // Image failed to load, so just return nothing + ImageCacheResult::LoadError => None, } } |