mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1347641 - Implement the BlobImageRenderer binding glue. r=jrmuizel
This commit is contained in:
parent
96f05a89cc
commit
4a5a35a9a2
@ -40,6 +40,8 @@ parent:
|
||||
sync Create(IntSize aSize);
|
||||
sync AddImage(ImageKey aImageKey, IntSize aSize, uint32_t aStride,
|
||||
SurfaceFormat aFormat, ByteBuffer aBytes);
|
||||
async AddBlobImage(ImageKey aImageKey, IntSize aSize, uint32_t aStride,
|
||||
SurfaceFormat aFormat, ByteBuffer aBytes);
|
||||
sync UpdateImage(ImageKey aImageKey, IntSize aSize,
|
||||
SurfaceFormat aFormat, ByteBuffer aBytes);
|
||||
sync DeleteImage(ImageKey aImageKey);
|
||||
|
@ -158,7 +158,7 @@ WebRenderBridgeParent::Destroy()
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
WebRenderBridgeParent::RecvAddImage(const wr::ImageKey& aImageKey,
|
||||
const gfx::IntSize& aSize,
|
||||
const gfx::IntSize& aSize,
|
||||
const uint32_t& aStride,
|
||||
const gfx::SurfaceFormat& aFormat,
|
||||
const ByteBuffer& aBuffer)
|
||||
@ -174,6 +174,24 @@ WebRenderBridgeParent::RecvAddImage(const wr::ImageKey& aImageKey,
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
WebRenderBridgeParent::RecvAddBlobImage(const wr::ImageKey& aImageKey,
|
||||
const gfx::IntSize& aSize,
|
||||
const uint32_t& aStride,
|
||||
const gfx::SurfaceFormat& aFormat,
|
||||
const ByteBuffer& aBuffer)
|
||||
{
|
||||
if (mDestroyed) {
|
||||
return IPC_OK();
|
||||
}
|
||||
MOZ_ASSERT(mApi);
|
||||
wr::ImageDescriptor descriptor(aSize, aStride, aFormat);
|
||||
mApi->AddBlobImage(aImageKey, descriptor,
|
||||
aBuffer.AsSlice());
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
WebRenderBridgeParent::RecvAddRawFont(const wr::FontKey& aFontKey,
|
||||
const ByteBuffer& aBuffer,
|
||||
|
@ -68,6 +68,11 @@ public:
|
||||
const uint32_t& aStride,
|
||||
const gfx::SurfaceFormat& aFormat,
|
||||
const ByteBuffer& aBuffer) override;
|
||||
mozilla::ipc::IPCResult RecvAddBlobImage(const wr::ImageKey& aImageKey,
|
||||
const gfx::IntSize& aSize,
|
||||
const uint32_t& aStride,
|
||||
const gfx::SurfaceFormat& aFormat,
|
||||
const ByteBuffer& aBuffer) override;
|
||||
mozilla::ipc::IPCResult RecvAddRawFont(const wr::FontKey& aFontKey,
|
||||
const ByteBuffer& aBuffer,
|
||||
const uint32_t& aFontIndex) override;
|
||||
|
40
gfx/webrender_bindings/Moz2DImageRenderer.cpp
Normal file
40
gfx/webrender_bindings/Moz2DImageRenderer.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#include "mozilla/Range.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "WebRenderTypes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace wr {
|
||||
|
||||
static bool Moz2DRenderCallback(const Range<uint8_t> aBlob,
|
||||
gfx::IntSize aSize,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
Range<uint8_t> output)
|
||||
{
|
||||
return false; // TODO(nical)
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool wr_moz2d_render_cb(const WrByteSlice blob,
|
||||
uint32_t width, uint32_t height,
|
||||
mozilla::wr::ImageFormat aFormat,
|
||||
WrByteSlice output)
|
||||
{
|
||||
return mozilla::wr::Moz2DRenderCallback(mozilla::wr::ByteSliceToRange(blob),
|
||||
mozilla::gfx::IntSize(width, height),
|
||||
mozilla::wr::WrImageFormatToSurfaceFormat(aFormat),
|
||||
mozilla::wr::ByteSliceToRange(output));
|
||||
}
|
||||
|
||||
} // extern
|
||||
|
||||
|
@ -302,6 +302,16 @@ WebRenderAPI::AddImage(ImageKey key, const ImageDescriptor& aDescriptor,
|
||||
RangeToByteSlice(aBytes));
|
||||
}
|
||||
|
||||
void
|
||||
WebRenderAPI::AddBlobImage(ImageKey key, const ImageDescriptor& aDescriptor,
|
||||
Range<uint8_t> aBytes)
|
||||
{
|
||||
wr_api_add_blob_image(mWrApi,
|
||||
key,
|
||||
&aDescriptor,
|
||||
RangeToByteSlice(aBytes));
|
||||
}
|
||||
|
||||
void
|
||||
WebRenderAPI::AddExternalImageHandle(ImageKey key,
|
||||
gfx::IntSize aSize,
|
||||
|
@ -67,6 +67,10 @@ public:
|
||||
const ImageDescriptor& aDescriptor,
|
||||
Range<uint8_t> aBytes);
|
||||
|
||||
void AddBlobImage(wr::ImageKey aKey,
|
||||
const ImageDescriptor& aDescriptor,
|
||||
Range<uint8_t> aBytes);
|
||||
|
||||
void AddExternalImageHandle(ImageKey key,
|
||||
gfx::IntSize aSize,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
|
@ -60,6 +60,20 @@ SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat) {
|
||||
}
|
||||
}
|
||||
|
||||
inline gfx::SurfaceFormat
|
||||
WrImageFormatToSurfaceFormat(ImageFormat aFormat) {
|
||||
switch (aFormat) {
|
||||
case ImageFormat::RGBA8:
|
||||
return gfx::SurfaceFormat::B8G8R8A8;
|
||||
case ImageFormat::A8:
|
||||
return gfx::SurfaceFormat::A8;
|
||||
case ImageFormat::RGB8:
|
||||
return gfx::SurfaceFormat::B8G8R8;
|
||||
default:
|
||||
return gfx::SurfaceFormat::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
struct ImageDescriptor: public WrImageDescriptor {
|
||||
ImageDescriptor(const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat)
|
||||
{
|
||||
@ -427,6 +441,10 @@ inline WrByteSlice RangeToByteSlice(mozilla::Range<uint8_t> aRange) {
|
||||
return WrByteSlice { aRange.begin().get(), aRange.length() };
|
||||
}
|
||||
|
||||
inline mozilla::Range<uint8_t> ByteSliceToRange(WrByteSlice aWrSlice) {
|
||||
return mozilla::Range<uint8_t>(aWrSlice.mBuffer, aWrSlice.mLength);
|
||||
}
|
||||
|
||||
struct BuiltDisplayList {
|
||||
VecU8 dl;
|
||||
WrBuiltDisplayListDescriptor dl_desc;
|
||||
|
@ -17,6 +17,7 @@ EXPORTS.mozilla.webrender += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'Moz2DImageRenderer.cpp',
|
||||
'RendererOGL.cpp',
|
||||
'RenderTextureHost.cpp',
|
||||
'RenderThread.cpp',
|
||||
|
@ -2,6 +2,8 @@ use std::ffi::CString;
|
||||
use std::{mem, slice};
|
||||
use std::path::PathBuf;
|
||||
use std::os::raw::{c_void, c_char};
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use gleam::gl;
|
||||
|
||||
use webrender_traits::{AuxiliaryLists, AuxiliaryListsDescriptor, BorderDetails, BorderRadius};
|
||||
@ -12,6 +14,8 @@ use webrender_traits::{ExternalEvent, ExternalImageId, FilterOp, FontKey, GlyphI
|
||||
use webrender_traits::{GradientStop, IdNamespace, ImageBorder, ImageData, ImageDescriptor};
|
||||
use webrender_traits::{ImageFormat, ImageKey, ImageMask, ImageRendering, ItemRange, LayerPixel};
|
||||
use webrender_traits::{LayoutPoint, LayoutRect, LayoutSize, LayoutTransform, MixBlendMode};
|
||||
use webrender_traits::{BlobImageData, BlobImageRenderer, BlobImageResult, BlobImageError};
|
||||
use webrender_traits::{BlobImageDescriptor, RasterizedBlobImage};
|
||||
use webrender_traits::{NinePatchDescriptor, NormalBorder, PipelineId, PropertyBinding, RenderApi};
|
||||
use webrender_traits::RepeatMode;
|
||||
use webrender::renderer::{Renderer, RendererOptions};
|
||||
@ -753,6 +757,7 @@ pub extern "C" fn wr_window_new(window_id: WrWindowId,
|
||||
enable_subpixel_aa: true,
|
||||
enable_profiler: enable_profiler,
|
||||
recorder: recorder,
|
||||
blob_image_renderer: Some(Box::new(Moz2dImageRenderer::new())),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@ -792,6 +797,19 @@ pub extern "C" fn wr_api_add_image(api: &mut RenderApi,
|
||||
None);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wr_api_add_blob_image(api: &mut RenderApi,
|
||||
image_key: ImageKey,
|
||||
descriptor: &WrImageDescriptor,
|
||||
bytes: ByteSlice) {
|
||||
assert!(unsafe { is_in_compositor_thread() });
|
||||
let copied_bytes = bytes.as_slice().to_owned();
|
||||
api.add_image(image_key,
|
||||
descriptor.to_descriptor(),
|
||||
ImageData::new_blob_image(copied_bytes),
|
||||
None);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wr_api_add_external_image_handle(api: &mut RenderApi,
|
||||
image_key: ImageKey,
|
||||
@ -1341,3 +1359,63 @@ pub unsafe extern "C" fn wr_dp_push_built_display_list(state: &mut WrState,
|
||||
|
||||
state.frame_builder.dl_builder.push_built_display_list(dl, aux);
|
||||
}
|
||||
|
||||
struct Moz2dImageRenderer {
|
||||
images: HashMap<ImageKey, BlobImageResult>
|
||||
}
|
||||
|
||||
impl BlobImageRenderer for Moz2dImageRenderer {
|
||||
fn request_blob_image(&mut self,
|
||||
key: ImageKey,
|
||||
data: Arc<BlobImageData>,
|
||||
descriptor: &BlobImageDescriptor) {
|
||||
let result = self.render_blob_image(data, descriptor);
|
||||
self.images.insert(key, result);
|
||||
}
|
||||
|
||||
fn resolve_blob_image(&mut self, key: ImageKey) -> BlobImageResult {
|
||||
return match self.images.remove(&key) {
|
||||
Some(result) => result,
|
||||
None => Err(BlobImageError::InvalidKey),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Moz2dImageRenderer {
|
||||
fn new() -> Self {
|
||||
Moz2dImageRenderer {
|
||||
images: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_blob_image(&mut self, data: Arc<BlobImageData>, descriptor: &BlobImageDescriptor) -> BlobImageResult {
|
||||
let mut output = Vec::with_capacity(
|
||||
(descriptor.width * descriptor.height * descriptor.format.bytes_per_pixel().unwrap()) as usize
|
||||
);
|
||||
|
||||
unsafe {
|
||||
if wr_moz2d_render_cb(ByteSlice::new(&data[..]),
|
||||
descriptor.width,
|
||||
descriptor.height,
|
||||
descriptor.format,
|
||||
MutByteSlice::new(output.as_mut_slice())) {
|
||||
return Ok(RasterizedBlobImage {
|
||||
width: descriptor.width,
|
||||
height: descriptor.height,
|
||||
data: output,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Err(BlobImageError::Other("unimplemented!".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
// TODO: figure out the API for tiled blob images.
|
||||
fn wr_moz2d_render_cb(blob: ByteSlice,
|
||||
width: u32,
|
||||
height: u32,
|
||||
format: ImageFormat,
|
||||
output: MutByteSlice) -> bool;
|
||||
}
|
||||
|
@ -540,6 +540,10 @@ WR_INLINE void
|
||||
wr_api_add_image(WrAPI* api, WrImageKey key, const WrImageDescriptor* descriptor, const WrByteSlice aSlice)
|
||||
WR_FUNC;
|
||||
|
||||
WR_INLINE void
|
||||
wr_api_add_blob_image(WrAPI* api, WrImageKey key, const WrImageDescriptor* descriptor, const WrByteSlice aSlice)
|
||||
WR_FUNC;
|
||||
|
||||
WR_INLINE void
|
||||
wr_api_add_external_image_handle(WrAPI* api, WrImageKey key, uint32_t width, uint32_t height,
|
||||
WrImageFormat format, uint64_t external_image_id)
|
||||
|
Loading…
Reference in New Issue
Block a user