Commit a36f19ef authored by Emircan Uysaler's avatar Emircan Uysaler Committed by Chromium LUCI CQ

[Fuchsia] Handle overlay transforms

This CL adds the corresponding Scenic commands for the received
gfx::OverlayTransform for Fuchsia. This allows us to flip or rotate
the overlay video content.

Bug: 1169182
Change-Id: I9a5689251f3a363cd88db0d9b0bcc1b550cf2133
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644565
Commit-Queue: Emircan Uysaler <emircan@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846369}
parent ddbcd80b
......@@ -8,6 +8,7 @@
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <lib/zx/eventpair.h>
#include "base/numerics/math_constants.h"
#include "ui/ozone/platform/scenic/scenic_gpu_host.h"
#include "ui/ozone/platform/scenic/scenic_surface_factory.h"
......@@ -20,6 +21,27 @@ namespace {
// [-0.5f, 0.5f] range, so 0.01f is small enough to make a difference.
constexpr float kElevationStep = 0.01f;
// Converts OverlayTransform enum to angle in radians.
float OverlayTransformToRadians(gfx::OverlayTransform plane_transform) {
switch (plane_transform) {
case gfx::OVERLAY_TRANSFORM_NONE:
case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL:
case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL:
return 0;
case gfx::OVERLAY_TRANSFORM_ROTATE_90:
return base::kPiFloat * .5f;
case gfx::OVERLAY_TRANSFORM_ROTATE_180:
return base::kPiFloat;
case gfx::OVERLAY_TRANSFORM_ROTATE_270:
return base::kPiFloat * 1.5f;
case gfx::OVERLAY_TRANSFORM_INVALID:
NOTREACHED();
return 0;
}
NOTREACHED();
return 0;
}
} // namespace
ScenicSurface::ScenicSurface(
......@@ -48,6 +70,10 @@ ScenicSurface::~ScenicSurface() {
scenic_surface_factory_->RemoveSurface(window_);
}
ScenicSurface::OverlayViewInfo::OverlayViewInfo(scenic::ViewHolder holder,
scenic::EntityNode node)
: view_holder(std::move(holder)), entity_node(std::move(node)) {}
void ScenicSurface::OnScenicEvents(
std::vector<fuchsia::ui::scenic::Event> events) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -124,6 +150,7 @@ bool ScenicSurface::UpdateOverlayViewPosition(
int plane_z_order,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect,
gfx::OverlayTransform plane_transform,
std::vector<zx::event> acquire_fences) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(overlays_.count(id));
......@@ -131,13 +158,15 @@ bool ScenicSurface::UpdateOverlayViewPosition(
if (overlay_view_info.plane_z_order == plane_z_order &&
overlay_view_info.display_bounds == display_bounds &&
overlay_view_info.crop_rect == crop_rect) {
overlay_view_info.crop_rect == crop_rect &&
overlay_view_info.plane_transform == plane_transform) {
return false;
}
overlay_view_info.plane_z_order = plane_z_order;
overlay_view_info.display_bounds = display_bounds;
overlay_view_info.crop_rect = crop_rect;
overlay_view_info.plane_transform = plane_transform;
for (auto& fence : acquire_fences)
scenic_session_.EnqueueAcquireFence(std::move(fence));
......@@ -205,22 +234,41 @@ void ScenicSurface::UpdateViewHolderScene() {
view_properties.focus_change = false;
info.view_holder.SetViewProperties(std::move(view_properties));
// Scale ImagePipe based on the display bounds and clip rect given.
const float scaled_width =
info.display_bounds.width() /
// We receive |display_bounds| in screen coordinates. Convert them to fit
// 1x1 View, which is later scaled up by the browser process.
float scaled_width = info.display_bounds.width() /
(info.crop_rect.width() * main_shape_size_.width());
const float scaled_height =
info.display_bounds.height() /
float scaled_height = info.display_bounds.height() /
(info.crop_rect.height() * main_shape_size_.height());
info.entity_node.SetScale(scaled_width, scaled_height, 1.f);
// Position ImagePipe based on the display bounds given.
const float scaled_x = info.display_bounds.x() / main_shape_size_.width();
const float scaled_y = info.display_bounds.y() / main_shape_size_.height();
// Position ImagePipe based on the display bounds given.
info.entity_node.SetTranslation(
scaled_x - (0.5f - scaled_width / 2),
scaled_y - (0.5f - scaled_height / 2),
-0.5f + scaled_x + scaled_width / 2,
-0.5f + scaled_y + scaled_height / 2,
(min_z_order - info.plane_z_order) * kElevationStep);
// Apply rotation if given. Scenic expects rotation passed as Quaternion.
const float angle = OverlayTransformToRadians(info.plane_transform);
info.entity_node.SetRotation(
{0.f, 0.f, sinf(angle * .5f), cosf(angle * .5f)});
// Scenic applies scaling before rotation.
if (info.plane_transform == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
info.plane_transform == gfx::OVERLAY_TRANSFORM_ROTATE_270) {
std::swap(scaled_width, scaled_height);
}
// Scenic expects flip as negative scaling.
if (info.plane_transform == gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL) {
scaled_width = -scaled_width;
} else if (info.plane_transform == gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL) {
scaled_height = -scaled_height;
}
// Scale ImagePipe based on the display bounds and clip rect given.
info.entity_node.SetScale(scaled_width, scaled_height, 1.f);
}
main_material_.SetColor(255, 255, 255, 0 > min_z_order ? 254 : 255);
......
......@@ -17,6 +17,7 @@
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/native_pixmap_handle.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/ozone/public/platform_window_surface.h"
namespace ui {
......@@ -58,6 +59,7 @@ class ScenicSurface : public ui::PlatformWindowSurface {
int plane_z_order,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect,
gfx::OverlayTransform plane_transform,
std::vector<zx::event> acquire_fences);
// Remove ViewHolder specified by |id|.
......@@ -93,14 +95,14 @@ class ScenicSurface : public ui::PlatformWindowSurface {
const gfx::AcceleratedWidget window_;
struct OverlayViewInfo {
OverlayViewInfo(scenic::ViewHolder holder, scenic::EntityNode node)
: view_holder(std::move(holder)), entity_node(std::move(node)) {}
OverlayViewInfo(scenic::ViewHolder holder, scenic::EntityNode node);
scenic::ViewHolder view_holder;
scenic::EntityNode entity_node;
int plane_z_order = 0;
gfx::Rect display_bounds;
gfx::RectF crop_rect;
gfx::OverlayTransform plane_transform;
};
std::unordered_map<gfx::SysmemBufferCollectionId,
OverlayViewInfo,
......
......@@ -120,7 +120,7 @@ bool SysmemNativePixmap::ScheduleOverlayPlane(
release_events.push_back(GpuFenceToZxEvent(std::move(fence)));
surface->UpdateOverlayViewPosition(buffer_collection_id, plane_z_order,
display_bounds, crop_rect,
display_bounds, crop_rect, plane_transform,
DuplicateZxEvents(acquire_events));
overlay_view->SetBlendMode(enable_blend);
......
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