| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/desktop_resizer.h" | 5 #include "remoting/host/desktop_resizer.h" |
| 6 #include "remoting/host/linux/x11_util.h" | 6 #include "remoting/host/linux/x11_util.h" |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <X11/extensions/Xrandr.h> | 9 #include <X11/extensions/Xrandr.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405. | 59 // TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405. |
| 60 const int kDefaultDPI = 96; | 60 const int kDefaultDPI = 96; |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 namespace remoting { | 64 namespace remoting { |
| 65 | 65 |
| 66 // Wrapper class for the XRRScreenResources struct. | 66 // Wrapper class for the XRRScreenResources struct. |
| 67 class ScreenResources { | 67 class ScreenResources { |
| 68 public: | 68 public: |
| 69 ScreenResources() : resources_(NULL) { | 69 ScreenResources() : resources_(nullptr) { |
| 70 } | 70 } |
| 71 | 71 |
| 72 ~ScreenResources() { | 72 ~ScreenResources() { |
| 73 Release(); | 73 Release(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool Refresh(Display* display, Window window) { | 76 bool Refresh(Display* display, Window window) { |
| 77 Release(); | 77 Release(); |
| 78 resources_ = XRRGetScreenResources(display, window); | 78 resources_ = XRRGetScreenResources(display, window); |
| 79 return resources_ != NULL; | 79 return resources_ != nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void Release() { | 82 void Release() { |
| 83 if (resources_) { | 83 if (resources_) { |
| 84 XRRFreeScreenResources(resources_); | 84 XRRFreeScreenResources(resources_); |
| 85 resources_ = NULL; | 85 resources_ = nullptr; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 RRMode GetIdForMode(const char* name) { | 89 RRMode GetIdForMode(const char* name) { |
| 90 CHECK(resources_); | 90 CHECK(resources_); |
| 91 for (int i = 0; i < resources_->nmode; ++i) { | 91 for (int i = 0; i < resources_->nmode; ++i) { |
| 92 const XRRModeInfo& mode = resources_->modes[i]; | 92 const XRRModeInfo& mode = resources_->modes[i]; |
| 93 if (strcmp(mode.name, name) == 0) { | 93 if (strcmp(mode.name, name) == 0) { |
| 94 return mode.id; | 94 return mode.id; |
| 95 } | 95 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 // Create a mode, and attach it to the primary output. If the mode already | 137 // Create a mode, and attach it to the primary output. If the mode already |
| 138 // exists, it is left unchanged. | 138 // exists, it is left unchanged. |
| 139 void CreateMode(const char* name, int width, int height); | 139 void CreateMode(const char* name, int width, int height); |
| 140 | 140 |
| 141 // Remove the specified mode from the primary output, and delete it. If the | 141 // Remove the specified mode from the primary output, and delete it. If the |
| 142 // mode is in use, it is not deleted. | 142 // mode is in use, it is not deleted. |
| 143 void DeleteMode(const char* name); | 143 void DeleteMode(const char* name); |
| 144 | 144 |
| 145 // Switch the primary output to the specified mode. If name is NULL, the | 145 // Switch the primary output to the specified mode. If name is nullptr, the |
| 146 // primary output is disabled instead, which is required before changing | 146 // primary output is disabled instead, which is required before changing |
| 147 // its resolution. | 147 // its resolution. |
| 148 void SwitchToMode(const char* name); | 148 void SwitchToMode(const char* name); |
| 149 | 149 |
| 150 Display* display_; | 150 Display* display_; |
| 151 int screen_; | 151 int screen_; |
| 152 Window root_; | 152 Window root_; |
| 153 ScreenResources resources_; | 153 ScreenResources resources_; |
| 154 bool exact_resize_; | 154 bool exact_resize_; |
| 155 | 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(DesktopResizerLinux); | 156 DISALLOW_COPY_AND_ASSIGN(DesktopResizerLinux); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 DesktopResizerLinux::DesktopResizerLinux() | 159 DesktopResizerLinux::DesktopResizerLinux() |
| 160 : display_(XOpenDisplay(NULL)), | 160 : display_(XOpenDisplay(nullptr)), |
| 161 screen_(DefaultScreen(display_)), | 161 screen_(DefaultScreen(display_)), |
| 162 root_(RootWindow(display_, screen_)), | 162 root_(RootWindow(display_, screen_)), |
| 163 exact_resize_(base::CommandLine::ForCurrentProcess()-> | 163 exact_resize_(base::CommandLine::ForCurrentProcess()-> |
| 164 HasSwitch("server-supports-exact-resize")) { | 164 HasSwitch("server-supports-exact-resize")) { |
| 165 XRRSelectInput(display_, root_, RRScreenChangeNotifyMask); | 165 XRRSelectInput(display_, root_, RRScreenChangeNotifyMask); |
| 166 } | 166 } |
| 167 | 167 |
| 168 DesktopResizerLinux::~DesktopResizerLinux() { | 168 DesktopResizerLinux::~DesktopResizerLinux() { |
| 169 XCloseDisplay(display_); | 169 XCloseDisplay(display_); |
| 170 } | 170 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 HOST_LOG << "Changing desktop size to " << resolution.dimensions().width() | 256 HOST_LOG << "Changing desktop size to " << resolution.dimensions().width() |
| 257 << "x" << resolution.dimensions().height(); | 257 << "x" << resolution.dimensions().height(); |
| 258 | 258 |
| 259 // TODO(lambroslambrou): Use the DPI from client size information. | 259 // TODO(lambroslambrou): Use the DPI from client size information. |
| 260 int width_mm = PixelsToMillimeters(resolution.dimensions().width(), | 260 int width_mm = PixelsToMillimeters(resolution.dimensions().width(), |
| 261 kDefaultDPI); | 261 kDefaultDPI); |
| 262 int height_mm = PixelsToMillimeters(resolution.dimensions().height(), | 262 int height_mm = PixelsToMillimeters(resolution.dimensions().height(), |
| 263 kDefaultDPI); | 263 kDefaultDPI); |
| 264 CreateMode(kTempModeName, resolution.dimensions().width(), | 264 CreateMode(kTempModeName, resolution.dimensions().width(), |
| 265 resolution.dimensions().height()); | 265 resolution.dimensions().height()); |
| 266 SwitchToMode(NULL); | 266 SwitchToMode(nullptr); |
| 267 XRRSetScreenSize(display_, root_, resolution.dimensions().width(), | 267 XRRSetScreenSize(display_, root_, resolution.dimensions().width(), |
| 268 resolution.dimensions().height(), width_mm, height_mm); | 268 resolution.dimensions().height(), width_mm, height_mm); |
| 269 SwitchToMode(kTempModeName); | 269 SwitchToMode(kTempModeName); |
| 270 DeleteMode(kModeName); | 270 DeleteMode(kModeName); |
| 271 CreateMode(kModeName, resolution.dimensions().width(), | 271 CreateMode(kModeName, resolution.dimensions().width(), |
| 272 resolution.dimensions().height()); | 272 resolution.dimensions().height()); |
| 273 SwitchToMode(kModeName); | 273 SwitchToMode(kModeName); |
| 274 DeleteMode(kTempModeName); | 274 DeleteMode(kTempModeName); |
| 275 } | 275 } |
| 276 | 276 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 304 RRMode mode_id = resources_.GetIdForMode(name); | 304 RRMode mode_id = resources_.GetIdForMode(name); |
| 305 if (mode_id) { | 305 if (mode_id) { |
| 306 XRRDeleteOutputMode(display_, resources_.GetOutput(), mode_id); | 306 XRRDeleteOutputMode(display_, resources_.GetOutput(), mode_id); |
| 307 XRRDestroyMode(display_, mode_id); | 307 XRRDestroyMode(display_, mode_id); |
| 308 resources_.Refresh(display_, root_); | 308 resources_.Refresh(display_, root_); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 void DesktopResizerLinux::SwitchToMode(const char* name) { | 312 void DesktopResizerLinux::SwitchToMode(const char* name) { |
| 313 RRMode mode_id = None; | 313 RRMode mode_id = None; |
| 314 RROutput* outputs = NULL; | 314 RROutput* outputs = nullptr; |
| 315 int number_of_outputs = 0; | 315 int number_of_outputs = 0; |
| 316 if (name) { | 316 if (name) { |
| 317 mode_id = resources_.GetIdForMode(name); | 317 mode_id = resources_.GetIdForMode(name); |
| 318 CHECK(mode_id); | 318 CHECK(mode_id); |
| 319 outputs = resources_.get()->outputs; | 319 outputs = resources_.get()->outputs; |
| 320 number_of_outputs = resources_.get()->noutput; | 320 number_of_outputs = resources_.get()->noutput; |
| 321 } | 321 } |
| 322 XRRSetCrtcConfig(display_, resources_.get(), resources_.GetCrtc(), | 322 XRRSetCrtcConfig(display_, resources_.get(), resources_.GetCrtc(), |
| 323 CurrentTime, 0, 0, mode_id, 1, outputs, number_of_outputs); | 323 CurrentTime, 0, 0, mode_id, 1, outputs, number_of_outputs); |
| 324 } | 324 } |
| 325 | 325 |
| 326 scoped_ptr<DesktopResizer> DesktopResizer::Create() { | 326 scoped_ptr<DesktopResizer> DesktopResizer::Create() { |
| 327 return make_scoped_ptr(new DesktopResizerLinux); | 327 return make_scoped_ptr(new DesktopResizerLinux); |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace remoting | 330 } // namespace remoting |
| OLD | NEW |