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

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

Issue 1432963003: [Ozone] Extends the lifetime of VaapiWrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT for upstream Created 5 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
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 VaapiDrmPicture::VaapiDrmPicture( 22 VaapiDrmPicture::VaapiDrmPicture(
23 VaapiWrapper* vaapi_wrapper, 23 scoped_refptr<VaapiWrapper> vaapi_wrapper,
24 const base::Callback<bool(void)>& make_context_current, 24 const base::Callback<bool(void)>& make_context_current,
25 int32 picture_buffer_id, 25 int32 picture_buffer_id,
26 uint32 texture_id, 26 uint32 texture_id,
27 const gfx::Size& size) 27 const gfx::Size& size)
28 : VaapiPicture(picture_buffer_id, texture_id, size), 28 : VaapiPicture(picture_buffer_id, texture_id, size),
29 vaapi_wrapper_(vaapi_wrapper), 29 vaapi_wrapper_(vaapi_wrapper),
30 make_context_current_(make_context_current), 30 make_context_current_(make_context_current) {}
31 weak_this_factory_(this) {
32 }
33 31
34 VaapiDrmPicture::~VaapiDrmPicture() { 32 VaapiDrmPicture::~VaapiDrmPicture() {
35 if (gl_image_ && make_context_current_.Run()) { 33 if (gl_image_ && make_context_current_.Run()) {
36 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); 34 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES);
37 gl_image_->Destroy(true); 35 gl_image_->Destroy(true);
38 36
37 LOG(WARNING) << "qxie2:" << __FUNCTION__ << ", gl_image:" << gl_image_;
39 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); 38 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
40 } 39 }
41 } 40 }
42 41
43 scoped_refptr<VASurface> VaapiDrmPicture::CreateVASurfaceForPixmap( 42 scoped_refptr<VASurface> VaapiDrmPicture::CreateVASurfaceForPixmap(
44 scoped_refptr<ui::NativePixmap> pixmap, 43 scoped_refptr<ui::NativePixmap> pixmap,
45 gfx::Size pixmap_size) { 44 gfx::Size pixmap_size) {
46 // Get the dmabuf of the created buffer. 45 // Get the dmabuf of the created buffer.
47 int dmabuf_fd = pixmap->GetDmaBufFd(); 46 int dmabuf_fd = pixmap->GetDmaBufFd();
48 if (dmabuf_fd < 0) { 47 if (dmabuf_fd < 0) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; 108 LOG(ERROR) << "Failed creating an Ozone NativePixmap";
110 return false; 109 return false;
111 } 110 }
112 111
113 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size()); 112 va_surface_ = CreateVASurfaceForPixmap(pixmap_, size());
114 if (!va_surface_) { 113 if (!va_surface_) {
115 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; 114 LOG(ERROR) << "Failed creating VASurface for NativePixmap";
116 return false; 115 return false;
117 } 116 }
118 117
119 // Weak pointers can only bind to methods without return values, 118 scoped_refptr<VaapiDrmPicture> ref = this;
Pawel Osciak 2015/11/16 04:24:35 This shouldn't be required. You should be able to
william.xie1 2015/11/16 08:07:25 Done.
120 // hence we cannot bind ScalePixmap here. Instead we use a 119 pixmap_->SetScalingCallback(base::Bind(&VaapiDrmPicture::ScalePixmap, ref));
121 // static function to solve this problem.
122 pixmap_->SetScalingCallback(base::Bind(&VaapiDrmPicture::CallScalePixmap,
123 weak_this_factory_.GetWeakPtr()));
124 120
125 if (!make_context_current_.Run()) 121 if (!make_context_current_.Run())
126 return false; 122 return false;
127 123
128 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, 124 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES,
129 texture_id()); 125 texture_id());
130 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( 126 scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
131 new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT)); 127 new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT));
132 if (!image->Initialize(pixmap_.get(), gfx::BufferFormat::BGRX_8888)) { 128 if (!image->Initialize(pixmap_.get(), gfx::BufferFormat::BGRX_8888)) {
133 LOG(ERROR) << "Failed to create GLImage"; 129 LOG(ERROR) << "Failed to create GLImage";
134 return false; 130 return false;
135 } 131 }
136 gl_image_ = image; 132 gl_image_ = image;
137 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { 133 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) {
138 LOG(ERROR) << "Failed to bind texture to GLImage"; 134 LOG(ERROR) << "Failed to bind texture to GLImage";
139 return false; 135 return false;
140 } 136 }
141 137
142 return true; 138 return true;
143 } 139 }
144 140
145 bool VaapiDrmPicture::DownloadFromSurface( 141 bool VaapiDrmPicture::DownloadFromSurface(
146 const scoped_refptr<VASurface>& va_surface) { 142 const scoped_refptr<VASurface>& va_surface) {
147 return vaapi_wrapper_->BlitSurface(va_surface, va_surface_); 143 return vaapi_wrapper_->BlitSurface(va_surface, va_surface_);
148 } 144 }
149 145
150 // static
151 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CallScalePixmap(
152 base::WeakPtr<VaapiDrmPicture> weak_ptr,
153 gfx::Size new_size) {
154 if (!weak_ptr.get()) {
155 LOG(ERROR) << "Failed scaling NativePixmap as scaling "
156 "unit(VaapiDrmPicture) is deleted";
157 return nullptr;
158 }
159 return weak_ptr->ScalePixmap(new_size);
160 }
161
162 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap( 146 scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap(
163 gfx::Size new_size) { 147 gfx::Size new_size) {
164 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) { 148 if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) {
165 scaled_pixmap_ = CreateNativePixmap(new_size); 149 scaled_pixmap_ = CreateNativePixmap(new_size);
166 if (!scaled_pixmap_) { 150 if (!scaled_pixmap_) {
167 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling"; 151 LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling";
168 scaled_va_surface_ = nullptr; 152 scaled_va_surface_ = nullptr;
169 return nullptr; 153 return nullptr;
170 } 154 }
171 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size); 155 scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size);
(...skipping 19 matching lines...) Expand all
191 175
192 scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() { 176 scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() {
193 return gl_image_; 177 return gl_image_;
194 } 178 }
195 179
196 bool VaapiDrmPicture::AllowOverlay() const { 180 bool VaapiDrmPicture::AllowOverlay() const {
197 return true; 181 return true;
198 } 182 }
199 183
200 } // namespace 184 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698