Chromium Code Reviews| Index: ash/display/display_change_observer_x11.cc |
| diff --git a/ash/display/display_change_observer_x11.cc b/ash/display/display_change_observer_x11.cc |
| index 2802e6c8984a836f65e3cbfb61e23587db525594..19b368285cb767cbf97b7c7188785d4305d95be7 100644 |
| --- a/ash/display/display_change_observer_x11.cc |
| +++ b/ash/display/display_change_observer_x11.cc |
| @@ -9,8 +9,6 @@ |
| #include <set> |
| #include <vector> |
| -#include <X11/extensions/Xrandr.h> |
| - |
| #include "ash/ash_switches.h" |
| #include "ash/display/display_info.h" |
| #include "ash/display/display_layout_store.h" |
| @@ -39,22 +37,9 @@ const unsigned int kHighDensityDPIThreshold = 160; |
| // 1 inch in mm. |
| const float kInchInMm = 25.4f; |
| -int64 GetDisplayId(XID output, size_t output_index) { |
| - int64 display_id; |
| - if (chromeos::GetDisplayId(output, output_index, &display_id)) |
| - return display_id; |
| - return gfx::Display::kInvalidDisplayID; |
| -} |
| - |
| } // namespace |
| -DisplayChangeObserverX11::DisplayChangeObserverX11() |
| - : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| - x_root_window_(DefaultRootWindow(xdisplay_)), |
| - xrandr_event_base_(0) { |
| - int error_base_ignored; |
| - XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); |
| - |
| +DisplayChangeObserverX11::DisplayChangeObserverX11() { |
| Shell::GetInstance()->AddShellObserver(this); |
| } |
| @@ -94,82 +79,47 @@ bool DisplayChangeObserverX11::GetResolutionForDisplayId(int64 display_id, |
| void DisplayChangeObserverX11::OnDisplayModeChanged( |
| const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| - // TODO(derat): Use |outputs| instead of re-fetching information. |
| - XRRScreenResources* screen_resources = |
| - XRRGetScreenResources(xdisplay_, x_root_window_); |
| - std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| - |
| - for (int c = 0; c < screen_resources->ncrtc; c++) { |
| - XID crtc_id = screen_resources->crtcs[c]; |
| - XRRCrtcInfo *crtc_info = |
| - XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); |
| - crtc_info_map[crtc_id] = crtc_info; |
| - } |
| - |
| std::vector<DisplayInfo> displays; |
| std::set<int64> ids; |
| - for (int output_index = 0; output_index < screen_resources->noutput; |
| - output_index++) { |
| - XID output = screen_resources->outputs[output_index]; |
| - XRROutputInfo *output_info = |
| - XRRGetOutputInfo(xdisplay_, screen_resources, output); |
| + for (size_t output_index = 0; output_index < outputs.size(); ++output_index) { |
| + const OutputConfigurator::OutputSnapshot& output = outputs[output_index]; |
| - const bool is_internal = chromeos::IsInternalOutputName( |
| - std::string(output_info->name)); |
| - |
| - if (is_internal && |
| + if (output.is_internal && |
| gfx::Display::InternalDisplayId() == gfx::Display::kInvalidDisplayID) { |
| - int64 id = GetDisplayId(output, output_index); |
| - // Fallback to output index. crbug.com/180100 |
| + // Fall back to output index. crbug.com/180100 |
| gfx::Display::SetInternalDisplayId( |
| - id == gfx::Display::kInvalidDisplayID ? output_index : id); |
| + output.display_id == gfx::Display::kInvalidDisplayID ? output_index : |
| + output.display_id); |
|
oshima
2013/08/16 23:13:05
output_index is different from the index of output
Daniel Erat
2013/08/16 23:35:36
Thanks, I'll store the original index in the Outpu
oshima
2013/08/19 20:00:24
This doesn't seem to be in the CL?
Daniel Erat
2013/08/19 22:09:30
Whoops, sorry. Adding.
|
| } |
| - if (output_info->connection != RR_Connected) { |
| - XRRFreeOutputInfo(output_info); |
| - continue; |
| - } |
| - const XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; |
| - if (!crtc_info) { |
| - LOG(WARNING) << "Crtc not found for output: output_index=" |
| - << output_index; |
| - continue; |
| - } |
| - const XRRModeInfo* mode = |
| - chromeos::FindXRRModeInfo(screen_resources, crtc_info->mode); |
| - if (!mode) { |
| - LOG(WARNING) << "Could not find a mode for the output: output_index=" |
| - << output_index; |
| + const OutputConfigurator::ModeInfo* mode_info = |
| + OutputConfigurator::GetModeInfo(output, output.current_mode); |
| + if (!mode_info) |
| continue; |
| - } |
| float device_scale_factor = 1.0f; |
| - if (!ShouldIgnoreSize(output_info->mm_width, output_info->mm_height) && |
| - (kInchInMm * mode->width / output_info->mm_width) > |
| + if (!ShouldIgnoreSize(output.width_mm, output.height_mm) && |
| + (kInchInMm * mode_info->width / output.width_mm) > |
| kHighDensityDPIThreshold) { |
| device_scale_factor = 2.0f; |
| } |
| gfx::Rect display_bounds( |
| - crtc_info->x, crtc_info->y, mode->width, mode->height); |
| + output.x, output.y, mode_info->width, mode_info->height); |
| std::vector<Resolution> resolutions; |
| - if (!is_internal) |
| - resolutions = GetResolutionList(screen_resources, output_info); |
| + if (!output.is_internal) |
| + resolutions = GetResolutionList(output); |
| - XRRFreeOutputInfo(output_info); |
| - |
| - std::string name = is_internal ? |
| + std::string name = output.is_internal ? |
| l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : |
| - chromeos::GetDisplayName(output); |
| + chromeos::GetDisplayName(output.output); |
| if (name.empty()) |
| name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| bool has_overscan = false; |
| - chromeos::GetOutputOverscanFlag(output, &has_overscan); |
| - |
| - int64 id = GetDisplayId(output, output_index); |
| + chromeos::GetOutputOverscanFlag(output.output, &has_overscan); |
| - // If ID is invalid or there is an duplicate, just use output index. |
| + int64 id = output.display_id; |
| if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) |
| id = output_index; |
|
oshima
2013/08/16 23:13:05
same here.
|
| ids.insert(id); |
| @@ -181,13 +131,6 @@ void DisplayChangeObserverX11::OnDisplayModeChanged( |
| displays.back().set_resolutions(resolutions); |
| } |
| - // Free all allocated resources. |
| - for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| - iter != crtc_info_map.end(); ++iter) { |
| - XRRFreeCrtcInfo(iter->second); |
| - } |
| - XRRFreeScreenResources(screen_resources); |
| - |
| // DisplayManager can be null during the boot. |
| Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| } |