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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
9 #include "base/files/file_path.h"
10 #include "third_party/khronos/EGL/egl.h"
11 #include "ui/ozone/common/egl_util.h"
12 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
13 #include "ui/ozone/platform/drm/gpu/drm_window.h"
14 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
15 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
16 #include "ui/ozone/platform/drm/gpu/gbm_surface.h"
17 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h"
18 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
19 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
20 #include "ui/ozone/public/native_pixmap.h"
21 #include "ui/ozone/public/surface_ozone_canvas.h"
22 #include "ui/ozone/public/surface_ozone_egl.h"
26 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless
)
27 : DrmSurfaceFactory(nullptr),
28 allow_surfaceless_(allow_surfaceless
),
29 drm_device_manager_(nullptr) {}
31 GbmSurfaceFactory::~GbmSurfaceFactory() {
32 DCHECK(thread_checker_
.CalledOnValidThread());
35 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager
* drm_device_manager
,
36 ScreenManager
* screen_manager
) {
37 drm_device_manager_
= drm_device_manager
;
38 screen_manager_
= screen_manager
;
41 intptr_t GbmSurfaceFactory::GetNativeDisplay() {
42 DCHECK(thread_checker_
.CalledOnValidThread());
43 return EGL_DEFAULT_DISPLAY
;
46 const int32
* GbmSurfaceFactory::GetEGLSurfaceProperties(
47 const int32
* desired_list
) {
48 DCHECK(thread_checker_
.CalledOnValidThread());
49 static const int32 kConfigAttribs
[] = {EGL_BUFFER_SIZE
,
65 return kConfigAttribs
;
68 bool GbmSurfaceFactory::LoadEGLGLES2Bindings(
69 AddGLLibraryCallback add_gl_library
,
70 SetGLGetProcAddressProcCallback set_gl_get_proc_address
) {
71 DCHECK(thread_checker_
.CalledOnValidThread());
72 return LoadDefaultEGLGLES2Bindings(add_gl_library
, set_gl_get_proc_address
);
75 scoped_ptr
<SurfaceOzoneCanvas
> GbmSurfaceFactory::CreateCanvasForWidget(
76 gfx::AcceleratedWidget widget
) {
77 DCHECK(thread_checker_
.CalledOnValidThread());
78 LOG(FATAL
) << "Software rendering mode is not supported with GBM platform";
82 scoped_ptr
<SurfaceOzoneEGL
> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
83 gfx::AcceleratedWidget widget
) {
84 DCHECK(thread_checker_
.CalledOnValidThread());
85 scoped_refptr
<GbmDevice
> gbm
= GetGbmDevice(widget
);
88 scoped_ptr
<GbmSurface
> surface(
89 new GbmSurface(screen_manager_
->GetWindow(widget
), gbm
));
90 if (!surface
->Initialize())
93 return surface
.Pass();
96 scoped_ptr
<SurfaceOzoneEGL
>
97 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
98 gfx::AcceleratedWidget widget
) {
99 DCHECK(thread_checker_
.CalledOnValidThread());
100 if (!allow_surfaceless_
)
103 return make_scoped_ptr(new GbmSurfaceless(screen_manager_
->GetWindow(widget
),
104 drm_device_manager_
));
107 scoped_refptr
<ui::NativePixmap
> GbmSurfaceFactory::CreateNativePixmap(
108 gfx::AcceleratedWidget widget
,
115 scoped_refptr
<GbmDevice
> gbm
= GetGbmDevice(widget
);
118 scoped_refptr
<GbmBuffer
> buffer
=
119 GbmBuffer::CreateBuffer(gbm
, format
, size
, true);
123 scoped_refptr
<GbmPixmap
> pixmap(new GbmPixmap(buffer
, screen_manager_
));
124 if (!pixmap
->Initialize())
130 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
131 DCHECK(thread_checker_
.CalledOnValidThread());
132 return allow_surfaceless_
;
135 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage
) {
136 DCHECK(thread_checker_
.CalledOnValidThread());
149 scoped_refptr
<GbmDevice
> GbmSurfaceFactory::GetGbmDevice(
150 gfx::AcceleratedWidget widget
) {
151 return static_cast<GbmDevice
*>(
152 drm_device_manager_
->GetDrmDevice(widget
).get());