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

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

Issue 490233002: VaapiVideoAccelerator: make Vaapi accelerator work with ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after Pawel's review Created 6 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/file_descriptor_posix.h"
6 #include "content/common/gpu/media/va_surface.h"
7 #include "content/common/gpu/media/vaapi_drm_picture.h"
8 #include "content/common/gpu/media/vaapi_wrapper.h"
9 #include "third_party/libva/va/drm/va_drm.h"
10 #include "third_party/libva/va/va.h"
11 #include "third_party/libva/va/va_drmcommon.h"
12 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/gl/gl_bindings.h"
14 #include "ui/gl/gl_image_linux_dma_buffer.h"
15 #include "ui/gl/scoped_binders.h"
16 #include "ui/ozone/public/native_pixmap.h"
17 #include "ui/ozone/public/ozone_platform.h"
18 #include "ui/ozone/public/surface_factory_ozone.h"
19
20 namespace content {
21
22 VaapiDrmPicture::VaapiDrmPicture(
23 scoped_refptr<VaapiWrapper> vaapi_wrapper,
24 const base::Callback<bool(void)> make_context_current,
25 int32 picture_buffer_id,
26 uint32 texture_id,
27 const gfx::Size& size)
28 : VaapiPicture(picture_buffer_id, texture_id, size),
29 vaapi_wrapper_(vaapi_wrapper),
30 make_context_current_(make_context_current) {
31 }
32
33 VaapiDrmPicture::~VaapiDrmPicture() {
34 if (egl_image_.get() && make_context_current_.Run()) {
35 egl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES);
36 egl_image_->Destroy(true);
37
38 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
39 }
40 }
41
42 bool VaapiDrmPicture::Initialize() {
43 VASurfaceAttrib va_attribs[2];
44 VASurfaceAttribExternalBuffers va_attrib_extbuf;
45
46 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
47 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
48
49 pixmap_ =
50 factory->CreateNativePixmap(size(), ui::SurfaceFactoryOzone::RGBA_8888);
51 if (!pixmap_.get()) {
52 LOG(ERROR) << "Failed creating an Ozone NativePixmap";
53 return false;
54 }
55
56 int dmabuf_fd = pixmap_->GetDmaBufFd();
57 if (dmabuf_fd < 0) {
58 LOG(ERROR) << "Failed get dmabuf from an Ozone NativePixmap";
59 return false;
60 }
61 int dmabuf_pitch = pixmap_->GetDmaBufPitch();
62
63 memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf));
64 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX;
65 va_attrib_extbuf.width = size().width();
66 va_attrib_extbuf.height = size().height();
67 va_attrib_extbuf.data_size = size().height() * dmabuf_pitch;
68 va_attrib_extbuf.num_planes = 1;
69 va_attrib_extbuf.pitches[0] = dmabuf_pitch;
70 va_attrib_extbuf.offsets[0] = 0;
71 va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd);
72 va_attrib_extbuf.num_buffers = 1;
73 va_attrib_extbuf.flags = 0;
74 va_attrib_extbuf.private_data = NULL;
75
76 va_attribs[0].type = VASurfaceAttribMemoryType;
77 va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
78 va_attribs[0].value.type = VAGenericValueTypeInteger;
79 va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
80
81 va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor;
82 va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
83 va_attribs[1].value.type = VAGenericValueTypePointer;
84 va_attribs[1].value.value.p = &va_attrib_extbuf;
85
86 va_surface_ = vaapi_wrapper_->CreateUnownedSurface(
87 VA_RT_FORMAT_RGB32, size(), va_attribs, arraysize(va_attribs));
88 if (!va_surface_.get()) {
89 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap";
90 return false;
91 }
92
93 if (!make_context_current_.Run())
94 return false;
95
96 egl_image_ = new gfx::GLImageLinuxDMABuffer(size(), GL_RGBA);
97 if (!egl_image_->Initialize(base::FileDescriptor(dmabuf_fd, false),
98 gfx::GpuMemoryBuffer::BGRA_8888,
99 dmabuf_pitch)) {
100 LOG(ERROR) << "Failed to create an EGLImage for an Ozone NativePixmap";
101 return false;
102 }
103
104 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES,
105 texture_id());
106 if (!egl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) {
107 LOG(ERROR) << "Failed to bind texture to EGLImage";
108 return false;
109 }
110
111 return true;
112 }
113
114 bool VaapiDrmPicture::DownloadFromSurface(
115 const scoped_refptr<VASurface>& va_surface) {
116 return vaapi_wrapper_->BlitSurface(va_surface->id(),
117 va_surface->size(),
118 va_surface_->id(),
119 va_surface_->size());
120 }
121
122 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698