mirror of
https://github.com/servo/servo.git
synced 2025-08-15 10:25:32 +01:00
Implement a more realistic and persistent document restyle.
This commit is contained in:
parent
33c4689b15
commit
2e770b78a2
4 changed files with 170 additions and 40 deletions
75
ports/geckolib/data.rs
Normal file
75
ports/geckolib/data.rs
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
use bindings::ServoStyleSetData;
|
||||
use euclid::Size2D;
|
||||
use euclid::size::TypedSize2D;
|
||||
use num_cpus;
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use style::animation::Animation;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::dom::OpaqueNode;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::parallel::WorkQueueData;
|
||||
use style::selector_matching::Stylist;
|
||||
use style::stylesheets::Stylesheet;
|
||||
use util::geometry::ViewportPx;
|
||||
use util::thread_state;
|
||||
use util::workqueue::WorkQueue;
|
||||
|
||||
pub struct PerDocumentStyleData {
|
||||
|
||||
/// Rule processor.
|
||||
pub stylist: Stylist,
|
||||
|
||||
/// List of stylesheets, mirrored from Gecko.
|
||||
pub stylesheets: Vec<Arc<Stylesheet>>,
|
||||
|
||||
/// Whether the stylesheets list above has changed since the last restyle.
|
||||
pub stylesheets_changed: bool,
|
||||
|
||||
// FIXME(bholley): Hook these up to something.
|
||||
pub new_animations_sender: Sender<Animation>,
|
||||
pub new_animations_receiver: Receiver<Animation>,
|
||||
pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
// FIXME(bholley): This shouldn't be per-document.
|
||||
pub work_queue: WorkQueue<SharedStyleContext, WorkQueueData>,
|
||||
}
|
||||
|
||||
impl PerDocumentStyleData {
|
||||
pub fn new() -> PerDocumentStyleData {
|
||||
// FIXME(bholley): Real window size.
|
||||
let window_size: TypedSize2D<ViewportPx, f32> = Size2D::typed(800.0, 600.0);
|
||||
let device = Device::new(MediaType::Screen, window_size);
|
||||
|
||||
let (new_anims_sender, new_anims_receiver) = channel();
|
||||
let num_threads = cmp::max(num_cpus::get() * 3 / 4, 1);
|
||||
|
||||
PerDocumentStyleData {
|
||||
stylist: Stylist::new(device),
|
||||
stylesheets: Vec::new(),
|
||||
stylesheets_changed: true,
|
||||
new_animations_sender: new_anims_sender,
|
||||
new_animations_receiver: new_anims_receiver,
|
||||
running_animations: Arc::new(RwLock::new(HashMap::new())),
|
||||
expired_animations: Arc::new(RwLock::new(HashMap::new())),
|
||||
work_queue: WorkQueue::new("StyleWorker", thread_state::LAYOUT, num_threads),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow_mut_from_raw<'a>(data: *mut ServoStyleSetData) -> &'a mut Self {
|
||||
unsafe { &mut *(data as *mut PerDocumentStyleData) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PerDocumentStyleData {
|
||||
fn drop(&mut self) {
|
||||
self.work_queue.shutdown();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue