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 <vector> |
| 6 |
5 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
6 #include "content/common/gpu/media/va_surface.h" | 8 #include "content/common/gpu/media/va_surface.h" |
7 #include "content/common/gpu/media/vaapi_drm_picture.h" | 9 #include "content/common/gpu/media/vaapi_drm_picture.h" |
8 #include "content/common/gpu/media/vaapi_wrapper.h" | 10 #include "content/common/gpu/media/vaapi_wrapper.h" |
9 #include "third_party/libva/va/drm/va_drm.h" | 11 #include "third_party/libva/va/drm/va_drm.h" |
10 #include "third_party/libva/va/va.h" | 12 #include "third_party/libva/va/va.h" |
11 #include "third_party/libva/va/va_drmcommon.h" | 13 #include "third_party/libva/va/va_drmcommon.h" |
| 14 #include "third_party/webrtc/base/scoped_ref_ptr.h" |
12 #include "ui/gfx/gpu_memory_buffer.h" | 15 #include "ui/gfx/gpu_memory_buffer.h" |
13 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_image_linux_dma_buffer.h" | 17 #include "ui/gl/gl_image_linux_dma_buffer.h" |
15 #include "ui/gl/scoped_binders.h" | 18 #include "ui/gl/scoped_binders.h" |
16 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | 19 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" |
17 #include "ui/ozone/public/native_pixmap.h" | 20 #include "ui/ozone/public/native_pixmap.h" |
18 #include "ui/ozone/public/ozone_platform.h" | 21 #include "ui/ozone/public/ozone_platform.h" |
19 #include "ui/ozone/public/surface_factory_ozone.h" | 22 #include "ui/ozone/public/surface_factory_ozone.h" |
20 | 23 |
21 namespace content { | 24 namespace content { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; | 58 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; |
56 return false; | 59 return false; |
57 } | 60 } |
58 | 61 |
59 // Get the dmabuf of the created buffer. | 62 // Get the dmabuf of the created buffer. |
60 int dmabuf_fd = pixmap_->GetDmaBufFd(); | 63 int dmabuf_fd = pixmap_->GetDmaBufFd(); |
61 if (dmabuf_fd < 0) { | 64 if (dmabuf_fd < 0) { |
62 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap"; | 65 LOG(ERROR) << "Failed to get dmabuf from an Ozone NativePixmap"; |
63 return false; | 66 return false; |
64 } | 67 } |
65 int dmabuf_pitch = pixmap_->GetDmaBufPitch(); | 68 std::vector<int> dmabuf_pitches = { pixmap_->GetDmaBufPitch() }; |
66 | 69 |
67 // Create a VASurface out of the created buffer using the dmabuf. | 70 // Create a VASurface out of the created buffer using the dmabuf. |
68 VASurfaceAttribExternalBuffers va_attrib_extbuf; | 71 VASurfaceAttribExternalBuffers va_attrib_extbuf; |
69 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); | 72 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); |
70 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX; | 73 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX; |
71 va_attrib_extbuf.width = size().width(); | 74 va_attrib_extbuf.width = size().width(); |
72 va_attrib_extbuf.height = size().height(); | 75 va_attrib_extbuf.height = size().height(); |
73 va_attrib_extbuf.data_size = size().height() * dmabuf_pitch; | 76 va_attrib_extbuf.data_size = size().height() * dmabuf_pitches[0]; |
74 va_attrib_extbuf.num_planes = 1; | 77 va_attrib_extbuf.num_planes = 1; |
75 va_attrib_extbuf.pitches[0] = dmabuf_pitch; | 78 va_attrib_extbuf.pitches[0] = dmabuf_pitches[0]; |
76 va_attrib_extbuf.offsets[0] = 0; | 79 va_attrib_extbuf.offsets[0] = 0; |
77 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); | 80 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); |
78 va_attrib_extbuf.num_buffers = 1; | 81 va_attrib_extbuf.num_buffers = 1; |
79 va_attrib_extbuf.flags = 0; | 82 va_attrib_extbuf.flags = 0; |
80 va_attrib_extbuf.private_data = NULL; | 83 va_attrib_extbuf.private_data = NULL; |
81 | 84 |
82 std::vector<VASurfaceAttrib> va_attribs; | 85 std::vector<VASurfaceAttrib> va_attribs; |
83 va_attribs.resize(2); | 86 va_attribs.resize(2); |
84 | 87 |
85 va_attribs[0].type = VASurfaceAttribMemoryType; | 88 va_attribs[0].type = VASurfaceAttribMemoryType; |
(...skipping 11 matching lines...) Expand all Loading... |
97 if (!va_surface_) { | 100 if (!va_surface_) { |
98 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; | 101 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; |
99 return false; | 102 return false; |
100 } | 103 } |
101 | 104 |
102 if (!make_context_current_.Run()) | 105 if (!make_context_current_.Run()) |
103 return false; | 106 return false; |
104 | 107 |
105 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, | 108 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, |
106 texture_id()); | 109 texture_id()); |
107 gl_image_ = ui::GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmap( | 110 const std::vector<gfx::GpuMemoryBuffer::Format> formats( |
108 pixmap_, size(), gfx::GpuMemoryBuffer::BGRA_8888, GL_RGBA); | 111 1, gfx::GpuMemoryBuffer::BGRA_8888); |
| 112 const std::vector<scoped_refptr<ui::NativePixmap>> pixmaps(1, pixmap_); |
| 113 gl_image_ = |
| 114 ui::GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmaps( |
| 115 1, pixmaps, size(), formats, GL_RGBA); |
109 if (!gl_image_) { | 116 if (!gl_image_) { |
110 LOG(ERROR) << "Failed to create GLImage"; | 117 LOG(ERROR) << "Failed to create GLImage"; |
111 return false; | 118 return false; |
112 } | 119 } |
113 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { | 120 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { |
114 LOG(ERROR) << "Failed to bind texture to GLImage"; | 121 LOG(ERROR) << "Failed to bind texture to GLImage"; |
115 return false; | 122 return false; |
116 } | 123 } |
117 | 124 |
118 return true; | 125 return true; |
119 } | 126 } |
120 | 127 |
121 bool VaapiDrmPicture::DownloadFromSurface( | 128 bool VaapiDrmPicture::DownloadFromSurface( |
122 const scoped_refptr<VASurface>& va_surface) { | 129 const scoped_refptr<VASurface>& va_surface) { |
123 return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), | 130 return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), |
124 va_surface_->id(), va_surface_->size()); | 131 va_surface_->id(), va_surface_->size()); |
125 } | 132 } |
126 | 133 |
127 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() { | 134 scoped_refptr<gfx::GLImage> VaapiDrmPicture::GetImageToBind() { |
128 return gl_image_; | 135 return gl_image_; |
129 } | 136 } |
130 | 137 |
131 bool VaapiDrmPicture::AllowOverlay() const { | 138 bool VaapiDrmPicture::AllowOverlay() const { |
132 return true; | 139 return true; |
133 } | 140 } |
134 | 141 |
135 } // namespace | 142 } // namespace |
OLD | NEW |