diff options
author | Glenn Watson <gw@intuitionlibrary.com> | 2014-07-04 07:53:25 +1000 |
---|---|---|
committer | Glenn Watson <gw@intuitionlibrary.com> | 2014-07-07 14:25:21 +1000 |
commit | 12978eeb50d8f727bc020bcdd0534e80d7890c7f (patch) | |
tree | b33c8659a0faf66765fef9cc016ac766a44007f5 /src/components/layout/layout_task.rs | |
parent | e62637fee2f1c9627468dde81a68df1dd40b6bc9 (diff) | |
download | servo-12978eeb50d8f727bc020bcdd0534e80d7890c7f.tar.gz servo-12978eeb50d8f727bc020bcdd0534e80d7890c7f.zip |
Next stage of refactoring font system. This commit introduces
the font cache task, and adapts client code to use it. It also
cleans up some existing code paths.
- Fonts are only read once from disk while in use (they
are discarded if the reference count reaches zero, however).
This saves memory and prevents unnecessary reading from disk.
- It will be easier to add web font support, as all fonts
are created and managed in a single place and the entire
pipeline ensures that only one in-memory copy of font data
is required.
An overview of how the pieces fit together:
FontTemplate - A structure containing everything that
is required to create (and select) font handles. This
structure is shared among all matching font handles
(via Arc).
FontTemplateData - A platform specific structure that
contains the actual font data inside a template (this is
a byte array on Linux/Android, CTFont on Mac).
FontHandle - An opaque, platform specific handle to
a font instance. Each FontHandle contains an Arc<>
reference to the FontTemplate it was created from.
FontCache - This is a separate task, that is responsible
for loading and caching FontTemplate structures. There
is one FontCache per constellation. It is only ever accessed
via the FontContext described below.
FontContext - This is the public interface to the FontCache
and is used by the layout and render code to create font
handles. These must *not* be shared between threads. There
is typically one FontContext per thread/task.
Diffstat (limited to 'src/components/layout/layout_task.rs')
-rw-r--r-- | src/components/layout/layout_task.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/components/layout/layout_task.rs b/src/components/layout/layout_task.rs index f7fd408fd6e..e97057c605c 100644 --- a/src/components/layout/layout_task.rs +++ b/src/components/layout/layout_task.rs @@ -27,7 +27,7 @@ use geom::rect::Rect; use geom::size::Size2D; use gfx::display_list::{ClipDisplayItemClass, ContentStackingLevel, DisplayItem}; use gfx::display_list::{DisplayItemIterator, DisplayList, OpaqueNode}; -use gfx::font_context::{FontContext, FontContextInfo}; +use gfx::font_context::FontContext; use gfx::render_task::{RenderMsg, RenderChan, RenderLayer}; use gfx::{render_task, color}; use script::dom::bindings::js::JS; @@ -44,6 +44,7 @@ use script::script_task::{ReflowCompleteMsg, ScriptChan, SendEventMsg}; use servo_msg::compositor_msg::Scrollable; use servo_msg::constellation_msg::{ConstellationChan, PipelineId, Failure, FailureMsg}; use servo_net::image_cache_task::{ImageCacheTask, ImageResponseMsg}; +use gfx::font_cache_task::{FontCacheTask}; use servo_net::local_image_cache::{ImageResponder, LocalImageCache}; use servo_util::geometry::Au; use servo_util::geometry; @@ -84,6 +85,9 @@ pub struct LayoutTask { /// The channel on which messages can be sent to the image cache. pub image_cache_task: ImageCacheTask, + /// Public interface to the font cache task. + pub font_cache_task: FontCacheTask, + /// The local image cache. pub local_image_cache: Arc<Mutex<LocalImageCache>>, @@ -278,6 +282,7 @@ impl LayoutTask { script_chan: ScriptChan, render_chan: RenderChan, img_cache_task: ImageCacheTask, + font_cache_task: FontCacheTask, opts: Opts, time_profiler_chan: TimeProfilerChan, shutdown_chan: Sender<()>) { @@ -293,6 +298,7 @@ impl LayoutTask { script_chan, render_chan, img_cache_task, + font_cache_task, &opts, time_profiler_chan); layout.start(); @@ -309,6 +315,7 @@ impl LayoutTask { script_chan: ScriptChan, render_chan: RenderChan, image_cache_task: ImageCacheTask, + font_cache_task: FontCacheTask, opts: &Opts, time_profiler_chan: TimeProfilerChan) -> LayoutTask { @@ -328,6 +335,7 @@ impl LayoutTask { script_chan: script_chan, render_chan: render_chan, image_cache_task: image_cache_task.clone(), + font_cache_task: font_cache_task, local_image_cache: local_image_cache, screen_size: screen_size, @@ -349,18 +357,12 @@ impl LayoutTask { // Create a layout context for use in building display lists, hit testing, &c. fn build_layout_context(&self, reflow_root: &LayoutNode, url: &Url) -> LayoutContext { - let font_context_info = FontContextInfo { - backend: self.opts.render_backend, - needs_font_list: true, - time_profiler_chan: self.time_profiler_chan.clone(), - }; - LayoutContext { image_cache: self.local_image_cache.clone(), screen_size: self.screen_size.clone(), constellation_chan: self.constellation_chan.clone(), layout_chan: self.chan.clone(), - font_context_info: font_context_info, + font_cache_task: self.font_cache_task.clone(), stylist: &*self.stylist, url: (*url).clone(), reflow_root: OpaqueNodeMethods::from_layout_node(reflow_root), @@ -594,7 +596,7 @@ impl LayoutTask { // FIXME(pcwalton): This is a pretty bogus thing to do. Essentially this is a workaround // for libgreen having slow TLS. let mut font_context_opt = if self.parallel_traversal.is_none() { - Some(box FontContext::new(layout_ctx.font_context_info.clone())) + Some(box FontContext::new(layout_ctx.font_cache_task.clone())) } else { None }; |