| 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 "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
| 6 | 6 |
| 7 #include <gbm.h> | 7 #include <gbm.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "third_party/khronos/EGL/egl.h" | 14 #include "third_party/khronos/EGL/egl.h" |
| 15 #include "ui/gfx/buffer_format_util.h" | 15 #include "ui/gfx/buffer_format_util.h" |
| 16 #include "ui/gl/gl_surface_egl.h" | 16 #include "ui/gl/gl_surface_egl.h" |
| 17 #include "ui/ozone/common/egl_util.h" | 17 #include "ui/ozone/common/egl_util.h" |
| 18 #include "ui/ozone/common/gl_ozone_egl.h" | 18 #include "ui/ozone/common/gl_ozone_egl.h" |
| 19 #include "ui/ozone/common/gl_ozone_osmesa.h" |
| 19 #include "ui/ozone/platform/drm/common/drm_util.h" | 20 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 20 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" | 21 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" |
| 21 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" | 22 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" |
| 22 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" | 23 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
| 23 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" | 24 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" |
| 24 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 25 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
| 25 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" | 26 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" |
| 26 #include "ui/ozone/platform/drm/gpu/screen_manager.h" | 27 #include "ui/ozone/platform/drm/gpu/screen_manager.h" |
| 27 #include "ui/ozone/public/native_pixmap.h" | 28 #include "ui/ozone/public/native_pixmap.h" |
| 28 #include "ui/ozone/public/surface_ozone_canvas.h" | 29 #include "ui/ozone/public/surface_ozone_canvas.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 private: | 69 private: |
| 69 GbmSurfaceFactory* surface_factory_; | 70 GbmSurfaceFactory* surface_factory_; |
| 70 DrmThreadProxy* drm_thread_proxy_; | 71 DrmThreadProxy* drm_thread_proxy_; |
| 71 | 72 |
| 72 DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLGbm); | 73 DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLGbm); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace | 76 } // namespace |
| 76 | 77 |
| 77 GbmSurfaceFactory::GbmSurfaceFactory(DrmThreadProxy* drm_thread_proxy) | 78 GbmSurfaceFactory::GbmSurfaceFactory(DrmThreadProxy* drm_thread_proxy) |
| 78 : egl_implementation_(new GLOzoneEGLGbm(this, drm_thread_proxy)), | 79 : egl_implementation_( |
| 80 base::MakeUnique<GLOzoneEGLGbm>(this, drm_thread_proxy)), |
| 81 osmesa_implementation_(base::MakeUnique<GLOzoneOSMesa>()), |
| 79 drm_thread_proxy_(drm_thread_proxy) {} | 82 drm_thread_proxy_(drm_thread_proxy) {} |
| 80 | 83 |
| 81 GbmSurfaceFactory::~GbmSurfaceFactory() { | 84 GbmSurfaceFactory::~GbmSurfaceFactory() { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget, | 88 void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget, |
| 86 GbmSurfaceless* surface) { | 89 GbmSurfaceless* surface) { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
| 88 widget_to_surface_map_.insert(std::make_pair(widget, surface)); | 91 widget_to_surface_map_.insert(std::make_pair(widget, surface)); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) { | 94 void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) { |
| 92 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
| 93 widget_to_surface_map_.erase(widget); | 96 widget_to_surface_map_.erase(widget); |
| 94 } | 97 } |
| 95 | 98 |
| 96 GbmSurfaceless* GbmSurfaceFactory::GetSurface( | 99 GbmSurfaceless* GbmSurfaceFactory::GetSurface( |
| 97 gfx::AcceleratedWidget widget) const { | 100 gfx::AcceleratedWidget widget) const { |
| 98 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
| 99 auto it = widget_to_surface_map_.find(widget); | 102 auto it = widget_to_surface_map_.find(widget); |
| 100 DCHECK(it != widget_to_surface_map_.end()); | 103 DCHECK(it != widget_to_surface_map_.end()); |
| 101 return it->second; | 104 return it->second; |
| 102 } | 105 } |
| 103 | 106 |
| 104 std::vector<gl::GLImplementation> | 107 std::vector<gl::GLImplementation> |
| 105 GbmSurfaceFactory::GetAllowedGLImplementations() { | 108 GbmSurfaceFactory::GetAllowedGLImplementations() { |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 107 std::vector<gl::GLImplementation> impls; | 110 return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2, |
| 108 impls.push_back(gl::kGLImplementationEGLGLES2); | 111 gl::kGLImplementationOSMesaGL}; |
| 109 impls.push_back(gl::kGLImplementationOSMesaGL); | |
| 110 return impls; | |
| 111 } | 112 } |
| 112 | 113 |
| 113 GLOzone* GbmSurfaceFactory::GetGLOzone(gl::GLImplementation implementation) { | 114 GLOzone* GbmSurfaceFactory::GetGLOzone(gl::GLImplementation implementation) { |
| 114 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
| 115 switch (implementation) { | 116 switch (implementation) { |
| 116 case gl::kGLImplementationEGLGLES2: | 117 case gl::kGLImplementationEGLGLES2: |
| 117 return egl_implementation_.get(); | 118 return egl_implementation_.get(); |
| 119 case gl::kGLImplementationOSMesaGL: |
| 120 return osmesa_implementation_.get(); |
| 118 default: | 121 default: |
| 119 return nullptr; | 122 return nullptr; |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 std::unique_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( | 126 std::unique_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( |
| 124 gfx::AcceleratedWidget widget) { | 127 gfx::AcceleratedWidget widget) { |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | 128 DCHECK(thread_checker_.CalledOnValidThread()); |
| 126 LOG(ERROR) << "Software rendering mode is not supported with GBM platform"; | 129 LOG(ERROR) << "Software rendering mode is not supported with GBM platform"; |
| 127 return nullptr; | 130 return nullptr; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 178 } |
| 176 | 179 |
| 177 scoped_refptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBufferFromFds( | 180 scoped_refptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBufferFromFds( |
| 178 widget, size, format, std::move(scoped_fds), planes); | 181 widget, size, format, std::move(scoped_fds), planes); |
| 179 if (!buffer) | 182 if (!buffer) |
| 180 return nullptr; | 183 return nullptr; |
| 181 return make_scoped_refptr(new GbmPixmap(this, buffer)); | 184 return make_scoped_refptr(new GbmPixmap(this, buffer)); |
| 182 } | 185 } |
| 183 | 186 |
| 184 } // namespace ui | 187 } // namespace ui |
| OLD | NEW |