OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ui/display/chromeos/x11/native_display_delegate_x11.h" | 5 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 void NativeDisplayDelegateX11::ForceDPMSOn() { | 169 void NativeDisplayDelegateX11::ForceDPMSOn() { |
170 CHECK(DPMSEnable(display_)); | 170 CHECK(DPMSEnable(display_)); |
171 CHECK(DPMSForceLevel(display_, DPMSModeOn)); | 171 CHECK(DPMSForceLevel(display_, DPMSModeOn)); |
172 } | 172 } |
173 | 173 |
174 std::vector<DisplaySnapshot*> NativeDisplayDelegateX11::GetDisplays() { | 174 std::vector<DisplaySnapshot*> NativeDisplayDelegateX11::GetDisplays() { |
175 CHECK(screen_) << "Server not grabbed"; | 175 CHECK(screen_) << "Server not grabbed"; |
176 | 176 |
177 cached_outputs_.clear(); | 177 cached_outputs_.clear(); |
178 RRCrtc last_used_crtc = None; | 178 std::set<RRCrtc> last_used_crtcs; |
179 | 179 |
180 InitModes(); | 180 InitModes(); |
181 for (int i = 0; i < screen_->noutput && cached_outputs_.size() < 2; ++i) { | 181 for (int i = 0; i < screen_->noutput; ++i) { |
182 RROutput output_id = screen_->outputs[i]; | 182 RROutput output_id = screen_->outputs[i]; |
183 XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, output_id); | 183 XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, output_id); |
184 if (output_info->connection == RR_Connected) { | 184 if (output_info->connection == RR_Connected) { |
185 DisplaySnapshotX11* output = | 185 DisplaySnapshotX11* output = |
186 InitDisplaySnapshot(output_id, output_info, &last_used_crtc, i); | 186 InitDisplaySnapshot(output_id, output_info, &last_used_crtcs, i); |
187 cached_outputs_.push_back(output); | 187 cached_outputs_.push_back(output); |
188 } | 188 } |
189 XRRFreeOutputInfo(output_info); | 189 XRRFreeOutputInfo(output_info); |
190 } | 190 } |
191 | 191 |
192 return cached_outputs_.get(); | 192 return cached_outputs_.get(); |
193 } | 193 } |
194 | 194 |
195 void NativeDisplayDelegateX11::AddMode(const DisplaySnapshot& output, | 195 void NativeDisplayDelegateX11::AddMode(const DisplaySnapshot& output, |
196 const DisplayMode* mode) { | 196 const DisplayMode* mode) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 new DisplayModeX11(gfx::Size(info.width, info.height), | 308 new DisplayModeX11(gfx::Size(info.width, info.height), |
309 info.modeFlags & RR_Interlace, | 309 info.modeFlags & RR_Interlace, |
310 refresh_rate, | 310 refresh_rate, |
311 info.id))); | 311 info.id))); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 DisplaySnapshotX11* NativeDisplayDelegateX11::InitDisplaySnapshot( | 315 DisplaySnapshotX11* NativeDisplayDelegateX11::InitDisplaySnapshot( |
316 RROutput output, | 316 RROutput output, |
317 XRROutputInfo* info, | 317 XRROutputInfo* info, |
318 RRCrtc* last_used_crtc, | 318 std::set<RRCrtc>* last_used_crtcs, |
319 int index) { | 319 int index) { |
320 int64_t display_id = 0; | 320 int64_t display_id = 0; |
321 if (!GetDisplayId(output, static_cast<uint8_t>(index), &display_id)) | 321 if (!GetDisplayId(output, static_cast<uint8_t>(index), &display_id)) |
322 display_id = index; | 322 display_id = index; |
323 | 323 |
324 bool has_overscan = false; | 324 bool has_overscan = false; |
325 GetOutputOverscanFlag(output, &has_overscan); | 325 GetOutputOverscanFlag(output, &has_overscan); |
326 | 326 |
327 DisplayConnectionType type = GetDisplayConnectionTypeFromName(info->name); | 327 DisplayConnectionType type = GetDisplayConnectionTypeFromName(info->name); |
328 if (type == DISPLAY_CONNECTION_TYPE_UNKNOWN) | 328 if (type == DISPLAY_CONNECTION_TYPE_UNKNOWN) |
329 LOG(ERROR) << "Unknown link type: " << info->name; | 329 LOG(ERROR) << "Unknown link type: " << info->name; |
330 | 330 |
331 RRMode native_mode_id = GetOutputNativeMode(info); | 331 RRMode native_mode_id = GetOutputNativeMode(info); |
332 RRMode current_mode_id = None; | 332 RRMode current_mode_id = None; |
333 gfx::Point origin; | 333 gfx::Point origin; |
334 if (info->crtc) { | 334 if (info->crtc) { |
335 XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(display_, screen_, info->crtc); | 335 XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(display_, screen_, info->crtc); |
336 current_mode_id = crtc_info->mode; | 336 current_mode_id = crtc_info->mode; |
337 origin.SetPoint(crtc_info->x, crtc_info->y); | 337 origin.SetPoint(crtc_info->x, crtc_info->y); |
338 XRRFreeCrtcInfo(crtc_info); | 338 XRRFreeCrtcInfo(crtc_info); |
339 } | 339 } |
340 | 340 |
341 RRCrtc crtc = None; | 341 RRCrtc crtc = None; |
342 // Assign a CRTC that isn't already in use. | 342 // Assign a CRTC that isn't already in use. |
343 for (int i = 0; i < info->ncrtc; ++i) { | 343 for (int i = 0; i < info->ncrtc; ++i) { |
344 if (info->crtcs[i] != *last_used_crtc) { | 344 if (last_used_crtcs->find(info->crtcs[i]) == last_used_crtcs->end()) { |
345 crtc = info->crtcs[i]; | 345 crtc = info->crtcs[i]; |
346 *last_used_crtc = crtc; | 346 last_used_crtcs->insert(crtc); |
347 break; | 347 break; |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 const DisplayMode* current_mode = NULL; | 351 const DisplayMode* current_mode = NULL; |
352 const DisplayMode* native_mode = NULL; | 352 const DisplayMode* native_mode = NULL; |
353 std::vector<const DisplayMode*> display_modes; | 353 std::vector<const DisplayMode*> display_modes; |
354 | 354 |
355 for (int i = 0; i < info->nmode; ++i) { | 355 for (int i = 0; i < info->nmode; ++i) { |
356 const RRMode mode = info->modes[i]; | 356 const RRMode mode = info->modes[i]; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 XSetForeground(display_, gc, color.pixel); | 640 XSetForeground(display_, gc, color.pixel); |
641 XSetFillStyle(display_, gc, FillSolid); | 641 XSetFillStyle(display_, gc, FillSolid); |
642 int width = DisplayWidth(display_, DefaultScreen(display_)); | 642 int width = DisplayWidth(display_, DefaultScreen(display_)); |
643 int height = DisplayHeight(display_, DefaultScreen(display_)); | 643 int height = DisplayHeight(display_, DefaultScreen(display_)); |
644 XFillRectangle(display_, window_, gc, 0, 0, width, height); | 644 XFillRectangle(display_, window_, gc, 0, 0, width, height); |
645 XFreeGC(display_, gc); | 645 XFreeGC(display_, gc); |
646 XFreeColors(display_, colormap, &color.pixel, 1, 0); | 646 XFreeColors(display_, colormap, &color.pixel, 1, 0); |
647 } | 647 } |
648 | 648 |
649 } // namespace ui | 649 } // namespace ui |
OLD | NEW |