Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/desktop_capture/desktop_frame_rotation.h" | |
| 12 | |
| 13 #include <string.h> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 | |
| 17 #include "third_party/libyuv/include/libyuv/rotate_argb.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // Returns a reverse-rotated Rotation of |rotation|. | |
| 24 Rotation Reverse(Rotation rotation) { | |
| 25 switch (rotation) { | |
| 26 case Rotation::CLOCK_WISE_0: | |
| 27 return rotation; | |
| 28 case Rotation::CLOCK_WISE_90: | |
| 29 return Rotation::CLOCK_WISE_270; | |
| 30 case Rotation::CLOCK_WISE_180: | |
| 31 return Rotation::CLOCK_WISE_180; | |
| 32 case Rotation::CLOCK_WISE_270: | |
| 33 return Rotation::CLOCK_WISE_90; | |
| 34 } | |
| 35 RTC_NOTREACHED(); | |
| 36 return Rotation::CLOCK_WISE_0; | |
| 37 } | |
| 38 | |
| 39 // Returns a rotated DesktopSize of |size|. | |
| 40 DesktopSize GetRotatedSize(DesktopSize size, Rotation rotation) { | |
| 41 switch (rotation) { | |
| 42 case Rotation::CLOCK_WISE_0: | |
| 43 case Rotation::CLOCK_WISE_180: | |
| 44 return size; | |
| 45 case Rotation::CLOCK_WISE_90: | |
| 46 case Rotation::CLOCK_WISE_270: | |
| 47 return DesktopSize(size.height(), size.width()); | |
| 48 } | |
| 49 RTC_NOTREACHED(); | |
| 50 return DesktopSize(); | |
| 51 } | |
| 52 | |
| 53 libyuv::RotationMode ToLibyuvRotationMode(Rotation rotation) { | |
| 54 switch (rotation) { | |
| 55 case Rotation::CLOCK_WISE_0: | |
| 56 return libyuv::kRotate0; | |
| 57 case Rotation::CLOCK_WISE_90: | |
| 58 return libyuv::kRotate90; | |
| 59 case Rotation::CLOCK_WISE_180: | |
| 60 return libyuv::kRotate180; | |
| 61 case Rotation::CLOCK_WISE_270: | |
| 62 return libyuv::kRotate270; | |
| 63 } | |
| 64 RTC_NOTREACHED(); | |
| 65 return libyuv::kRotate0; | |
| 66 } | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 DesktopRect RotateRect(DesktopRect rect, DesktopSize size, Rotation rotation) { | |
| 71 switch (rotation) { | |
| 72 case Rotation::CLOCK_WISE_0: | |
| 73 return rect; | |
| 74 case Rotation::CLOCK_WISE_90: | |
| 75 return DesktopRect::MakeXYWH(size.height() - rect.bottom(), rect.left(), | |
| 76 rect.height(), rect.width()); | |
| 77 case Rotation::CLOCK_WISE_180: | |
| 78 return DesktopRect::MakeXYWH(size.width() - rect.right(), | |
| 79 size.height() - rect.bottom(), rect.width(), | |
| 80 rect.height()); | |
| 81 case Rotation::CLOCK_WISE_270: | |
| 82 return DesktopRect::MakeXYWH(rect.top(), size.width() - rect.right(), | |
| 83 rect.height(), rect.width()); | |
| 84 } | |
| 85 RTC_NOTREACHED(); | |
| 86 return DesktopRect(); | |
| 87 } | |
| 88 | |
| 89 | |
| 90 void RotateDesktopFrame(const DesktopFrame& source, | |
| 91 const Rotation& rotation, | |
| 92 const DesktopRect& rect, | |
|
Sergey Ulanov
2016/11/19 02:11:40
I think it's more intuitive if |rect| was specifie
Hzj_jie
2016/11/19 05:10:59
Done.
| |
| 93 DesktopFrame* target) { | |
| 94 RTC_DCHECK(target); | |
| 95 RTC_DCHECK(DesktopRect::MakeSize(target->size()).ContainsRect(rect)); | |
|
Sergey Ulanov
2016/11/19 02:11:40
Also need to DCHECK that source and target are the
Hzj_jie
2016/11/19 05:10:59
In a typical multi-monitor scenario of DirectX cap
Sergey Ulanov
2016/11/21 21:01:12
I see. But in this case shouldn't we also shift th
Hzj_jie
2016/11/21 23:33:30
Yes, I missed this point. But I do not think a Des
| |
| 96 | |
| 97 if (rect.is_empty()) { | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 target->mutable_updated_region()->AddRect(rect); | |
| 102 const Rotation reverse_rotation = Reverse(rotation); | |
| 103 // The rectangle in |source|. | |
| 104 const DesktopRect source_rect = RotateRect( | |
| 105 rect, GetRotatedSize(source.size(), reverse_rotation), reverse_rotation); | |
| 106 int result = libyuv::ARGBRotate( | |
| 107 source.GetFrameDataAtPos(source_rect.top_left()), source.stride(), | |
| 108 target->GetFrameDataAtPos(rect.top_left()), target->stride(), | |
| 109 source_rect.width(), source_rect.height(), | |
| 110 ToLibyuvRotationMode(rotation)); | |
| 111 RTC_DCHECK_EQ(result, 0); | |
| 112 } | |
| 113 | |
| 114 } // namespace webrtc | |
| OLD | NEW |