chromium/remoting/host/x11_desktop_resizer.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "remoting/host/x11_desktop_resizer.h"

#include <gio/gio.h>

#include <algorithm>
#include <iterator>
#include <memory>
#include <ranges>
#include <string>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/system/sys_info.h"
#include "base/types/cxx23_to_underlying.h"
#include "remoting/base/logging.h"
#include "remoting/host/desktop_geometry.h"
#include "remoting/host/linux/x11_util.h"
#include "remoting/host/x11_crtc_resizer.h"
#include "remoting/host/x11_display_util.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/x/future.h"
#include "ui/gfx/x/randr.h"

// On Linux, we use the xrandr extension to change the desktop resolution.
//
// Xrandr has a number of restrictions that make exact resize more complex:
//
//   1. It's not possible to change the resolution of an existing mode. Instead,
//      the mode must be deleted and recreated.
//   2. It's not possible to delete a mode that's in use.
//   3. Errors are communicated via Xlib's spectacularly unhelpful mechanism
//      of terminating the process unless you install an error handler.
//   4. The root window size must always enclose any enabled Outputs (that is,
//      any output which is attached to a CRTC).
//   5. An Output cannot be given properties (xy-offsets, mode) which would
//      extend its rectangle beyond the root window size.
//
// Since we want the current mode name to be consistent (for each Output), the
// approach is as follows:
//
//   1. Fetch information about all the active (enabled) CRTCs.
//   2. Disable the RANDR Output being resized.
//   3. Delete the CRD mode, if it exists.
//   4. Create the CRD mode at the new resolution, and add it to the Output's
//      list of modes.
//   5. Adjust the properties (in memory) of any CRTCs to be modified:
//      * Width/height (mode) of the CRTC being resized.
//      * xy-offsets to avoid overlapping CRTCs.
//   6. Disable any CRTCs that might prevent changing the root window size.
//   7. Compute the bounding rectangle of all CRTCs (after adjustment), and set
//      it as the new root window size.
//   8. Apply all adjusted CRTC properties to the CRTCs. This will set the
//      Output being resized to the new CRD mode (which re-enables it), and it
//      will re-enable any other CRTCs that were disabled.

namespace {

constexpr auto kInvalidMode =;
constexpr auto kDisabledCrtc =;
constexpr base::TimeDelta kGnomeWaitTime =;

int PixelsToMillimeters(int pixels, int dpi) {}

// Returns a physical size in mm that will work well with GNOME's
// automatic scale-selection algorithm.
gfx::Size CalculateSizeInMmForGnome(
    const remoting::DesktopResolution& resolution) {}

// TODO(jamiewalch): Use the correct DPI for the mode: http://crbug.com/172405.
const int kDefaultDPI =;

x11::RandR::Output GetOutputFromContext(void* context) {}

std::string GetModeNameForOutput(x11::RandR::Output output) {}

uint32_t GetDotClockForModeInfo() {}

// Gets current layout with context information from a list of monitors.
std::vector<remoting::DesktopLayoutWithContext> GetLayoutWithContext(
    std::vector<x11::RandR::MonitorInfo>& monitors) {}

}  // namespace

namespace remoting {

ScreenResources::ScreenResources() = default;

ScreenResources::~ScreenResources() = default;

bool ScreenResources::Refresh(x11::RandR* randr, x11::Window window) {}

x11::RandR::Mode ScreenResources::GetIdForMode(const std::string& name) {}

x11::RandR::GetScreenResourcesCurrentReply* ScreenResources::get() {}

X11DesktopResizer::X11DesktopResizer()
    :{}

X11DesktopResizer::~X11DesktopResizer() = default;

DesktopResolution X11DesktopResizer::GetCurrentResolution(
    DesktopScreenId screen_id) {}

std::list<DesktopResolution> X11DesktopResizer::GetSupportedResolutions(
    const DesktopResolution& preferred,
    DesktopScreenId screen_id) {}

void X11DesktopResizer::SetResolution(const DesktopResolution& resolution,
                                      DesktopScreenId screen_id) {}

void X11DesktopResizer::RestoreResolution(const DesktopResolution& original,
                                          DesktopScreenId screen_id) {}

bool X11DesktopResizer::TryGetCurrentMonitors(
    std::vector<x11::RandR::MonitorInfo>& list) {}

DesktopLayoutSet X11DesktopResizer::GetLayout() {}

void X11DesktopResizer::SetVideoLayout(const DesktopLayoutSet& layout) {}

void X11DesktopResizer::SetResolutionForOutput(
    x11::RandR::Output output,
    const DesktopResolution& resolution) {}

x11::RandR::Mode X11DesktopResizer::UpdateMode(x11::RandR::Output output,
                                               int width,
                                               int height) {}

void X11DesktopResizer::DeleteMode(x11::RandR::Output output,
                                   const std::string& name) {}

void X11DesktopResizer::UpdateRootWindow(X11CrtcResizer& resizer) {}

X11DesktopResizer::OutputInfoList X11DesktopResizer::GetDisabledOutputs() {}

void X11DesktopResizer::RequestGnomeDisplayConfig() {}

void X11DesktopResizer::OnGnomeDisplayConfigReceived(
    GnomeDisplayConfig config) {}

}  // namespace remoting