ozone: gbm: Update hardware cursor in GPU process
[chromium-blink-merge.git] / ui / ozone / platform / dri / virtual_terminal_manager.cc
blobefd8350457755ff4c304c11e9bf803948c93b312
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/ozone/platform/dri/virtual_terminal_manager.h"
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <linux/kd.h>
10 #include <linux/vt.h>
11 #include <sys/ioctl.h>
12 #include <unistd.h>
14 #include "base/logging.h"
16 namespace ui {
18 namespace {
20 const char kTTYDevice[] = "/dev/tty1";
22 const int kVT = 1;
24 } // namespace
26 VirtualTerminalManager::VirtualTerminalManager() {
27 // Use the current console.
28 fd_ = open(kTTYDevice, O_RDWR | O_CLOEXEC, 0);
29 if (fd_ < 0)
30 LOG(ERROR) << "Failed to open '" << kTTYDevice << "' " << strerror(errno);
32 if (ioctl(fd_, VT_ACTIVATE, kVT) || ioctl(fd_, VT_WAITACTIVE, kVT))
33 LOG(ERROR) << "Failed to switch to VT: " << kVT
34 << " error: " << strerror(errno);;
36 if (ioctl(fd_, KDGETMODE, &vt_mode_))
37 LOG(ERROR) << "Failed to get VT mode: " << strerror(errno);
39 if (ioctl(fd_, KDSETMODE, KD_GRAPHICS))
40 LOG(ERROR) << "Failed to set graphics mode: " << strerror(errno);
42 if (tcgetattr(fd_, &terminal_attributes_))
43 LOG(ERROR) << "Failed to get terminal attributes";
45 // Stop the TTY from processing keys and echo-ing them to the terminal.
46 struct termios raw_attributes = terminal_attributes_;
47 cfmakeraw(&raw_attributes);
48 raw_attributes.c_oflag |= OPOST;
49 if (tcsetattr(fd_, TCSANOW, &raw_attributes))
50 LOG(ERROR) << "Failed to set raw attributes";
52 if (ioctl(fd_, KDGKBMODE, &previous_keyboard_mode_))
53 LOG(ERROR) << "Failed to get keyboard mode";
55 if (ioctl(fd_, KDSKBMODE, K_OFF) && ioctl(fd_, KDSKBMODE, K_RAW))
56 LOG(ERROR) << "Failed to set keyboard mode";
59 VirtualTerminalManager::~VirtualTerminalManager() {
60 if (fd_ < 0)
61 return;
63 if (ioctl(fd_, KDSETMODE, &vt_mode_))
64 LOG(ERROR) << "Failed to restore VT mode";
66 if (ioctl(fd_, KDSKBMODE, previous_keyboard_mode_))
67 LOG(ERROR) << "Failed to restore keyboard mode";
69 if (tcsetattr(fd_, TCSANOW, &terminal_attributes_))
70 LOG(ERROR) << "Failed to restore terminal attributes";
72 close(fd_);
75 } // namespace ui