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

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 review on RenderingHelper Created 6 years, 1 month 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 (c) 2014 The Chromium Authors. All rights reserved.
Pawel Osciak 2014/11/12 05:52:58 No "(c)" in new files please. Please use http://ww
llandwerlin-old 2014/11/12 18:04:42 Acknowledged.
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_drmcommon.h"
11 #include "ui/gfx/gpu_memory_buffer.h"
12 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_image_linux_dma_buffer.h"
14 #include "ui/gl/scoped_binders.h"
15 #include "ui/ozone/public/native_pixmap.h"
16 #include "ui/ozone/public/ozone_platform.h"
17 #include "ui/ozone/public/surface_factory_ozone.h"
18
19 namespace content {
20
21 VaapiDrmPicture::VaapiDrmPicture(
22 base::WeakPtr<VaapiWrapper> vaapi_wrapper,
23 const base::Callback<bool(void)> make_context_current,
24 int32 picture_buffer_id,
25 uint32 texture_id,
26 const gfx::Size& size)
27 : VaapiPicture(picture_buffer_id, texture_id, size),
28 vaapi_wrapper_(vaapi_wrapper),
29 make_context_current_(make_context_current) {
30 }
31
32 VaapiDrmPicture::~VaapiDrmPicture() {
33 // At this point |vaapi_wrapper_| shouldn't be available anymore.
34 DCHECK(!vaapi_wrapper_.get());
35
36 if (egl_image_.get() && make_context_current_.Run()) {
37 egl_image_->Destroy(true);
38
39 DCHECK_EQ(glGetError(), GL_NO_ERROR);
40 }
41 }
42
43 bool VaapiDrmPicture::Initialize() {
44 VASurfaceAttrib va_attribs[2];
45 VASurfaceAttribExternalBuffers va_attrib_extbuf;
46
47 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
48 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
49
50 pixmap_ =
51 factory->CreateNativePixmap(size(), ui::SurfaceFactoryOzone::RGBA_8888);
52 if (!pixmap_.get()) {
53 LOG(ERROR) << "Failed creating an Ozone NativePixmap";
54 return false;
55 }
56
57 int dmabuf_fd = pixmap_->GetDmaBufFd();
58 if (dmabuf_fd < 0) {
59 LOG(ERROR) << "Failed get dmabuf from an Ozone NativePixmap";
60 return false;
61 }
62 int dmabuf_pitch = pixmap_->GetDmaBufPitch();
63
64 va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX;
Pawel Osciak 2014/11/12 05:52:58 Perhaps memset it to 0 first and also drop 0-assig
llandwerlin-old 2014/11/12 18:04:42 Acknowledged.
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(
Pawel Osciak 2014/11/12 05:52:58 You can't dereference a WeakPtr like this. It will
llandwerlin-old 2014/11/12 18:04:42 Acknowledged.
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 }
Pawel Osciak 2014/11/12 05:52:58 Do we need to make context current somewhere aroun
llandwerlin-old 2014/11/12 18:04:42 It's done line 93.
Pawel Osciak 2014/12/08 10:55:15 Right, somehow missed that, sorry.
103
104 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES,
105 texture_id());
106 if (!egl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) {
Pawel Osciak 2014/11/12 05:52:58 Do we need to ReleaseTexImage() somewhere?
llandwerlin-old 2014/11/12 18:04:42 I guess I can do this in the destructor of the Vaa
Pawel Osciak 2014/12/08 10:55:15 Yes, but we should still do this. Thanks for addin
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 void VaapiDrmPicture::DisposeVaapi() {
123 va_surface_ = NULL;
124 }
125
126 // static
127 uint32 VaapiPicture::GetGLTextureTarget() {
Pawel Osciak 2014/11/12 05:52:58 I feel this is not a good way to do this. Please m
llandwerlin-old 2014/11/12 18:04:42 We need to know the texture target for the user pr
128 return GL_TEXTURE_EXTERNAL_OES;
129 }
130
131 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698