| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" | 11 #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" |
| 12 | 12 |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 #include "webrtc/base/random.h" | 18 #include "webrtc/base/random.h" |
| 19 #include "webrtc/base/timeutils.h" | 19 #include "webrtc/base/timeutils.h" |
| 20 #include "webrtc/modules/desktop_capture/rgba_color.h" |
| 20 | 21 |
| 21 namespace webrtc { | 22 namespace webrtc { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Sets |updated_region| to |frame|. If |enlarge_updated_region| is | 26 // Sets |updated_region| to |frame|. If |enlarge_updated_region| is |
| 26 // true, this function will randomly enlarge each DesktopRect in | 27 // true, this function will randomly enlarge each DesktopRect in |
| 27 // |updated_region|. But the enlarged DesktopRegion won't excceed the | 28 // |updated_region|. But the enlarged DesktopRegion won't excceed the |
| 28 // frame->size(). If |add_random_updated_region| is true, several random | 29 // frame->size(). If |add_random_updated_region| is true, several random |
| 29 // rectangles will also be included in |frame|. | 30 // rectangles will also be included in |frame|. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 const int top = random.Rand(0, frame->size().height() - 2); | 54 const int top = random.Rand(0, frame->size().height() - 2); |
| 54 const int right = random.Rand(left + 1, frame->size().width()); | 55 const int right = random.Rand(left + 1, frame->size().width()); |
| 55 const int bottom = random.Rand(top + 1, frame->size().height()); | 56 const int bottom = random.Rand(top + 1, frame->size().height()); |
| 56 frame->mutable_updated_region()->AddRect( | 57 frame->mutable_updated_region()->AddRect( |
| 57 DesktopRect::MakeLTRB(left, top, right, bottom)); | 58 DesktopRect::MakeLTRB(left, top, right, bottom)); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Paints pixels in |rect| of |frame| to |color|. | 63 // Paints pixels in |rect| of |frame| to |color|. |
| 63 void PaintRect(DesktopFrame* frame, DesktopRect rect, uint32_t color) { | 64 void PaintRect(DesktopFrame* frame, DesktopRect rect, RgbaColor rgba_color) { |
| 64 static_assert(DesktopFrame::kBytesPerPixel == sizeof(uint32_t), | 65 static_assert(DesktopFrame::kBytesPerPixel == sizeof(uint32_t), |
| 65 "kBytesPerPixel should be 4."); | 66 "kBytesPerPixel should be 4."); |
| 66 RTC_DCHECK(frame->size().width() >= rect.right() && | 67 RTC_DCHECK(frame->size().width() >= rect.right() && |
| 67 frame->size().height() >= rect.bottom()); | 68 frame->size().height() >= rect.bottom()); |
| 69 uint32_t color = rgba_color.ToUInt32(); |
| 68 uint8_t* row = frame->GetFrameDataAtPos(rect.top_left()); | 70 uint8_t* row = frame->GetFrameDataAtPos(rect.top_left()); |
| 69 for (int i = 0; i < rect.height(); i++) { | 71 for (int i = 0; i < rect.height(); i++) { |
| 70 uint32_t* column = reinterpret_cast<uint32_t*>(row); | 72 uint32_t* column = reinterpret_cast<uint32_t*>(row); |
| 71 for (int j = 0; j < rect.width(); j++) { | 73 for (int j = 0; j < rect.width(); j++) { |
| 72 column[j] = color; | 74 column[j] = color; |
| 73 } | 75 } |
| 74 row += frame->stride(); | 76 row += frame->stride(); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 // Paints pixels in |region| of |frame| to |color|. | 80 // Paints pixels in |region| of |frame| to |color|. |
| 79 void PaintRegion(DesktopFrame* frame, DesktopRegion* region, uint32_t color) { | 81 void PaintRegion(DesktopFrame* frame, |
| 82 DesktopRegion* region, |
| 83 RgbaColor rgba_color) { |
| 80 region->IntersectWith(DesktopRect::MakeSize(frame->size())); | 84 region->IntersectWith(DesktopRect::MakeSize(frame->size())); |
| 81 for (DesktopRegion::Iterator it(*region); !it.IsAtEnd(); it.Advance()) { | 85 for (DesktopRegion::Iterator it(*region); !it.IsAtEnd(); it.Advance()) { |
| 82 PaintRect(frame, it.rect(), color); | 86 PaintRect(frame, it.rect(), rgba_color); |
| 83 } | 87 } |
| 84 } | 88 } |
| 85 | 89 |
| 86 } // namespace | 90 } // namespace |
| 87 | 91 |
| 88 DesktopFrameGenerator::DesktopFrameGenerator() {} | 92 DesktopFrameGenerator::DesktopFrameGenerator() {} |
| 89 DesktopFrameGenerator::~DesktopFrameGenerator() {} | 93 DesktopFrameGenerator::~DesktopFrameGenerator() {} |
| 90 | 94 |
| 91 DesktopFramePainter::DesktopFramePainter() {} | 95 DesktopFramePainter::DesktopFramePainter() {} |
| 92 DesktopFramePainter::~DesktopFramePainter() {} | 96 DesktopFramePainter::~DesktopFramePainter() {} |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 BlackWhiteDesktopFramePainter::~BlackWhiteDesktopFramePainter() {} | 168 BlackWhiteDesktopFramePainter::~BlackWhiteDesktopFramePainter() {} |
| 165 | 169 |
| 166 DesktopRegion* BlackWhiteDesktopFramePainter::updated_region() { | 170 DesktopRegion* BlackWhiteDesktopFramePainter::updated_region() { |
| 167 return &updated_region_; | 171 return &updated_region_; |
| 168 } | 172 } |
| 169 | 173 |
| 170 bool BlackWhiteDesktopFramePainter::Paint(DesktopFrame* frame, | 174 bool BlackWhiteDesktopFramePainter::Paint(DesktopFrame* frame, |
| 171 DesktopRegion* updated_region) { | 175 DesktopRegion* updated_region) { |
| 172 RTC_DCHECK(updated_region->is_empty()); | 176 RTC_DCHECK(updated_region->is_empty()); |
| 173 memset(frame->data(), 0, frame->stride() * frame->size().height()); | 177 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
| 174 PaintRegion(frame, &updated_region_, UINT32_MAX); | 178 PaintRegion(frame, &updated_region_, RgbaColor(0xFFFFFFFF)); |
| 175 updated_region_.Swap(updated_region); | 179 updated_region_.Swap(updated_region); |
| 176 return true; | 180 return true; |
| 177 } | 181 } |
| 178 | 182 |
| 179 } // namespace webrtc | 183 } // namespace webrtc |
| OLD | NEW |