Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / gbm_surface_factory.cc
blob40c9e85902f003353761b81d6159a71151b59fb2
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"
7 #include <gbm.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"
24 namespace ui {
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,
50 32,
51 EGL_ALPHA_SIZE,
53 EGL_BLUE_SIZE,
55 EGL_GREEN_SIZE,
57 EGL_RED_SIZE,
59 EGL_RENDERABLE_TYPE,
60 EGL_OPENGL_ES2_BIT,
61 EGL_SURFACE_TYPE,
62 EGL_WINDOW_BIT,
63 EGL_NONE};
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";
79 return nullptr;
82 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
83 gfx::AcceleratedWidget widget) {
84 DCHECK(thread_checker_.CalledOnValidThread());
85 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
86 DCHECK(gbm);
88 scoped_ptr<GbmSurface> surface(
89 new GbmSurface(screen_manager_->GetWindow(widget), gbm));
90 if (!surface->Initialize())
91 return nullptr;
93 return surface.Pass();
96 scoped_ptr<SurfaceOzoneEGL>
97 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
98 gfx::AcceleratedWidget widget) {
99 DCHECK(thread_checker_.CalledOnValidThread());
100 if (!allow_surfaceless_)
101 return nullptr;
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,
109 gfx::Size size,
110 BufferFormat format,
111 BufferUsage usage) {
112 if (usage == MAP)
113 return nullptr;
115 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
116 DCHECK(gbm);
118 scoped_refptr<GbmBuffer> buffer =
119 GbmBuffer::CreateBuffer(gbm, format, size, true);
120 if (!buffer.get())
121 return nullptr;
123 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer, screen_manager_));
124 if (!pixmap->Initialize())
125 return nullptr;
127 return pixmap;
130 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
131 DCHECK(thread_checker_.CalledOnValidThread());
132 return allow_surfaceless_;
135 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) {
136 DCHECK(thread_checker_.CalledOnValidThread());
137 switch (usage) {
138 case MAP:
139 return false;
140 case PERSISTENT_MAP:
141 return false;
142 case SCANOUT:
143 return true;
145 NOTREACHED();
146 return false;
149 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice(
150 gfx::AcceleratedWidget widget) {
151 return static_cast<GbmDevice*>(
152 drm_device_manager_->GetDrmDevice(widget).get());
155 } // namespace ui