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

Make render API generate IDs in a way that works for e10s. #67

Merged
merged 1 commit into from Oct 30, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -5,6 +5,7 @@ use euclid::{Matrix4, Point2D, Rect, Size2D};
use fnv::FnvHasher;
use gleam::gl;
use platform::font::NativeFontHandle;
use render_api::RenderApi;
use std::collections::HashMap;
use std::collections::hash_state::DefaultState;
use std::sync::Arc;
@@ -20,6 +21,12 @@ const COLOR_FLOAT_TO_FIXED: f32 = 255.0;
pub const ORTHO_NEAR_PLANE: f32 = -1000000.0;
pub const ORTHO_FAR_PLANE: f32 = 1000000.0;

#[derive(Clone, Copy, Debug)]
pub struct IdNamespace(pub u32);

#[derive(Clone, Copy, Debug)]
pub struct ResourceId(pub u32);

pub enum FontTemplate {
Raw(Arc<Vec<u8>>),
Native(NativeFontHandle),
@@ -343,6 +350,7 @@ pub enum ApiMsg {
AddNativeFont(FontKey, NativeFontHandle),
AddImage(ImageKey, u32, u32, ImageFormat, Vec<u8>),
AddDisplayList(DisplayListID, PipelineId, Epoch, DisplayListBuilder),
CloneApi(Sender<RenderApi>),
SetRootStackingContext(StackingContext, ColorF, Epoch, PipelineId),
SetRootPipeline(PipelineId),
Scroll(Point2D<f32>),
@@ -1,34 +1,44 @@
use euclid::Point2D;
use internal_types::ApiMsg;
use internal_types::{ApiMsg, IdNamespace, ResourceId};
use platform::font::NativeFontHandle;
use std::cell::Cell;
use std::sync::mpsc::{self, Sender};
use types::{PipelineId, ImageKey, ImageFormat, StackingContext};
use types::{ColorF, DisplayListID, DisplayListBuilder, Epoch, FontKey};

#[derive(Clone)]
pub struct RenderApi {
pub tx: Sender<ApiMsg>,
pub id_namespace: IdNamespace,
pub next_id: Cell<ResourceId>,
}

impl RenderApi {
pub fn add_raw_font(&self, key: FontKey, bytes: Vec<u8>) {
pub fn add_raw_font(&self, bytes: Vec<u8>) -> FontKey {
let new_id = self.next_unique_id();
let key = FontKey::new(new_id.0, new_id.1);
let msg = ApiMsg::AddRawFont(key, bytes);
self.tx.send(msg).unwrap();
key
}

pub fn add_native_font(&self, key: FontKey, native_font_handle: NativeFontHandle) {
pub fn add_native_font(&self, native_font_handle: NativeFontHandle) -> FontKey {
let new_id = self.next_unique_id();
let key = FontKey::new(new_id.0, new_id.1);
let msg = ApiMsg::AddNativeFont(key, native_font_handle);
self.tx.send(msg).unwrap();
key
}

pub fn add_image(&self,
key: ImageKey,
width: u32,
height: u32,
format: ImageFormat,
bytes: Vec<u8>) {
bytes: Vec<u8>) -> ImageKey {
let new_id = self.next_unique_id();
let key = ImageKey::new(new_id.0, new_id.1);
let msg = ApiMsg::AddImage(key, width, height, format, bytes);
self.tx.send(msg).unwrap();
key
}

// TODO: Support changing dimensions (and format) during image update?
@@ -45,7 +55,8 @@ impl RenderApi {
pipeline_id: PipelineId,
epoch: Epoch) -> DisplayListID {
debug_assert!(display_list.item_count() > 0, "Avoid adding empty lists!");
let id = DisplayListID::new();
let new_id = self.next_unique_id();
let id = DisplayListID(new_id.0, new_id.1);
let msg = ApiMsg::AddDisplayList(id, pipeline_id, epoch, display_list);
self.tx.send(msg).unwrap();
id
@@ -76,5 +87,19 @@ impl RenderApi {
self.tx.send(msg).unwrap();
rx.recv().unwrap()
}

pub fn clone_api(&self) -> RenderApi {
let (tx, rx) = mpsc::channel();
let msg = ApiMsg::CloneApi(tx);
self.tx.send(msg).unwrap();
rx.recv().unwrap()
}

fn next_unique_id(&self) -> (u32, u32) {
let IdNamespace(namespace) = self.id_namespace;
let ResourceId(id) = self.next_id.get();
self.next_id.set(ResourceId(id + 1));
(namespace, id)
}
}

@@ -12,13 +12,15 @@ use internal_types::{PackedVertex, WorkVertex, DisplayList, DrawCommand, DrawCom
use internal_types::{ClipRectToRegionResult, DrawListIndex, DrawListItemIndex, DisplayItemKey};
use internal_types::{CompositeInfo, BorderEdgeDirection, RenderTargetIndex, GlyphKey};
use internal_types::{FontTemplate, Glyph, PolygonPosColorUv, RectPosUv, TextureTarget};
use internal_types::{ResourceId, IdNamespace};
use layer::Layer;
use optimizer;
use platform::font::{FontContext, RasterizedGlyph};
use render_api::RenderApi;
use renderer::BLUR_INFLATION_FACTOR;
use resource_cache::ResourceCache;
use resource_list::ResourceList;
use std::cell::RefCell;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::hash_state::DefaultState;
@@ -1236,6 +1238,7 @@ enum StackingContextKind<'a> {

pub struct RenderBackend {
api_rx: Receiver<ApiMsg>,
api_tx: Sender<ApiMsg>,
result_tx: Sender<ResultMsg>,
viewport: Rect<i32>,
device_pixel_ratio: f32,
@@ -1252,22 +1255,25 @@ pub struct RenderBackend {
draw_list_map: DrawListMap,
stacking_contexts: StackingContextMap,
next_draw_list_id: DrawListID,
next_namespace_id: IdNamespace,

scene: Scene,
}

impl RenderBackend {
pub fn new(rx: Receiver<ApiMsg>,
tx: Sender<ResultMsg>,
pub fn new(api_rx: Receiver<ApiMsg>,
api_tx: Sender<ApiMsg>,
result_tx: Sender<ResultMsg>,
viewport: Rect<i32>,
device_pixel_ratio: f32,
quad_program_id: ProgramId,
white_image_id: TextureCacheItemId,
dummy_mask_image_id: TextureCacheItemId,
texture_cache: TextureCache) -> RenderBackend {
let mut backend = RenderBackend {
api_rx: rx,
result_tx: tx,
api_rx: api_rx,
api_tx: api_tx,
result_tx: result_tx,
viewport: viewport,
device_pixel_ratio: device_pixel_ratio,
root_pipeline_id: None,
@@ -1283,6 +1289,7 @@ impl RenderBackend {
draw_list_map: HashMap::with_hash_state(Default::default()),
stacking_contexts: HashMap::with_hash_state(Default::default()),

next_namespace_id: IdNamespace(1),
next_draw_list_id: DrawListID(0),
};

@@ -1369,6 +1376,18 @@ impl RenderBackend {

self.display_list_map.insert(id, display_list);
}
ApiMsg::CloneApi(sender) => {
let new_api = RenderApi {
tx: self.api_tx.clone(),
id_namespace: self.next_namespace_id,
next_id: Cell::new(ResourceId(0)),
};

let IdNamespace(id_namespace) = self.next_namespace_id;
self.next_namespace_id = IdNamespace(id_namespace + 1);

sender.send(new_api).unwrap();
}
ApiMsg::SetRootStackingContext(stacking_context, background_color, epoch, pipeline_id) => {
let _pf = util::ProfileScope::new("SetRootStackingContext");

@@ -4,18 +4,19 @@ use device::{Device, ProgramId, TextureId, TextureIndex, UniformLocation, VAOId,
use euclid::{Rect, Matrix4, Point2D, Size2D};
use fnv::FnvHasher;
use gleam::gl;
use internal_types::{ApiMsg, Frame, ResultMsg, TextureUpdateOp, BatchUpdateOp, BatchUpdateList};
use internal_types::{Frame, ResultMsg, TextureUpdateOp, BatchUpdateOp, BatchUpdateList};
use internal_types::{TextureUpdateDetails, TextureUpdateList, PackedVertex, RenderTargetMode};
use internal_types::{BatchId, ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, DrawCommandInfo};
use internal_types::{PackedVertexForTextureCacheUpdate, TextureTarget};
use internal_types::{PackedVertexForTextureCacheUpdate, TextureTarget, IdNamespace, ResourceId};
use render_api::RenderApi;
use render_backend::RenderBackend;
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_state::DefaultState;
use std::f32;
use std::mem;
use std::path::PathBuf;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::mpsc::{channel, Receiver};
use std::thread;
use texture_cache::{TextureCache, TextureInsertOp};
use types::{ColorF, Epoch, PipelineId, RenderNotifier, ImageFormat, MixBlendMode};
@@ -42,7 +43,6 @@ struct RenderContext {
}

pub struct Renderer {
api_tx: Sender<ApiMsg>,
result_rx: Receiver<ResultMsg>,
device: Device,
pending_texture_updates: Vec<TextureUpdateList>,
@@ -76,7 +76,7 @@ impl Renderer {
width: u32,
height: u32,
device_pixel_ratio: f32,
resource_path: PathBuf) -> Renderer {
resource_path: PathBuf) -> (Renderer, RenderApi) {
let (api_tx, api_rx) = channel();
let (result_tx, result_rx) = channel();

@@ -135,8 +135,10 @@ impl Renderer {

device.end_frame();

let backend_api_tx = api_tx.clone();
thread::spawn(move || {
let mut backend = RenderBackend::new(api_rx,
backend_api_tx,
result_tx,
initial_viewport,
device_pixel_ratio,
@@ -147,8 +149,7 @@ impl Renderer {
backend.run(notifier);
});

Renderer {
api_tx: api_tx,
let renderer = Renderer {
result_rx: result_rx,
device: device,
current_frame: None,
@@ -169,13 +170,15 @@ impl Renderer {
u_filter_texture_size: u_filter_texture_size,
u_direction: u_direction,
u_quad_transform_array: u_quad_transform_array,
}
}
};

pub fn new_api(&self) -> RenderApi {
RenderApi {
tx: self.api_tx.clone()
}
let api = RenderApi {
tx: api_tx,
id_namespace: IdNamespace(0), // special case
next_id: Cell::new(ResourceId(0)),
};

(renderer, api)
}

pub fn current_epoch(&self, pipeline_id: PipelineId) -> Option<Epoch> {
@@ -1,22 +1,21 @@
use app_units::Au;
use euclid::{Point2D, Rect, Size2D, Matrix4};
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct FontKey(u64);
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct FontKey(u32, u32);

impl FontKey {
pub fn new(key: u64) -> FontKey {
FontKey(key)
pub fn new(key0: u32, key1: u32) -> FontKey {
FontKey(key0, key1)
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ImageKey(u64);
pub struct ImageKey(u32, u32);

impl ImageKey {
pub fn new(key: u64) -> ImageKey {
ImageKey(key)
pub fn new(key0: u32, key1: u32) -> ImageKey {
ImageKey(key0, key1)
}
}

@@ -75,13 +74,6 @@ pub struct Epoch(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PipelineId(pub u32, pub u32);

static RESOURCE_ID_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;

#[inline]
pub fn new_resource_id() -> usize {
RESOURCE_ID_COUNTER.fetch_add(1, Ordering::SeqCst)
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct RenderTargetID(pub u32); // TODO: HACK HACK HACK this is an alias for device::TextureId

@@ -109,13 +101,7 @@ impl ScrollLayerId {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DisplayListID(usize);

impl DisplayListID {
pub fn new() -> DisplayListID {
DisplayListID(new_resource_id())
}
}
pub struct DisplayListID(pub u32, pub u32);

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum BoxShadowClipMode {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.