Commit 41c3cab8 authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ozone: Add OverlaySurface interface for presenting overlays

This is cleaned up replacement for the functionality provided by
"surfaceless" GLSurface implementations that present to platform windows
(i.e. objects returned from CreateSurfacelessViewGLSurface()).

It is intended for use with vulkan although it currently does not currently
have any dependencies on any vulkan APIs.

Bug: 1097208
Test: ozone_demo --enable-vulkan on eve (with full series)

Change-Id: Ie5318e848f804c8b9f8fbc78372016286d0c3e6b
Reviewed-on: https://chromium-review.googlesource.com/1104864
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570174}
parent 26121cb9
...@@ -78,6 +78,10 @@ jumbo_component("ozone_base") { ...@@ -78,6 +78,10 @@ jumbo_component("ozone_base") {
"public/overlay_candidates_ozone.cc", "public/overlay_candidates_ozone.cc",
"public/overlay_candidates_ozone.h", "public/overlay_candidates_ozone.h",
"public/overlay_manager_ozone.h", "public/overlay_manager_ozone.h",
"public/overlay_plane.cc",
"public/overlay_plane.h",
"public/overlay_surface.cc",
"public/overlay_surface.h",
"public/overlay_surface_candidate.cc", "public/overlay_surface_candidate.cc",
"public/overlay_surface_candidate.h", "public/overlay_surface_candidate.h",
"public/ozone_switches.cc", "public/ozone_switches.cc",
......
...@@ -76,6 +76,7 @@ class OZONE_BASE_EXPORT GLOzone { ...@@ -76,6 +76,7 @@ class OZONE_BASE_EXPORT GLOzone {
// semantics. The surface is not backed by any buffers and is used for // semantics. The surface is not backed by any buffers and is used for
// overlay-only displays. This will return null if surfaceless mode is // overlay-only displays. This will return null if surfaceless mode is
// unsupported. // unsupported.
// TODO(spang): Consider deprecating this and using OverlaySurface for GL.
virtual scoped_refptr<gl::GLSurface> CreateSurfacelessViewGLSurface( virtual scoped_refptr<gl::GLSurface> CreateSurfacelessViewGLSurface(
gfx::AcceleratedWidget window) = 0; gfx::AcceleratedWidget window) = 0;
......
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/public/overlay_plane.h"
namespace ui {
OverlayPlane::OverlayPlane() {}
OverlayPlane::OverlayPlane(scoped_refptr<gfx::NativePixmap> pixmap,
std::unique_ptr<gfx::GpuFence> gpu_fence,
int z_order,
gfx::OverlayTransform plane_transform,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect,
bool enable_blend)
: pixmap(std::move(pixmap)),
gpu_fence(std::move(gpu_fence)),
z_order(z_order),
plane_transform(plane_transform),
display_bounds(display_bounds),
crop_rect(crop_rect),
enable_blend(enable_blend) {}
OverlayPlane::OverlayPlane(OverlayPlane&& other) = default;
OverlayPlane& OverlayPlane::operator=(OverlayPlane&& other) = default;
OverlayPlane::~OverlayPlane() {}
} // namespace ui
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PUBLIC_OVERLAY_PLANE_H_
#define UI_OZONE_PUBLIC_OVERLAY_PLANE_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/gpu_fence.h"
#include "ui/gfx/native_pixmap.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/ozone/ozone_base_export.h"
namespace ui {
// Configuration for a hardware overlay plane.
//
// Modern display hardware is capable of transforming and composing multiple
// images into a final fullscreen image. An OverlayPlane represents one such
// image as well as any transformations that must be applied.
struct OZONE_BASE_EXPORT OverlayPlane {
OverlayPlane();
OverlayPlane(scoped_refptr<gfx::NativePixmap> pixmap,
std::unique_ptr<gfx::GpuFence> gpu_fence,
int z_order,
gfx::OverlayTransform plane_transform,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect,
bool enable_blend);
OverlayPlane(OverlayPlane&& other);
OverlayPlane& operator=(OverlayPlane&& other);
~OverlayPlane();
// Image to be presented by the overlay.
scoped_refptr<gfx::NativePixmap> pixmap;
// Fence which when signaled marks that writes to |pixmap| have completed.
std::unique_ptr<gfx::GpuFence> gpu_fence;
// Specifies the stacking order of the plane relative to the main framebuffer
// located at index 0.
int z_order = 0;
// Specifies how the buffer is to be transformed during composition.
gfx::OverlayTransform plane_transform =
gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE;
// Pixel bounds within the display to position the image.
//
// A fullscreen buffer would use gfx::Rect(display_size_pixels).
gfx::Rect display_bounds;
// Normalized bounds of the image to be displayed in |display_bounds|.
gfx::RectF crop_rect = gfx::RectF(1.f, 1.f);
// Whether alpha blending should be enabled.
bool enable_blend = false;
};
} // namespace ui
#endif // UI_OZONE_PUBLIC_OVERLAY_PLANE_H_
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/public/overlay_surface.h"
namespace ui {
OverlaySurface::OverlaySurface() {}
OverlaySurface::~OverlaySurface() {}
} // namespace ui
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PUBLIC_OVERLAY_SURFACE_H_
#define UI_OZONE_PUBLIC_OVERLAY_SURFACE_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/native_pixmap.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/swap_result.h"
#include "ui/ozone/ozone_base_export.h"
namespace ui {
struct OverlayPlane;
// An overlay surface is similar to a surface, but natively uses overlays and
// does not internally allocate any buffers.
class OZONE_BASE_EXPORT OverlaySurface {
public:
OverlaySurface();
virtual ~OverlaySurface();
// Called with the swap result once the frame is submitted.
//
// If the swap result is gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS, there has
// been a configuration change that necessitates re-allocation of buffers by
// the client (and re-testing of overlay configurations).
using SubmissionCallback = base::OnceCallback<void(gfx::SwapResult)>;
// Called when the frame has been presented.
//
// Buffers are presented in the same order as they are submitted.
using PresentationCallback =
base::OnceCallback<void(const gfx::PresentationFeedback& feedback)>;
// Called when the buffers backing a frame can be reused for rendering.
//
// Buffers are released in the same order as they are submitted. The buffers
// backing a frame will not generally be released until after a replacement
// frame has been submitted.
// TODO(spang): Find out if there's any benefit to using out fences here.
using ReleaseCallback = base::OnceClosure;
// Submits a new frame consisting of |overlay_planes|.
//
// The configuration of |overlay_planes| must have been validated prior to use
// (see CheckOverlaySupport).
//
// Only one frame should be submitted at a time. Once the submission callback
// is made, it is safe to call SubmitFrame() again. Rendered but unsubmitted
// frames can be queued by the client if desired.
//
// The surface owns all buffers backing |overlay_planes| starting at the call
// to SubmitFrame() and ending at the call to |release_callback|. Buffers must
// not be re-used for rendering while owned by the surface.
//
// Each plane in |overlay_planes| can optionally carry a fence that signals
// when writes to its backing buffers have completed. When fences are
// provided, frames can be submitted before rendering completes and each
// buffer will not be read from until its fence has been signaled.
virtual void SubmitFrame(std::vector<OverlayPlane> overlay_planes,
SubmissionCallback submission_callback,
PresentationCallback presentation_callback,
ReleaseCallback release_callback) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(OverlaySurface);
};
} // namespace ui
#endif // UI_OZONE_PUBLIC_OVERLAY_SURFACE_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "gpu/vulkan/buildflags.h" #include "gpu/vulkan/buildflags.h"
#include "ui/gfx/native_pixmap.h" #include "ui/gfx/native_pixmap.h"
#include "ui/ozone/public/overlay_surface.h"
#include "ui/ozone/public/surface_ozone_canvas.h" #include "ui/ozone/public/surface_ozone_canvas.h"
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
...@@ -37,6 +38,11 @@ SurfaceFactoryOzone::CreateVulkanImplementation() { ...@@ -37,6 +38,11 @@ SurfaceFactoryOzone::CreateVulkanImplementation() {
} }
#endif #endif
std::unique_ptr<OverlaySurface> SurfaceFactoryOzone::CreateOverlaySurface(
gfx::AcceleratedWidget widget) {
return nullptr;
}
std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryOzone::CreateCanvasForWidget( std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryOzone::CreateCanvasForWidget(
gfx::AcceleratedWidget widget) { gfx::AcceleratedWidget widget) {
return nullptr; return nullptr;
......
...@@ -35,6 +35,7 @@ class NativePixmap; ...@@ -35,6 +35,7 @@ class NativePixmap;
namespace ui { namespace ui {
class SurfaceOzoneCanvas; class SurfaceOzoneCanvas;
class OverlaySurface;
// The Ozone interface allows external implementations to hook into Chromium to // The Ozone interface allows external implementations to hook into Chromium to
// provide a system specific implementation. The Ozone interface supports two // provide a system specific implementation. The Ozone interface supports two
...@@ -81,6 +82,10 @@ class OZONE_BASE_EXPORT SurfaceFactoryOzone { ...@@ -81,6 +82,10 @@ class OZONE_BASE_EXPORT SurfaceFactoryOzone {
CreateVulkanImplementation(); CreateVulkanImplementation();
#endif #endif
// Creates an overlay surface for a platform window.
virtual std::unique_ptr<OverlaySurface> CreateOverlaySurface(
gfx::AcceleratedWidget window);
// Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget. // Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget.
// //
// Note: The platform must support creation of SurfaceOzoneCanvas from the // Note: The platform must support creation of SurfaceOzoneCanvas from the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment