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

Side by Side Diff: ui/display/chromeos/x11/native_display_delegate_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 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 DISALLOW_COPY_AND_ASSIGN(HelperDelegateX11); 99 DISALLOW_COPY_AND_ASSIGN(HelperDelegateX11);
100 }; 100 };
101 101
102 //////////////////////////////////////////////////////////////////////////////// 102 ////////////////////////////////////////////////////////////////////////////////
103 // NativeDisplayDelegateX11 implementation: 103 // NativeDisplayDelegateX11 implementation:
104 104
105 NativeDisplayDelegateX11::NativeDisplayDelegateX11() 105 NativeDisplayDelegateX11::NativeDisplayDelegateX11()
106 : display_(gfx::GetXDisplay()), 106 : display_(gfx::GetXDisplay()),
107 window_(DefaultRootWindow(display_)), 107 window_(DefaultRootWindow(display_)),
108 screen_(NULL),
109 background_color_argb_(0) {} 108 background_color_argb_(0) {}
110 109
111 NativeDisplayDelegateX11::~NativeDisplayDelegateX11() { 110 NativeDisplayDelegateX11::~NativeDisplayDelegateX11() {
112 if (ui::PlatformEventSource::GetInstance()) { 111 if (ui::PlatformEventSource::GetInstance()) {
113 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher( 112 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(
114 platform_event_dispatcher_.get()); 113 platform_event_dispatcher_.get());
115 } 114 }
116 115
117 STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end()); 116 STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end());
118 } 117 }
119 118
120 void NativeDisplayDelegateX11::Initialize() { 119 void NativeDisplayDelegateX11::Initialize() {
121 int error_base_ignored = 0; 120 int error_base_ignored = 0;
122 int xrandr_event_base = 0; 121 int xrandr_event_base = 0;
123 XRRQueryExtension(display_, &xrandr_event_base, &error_base_ignored); 122 XRRQueryExtension(display_, &xrandr_event_base, &error_base_ignored);
124 123
125 helper_delegate_.reset(new HelperDelegateX11(this)); 124 helper_delegate_.reset(new HelperDelegateX11(this));
126 platform_event_dispatcher_.reset(new NativeDisplayEventDispatcherX11( 125 platform_event_dispatcher_.reset(new NativeDisplayEventDispatcherX11(
127 helper_delegate_.get(), xrandr_event_base)); 126 helper_delegate_.get(), xrandr_event_base));
128 127
129 if (ui::PlatformEventSource::GetInstance()) { 128 if (ui::PlatformEventSource::GetInstance()) {
130 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher( 129 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(
131 platform_event_dispatcher_.get()); 130 platform_event_dispatcher_.get());
132 } 131 }
133 } 132 }
134 133
135 void NativeDisplayDelegateX11::GrabServer() { 134 void NativeDisplayDelegateX11::GrabServer() {
136 CHECK(!screen_) << "Server already grabbed"; 135 CHECK(!screen_) << "Server already grabbed";
137 XGrabServer(display_); 136 XGrabServer(display_);
138 screen_ = XRRGetScreenResources(display_, window_); 137 screen_.reset(XRRGetScreenResources(display_, window_));
139 CHECK(screen_); 138 CHECK(screen_);
140 } 139 }
141 140
142 void NativeDisplayDelegateX11::UngrabServer() { 141 void NativeDisplayDelegateX11::UngrabServer() {
143 CHECK(screen_) << "Server not grabbed"; 142 CHECK(screen_) << "Server not grabbed";
144 XRRFreeScreenResources(screen_); 143 screen_.reset();
145 screen_ = NULL;
146 XUngrabServer(display_); 144 XUngrabServer(display_);
147 // crbug.com/366125 145 // crbug.com/366125
148 XFlush(display_); 146 XFlush(display_);
149 } 147 }
150 148
151 bool NativeDisplayDelegateX11::TakeDisplayControl() { 149 bool NativeDisplayDelegateX11::TakeDisplayControl() {
152 NOTIMPLEMENTED(); 150 NOTIMPLEMENTED();
153 return false; 151 return false;
154 } 152 }
155 153
(...skipping 16 matching lines...) Expand all
172 void NativeDisplayDelegateX11::GetDisplays( 170 void NativeDisplayDelegateX11::GetDisplays(
173 const GetDisplaysCallback& callback) { 171 const GetDisplaysCallback& callback) {
174 CHECK(screen_) << "Server not grabbed"; 172 CHECK(screen_) << "Server not grabbed";
175 173
176 cached_outputs_.clear(); 174 cached_outputs_.clear();
177 std::set<RRCrtc> last_used_crtcs; 175 std::set<RRCrtc> last_used_crtcs;
178 176
179 InitModes(); 177 InitModes();
180 for (int i = 0; i < screen_->noutput; ++i) { 178 for (int i = 0; i < screen_->noutput; ++i) {
181 RROutput output_id = screen_->outputs[i]; 179 RROutput output_id = screen_->outputs[i];
182 XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, output_id); 180 XRROutputInfo* output_info =
181 XRRGetOutputInfo(display_, screen_.get(), output_id);
183 if (output_info->connection == RR_Connected) { 182 if (output_info->connection == RR_Connected) {
184 DisplaySnapshotX11* output = 183 DisplaySnapshotX11* output =
185 InitDisplaySnapshot(output_id, output_info, &last_used_crtcs, i); 184 InitDisplaySnapshot(output_id, output_info, &last_used_crtcs, i);
186 cached_outputs_.push_back(output); 185 cached_outputs_.push_back(output);
187 } 186 }
188 XRRFreeOutputInfo(output_info); 187 XRRFreeOutputInfo(output_info);
189 } 188 }
190 189
191 callback.Run(cached_outputs_.get()); 190 callback.Run(cached_outputs_.get());
192 } 191 }
(...skipping 30 matching lines...) Expand all
223 RRMode mode, 222 RRMode mode,
224 RROutput output, 223 RROutput output,
225 int x, 224 int x,
226 int y) { 225 int y) {
227 CHECK(screen_) << "Server not grabbed"; 226 CHECK(screen_) << "Server not grabbed";
228 VLOG(1) << "ConfigureCrtc: crtc=" << crtc << " mode=" << mode 227 VLOG(1) << "ConfigureCrtc: crtc=" << crtc << " mode=" << mode
229 << " output=" << output << " x=" << x << " y=" << y; 228 << " output=" << output << " x=" << x << " y=" << y;
230 // Xrandr.h is full of lies. XRRSetCrtcConfig() is defined as returning a 229 // Xrandr.h is full of lies. XRRSetCrtcConfig() is defined as returning a
231 // Status, which is typically 0 for failure and 1 for success. In 230 // Status, which is typically 0 for failure and 1 for success. In
232 // actuality it returns a RRCONFIGSTATUS, which uses 0 for success. 231 // actuality it returns a RRCONFIGSTATUS, which uses 0 for success.
233 if (XRRSetCrtcConfig(display_, 232 if (XRRSetCrtcConfig(display_, screen_.get(), crtc, CurrentTime, x, y, mode,
234 screen_, 233 RR_Rotate_0, (output && mode) ? &output : NULL,
235 crtc,
236 CurrentTime,
237 x,
238 y,
239 mode,
240 RR_Rotate_0,
241 (output && mode) ? &output : NULL,
242 (output && mode) ? 1 : 0) != RRSetConfigSuccess) { 234 (output && mode) ? 1 : 0) != RRSetConfigSuccess) {
243 LOG(WARNING) << "Unable to configure CRTC " << crtc << ":" 235 LOG(WARNING) << "Unable to configure CRTC " << crtc << ":"
244 << " mode=" << mode << " output=" << output << " x=" << x 236 << " mode=" << mode << " output=" << output << " x=" << x
245 << " y=" << y; 237 << " y=" << y;
246 return false; 238 return false;
247 } 239 }
248 240
249 return true; 241 return true;
250 } 242 }
251 243
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 GetOutputOverscanFlag(output, &has_overscan); 317 GetOutputOverscanFlag(output, &has_overscan);
326 318
327 DisplayConnectionType type = GetDisplayConnectionTypeFromName(info->name); 319 DisplayConnectionType type = GetDisplayConnectionTypeFromName(info->name);
328 if (type == DISPLAY_CONNECTION_TYPE_UNKNOWN) 320 if (type == DISPLAY_CONNECTION_TYPE_UNKNOWN)
329 LOG(ERROR) << "Unknown link type: " << info->name; 321 LOG(ERROR) << "Unknown link type: " << info->name;
330 322
331 RRMode native_mode_id = GetOutputNativeMode(info); 323 RRMode native_mode_id = GetOutputNativeMode(info);
332 RRMode current_mode_id = None; 324 RRMode current_mode_id = None;
333 gfx::Point origin; 325 gfx::Point origin;
334 if (info->crtc) { 326 if (info->crtc) {
335 XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(display_, screen_, info->crtc); 327 XRRCrtcInfo* crtc_info =
328 XRRGetCrtcInfo(display_, screen_.get(), info->crtc);
336 current_mode_id = crtc_info->mode; 329 current_mode_id = crtc_info->mode;
337 origin.SetPoint(crtc_info->x, crtc_info->y); 330 origin.SetPoint(crtc_info->x, crtc_info->y);
338 XRRFreeCrtcInfo(crtc_info); 331 XRRFreeCrtcInfo(crtc_info);
339 } 332 }
340 333
341 RRCrtc crtc = None; 334 RRCrtc crtc = None;
342 // Assign a CRTC that isn't already in use. 335 // Assign a CRTC that isn't already in use.
343 for (int i = 0; i < info->ncrtc; ++i) { 336 for (int i = 0; i < info->ncrtc; ++i) {
344 if (last_used_crtcs->find(info->crtcs[i]) == last_used_crtcs->end()) { 337 if (last_used_crtcs->find(info->crtcs[i]) == last_used_crtcs->end()) {
345 crtc = info->crtcs[i]; 338 crtc = info->crtcs[i];
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 XSetForeground(display_, gc, color.pixel); 627 XSetForeground(display_, gc, color.pixel);
635 XSetFillStyle(display_, gc, FillSolid); 628 XSetFillStyle(display_, gc, FillSolid);
636 int width = DisplayWidth(display_, DefaultScreen(display_)); 629 int width = DisplayWidth(display_, DefaultScreen(display_));
637 int height = DisplayHeight(display_, DefaultScreen(display_)); 630 int height = DisplayHeight(display_, DefaultScreen(display_));
638 XFillRectangle(display_, window_, gc, 0, 0, width, height); 631 XFillRectangle(display_, window_, gc, 0, 0, width, height);
639 XFreeGC(display_, gc); 632 XFreeGC(display_, gc);
640 XFreeColors(display_, colormap, &color.pixel, 1, 0); 633 XFreeColors(display_, colormap, &color.pixel, 1, 0);
641 } 634 }
642 635
643 } // namespace ui 636 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/chromeos/x11/native_display_delegate_x11.h ('k') | ui/views/widget/desktop_aura/desktop_screen_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698