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

move FontInstance out of webrender_api so it is easier to extend #2028

Merged
merged 1 commit into from Nov 13, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,6 @@
[package]
name = "webrender"
version = "0.53.1"
version = "0.53.2"
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
license = "MPL-2.0"
repository = "https://github.com/servo/webrender"
@@ -5,7 +5,7 @@
use api::{BorderDetails, BorderDisplayItem, BuiltDisplayList};
use api::{ClipAndScrollInfo, ClipId, ColorF, PremultipliedColorF};
use api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DeviceUintRect, DeviceUintSize};
use api::{ExtendMode, FilterOp, FontInstance, FontRenderMode};
use api::{ExtendMode, FilterOp, FontRenderMode};
use api::{GlyphInstance, GlyphOptions, GradientStop, HitTestFlags, HitTestItem, HitTestResult};
use api::{ImageKey, ImageRendering, ItemRange, ItemTag, LayerPoint, LayerPrimitiveInfo, LayerRect};
use api::{LayerPixel, LayerSize, LayerToScrollTransform, LayerVector2D, LayoutVector2D, LineOrientation};
@@ -19,6 +19,7 @@ use clip_scroll_node::{ClipScrollNode, NodeType};
use clip_scroll_tree::ClipScrollTree;
use euclid::{SideOffsets2D, TypedTransform3D, vec2, vec3};
use frame::FrameId;
use glyph_rasterizer::FontInstance;
use gpu_cache::GpuCache;
use internal_types::{FastHashMap, FastHashSet, HardwareCompositeOp};
use picture::{PictureKind, PicturePrimitive};
@@ -2,8 +2,8 @@
* 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 api::{DevicePoint, DeviceUintSize, FontInstance, GlyphKey};
use glyph_rasterizer::GlyphFormat;
use api::{DevicePoint, DeviceUintSize, GlyphKey};
use glyph_rasterizer::{FontInstance, GlyphFormat};
use internal_types::FastHashMap;
use resource_cache::ResourceClassCache;
use std::sync::Arc;
@@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(test)]
use api::{ColorF, ColorU, IdNamespace, LayoutPoint, SubpixelDirection};
use api::{DevicePoint, DeviceUintSize, FontInstance, FontRenderMode};
use api::{FontKey, FontTemplate, GlyphDimensions, GlyphKey};
use api::{IdNamespace, LayoutPoint};
use api::{ColorF, ColorU, DevicePoint, DeviceUintSize};
use api::{FontInstancePlatformOptions, FontRenderMode, FontVariation};
use api::{FontKey, FontTemplate, GlyphDimensions, GlyphKey, SubpixelDirection};
use api::{ImageData, ImageDescriptor, ImageFormat};
#[cfg(test)]
use app_units::Au;
use device::TextureFilter;
use glyph_cache::{CachedGlyphInfo, GlyphCache};
@@ -23,6 +23,58 @@ use std::sync::{Arc, Mutex, MutexGuard};
use std::sync::mpsc::{channel, Receiver, Sender};
use texture_cache::{TextureCache, TextureCacheHandle};

#[derive(Clone, Hash, PartialEq, Eq, Debug, Ord, PartialOrd)]
pub struct FontInstance {
pub font_key: FontKey,
// The font size is in *device* pixels, not logical pixels.
// It is stored as an Au since we need sub-pixel sizes, but
// can't store as a f32 due to use of this type as a hash key.
// TODO(gw): Perhaps consider having LogicalAu and DeviceAu
// or something similar to that.
pub size: Au,
pub color: ColorU,
pub bg_color: ColorU,
pub render_mode: FontRenderMode,
pub subpx_dir: SubpixelDirection,
pub platform_options: Option<FontInstancePlatformOptions>,
pub variations: Vec<FontVariation>,
pub synthetic_italics: bool,
}

