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_rotator.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 rotated DesktopRect of |rect|. The |size| represents the size of | |
| 24 // the DesktopFrame which |rect| belongs in. | |
| 25 DesktopRect Rotate(DesktopRect rect, DesktopSize size, Rotation rotation) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
Maybe call it RotateRect()?
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 26 switch (rotation) { | |
| 27 case Rotation::CLOCK_WISE_0: | |
| 28 return rect; | |
| 29 case Rotation::CLOCK_WISE_90: | |
| 30 return DesktopRect::MakeLTRB(size.height() - rect.bottom(), rect.left(), | |
| 31 size.height() - rect.top(), rect.right()); | |
| 32 case Rotation::CLOCK_WISE_180: | |
| 33 return DesktopRect::MakeLTRB( | |
|
Sergey Ulanov
2016/11/15 20:50:22
nit: this would be slightly simpler with MakeXYWH(
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 34 size.width() - rect.right(), size.height() - rect.bottom(), | |
| 35 size.width() - rect.left(), size.height() - rect.top()); | |
| 36 case Rotation::CLOCK_WISE_270: | |
| 37 return DesktopRect::MakeLTRB(rect.top(), size.width() - rect.right(), | |
| 38 rect.bottom(), size.width() - rect.left()); | |
| 39 default: | |
|
Sergey Ulanov
2016/11/15 20:50:22
Don't need default case. Maybe add NOTREACHED afte
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 40 RTC_NOTREACHED(); | |
| 41 return DesktopRect(); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 // Returns a reverse-rotated Rotation of |rotation|. | |
| 46 Rotation Reverse(Rotation rotation) { | |
| 47 switch (rotation) { | |
| 48 case Rotation::CLOCK_WISE_0: | |
| 49 return rotation; | |
| 50 case Rotation::CLOCK_WISE_90: | |
| 51 return Rotation::CLOCK_WISE_270; | |
| 52 case Rotation::CLOCK_WISE_180: | |
| 53 return Rotation::CLOCK_WISE_180; | |
| 54 case Rotation::CLOCK_WISE_270: | |
| 55 return Rotation::CLOCK_WISE_90; | |
| 56 default: | |
|
Sergey Ulanov
2016/11/15 20:50:22
don't need default case.
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 57 RTC_NOTREACHED(); | |
| 58 return Rotation::CLOCK_WISE_0; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 // Returns a reverse-rotated DesktopRect of |rect|. The |size| represents the | |
| 63 // size of the DesktopFrame which |rect| belongs in. | |
| 64 DesktopRect Derotate(DesktopRect rect, DesktopSize size, Rotation rotation) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
I don't think you need this function, given that i
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 65 return Rotate(rect, size, Reverse(rotation)); | |
| 66 } | |
| 67 | |
| 68 // Returns a reverse-rotated DesktopSize of |size|. | |
| 69 DesktopSize Derotate(DesktopSize size, Rotation rotation) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
GetRotatedSize()?
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 70 switch (rotation) { | |
| 71 case Rotation::CLOCK_WISE_0: | |
| 72 case Rotation::CLOCK_WISE_180: | |
| 73 return size; | |
| 74 case Rotation::CLOCK_WISE_90: | |
| 75 case Rotation::CLOCK_WISE_270: | |
| 76 return DesktopSize(size.height(), size.width()); | |
| 77 default: | |
| 78 RTC_NOTREACHED(); | |
| 79 return DesktopSize(); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 libyuv::RotationMode ToYuvRotationMode(Rotation rotation) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
ToLibyuvRotationMode
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 84 switch (rotation) { | |
| 85 case Rotation::CLOCK_WISE_0: | |
| 86 return libyuv::kRotate0; | |
| 87 case Rotation::CLOCK_WISE_90: | |
| 88 return libyuv::kRotate90; | |
| 89 case Rotation::CLOCK_WISE_180: | |
| 90 return libyuv::kRotate180; | |
| 91 case Rotation::CLOCK_WISE_270: | |
| 92 return libyuv::kRotate270; | |
| 93 default: | |
| 94 RTC_NOTREACHED(); | |
| 95 return libyuv::kRotate0; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 } // namespace | |
| 100 | |
| 101 bool CopyRotatedRectTo(const DesktopFrame& src, | |
| 102 DesktopRect rect, | |
| 103 Rotation rotation, | |
| 104 DesktopFrame* target) { | |
| 105 if (!target) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
Do you really need this? Maybe replace with a DCHE
Hzj_jie
2016/11/16 01:18:33
Done.
| |
| 106 return false; | |
| 107 } | |
| 108 if (!DesktopRect::MakeSize(target->size()).ContainsRect(rect)) { | |
| 109 return false; | |
| 110 } | |
| 111 if (rect.is_empty()) { | |
|
Sergey Ulanov
2016/11/15 20:50:22
Do we need this special case? I think CopyPixelsFr
Hzj_jie
2016/11/16 01:18:33
When the input rectangle is empty, ARGBRotate will
| |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 target->mutable_updated_region()->AddRect(rect); | |
| 116 if (rotation == Rotation::CLOCK_WISE_0) { | |
| 117 // A shortcut: if |rotation| is 0, this function uses | |
| 118 // DesktopFrame::CopyPixelsFrom() for a better performance. | |
|
Sergey Ulanov
2016/11/15 20:50:22
Does it actually perform better? I would guess lib
Hzj_jie
2016/11/16 01:18:33
Done.
No, it's for old version, and should be remo
| |
| 119 target->CopyPixelsFrom(src, rect.top_left(), rect); | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 // The rectangle in |src|. | |
| 124 const DesktopRect src_rect = | |
| 125 Derotate(rect, Derotate(src.size(), rotation), rotation); | |
| 126 return libyuv::ARGBRotate( | |
| 127 src.GetFrameDataAtPos(src_rect.top_left()), src.stride(), | |
| 128 target->GetFrameDataAtPos(rect.top_left()), target->stride(), | |
| 129 src_rect.width(), src_rect.height(), | |
| 130 ToYuvRotationMode(rotation)) == 0; | |
| 131 } | |
| 132 | |
| 133 bool CopyUnrotatedRectTo(const DesktopFrame& src, | |
| 134 DesktopRect rect, | |
| 135 Rotation rotation, | |
| 136 DesktopFrame* target) { | |
| 137 return CopyRotatedRectTo(src, Rotate(rect, src.size(), rotation), rotation, | |
| 138 target); | |
| 139 } | |
| 140 | |
| 141 } // namespace webrtc | |
| OLD | NEW |