Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: content/common/gpu/media/vaapi_drm_picture.cc

Issue 1422563002: [Ozone] Enables overlay render format setting path and by default use UYVY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_descriptor_posix.h" 5 #include "base/file_descriptor_posix.h"
6 #include "content/common/gpu/media/va_surface.h" 6 #include "content/common/gpu/media/va_surface.h"
7 #include "content/common/gpu/media/vaapi_drm_picture.h" 7 #include "content/common/gpu/media/vaapi_drm_picture.h"
8 #include "content/common/gpu/media/vaapi_wrapper.h" 8 #include "content/common/gpu/media/vaapi_wrapper.h"
9 #include "third_party/libva/va/drm/va_drm.h" 9 #include "third_party/libva/va/drm/va_drm.h"
10 #include "third_party/libva/va/va.h" 10 #include "third_party/libva/va/va.h"
11 #include "third_party/libva/va/va_drmcommon.h" 11 #include "third_party/libva/va/va_drmcommon.h"
12 #include "ui/gfx/gpu_memory_buffer.h" 12 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/gl/gl_bindings.h" 13 #include "ui/gl/gl_bindings.h"
14 #include "ui/gl/gl_image_ozone_native_pixmap.h" 14 #include "ui/gl/gl_image_ozone_native_pixmap.h"
15 #include "ui/gl/scoped_binders.h" 15 #include "ui/gl/scoped_binders.h"
16 #include "ui/ozone/public/native_pixmap.h" 16 #include "ui/ozone/public/native_pixmap.h"
17 #include "ui/ozone/public/ozone_platform.h" 17 #include "ui/ozone/public/ozone_platform.h"
18 #include "ui/ozone/public/surface_factory_ozone.h" 18 #include "ui/ozone/public/surface_factory_ozone.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 int GetVASurfaceFormatFromPixmapFormat(int fmt) {
23 switch (fmt) {
24 case GBM_FORMAT_XRGB8888:
25 return VA_FOURCC_BGRX;
kalyank 2015/10/21 19:48:41 Hmm do we need this conversion ? GBM_FORMAT_* are
marcheu1 2015/10/21 19:58:57 Sadly, there are formats like GBM_BO_FORMAT_XRGB88
kalyank 2015/10/21 20:20:00 We shouldn't be using GBM_BO_FORMAT_XRGB8888 at al
william.xie1 2015/10/22 07:35:41 Suggested by Spang, here is gfx::BufferFormat to V
william.xie1 2015/10/22 07:35:41 Acknowledged.
26 case GBM_FORMAT_UYVY:
27 return VA_FOURCC_UYVY;
28 default:
29 NOTREACHED();
30 return 0;
31 }
32 }
33
22 VaapiDrmPicture::VaapiDrmPicture( 34 VaapiDrmPicture::VaapiDrmPicture(
23 VaapiWrapper* vaapi_wrapper, 35 VaapiWrapper* vaapi_wrapper,
24 const base::Callback<bool(void)>& make_context_current, 36 const base::Callback<bool(void)>& make_context_current,
25 int32 picture_buffer_id, 37 int32 picture_buffer_id,
26 uint32 texture_id, 38 uint32 texture_id,
27 const gfx::Size& size) 39 const gfx::Size& size)
28 : VaapiPicture(picture_buffer_id, texture_id, size), 40 : VaapiPicture(picture_buffer_id, texture_id, size),
29 vaapi_wrapper_(vaapi_wrapper), 41 vaapi_wrapper_(vaapi_wrapper),
30 make_context_current_(make_context_current), 42 make_context_current_(make_context_current),
31 weak_this_factory_(this) { 43 weak_this_factory_(this) {
(...skipping 15 matching lines...) Expand all
47 int dmabuf_fd = pixmap->GetDmaBufFd(); 59 int dmabuf_fd = pixmap->GetDmaBufFd();
48 if (dmabuf_fd < 0) { 60 if (dmabuf_fd < 0) {
49 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap"; 61 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap";
50 return nullptr; 62 return nullptr;
51 } 63 }
52 int dmabuf_pitch = pixmap->GetDmaBufPitch(); 64 int dmabuf_pitch = pixmap->GetDmaBufPitch();
53 65
54 // Create a VASurface out of the created buffer using the dmabuf. 66 // Create a VASurface out of the created buffer using the dmabuf.
55 VASurfaceAttribExternalBuffers va_attrib_extbuf; 67 VASurfaceAttribExternalBuffers va_attrib_extbuf;
56 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); 68 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf));
57 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX; 69 va_attrib_extbuf.pixel_format =
70 GetVASurfaceFormatFromPixmapFormat(pixmap->GetPixelFormat());
58 va_attrib_extbuf.width = pixmap_size.width(); 71 va_attrib_extbuf.width = pixmap_size.width();
59 va_attrib_extbuf.height = pixmap_size.height(); 72 va_attrib_extbuf.height = pixmap_size.height();
60 va_attrib_extbuf.data_size = pixmap_size.height() * dmabuf_pitch; 73 va_attrib_extbuf.data_size = pixmap_size.height() * dmabuf_pitch;
61 va_attrib_extbuf.num_planes = 1; 74 va_attrib_extbuf.num_planes = 1;
62 va_attrib_extbuf.pitches[0] = dmabuf_pitch; 75 va_attrib_extbuf.pitches[0] = dmabuf_pitch;
63 va_attrib_extbuf.offsets[0] = 0; 76 va_attrib_extbuf.offsets[0] = 0;
64 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); 77 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd);
65 va_attrib_extbuf.num_buffers = 1; 78 va_attrib_extbuf.num_buffers = 1;
66 va_attrib_extbuf.flags = 0; 79 va_attrib_extbuf.flags = 0;
67 va_attrib_extbuf.private_data = NULL; 80 va_attrib_extbuf.private_data = NULL;
68 81
69 std::vector<VASurfaceAttrib> va_attribs; 82 std::vector<VASurfaceAttrib> va_attribs;
70 va_attribs.resize(2); 83 va_attribs.resize(2);
71 84
72 va_attribs[0].type = VASurfaceAttribMemoryType; 85 va_attribs[0].type = VASurfaceAttribMemoryType;
73 va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE; 86 va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
74 va_attribs[0].value.type = VAGenericValueTypeInteger; 87 va_attribs[0].value.type = VAGenericValueTypeInteger;
75 va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; 88 va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
76 89
77 va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor; 90 va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor;
78 va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE; 91 va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
79 va_attribs[1].value.type = VAGenericValueTypePointer; 92 va_attribs[1].value.type = VAGenericValueTypePointer;
80 va_attribs[1].value.value.p = &va_attrib_extbuf; 93 va_attribs[1].value.value.p = &va_attrib_extbuf;
81 94
82 scoped_refptr<VASurface> va_surface = vaapi_wrapper_->CreateUnownedSurface( 95 scoped_refptr<VASurface> va_surface = vaapi_wrapper_->CreateUnownedSurface(
83 VA_RT_FORMAT_RGB32, pixmap_size, va_attribs); 96 va_attrib_extbuf.pixel_format == VA_FOURCC_UYVY ? VA_RT_FORMAT_YUV422
97 : VA_RT_FORMAT_RGB32,
98 pixmap_size, va_attribs);
84 if (!va_surface) { 99 if (!va_surface) {
85 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; 100 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap";
86 return nullptr; 101 return nullptr;
87 } 102 }
88 103
89 return va_surface; 104 return va_surface;
90 } 105 }
91 106
92 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CreateNativePixmap( 107 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CreateNativePixmap(
93 gfx::Size size) { 108 gfx::Size size,
109 gfx::BufferFormat format) {
94 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); 110 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
95 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); 111 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
96 112
97 // Create a buffer from Ozone. 113 // Create a buffer from Ozone.
98 return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, 114 return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
99 gfx::BufferFormat::BGRX_8888,
100 gfx::BufferUsage::SCANOUT); 115 gfx::BufferUsage::SCANOUT);
101 } 116 }
102 117
103 bool VaapiDrmPicture::Initialize() { 118 bool VaapiDrmPicture::Initialize() {
104 // We want to create a VASurface and an EGLImage out of the same 119 // We want to create a VASurface and an EGLImage out of the same
105 // memory buffer, so we can output decoded pictures to it using 120 // memory buffer, so we can output decoded pictures to it using
106 // VAAPI and also use it to paint with GL. 121 // VAAPI and also use it to paint with GL.
107 pixmap_ = CreateNativePixmap(size()); 122 pixmap_ = CreateNativePixmap(size(), gfx::BufferFormat::BGRX_8888);
108 if (!pixmap_) { 123 if (!pixmap_) {
109 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; 124 LOG(ERROR) << "Failed creating an Ozone NativePixmap";
110 return false; 125 return false;
111 } 126 }
112 127
113 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size()); 128 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size());
114 if (!va_surface_) { 129 if (!va_surface_) {
115 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; 130 LOG(ERROR) << "Failed creating VASurface for NativePixmap";
116 return false; 131 return false;
117 } 132 }
(...skipping 19 matching lines...) Expand all
137 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { 152 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) {
138 LOG(ERROR) << "Failed to bind texture to GLImage"; 153 LOG(ERROR) << "Failed to bind texture to GLImage";
139 return false; 154 return false;
140 } 155 }
141 156
142 return true; 157 return true;
143 } 158 }
144 159
145 bool VaapiDrmPicture::DownloadFromSurface( 160 bool VaapiDrmPicture::DownloadFromSurface(
146 const scoped_refptr<VASurface>& va_surface) { 161 const scoped_refptr<VASurface>& va_surface) {
147 return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), 162 return vaapi_wrapper_->BlitSurface(va_surface, va_surface_);
148 va_surface_->id(), va_surface_->size());
149 } 163 }
150 164
151 // static 165 // static
152 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CallScalePixmap( 166 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CallScalePixmap(
153 base::WeakPtr<VaapiDrmPicture> weak_ptr, 167 base::WeakPtr<VaapiDrmPicture> weak_ptr,
154 gfx::Size new_size) { 168 gfx::Size new_size) {
155 if (!weak_ptr.get()) { 169 if (!weak_ptr.get()) {
156 LOG(ERROR) << "Failed scaling NativePixmap as scaling " 170 LOG(ERROR) << "Failed scaling NativePixmap as scaling "
157 "unit(VaapiDrmPicture) is deleted"; 171 "unit(VaapiDrmPicture) is deleted";
158 return nullptr; 172 return nullptr;
159 } 173 }
160 return weak_ptr->ScalePixmap(new_size); 174 return weak_ptr->ScalePixmap(new_size);
161 } 175 }
162 176
163 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap( 177 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap(
164 gfx::Size new_size) { 178 gfx::Size new_size) {
165 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) { 179 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) {
166 scaled_pixmap_ = CreateNativePixmap(new_size); 180 scaled_pixmap_ = CreateNativePixmap(new_size, gfx::BufferFormat::UYVY_422);
kalyank 2015/10/21 19:48:41 We use UYUY format when scaling is needed otherwis
kalyank 2015/10/21 21:32:23 Using YUV formats has benefits when video buffer c
seanvk 2015/10/21 21:38:34 Agree with @kalyank. We should not be assuming ha
william.xie1 2015/10/22 07:35:41 Done.
william.xie1 2015/10/22 07:35:41 Done.
167 if (!scaled_pixmap_) { 181 if (!scaled_pixmap_) {
168 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling"; 182 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling";
169 scaled_va_surface_ = nullptr; 183 scaled_va_surface_ = nullptr;
170 return nullptr; 184 return nullptr;
171 } 185 }
172 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size); 186 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size);
173 if (!scaled_va_surface_) { 187 if (!scaled_va_surface_) {
174 LOG(ERROR) << "Failed creating VA Surface for pixmap"; 188 LOG(ERROR) << "Failed creating VA Surface for pixmap";
175 scaled_pixmap_ = nullptr; 189 scaled_pixmap_ = nullptr;
176 return nullptr; 190 return nullptr;
177 } 191 }
178 } 192 }
179 193
180 DCHECK(scaled_pixmap_); 194 DCHECK(scaled_pixmap_);
181 bool vpp_result = vaapi_wrapper_->BlitSurface( 195 bool vpp_result =
182 va_surface_->id(), va_surface_->size(), scaled_va_surface_->id(), 196 vaapi_wrapper_->BlitSurface(va_surface_, scaled_va_surface_);
183 scaled_va_surface_->size());
184 if (!vpp_result) { 197 if (!vpp_result) {
185 LOG(ERROR) << "Failed scaling NativePixmap"; 198 LOG(ERROR) << "Failed scaling NativePixmap";
186 scaled_pixmap_ = nullptr; 199 scaled_pixmap_ = nullptr;
187 scaled_va_surface_ = nullptr; 200 scaled_va_surface_ = nullptr;
188 return nullptr; 201 return nullptr;
189 } 202 }
190 203
191 return scaled_pixmap_; 204 return scaled_pixmap_;
192 } 205 }
193 206
194 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() { 207 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() {
195 return gl_image_; 208 return gl_image_;
196 } 209 }
197 210
198 bool VaapiDrmPicture::AllowOverlay() const { 211 bool VaapiDrmPicture::AllowOverlay() const {
199 return true; 212 return true;
200 } 213 }
201 214
202 } // namespace 215 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698