From 3c16245b5b52fc947a9a2765ab038d13b375d5e3 Mon Sep 17 00:00:00 2001 From: "william.xie" Date: Fri, 26 Jun 2015 04:18:33 -0700 Subject: [Ozone] enable video scaling when playing on overlay When video playback on overlay, framebuffer needs to be scaled according to the display size. Considerring overlay hardware doesn't support scaling well, this CL is target to enable video scaling by VPP (video post processing unit) to get video playback working with correct size on overlay. BUG=499220 TEST=Enable Ozone hardware overlay, play h264 video, zoom webpage, verify that video is scaling along with webpage Review URL: https://codereview.chromium.org/1156893002 Cr-Commit-Position: refs/heads/master@{#336352} --- ui/ozone/platform/cast/surface_factory_cast.cc | 4 +++ ui/ozone/platform/drm/gpu/gbm_buffer.cc | 37 ++++++++++++++++++++++++++ ui/ozone/platform/drm/gpu/gbm_buffer.h | 7 +++++ ui/ozone/public/native_pixmap.h | 10 +++++++ 4 files changed, 58 insertions(+) (limited to 'ui') diff --git a/ui/ozone/platform/cast/surface_factory_cast.cc b/ui/ozone/platform/cast/surface_factory_cast.cc index 9a0a466..3288f43 100644 --- a/ui/ozone/platform/cast/surface_factory_cast.cc +++ b/ui/ozone/platform/cast/surface_factory_cast.cc @@ -197,6 +197,10 @@ scoped_refptr SurfaceFactoryCast::CreateNativePixmap( const gfx::RectF& crop_rect) override { return true; } + void SetScalingCallback(const ScalingCallback& scaling_callback) override {} + scoped_refptr GetScaledPixmap(gfx::Size new_size) override { + return nullptr; + } private: ~CastPixmap() override {} diff --git a/ui/ozone/platform/drm/gpu/gbm_buffer.cc b/ui/ozone/platform/drm/gpu/gbm_buffer.cc index 8da5e5d..c92ba44 100644 --- a/ui/ozone/platform/drm/gpu/gbm_buffer.cc +++ b/ui/ozone/platform/drm/gpu/gbm_buffer.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/trace_event/trace_event.h" +#include "ui/gfx/geometry/size_conversions.h" #include "ui/ozone/platform/drm/gpu/drm_window.h" #include "ui/ozone/platform/drm/gpu/gbm_device.h" @@ -83,6 +84,14 @@ bool GbmPixmap::Initialize() { return true; } +void GbmPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) { + scaling_callback_ = scaling_callback; +} + +scoped_refptr GbmPixmap::GetScaledPixmap(gfx::Size new_size) { + return scaling_callback_.Run(new_size); +} + GbmPixmap::~GbmPixmap() { if (dma_buf_ > 0) close(dma_buf_); @@ -105,9 +114,37 @@ bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, gfx::OverlayTransform plane_transform, const gfx::Rect& display_bounds, const gfx::RectF& crop_rect) { + gfx::Size required_size; + if (plane_z_order && + ShouldApplyScaling(display_bounds, crop_rect, &required_size)) { + scoped_refptr scaled_pixmap = GetScaledPixmap(required_size); + if (scaled_pixmap) { + return scaled_pixmap->ScheduleOverlayPlane( + widget, plane_z_order, plane_transform, display_bounds, crop_rect); + } else { + return false; + } + } + screen_manager_->GetWindow(widget)->QueueOverlayPlane(OverlayPlane( buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); return true; } +bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, + const gfx::RectF& crop_rect, + gfx::Size* required_size) { + if (crop_rect.width() == 0 || crop_rect.height() == 0) { + PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; + return false; + } + + gfx::Size pixmap_size = buffer_->GetSize(); + // If the required size is not integer-sized, round it to the next integer. + *required_size = gfx::ToCeiledSize( + gfx::SizeF(display_bounds.width() / crop_rect.width(), + display_bounds.height() / crop_rect.height())); + return pixmap_size != *required_size; +} + } // namespace ui diff --git a/ui/ozone/platform/drm/gpu/gbm_buffer.h b/ui/ozone/platform/drm/gpu/gbm_buffer.h index 3f0c5d7..4f420e7 100644 --- a/ui/ozone/platform/drm/gpu/gbm_buffer.h +++ b/ui/ozone/platform/drm/gpu/gbm_buffer.h @@ -39,6 +39,8 @@ class GbmPixmap : public NativePixmap { GbmPixmap(const scoped_refptr& buffer, ScreenManager* screen_manager); bool Initialize(); + void SetScalingCallback(const ScalingCallback& scaling_callback) override; + scoped_refptr GetScaledPixmap(gfx::Size new_size) override; // NativePixmap: void* GetEGLClientBuffer() override; @@ -54,12 +56,17 @@ class GbmPixmap : public NativePixmap { private: ~GbmPixmap() override; + bool ShouldApplyScaling(const gfx::Rect& display_bounds, + const gfx::RectF& crop_rect, + gfx::Size* required_size); scoped_refptr buffer_; int dma_buf_ = -1; ScreenManager* screen_manager_; // Not owned. + ScalingCallback scaling_callback_; + DISALLOW_COPY_AND_ASSIGN(GbmPixmap); }; diff --git a/ui/ozone/public/native_pixmap.h b/ui/ozone/public/native_pixmap.h index a1204f7..0251a12 100644 --- a/ui/ozone/public/native_pixmap.h +++ b/ui/ozone/public/native_pixmap.h @@ -5,6 +5,7 @@ #ifndef UI_OZONE_PUBLIC_NATIVE_PIXMAP_H_ #define UI_OZONE_PUBLIC_NATIVE_PIXMAP_H_ +#include "base/bind.h" #include "base/memory/ref_counted.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/overlay_transform.h" @@ -43,6 +44,15 @@ class NativePixmap : public base::RefCountedThreadSafe { const gfx::Rect& display_bounds, const gfx::RectF& crop_rect) = 0; + // This represents a callback function pointing to scaling unit like VPP + // to do scaling operations on native pixmap with required size. + typedef base::Callback(gfx::Size)> + ScalingCallback; + + // Set callback function for the pixmap used for scaling. + virtual void SetScalingCallback(const ScalingCallback& scaling_callback) = 0; + virtual scoped_refptr GetScaledPixmap(gfx::Size new_size) = 0; + protected: virtual ~NativePixmap() {} -- cgit v1.1