Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: webrtc/modules/desktop_capture/desktop_frame_rotator.cc

Issue 2500883004: Add DesktopFrame rotation functions (Closed)
Patch Set: Resolve review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 RotateRect(DesktopRect rect, DesktopSize size, Rotation rotation) {
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(),
Sergey Ulanov 2016/11/17 02:07:39 MakeXYWH() here for consistency.
Hzj_jie 2016/11/17 07:14:55 Done.
31 size.height() - rect.top(), rect.right());
32 case Rotation::CLOCK_WISE_180:
33 return DesktopRect::MakeXYWH(size.width() - rect.right(),
34 size.height() - rect.bottom(), rect.width(),
35 rect.height());
36 case Rotation::CLOCK_WISE_270:
37 return DesktopRect::MakeLTRB(rect.top(), size.width() - rect.right(),
Sergey Ulanov 2016/11/17 02:07:39 MakeXYWH()?
Hzj_jie 2016/11/17 07:14:55 Done.
38 rect.bottom(), size.width() - rect.left());
39 }
40 RTC_NOTREACHED();
41 return DesktopRect();
42 }
43
44 // Returns a reverse-rotated Rotation of |rotation|.
45 Rotation Reverse(Rotation rotation) {
46 switch (rotation) {
47 case Rotation::CLOCK_WISE_0:
48 return rotation;
49 case Rotation::CLOCK_WISE_90:
50 return Rotation::CLOCK_WISE_270;
51 case Rotation::CLOCK_WISE_180:
52 return Rotation::CLOCK_WISE_180;
53 case Rotation::CLOCK_WISE_270:
54 return Rotation::CLOCK_WISE_90;
55 }
56 RTC_NOTREACHED();
57 return Rotation::CLOCK_WISE_0;
58 }
59
60 // Returns a rotated DesktopSize of |size|.
61 DesktopSize GetRotatedSize(DesktopSize size, Rotation rotation) {
62 switch (rotation) {
63 case Rotation::CLOCK_WISE_0:
64 case Rotation::CLOCK_WISE_180:
65 return size;
66 case Rotation::CLOCK_WISE_90:
67 case Rotation::CLOCK_WISE_270:
68 return DesktopSize(size.height(), size.width());
69 default:
Sergey Ulanov 2016/11/17 02:07:38 Please remove default case.
Hzj_jie 2016/11/17 07:14:55 Done.
70 RTC_NOTREACHED();
71 return DesktopSize();
72 }
73 }
74
75 libyuv::RotationMode ToLibyuvRotationMode(Rotation rotation) {
76 switch (rotation) {
77 case Rotation::CLOCK_WISE_0:
78 return libyuv::kRotate0;
79 case Rotation::CLOCK_WISE_90:
80 return libyuv::kRotate90;
81 case Rotation::CLOCK_WISE_180:
82 return libyuv::kRotate180;
83 case Rotation::CLOCK_WISE_270:
84 return libyuv::kRotate270;
85 default:
Sergey Ulanov 2016/11/17 02:07:39 Don't need this.
Hzj_jie 2016/11/17 07:14:55 Done.
86 RTC_NOTREACHED();
87 return libyuv::kRotate0;
88 }
89 }
90
91 } // namespace
92
93 bool CopyRotatedRectTo(const DesktopFrame& source,
Sergey Ulanov 2016/11/17 02:07:39 Do we really need to return any result from this f
Hzj_jie 2016/11/17 07:14:55 Done.
94 DesktopRect rect,
95 Rotation rotation,
96 DesktopFrame* target) {
97 RTC_DCHECK(target);
98 if (!DesktopRect::MakeSize(target->size()).ContainsRect(rect)) {
Sergey Ulanov 2016/11/17 02:07:39 Replace this with DCHECK?
Hzj_jie 2016/11/17 07:14:55 Done.
99 return false;
100 }
101 if (rect.is_empty()) {
102 return true;
103 }
104
105 target->mutable_updated_region()->AddRect(rect);
106 // The rectangle in |source|.
107 const DesktopRect source_rect =
108 RotateRect(rect, GetRotatedSize(source.size(), Reverse(rotation)),
Sergey Ulanov 2016/11/17 02:07:39 Don't need really need to reverse rotation for Get
Hzj_jie 2016/11/17 07:14:55 Yes, I know they are same. But I think Reverse(rot
109 Reverse(rotation));
110 return libyuv::ARGBRotate(
111 source.GetFrameDataAtPos(source_rect.top_left()), source.stride(),
112 target->GetFrameDataAtPos(rect.top_left()), target->stride(),
113 source_rect.width(), source_rect.height(),
114 ToLibyuvRotationMode(rotation)) == 0;
115 }
116
117 bool CopyUnrotatedRectTo(const DesktopFrame& source,
118 DesktopRect rect,
119 Rotation rotation,
120 DesktopFrame* target) {
121 return CopyRotatedRectTo(source, RotateRect(rect, source.size(), rotation),
122 rotation, target);
123 }
124
125 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698