Bug 1403198 - support WR native font handles in blob image. r=jrmuizel

MozReview-Commit-ID: 1n0z2xNZDxp
This commit is contained in:
Lee Salzman 2017-11-06 20:21:25 -05:00
parent 826eee8b2a
commit 135158086d
3 changed files with 75 additions and 6 deletions

View File

@ -15,8 +15,13 @@
#include <iostream>
#include <unordered_map>
#ifdef MOZ_ENABLE_FREETYPE
#ifdef XP_MACOSX
#include "mozilla/gfx/UnscaledFontMac.h"
#elif defined(XP_WIN)
#include "mozilla/gfx/UnscaledFontDWrite.h"
#elif defined(MOZ_ENABLE_FREETYPE)
#include "mozilla/ThreadLocal.h"
#include "mozilla/gfx/UnscaledFontFreeType.h"
#endif
namespace std {
@ -67,11 +72,35 @@ AddFontData(WrFontKey aKey, const uint8_t *aData, size_t aSize, uint32_t aIndex,
}
}
void
AddNativeFontHandle(WrFontKey aKey, void* aHandle, uint32_t aIndex) {
auto i = sFontDataTable.find(aKey);
if (i == sFontDataTable.end()) {
FontTemplate font;
font.mData = nullptr;
font.mSize = 0;
font.mIndex = 0;
font.mVec = nullptr;
#ifdef XP_MACOSX
font.mUnscaledFont = new UnscaledFontMac(reinterpret_cast<CGFontRef>(aHandle), true);
#elif defined(XP_WIN)
font.mUnscaledFont = new UnscaledFontDWrite(reinterpret_cast<IDWriteFontFace*>(aHandle), nullptr);
#elif defined(ANDROID)
font.mUnscaledFont = new UnscaledFontFreeType(reinterpret_cast<const char*>(aHandle), aIndex);
#else
font.mUnscaledFont = new UnscaledFontFontconfig(reinterpret_cast<const char*>(aHandle), aIndex);
#endif
sFontDataTable[aKey] = font;
}
}
void
DeleteFontData(WrFontKey aKey) {
auto i = sFontDataTable.find(aKey);
if (i != sFontDataTable.end()) {
wr_dec_ref_arc(i->second.mVec);
if (i->second.mVec) {
wr_dec_ref_arc(i->second.mVec);
}
sFontDataTable.erase(i);
}
}
@ -84,12 +113,13 @@ GetUnscaledFont(Translator *aTranslator, wr::FontKey key) {
if (data.mUnscaledFont) {
return data.mUnscaledFont;
}
MOZ_ASSERT(data.mData);
FontType type =
#ifdef XP_MACOSX
FontType::MAC;
#elif XP_WIN
#elif defined(XP_WIN)
FontType::DWRITE;
#elif ANDROID
#elif defined(ANDROID)
FontType::FREETYPE;
#else
FontType::FONTCONFIG;

View File

@ -48,6 +48,11 @@ if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
'RenderD3D11TextureHostOGL.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
DEFINES['MOZ_ENABLE_FREETYPE'] = True
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'

View File

@ -5,10 +5,20 @@ use rayon::ThreadPool;
use std::collections::hash_map::{HashMap, Entry};
use std::mem;
use std::os::raw::c_void;
use std::ptr;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::Arc;
#[cfg(target_os = "windows")]
use dwrote;
#[cfg(target_os = "macos")]
use core_foundation::base::TCFType;
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
use std::ffi::CString;
pub struct Moz2dImageRenderer {
blob_commands: HashMap<ImageKey, (Arc<BlobImageData>, Option<TileSize>)>,
@ -104,14 +114,37 @@ impl BlobImageRenderer for Moz2dImageRenderer {
let tile_size = blob.1;
let commands = Arc::clone(&blob.0);
#[cfg(target_os = "windows")]
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
let system_fc = dwrote::FontCollection::system();
let font = system_fc.get_font_from_descriptor(handle).unwrap();
let face = font.create_font_face();
unsafe { AddNativeFontHandle(key, face.as_ptr() as *mut c_void, 0) };
}
#[cfg(target_os = "macos")]
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
unsafe { AddNativeFontHandle(key, handle.0.as_concrete_TypeRef() as *mut c_void, 0) };
}
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
fn process_native_font_handle(key: FontKey, handle: &NativeFontHandle) {
let cstr = CString::new(handle.pathname.clone()).unwrap();
unsafe { AddNativeFontHandle(key, cstr.as_ptr() as *mut c_void, handle.index) };
}
fn process_fonts(mut extra_data: BufReader, resources: &BlobImageResources) {
let font_count = extra_data.read_usize();
for _ in 0..font_count {
let key = extra_data.read_font_key();
let template = resources.get_font_data(key);
if let &FontTemplate::Raw(ref data, ref index) = template {
unsafe { AddFontData(key, data.as_ptr(), data.len(), *index, data); }
match template {
&FontTemplate::Raw(ref data, ref index) => {
unsafe { AddFontData(key, data.as_ptr(), data.len(), *index, data); }
}
&FontTemplate::Native(ref handle) => {
process_native_font_handle(key, handle);
}
}
resources.get_font_data(key);
}
@ -199,6 +232,7 @@ use bindings::WrFontKey;
extern "C" {
#[allow(improper_ctypes)]
fn AddFontData(key: WrFontKey, data: *const u8, size: usize, index: u32, vec: &ArcVecU8);
fn AddNativeFontHandle(key: WrFontKey, handle: *mut c_void, index: u32);
fn DeleteFontData(key: WrFontKey);
}