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

task -> thread #9201

Merged
merged 1 commit into from Jan 10, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

task -> thread

  • Loading branch information
rohan.prinja authored and ajnirp committed Jan 10, 2016
commit 1f02c4ebbb7d5ea49051f4391f1418f20c15d7a9
@@ -22,10 +22,10 @@ use std::borrow::ToOwned;
use std::mem;
use std::sync::mpsc::{Sender, channel};
use util::opts;
use util::task::spawn_named;
use util::thread::spawn_named;
use util::vec::byte_swap;

impl<'a> CanvasPaintTask<'a> {
impl<'a> CanvasPaintThread<'a> {
/// It reads image data from the canvas
/// canvas_size: The size of the canvas we're reading from
/// read_rect: The area of the canvas we want to read from
@@ -57,7 +57,7 @@ impl<'a> CanvasPaintTask<'a> {
}
}

pub struct CanvasPaintTask<'a> {
pub struct CanvasPaintThread<'a> {
drawtarget: DrawTarget,
/// TODO(pcwalton): Support multiple paths.
path_builder: PathBuilder,
@@ -101,28 +101,28 @@ impl<'a> CanvasPaintState<'a> {
}
}

impl<'a> CanvasPaintTask<'a> {
fn new(size: Size2D<i32>) -> CanvasPaintTask<'a> {
let draw_target = CanvasPaintTask::create(size);
impl<'a> CanvasPaintThread<'a> {
fn new(size: Size2D<i32>) -> CanvasPaintThread<'a> {
let draw_target = CanvasPaintThread::create(size);
let path_builder = draw_target.create_path_builder();
CanvasPaintTask {
CanvasPaintThread {
drawtarget: draw_target,
path_builder: path_builder,
state: CanvasPaintState::new(),
saved_states: Vec::new(),
}
}

/// Creates a new `CanvasPaintTask` and returns the out-of-process sender and the in-process
/// Creates a new `CanvasPaintThread` and returns the out-of-process sender and the in-process
/// sender for it.
pub fn start(size: Size2D<i32>) -> (IpcSender<CanvasMsg>, Sender<CanvasMsg>) {
// TODO(pcwalton): Ask the pipeline to create this for us instead of spawning it directly.
// This will be needed for multiprocess Servo.
let (out_of_process_chan, out_of_process_port) = ipc::channel::<CanvasMsg>().unwrap();
let (in_process_chan, in_process_port) = channel();
ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone());
spawn_named("CanvasTask".to_owned(), move || {
let mut painter = CanvasPaintTask::new(size);
spawn_named("CanvasThread".to_owned(), move || {
let mut painter = CanvasPaintThread::new(size);
loop {
let msg = in_process_port.recv();
match msg.unwrap() {
@@ -202,7 +202,7 @@ impl<'a> CanvasPaintTask<'a> {
}
}
}
CanvasMsg::WebGL(_) => panic!("Wrong message sent to Canvas2D task"),
CanvasMsg::WebGL(_) => panic!("Wrong message sent to Canvas2D thread"),
}
}
});
@@ -516,7 +516,7 @@ impl<'a> CanvasPaintTask<'a> {
}

fn recreate(&mut self, size: Size2D<i32>) {
self.drawtarget = CanvasPaintTask::create(size);
self.drawtarget = CanvasPaintThread::create(size);
}

fn send_pixel_contents(&mut self, chan: IpcSender<IpcSharedMemory>) {
@@ -22,6 +22,6 @@ extern crate num;
extern crate offscreen_gl_context;
extern crate util;

pub mod canvas_paint_task;
pub mod canvas_paint_thread;
mod premultiplytable;
pub mod webgl_paint_task;
pub mod webgl_paint_thread;
@@ -14,25 +14,25 @@ use layers::platform::surface::NativeSurface;
use offscreen_gl_context::{ColorAttachmentType, GLContext, GLContextAttributes, NativeGLContext};
use std::borrow::ToOwned;
use std::sync::mpsc::{Sender, channel};
use util::task::spawn_named;
use util::thread::spawn_named;
use util::vec::byte_swap;

pub struct WebGLPaintTask {
pub struct WebGLPaintThread {
size: Size2D<i32>,
original_context_size: Size2D<i32>,
gl_context: GLContext<NativeGLContext>,
}

impl WebGLPaintTask {
fn new(size: Size2D<i32>, attrs: GLContextAttributes) -> Result<WebGLPaintTask, &'static str> {
impl WebGLPaintThread {
fn new(size: Size2D<i32>, attrs: GLContextAttributes) -> Result<WebGLPaintThread, &'static str> {
let context = try!(GLContext::new(size, attrs, ColorAttachmentType::Texture, None));

// NOTE: As of right now this is always equal to the size parameter,
// but this doesn't have to be true. Firefox after failing with
// the requested size, tries with the nearest powers of two, for example.
let real_size = context.borrow_draw_buffer().unwrap().size();

Ok(WebGLPaintTask {
Ok(WebGLPaintThread {
size: real_size,
original_context_size: real_size,
gl_context: context
@@ -183,19 +183,19 @@ impl WebGLPaintTask {
assert!(gl::get_error() == gl::NO_ERROR);
}

/// Creates a new `WebGLPaintTask` and returns the out-of-process sender and the in-process
/// Creates a new `WebGLPaintThread` and returns the out-of-process sender and the in-process
/// sender for it.
pub fn start(size: Size2D<i32>, attrs: GLContextAttributes)
-> Result<(IpcSender<CanvasMsg>, Sender<CanvasMsg>), &'static str> {
let (out_of_process_chan, out_of_process_port) = ipc::channel::<CanvasMsg>().unwrap();
let (in_process_chan, in_process_port) = channel();
let (result_chan, result_port) = channel();
ROUTER.route_ipc_receiver_to_mpsc_sender(out_of_process_port, in_process_chan.clone());
spawn_named("WebGLTask".to_owned(), move || {
let mut painter = match WebGLPaintTask::new(size, attrs) {
Ok(task) => {
spawn_named("WebGLThread".to_owned(), move || {
let mut painter = match WebGLPaintThread::new(size, attrs) {
Ok(thread) => {
result_chan.send(Ok(())).unwrap();
task
thread
},
Err(e) => {
result_chan.send(Err(e)).unwrap();
@@ -225,7 +225,7 @@ impl WebGLPaintTask {
painter.send_native_surface(chan),
}
}
CanvasMsg::Canvas2d(_) => panic!("Wrong message sent to WebGLTask"),
CanvasMsg::Canvas2d(_) => panic!("Wrong message sent to WebGLThread"),
}
}
});
@@ -279,7 +279,7 @@ impl WebGLPaintTask {
}

fn create_texture(&self, chan: IpcSender<Option<NonZero<u32>>>) {
let texture = gl::gen_textures(1)[0];
let texture = gl::gen_framebuffers(1)[0];
let texture = if texture == 0 {
None
} else {
@@ -5,15 +5,15 @@
use CompositorMsg as ConstellationMsg;
use app_units::Au;
use compositor_layer::{CompositorData, CompositorLayer, RcCompositorLayer, WantsScrollEventsFlag};
use compositor_task::{CompositorEventListener, CompositorProxy};
use compositor_task::{CompositorReceiver, InitialCompositorState, Msg};
use compositor_thread::{CompositorEventListener, CompositorProxy};
use compositor_thread::{CompositorReceiver, InitialCompositorState, Msg};
use constellation::SendableFrameTree;
use euclid::point::TypedPoint2D;
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use euclid::{Matrix4, Point2D, Rect, Size2D};
use gfx::paint_task::{ChromeToPaintMsg, PaintRequest};
use gfx::paint_thread::{ChromeToPaintMsg, PaintRequest};
use gfx_traits::{color, LayerId, LayerKind, LayerProperties, ScrollPolicy};
use gleam::gl;
use gleam::gl::types::{GLint, GLsizei};
@@ -375,13 +375,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pub fn finish_shutting_down(&mut self) {
debug!("Compositor received message that constellation shutdown is complete");

// Clear out the compositor layers so that painting tasks can destroy the buffers.
// Clear out the compositor layers so that painting threads can destroy the buffers.
if let Some(ref root_layer) = self.scene.root {
root_layer.forget_all_tiles();
}

// Drain compositor port, sometimes messages contain channels that are blocking
// another task from finishing (i.e. SetFrameTree).
// another thread from finishing (i.e. SetFrameTree).
while self.port.try_recv_compositor_msg().is_some() {}

// Tell the profiler, memory profiler, and scrolling timer to shut down.
@@ -546,7 +546,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
reply.send(img).unwrap();
}

(Msg::PaintTaskExited(pipeline_id), ShutdownState::NotShuttingDown) => {
(Msg::PaintThreadExited(pipeline_id), ShutdownState::NotShuttingDown) => {
self.remove_pipeline_root_layer(pipeline_id);
}

@@ -580,7 +580,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}

(Msg::CollectMemoryReports(reports_chan), ShutdownState::NotShuttingDown) => {
let name = "compositor-task";
let name = "compositor-thread";
// These are both `ExplicitUnknownLocationSize` because the memory might be in the
// GPU or on the heap.
let reports = vec![mem::Report {
@@ -975,7 +975,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
epoch: Epoch,
frame_tree_id: FrameTreeId) {
// If the frame tree id has changed since this paint request was sent,
// reject the buffers and send them back to the paint task. If this isn't handled
// reject the buffers and send them back to the paint thread. If this isn't handled
// correctly, the content_age in the tile grid can get out of sync when iframes are
// loaded and the frame tree changes. This can result in the compositor thinking it
// has already drawn the most recently painted buffer, and missing a frame.
@@ -1470,7 +1470,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
};

// All the BufferRequests are in layer/device coordinates, but the paint task
// All the BufferRequests are in layer/device coordinates, but the paint thread
// wants to know the page coordinates. We scale them before sending them.
for request in &mut layer_requests {
request.page_rect = request.page_rect / scale.get();
@@ -1568,7 +1568,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// If a layer has sent a request for the current epoch, but it hasn't
// arrived yet then this layer is waiting for a paint message.
//
// Also don't check the root layer, because the paint task won't paint
// Also don't check the root layer, because the paint thread won't paint
// anything for it after first layout.
if layer_data.id != LayerId::null() &&
layer_data.requested_epoch == current_epoch &&
@@ -1587,7 +1587,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {

/// Query the constellation to see if the current compositor
/// output matches the current frame tree output, and if the
/// associated script tasks are idle.
/// associated script threads are idle.
fn is_ready_to_paint_image_output(&mut self) -> Result<(), NotReadyToPaint> {
match self.ready_to_save_state {
ReadyState::Unknown => {
@@ -2001,7 +2001,7 @@ fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc<Layer<CompositorDat

impl<Window> CompositorEventListener for IOCompositor<Window> where Window: WindowMethods {
fn handle_events(&mut self, messages: Vec<WindowEvent>) -> bool {
// Check for new messages coming from the other tasks in the system.
// Check for new messages coming from the other threads in the system.
while let Some(msg) = self.port.try_recv_compositor_msg() {
if !self.handle_browser_message(msg) {
break
@@ -97,17 +97,17 @@ pub trait CompositorLayer {

/// Removes the root layer (and any children) for a given pipeline from the
/// compositor. Buffers that the compositor is holding are returned to the
/// owning paint task.
/// owning paint thread.
fn remove_root_layer_with_pipeline_id<Window>(&self,
compositor: &mut IOCompositor<Window>,
pipeline_id: PipelineId)
where Window: WindowMethods;

/// Destroys all tiles of all layers, including children, *without* sending them back to the
/// painter. You must call this only when the paint task is destined to be going down;
/// painter. You must call this only when the paint thread is destined to be going down;
/// otherwise, you will leak tiles.
///
/// This is used during shutdown, when we know the paint task is going away.
/// This is used during shutdown, when we know the paint thread is going away.
fn forget_all_tiles(&self);

/// Move the layer's descendants that don't want scroll events and scroll by a relative
@@ -280,7 +280,7 @@ impl CompositorLayer for Layer<CompositorData> {

match index {
Some(index) => {
// Remove the root layer, and return buffers to the paint task
// Remove the root layer, and return buffers to the paint thread
let child = self.children().remove(index);
child.clear_all_tiles(compositor);
}
@@ -294,10 +294,10 @@ impl CompositorLayer for Layer<CompositorData> {
}

/// Destroys all tiles of all layers, including children, *without* sending them back to the
/// painter. You must call this only when the paint task is destined to be going down;
/// painter. You must call this only when the paint thread is destined to be going down;
/// otherwise, you will leak tiles.
///
/// This is used during shutdown, when we know the paint task is going away.
/// This is used during shutdown, when we know the paint thread is going away.
fn forget_all_tiles(&self) {
let tiles = self.collect_buffers();
for tile in tiles {
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Communication with the compositor task.
//! Communication with the compositor thread.

use CompositorMsg as ConstellationMsg;
use compositor;
@@ -107,10 +107,10 @@ impl PaintListener for Box<CompositorProxy + 'static + Send> {
fn native_display(&mut self) -> Option<NativeDisplay> {
let (chan, port) = channel();
self.send(Msg::GetNativeDisplay(chan));
// If the compositor is shutting down when a paint task
// If the compositor is shutting down when a paint thread
// is being created, the compositor won't respond to
// this message, resulting in an eventual panic. Instead,
// just return None in this case, since the paint task
// just return None in this case, since the paint thread
// will exit shortly and never actually be requested
// to paint buffers by the compositor.
port.recv().unwrap_or(None)
@@ -146,12 +146,12 @@ impl PaintListener for Box<CompositorProxy + 'static + Send> {
self.send(Msg::InitializeLayersForPipeline(pipeline_id, epoch, properties));
}

fn notify_paint_task_exiting(&mut self, pipeline_id: PipelineId) {
self.send(Msg::PaintTaskExited(pipeline_id))
fn notify_paint_thread_exiting(&mut self, pipeline_id: PipelineId) {
self.send(Msg::PaintThreadExited(pipeline_id))
}
}

/// Messages from the painting task and the constellation task to the compositor task.
/// Messages from the painting thread and the constellation thread to the compositor thread.
pub enum Msg {
/// Requests that the compositor shut down.
Exit(IpcSender<()>),
@@ -199,8 +199,8 @@ pub enum Msg {
SetCursor(Cursor),
/// Composite to a PNG file and return the Image over a passed channel.
CreatePng(IpcSender<Option<Image>>),
/// Informs the compositor that the paint task for the given pipeline has exited.
PaintTaskExited(PipelineId),
/// Informs the compositor that the paint thread for the given pipeline has exited.
PaintThreadExited(PipelineId),
/// Alerts the compositor that the viewport has been constrained in some manner
ViewportConstrained(PipelineId, ViewportConstraints),
/// A reply to the compositor asking if the output image is stable.
@@ -209,7 +209,7 @@ pub enum Msg {
NewFavicon(Url),
/// <head> tag finished parsing
HeadParsed,
/// Signal that the paint task ignored the paint requests that carried
/// Signal that the paint thread ignored the paint requests that carried
/// these native surfaces, so that they can be re-added to the surface cache.
ReturnUnusedNativeSurfaces(Vec<NativeSurface>),
/// Collect memory reports and send them back to the given mem::ReportsChan.
@@ -247,7 +247,7 @@ impl Debug for Msg {
Msg::TouchEventProcessed(..) => write!(f, "TouchEventProcessed"),
Msg::SetCursor(..) => write!(f, "SetCursor"),
Msg::CreatePng(..) => write!(f, "CreatePng"),
Msg::PaintTaskExited(..) => write!(f, "PaintTaskExited"),
Msg::PaintThreadExited(..) => write!(f, "PaintThreadExited"),
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
Msg::NewFavicon(..) => write!(f, "NewFavicon"),
@@ -263,9 +263,9 @@ impl Debug for Msg {
}
}

pub struct CompositorTask;
pub struct CompositorThread;

impl CompositorTask {
impl CompositorThread {
pub fn create<Window>(window: Option<Rc<Window>>,
state: InitialCompositorState)
-> Box<CompositorEventListener + 'static>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.