impl FontInstance {
pub fn new(
font_key: FontKey,
size: Au,
color: ColorF,
bg_color: ColorU,
render_mode: FontRenderMode,
subpx_dir: SubpixelDirection,
platform_options: Option<FontInstancePlatformOptions>,
variations: Vec<FontVariation>,
synthetic_italics: bool,
) -> Self {
FontInstance {
font_key,
size,
color: color.into(),
bg_color,
render_mode,
subpx_dir,
platform_options,
variations,
synthetic_italics,
}
}

pub fn get_subpx_offset(&self, glyph: &GlyphKey) -> (f64, f64) {
match self.subpx_dir {
SubpixelDirection::None => (0.0, 0.0),
SubpixelDirection::Horizontal => (glyph.subpixel_offset.into(), 0.0),
SubpixelDirection::Vertical => (0.0, glyph.subpixel_offset.into()),
}
}
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum GlyphFormat {
Mono,
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{ColorU, FontKey, FontRenderMode, GlyphDimensions};
use api::{FontInstance, FontVariation, NativeFontHandle};
use api::{FontVariation, NativeFontHandle};
use api::{GlyphKey, SubpixelDirection};
use app_units::Au;
use core_foundation::array::{CFArray, CFArrayRef};
@@ -22,7 +22,7 @@ use core_text;
use core_text::font::{CTFont, CTFontRef};
use core_text::font_descriptor::{kCTFontDefaultOrientation, kCTFontColorGlyphsTrait};
use gamma_lut::{ColorLut, GammaLut};
use glyph_rasterizer::{GlyphFormat, RasterizedGlyph};
use glyph_rasterizer::{FontInstance, GlyphFormat, RasterizedGlyph};
use internal_types::FastHashMap;
use std::collections::hash_map::Entry;
use std::ptr;
@@ -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/. */

use api::{ColorU, GlyphDimensions, GlyphKey, FontInstance, FontKey, FontRenderMode};
use api::{ColorU, GlyphDimensions, GlyphKey, FontKey, FontRenderMode};
use api::{FontInstancePlatformOptions, FontLCDFilter, FontHinting};
use api::{NativeFontHandle, SubpixelDirection};
use api::{FONT_FORCE_AUTOHINT, FONT_NO_AUTOHINT, FONT_EMBEDDED_BITMAP};
@@ -18,7 +18,7 @@ use freetype::freetype::{FT_LOAD_COLOR, FT_LOAD_DEFAULT, FT_LOAD_FORCE_AUTOHINT}
use freetype::freetype::{FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH, FT_LOAD_NO_AUTOHINT};
use freetype::freetype::{FT_LOAD_NO_BITMAP, FT_LOAD_NO_HINTING, FT_LOAD_VERTICAL_LAYOUT};
use freetype::freetype::{FT_FACE_FLAG_SCALABLE, FT_FACE_FLAG_FIXED_SIZES, FT_Err_Cannot_Render_Glyph};
use glyph_rasterizer::{GlyphFormat, RasterizedGlyph};
use glyph_rasterizer::{FontInstance, GlyphFormat, RasterizedGlyph};
use internal_types::FastHashMap;
use std::{cmp, mem, ptr, slice};
use std::cmp::max;
@@ -2,11 +2,11 @@
* 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 api::{FontInstance, FontInstancePlatformOptions, FontKey, FontRenderMode};
use api::{FontInstancePlatformOptions, FontKey, FontRenderMode};
use api::{ColorU, GlyphDimensions, GlyphKey, SubpixelDirection};
use dwrote;
use gamma_lut::{ColorLut, GammaLut};
use glyph_rasterizer::{GlyphFormat, RasterizedGlyph};
use glyph_rasterizer::{FontInstance, GlyphFormat, RasterizedGlyph};
use internal_types::FastHashMap;
use std::sync::Arc;

@@ -3,14 +3,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{BorderRadius, BuiltDisplayList, ColorF, ComplexClipRegion, DeviceIntRect};
use api::{DevicePoint, ExtendMode, FontInstance, GlyphInstance, GlyphKey};
use api::{DevicePoint, ExtendMode, GlyphInstance, GlyphKey};
use api::{GradientStop, ImageKey, ImageRendering, ItemRange, ItemTag, LayerPoint, LayerRect};
use api::{ClipMode, LayerSize, LayerVector2D, LineOrientation, LineStyle};
use api::{ClipAndScrollInfo, EdgeAaSegmentMask, PremultipliedColorF, TileOffset};
use api::{YuvColorSpace, YuvFormat};
use border::BorderCornerInstance;
use clip::{ClipSourcesHandle, ClipStore, Geometry};
use frame_builder::PrimitiveContext;
use glyph_rasterizer::FontInstance;
use gpu_cache::{GpuBlockData, GpuCache, GpuCacheAddress, GpuCacheHandle, GpuDataRequest,
ToGpuBlocks};
use picture::PicturePrimitive;
@@ -471,11 +471,13 @@ impl RenderBackend {
self.resource_cache
.update_resources(updates, &mut profile_counters.resources);
}
ApiMsg::GetGlyphDimensions(font, glyph_keys, tx) => {
ApiMsg::GetGlyphDimensions(instance_key, glyph_keys, tx) => {
let mut glyph_dimensions = Vec::with_capacity(glyph_keys.len());
for glyph_key in &glyph_keys {
let glyph_dim = self.resource_cache.get_glyph_dimensions(&font, glyph_key);
glyph_dimensions.push(glyph_dim);
if let Some(font) = self.resource_cache.get_font_instance(instance_key) {
for glyph_key in &glyph_keys {
let glyph_dim = self.resource_cache.get_glyph_dimensions(&font, glyph_key);
glyph_dimensions.push(glyph_dim);
}
}
tx.send(glyph_dimensions).unwrap();
}
@@ -6,7 +6,7 @@ use api::{AddFont, BlobImageData, BlobImageResources, ResourceUpdate, ResourceUp
use api::{BlobImageDescriptor, BlobImageError, BlobImageRenderer, BlobImageRequest};
use api::{ColorF, FontRenderMode};
use api::{DevicePoint, DeviceUintRect, DeviceUintSize};
use api::{Epoch, FontInstance, FontInstanceKey, FontKey, FontTemplate};
use api::{Epoch, FontInstanceKey, FontKey, FontTemplate};
use api::{ExternalImageData, ExternalImageType};
use api::{FontInstanceOptions, FontInstancePlatformOptions, FontVariation};
use api::{GlyphDimensions, GlyphKey, IdNamespace};
@@ -16,7 +16,7 @@ use app_units::Au;
use device::TextureFilter;
use frame::FrameId;
use glyph_cache::GlyphCache;
use glyph_rasterizer::{GlyphFormat, GlyphRasterizer, GlyphRequest};
use glyph_rasterizer::{FontInstance, GlyphFormat, GlyphRasterizer, GlyphRequest};
use gpu_cache::{GpuCache, GpuCacheAddress, GpuCacheHandle};
use internal_types::{FastHashMap, FastHashSet, SourceTexture, TextureUpdateList};
use profiler::{ResourceProfileCounters, TextureCacheProfileCounters};
@@ -389,6 +389,11 @@ impl ResourceCache {
self.resources.font_instances.clone()
}

pub fn get_font_instance(&self, instance_key: FontInstanceKey) -> Option<FontInstance> {
let instance_map = self.resources.font_instances.read().unwrap();
instance_map.get(&instance_key).cloned()
}

pub fn add_image_template(
&mut self,
image_key: ImageKey,
@@ -1,6 +1,6 @@
[package]
name = "webrender_api"
version = "0.53.1"
version = "0.53.2"
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
license = "MPL-2.0"
repository = "https://github.com/servo/webrender"
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use {BuiltDisplayList, BuiltDisplayListDescriptor, ClipId, ColorF, DeviceIntPoint, DeviceUintRect};
use {DeviceUintSize, FontInstance, FontInstanceKey, FontInstanceOptions};
use {DeviceUintSize, FontInstanceKey, FontInstanceOptions};
use {FontInstancePlatformOptions, FontKey, FontVariation, GlyphDimensions, GlyphKey, ImageData};
use {ImageDescriptor, ImageKey, ItemTag, LayoutPoint, LayoutSize, LayoutTransform, LayoutVector2D};
use {NativeFontHandle, WorldPoint};
@@ -265,7 +265,7 @@ pub enum ApiMsg {
UpdateResources(ResourceUpdates),
/// Gets the glyph dimensions
GetGlyphDimensions(
FontInstance,
FontInstanceKey,
Vec<GlyphKey>,
MsgSender<Vec<Option<GlyphDimensions>>>,
),
@@ -448,7 +448,7 @@ impl RenderApi {
/// This means that glyph dimensions e.g. for spaces (' ') will mostly be None.
pub fn get_glyph_dimensions(
&self,
font: FontInstance,
font: FontInstanceKey,
glyph_keys: Vec<GlyphKey>,
) -> Vec<Option<GlyphDimensions>> {
let (tx, rx) = channel::msg_channel().unwrap();
@@ -2,8 +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/. */

use {ColorF, ColorU, IdNamespace, LayoutPoint};
use app_units::Au;
use {ColorU, IdNamespace, LayoutPoint};
#[cfg(target_os = "macos")]
use core_foundation::string::CFString;
#[cfg(target_os = "macos")]
@@ -309,58 +308,6 @@ impl Default for FontInstancePlatformOptions {
}
}

#[derive(Clone, Hash, PartialEq, Eq, Debug, Deserialize, Serialize, Ord, PartialOrd)]
pub struct FontInstance {
pub font_key: FontKey,
// The font size is in *device* pixels, not logical pixels.
// It is stored as an Au since we need sub-pixel sizes, but
// can't store as a f32 due to use of this type as a hash key.
// TODO(gw): Perhaps consider having LogicalAu and DeviceAu
// or something similar to that.
pub size: Au,
pub color: ColorU,
pub bg_color: ColorU,
pub render_mode: FontRenderMode,
pub subpx_dir: SubpixelDirection,
pub platform_options: Option<FontInstancePlatformOptions>,
pub variations: Vec<FontVariation>,
pub synthetic_italics: bool,
}

impl FontInstance {
pub fn new(
font_key: FontKey,
size: Au,
color: ColorF,
bg_color: ColorU,
render_mode: FontRenderMode,
subpx_dir: SubpixelDirection,
platform_options: Option<FontInstancePlatformOptions>,
variations: Vec<FontVariation>,
synthetic_italics: bool,
) -> Self {
FontInstance {
font_key,
size,
color: color.into(),
bg_color,
render_mode,
subpx_dir,
platform_options,
variations,
synthetic_italics,
}
}

pub fn get_subpx_offset(&self, glyph: &GlyphKey) -> (f64, f64) {
match self.subpx_dir {
SubpixelDirection::None => (0.0, 0.0),
SubpixelDirection::Horizontal => (glyph.subpixel_offset.into(), 0.0),
SubpixelDirection::Vertical => (0.0, glyph.subpixel_offset.into()),
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Ord, PartialOrd)]
pub struct FontInstanceKey(pub IdNamespace, pub u32);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.