Commit b697fd00 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Fix VAAPI build

Fixes the build after [1] broke it.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2392140

R=mcasas
CC=tmathmeyer

Bug: 1066670, 1127532
Change-Id: I340f91a1d4ba7214ea47fa4b1bb4a368fe5597f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406168Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Reviewed-by: default avatarTed Meyer <tmathmeyer@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809151}
parent c6ecc1b3
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_egl_pixmap.h" #include "ui/gl/gl_image_egl_pixmap.h"
#include "ui/gl/scoped_binders.h" #include "ui/gl/scoped_binders.h"
...@@ -15,25 +17,31 @@ namespace media { ...@@ -15,25 +17,31 @@ namespace media {
namespace { namespace {
inline Pixmap CreatePixmap(const gfx::Size& size) { inline ::Pixmap CreatePixmap(const gfx::Size& size) {
auto* display = gfx::GetXDisplay(); auto* connection = x11::Connection::Get();
if (!display) if (!connection->Ready())
return 0; return base::strict_cast<::Pixmap>(x11::Pixmap::None);
int screen = DefaultScreen(display); auto root = connection->default_root();
auto root = XRootWindow(display, screen);
if (root == BadValue)
return 0;
XWindowAttributes win_attr = {}; uint8_t depth = 0;
// returns 0 on failure, see: if (auto reply = connection->GetGeometry({root}).Sync())
// https://tronche.com/gui/x/xlib/introduction/errors.html#Status depth = reply->depth;
if (!XGetWindowAttributes(display, root, &win_attr)) else
return 0; return base::strict_cast<::Pixmap>(x11::Pixmap::None);
// TODO(tmathmeyer) should we use the depth from libva instead of root window? // TODO(tmathmeyer) should we use the depth from libva instead of root window?
return XCreatePixmap(display, root, size.width(), size.height(), auto pixmap = connection->GenerateId<x11::Pixmap>();
win_attr.depth); uint16_t pixmap_width, pixmap_height;
if (!base::CheckedNumeric<int>(size.width()).AssignIfValid(&pixmap_width) ||
!base::CheckedNumeric<int>(size.height()).AssignIfValid(&pixmap_height)) {
return base::strict_cast<::Pixmap>(x11::Pixmap::None);
}
auto req = connection->CreatePixmap(
{depth, pixmap, root, pixmap_width, pixmap_height});
if (req.Sync().error)
pixmap = x11::Pixmap::None;
return base::strict_cast<::Pixmap>(pixmap);
} }
} // namespace } // namespace
...@@ -71,11 +79,8 @@ VaapiPictureNativePixmapAngle::~VaapiPictureNativePixmapAngle() { ...@@ -71,11 +79,8 @@ VaapiPictureNativePixmapAngle::~VaapiPictureNativePixmapAngle() {
DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
} }
if (x_pixmap_) { if (x_pixmap_)
if (auto* display = gfx::GetXDisplay()) { x11::Connection::Get()->FreePixmap({static_cast<x11::Pixmap>(x_pixmap_)});
XFreePixmap(display, x_pixmap_);
}
}
} }
Status VaapiPictureNativePixmapAngle::Allocate(gfx::BufferFormat format) { Status VaapiPictureNativePixmapAngle::Allocate(gfx::BufferFormat format) {
......
...@@ -46,7 +46,7 @@ class VaapiPictureNativePixmapAngle : public VaapiPictureNativePixmap { ...@@ -46,7 +46,7 @@ class VaapiPictureNativePixmapAngle : public VaapiPictureNativePixmap {
VASurfaceID va_surface_id() const override; VASurfaceID va_surface_id() const override;
private: private:
Pixmap x_pixmap_ = 0; ::Pixmap x_pixmap_ = 0;
DISALLOW_COPY_AND_ASSIGN(VaapiPictureNativePixmapAngle); DISALLOW_COPY_AND_ASSIGN(VaapiPictureNativePixmapAngle);
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_glx.h" #include "ui/gl/gl_image_glx.h"
...@@ -33,7 +34,7 @@ VaapiTFPPicture::VaapiTFPPicture( ...@@ -33,7 +34,7 @@ VaapiTFPPicture::VaapiTFPPicture(
texture_id, texture_id,
client_texture_id, client_texture_id,
texture_target), texture_target),
x_display_(gfx::GetXDisplay()), connection_(x11::Connection::Get()),
x_pixmap_(0) { x_pixmap_(0) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!features::IsUsingOzonePlatform()); DCHECK(!features::IsUsingOzonePlatform());
...@@ -49,7 +50,7 @@ VaapiTFPPicture::~VaapiTFPPicture() { ...@@ -49,7 +50,7 @@ VaapiTFPPicture::~VaapiTFPPicture() {
} }
if (x_pixmap_) if (x_pixmap_)
XFreePixmap(x_display_, x_pixmap_); connection_->FreePixmap({static_cast<x11::Pixmap>(x_pixmap_)});
} }
Status VaapiTFPPicture::Initialize() { Status VaapiTFPPicture::Initialize() {
...@@ -84,16 +85,33 @@ Status VaapiTFPPicture::Allocate(gfx::BufferFormat format) { ...@@ -84,16 +85,33 @@ Status VaapiTFPPicture::Allocate(gfx::BufferFormat format) {
return StatusCode::kVaapiUnsupportedFormat; return StatusCode::kVaapiUnsupportedFormat;
} }
XWindowAttributes win_attr; if (!connection_->Ready())
int screen = DefaultScreen(x_display_); return StatusCode::kVaapiNoPixmap;
XGetWindowAttributes(x_display_, XRootWindow(x_display_, screen), &win_attr);
auto root = connection_->default_root();
uint8_t depth = 0;
if (auto reply = connection_->GetGeometry({root}).Sync())
depth = reply->depth;
else
return StatusCode::kVaapiNoPixmap;
// TODO(posciak): pass the depth required by libva, not the RootWindow's // TODO(posciak): pass the depth required by libva, not the RootWindow's
// depth // depth
x_pixmap_ = XCreatePixmap(x_display_, XRootWindow(x_display_, screen), auto pixmap = connection_->GenerateId<x11::Pixmap>();
size_.width(), size_.height(), win_attr.depth); uint16_t pixmap_width, pixmap_height;
if (!x_pixmap_) { if (!base::CheckedNumeric<int>(size_.width()).AssignIfValid(&pixmap_width) ||
!base::CheckedNumeric<int>(size_.height())
.AssignIfValid(&pixmap_height)) {
return StatusCode::kVaapiNoPixmap;
}
auto req = connection_->CreatePixmap(
{depth, pixmap, root, pixmap_width, pixmap_height});
if (req.Sync().error) {
DLOG(ERROR) << "Failed creating an X Pixmap for TFP"; DLOG(ERROR) << "Failed creating an X Pixmap for TFP";
return StatusCode::kVaapiNoPixmap; return StatusCode::kVaapiNoPixmap;
} else {
x_pixmap_ = base::strict_cast<::Pixmap>(pixmap);
} }
return Initialize(); return Initialize();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "media/gpu/vaapi/vaapi_picture.h" #include "media/gpu/vaapi/vaapi_picture.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/x/connection.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
namespace gl { namespace gl {
...@@ -47,9 +48,9 @@ class VaapiTFPPicture : public VaapiPicture { ...@@ -47,9 +48,9 @@ class VaapiTFPPicture : public VaapiPicture {
private: private:
Status Initialize(); Status Initialize();
Display* x_display_; x11::Connection* const connection_;
Pixmap x_pixmap_; ::Pixmap x_pixmap_;
scoped_refptr<gl::GLImageGLX> glx_image_; scoped_refptr<gl::GLImageGLX> glx_image_;
DISALLOW_COPY_AND_ASSIGN(VaapiTFPPicture); DISALLOW_COPY_AND_ASSIGN(VaapiTFPPicture);
......
...@@ -58,8 +58,13 @@ ...@@ -58,8 +58,13 @@
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#if defined(USE_X11) #if defined(USE_X11)
#include <va/va_x11.h>
#include "ui/gfx/x/x11_types.h" // nogncheck #include "ui/gfx/x/x11_types.h" // nogncheck
typedef XID Drawable;
extern "C" {
#include "media/gpu/vaapi/va_x11.sigs"
}
#endif #endif
#if defined(USE_OZONE) #if defined(USE_OZONE)
......
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