Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove types.rs and move its types into the relevant files. #963

Merged
merged 2 commits into from Mar 7, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Remove types.rs and move its types into the relevant files.

  • Loading branch information
nical committed Mar 6, 2017
commit eccb016e32e320263df016566d0039541d344a10
@@ -46,7 +46,7 @@ use time::precise_time_ns;
use thread_profiler::{register_thread_with_profiler, write_profile};
use util::TransformedRectKind;
use webrender_traits::{ColorF, Epoch, PipelineId, RenderNotifier, RenderDispatcher};
use webrender_traits::{ExternalImageId, ImageData, ImageFormat, RenderApiSender, RendererKind};
use webrender_traits::{ExternalImageId, ImageData, ImageFormat, RenderApiSender};
use webrender_traits::{DeviceIntRect, DevicePoint, DeviceIntPoint, DeviceIntSize, DeviceUintSize};
use webrender_traits::{ImageDescriptor, BlobImageRenderer};
use webrender_traits::channel;
@@ -75,6 +75,12 @@ const GPU_TAG_PRIM_BORDER: GpuProfileTag = GpuProfileTag { label: "Border", colo
const GPU_TAG_PRIM_CACHE_IMAGE: GpuProfileTag = GpuProfileTag { label: "CacheImage", color: debug_colors::SILVER };
const GPU_TAG_BLUR: GpuProfileTag = GpuProfileTag { label: "Blur", color: debug_colors::VIOLET };

#[derive(Debug, Copy, Clone)]
pub enum RendererKind {
Native,
OSMesa,
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum BlendMode {
None,
@@ -6,17 +6,132 @@ use byteorder::{LittleEndian, WriteBytesExt};
use channel::{self, MsgSender, PayloadHelperMethods, PayloadSender};
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use std::cell::Cell;
use {ApiMsg, ColorF, Epoch, ImageDescriptor};
use {FontKey, IdNamespace, ImageKey, NativeFontHandle, PipelineId};
use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ScrollLocation, ServoScrollRootId};
use {GlyphKey, GlyphDimensions, ImageData, WebGLContextId, WebGLCommand, TileSize};
use {DeviceIntSize, DynamicProperties, LayoutPoint, LayoutSize, WorldPoint, PropertyBindingKey, PropertyBindingId};
use {DeviceUintRect, DeviceUintSize};
use {BuiltDisplayList, AuxiliaryLists};
use VRCompositorCommand;
use {ExternalEvent, PageZoomFactor};
use {ColorF, ImageDescriptor};
use {FontKey, ImageKey, NativeFontHandle, ServoScrollRootId};
use {GlyphKey, GlyphDimensions, ImageData, WebGLContextId, WebGLCommand};
use {DeviceIntSize, LayoutPoint, LayoutSize, WorldPoint};
use {DeviceUintRect, DeviceUintSize, LayoutTransform};
use {BuiltDisplayList, BuiltDisplayListDescriptor, AuxiliaryLists, AuxiliaryListsDescriptor};
use std::fmt;
use std::marker::PhantomData;

pub type TileSize = u16;

#[derive(Clone, Deserialize, Serialize)]
pub enum ApiMsg {
AddRawFont(FontKey, Vec<u8>),
AddNativeFont(FontKey, NativeFontHandle),
DeleteFont(FontKey),
/// Gets the glyph dimensions
GetGlyphDimensions(Vec<GlyphKey>, MsgSender<Vec<Option<GlyphDimensions>>>),
/// Adds an image from the resource cache.
AddImage(ImageKey, ImageDescriptor, ImageData, Option<TileSize>),
/// Updates the the resource cache with the new image data.
UpdateImage(ImageKey, ImageDescriptor, Vec<u8>),
/// Drops an image from the resource cache.
DeleteImage(ImageKey),
CloneApi(MsgSender<IdNamespace>),
/// Supplies a new frame to WebRender.
///
/// After receiving this message, WebRender will read the display list, followed by the
/// auxiliary lists, from the payload channel.
SetRootDisplayList(Option<ColorF>,
Epoch,
PipelineId,
LayoutSize,
BuiltDisplayListDescriptor,
AuxiliaryListsDescriptor,
bool),
SetPageZoom(PageZoomFactor),
SetRootPipeline(PipelineId),
SetWindowParameters(DeviceUintSize, DeviceUintRect),
Scroll(ScrollLocation, WorldPoint, ScrollEventPhase),
ScrollLayersWithScrollId(LayoutPoint, PipelineId, ServoScrollRootId),
TickScrollingBounce,
TranslatePointToLayerSpace(WorldPoint, MsgSender<(LayoutPoint, PipelineId)>),
GetScrollLayerState(MsgSender<Vec<ScrollLayerState>>),
RequestWebGLContext(DeviceIntSize, GLContextAttributes, MsgSender<Result<(WebGLContextId, GLLimits), String>>),
ResizeWebGLContext(WebGLContextId, DeviceIntSize),
WebGLCommand(WebGLContextId, WebGLCommand),
GenerateFrame(Option<DynamicProperties>),
// WebVR commands that must be called in the WebGL render thread.
VRCompositorCommand(WebGLContextId, VRCompositorCommand),
/// An opaque handle that must be passed to the render notifier. It is used by Gecko
/// to forward gecko-specific messages to the render thread preserving the ordering
/// within the other messages.
ExternalEvent(ExternalEvent),
ShutDown,
}

impl fmt::Debug for ApiMsg {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&ApiMsg::AddRawFont(..) => { write!(f, "ApiMsg::AddRawFont") }
&ApiMsg::AddNativeFont(..) => { write!(f, "ApiMsg::AddNativeFont") }
&ApiMsg::DeleteFont(..) => { write!(f, "ApiMsg::DeleteFont") }
&ApiMsg::GetGlyphDimensions(..) => { write!(f, "ApiMsg::GetGlyphDimensions") }
&ApiMsg::AddImage(..) => { write!(f, "ApiMsg::AddImage") }
&ApiMsg::UpdateImage(..) => { write!(f, "ApiMsg::UpdateImage") }
&ApiMsg::DeleteImage(..) => { write!(f, "ApiMsg::DeleteImage") }
&ApiMsg::CloneApi(..) => { write!(f, "ApiMsg::CloneApi") }
&ApiMsg::SetRootDisplayList(..) => { write!(f, "ApiMsg::SetRootDisplayList") }
&ApiMsg::SetRootPipeline(..) => { write!(f, "ApiMsg::SetRootPipeline") }
&ApiMsg::Scroll(..) => { write!(f, "ApiMsg::Scroll") }
&ApiMsg::ScrollLayersWithScrollId(..) => { write!(f, "ApiMsg::ScrollLayersWithScrollId") }
&ApiMsg::TickScrollingBounce => { write!(f, "ApiMsg::TickScrollingBounce") }
&ApiMsg::TranslatePointToLayerSpace(..) => { write!(f, "ApiMsg::TranslatePointToLayerSpace") }
&ApiMsg::GetScrollLayerState(..) => { write!(f, "ApiMsg::GetScrollLayerState") }
&ApiMsg::RequestWebGLContext(..) => { write!(f, "ApiMsg::RequestWebGLContext") }
&ApiMsg::ResizeWebGLContext(..) => { write!(f, "ApiMsg::ResizeWebGLContext") }
&ApiMsg::WebGLCommand(..) => { write!(f, "ApiMsg::WebGLCommand") }
&ApiMsg::GenerateFrame(..) => { write!(f, "ApiMsg::GenerateFrame") }
&ApiMsg::VRCompositorCommand(..) => { write!(f, "ApiMsg::VRCompositorCommand") }
&ApiMsg::ExternalEvent(..) => { write!(f, "ApiMsg::ExternalEvent") }
&ApiMsg::ShutDown => { write!(f, "ApiMsg::ShutDown") }
&ApiMsg::SetPageZoom(..) => { write!(f, "ApiMsg::SetPageZoom") }
&ApiMsg::SetWindowParameters(..) => { write!(f, "ApiMsg::SetWindowParameters") }
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Epoch(pub u32);

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct PipelineId(pub u32, pub u32);

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct IdNamespace(pub u32);

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct ResourceId(pub u32);

/// An opaque pointer-sized value.
#[repr(C)]
#[derive(Clone, Deserialize, Serialize)]
pub struct ExternalEvent {
raw: usize,
}

unsafe impl Send for ExternalEvent {}

impl ExternalEvent {
pub fn from_raw(raw: usize) -> Self { ExternalEvent { raw: raw } }
/// Consumes self to make it obvious that the event should be forwarded only once.
pub fn unwrap(self) -> usize { self.raw }
}


#[derive(Clone, Deserialize, Serialize)]
pub struct RenderApiSender {
api_sender: MsgSender<ApiMsg>,
payload_sender: PayloadSender,
}

impl RenderApiSender {
pub fn new(api_sender: MsgSender<ApiMsg>,
payload_sender: PayloadSender)
@@ -293,3 +408,139 @@ impl RenderApi {
(namespace, id)
}
}

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum ScrollEventPhase {
/// The user started scrolling.
Start,
/// The user performed a scroll. The Boolean flag indicates whether the user's fingers are
/// down, if a touchpad is in use. (If false, the event is a touchpad fling.)
Move(bool),
/// The user ended scrolling.
End,
}

#[derive(Clone, Deserialize, Serialize)]
pub struct ScrollLayerState {
pub pipeline_id: PipelineId,
pub scroll_root_id: ServoScrollRootId,
pub scroll_offset: LayoutPoint,
}

#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum ScrollLocation {
/// Scroll by a certain amount.
Delta(LayoutPoint),
/// Scroll to very top of element.
Start,
/// Scroll to very bottom of element.
End
}

/// Represents a desktop style page zoom factor.
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct PageZoomFactor(f32);

impl PageZoomFactor {
/// Construct a new page zoom factor.
pub fn new(scale: f32) -> PageZoomFactor {
PageZoomFactor(scale)
}

/// Get the page zoom factor as an untyped float.
pub fn get(&self) -> f32 {
self.0
}
}

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, Eq, Hash)]
pub struct PropertyBindingId {
namespace: u32,
uid: u32,
}

