Bug 1397458 - part 4 - supply font variations to WebRender AddFontInstance
MozReview-Commit-ID: 6JSMMVK0GZm
--- a/gfx/layers/ipc/WebRenderMessages.ipdlh
+++ b/gfx/layers/ipc/WebRenderMessages.ipdlh
@@ -110,17 +110,18 @@ struct OpAddRawFont {
};
struct OpDeleteFont {
FontKey key;
};
struct OpAddFontInstance {
MaybeFontInstanceOptions options;
- MaybeFontInstancePlatformOptions platformOptions ;
+ MaybeFontInstancePlatformOptions platformOptions;
+ OffsetRange variations;
FontInstanceKey instanceKey;
FontKey fontKey;
float glyphSize;
};
struct OpDeleteFontInstance {
FontInstanceKey key;
};
--- a/gfx/layers/wr/IpcResourceUpdateQueue.cpp
+++ b/gfx/layers/wr/IpcResourceUpdateQueue.cpp
@@ -277,21 +277,24 @@ IpcResourceUpdateQueue::DeleteFont(wr::F
mUpdates.AppendElement(layers::OpDeleteFont(aKey));
}
void
IpcResourceUpdateQueue::AddFontInstance(wr::FontInstanceKey aKey,
wr::FontKey aFontKey,
float aGlyphSize,
const wr::FontInstanceOptions* aOptions,
- const wr::FontInstancePlatformOptions* aPlatformOptions)
+ const wr::FontInstancePlatformOptions* aPlatformOptions,
+ Range<const gfx::FontVariation> aVariations)
{
+ auto bytes = mWriter.WriteAsBytes(aVariations);
mUpdates.AppendElement(layers::OpAddFontInstance(
aOptions ? Some(*aOptions) : Nothing(),
aPlatformOptions ? Some(*aPlatformOptions) : Nothing(),
+ bytes,
aKey, aFontKey,
aGlyphSize
));
}
void
IpcResourceUpdateQueue::DeleteFontInstance(wr::FontInstanceKey aKey)
{
--- a/gfx/layers/wr/IpcResourceUpdateQueue.h
+++ b/gfx/layers/wr/IpcResourceUpdateQueue.h
@@ -18,16 +18,22 @@ namespace wr {
/// allocations and creates dedicated shmems for large allocations.
class ShmSegmentsWriter {
public:
ShmSegmentsWriter(ipc::IShmemAllocator* aAllocator, size_t aChunkSize);
~ShmSegmentsWriter();
layers::OffsetRange Write(Range<uint8_t> aBytes);
+ template<typename T>
+ layers::OffsetRange WriteAsBytes(Range<T> aValues)
+ {
+ return Write(Range<uint8_t>((uint8_t*)aValues.begin().get(), aValues.length() * sizeof(T)));
+ }
+
void Flush(nsTArray<ipc::Shmem>& aSmallAllocs, nsTArray<ipc::Shmem>& aLargeAllocs);
void Clear();
protected:
void AllocChunk();
layers::OffsetRange AllocLargeChunk(size_t aSize);
@@ -90,17 +96,18 @@ public:
void AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex);
void DeleteFont(wr::FontKey aKey);
void AddFontInstance(wr::FontInstanceKey aKey,
wr::FontKey aFontKey,
float aGlyphSize,
const wr::FontInstanceOptions* aOptions,
- const wr::FontInstancePlatformOptions* aPlatformOptions);
+ const wr::FontInstancePlatformOptions* aPlatformOptions,
+ Range<const gfx::FontVariation> aVariations);
void DeleteFontInstance(wr::FontInstanceKey aKey);
void Clear();
void Flush(nsTArray<layers::OpUpdateResource>& aUpdates,
nsTArray<ipc::Shmem>& aSmallAllocs,
nsTArray<ipc::Shmem>& aLargeAllocs);
--- a/gfx/layers/wr/WebRenderBridgeChild.cpp
+++ b/gfx/layers/wr/WebRenderBridgeChild.cpp
@@ -308,17 +308,24 @@ WebRenderBridgeChild::GetFontKeyForScale
resources.AddRawFont(fontKey, data.mFontBuffer.AsSlice(), data.mFontIndex);
mFontKeys.Put(unscaled, fontKey);
}
instanceKey.mNamespace = GetNamespace();
instanceKey.mHandle = GetNextResourceId();
- resources.AddFontInstance(instanceKey, fontKey, aScaledFont->GetSize(), nullptr, nullptr);
+ Maybe<wr::FontInstanceOptions> options;
+ Maybe<wr::FontInstancePlatformOptions> platformOptions;
+ std::vector<FontVariation> variations;
+ aScaledFont->GetWRFontInstanceOptions(&options, &platformOptions, &variations);
+
+ resources.AddFontInstance(instanceKey, fontKey, aScaledFont->GetSize(),
+ options.ptrOr(nullptr), platformOptions.ptrOr(nullptr),
+ Range<const FontVariation>(variations.data(), variations.size()));
UpdateResources(resources);
mFontInstanceKeys.Put(aScaledFont, instanceKey);
return instanceKey;
}
void
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -292,20 +292,25 @@ WebRenderBridgeParent::UpdateResources(c
if (!reader.Read(op.bytes(), bytes)) {
return false;
}
aUpdates.AddRawFont(op.key(), bytes, op.fontIndex());
break;
}
case OpUpdateResource::TOpAddFontInstance: {
const auto& op = cmd.get_OpAddFontInstance();
+ wr::Vec_u8 variations;
+ if (!reader.Read(op.variations(), variations)) {
+ return false;
+ }
aUpdates.AddFontInstance(op.instanceKey(), op.fontKey(),
op.glyphSize(),
op.options().ptrOr(nullptr),
- op.platformOptions().ptrOr(nullptr));
+ op.platformOptions().ptrOr(nullptr),
+ variations);
break;
}
case OpUpdateResource::TOpDeleteImage: {
const auto& op = cmd.get_OpDeleteImage();
aUpdates.DeleteImage(op.key());
break;
}
case OpUpdateResource::TOpDeleteFont: {
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -563,20 +563,22 @@ ResourceUpdateQueue::DeleteFont(wr::Font
wr_resource_updates_delete_font(mUpdates, aKey);
}
void
ResourceUpdateQueue::AddFontInstance(wr::FontInstanceKey aKey,
wr::FontKey aFontKey,
float aGlyphSize,
const wr::FontInstanceOptions* aOptions,
- const wr::FontInstancePlatformOptions* aPlatformOptions)
+ const wr::FontInstancePlatformOptions* aPlatformOptions,
+ wr::Vec_u8& aVariations)
{
wr_resource_updates_add_font_instance(mUpdates, aKey, aFontKey, aGlyphSize,
- aOptions, aPlatformOptions);
+ aOptions, aPlatformOptions,
+ &aVariations.inner);
}
void
ResourceUpdateQueue::DeleteFontInstance(wr::FontInstanceKey aKey)
{
wr_resource_updates_delete_font_instance(mUpdates, aKey);
}
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -96,17 +96,18 @@ public:
void AddRawFont(wr::FontKey aKey, wr::Vec_u8& aBytes, uint32_t aIndex);
void DeleteFont(wr::FontKey aKey);
void AddFontInstance(wr::FontInstanceKey aKey,
wr::FontKey aFontKey,
float aGlyphSize,
const wr::FontInstanceOptions* aOptions,
- const wr::FontInstancePlatformOptions* aPlatformOptions);
+ const wr::FontInstancePlatformOptions* aPlatformOptions,
+ wr::Vec_u8& aVariations);
void DeleteFontInstance(wr::FontInstanceKey aKey);
void Clear();
// Try to avoid using this when possible.
wr::ResourceUpdates* Raw() { return mUpdates; }
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -84,21 +84,32 @@ pub struct WrVecU8 {
impl WrVecU8 {
fn to_vec(self) -> Vec<u8> {
unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) }
}
// Equivalent to `to_vec` but clears self instead of consuming the value.
fn flush_into_vec(&mut self) -> Vec<u8> {
- let vec = unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) };
+ self.convert_into_vec::<u8>()
+ }
+
+ // Like flush_into_vec, but also does an unsafe conversion to the desired type.
+ fn convert_into_vec<T>(&mut self) -> Vec<T> {
+ let vec = unsafe {
+ Vec::from_raw_parts(
+ self.data as *mut T,
+ self.length / mem::size_of::<T>(),
+ self.capacity / mem::size_of::<T>(),
+ )
+ };
self.data = ptr::null_mut();
self.length = 0;
self.capacity = 0;
- return vec;
+ vec
}
fn from_vec(mut v: Vec<u8>) -> WrVecU8 {
let w = WrVecU8 {
data: v.as_mut_ptr(),
length: v.len(),
capacity: v.capacity(),
};
@@ -958,24 +969,26 @@ pub extern "C" fn wr_resource_updates_de
#[no_mangle]
pub extern "C" fn wr_resource_updates_add_font_instance(
resources: &mut ResourceUpdates,
key: WrFontInstanceKey,
font_key: WrFontKey,
glyph_size: f32,
options: *const FontInstanceOptions,
- platform_options: *const FontInstancePlatformOptions
+ platform_options: *const FontInstancePlatformOptions,
+ variations: &mut WrVecU8,
) {
resources.add_font_instance(
key,
font_key,
Au::from_f32_px(glyph_size),
unsafe { options.as_ref().cloned() },
- unsafe { platform_options.as_ref().cloned() }
+ unsafe { platform_options.as_ref().cloned() },
+ variations.convert_into_vec::<FontVariation>(),
);
}
#[no_mangle]
pub extern "C" fn wr_resource_updates_delete_font_instance(
resources: &mut ResourceUpdates,
key: WrFontInstanceKey
) {
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -1217,17 +1217,18 @@ void wr_resource_updates_add_external_im
WR_FUNC;
WR_INLINE
void wr_resource_updates_add_font_instance(ResourceUpdates *aResources,
WrFontInstanceKey aKey,
WrFontKey aFontKey,
float aGlyphSize,
const FontInstanceOptions *aOptions,
- const FontInstancePlatformOptions *aPlatformOptions)
+ const FontInstancePlatformOptions *aPlatformOptions,
+ WrVecU8 *aVariations)
WR_FUNC;
WR_INLINE
void wr_resource_updates_add_image(ResourceUpdates *aResources,
WrImageKey aImageKey,
const WrImageDescriptor *aDescriptor,
WrVecU8 *aBytes)
WR_FUNC;