Commit 15547013 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

Fix ASAN bot - linking of remoting

This fixes the following error:

ld.lld: error: duplicate symbol: remoting::DesktopResizer::Create()
>>> defined at desktop_resizer_ozone.cc:53 (../../remoting/host/desktop_resizer_ozone.cc:53)
>>>            common/desktop_resizer_ozone.o:(remoting::DesktopResizer::Create()) in archive obj/remoting/host/libcommon.a
>>> defined at desktop_resizer_x11.cc:362 (../../remoting/host/desktop_resizer_x11.cc:362)
>>>            common/desktop_resizer_x11.o:(.text._ZN8remoting14DesktopResizer6CreateEv+0x0) in archive obj/remoting/host/libcommon.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This patch uses the same approach as in another places. For example,
DesktopScreenLinux.

Bug: 1085700
Change-Id: I0bb0c8e6d62ea66c618422d4af9044c52c57c729
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376854
Commit-Queue: Maksim Sisov (GMT+3) <msisov@igalia.com>
Commit-Queue: Joe Downing <joedow@chromium.org>
Auto-Submit: Maksim Sisov (GMT+3) <msisov@igalia.com>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801862}
parent da75e6c8
......@@ -146,8 +146,10 @@ static_library("common") {
"desktop_resizer.h",
"desktop_resizer_mac.cc",
"desktop_resizer_ozone.cc",
"desktop_resizer_ozone.h",
"desktop_resizer_win.cc",
"desktop_resizer_x11.cc",
"desktop_resizer_x11.h",
"desktop_session.cc",
"desktop_session.h",
"desktop_session_agent.cc",
......@@ -353,6 +355,7 @@ static_library("common") {
}
if (is_linux && !is_chromeos) {
sources += [ "desktop_resizer_linux.cc" ]
public_deps += [ "//remoting/host/linux" ]
libs += [ "pam" ]
}
......@@ -369,12 +372,16 @@ static_library("common") {
sources -= [
"clipboard_x11.cc",
"desktop_resizer_x11.cc",
"desktop_resizer_x11.h",
"input_injector_x11.cc",
]
}
if (!use_ozone) {
sources -= [ "desktop_resizer_ozone.cc" ]
sources -= [
"desktop_resizer_ozone.cc",
"desktop_resizer_ozone.h",
]
}
if (is_chromeos) {
......@@ -399,11 +406,15 @@ static_library("common") {
if (use_ozone) {
deps += [ "//ui/ozone" ]
sources -= [ "desktop_resizer_ozone.cc" ]
sources -= [
"desktop_resizer_ozone.cc",
"desktop_resizer_ozone.h",
]
} else {
sources -= [
"clipboard_x11.cc",
"desktop_resizer_x11.cc",
"desktop_resizer_x11.h",
"input_injector_chromeos.cc",
"input_injector_chromeos.h",
]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/host/desktop_resizer.h"
#include <memory>
#include "base/notreached.h"
#if defined(USE_X11)
#include "remoting/host/desktop_resizer_x11.h"
#endif
#if defined(USE_OZONE)
#include "remoting/host/desktop_resizer_ozone.h"
#include "ui/base/ui_base_features.h"
#endif
namespace remoting {
std::unique_ptr<DesktopResizer> DesktopResizer::Create() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform())
return std::make_unique<DesktopResizerOzone>();
#endif
#if defined(USE_X11)
return std::make_unique<DesktopResizerX11>();
#else
NOTREACHED();
return nullptr;
#endif
}
} // namespace remoting
......@@ -2,35 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/host/desktop_resizer.h"
#include "remoting/host/desktop_resizer_ozone.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "build/build_config.h"
namespace remoting {
class DesktopResizerOzone : public DesktopResizer {
public:
DesktopResizerOzone();
~DesktopResizerOzone() override;
DesktopResizerOzone::DesktopResizerOzone() = default;
// DesktopResizer:
ScreenResolution GetCurrentResolution() override;
std::list<ScreenResolution> GetSupportedResolutions(
const ScreenResolution& preferred) override;
void SetResolution(const ScreenResolution& resolution) override;
void RestoreResolution(const ScreenResolution& original) override;
private:
DISALLOW_COPY_AND_ASSIGN(DesktopResizerOzone);
};
DesktopResizerOzone::DesktopResizerOzone() {
}
DesktopResizerOzone::~DesktopResizerOzone() {
}
DesktopResizerOzone::~DesktopResizerOzone() = default;
ScreenResolution DesktopResizerOzone::GetCurrentResolution() {
NOTIMPLEMENTED();
......@@ -47,11 +27,15 @@ void DesktopResizerOzone::SetResolution(const ScreenResolution& resolution) {
NOTIMPLEMENTED();
}
void DesktopResizerOzone::RestoreResolution(const ScreenResolution& original) {
}
void DesktopResizerOzone::RestoreResolution(const ScreenResolution& original) {}
// To avoid multiple definitions when use_x11 && use_ozone is true, disable this
// factory method for OS_LINUX as Linux has a factory method that decides what
// desktopresizer to use based on IsUsingOzonePlatform feature flag.
#if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
std::unique_ptr<DesktopResizer> DesktopResizer::Create() {
return base::WrapUnique(new DesktopResizerOzone);
}
#endif
} // namespace remoting
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_DESKTOP_RESIZER_OZONE_H_
#define REMOTING_HOST_DESKTOP_RESIZER_OZONE_H_
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "remoting/host/desktop_resizer.h"
namespace remoting {
class DesktopResizerOzone : public DesktopResizer {
public:
DesktopResizerOzone();
DesktopResizerOzone(const DesktopResizerOzone&) = delete;
DesktopResizerOzone& operator=(const DesktopResizerOzone&) = delete;
~DesktopResizerOzone() override;
// DesktopResizer:
ScreenResolution GetCurrentResolution() override;
std::list<ScreenResolution> GetSupportedResolutions(
const ScreenResolution& preferred) override;
void SetResolution(const ScreenResolution& resolution) override;
void RestoreResolution(const ScreenResolution& original) override;
};
} // namespace remoting
#endif // REMOTING_HOST_DESKTOP_RESIZER_OZONE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/host/desktop_resizer.h"
#include "remoting/host/desktop_resizer_x11.h"
#include <string.h>
......@@ -67,98 +67,42 @@ const int kDefaultDPI = 96;
namespace remoting {
// Wrapper class for the XRRScreenResources struct.
class ScreenResources {
public:
ScreenResources() = default;
ScreenResources::ScreenResources() = default;
~ScreenResources() = default;
ScreenResources::~ScreenResources() = default;
bool Refresh(x11::RandR* randr, x11::Window window) {
resources_ = nullptr;
if (auto response = randr->GetScreenResourcesCurrent({window}).Sync())
resources_ = std::move(response.reply);
return resources_ != nullptr;
}
bool ScreenResources::Refresh(x11::RandR* randr, x11::Window window) {
resources_ = nullptr;
if (auto response = randr->GetScreenResourcesCurrent({window}).Sync())
resources_ = std::move(response.reply);
return resources_ != nullptr;
}
x11::RandR::Mode GetIdForMode(const std::string& name) {
CHECK(resources_);
const char* names = reinterpret_cast<const char*>(resources_->names.data());
for (const auto& mode_info : resources_->modes) {
std::string mode_name(names, mode_info.name_len);
names += mode_info.name_len;
if (name == mode_name)
return static_cast<x11::RandR::Mode>(mode_info.id);
}
return kInvalidMode;
x11::RandR::Mode ScreenResources::GetIdForMode(const std::string& name) {
CHECK(resources_);
const char* names = reinterpret_cast<const char*>(resources_->names.data());
for (const auto& mode_info : resources_->modes) {
std::string mode_name(names, mode_info.name_len);
names += mode_info.name_len;
if (name == mode_name)
return static_cast<x11::RandR::Mode>(mode_info.id);
}
return kInvalidMode;
}
// For now, assume we're only ever interested in the first output.
x11::RandR::Output GetOutput() {
CHECK(resources_);
return resources_->outputs[0];
}
x11::RandR::Output ScreenResources::GetOutput() {
CHECK(resources_);
return resources_->outputs[0];
}
// For now, assume we're only ever interested in the first crtc.
x11::RandR::Crtc GetCrtc() {
CHECK(resources_);
return resources_->crtcs[0];
}
x11::RandR::Crtc ScreenResources::GetCrtc() {
CHECK(resources_);
return resources_->crtcs[0];
}
x11::RandR::GetScreenResourcesCurrentReply* get() { return resources_.get(); }
private:
std::unique_ptr<x11::RandR::GetScreenResourcesCurrentReply> resources_;
};
class DesktopResizerX11 : public DesktopResizer,
public x11::Connection::Delegate {
public:
DesktopResizerX11();
~DesktopResizerX11() override;
// DesktopResizer interface
ScreenResolution GetCurrentResolution() override;
std::list<ScreenResolution> GetSupportedResolutions(
const ScreenResolution& preferred) override;
void SetResolution(const ScreenResolution& resolution) override;
void RestoreResolution(const ScreenResolution& original) override;
private:
// x11::Connection::Delegate:
bool ShouldContinueStream() const override;
void DispatchXEvent(x11::Event* event) override;
// Add a mode matching the specified resolution and switch to it.
void SetResolutionNewMode(const ScreenResolution& resolution);
// Attempt to switch to an existing mode matching the specified resolution
// using RandR, if such a resolution exists. Otherwise, do nothing.
void SetResolutionExistingMode(const ScreenResolution& resolution);
// Create a mode, and attach it to the primary output. If the mode already
// exists, it is left unchanged.
void CreateMode(const char* name, int width, int height);
// Remove the specified mode from the primary output, and delete it. If the
// mode is in use, it is not deleted.
void DeleteMode(const char* name);
// Switch the primary output to the specified mode. If name is nullptr, the
// primary output is disabled instead, which is required before changing
// its resolution.
void SwitchToMode(const char* name);
x11::Connection connection_;
x11::RandR* const randr_ = nullptr;
const x11::Screen* const screen_ = nullptr;
x11::Window root_;
ScreenResources resources_;
bool exact_resize_;
bool has_randr_;
DISALLOW_COPY_AND_ASSIGN(DesktopResizerX11);
};
x11::RandR::GetScreenResourcesCurrentReply* ScreenResources::get() {
return resources_.get();
}
DesktopResizerX11::DesktopResizerX11()
: randr_(&connection_.randr()),
......@@ -359,8 +303,4 @@ void DesktopResizerX11::SwitchToMode(const char* name) {
});
}
std::unique_ptr<DesktopResizer> DesktopResizer::Create() {
return base::WrapUnique(new DesktopResizerX11);
}
} // namespace remoting
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_DESKTOP_RESIZER_X11_H_
#define REMOTING_HOST_DESKTOP_RESIZER_X11_H_
#include <string.h>
#include "base/command_line.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "remoting/base/logging.h"
#include "remoting/host/desktop_resizer.h"
#include "remoting/host/linux/x11_util.h"
#include "ui/gfx/x/randr.h"
#include "ui/gfx/x/x11.h"
namespace remoting {
// Wrapper class for the XRRScreenResources struct.
class ScreenResources {
public:
ScreenResources();
~ScreenResources();
bool Refresh(x11::RandR* randr, x11::Window window);
x11::RandR::Mode GetIdForMode(const std::string& name);
// For now, assume we're only ever interested in the first output.
x11::RandR::Output GetOutput();
// For now, assume we're only ever interested in the first crtc.
x11::RandR::Crtc GetCrtc();
x11::RandR::GetScreenResourcesCurrentReply* get();
private:
std::unique_ptr<x11::RandR::GetScreenResourcesCurrentReply> resources_;
};
class DesktopResizerX11 : public DesktopResizer,
public x11::Connection::Delegate {
public:
DesktopResizerX11();
DesktopResizerX11(const DesktopResizerX11&) = delete;
DesktopResizerX11& operator=(const DesktopResizerX11&) = delete;
~DesktopResizerX11() override;
// DesktopResizer interface
ScreenResolution GetCurrentResolution() override;
std::list<ScreenResolution> GetSupportedResolutions(
const ScreenResolution& preferred) override;
void SetResolution(const ScreenResolution& resolution) override;
void RestoreResolution(const ScreenResolution& original) override;
private:
// x11::Connection::Delegate:
bool ShouldContinueStream() const override;
void DispatchXEvent(x11::Event* event) override;
// Add a mode matching the specified resolution and switch to it.
void SetResolutionNewMode(const ScreenResolution& resolution);
// Attempt to switch to an existing mode matching the specified resolution
// using RandR, if such a resolution exists. Otherwise, do nothing.
void SetResolutionExistingMode(const ScreenResolution& resolution);
// Create a mode, and attach it to the primary output. If the mode already
// exists, it is left unchanged.
void CreateMode(const char* name, int width, int height);
// Remove the specified mode from the primary output, and delete it. If the
// mode is in use, it is not deleted.
void DeleteMode(const char* name);
// Switch the primary output to the specified mode. If name is nullptr, the
// primary output is disabled instead, which is required before changing
// its resolution.
void SwitchToMode(const char* name);
x11::Connection connection_;
x11::RandR* const randr_ = nullptr;
const x11::Screen* const screen_ = nullptr;
x11::Window root_;
ScreenResources resources_;
bool exact_resize_;
bool has_randr_;
};
} // namespace remoting
#endif // REMOTING_HOST_DESKTOP_RESIZER_X11_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment