Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 1011173003: x11: Use gfx::XScopedPtr<> in more places. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/views/widget/desktop_aura/desktop_screen_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
6 6
7 #include <X11/extensions/Xrandr.h> 7 #include <X11/extensions/Xrandr.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 // It clashes with out RootWindow. 10 // It clashes with out RootWindow.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const std::vector<gfx::Display>& test_displays) 252 const std::vector<gfx::Display>& test_displays)
253 : xdisplay_(gfx::GetXDisplay()), 253 : xdisplay_(gfx::GetXDisplay()),
254 x_root_window_(DefaultRootWindow(xdisplay_)), 254 x_root_window_(DefaultRootWindow(xdisplay_)),
255 has_xrandr_(false), 255 has_xrandr_(false),
256 xrandr_event_base_(0), 256 xrandr_event_base_(0),
257 displays_(test_displays) { 257 displays_(test_displays) {
258 } 258 }
259 259
260 std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() { 260 std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() {
261 std::vector<gfx::Display> displays; 261 std::vector<gfx::Display> displays;
262 XRRScreenResources* resources = 262 gfx::XScopedPtr<
263 XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_); 263 XRRScreenResources,
264 gfx::XObjectDeleter<XRRScreenResources, void, XRRFreeScreenResources>>
265 resources(XRRGetScreenResourcesCurrent(xdisplay_, x_root_window_));
264 if (!resources) { 266 if (!resources) {
265 LOG(ERROR) << "XRandR returned no displays. Falling back to Root Window."; 267 LOG(ERROR) << "XRandR returned no displays. Falling back to Root Window.";
266 return GetFallbackDisplayList(); 268 return GetFallbackDisplayList();
267 } 269 }
268 270
269 bool has_work_area = false; 271 bool has_work_area = false;
270 gfx::Rect work_area; 272 gfx::Rect work_area;
271 std::vector<int> value; 273 std::vector<int> value;
272 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && 274 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) &&
273 value.size() >= 4) { 275 value.size() >= 4) {
274 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); 276 work_area = gfx::Rect(value[0], value[1], value[2], value[3]);
275 has_work_area = true; 277 has_work_area = true;
276 } 278 }
277 279
278 float device_scale_factor = 1.0f; 280 float device_scale_factor = 1.0f;
279 for (int i = 0; i < resources->noutput; ++i) { 281 for (int i = 0; i < resources->noutput; ++i) {
280 RROutput output_id = resources->outputs[i]; 282 RROutput output_id = resources->outputs[i];
281 XRROutputInfo* output_info = 283 gfx::XScopedPtr<XRROutputInfo,
282 XRRGetOutputInfo(xdisplay_, resources, output_id); 284 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>>
285 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id));
283 286
284 bool is_connected = (output_info->connection == RR_Connected); 287 bool is_connected = (output_info->connection == RR_Connected);
285 if (!is_connected) { 288 if (!is_connected)
286 XRRFreeOutputInfo(output_info);
287 continue; 289 continue;
288 }
289 290
290 if (output_info->crtc) { 291 if (output_info->crtc) {
291 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, 292 gfx::XScopedPtr<XRRCrtcInfo,
292 resources, 293 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>>
293 output_info->crtc); 294 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc));
294 295
295 int64 display_id = -1; 296 int64 display_id = -1;
296 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { 297 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) {
297 // It isn't ideal, but if we can't parse the EDID data, fallback on the 298 // It isn't ideal, but if we can't parse the EDID data, fallback on the
298 // display number. 299 // display number.
299 display_id = i; 300 display_id = i;
300 } 301 }
301 302
302 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 303 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
303 gfx::Display display(display_id, crtc_bounds); 304 gfx::Display display(display_id, crtc_bounds);
(...skipping 25 matching lines...) Expand all
329 break; 330 break;
330 case RR_Rotate_180: 331 case RR_Rotate_180:
331 display.set_rotation(gfx::Display::ROTATE_180); 332 display.set_rotation(gfx::Display::ROTATE_180);
332 break; 333 break;
333 case RR_Rotate_270: 334 case RR_Rotate_270:
334 display.set_rotation(gfx::Display::ROTATE_270); 335 display.set_rotation(gfx::Display::ROTATE_270);
335 break; 336 break;
336 } 337 }
337 338
338 displays.push_back(display); 339 displays.push_back(display);
339
340 XRRFreeCrtcInfo(crtc);
341 } 340 }
342
343 XRRFreeOutputInfo(output_info);
344 } 341 }
345 342
346 XRRFreeScreenResources(resources);
347
348 if (displays.empty()) 343 if (displays.empty())
349 return GetFallbackDisplayList(); 344 return GetFallbackDisplayList();
350 345
351 return displays; 346 return displays;
352 } 347 }
353 348
354 void DesktopScreenX11::ConfigureTimerFired() { 349 void DesktopScreenX11::ConfigureTimerFired() {
355 std::vector<gfx::Display> old_displays = displays_; 350 std::vector<gfx::Display> old_displays = displays_;
356 displays_ = BuildDisplaysFromXRandRInfo(); 351 displays_ = BuildDisplaysFromXRandRInfo();
357 352
358 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 353 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
359 } 354 }
360 355
361 //////////////////////////////////////////////////////////////////////////////// 356 ////////////////////////////////////////////////////////////////////////////////
362 357
363 gfx::Screen* CreateDesktopScreen() { 358 gfx::Screen* CreateDesktopScreen() {
364 return new DesktopScreenX11; 359 return new DesktopScreenX11;
365 } 360 }
366 361
367 } // namespace views 362 } // namespace views
OLDNEW
« no previous file with comments | « ui/display/chromeos/x11/native_display_delegate_x11.cc ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698