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