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_surfaceless.h"
17 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
18 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
19 #include "ui/ozone/public/native_pixmap.h"
20 #include "ui/ozone/public/surface_ozone_canvas.h"
21 #include "ui/ozone/public/surface_ozone_egl.h"
25 GbmSurfaceFactory::GbmSurfaceFactory()
26 : drm_device_manager_(nullptr), screen_manager_(nullptr) {}
28 GbmSurfaceFactory::~GbmSurfaceFactory() {
29 DCHECK(thread_checker_
.CalledOnValidThread());
32 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager
* drm_device_manager
,
33 ScreenManager
* screen_manager
) {
34 drm_device_manager_
= drm_device_manager
;
35 screen_manager_
= screen_manager
;
38 intptr_t GbmSurfaceFactory::GetNativeDisplay() {
39 DCHECK(thread_checker_
.CalledOnValidThread());
40 return EGL_DEFAULT_DISPLAY
;
43 const int32
* GbmSurfaceFactory::GetEGLSurfaceProperties(
44 const int32
* desired_list
) {
45 DCHECK(thread_checker_
.CalledOnValidThread());
46 static const int32 kConfigAttribs
[] = {EGL_BUFFER_SIZE
,
62 return kConfigAttribs
;
65 bool GbmSurfaceFactory::LoadEGLGLES2Bindings(
66 AddGLLibraryCallback add_gl_library
,
67 SetGLGetProcAddressProcCallback set_gl_get_proc_address
) {
68 DCHECK(thread_checker_
.CalledOnValidThread());
69 return LoadDefaultEGLGLES2Bindings(add_gl_library
, set_gl_get_proc_address
);
72 scoped_ptr
<SurfaceOzoneCanvas
> GbmSurfaceFactory::CreateCanvasForWidget(
73 gfx::AcceleratedWidget widget
) {
74 DCHECK(thread_checker_
.CalledOnValidThread());
75 LOG(FATAL
) << "Software rendering mode is not supported with GBM platform";
79 scoped_ptr
<SurfaceOzoneEGL
> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
80 gfx::AcceleratedWidget widget
) {
85 scoped_ptr
<SurfaceOzoneEGL
>
86 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
87 gfx::AcceleratedWidget widget
) {
88 DCHECK(thread_checker_
.CalledOnValidThread());
89 return make_scoped_ptr(new GbmSurfaceless(screen_manager_
->GetWindow(widget
),
90 drm_device_manager_
));
93 scoped_refptr
<ui::NativePixmap
> GbmSurfaceFactory::CreateNativePixmap(
94 gfx::AcceleratedWidget widget
,
96 gfx::BufferFormat format
,
97 gfx::BufferUsage usage
) {
98 #if !defined(OS_CHROMEOS)
99 // Support for memory mapping accelerated buffers requires some
100 // CrOS-specific patches (using vgem).
101 DCHECK(gfx::BufferUsage::SCANOUT
== usage
);
104 scoped_refptr
<GbmDevice
> gbm
= GetGbmDevice(widget
);
107 scoped_refptr
<GbmBuffer
> buffer
=
108 GbmBuffer::CreateBuffer(gbm
, format
, size
, usage
);
112 scoped_refptr
<GbmPixmap
> pixmap(new GbmPixmap(buffer
, screen_manager_
));
113 if (!pixmap
->Initialize())
119 scoped_refptr
<GbmDevice
> GbmSurfaceFactory::GetGbmDevice(
120 gfx::AcceleratedWidget widget
) {
121 return static_cast<GbmDevice
*>(
122 drm_device_manager_
->GetDrmDevice(widget
).get());