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 #include "third_party/libyuv/include/libyuv/rotate_argb.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 libyuv::RotationMode ToLibyuvRotationMode(Rotation rotation) { | |
| 23 switch (rotation) { | |
| 24 case Rotation::CLOCK_WISE_0: | |
| 25 return libyuv::kRotate0; | |
| 26 case Rotation::CLOCK_WISE_90: | |
| 27 return libyuv::kRotate90; | |
| 28 case Rotation::CLOCK_WISE_180: | |
| 29 return libyuv::kRotate180; | |
| 30 case Rotation::CLOCK_WISE_270: | |
| 31 return libyuv::kRotate270; | |
| 32 } | |
| 33 RTC_NOTREACHED(); | |
| 34 return libyuv::kRotate0; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 Rotation ReverseRotation(Rotation rotation) { | |
| 40 switch (rotation) { | |
| 41 case Rotation::CLOCK_WISE_0: | |
| 42 return rotation; | |
| 43 case Rotation::CLOCK_WISE_90: | |
| 44 return Rotation::CLOCK_WISE_270; | |
| 45 case Rotation::CLOCK_WISE_180: | |
| 46 return Rotation::CLOCK_WISE_180; | |
| 47 case Rotation::CLOCK_WISE_270: | |
| 48 return Rotation::CLOCK_WISE_90; | |
| 49 } | |
| 50 RTC_NOTREACHED(); | |
| 51 return Rotation::CLOCK_WISE_0; | |
| 52 } | |
| 53 | |
| 54 DesktopSize RotateSize(DesktopSize size, Rotation rotation) { | |
| 55 switch (rotation) { | |
| 56 case Rotation::CLOCK_WISE_0: | |
| 57 case Rotation::CLOCK_WISE_180: | |
| 58 return size; | |
| 59 case Rotation::CLOCK_WISE_90: | |
| 60 case Rotation::CLOCK_WISE_270: | |
| 61 return DesktopSize(size.height(), size.width()); | |
| 62 } | |
| 63 RTC_NOTREACHED(); | |
| 64 return DesktopSize(); | |
| 65 } | |
| 66 | |
| 67 DesktopRect RotateRect(DesktopRect rect, DesktopSize size, Rotation rotation) { | |
| 68 switch (rotation) { | |
| 69 case Rotation::CLOCK_WISE_0: | |
| 70 return rect; | |
| 71 case Rotation::CLOCK_WISE_90: | |
| 72 return DesktopRect::MakeXYWH(size.height() - rect.bottom(), rect.left(), | |
| 73 rect.height(), rect.width()); | |
| 74 case Rotation::CLOCK_WISE_180: | |
| 75 return DesktopRect::MakeXYWH(size.width() - rect.right(), | |
| 76 size.height() - rect.bottom(), rect.width(), | |
| 77 rect.height()); | |
| 78 case Rotation::CLOCK_WISE_270: | |
| 79 return DesktopRect::MakeXYWH(rect.top(), size.width() - rect.right(), | |
| 80 rect.height(), rect.width()); | |
| 81 } | |
| 82 RTC_NOTREACHED(); | |
| 83 return DesktopRect(); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 void RotateDesktopFrame(const DesktopFrame& source, | |
| 88 const DesktopRect& source_rect, | |
| 89 const Rotation& rotation, | |
| 90 DesktopFrame* target) { | |
| 91 RTC_DCHECK(target); | |
| 92 // The rectangle in |target|. | |
| 93 const DesktopRect target_rect = | |
| 94 RotateRect(source_rect, source.size(), rotation); | |
| 95 RTC_DCHECK(DesktopRect::MakeSize(target->size()).ContainsRect(target_rect)); | |
|
Sergey Ulanov
2016/11/21 21:01:12
Also DCHECK that |source_rect| is inside |source|?
Hzj_jie
2016/11/21 23:33:30
Done.
| |
| 96 | |
| 97 if (target_rect.is_empty()) { | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 target->mutable_updated_region()->AddRect(target_rect); | |
| 102 int result = libyuv::ARGBRotate( | |
| 103 source.GetFrameDataAtPos(source_rect.top_left()), source.stride(), | |
| 104 target->GetFrameDataAtPos(target_rect.top_left()), target->stride(), | |
| 105 source_rect.width(), source_rect.height(), | |
| 106 ToLibyuvRotationMode(rotation)); | |
| 107 RTC_DCHECK_EQ(result, 0); | |
| 108 } | |
| 109 | |
| 110 } // namespace webrtc | |
| OLD | NEW |