OLD | NEW |
---|---|
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 // Format for storing the video decoded pictures | |
Pawel Osciak
2015/10/30 02:38:34
Nit: please use dots at the end of sentences.
Also
william.xie1
2015/10/30 08:52:17
Done.
| |
23 const gfx::BufferFormat kPictureStorageFormat = gfx::BufferFormat::BGRX_8888; | |
24 // Format for renderring the video pictures | |
Pawel Osciak
2015/10/30 02:38:34
This is also not precise enough. We don't use this
william.xie1
2015/10/30 08:52:17
Done.
| |
25 const gfx::BufferFormat kPictureRenderFormat = gfx::BufferFormat::UYVY_422; | |
26 | |
27 uint32_t BufferFormatToVAFourCC(gfx::BufferFormat fmt) { | |
28 switch (fmt) { | |
29 case gfx::BufferFormat::BGRX_8888: | |
30 return VA_FOURCC_BGRX; | |
31 case gfx::BufferFormat::UYVY_422: | |
32 return VA_FOURCC_UYVY; | |
33 default: | |
34 NOTREACHED(); | |
35 return 0; | |
36 } | |
37 } | |
38 | |
39 uint32_t VAFourCCToVARTFormat(uint32_t fourcc) { | |
40 switch (fourcc) { | |
41 case VA_FOURCC_UYVY: | |
42 return VA_RT_FORMAT_YUV422; | |
43 case VA_FOURCC_BGRX: | |
44 return VA_RT_FORMAT_RGB32; | |
45 default: | |
46 NOTREACHED(); | |
47 return 0; | |
48 } | |
49 } | |
50 | |
22 VaapiDrmPicture::VaapiDrmPicture( | 51 VaapiDrmPicture::VaapiDrmPicture( |
23 VaapiWrapper* vaapi_wrapper, | 52 VaapiWrapper* vaapi_wrapper, |
24 const base::Callback<bool(void)>& make_context_current, | 53 const base::Callback<bool(void)>& make_context_current, |
25 int32 picture_buffer_id, | 54 int32 picture_buffer_id, |
26 uint32 texture_id, | 55 uint32 texture_id, |
27 const gfx::Size& size) | 56 const gfx::Size& size) |
28 : VaapiPicture(picture_buffer_id, texture_id, size), | 57 : VaapiPicture(picture_buffer_id, texture_id, size), |
29 vaapi_wrapper_(vaapi_wrapper), | 58 vaapi_wrapper_(vaapi_wrapper), |
30 make_context_current_(make_context_current), | 59 make_context_current_(make_context_current), |
31 weak_this_factory_(this) { | 60 weak_this_factory_(this) { |
(...skipping 15 matching lines...) Expand all Loading... | |
47 int dmabuf_fd = pixmap->GetDmaBufFd(); | 76 int dmabuf_fd = pixmap->GetDmaBufFd(); |
48 if (dmabuf_fd < 0) { | 77 if (dmabuf_fd < 0) { |
49 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap"; | 78 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap"; |
50 return nullptr; | 79 return nullptr; |
51 } | 80 } |
52 int dmabuf_pitch = pixmap->GetDmaBufPitch(); | 81 int dmabuf_pitch = pixmap->GetDmaBufPitch(); |
53 | 82 |
54 // Create a VASurface out of the created buffer using the dmabuf. | 83 // Create a VASurface out of the created buffer using the dmabuf. |
55 VASurfaceAttribExternalBuffers va_attrib_extbuf; | 84 VASurfaceAttribExternalBuffers va_attrib_extbuf; |
56 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); | 85 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); |
57 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX; | 86 va_attrib_extbuf.pixel_format = |
87 BufferFormatToVAFourCC(pixmap->GetBufferFormat()); | |
58 va_attrib_extbuf.width = pixmap_size.width(); | 88 va_attrib_extbuf.width = pixmap_size.width(); |
59 va_attrib_extbuf.height = pixmap_size.height(); | 89 va_attrib_extbuf.height = pixmap_size.height(); |
60 va_attrib_extbuf.data_size = pixmap_size.height() * dmabuf_pitch; | 90 va_attrib_extbuf.data_size = pixmap_size.height() * dmabuf_pitch; |
61 va_attrib_extbuf.num_planes = 1; | 91 va_attrib_extbuf.num_planes = 1; |
62 va_attrib_extbuf.pitches[0] = dmabuf_pitch; | 92 va_attrib_extbuf.pitches[0] = dmabuf_pitch; |
63 va_attrib_extbuf.offsets[0] = 0; | 93 va_attrib_extbuf.offsets[0] = 0; |
64 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); | 94 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); |
65 va_attrib_extbuf.num_buffers = 1; | 95 va_attrib_extbuf.num_buffers = 1; |
66 va_attrib_extbuf.flags = 0; | 96 va_attrib_extbuf.flags = 0; |
67 va_attrib_extbuf.private_data = NULL; | 97 va_attrib_extbuf.private_data = NULL; |
68 | 98 |
69 std::vector<VASurfaceAttrib> va_attribs; | 99 std::vector<VASurfaceAttrib> va_attribs; |
70 va_attribs.resize(2); | 100 va_attribs.resize(2); |
71 | 101 |
72 va_attribs[0].type = VASurfaceAttribMemoryType; | 102 va_attribs[0].type = VASurfaceAttribMemoryType; |
73 va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE; | 103 va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE; |
74 va_attribs[0].value.type = VAGenericValueTypeInteger; | 104 va_attribs[0].value.type = VAGenericValueTypeInteger; |
75 va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; | 105 va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; |
76 | 106 |
77 va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor; | 107 va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor; |
78 va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE; | 108 va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE; |
79 va_attribs[1].value.type = VAGenericValueTypePointer; | 109 va_attribs[1].value.type = VAGenericValueTypePointer; |
80 va_attribs[1].value.value.p = &va_attrib_extbuf; | 110 va_attribs[1].value.value.p = &va_attrib_extbuf; |
81 | 111 |
82 scoped_refptr<VASurface> va_surface = vaapi_wrapper_->CreateUnownedSurface( | 112 scoped_refptr<VASurface> va_surface = vaapi_wrapper_->CreateUnownedSurface( |
83 VA_RT_FORMAT_RGB32, pixmap_size, va_attribs); | 113 VAFourCCToVARTFormat(va_attrib_extbuf.pixel_format), pixmap_size, |
114 va_attribs); | |
84 if (!va_surface) { | 115 if (!va_surface) { |
85 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; | 116 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; |
86 return nullptr; | 117 return nullptr; |
87 } | 118 } |
88 | 119 |
89 return va_surface; | 120 return va_surface; |
90 } | 121 } |
91 | 122 |
92 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CreateNativePixmap( | 123 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CreateNativePixmap( |
93 gfx::Size size) { | 124 gfx::Size size, |
125 gfx::BufferFormat format) { | |
94 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); | 126 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
95 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); | 127 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
96 | 128 |
97 // Create a buffer from Ozone. | 129 // Create a buffer from Ozone. |
98 return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, | 130 return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format, |
99 gfx::BufferFormat::BGRX_8888, | |
100 gfx::BufferUsage::SCANOUT); | 131 gfx::BufferUsage::SCANOUT); |
101 } | 132 } |
102 | 133 |
103 bool VaapiDrmPicture::Initialize() { | 134 bool VaapiDrmPicture::Initialize() { |
104 // We want to create a VASurface and an EGLImage out of the same | 135 // 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 | 136 // memory buffer, so we can output decoded pictures to it using |
106 // VAAPI and also use it to paint with GL. | 137 // VAAPI and also use it to paint with GL. |
107 pixmap_ = CreateNativePixmap(size()); | 138 pixmap_ = CreateNativePixmap(size(), kPictureStorageFormat); |
108 if (!pixmap_) { | 139 if (!pixmap_) { |
109 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; | 140 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; |
110 return false; | 141 return false; |
111 } | 142 } |
112 | 143 |
113 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size()); | 144 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size()); |
114 if (!va_surface_) { | 145 if (!va_surface_) { |
115 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; | 146 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; |
116 return false; | 147 return false; |
117 } | 148 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 LOG(ERROR) << "Failed scaling NativePixmap as scaling " | 187 LOG(ERROR) << "Failed scaling NativePixmap as scaling " |
157 "unit(VaapiDrmPicture) is deleted"; | 188 "unit(VaapiDrmPicture) is deleted"; |
158 return nullptr; | 189 return nullptr; |
159 } | 190 } |
160 return weak_ptr->ScalePixmap(new_size); | 191 return weak_ptr->ScalePixmap(new_size); |
161 } | 192 } |
162 | 193 |
163 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap( | 194 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap( |
164 gfx::Size new_size) { | 195 gfx::Size new_size) { |
165 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) { | 196 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) { |
166 scaled_pixmap_ = CreateNativePixmap(new_size); | 197 scaled_pixmap_ = CreateNativePixmap(new_size, kPictureRenderFormat); |
kalyank
2015/10/29 17:49:40
Sorry, if I wasn't clear earlier, hardcoding the f
Pawel Osciak
2015/10/30 02:38:34
+1 to this, this is basically what I was hoping fo
william.xie1
2015/10/30 08:52:17
Done.
william.xie1
2015/10/30 08:52:17
Done.
william.xie1
2015/10/30 08:52:17
We get the optimal format from ozone platform, cur
seanvk
2015/10/30 15:20:43
Keep in mind too that SoC x86 platforms may use ot
| |
167 if (!scaled_pixmap_) { | 198 if (!scaled_pixmap_) { |
168 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling"; | 199 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling"; |
169 scaled_va_surface_ = nullptr; | 200 scaled_va_surface_ = nullptr; |
170 return nullptr; | 201 return nullptr; |
171 } | 202 } |
172 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size); | 203 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size); |
173 if (!scaled_va_surface_) { | 204 if (!scaled_va_surface_) { |
174 LOG(ERROR) << "Failed creating VA Surface for pixmap"; | 205 LOG(ERROR) << "Failed creating VA Surface for pixmap"; |
175 scaled_pixmap_ = nullptr; | 206 scaled_pixmap_ = nullptr; |
176 return nullptr; | 207 return nullptr; |
(...skipping 16 matching lines...) Expand all Loading... | |
193 | 224 |
194 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() { | 225 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() { |
195 return gl_image_; | 226 return gl_image_; |
196 } | 227 } |
197 | 228 |
198 bool VaapiDrmPicture::AllowOverlay() const { | 229 bool VaapiDrmPicture::AllowOverlay() const { |
199 return true; | 230 return true; |
200 } | 231 } |
201 | 232 |
202 } // namespace | 233 } // namespace |
OLD | NEW |