| 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> |
| 10 |
| 9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 12 #include "third_party/khronos/EGL/egl.h" | 14 #include "third_party/khronos/EGL/egl.h" |
| 13 #include "ui/gfx/buffer_format_util.h" | 15 #include "ui/gfx/buffer_format_util.h" |
| 16 #include "ui/gl/gl_surface_egl.h" |
| 14 #include "ui/ozone/common/egl_util.h" | 17 #include "ui/ozone/common/egl_util.h" |
| 15 #include "ui/ozone/platform/drm/common/drm_util.h" | 18 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 16 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" | 19 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" |
| 17 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" | 20 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" |
| 18 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
| 19 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 22 #include "ui/ozone/platform/drm/gpu/gl_surface_gbm_buffered_surfaceless.h" |
| 23 #include "ui/ozone/platform/drm/gpu/gl_surface_gbm_surfaceless.h" |
| 20 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" | 24 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" |
| 21 #include "ui/ozone/platform/drm/gpu/screen_manager.h" | 25 #include "ui/ozone/platform/drm/gpu/screen_manager.h" |
| 22 #include "ui/ozone/public/native_pixmap.h" | 26 #include "ui/ozone/public/native_pixmap.h" |
| 23 #include "ui/ozone/public/surface_ozone_canvas.h" | 27 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 24 #include "ui/ozone/public/surface_ozone_egl.h" | |
| 25 | 28 |
| 26 namespace ui { | 29 namespace ui { |
| 27 | 30 |
| 28 GbmSurfaceFactory::GbmSurfaceFactory(DrmThreadProxy* drm_thread) | 31 GbmSurfaceFactory::GbmSurfaceFactory(DrmThreadProxy* drm_thread) |
| 29 : drm_thread_(drm_thread) {} | 32 : drm_thread_(drm_thread) {} |
| 30 | 33 |
| 31 GbmSurfaceFactory::~GbmSurfaceFactory() { | 34 GbmSurfaceFactory::~GbmSurfaceFactory() { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget, | 38 void GbmSurfaceFactory::RegisterSurface(gfx::AcceleratedWidget widget, |
| 36 GbmSurfaceless* surface) { | 39 GLSurfaceGbmSurfaceless* surface) { |
| 37 DCHECK(thread_checker_.CalledOnValidThread()); | 40 DCHECK(thread_checker_.CalledOnValidThread()); |
| 38 widget_to_surface_map_.insert(std::make_pair(widget, surface)); | 41 widget_to_surface_map_.insert(std::make_pair(widget, surface)); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) { | 44 void GbmSurfaceFactory::UnregisterSurface(gfx::AcceleratedWidget widget) { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); | 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 widget_to_surface_map_.erase(widget); | 46 widget_to_surface_map_.erase(widget); |
| 44 } | 47 } |
| 45 | 48 |
| 46 GbmSurfaceless* GbmSurfaceFactory::GetSurface( | 49 GLSurfaceGbmSurfaceless* GbmSurfaceFactory::GetSurface( |
| 47 gfx::AcceleratedWidget widget) const { | 50 gfx::AcceleratedWidget widget) const { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 51 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 auto it = widget_to_surface_map_.find(widget); | 52 auto it = widget_to_surface_map_.find(widget); |
| 50 DCHECK(it != widget_to_surface_map_.end()); | 53 DCHECK(it != widget_to_surface_map_.end()); |
| 51 return it->second; | 54 return it->second; |
| 52 } | 55 } |
| 53 | 56 |
| 57 bool GbmSurfaceFactory::UseNewSurfaceAPI() { |
| 58 return true; |
| 59 } |
| 60 |
| 61 scoped_refptr<gl::GLSurface> GbmSurfaceFactory::CreateViewGLSurface( |
| 62 gl::GLImplementation implementation, |
| 63 gfx::AcceleratedWidget widget) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 |
| 66 if (implementation != gl::kGLImplementationEGLGLES2) { |
| 67 NOTREACHED(); |
| 68 return nullptr; |
| 69 } |
| 70 |
| 71 return gl::InitializeGLSurface(new GLSurfaceGbmBufferedSurfaceless( |
| 72 drm_thread_->CreateDrmWindowProxy(widget), this, widget)); |
| 73 } |
| 74 |
| 75 scoped_refptr<gl::GLSurface> GbmSurfaceFactory::CreateSurfacelessViewGLSurface( |
| 76 gl::GLImplementation implementation, |
| 77 gfx::AcceleratedWidget widget) { |
| 78 DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 |
| 80 if (implementation != gl::kGLImplementationEGLGLES2) { |
| 81 NOTREACHED(); |
| 82 return nullptr; |
| 83 } |
| 84 |
| 85 return gl::InitializeGLSurface(new GLSurfaceGbmSurfaceless( |
| 86 drm_thread_->CreateDrmWindowProxy(widget), this, widget)); |
| 87 } |
| 88 |
| 89 scoped_refptr<gl::GLSurface> GbmSurfaceFactory::CreateOffscreenGLSurface( |
| 90 gl::GLImplementation implementation, |
| 91 const gfx::Size& size) { |
| 92 DCHECK(thread_checker_.CalledOnValidThread()); |
| 93 |
| 94 if (implementation != gl::kGLImplementationEGLGLES2) { |
| 95 NOTREACHED(); |
| 96 return nullptr; |
| 97 } |
| 98 |
| 99 DCHECK_EQ(size.width(), 0); |
| 100 DCHECK_EQ(size.height(), 0); |
| 101 |
| 102 return gl::InitializeGLSurface(new gl::SurfacelessEGL(size)); |
| 103 } |
| 104 |
| 54 intptr_t GbmSurfaceFactory::GetNativeDisplay() { | 105 intptr_t GbmSurfaceFactory::GetNativeDisplay() { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 return EGL_DEFAULT_DISPLAY; | 107 return EGL_DEFAULT_DISPLAY; |
| 57 } | 108 } |
| 58 | 109 |
| 59 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( | 110 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( |
| 60 AddGLLibraryCallback add_gl_library, | 111 AddGLLibraryCallback add_gl_library, |
| 61 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 112 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 113 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); | 114 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
| 64 } | 115 } |
| 65 | 116 |
| 66 std::unique_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( | 117 std::unique_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( |
| 67 gfx::AcceleratedWidget widget) { | 118 gfx::AcceleratedWidget widget) { |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
| 69 LOG(ERROR) << "Software rendering mode is not supported with GBM platform"; | 120 LOG(ERROR) << "Software rendering mode is not supported with GBM platform"; |
| 70 return nullptr; | 121 return nullptr; |
| 71 } | 122 } |
| 72 | 123 |
| 73 std::unique_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | |
| 74 gfx::AcceleratedWidget widget) { | |
| 75 NOTREACHED(); | |
| 76 return nullptr; | |
| 77 } | |
| 78 | |
| 79 std::unique_ptr<SurfaceOzoneEGL> | |
| 80 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( | |
| 81 gfx::AcceleratedWidget widget) { | |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 83 return base::WrapUnique( | |
| 84 new GbmSurfaceless(drm_thread_->CreateDrmWindowProxy(widget), this)); | |
| 85 } | |
| 86 | |
| 87 std::vector<gfx::BufferFormat> GbmSurfaceFactory::GetScanoutFormats( | 124 std::vector<gfx::BufferFormat> GbmSurfaceFactory::GetScanoutFormats( |
| 88 gfx::AcceleratedWidget widget) { | 125 gfx::AcceleratedWidget widget) { |
| 89 std::vector<gfx::BufferFormat> scanout_formats; | 126 std::vector<gfx::BufferFormat> scanout_formats; |
| 90 drm_thread_->GetScanoutFormats(widget, &scanout_formats); | 127 drm_thread_->GetScanoutFormats(widget, &scanout_formats); |
| 91 return scanout_formats; | 128 return scanout_formats; |
| 92 } | 129 } |
| 93 | 130 |
| 94 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 131 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
| 95 gfx::AcceleratedWidget widget, | 132 gfx::AcceleratedWidget widget, |
| 96 gfx::Size size, | 133 gfx::Size size, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 169 } |
| 133 | 170 |
| 134 scoped_refptr<GbmBuffer> buffer = drm_thread_->CreateBufferFromFds( | 171 scoped_refptr<GbmBuffer> buffer = drm_thread_->CreateBufferFromFds( |
| 135 widget, size, format, std::move(scoped_fds), planes); | 172 widget, size, format, std::move(scoped_fds), planes); |
| 136 if (!buffer) | 173 if (!buffer) |
| 137 return nullptr; | 174 return nullptr; |
| 138 return make_scoped_refptr(new GbmPixmap(this, buffer)); | 175 return make_scoped_refptr(new GbmPixmap(this, buffer)); |
| 139 } | 176 } |
| 140 | 177 |
| 141 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |