Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: ui/ozone/platform/drm/gpu/gbm_surface_factory.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
6
7 #include <gbm.h>
8
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"
23
24 namespace ui {
25
26 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless)
27 : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) {
28 }
29
30 GbmSurfaceFactory::~GbmSurfaceFactory() {
31 DCHECK(thread_checker_.CalledOnValidThread());
32 }
33
34 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager,
35 ScreenManager* screen_manager) {
36 drm_device_manager_ = drm_device_manager;
37 screen_manager_ = screen_manager;
38 }
39
40 intptr_t GbmSurfaceFactory::GetNativeDisplay() {
41 DCHECK(thread_checker_.CalledOnValidThread());
42 auto primary_device = drm_device_manager_->GetDrmDevice(
43 gfx::kNullAcceleratedWidget);
44 DCHECK(primary_device.get());
45 auto gbm_device = static_cast<GbmDevice*>(primary_device.get());
46 return reinterpret_cast<EGLNativeDisplayType>(gbm_device->device());
47 }
48
49 const int32* GbmSurfaceFactory::GetEGLSurfaceProperties(
50 const int32* desired_list) {
51 DCHECK(thread_checker_.CalledOnValidThread());
52 static const int32 kConfigAttribs[] = {EGL_BUFFER_SIZE,
53 32,
54 EGL_ALPHA_SIZE,
55 8,
56 EGL_BLUE_SIZE,
57 8,
58 EGL_GREEN_SIZE,
59 8,
60 EGL_RED_SIZE,
61 8,
62 EGL_RENDERABLE_TYPE,
63 EGL_OPENGL_ES2_BIT,
64 EGL_SURFACE_TYPE,
65 EGL_WINDOW_BIT,
66 EGL_NONE};
67
68 return kConfigAttribs;
69 }
70
71 bool GbmSurfaceFactory::LoadEGLGLES2Bindings(
72 AddGLLibraryCallback add_gl_library,
73 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address);
76 }
77
78 scoped_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget(
79 gfx::AcceleratedWidget widget) {
80 DCHECK(thread_checker_.CalledOnValidThread());
81 LOG(FATAL) << "Software rendering mode is not supported with GBM platform";
82 return nullptr;
83 }
84
85 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
86 gfx::AcceleratedWidget widget) {
87 DCHECK(thread_checker_.CalledOnValidThread());
88 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
89 DCHECK(gbm);
90
91 scoped_ptr<GbmSurface> surface(
92 new GbmSurface(screen_manager_->GetWindow(widget), gbm));
93 if (!surface->Initialize())
94 return nullptr;
95
96 return surface.Pass();
97 }
98
99 scoped_ptr<SurfaceOzoneEGL>
100 GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
101 gfx::AcceleratedWidget widget) {
102 DCHECK(thread_checker_.CalledOnValidThread());
103 if (!allow_surfaceless_)
104 return nullptr;
105
106 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget),
107 drm_device_manager_));
108 }
109
110 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
111 gfx::AcceleratedWidget widget,
112 gfx::Size size,
113 BufferFormat format,
114 BufferUsage usage) {
115 if (usage == MAP)
116 return nullptr;
117
118 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
119 DCHECK(gbm);
120
121 scoped_refptr<GbmBuffer> buffer =
122 GbmBuffer::CreateBuffer(gbm, format, size, true);
123 if (!buffer.get())
124 return nullptr;
125
126 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer, screen_manager_));
127 if (!pixmap->Initialize())
128 return nullptr;
129
130 return pixmap;
131 }
132
133 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
134 DCHECK(thread_checker_.CalledOnValidThread());
135 return allow_surfaceless_;
136 }
137
138 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) {
139 DCHECK(thread_checker_.CalledOnValidThread());
140 switch (usage) {
141 case MAP:
142 return false;
143 case PERSISTENT_MAP:
144 return false;
145 case SCANOUT:
146 return true;
147 }
148 NOTREACHED();
149 return false;
150 }
151
152 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice(
153 gfx::AcceleratedWidget widget) {
154 return static_cast<GbmDevice*>(
155 drm_device_manager_->GetDrmDevice(widget).get());
156 }
157
158 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/gbm_surface_factory.h ('k') | ui/ozone/platform/drm/gpu/gbm_surfaceless.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698