mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Adds SetFrameDataToBlack() and FrameDataIsBlack() to DesktopFrame
Bug: None Change-Id: I558b2398de409b0b44f331520e3d4692e45b9315 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/296884 Reviewed-by: Alexander Cooper <alcooper@chromium.org> Commit-Queue: Henrik Andreassson <henrika@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39537}
This commit is contained in:
parent
86eb6ba207
commit
bedb69f26d
3 changed files with 41 additions and 0 deletions
|
@ -144,6 +144,23 @@ void DesktopFrame::MoveFrameInfoFrom(DesktopFrame* other) {
|
|||
set_icc_profile(other->icc_profile());
|
||||
}
|
||||
|
||||
bool DesktopFrame::FrameDataIsBlack() const {
|
||||
if (size().is_empty())
|
||||
return false;
|
||||
|
||||
uint32_t* pixel = reinterpret_cast<uint32_t*>(data());
|
||||
for (int i = 0; i < size().width() * size().height(); ++i) {
|
||||
if (*pixel++)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DesktopFrame::SetFrameDataToBlack() {
|
||||
const uint8_t kBlackPixelValue = 0x00;
|
||||
memset(data(), kBlackPixelValue, stride() * size().height());
|
||||
}
|
||||
|
||||
BasicDesktopFrame::BasicDesktopFrame(DesktopSize size)
|
||||
: DesktopFrame(size,
|
||||
kBytesPerPixel * size.width(),
|
||||
|
|
|
@ -142,6 +142,13 @@ class RTC_EXPORT DesktopFrame {
|
|||
icc_profile_ = icc_profile;
|
||||
}
|
||||
|
||||
// Sets all pixel values in the data buffer to zero.
|
||||
void SetFrameDataToBlack();
|
||||
|
||||
// Returns true if all pixel values in the data buffer are zero or false
|
||||
// otherwise. Also returns false if the frame is empty.
|
||||
bool FrameDataIsBlack() const;
|
||||
|
||||
protected:
|
||||
DesktopFrame(DesktopSize size,
|
||||
int stride,
|
||||
|
|
|
@ -87,6 +87,23 @@ void RunTests(const TestData* tests, int num_tests) {
|
|||
|
||||
} // namespace
|
||||
|
||||
TEST(DesktopFrameTest, NewFrameIsBlack) {
|
||||
auto frame = std::make_unique<BasicDesktopFrame>(DesktopSize(10, 10));
|
||||
EXPECT_TRUE(frame->FrameDataIsBlack());
|
||||
}
|
||||
|
||||
TEST(DesktopFrameTest, EmptyFrameIsNotBlack) {
|
||||
auto frame = std::make_unique<BasicDesktopFrame>(DesktopSize());
|
||||
EXPECT_FALSE(frame->FrameDataIsBlack());
|
||||
}
|
||||
|
||||
TEST(DesktopFrameTest, FrameDataSwitchesBetweenNonBlackAndBlack) {
|
||||
auto frame = CreateTestFrame(DesktopRect::MakeXYWH(0, 0, 10, 10), 0xff);
|
||||
EXPECT_FALSE(frame->FrameDataIsBlack());
|
||||
frame->SetFrameDataToBlack();
|
||||
EXPECT_TRUE(frame->FrameDataIsBlack());
|
||||
}
|
||||
|
||||
TEST(DesktopFrameTest, CopyIntersectingPixelsMatchingRects) {
|
||||
const TestData tests[] = {
|
||||
{"0 origin",
|
||||
|
|
Loading…
Reference in a new issue