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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
// Copyright 2015 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 "components/exo/display.h"
#include <iterator>
#include <utility>
#include "ash/public/cpp/shell_window_ids.h"
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/exo/notification_surface.h"
#include "components/exo/notification_surface_manager.h"
#include "components/exo/shared_memory.h"
#include "components/exo/shell_surface.h"
#include "components/exo/sub_surface.h"
#include "components/exo/surface.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
#if defined(USE_OZONE)
#include <GLES2/gl2extchromium.h>
#include "components/exo/buffer.h"
#include "gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "ui/ozone/public/ozone_switches.h"
#endif
namespace exo {
namespace {
#if defined(USE_OZONE)
// TODO(dcastagna): The following formats should be determined at runtime
// querying kms (via ozone).
const gfx::BufferFormat kOverlayFormats[] = {
// TODO(dcastagna): Remove RGBX/RGBA once all the platforms using the fullscreen
// optimization will have switched to atomic.
#if defined(ARCH_CPU_ARM_FAMILY)
gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::RGBA_8888,
#endif
gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::BGRA_8888};
const gfx::BufferFormat kOverlayFormatsForDrmAtomic[] = {
gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::RGBA_8888,
gfx::BufferFormat::BGR_565};
#endif
} // namespace
////////////////////////////////////////////////////////////////////////////////
// Display, public:
Display::Display() : Display(nullptr) {}
Display::Display(NotificationSurfaceManager* notification_surface_manager)
: notification_surface_manager_(notification_surface_manager)
#if defined(USE_OZONE)
,
overlay_formats_(std::begin(kOverlayFormats), std::end(kOverlayFormats))
#endif
{
#if defined(USE_OZONE)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDrmAtomic)) {
overlay_formats_.insert(overlay_formats_.end(),
std::begin(kOverlayFormatsForDrmAtomic),
std::end(kOverlayFormatsForDrmAtomic));
}
#endif
}
Display::~Display() {}
std::unique_ptr<Surface> Display::CreateSurface() {
TRACE_EVENT0("exo", "Display::CreateSurface");
return base::WrapUnique(new Surface);
}
std::unique_ptr<SharedMemory> Display::CreateSharedMemory(
const base::SharedMemoryHandle& handle,
size_t size) {
TRACE_EVENT1("exo", "Display::CreateSharedMemory", "size", size);
if (!base::SharedMemory::IsHandleValid(handle))
return nullptr;
return base::MakeUnique<SharedMemory>(handle);
}
#if defined(USE_OZONE)
std::unique_ptr<Buffer> Display::CreateLinuxDMABufBuffer(
const gfx::Size& size,
gfx::BufferFormat format,
const std::vector<gfx::NativePixmapPlane>& planes,
std::vector<base::ScopedFD>&& fds) {
TRACE_EVENT1("exo", "Display::CreateLinuxDMABufBuffer", "size",
size.ToString());
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::OZONE_NATIVE_PIXMAP;
for (auto& fd : fds)
handle.native_pixmap_handle.fds.emplace_back(std::move(fd));
for (auto& plane : planes)
handle.native_pixmap_handle.planes.push_back(plane);
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer =
gpu::GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle(
handle, size, format, gfx::BufferUsage::GPU_READ,
gpu::GpuMemoryBufferImpl::DestructionCallback());
if (!gpu_memory_buffer) {
LOG(ERROR) << "Failed to create GpuMemoryBuffer from handle";
return nullptr;
}
// Using zero-copy for optimal performance.
bool use_zero_copy = true;
bool is_overlay_candidate =
std::find(overlay_formats_.begin(), overlay_formats_.end(), format) !=
overlay_formats_.end();
return base::MakeUnique<Buffer>(
std::move(gpu_memory_buffer), GL_TEXTURE_EXTERNAL_OES,
// COMMANDS_COMPLETED queries are required by native pixmaps.
GL_COMMANDS_COMPLETED_CHROMIUM, use_zero_copy, is_overlay_candidate);
}
#endif
std::unique_ptr<ShellSurface> Display::CreateShellSurface(Surface* surface) {
TRACE_EVENT1("exo", "Display::CreateShellSurface", "surface",
surface->AsTracedValue());
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
return base::MakeUnique<ShellSurface>(
surface, nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true /* activatable */, false /* can_minimize */,
ash::kShellWindowId_DefaultContainer);
}
std::unique_ptr<ShellSurface> Display::CreatePopupShellSurface(
Surface* surface,
ShellSurface* parent,
const gfx::Point& position) {
TRACE_EVENT2("exo", "Display::CreatePopupShellSurface", "surface",
surface->AsTracedValue(), "parent", parent->AsTracedValue());
if (surface->window()->Contains(parent->GetWidget()->GetNativeWindow())) {
DLOG(ERROR) << "Parent is contained within surface's hierarchy";
return nullptr;
}
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
// |position| is relative to the parent's main surface origin, and |origin| is
// in screen coordinates.
gfx::Point origin = position;
wm::ConvertPointToScreen(
ShellSurface::GetMainSurface(parent->GetWidget()->GetNativeWindow())
->window(),
&origin);
return base::MakeUnique<ShellSurface>(
surface, parent, ShellSurface::BoundsMode::FIXED, origin,
false /* activatable */, false /* can_minimize */,
ash::kShellWindowId_DefaultContainer);
}
std::unique_ptr<ShellSurface> Display::CreateRemoteShellSurface(
Surface* surface,
const gfx::Point& origin,
int container) {
TRACE_EVENT2("exo", "Display::CreateRemoteShellSurface", "surface",
surface->AsTracedValue(), "container", container);
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
// Remote shell surfaces in system modal container cannot be minimized.
bool can_minimize = container != ash::kShellWindowId_SystemModalContainer;
return base::MakeUnique<ShellSurface>(
surface, nullptr, ShellSurface::BoundsMode::CLIENT, origin,
true /* activatable */, can_minimize, container);
}
std::unique_ptr<SubSurface> Display::CreateSubSurface(Surface* surface,
Surface* parent) {
TRACE_EVENT2("exo", "Display::CreateSubSurface", "surface",
surface->AsTracedValue(), "parent", parent->AsTracedValue());
if (surface->window()->Contains(parent->window())) {
DLOG(ERROR) << "Parent is contained within surface's hierarchy";
return nullptr;
}
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
return base::MakeUnique<SubSurface>(surface, parent);
}
std::unique_ptr<NotificationSurface> Display::CreateNotificationSurface(
Surface* surface,
const std::string& notification_id) {
TRACE_EVENT2("exo", "Display::CreateNotificationSurface", "surface",
surface->AsTracedValue(), "notification_id", notification_id);
if (!notification_surface_manager_ ||
notification_surface_manager_->GetSurface(notification_id)) {
DLOG(ERROR) << "Invalid notification id, id=" << notification_id;
return nullptr;
}
return base::MakeUnique<NotificationSurface>(notification_surface_manager_,
surface, notification_id);
}
} // namespace exo
|