| 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/dri/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
| 6 | 6 |
| 7 #include <gbm.h> | 7 #include <gbm.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "third_party/khronos/EGL/egl.h" | 11 #include "third_party/khronos/EGL/egl.h" |
| 12 #include "ui/ozone/common/egl_util.h" | 12 #include "ui/ozone/common/egl_util.h" |
| 13 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" | 13 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h" |
| 14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
| 15 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
| 16 #include "ui/ozone/platform/dri/gbm_buffer.h" | 15 #include "ui/ozone/platform/dri/gbm_buffer.h" |
| 17 #include "ui/ozone/platform/dri/gbm_surface.h" | 16 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 18 #include "ui/ozone/platform/dri/gbm_surfaceless.h" | 17 #include "ui/ozone/platform/dri/gbm_surfaceless.h" |
| 18 #include "ui/ozone/platform/dri/gbm_wrapper.h" |
| 19 #include "ui/ozone/platform/dri/screen_manager.h" | 19 #include "ui/ozone/platform/dri/screen_manager.h" |
| 20 #include "ui/ozone/public/native_pixmap.h" | 20 #include "ui/ozone/public/native_pixmap.h" |
| 21 #include "ui/ozone/public/overlay_candidates_ozone.h" | 21 #include "ui/ozone/public/overlay_candidates_ozone.h" |
| 22 #include "ui/ozone/public/ozone_switches.h" | 22 #include "ui/ozone/public/ozone_switches.h" |
| 23 #include "ui/ozone/public/surface_ozone_egl.h" | 23 #include "ui/ozone/public/surface_ozone_egl.h" |
| 24 | 24 |
| 25 namespace ui { | 25 namespace ui { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class SingleOverlay : public OverlayCandidatesOzone { | 28 class SingleOverlay : public OverlayCandidatesOzone { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); | 65 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 70 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
| 71 : DriSurfaceFactory(NULL, NULL), | 71 : DriSurfaceFactory(NULL, NULL), |
| 72 device_(NULL), | |
| 73 allow_surfaceless_(allow_surfaceless) { | 72 allow_surfaceless_(allow_surfaceless) { |
| 74 } | 73 } |
| 75 | 74 |
| 76 GbmSurfaceFactory::~GbmSurfaceFactory() {} | 75 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
| 77 | 76 |
| 78 void GbmSurfaceFactory::InitializeGpu( | 77 void GbmSurfaceFactory::InitializeGpu( |
| 79 DriWrapper* dri, | 78 GbmWrapper* gbm, |
| 80 gbm_device* device, | |
| 81 ScreenManager* screen_manager, | 79 ScreenManager* screen_manager, |
| 82 DriWindowDelegateManager* window_manager) { | 80 DriWindowDelegateManager* window_manager) { |
| 83 drm_ = dri; | 81 gbm_ = gbm; |
| 84 device_ = device; | |
| 85 screen_manager_ = screen_manager; | 82 screen_manager_ = screen_manager; |
| 86 window_manager_ = window_manager; | 83 window_manager_ = window_manager; |
| 87 } | 84 } |
| 88 | 85 |
| 89 intptr_t GbmSurfaceFactory::GetNativeDisplay() { | 86 intptr_t GbmSurfaceFactory::GetNativeDisplay() { |
| 90 #if defined(USE_MESA_PLATFORM_NULL) | 87 #if defined(USE_MESA_PLATFORM_NULL) |
| 91 return EGL_DEFAULT_DISPLAY; | 88 return EGL_DEFAULT_DISPLAY; |
| 92 #else | 89 #else |
| 93 return reinterpret_cast<intptr_t>(device_); | 90 DCHECK(gbm_); |
| 91 return reinterpret_cast<intptr_t>(gbm_->device()); |
| 94 #endif | 92 #endif |
| 95 } | 93 } |
| 96 | 94 |
| 97 int GbmSurfaceFactory::GetDrmFd() { | 95 int GbmSurfaceFactory::GetDrmFd() { |
| 98 DCHECK(drm_); | 96 DCHECK(gbm_); |
| 99 return drm_->get_fd(); | 97 return gbm_->get_fd(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( | 100 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( |
| 103 const int32* desired_list) { | 101 const int32* desired_list) { |
| 104 static const int32 kConfigAttribs[] = { | 102 static const int32 kConfigAttribs[] = { |
| 105 EGL_BUFFER_SIZE, 32, | 103 EGL_BUFFER_SIZE, 32, |
| 106 EGL_ALPHA_SIZE, 8, | 104 EGL_ALPHA_SIZE, 8, |
| 107 EGL_BLUE_SIZE, 8, | 105 EGL_BLUE_SIZE, 8, |
| 108 EGL_GREEN_SIZE, 8, | 106 EGL_GREEN_SIZE, 8, |
| 109 EGL_RED_SIZE, 8, | 107 EGL_RED_SIZE, 8, |
| 110 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 108 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 111 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | 109 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 112 EGL_NONE | 110 EGL_NONE |
| 113 }; | 111 }; |
| 114 | 112 |
| 115 return kConfigAttribs; | 113 return kConfigAttribs; |
| 116 } | 114 } |
| 117 | 115 |
| 118 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( | 116 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( |
| 119 AddGLLibraryCallback add_gl_library, | 117 AddGLLibraryCallback add_gl_library, |
| 120 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 118 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 121 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); | 119 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
| 122 } | 120 } |
| 123 | 121 |
| 124 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | 122 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
| 125 gfx::AcceleratedWidget widget) { | 123 gfx::AcceleratedWidget widget) { |
| 126 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); | 124 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); |
| 127 | 125 |
| 128 scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, device_, drm_)); | 126 scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, gbm_)); |
| 129 if (!surface->Initialize()) | 127 if (!surface->Initialize()) |
| 130 return nullptr; | 128 return nullptr; |
| 131 | 129 |
| 132 return surface.Pass(); | 130 return surface.Pass(); |
| 133 } | 131 } |
| 134 | 132 |
| 135 scoped_ptr<SurfaceOzoneEGL> | 133 scoped_ptr<SurfaceOzoneEGL> |
| 136 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( | 134 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( |
| 137 gfx::AcceleratedWidget widget) { | 135 gfx::AcceleratedWidget widget) { |
| 138 if (!allow_surfaceless_) | 136 if (!allow_surfaceless_) |
| 139 return scoped_ptr<SurfaceOzoneEGL>(); | 137 return scoped_ptr<SurfaceOzoneEGL>(); |
| 140 | 138 |
| 141 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); | 139 DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); |
| 142 return scoped_ptr<SurfaceOzoneEGL>(new GbmSurfaceless(delegate)); | 140 return scoped_ptr<SurfaceOzoneEGL>(new GbmSurfaceless(delegate)); |
| 143 } | 141 } |
| 144 | 142 |
| 145 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 143 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
| 146 gfx::AcceleratedWidget widget, | 144 gfx::AcceleratedWidget widget, |
| 147 gfx::Size size, | 145 gfx::Size size, |
| 148 BufferFormat format, | 146 BufferFormat format, |
| 149 BufferUsage usage) { | 147 BufferUsage usage) { |
| 150 if (usage == MAP) | 148 if (usage == MAP) |
| 151 return NULL; | 149 return NULL; |
| 152 | 150 |
| 153 scoped_refptr<GbmBuffer> buffer = | 151 scoped_refptr<GbmBuffer> buffer = |
| 154 GbmBuffer::CreateBuffer(drm_, device_, format, size, true); | 152 GbmBuffer::CreateBuffer(gbm_, format, size, true); |
| 155 if (!buffer.get()) | 153 if (!buffer.get()) |
| 156 return NULL; | 154 return NULL; |
| 157 | 155 |
| 158 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); | 156 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); |
| 159 if (!pixmap->Initialize(drm_)) | 157 if (!pixmap->Initialize(gbm_)) |
| 160 return NULL; | 158 return NULL; |
| 161 | 159 |
| 162 return pixmap; | 160 return pixmap; |
| 163 } | 161 } |
| 164 | 162 |
| 165 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( | 163 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( |
| 166 gfx::AcceleratedWidget w) { | 164 gfx::AcceleratedWidget w) { |
| 167 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 165 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 168 switches::kOzoneTestSingleOverlaySupport)) | 166 switches::kOzoneTestSingleOverlaySupport)) |
| 169 return new SingleOverlay(); | 167 return new SingleOverlay(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return true; | 205 return true; |
| 208 } | 206 } |
| 209 NOTREACHED(); | 207 NOTREACHED(); |
| 210 return false; | 208 return false; |
| 211 } | 209 } |
| 212 | 210 |
| 213 DriWindowDelegate* GbmSurfaceFactory::GetOrCreateWindowDelegate( | 211 DriWindowDelegate* GbmSurfaceFactory::GetOrCreateWindowDelegate( |
| 214 gfx::AcceleratedWidget widget) { | 212 gfx::AcceleratedWidget widget) { |
| 215 if (!window_manager_->HasWindowDelegate(widget)) { | 213 if (!window_manager_->HasWindowDelegate(widget)) { |
| 216 scoped_ptr<DriWindowDelegate> delegate(new DriWindowDelegateImpl( | 214 scoped_ptr<DriWindowDelegate> delegate(new DriWindowDelegateImpl( |
| 217 widget, drm_, window_manager_, screen_manager_)); | 215 widget, gbm_, window_manager_, screen_manager_)); |
| 218 delegate->Initialize(); | 216 delegate->Initialize(); |
| 219 window_manager_->AddWindowDelegate(widget, delegate.Pass()); | 217 window_manager_->AddWindowDelegate(widget, delegate.Pass()); |
| 220 } | 218 } |
| 221 | 219 |
| 222 return window_manager_->GetWindowDelegate(widget); | 220 return window_manager_->GetWindowDelegate(widget); |
| 223 } | 221 } |
| 224 | 222 |
| 225 } // namespace ui | 223 } // namespace ui |
| OLD | NEW |