| 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/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/drm/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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); | 67 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 72 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
| 73 : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) { | 73 : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) { |
| 74 } | 74 } |
| 75 | 75 |
| 76 GbmSurfaceFactory::~GbmSurfaceFactory() { | 76 GbmSurfaceFactory::~GbmSurfaceFactory() { |
| 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager, | 80 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager, |
| 80 ScreenManager* screen_manager) { | 81 ScreenManager* screen_manager) { |
| 81 drm_device_manager_ = drm_device_manager; | 82 drm_device_manager_ = drm_device_manager; |
| 82 screen_manager_ = screen_manager; | 83 screen_manager_ = screen_manager; |
| 83 } | 84 } |
| 84 | 85 |
| 85 intptr_t GbmSurfaceFactory::GetNativeDisplay() { | 86 intptr_t GbmSurfaceFactory::GetNativeDisplay() { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 #if defined(USE_MESA_PLATFORM_NULL) | 88 #if defined(USE_MESA_PLATFORM_NULL) |
| 87 return EGL_DEFAULT_DISPLAY; | 89 return EGL_DEFAULT_DISPLAY; |
| 88 #else | 90 #else |
| 89 scoped_refptr<GbmDevice> gbm = GetGbmDevice(gfx::kNullAcceleratedWidget); | 91 scoped_refptr<GbmDevice> gbm = GetGbmDevice(gfx::kNullAcceleratedWidget); |
| 90 DCHECK(gbm); | 92 DCHECK(gbm); |
| 91 return reinterpret_cast<intptr_t>(gbm->device()); | 93 return reinterpret_cast<intptr_t>(gbm->device()); |
| 92 #endif | 94 #endif |
| 93 } | 95 } |
| 94 | 96 |
| 95 int GbmSurfaceFactory::GetDrmFd() { | 97 int GbmSurfaceFactory::GetDrmFd() { |
| 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 scoped_refptr<GbmDevice> gbm = GetGbmDevice(gfx::kNullAcceleratedWidget); | 99 scoped_refptr<GbmDevice> gbm = GetGbmDevice(gfx::kNullAcceleratedWidget); |
| 97 DCHECK(gbm); | 100 DCHECK(gbm); |
| 98 return gbm->get_fd(); | 101 return gbm->get_fd(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( | 104 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties( |
| 102 const int32* desired_list) { | 105 const int32* desired_list) { |
| 106 DCHECK(thread_checker_.CalledOnValidThread()); |
| 103 static const int32 kConfigAttribs[] = {EGL_BUFFER_SIZE, | 107 static const int32 kConfigAttribs[] = {EGL_BUFFER_SIZE, |
| 104 32, | 108 32, |
| 105 EGL_ALPHA_SIZE, | 109 EGL_ALPHA_SIZE, |
| 106 8, | 110 8, |
| 107 EGL_BLUE_SIZE, | 111 EGL_BLUE_SIZE, |
| 108 8, | 112 8, |
| 109 EGL_GREEN_SIZE, | 113 EGL_GREEN_SIZE, |
| 110 8, | 114 8, |
| 111 EGL_RED_SIZE, | 115 EGL_RED_SIZE, |
| 112 8, | 116 8, |
| 113 EGL_RENDERABLE_TYPE, | 117 EGL_RENDERABLE_TYPE, |
| 114 EGL_OPENGL_ES2_BIT, | 118 EGL_OPENGL_ES2_BIT, |
| 115 EGL_SURFACE_TYPE, | 119 EGL_SURFACE_TYPE, |
| 116 EGL_WINDOW_BIT, | 120 EGL_WINDOW_BIT, |
| 117 EGL_NONE}; | 121 EGL_NONE}; |
| 118 | 122 |
| 119 return kConfigAttribs; | 123 return kConfigAttribs; |
| 120 } | 124 } |
| 121 | 125 |
| 122 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( | 126 bool GbmSurfaceFactory::LoadEGLGLES2Bindings( |
| 123 AddGLLibraryCallback add_gl_library, | 127 AddGLLibraryCallback add_gl_library, |
| 124 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 128 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 129 DCHECK(thread_checker_.CalledOnValidThread()); |
| 125 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); | 130 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
| 126 } | 131 } |
| 127 | 132 |
| 128 scoped_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( | 133 scoped_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget( |
| 129 gfx::AcceleratedWidget widget) { | 134 gfx::AcceleratedWidget widget) { |
| 135 DCHECK(thread_checker_.CalledOnValidThread()); |
| 130 LOG(FATAL) << "Software rendering mode is not supported with GBM platform"; | 136 LOG(FATAL) << "Software rendering mode is not supported with GBM platform"; |
| 131 return nullptr; | 137 return nullptr; |
| 132 } | 138 } |
| 133 | 139 |
| 134 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | 140 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
| 135 gfx::AcceleratedWidget widget) { | 141 gfx::AcceleratedWidget widget) { |
| 142 DCHECK(thread_checker_.CalledOnValidThread()); |
| 136 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); | 143 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); |
| 137 DCHECK(gbm); | 144 DCHECK(gbm); |
| 138 | 145 |
| 139 scoped_ptr<GbmSurface> surface( | 146 scoped_ptr<GbmSurface> surface( |
| 140 new GbmSurface(screen_manager_->GetWindow(widget), gbm)); | 147 new GbmSurface(screen_manager_->GetWindow(widget), gbm)); |
| 141 if (!surface->Initialize()) | 148 if (!surface->Initialize()) |
| 142 return nullptr; | 149 return nullptr; |
| 143 | 150 |
| 144 return surface.Pass(); | 151 return surface.Pass(); |
| 145 } | 152 } |
| 146 | 153 |
| 147 scoped_ptr<SurfaceOzoneEGL> | 154 scoped_ptr<SurfaceOzoneEGL> |
| 148 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( | 155 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget( |
| 149 gfx::AcceleratedWidget widget) { | 156 gfx::AcceleratedWidget widget) { |
| 157 DCHECK(thread_checker_.CalledOnValidThread()); |
| 150 if (!allow_surfaceless_) | 158 if (!allow_surfaceless_) |
| 151 return nullptr; | 159 return nullptr; |
| 152 | 160 |
| 153 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget), | 161 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget), |
| 154 drm_device_manager_)); | 162 drm_device_manager_)); |
| 155 } | 163 } |
| 156 | 164 |
| 157 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 165 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
| 158 gfx::AcceleratedWidget widget, | 166 gfx::AcceleratedWidget widget, |
| 159 gfx::Size size, | 167 gfx::Size size, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 | 180 |
| 173 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); | 181 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); |
| 174 if (!pixmap->Initialize()) | 182 if (!pixmap->Initialize()) |
| 175 return nullptr; | 183 return nullptr; |
| 176 | 184 |
| 177 return pixmap; | 185 return pixmap; |
| 178 } | 186 } |
| 179 | 187 |
| 180 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( | 188 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( |
| 181 gfx::AcceleratedWidget w) { | 189 gfx::AcceleratedWidget w) { |
| 190 DCHECK(thread_checker_.CalledOnValidThread()); |
| 182 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 191 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 183 switches::kOzoneTestSingleOverlaySupport)) | 192 switches::kOzoneTestSingleOverlaySupport)) |
| 184 return new SingleOverlay(); | 193 return new SingleOverlay(); |
| 185 return NULL; | 194 return NULL; |
| 186 } | 195 } |
| 187 | 196 |
| 188 bool GbmSurfaceFactory::ScheduleOverlayPlane( | 197 bool GbmSurfaceFactory::ScheduleOverlayPlane( |
| 189 gfx::AcceleratedWidget widget, | 198 gfx::AcceleratedWidget widget, |
| 190 int plane_z_order, | 199 int plane_z_order, |
| 191 gfx::OverlayTransform plane_transform, | 200 gfx::OverlayTransform plane_transform, |
| 192 scoped_refptr<NativePixmap> buffer, | 201 scoped_refptr<NativePixmap> buffer, |
| 193 const gfx::Rect& display_bounds, | 202 const gfx::Rect& display_bounds, |
| 194 const gfx::RectF& crop_rect) { | 203 const gfx::RectF& crop_rect) { |
| 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 195 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); | 205 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); |
| 196 if (!pixmap.get()) { | 206 if (!pixmap.get()) { |
| 197 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer."; | 207 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer."; |
| 198 return false; | 208 return false; |
| 199 } | 209 } |
| 200 HardwareDisplayController* hdc = | 210 HardwareDisplayController* hdc = |
| 201 screen_manager_->GetWindow(widget)->GetController(); | 211 screen_manager_->GetWindow(widget)->GetController(); |
| 202 if (!hdc) | 212 if (!hdc) |
| 203 return true; | 213 return true; |
| 204 | 214 |
| 205 hdc->QueueOverlayPlane(OverlayPlane(pixmap->buffer(), plane_z_order, | 215 hdc->QueueOverlayPlane(OverlayPlane(pixmap->buffer(), plane_z_order, |
| 206 plane_transform, display_bounds, | 216 plane_transform, display_bounds, |
| 207 crop_rect)); | 217 crop_rect)); |
| 208 return true; | 218 return true; |
| 209 } | 219 } |
| 210 | 220 |
| 211 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { | 221 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 212 return allow_surfaceless_; | 223 return allow_surfaceless_; |
| 213 } | 224 } |
| 214 | 225 |
| 215 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) { | 226 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) { |
| 227 DCHECK(thread_checker_.CalledOnValidThread()); |
| 216 switch (usage) { | 228 switch (usage) { |
| 217 case MAP: | 229 case MAP: |
| 218 return false; | 230 return false; |
| 219 case SCANOUT: | 231 case SCANOUT: |
| 220 return true; | 232 return true; |
| 221 } | 233 } |
| 222 NOTREACHED(); | 234 NOTREACHED(); |
| 223 return false; | 235 return false; |
| 224 } | 236 } |
| 225 | 237 |
| 226 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( | 238 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( |
| 227 gfx::AcceleratedWidget widget) { | 239 gfx::AcceleratedWidget widget) { |
| 228 return static_cast<GbmDevice*>( | 240 return static_cast<GbmDevice*>( |
| 229 drm_device_manager_->GetDrmDevice(widget).get()); | 241 drm_device_manager_->GetDrmDevice(widget).get()); |
| 230 } | 242 } |
| 231 | 243 |
| 232 } // namespace ui | 244 } // namespace ui |
| OLD | NEW |