Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct FlattenInfo {
offset_from_current_layer: Point2D<f32>,
transform: Matrix4D<f32>,
perspective: Matrix4D<f32>,
pipeline_id: PipelineId,
}

#[derive(Debug)]
Expand Down Expand Up @@ -389,8 +390,10 @@ impl RenderTarget {
}
}

pub type LayerMap = HashMap<ScrollLayerId, Layer, BuildHasherDefault<FnvHasher>>;

pub struct Frame {
pub layers: HashMap<ScrollLayerId, Layer, BuildHasherDefault<FnvHasher>>,
pub layers: LayerMap,
pub pipeline_epoch_map: HashMap<PipelineId, Epoch, BuildHasherDefault<FnvHasher>>,
pub pipeline_auxiliary_lists: HashMap<PipelineId,
AuxiliaryLists,
Expand All @@ -401,7 +404,7 @@ pub struct Frame {
next_render_target_id: RenderTargetId,
next_draw_list_group_id: DrawListGroupId,
draw_list_groups: HashMap<DrawListGroupId, DrawListGroup, BuildHasherDefault<FnvHasher>>,
root_scroll_layer_id: Option<ScrollLayerId>,
pub root_scroll_layer_id: Option<ScrollLayerId>,
id: FrameId,
}

Expand Down Expand Up @@ -737,11 +740,13 @@ impl Frame {
// Insert global position: fixed elements layer
debug_assert!(self.layers.is_empty());
let root_fixed_layer_id = ScrollLayerId::create_fixed(root_pipeline_id);
self.layers.insert(root_fixed_layer_id,
Layer::new(root_stacking_context.stacking_context.overflow.origin,
root_stacking_context.stacking_context.overflow.size,
root_pipeline.viewport_size,
Matrix4D::identity()));
self.layers.insert(
root_fixed_layer_id,
Layer::new(root_stacking_context.stacking_context.overflow.origin,
root_stacking_context.stacking_context.overflow.size,
root_pipeline.viewport_size,
Matrix4D::identity(),
root_pipeline_id));

// Work around borrow check on resource cache
{
Expand All @@ -763,6 +768,7 @@ impl Frame {
current_clip_rect: MAX_RECT,
transform: Matrix4D::identity(),
perspective: Matrix4D::identity(),
pipeline_id: root_pipeline_id,
};

let root_pipeline = SceneItemKind::Pipeline(root_pipeline);
Expand Down Expand Up @@ -893,6 +899,7 @@ impl Frame {
current_clip_rect: MAX_RECT,
transform: info.transform,
perspective: info.perspective,
pipeline_id: pipeline.pipeline_id,
};

let iframe_stacking_context = context.scene
Expand All @@ -908,7 +915,8 @@ impl Frame {
Layer::new(layer_origin,
layer_size,
iframe_info.viewport_size,
iframe_info.transform));
iframe_info.transform,
pipeline.pipeline_id));

self.flatten(iframe,
&iframe_info,
Expand Down Expand Up @@ -996,6 +1004,7 @@ impl Frame {
current_clip_rect: local_clip_rect,
transform: transform,
perspective: perspective,
pipeline_id: parent_info.pipeline_id,
};

match (stacking_context.scroll_policy, stacking_context.scroll_layer_id) {
Expand All @@ -1014,7 +1023,8 @@ impl Frame {
let layer = Layer::new(parent_info.offset_from_origin,
stacking_context.overflow.size,
viewport_size,
transform);
transform,
parent_info.pipeline_id);
if parent_info.actual_scroll_layer_id != scroll_layer_id {
self.layers.get_mut(&parent_info.actual_scroll_layer_id).unwrap().add_child(scroll_layer_id);
}
Expand Down Expand Up @@ -1327,4 +1337,27 @@ impl Frame {
}
layers_bouncing_back
}

pub fn root_scroll_layer_for_pipeline(&self, pipeline_id: PipelineId)
-> Option<ScrollLayerId> {
let root_scroll_layer_id = match self.root_scroll_layer_id {
Some(root_scroll_layer_id) => root_scroll_layer_id,
None => return None,
};
return search(&self.layers, root_scroll_layer_id, pipeline_id);

fn search(layers: &LayerMap, layer_id: ScrollLayerId, query: PipelineId)
-> Option<ScrollLayerId> {
let layer = layers.get(&layer_id).expect("No layer with that ID!");
if layer.pipeline_id == query {
return Some(layer_id)
}
for &kid in &layer.children {
if let Some(layer_id) = search(layers, kid, query) {
return Some(layer_id)
}
}
None
}
}
}
8 changes: 6 additions & 2 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use euclid::{Matrix4D, Point2D, Rect, Size2D};
use internal_types::{BatchUpdate, BatchUpdateList, BatchUpdateOp};
use internal_types::{DrawListItemIndex, DrawListId, DrawListGroupId};
use spring::{DAMPING, STIFFNESS, Spring};
use webrender_traits::ScrollLayerId;
use webrender_traits::{PipelineId, ScrollLayerId};

pub struct Layer {
// TODO: Remove pub from here if possible in the future
Expand All @@ -18,14 +18,17 @@ pub struct Layer {
pub world_origin: Point2D<f32>,
pub local_transform: Matrix4D<f32>,
pub world_transform: Matrix4D<f32>,
pub pipeline_id: PipelineId,
pub children: Vec<ScrollLayerId>,
}

impl Layer {
pub fn new(world_origin: Point2D<f32>,
layer_size: Size2D<f32>,
viewport_size: Size2D<f32>,
transform: Matrix4D<f32>) -> Layer {
transform: Matrix4D<f32>,
pipeline_id: PipelineId)
-> Layer {
let rect = Rect::new(Point2D::zero(), layer_size);
let aabb_tree = AABBTree::new(8192.0, &rect);

Expand All @@ -38,6 +41,7 @@ impl Layer {
local_transform: transform,
world_transform: transform,
children: Vec::new(),
pipeline_id: pipeline_id,
}
}

Expand Down
38 changes: 27 additions & 11 deletions src/render_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use byteorder::{LittleEndian, ReadBytesExt};
use euclid::Matrix4D;
use frame::Frame;
use internal_types::{FontTemplate, ResultMsg, RendererFrame};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcReceiver};
Expand All @@ -16,7 +17,7 @@ use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use texture_cache::{TextureCache, TextureCacheItemId};
use webrender_traits::{ApiMsg, AuxiliaryLists, BuiltDisplayList, IdNamespace, RenderNotifier};
use webrender_traits::{WebGLContextId, ScrollLayerId};
use webrender_traits::{PipelineId, WebGLContextId, ScrollLayerId};
use batch::new_id;
use device::TextureId;
use offscreen_gl_context::{NativeGLContext, GLContext, ColorAttachmentType, NativeGLContextMethods, NativeGLContextHandle};
Expand Down Expand Up @@ -222,21 +223,36 @@ impl RenderBackend {
self.publish_frame(frame, &mut profile_counters);
}
ApiMsg::TranslatePointToLayerSpace(point, tx) => {
// TODO(pcwalton): Select other layers for mouse events.
// First, find the specific layer that contains the point.
let point = point / self.device_pixel_ratio;
match self.scene.root_pipeline_id {
Some(root_pipeline_id) => {
match self.frame.layers.get_mut(&ScrollLayerId::new(root_pipeline_id, 0)) {
None => tx.send(point).unwrap(),
Some(layer) => {
tx.send(point - layer.scrolling.offset).unwrap()
if let (Some(root_pipeline_id), Some(root_scroll_layer_id)) =
(self.scene.root_pipeline_id,
self.frame.root_scroll_layer_id) {
if let Some(scroll_layer_id) =
self.frame.get_scroll_layer(&point,
root_scroll_layer_id,
&Matrix4D::identity()) {
if let Some(layer) = self.frame.layers.get(&scroll_layer_id) {
// Now, because we send a *pipeline ID*, not a layer ID, as
// a response, we need the translated point to be relative
// to the origin of that pipeline in the scene. So we need
// to find the root layer for the pipeline. (We don't send
// layer IDs because layer IDs are internal to WebRender;
// Servo won't know what to do with them.)
if let Some(layer_id) =
self.frame.root_scroll_layer_for_pipeline(
layer.pipeline_id) {
if let Some(layer) = self.frame.layers.get(&layer_id) {
let point = point - layer.world_origin -
layer.scrolling.offset;
tx.send((point, layer.pipeline_id)).unwrap();
continue
}
}
}
}
None => {
tx.send(point).unwrap()
}
}
tx.send((point, PipelineId(0, 0))).unwrap()
}
ApiMsg::RequestWebGLContext(size, attributes, tx) => {
if let Some(ref handle) = self.webrender_context_handle {
Expand Down