Disable discard_framebuffer on ARM Mali-400 on Linux
[chromium-blink-merge.git] / ui / base / x / x11_foreign_window_manager.cc
blobf40ac34036eff17195af363937496a6dbcb0b1d3
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/base/x/x11_foreign_window_manager.h"
7 #include <X11/Xlib.h>
9 #include "base/compiler_specific.h"
10 #include "base/memory/singleton.h"
12 namespace ui {
14 // static
15 XForeignWindowManager* XForeignWindowManager::GetInstance() {
16 return Singleton<XForeignWindowManager>::get();
19 int XForeignWindowManager::RequestEvents(XID xid, long event_mask) {
20 request_map_[xid].push_back(Request(next_request_id_, event_mask));
21 UpdateSelectedEvents(xid);
22 return next_request_id_++;
25 void XForeignWindowManager::CancelRequest(int request_id) {
26 for (std::map<XID, RequestVector>::iterator map_it = request_map_.begin();
27 map_it != request_map_.end(); ++map_it) {
28 RequestVector* vector = &map_it->second;
29 for (RequestVector::iterator vector_it = vector->begin();
30 vector_it != vector->end(); ++vector_it) {
31 if (vector_it->request_id == request_id) {
32 vector->erase(vector_it);
33 UpdateSelectedEvents(map_it->first);
34 if (vector->empty())
35 request_map_.erase(map_it);
36 return;
42 void XForeignWindowManager::OnWindowDestroyed(XID xid) {
43 request_map_.erase(xid);
46 XForeignWindowManager::XForeignWindowManager() : next_request_id_(0) {
49 XForeignWindowManager::~XForeignWindowManager() {
52 void XForeignWindowManager::UpdateSelectedEvents(XID xid) {
53 std::map<XID, RequestVector>::iterator it = request_map_.find(xid);
54 if (it == request_map_.end())
55 return;
57 long event_mask = NoEventMask;
58 const RequestVector& list = it->second;
59 for (size_t i = 0; i < list.size(); ++i)
60 event_mask |= list[i].event_mask;
62 XSelectInput(gfx::GetXDisplay(), xid, event_mask);
65 XForeignWindowManager::Request::Request(int request_id, long event_mask)
66 : request_id(request_id),
67 event_mask(event_mask) {
70 XForeignWindowManager::Request::~Request() {
73 } // namespace ui