mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00

git ls-files | grep -e "\(\.h\|\.cc\)$" | grep -e "^modules/" | xargs clang-format -i ; git cl format after landing: add to .git-blame-ignore-revs Bug: webrtc:15082 Change-Id: I2c3cd28740062794f8c10e39d8406aadb9e9a35a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/301620 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Auto-Submit: Jared Siskin <jtsiskin@meta.com> Cr-Commit-Position: refs/heads/main@{#39901}
89 lines
2.9 KiB
C++
89 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/desktop_capture/screen_capturer_helper.h"
|
|
|
|
namespace webrtc {
|
|
|
|
void ScreenCapturerHelper::ClearInvalidRegion() {
|
|
MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
|
|
invalid_region_.Clear();
|
|
}
|
|
|
|
void ScreenCapturerHelper::InvalidateRegion(
|
|
const DesktopRegion& invalid_region) {
|
|
MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
|
|
invalid_region_.AddRegion(invalid_region);
|
|
}
|
|
|
|
void ScreenCapturerHelper::InvalidateScreen(const DesktopSize& size) {
|
|
MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
|
|
invalid_region_.AddRect(DesktopRect::MakeSize(size));
|
|
}
|
|
|
|
void ScreenCapturerHelper::TakeInvalidRegion(DesktopRegion* invalid_region) {
|
|
invalid_region->Clear();
|
|
|
|
{
|
|
MutexLock scoped_invalid_region_lock(&invalid_region_mutex_);
|
|
invalid_region->Swap(&invalid_region_);
|
|
}
|
|
|
|
if (log_grid_size_ > 0) {
|
|
DesktopRegion expanded_region;
|
|
ExpandToGrid(*invalid_region, log_grid_size_, &expanded_region);
|
|
expanded_region.Swap(invalid_region);
|
|
|
|
invalid_region->IntersectWith(DesktopRect::MakeSize(size_most_recent_));
|
|
}
|
|
}
|
|
|
|
void ScreenCapturerHelper::SetLogGridSize(int log_grid_size) {
|
|
log_grid_size_ = log_grid_size;
|
|
}
|
|
|
|
const DesktopSize& ScreenCapturerHelper::size_most_recent() const {
|
|
return size_most_recent_;
|
|
}
|
|
|
|
void ScreenCapturerHelper::set_size_most_recent(const DesktopSize& size) {
|
|
size_most_recent_ = size;
|
|
}
|
|
|
|
// Returns the largest multiple of `n` that is <= `x`.
|
|
// `n` must be a power of 2. `nMask` is ~(`n` - 1).
|
|
static int DownToMultiple(int x, int nMask) {
|
|
return (x & nMask);
|
|
}
|
|
|
|
// Returns the smallest multiple of `n` that is >= `x`.
|
|
// `n` must be a power of 2. `nMask` is ~(`n` - 1).
|
|
static int UpToMultiple(int x, int n, int nMask) {
|
|
return ((x + n - 1) & nMask);
|
|
}
|
|
|
|
void ScreenCapturerHelper::ExpandToGrid(const DesktopRegion& region,
|
|
int log_grid_size,
|
|
DesktopRegion* result) {
|
|
RTC_DCHECK_GE(log_grid_size, 1);
|
|
int grid_size = 1 << log_grid_size;
|
|
int grid_size_mask = ~(grid_size - 1);
|
|
|
|
result->Clear();
|
|
for (DesktopRegion::Iterator it(region); !it.IsAtEnd(); it.Advance()) {
|
|
int left = DownToMultiple(it.rect().left(), grid_size_mask);
|
|
int right = UpToMultiple(it.rect().right(), grid_size, grid_size_mask);
|
|
int top = DownToMultiple(it.rect().top(), grid_size_mask);
|
|
int bottom = UpToMultiple(it.rect().bottom(), grid_size, grid_size_mask);
|
|
result->AddRect(DesktopRect::MakeLTRB(left, top, right, bottom));
|
|
}
|
|
}
|
|
|
|
} // namespace webrtc
|