1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
#include <gbm.h>
#include "base/files/file_path.h"
#include "third_party/khronos/EGL/egl.h"
#include "ui/ozone/common/egl_util.h"
#include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
#include "ui/ozone/platform/drm/gpu/drm_window.h"
#include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
#include "ui/ozone/platform/drm/gpu/gbm_device.h"
#include "ui/ozone/platform/drm/gpu/gbm_surface.h"
#include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h"
#include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
#include "ui/ozone/platform/drm/gpu/screen_manager.h"
#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/surface_ozone_canvas.h"
#include "ui/ozone/public/surface_ozone_egl.h"
namespace ui {
GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless)
: DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) {
}
GbmSurfaceFactory::~GbmSurfaceFactory() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager,
ScreenManager* screen_manager) {
drm_device_manager_ = drm_device_manager;
screen_manager_ = screen_manager;
}
intptr_t GbmSurfaceFactory::GetNativeDisplay() {
DCHECK(thread_checker_.CalledOnValidThread());
return EGL_DEFAULT_DISPLAY;
}
const int32* GbmSurfaceFactory::GetEGLSurfaceProperties(
const int32* desired_list) {
DCHECK(thread_checker_.CalledOnValidThread());
static const int32 kConfigAttribs[] = {EGL_BUFFER_SIZE,
32,
EGL_ALPHA_SIZE,
8,
EGL_BLUE_SIZE,
8,
EGL_GREEN_SIZE,
8,
EGL_RED_SIZE,
8,
EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE,
EGL_WINDOW_BIT,
EGL_NONE};
return kConfigAttribs;
}
bool GbmSurfaceFactory::LoadEGLGLES2Bindings(
AddGLLibraryCallback add_gl_library,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
DCHECK(thread_checker_.CalledOnValidThread());
return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address);
}
scoped_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget(
gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
LOG(FATAL) << "Software rendering mode is not supported with GBM platform";
return nullptr;
}
scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
DCHECK(gbm);
scoped_ptr<GbmSurface> surface(
new GbmSurface(screen_manager_->GetWindow(widget), gbm));
if (!surface->Initialize())
return nullptr;
return surface.Pass();
}
scoped_ptr<SurfaceOzoneEGL>
GbmSurfaceFactory::CreateSurfacelessEGLSurfaceForWidget(
gfx::AcceleratedWidget widget) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!allow_surfaceless_)
return nullptr;
return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget),
drm_device_manager_));
}
scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
gfx::Size size,
BufferFormat format,
BufferUsage usage) {
if (usage == MAP)
return nullptr;
scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
DCHECK(gbm);
scoped_refptr<GbmBuffer> buffer =
GbmBuffer::CreateBuffer(gbm, format, size, true);
if (!buffer.get())
return nullptr;
scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer));
if (!pixmap->Initialize())
return nullptr;
return pixmap;
}
bool GbmSurfaceFactory::ScheduleOverlayPlane(
gfx::AcceleratedWidget widget,
int plane_z_order,
gfx::OverlayTransform plane_transform,
scoped_refptr<NativePixmap> buffer,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect) {
DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get());
if (!pixmap.get()) {
LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer.";
return false;
}
screen_manager_->GetWindow(widget)->QueueOverlayPlane(
OverlayPlane(pixmap->buffer(), plane_z_order, plane_transform,
display_bounds, crop_rect));
return true;
}
bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
DCHECK(thread_checker_.CalledOnValidThread());
return allow_surfaceless_;
}
bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) {
DCHECK(thread_checker_.CalledOnValidThread());
switch (usage) {
case MAP:
return false;
case PERSISTENT_MAP:
return false;
case SCANOUT:
return true;
}
NOTREACHED();
return false;
}
scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice(
gfx::AcceleratedWidget widget) {
return static_cast<GbmDevice*>(
drm_device_manager_->GetDrmDevice(widget).get());
}
} // namespace ui
|