mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1918133 - Stub stacking context snapshot API. r=gfx-reviewers,gw
Differential Revision: https://phabricator.services.mozilla.com/D225226
This commit is contained in:
parent
ea46a80865
commit
cc93351050
@ -1059,6 +1059,14 @@ void TransactionBuilder::DeleteBlobImage(BlobImageKey aKey) {
|
||||
wr_resource_updates_delete_blob_image(mTxn, aKey);
|
||||
}
|
||||
|
||||
void TransactionBuilder::AddSnapshotImage(wr::SnapshotImageKey aKey) {
|
||||
wr_resource_updates_add_snapshot_image(mTxn, aKey);
|
||||
}
|
||||
|
||||
void TransactionBuilder::DeleteSnapshotImage(wr::SnapshotImageKey aKey) {
|
||||
wr_resource_updates_delete_snapshot_image(mTxn, aKey);
|
||||
}
|
||||
|
||||
void TransactionBuilder::AddRawFont(wr::FontKey aKey, wr::Vec<uint8_t>& aBytes,
|
||||
uint32_t aIndex) {
|
||||
wr_resource_updates_add_raw_font(mTxn, aKey, &aBytes.inner, aIndex);
|
||||
|
@ -186,6 +186,10 @@ class TransactionBuilder final {
|
||||
|
||||
void DeleteBlobImage(wr::BlobImageKey aKey);
|
||||
|
||||
void AddSnapshotImage(wr::SnapshotImageKey aKey);
|
||||
|
||||
void DeleteSnapshotImage(wr::SnapshotImageKey aKey);
|
||||
|
||||
void AddRawFont(wr::FontKey aKey, wr::Vec<uint8_t>& aBytes, uint32_t aIndex);
|
||||
|
||||
void AddFontDescriptor(wr::FontKey aKey, wr::Vec<uint8_t>& aBytes,
|
||||
|
@ -2311,6 +2311,21 @@ pub extern "C" fn wr_resource_updates_delete_blob_image(txn: &mut Transaction, k
|
||||
txn.delete_blob_image(key);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wr_resource_updates_add_snapshot_image(
|
||||
txn: &mut Transaction,
|
||||
image_key: SnapshotImageKey,
|
||||
) {
|
||||
txn.add_snapshot_image(
|
||||
image_key,
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wr_resource_updates_delete_snapshot_image(txn: &mut Transaction, key: SnapshotImageKey) {
|
||||
txn.delete_snapshot_image(key);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wr_api_send_transaction(dh: &mut DocumentHandle, transaction: &mut Transaction, is_async: bool) {
|
||||
if transaction.is_empty() {
|
||||
@ -2789,6 +2804,7 @@ pub extern "C" fn wr_dp_push_stacking_context(
|
||||
&[],
|
||||
glyph_raster_space,
|
||||
params.flags,
|
||||
None, // TODO(nical)
|
||||
);
|
||||
|
||||
result
|
||||
|
@ -10,7 +10,7 @@ use std::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::u32;
|
||||
use api::MinimapData;
|
||||
use api::{MinimapData, SnapshotImageKey};
|
||||
use time::precise_time_ns;
|
||||
use crate::api::channel::{Sender, single_msg_channel, unbounded_channel};
|
||||
use crate::api::{BuiltDisplayList, IdNamespace, ExternalScrollId, Parameter, BoolParameter};
|
||||
@ -59,6 +59,10 @@ pub enum ResourceUpdate {
|
||||
DeleteBlobImage(BlobImageKey),
|
||||
/// See `AddBlobImage::visible_area`.
|
||||
SetBlobImageVisibleArea(BlobImageKey, DeviceIntRect),
|
||||
/// See `AddSnapshotImage`.
|
||||
AddSnapshotImage(AddSnapshotImage),
|
||||
/// See `AddSnapshotImage`.
|
||||
DeleteSnapshotImage(SnapshotImageKey),
|
||||
/// See `AddFont`.
|
||||
AddFont(AddFont),
|
||||
/// Deletes an already existing font resource.
|
||||
@ -99,6 +103,8 @@ impl fmt::Debug for ResourceUpdate {
|
||||
ResourceUpdate::DeleteImage(..) => f.write_str("ResourceUpdate::DeleteImage"),
|
||||
ResourceUpdate::DeleteBlobImage(..) => f.write_str("ResourceUpdate::DeleteBlobImage"),
|
||||
ResourceUpdate::SetBlobImageVisibleArea(..) => f.write_str("ResourceUpdate::SetBlobImageVisibleArea"),
|
||||
ResourceUpdate::AddSnapshotImage(..) => f.write_str("ResourceUpdate::AddSnapshotImage"),
|
||||
ResourceUpdate::DeleteSnapshotImage(..) => f.write_str("ResourceUpdate::DeleteSnapshotImage"),
|
||||
ResourceUpdate::AddFont(..) => f.write_str("ResourceUpdate::AddFont"),
|
||||
ResourceUpdate::DeleteFont(..) => f.write_str("ResourceUpdate::DeleteFont"),
|
||||
ResourceUpdate::AddFontInstance(..) => f.write_str("ResourceUpdate::AddFontInstance"),
|
||||
@ -505,6 +511,21 @@ impl Transaction {
|
||||
self.resource_updates.push(ResourceUpdate::SetBlobImageVisibleArea(key, area));
|
||||
}
|
||||
|
||||
/// See `ResourceUpdate::AddSnapshotImage`.
|
||||
pub fn add_snapshot_image(
|
||||
&mut self,
|
||||
key: SnapshotImageKey,
|
||||
) {
|
||||
self.resource_updates.push(
|
||||
ResourceUpdate::AddSnapshotImage(AddSnapshotImage { key })
|
||||
);
|
||||
}
|
||||
|
||||
/// See `ResourceUpdate::DeleteSnapshotImage`.
|
||||
pub fn delete_snapshot_image(&mut self, key: SnapshotImageKey) {
|
||||
self.resource_updates.push(ResourceUpdate::DeleteSnapshotImage(key));
|
||||
}
|
||||
|
||||
/// See `ResourceUpdate::AddFont`.
|
||||
pub fn add_raw_font(&mut self, key: FontKey, bytes: Vec<u8>, index: u32) {
|
||||
self.resource_updates
|
||||
@ -724,6 +745,16 @@ pub struct UpdateBlobImage {
|
||||
pub dirty_rect: BlobDirtyRect,
|
||||
}
|
||||
|
||||
/// Creates a snapshot image resource.
|
||||
///
|
||||
/// Must be matched with a `DeleteSnapshotImage` at some point to prevent memory leaks.
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(any(feature = "serde"), derive(Deserialize, Serialize))]
|
||||
pub struct AddSnapshotImage {
|
||||
/// The key identfying the snapshot resource.
|
||||
pub key: SnapshotImageKey,
|
||||
}
|
||||
|
||||
/// Creates a font resource.
|
||||
///
|
||||
/// Must be matched with a corresponding `ResourceUpdate::DeleteFont` at some point to prevent
|
||||
|
@ -673,6 +673,12 @@ impl ResourceCache {
|
||||
ResourceUpdate::DeleteBlobImage(img) => {
|
||||
self.delete_image_template(img.as_image());
|
||||
}
|
||||
ResourceUpdate::AddSnapshotImage(_img) => {
|
||||
// TODO
|
||||
}
|
||||
ResourceUpdate::DeleteSnapshotImage(_img) => {
|
||||
// TODO
|
||||
}
|
||||
ResourceUpdate::DeleteFont(font) => {
|
||||
if let Some(shared_key) = self.resources.fonts.font_keys.delete_key(&font) {
|
||||
self.delete_font_template(shared_key);
|
||||
|
@ -6,7 +6,7 @@ use euclid::{SideOffsets2D, Angle};
|
||||
use peek_poke::PeekPoke;
|
||||
use std::ops::Not;
|
||||
// local imports
|
||||
use crate::font;
|
||||
use crate::{font, SnapshotImageKey};
|
||||
use crate::{APZScrollGeneration, HasScrollLinkedEffect, PipelineId, PropertyBinding};
|
||||
use crate::serde::{Serialize, Deserialize};
|
||||
use crate::color::ColorF;
|
||||
@ -876,10 +876,17 @@ pub struct ReferenceFrame {
|
||||
pub key: SpatialTreeItemKey,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
|
||||
pub struct SnapshotInfo {
|
||||
pub key: SnapshotImageKey,
|
||||
pub area: LayoutRect,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
|
||||
pub struct PushStackingContextDisplayItem {
|
||||
pub origin: LayoutPoint,
|
||||
pub spatial_id: SpatialId,
|
||||
pub snapshot: Option<SnapshotInfo>,
|
||||
pub prim_flags: PrimitiveFlags,
|
||||
pub ref_frame_offset: LayoutVector2D,
|
||||
pub stacking_context: StackingContext,
|
||||
|
@ -1795,6 +1795,7 @@ impl DisplayListBuilder {
|
||||
filter_primitives: &[di::FilterPrimitive],
|
||||
raster_space: di::RasterSpace,
|
||||
flags: di::StackingContextFlags,
|
||||
snapshot: Option<di::SnapshotInfo>
|
||||
) {
|
||||
let ref_frame_offset = self.rf_mapper.current_offset();
|
||||
self.push_filters(filters, filter_datas, filter_primitives);
|
||||
@ -1802,6 +1803,7 @@ impl DisplayListBuilder {
|
||||
let item = di::DisplayItem::PushStackingContext(di::PushStackingContextDisplayItem {
|
||||
origin,
|
||||
spatial_id,
|
||||
snapshot,
|
||||
prim_flags,
|
||||
ref_frame_offset,
|
||||
stacking_context: di::StackingContext {
|
||||
@ -1856,6 +1858,7 @@ impl DisplayListBuilder {
|
||||
filter_primitives,
|
||||
di::RasterSpace::Screen,
|
||||
di::StackingContextFlags::empty(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,26 @@ impl BlobImageKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// An opaque identifier describing a snapshot image registered with WebRender.
|
||||
/// This is used as a handle to reference snapshot images, and can be used as an
|
||||
/// image in display items.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, PeekPoke)]
|
||||
pub struct SnapshotImageKey(pub ImageKey);
|
||||
|
||||
impl SnapshotImageKey {
|
||||
/// Interpret this snapshot image as an image for a display item.
|
||||
pub fn as_image(self) -> ImageKey {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SnapshotImageKey {
|
||||
fn default() -> Self {
|
||||
SnapshotImageKey(ImageKey::DUMMY)
|
||||
}
|
||||
}
|
||||
|
||||
/// An arbitrary identifier for an external image provided by the
|
||||
/// application. It must be a unique identifier for each external
|
||||
/// image.
|
||||
|
@ -312,6 +312,11 @@ fn is_image_opaque(format: ImageFormat, bytes: &[u8]) -> bool {
|
||||
|
||||
struct IsRoot(bool);
|
||||
|
||||
pub struct Snapshot {
|
||||
key: SnapshotImageKey,
|
||||
size: LayoutSize,
|
||||
}
|
||||
|
||||
pub struct YamlFrameReader {
|
||||
yaml_path: PathBuf,
|
||||
aux_dir: PathBuf,
|
||||
@ -332,6 +337,7 @@ pub struct YamlFrameReader {
|
||||
fonts: HashMap<FontDescriptor, FontKey>,
|
||||
font_instances: HashMap<(FontKey, FontSize, FontInstanceFlags, SyntheticItalics), FontInstanceKey>,
|
||||
font_render_mode: Option<FontRenderMode>,
|
||||
snapshots: HashMap<String, Snapshot>,
|
||||
allow_mipmaps: bool,
|
||||
|
||||
/// A HashMap that allows specifying a numeric id for clip and clip chains in YAML
|
||||
@ -366,6 +372,7 @@ impl YamlFrameReader {
|
||||
fonts: HashMap::new(),
|
||||
font_instances: HashMap::new(),
|
||||
font_render_mode: None,
|
||||
snapshots: HashMap::new(),
|
||||
allow_mipmaps: false,
|
||||
image_map: HashMap::new(),
|
||||
user_clip_id_map: HashMap::new(),
|
||||
@ -666,6 +673,15 @@ impl YamlFrameReader {
|
||||
kind,
|
||||
)
|
||||
}
|
||||
("snapshot", args, _) => {
|
||||
let snapshot = self.snapshots
|
||||
.get(args[0])
|
||||
.expect("Missing snapshot");
|
||||
return (
|
||||
snapshot.key.as_image(),
|
||||
snapshot.size,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
panic!("Failed to load image {:?}", file.to_str());
|
||||
}
|
||||
@ -1286,6 +1302,7 @@ impl YamlFrameReader {
|
||||
"src"
|
||||
}];
|
||||
let tiling = item["tile-size"].as_i64();
|
||||
|
||||
let file = rsrc_path(filename, &self.aux_dir);
|
||||
let (image_key, image_dims) =
|
||||
self.add_or_get_image(&file, tiling, item, wrench);
|
||||
@ -2020,6 +2037,26 @@ impl YamlFrameReader {
|
||||
let filter_datas = yaml["filter-datas"].as_vec_filter_data().unwrap_or_default();
|
||||
let filter_primitives = yaml["filter-primitives"].as_vec_filter_primitive().unwrap_or_default();
|
||||
|
||||
let snapshot = if !yaml["snapshot"].is_badvalue() {
|
||||
let yaml = &yaml["snapshot"];
|
||||
let name = yaml["name"].as_str().unwrap_or("snapshot");
|
||||
let area = yaml["area"].as_rect().unwrap_or(bounds);
|
||||
|
||||
let key = SnapshotImageKey(wrench.api.generate_image_key());
|
||||
self.snapshots.insert(name.to_string(), Snapshot {
|
||||
key,
|
||||
size: bounds.size(),
|
||||
});
|
||||
|
||||
let mut txn = Transaction::new();
|
||||
txn.add_snapshot_image(key);
|
||||
wrench.api.send_transaction(wrench.document_id, txn);
|
||||
|
||||
Some(SnapshotInfo { key, area })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut flags = StackingContextFlags::empty();
|
||||
flags.set(StackingContextFlags::IS_BLEND_CONTAINER, is_blend_container);
|
||||
flags.set(StackingContextFlags::WRAPS_BACKDROP_FILTER, wraps_backdrop_filter);
|
||||
@ -2036,6 +2073,7 @@ impl YamlFrameReader {
|
||||
&filter_primitives,
|
||||
raster_space,
|
||||
flags,
|
||||
snapshot,
|
||||
);
|
||||
|
||||
if let Some(yaml_items) = yaml["items"].as_vec() {
|
||||
|
Loading…
Reference in New Issue
Block a user