Expose device_scale_factor as a float rather than an int32_t

Since the device_scale_factor is usually exposed as a float in chromium,
we want to keep it same here for consistency.

Bug: chromium:383946052
Change-Id: I8d055ca0fcac623f59dcf96eb3cee15efc23b2ba
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376700
Commit-Queue: Palak Agarwal <agpalak@google.com>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43869}
This commit is contained in:
Palak Agarwal 2025-02-10 10:54:58 +00:00 committed by WebRTC LUCI CQ
parent e53cd509f2
commit 5ebaa2f7bd
12 changed files with 32 additions and 29 deletions

View File

@ -75,10 +75,10 @@ class RTC_EXPORT DesktopFrame {
const DesktopVector& dpi() const { return dpi_; }
void set_dpi(const DesktopVector& dpi) { dpi_ = dpi; }
std::optional<int32_t> device_scale_factor() const {
std::optional<float> device_scale_factor() const {
return device_scale_factor_;
}
void set_device_scale_factor(std::optional<int32_t> device_scale_factor) {
void set_device_scale_factor(std::optional<float> device_scale_factor) {
device_scale_factor_ = device_scale_factor;
}
// Indicates if this frame may have the mouse cursor in it. Capturers that
@ -181,8 +181,8 @@ class RTC_EXPORT DesktopFrame {
std::vector<uint8_t> icc_profile_;
// Currently only used on Windows. It stores the device scale factor of the
// captured surface and has distinct values possible in the range of
// [100,500].
std::optional<int32_t> device_scale_factor_;
// [1,5].
std::optional<float> device_scale_factor_;
};
// A DesktopFrame that stores data in the heap.

View File

@ -105,8 +105,9 @@ TEST(DesktopFrameTest, FrameHasDefaultDeviceScaleFactor) {
TEST(DesktopFrameTest, FrameSetsDeviceScaleFactorCorrectly) {
auto frame = std::make_unique<BasicDesktopFrame>(DesktopSize());
EXPECT_EQ(frame->device_scale_factor(), std::nullopt);
frame->set_device_scale_factor(/*device_scale_factor=*/150);
EXPECT_EQ(frame->device_scale_factor(), 150);
float device_scale_factor = 1.5f;
frame->set_device_scale_factor(device_scale_factor);
EXPECT_EQ(frame->device_scale_factor(), device_scale_factor);
}
TEST(DesktopFrameTest, FrameDataSwitchesBetweenNonBlackAndBlack) {

View File

@ -148,7 +148,7 @@ bool DxgiAdapterDuplicator::DuplicateMonitor(Context* context,
DesktopVector(), target);
}
std::optional<int32_t> DxgiAdapterDuplicator::GetDeviceScaleFactor(
std::optional<float> DxgiAdapterDuplicator::GetDeviceScaleFactor(
int screen_id) const {
if (screen_id < 0 || static_cast<size_t>(screen_id) >= duplicators_.size()) {
return std::nullopt;

View File

@ -58,7 +58,7 @@ class DxgiAdapterDuplicator {
// Returns the device scale factor of screen identified by `screen_id`, which
// is owned by this DxgiAdapterDuplicator. `screen_id` should be between [0,
// screen_count()).
std::optional<int32_t> GetDeviceScaleFactor(int screen_id) const;
std::optional<float> GetDeviceScaleFactor(int screen_id) const;
// Returns the size of one screen owned by this DxgiAdapterDuplicator. `id`
// should be between [0, screen_count()).

View File

@ -404,7 +404,7 @@ DesktopSize DxgiDuplicatorController::desktop_size() const {
return desktop_rect_.size();
}
std::optional<int32_t> DxgiDuplicatorController::GetDeviceScaleFactor(
std::optional<float> DxgiDuplicatorController::GetDeviceScaleFactor(
int monitor_id) const {
if (monitor_id < 0) {
return std::nullopt;

View File

@ -210,7 +210,7 @@ class RTC_EXPORT DxgiDuplicatorController {
// If system does not support DXGI based capturer, or `monitor_id` is greater
// than the total screen count of all the Duplicators, this function returns
// std::nullopt.
std::optional<int32_t> GetDeviceScaleFactor(int monitor_id) const
std::optional<float> GetDeviceScaleFactor(int monitor_id) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns the size of one screen. `id` should be >= 0. If system does not

View File

@ -27,7 +27,7 @@ DxgiFrame::~DxgiFrame() = default;
bool DxgiFrame::Prepare(DesktopSize size,
DesktopCapturer::SourceId source_id,
std::optional<int32_t> device_scale_factor) {
std::optional<float> device_scale_factor) {
if (source_id != source_id_) {
// Once the source has been changed, the entire source should be copied.
source_id_ = source_id;

View File

@ -49,7 +49,7 @@ class DxgiFrame final {
// factor.
bool Prepare(DesktopSize size,
DesktopCapturer::SourceId source_id,
std::optional<int32_t> device_scale_factor);
std::optional<float> device_scale_factor);
// Should not be called if Prepare() is not executed or returns false.
Context* context();

View File

@ -73,9 +73,13 @@ DxgiOutputDuplicator::DxgiOutputDuplicator(const D3dDevice& device,
RTC_DCHECK(!desktop_rect_.is_empty());
RTC_DCHECK_GT(desktop_rect_.width(), 0);
RTC_DCHECK_GT(desktop_rect_.height(), 0);
HRESULT hr = GetScaleFactorForMonitor(desc.Monitor, &device_scale_factor_);
DEVICE_SCALE_FACTOR device_scale_factor = DEVICE_SCALE_FACTOR_INVALID;
HRESULT hr = GetScaleFactorForMonitor(desc.Monitor, &device_scale_factor);
RTC_LOG_IF(LS_ERROR, FAILED(hr))
<< "Failed to get scale factor for monitor: " << hr;
if (device_scale_factor != DEVICE_SCALE_FACTOR_INVALID) {
device_scale_factor_ = static_cast<float>(device_scale_factor) / 100.0f;
}
}
DxgiOutputDuplicator::DxgiOutputDuplicator(DxgiOutputDuplicator&& other) =
@ -421,13 +425,6 @@ int64_t DxgiOutputDuplicator::num_frames_captured() const {
return num_frames_captured_;
}
std::optional<DEVICE_SCALE_FACTOR> DxgiOutputDuplicator::device_scale_factor()
const {
return (device_scale_factor_ != DEVICE_SCALE_FACTOR_INVALID
? std::make_optional(device_scale_factor_)
: std::nullopt);
}
void DxgiOutputDuplicator::TranslateRect(const DesktopVector& position) {
desktop_rect_.Translate(position);
RTC_DCHECK_GE(desktop_rect_.left(), 0);

View File

@ -86,7 +86,9 @@ class DxgiOutputDuplicator {
// Device scale factor of the monitor associated with this
// DxigOutputDuplicator.
std::optional<DEVICE_SCALE_FACTOR> device_scale_factor() const;
std::optional<float> device_scale_factor() const {
return device_scale_factor_;
}
// Moves `desktop_rect_`. See DxgiDuplicatorController::TranslateRect().
void TranslateRect(const DesktopVector& position);
@ -138,7 +140,7 @@ class DxgiOutputDuplicator {
std::unique_ptr<DxgiTexture> texture_;
Rotation rotation_;
DesktopSize unrotated_size_;
DEVICE_SCALE_FACTOR device_scale_factor_ = DEVICE_SCALE_FACTOR_INVALID;
std::optional<float> device_scale_factor_;
// After each AcquireNextFrame() function call, updated_region_(s) of all
// active Context(s) need to be updated. Since they have missed the

View File

@ -113,9 +113,14 @@ WgcCaptureSession::WgcCaptureSession(intptr_t source_id,
monitor = MonitorFromWindow(reinterpret_cast<HWND>(source_id),
/*dwFlags=*/MONITOR_DEFAULTTONEAREST);
}
HRESULT hr = GetScaleFactorForMonitor(monitor, &device_scale_factor_);
DEVICE_SCALE_FACTOR device_scale_factor = DEVICE_SCALE_FACTOR_INVALID;
HRESULT hr = GetScaleFactorForMonitor(monitor, &device_scale_factor);
RTC_LOG_IF(LS_ERROR, FAILED(hr))
<< "Failed to get scale factor for monitor: " << hr;
if (device_scale_factor != DEVICE_SCALE_FACTOR_INVALID) {
device_scale_factor_ = static_cast<float>(device_scale_factor) / 100.0f;
}
}
WgcCaptureSession::~WgcCaptureSession() {
@ -468,9 +473,7 @@ HRESULT WgcCaptureSession::ProcessFrame() {
}
DesktopFrame* current_frame = queue_.current_frame();
if (device_scale_factor_ != DEVICE_SCALE_FACTOR_INVALID) {
current_frame->set_device_scale_factor(device_scale_factor_);
}
DesktopFrame* previous_frame = queue_.previous_frame();
// Will be set to true while copying the frame data to the `current_frame` if

View File

@ -151,9 +151,9 @@ class WgcCaptureSession final {
// Captures the device scale factor of the monitor where the frame is captured
// from. This value is the same as the scale from windows settings. Valid
// values are some distinct numbers in the range of [100,500], for example,
// 100, 150, 250, etc.
DEVICE_SCALE_FACTOR device_scale_factor_ = DEVICE_SCALE_FACTOR_INVALID;
// values are some distinct numbers in the range of [1,5], for example,
// 1, 1.5, 2.5, etc.
std::optional<float> device_scale_factor_;
SequenceChecker sequence_checker_;
};