Bug 1591837 - Support specification of FBO id in native compositor interface. r=mstange

Platform differences between DirectComposition and CoreAnimation
mean that WR needs to bind the FBO ID that the underlying platform
returns as part of the surface binding operation.

Differential Revision: https://phabricator.services.mozilla.com/D50760

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Glenn Watson 2019-10-28 20:38:57 +00:00
Родитель 770ea8cdd6
Коммит d9b66a11dc
8 изменённых файлов: 54 добавлений и 22 удалений

Просмотреть файл

@ -36,9 +36,9 @@ void wr_compositor_begin_frame(void* aCompositor) {
}
void wr_compositor_bind(void* aCompositor, wr::NativeSurfaceId aId,
wr::DeviceIntPoint* aOffset) {
wr::DeviceIntPoint* aOffset, uint32_t* aFboId) {
RenderCompositor* compositor = static_cast<RenderCompositor*>(aCompositor);
compositor->Bind(aId, aOffset);
compositor->Bind(aId, aOffset, aFboId);
}
void wr_compositor_create_surface(void* aCompositor, wr::NativeSurfaceId aId,

Просмотреть файл

@ -68,7 +68,8 @@ class RenderCompositor {
// Interface for wr::Compositor
virtual void CompositorBeginFrame() {}
virtual void CompositorEndFrame() {}
virtual void Bind(wr::NativeSurfaceId aId, wr::DeviceIntPoint* aOffset) {}
virtual void Bind(wr::NativeSurfaceId aId, wr::DeviceIntPoint* aOffset,
uint32_t* aFboId) {}
virtual void Unbind() {}
virtual void CreateSurface(wr::NativeSurfaceId aId, wr::DeviceIntSize aSize) {
}

Просмотреть файл

@ -25,7 +25,7 @@ use webrender::{
BinaryRecorder, Compositor, DebugFlags, Device, ExternalImage, ExternalImageHandler, ExternalImageSource,
NativeSurfaceId, PipelineInfo, ProfilerHooks, RecordedFrameHandle, Renderer, RendererOptions, RendererStats,
SceneBuilderHooks, ShaderPrecacheFlags, Shaders, ThreadListener, UploadMethod, VertexUsageHint,
WrShaders, set_profiler_hooks, CompositorConfig
WrShaders, set_profiler_hooks, CompositorConfig, NativeSurfaceInfo
};
use thread_profiler::register_thread_with_profiler;
use moz2d_renderer::Moz2dBlobImageHandler;
@ -1149,6 +1149,7 @@ extern "C" {
compositor: *mut c_void,
id: NativeSurfaceId,
offset: &mut DeviceIntPoint,
fbo_id: &mut u32,
);
fn wr_compositor_unbind(compositor: *mut c_void);
fn wr_compositor_begin_frame(compositor: *mut c_void);
@ -1193,16 +1194,22 @@ impl Compositor for WrCompositor {
fn bind(
&mut self,
id: NativeSurfaceId,
) -> DeviceIntPoint {
let mut offset = DeviceIntPoint::zero();
) -> NativeSurfaceInfo {
let mut surface_info = NativeSurfaceInfo {
origin: DeviceIntPoint::zero(),
fbo_id: 0,
};
unsafe {
wr_compositor_bind(
self.0,
id,
&mut offset,
&mut surface_info.origin,
&mut surface_info.fbo_id,
);
}
offset
surface_info
}
fn unbind(

Просмотреть файл

@ -55,13 +55,16 @@ impl webrender::Compositor for DirectCompositeInterface {
fn bind(
&mut self,
id: webrender::NativeSurfaceId,
) -> DeviceIntPoint {
) -> webrender::NativeSurfaceInfo {
let (x, y) = compositor::bind_surface(
self.window,
id.0,
);
DeviceIntPoint::new(x, y)
webrender::NativeSurfaceInfo {
origin: DeviceIntPoint::new(x, y),
fbo_id: 0,
}
}
fn unbind(&mut self) {

Просмотреть файл

@ -200,6 +200,27 @@ impl CompositeState {
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct NativeSurfaceId(pub u64);
/// Information about a bound surface that the native compositor
/// returns to WR.
#[repr(C)]
#[derive(Copy, Clone)]
pub struct NativeSurfaceInfo {
/// An offset into the surface that WR should draw. Some compositing
/// implementations (notably, DirectComposition) use texture atlases
/// when the surface sizes are small. In this case, an offset can
/// be returned into the larger texture where WR should draw. This
/// can be (0, 0) if texture atlases are not used.
pub origin: DeviceIntPoint,
/// The ID of the FBO that WR should bind to, in order to draw to
/// the bound surface. On Windows (ANGLE) this will always be 0,
/// since creating a p-buffer sets the default framebuffer to
/// be the DirectComposition surface. On Mac, this will be non-zero,
/// since it identifies the IOSurface that has been bound to draw to.
// TODO(gw): This may need to be a larger / different type for WR
// backends that are not GL.
pub fbo_id: u32,
}
/// Defines an interface to a native (OS level) compositor. If supplied
/// by the client application, then picture cache slices will be
/// composited by the OS compositor, rather than drawn via WR batches.
@ -225,7 +246,7 @@ pub trait Compositor {
fn bind(
&mut self,
id: NativeSurfaceId,
) -> DeviceIntPoint;
) -> NativeSurfaceInfo;
/// Unbind the surface. This is called by WR when it has
/// finished issuing OpenGL commands on the current surface.

Просмотреть файл

@ -1082,6 +1082,7 @@ pub enum DrawTarget {
/// An OS compositor surface
NativeSurface {
offset: DeviceIntPoint,
external_fbo_id: u32,
dimensions: DeviceIntSize,
},
}
@ -1732,21 +1733,21 @@ impl Device {
) {
let (fbo_id, rect, depth_available) = match target {
DrawTarget::Default { rect, .. } => {
(Some(self.default_draw_fbo), rect, true)
(self.default_draw_fbo, rect, true)
}
DrawTarget::Texture { dimensions, fbo_id, with_depth, .. } => {
let rect = FramebufferIntRect::new(
FramebufferIntPoint::zero(),
FramebufferIntSize::from_untyped(dimensions.to_untyped()),
);
(Some(fbo_id), rect, with_depth)
(fbo_id, rect, with_depth)
},
DrawTarget::External { fbo, size } => {
(Some(fbo), size.into(), false)
(fbo, size.into(), false)
}
DrawTarget::NativeSurface { offset, dimensions, .. } => {
DrawTarget::NativeSurface { external_fbo_id, offset, dimensions, .. } => {
(
None,
FBOId(external_fbo_id),
FramebufferIntRect::new(
FramebufferIntPoint::from_untyped(offset.to_untyped()),
FramebufferIntSize::from_untyped(dimensions.to_untyped()),
@ -1757,9 +1758,7 @@ impl Device {
};
self.depth_available = depth_available;
if let Some(fbo_id) = fbo_id {
self.bind_draw_target_impl(fbo_id);
}
self.bind_draw_target_impl(fbo_id);
self.gl.viewport(
rect.origin.x,
rect.origin.y,

Просмотреть файл

@ -201,7 +201,7 @@ pub extern crate api;
extern crate webrender_build;
#[doc(hidden)]
pub use crate::composite::{CompositorConfig, Compositor, NativeSurfaceId};
pub use crate::composite::{CompositorConfig, Compositor, NativeSurfaceId, NativeSurfaceInfo};
pub use crate::device::{build_shader_strings, UploadMethod, VertexUsageHint, get_gl_target};
pub use crate::device::{ProgramBinary, ProgramCache, ProgramCacheObserver, FormatDesc};
pub use crate::device::Device;

Просмотреть файл

@ -5055,7 +5055,7 @@ impl Renderer {
)
}
ResolvedSurfaceTexture::NativeSurface { id, size, .. } => {
let offset = match self.compositor_config {
let surface_info = match self.compositor_config {
CompositorConfig::Native { ref mut compositor, .. } => {
compositor.bind(id)
}
@ -5065,7 +5065,8 @@ impl Renderer {
};
DrawTarget::NativeSurface {
offset,
offset: surface_info.origin,
external_fbo_id: surface_info.fbo_id,
dimensions: size,
}
}