In https://webrtc-review.googlesource.com/c/src/+/1560 we moved WebRTC from src/webrtc to src/ (in order to preserve an healthy git history). This CL takes care of fixing header guards, #include paths, etc... NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iea91618212bee0af16aa3f05071eab8f93706578 Reviewed-on: https://webrtc-review.googlesource.com/1561 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19846}
103 lines
3.2 KiB
C++
103 lines
3.2 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"
|
|
|
|
#include <assert.h>
|
|
#include <algorithm>
|
|
|
|
namespace webrtc {
|
|
|
|
ScreenCapturerHelper::ScreenCapturerHelper()
|
|
: invalid_region_lock_(RWLockWrapper::CreateRWLock()),
|
|
log_grid_size_(0) {
|
|
}
|
|
|
|
ScreenCapturerHelper::~ScreenCapturerHelper() {
|
|
}
|
|
|
|
void ScreenCapturerHelper::ClearInvalidRegion() {
|
|
WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
|
|
invalid_region_.Clear();
|
|
}
|
|
|
|
void ScreenCapturerHelper::InvalidateRegion(
|
|
const DesktopRegion& invalid_region) {
|
|
WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
|
|
invalid_region_.AddRegion(invalid_region);
|
|
}
|
|
|
|
void ScreenCapturerHelper::InvalidateScreen(const DesktopSize& size) {
|
|
WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
|
|
invalid_region_.AddRect(DesktopRect::MakeSize(size));
|
|
}
|
|
|
|
void ScreenCapturerHelper::TakeInvalidRegion(
|
|
DesktopRegion* invalid_region) {
|
|
invalid_region->Clear();
|
|
|
|
{
|
|
WriteLockScoped scoped_invalid_region_lock(*invalid_region_lock_);
|
|
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) {
|
|
assert(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
|