Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chromium
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Web
chromium
Commits
77ee9e5d
Commit
77ee9e5d
authored
Jul 26, 2017
by
Gustavo Noronha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HACK: use a separate thread to poll the Wayland socket
parent
38b78d1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
17 deletions
+62
-17
ui/ozone/platform/wayland/wayland_connection.cc
ui/ozone/platform/wayland/wayland_connection.cc
+50
-12
ui/ozone/platform/wayland/wayland_connection.h
ui/ozone/platform/wayland/wayland_connection.h
+12
-5
No files found.
ui/ozone/platform/wayland/wayland_connection.cc
View file @
77ee9e5d
...
...
@@ -7,11 +7,15 @@
#include <xdg-shell-unstable-v5-client-protocol.h>
#include <xdg-shell-unstable-v6-client-protocol.h>
#include <signal.h>
#include <poll.h>
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/ozone/platform/wayland/wayland_object.h"
#include "ui/ozone/platform/wayland/wayland_window.h"
...
...
@@ -36,6 +40,10 @@ WaylandConnection::WaylandConnection() : controller_(FROM_HERE) {}
WaylandConnection
::~
WaylandConnection
()
{
DCHECK
(
window_map_
.
empty
());
// Clear display explicitly to signal the poll in our thread
// that it should wake up and go away.
display_
.
reset
(
nullptr
);
}
bool
WaylandConnection
::
Initialize
()
{
...
...
@@ -84,6 +92,32 @@ bool WaylandConnection::Initialize() {
return
true
;
}
void
WaylandConnection
::
WaylandEventsThread
()
{
struct
pollfd
to_poll
=
{
wl_display_get_fd
(
display_
.
get
()),
POLLIN
,
0
};
for
(;;)
{
if
(
!
display_
)
break
;
if
(
wl_display_prepare_read
(
display_
.
get
())
!=
0
)
{
ui_task_runner_
->
PostTask
(
FROM_HERE
,
base
::
Bind
(
&
WaylandConnection
::
DispatchEvents
,
this
));
continue
;
}
int
events
=
poll
(
&
to_poll
,
1
,
10
);
if
(
events
==
0
||
!
(
to_poll
.
revents
&
POLLIN
))
{
wl_display_cancel_read
(
display_
.
get
());
continue
;
}
else
if
(
events
<
0
||
(
to_poll
.
revents
&
POLLHUP
))
{
break
;
}
wl_display_read_events
(
display_
.
get
());
ui_task_runner_
->
PostTask
(
FROM_HERE
,
base
::
Bind
(
&
WaylandConnection
::
DispatchEvents
,
this
));
}
}
bool
WaylandConnection
::
StartProcessingEvents
()
{
if
(
watching_
)
return
true
;
...
...
@@ -92,15 +126,27 @@ bool WaylandConnection::StartProcessingEvents() {
wl_display_flush
(
display_
.
get
());
DCHECK
(
base
::
MessageLoopForUI
::
IsCurrent
());
if
(
!
base
::
MessageLoopForUI
::
current
()
->
WatchFileDescriptor
(
wl_display_get_fd
(
display_
.
get
()),
true
,
base
::
MessagePumpLibevent
::
WATCH_READ
,
&
controller_
,
this
))
return
false
;
ui_task_runner_
=
base
::
MessageLoopForUI
::
current
()
->
task_runner
();
thread_
=
base
::
MakeUnique
<
base
::
Thread
>
(
"WaylandThread"
);
base
::
Thread
::
Options
thread_options
(
base
::
MessageLoop
::
TYPE_UI
,
0
);
thread_options
.
priority
=
base
::
ThreadPriority
::
NORMAL
;
CHECK
(
thread_
->
StartWithOptions
(
thread_options
));
thread_
->
task_runner
()
->
PostTask
(
FROM_HERE
,
base
::
Bind
(
&
WaylandConnection
::
WaylandEventsThread
,
this
));
watching_
=
true
;
return
true
;
}
void
WaylandConnection
::
DispatchEvents
()
{
wl_display_dispatch_pending
(
display_
.
get
());
for
(
const
auto
&
window
:
window_map_
)
window
.
second
->
ApplyPendingBounds
();
}
void
WaylandConnection
::
ScheduleFlush
()
{
if
(
scheduled_flush_
||
!
watching_
)
return
;
...
...
@@ -152,14 +198,6 @@ void WaylandConnection::DispatchUiEvent(Event* event) {
PlatformEventSource
::
DispatchEvent
(
event
);
}
void
WaylandConnection
::
OnFileCanReadWithoutBlocking
(
int
fd
)
{
wl_display_dispatch
(
display_
.
get
());
for
(
const
auto
&
window
:
window_map_
)
window
.
second
->
ApplyPendingBounds
();
}
void
WaylandConnection
::
OnFileCanWriteWithoutBlocking
(
int
fd
)
{}
const
std
::
vector
<
std
::
unique_ptr
<
WaylandOutput
>>&
WaylandConnection
::
GetOutputList
()
const
{
return
output_list_
;
...
...
ui/ozone/platform/wayland/wayland_connection.h
View file @
77ee9e5d
...
...
@@ -16,12 +16,17 @@
#include "ui/ozone/platform/wayland/wayland_pointer.h"
#include "ui/ozone/platform/wayland/wayland_touch.h"
namespace
base
{
class
SingleThreadTaskRunner
;
class
Thread
;
}
namespace
ui
{
class
WaylandWindow
;
class
WaylandConnection
:
public
PlatformEventSource
,
public
base
::
MessagePumpLibevent
::
Watcher
{
public
base
::
RefCountedThreadSafe
<
WaylandConnection
>
{
public:
WaylandConnection
();
~
WaylandConnection
()
override
;
...
...
@@ -65,10 +70,6 @@ class WaylandConnection : public PlatformEventSource,
// PlatformEventSource
void
OnDispatcherListChanged
()
override
;
// base::MessagePumpLibevent::Watcher
void
OnFileCanReadWithoutBlocking
(
int
fd
)
override
;
void
OnFileCanWriteWithoutBlocking
(
int
fd
)
override
;
// wl_registry_listener
static
void
Global
(
void
*
data
,
wl_registry
*
registry
,
...
...
@@ -87,6 +88,9 @@ class WaylandConnection : public PlatformEventSource,
// xdg_shell_listener
static
void
Ping
(
void
*
data
,
xdg_shell
*
shell
,
uint32_t
serial
);
void
WaylandEventsThread
();
void
DispatchEvents
();
#if defined(USE_ILM)
// serverinfo_listener
static
void
ServerInfo
(
void
*
data
,
struct
serverinfo
*
serverinfo
,
uint32_t
client_handle
);
...
...
@@ -120,6 +124,9 @@ class WaylandConnection : public PlatformEventSource,
// press event. It is used to create new subsurfaces.
uint32_t
serial_
=
0
;
std
::
unique_ptr
<
base
::
Thread
>
thread_
;
scoped_refptr
<
base
::
SingleThreadTaskRunner
>
ui_task_runner_
;
#if defined(USE_ILM)
uint32_t
connect_id_
=
0
;
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment