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 "ui/gfx/gpu_memory_buffer.h" | 11 #include "ui/gfx/gpu_memory_buffer.h" |
12 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
13 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 13 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
14 #include "ui/gl/scoped_binders.h" | 14 #include "ui/gl/scoped_binders.h" |
15 #include "ui/ozone/public/native_pixmap.h" | 15 #include "ui/ozone/public/native_pixmap.h" |
16 #include "ui/ozone/public/ozone_platform.h" | 16 #include "ui/ozone/public/ozone_platform.h" |
17 #include "ui/ozone/public/surface_factory_ozone.h" | 17 #include "ui/ozone/public/surface_factory_ozone.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 // We decode video into YUV420, but for usage with GLImages we have to convert | 20 // We decode video into YUV420, but for usage with GLImages we have to convert |
21 // to BGRX_8888. | 21 // to BGRX_8888. |
22 const gfx::BufferFormat kPictureForGLImageFormat = gfx::BufferFormat::BGRX_8888; | 22 const gfx::BufferFormat kPictureForGLImageFormat = gfx::BufferFormat::BGRX_8888; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 VaapiDrmPicture::VaapiDrmPicture( | 28 VaapiDrmPicture::VaapiDrmPicture( |
29 const scoped_refptr<VaapiWrapper>& vaapi_wrapper, | 29 const scoped_refptr<VaapiWrapper>& vaapi_wrapper, |
30 const base::Callback<bool(void)>& make_context_current, | 30 const MakeGLContextCurrentCallback& make_context_current_cb, |
31 int32_t picture_buffer_id, | 31 int32_t picture_buffer_id, |
32 uint32_t texture_id, | 32 uint32_t texture_id, |
33 const gfx::Size& size) | 33 const gfx::Size& size) |
34 : VaapiPicture(picture_buffer_id, texture_id, size), | 34 : VaapiPicture(picture_buffer_id, texture_id, size), |
35 vaapi_wrapper_(vaapi_wrapper), | 35 vaapi_wrapper_(vaapi_wrapper), |
36 make_context_current_(make_context_current) {} | 36 make_context_current_cb_(make_context_current_cb) {} |
37 | 37 |
38 VaapiDrmPicture::~VaapiDrmPicture() { | 38 VaapiDrmPicture::~VaapiDrmPicture() { |
39 if (gl_image_ && make_context_current_.Run()) { | 39 if (gl_image_ && make_context_current_cb_.Run()) { |
40 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); | 40 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); |
41 gl_image_->Destroy(true); | 41 gl_image_->Destroy(true); |
42 | 42 |
43 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); | 43 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 bool VaapiDrmPicture::Initialize() { | 47 bool VaapiDrmPicture::Initialize() { |
48 // We want to create a VASurface and an EGLImage out of the same | 48 // We want to create a VASurface and an EGLImage out of the same |
49 // memory buffer, so we can output decoded pictures to it using | 49 // memory buffer, so we can output decoded pictures to it using |
(...skipping 10 matching lines...) Expand all Loading... |
60 | 60 |
61 va_surface_ = vaapi_wrapper_->CreateVASurfaceForPixmap(pixmap_); | 61 va_surface_ = vaapi_wrapper_->CreateVASurfaceForPixmap(pixmap_); |
62 if (!va_surface_) { | 62 if (!va_surface_) { |
63 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; | 63 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
67 pixmap_->SetProcessingCallback( | 67 pixmap_->SetProcessingCallback( |
68 base::Bind(&VaapiWrapper::ProcessPixmap, vaapi_wrapper_)); | 68 base::Bind(&VaapiWrapper::ProcessPixmap, vaapi_wrapper_)); |
69 | 69 |
70 if (!make_context_current_.Run()) | 70 if (!make_context_current_cb_.Run()) |
71 return false; | 71 return false; |
72 | 72 |
73 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, | 73 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, |
74 texture_id()); | 74 texture_id()); |
75 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | 75 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( |
76 new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT)); | 76 new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT)); |
77 if (!image->Initialize(pixmap_.get(), pixmap_->GetBufferFormat())) { | 77 if (!image->Initialize(pixmap_.get(), pixmap_->GetBufferFormat())) { |
78 LOG(ERROR) << "Failed to create GLImage"; | 78 LOG(ERROR) << "Failed to create GLImage"; |
79 return false; | 79 return false; |
80 } | 80 } |
(...skipping 13 matching lines...) Expand all Loading... |
94 | 94 |
95 scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() { | 95 scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() { |
96 return gl_image_; | 96 return gl_image_; |
97 } | 97 } |
98 | 98 |
99 bool VaapiDrmPicture::AllowOverlay() const { | 99 bool VaapiDrmPicture::AllowOverlay() const { |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
OLD | NEW |