/// A unique key that is used for connecting animated property
/// values to bindings in the display list.
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct PropertyBindingKey<T> {
pub id: PropertyBindingId,
_phantom: PhantomData<T>,
}

/// Construct a property value from a given key and value.
impl<T: Copy> PropertyBindingKey<T> {
pub fn with(&self, value: T) -> PropertyValue<T> {
PropertyValue {
key: *self,
value: value,
}
}
}

/// A binding property can either be a specific value
/// (the normal, non-animated case) or point to a binding location
/// to fetch the current value from.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum PropertyBinding<T> {
Value(T),
Binding(PropertyBindingKey<T>),
}

impl<T> From<T> for PropertyBinding<T> {
fn from(value: T) -> PropertyBinding<T> {
PropertyBinding::Value(value)
}
}

impl<T> From<PropertyBindingKey<T>> for PropertyBinding<T> {
fn from(key: PropertyBindingKey<T>) -> PropertyBinding<T> {
PropertyBinding::Binding(key)
}
}

/// The current value of an animated property. This is
/// supplied by the calling code.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct PropertyValue<T> {
pub key: PropertyBindingKey<T>,
pub value: T,
}

/// When using generate_frame(), a list of PropertyValue structures
/// can optionally be supplied to provide the current value of any
/// animated properties.
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct DynamicProperties {
pub transforms: Vec<PropertyValue<LayoutTransform>>,
pub floats: Vec<PropertyValue<f32>>,
}

pub type VRCompositorId = u64;

// WebVR commands that must be called in the WebGL render thread.
#[derive(Clone, Deserialize, Serialize)]
pub enum VRCompositorCommand {
Create(VRCompositorId),
SyncPoses(VRCompositorId, f64, f64, MsgSender<Result<Vec<u8>,()>>),
SubmitFrame(VRCompositorId, [f32; 4], [f32; 4]),
Release(VRCompositorId)
}

// Trait object that handles WebVR commands.
// Receives the texture_id associated to the WebGLContext.
pub trait VRCompositorHandler: Send {
fn handle(&mut self, command: VRCompositorCommand, texture_id: Option<u32>);
}

pub trait RenderNotifier: Send {
fn new_frame_ready(&mut self);
fn new_scroll_frame_ready(&mut self, composite_needed: bool);
fn external_event(&mut self, _evt: ExternalEvent) { unimplemented!() }
fn shut_down(&mut self) {}
}

// Trait to allow dispatching functions to a specific thread or event loop.
pub trait RenderDispatcher: Send {
fn dispatch(&self, Box<Fn() + Send>);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.