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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/desktop_frame_rotator.cc
diff --git a/webrtc/modules/desktop_capture/desktop_frame_rotator.cc b/webrtc/modules/desktop_capture/desktop_frame_rotator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ac4995f1b1c8dbb82429ebb4d95230331088ee5
--- /dev/null
+++ b/webrtc/modules/desktop_capture/desktop_frame_rotator.cc
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/desktop_capture/desktop_frame_rotator.h"
+
+#include <string.h>
+
+#include "webrtc/base/checks.h"
+
+#include "third_party/libyuv/include/libyuv/rotate_argb.h"
+
+namespace webrtc {
+
+namespace {
+
+// Returns a rotated DesktopRect of |rect|. The |size| represents the size of
+// the DesktopFrame which |rect| belongs in.
+DesktopRect RotateRect(DesktopRect rect, DesktopSize size, Rotation rotation) {
+ switch (rotation) {
+ case Rotation::CLOCK_WISE_0:
+ return rect;
+ case Rotation::CLOCK_WISE_90:
+ 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.
+ size.height() - rect.top(), rect.right());
+ case Rotation::CLOCK_WISE_180:
+ return DesktopRect::MakeXYWH(size.width() - rect.right(),
+ size.height() - rect.bottom(), rect.width(),
+ rect.height());
+ case Rotation::CLOCK_WISE_270:
+ 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.
+ rect.bottom(), size.width() - rect.left());
+ }
+ RTC_NOTREACHED();
+ return DesktopRect();
+}
+
+// Returns a reverse-rotated Rotation of |rotation|.
+Rotation Reverse(Rotation rotation) {
+ switch (rotation) {
+ case Rotation::CLOCK_WISE_0:
+ return rotation;
+ case Rotation::CLOCK_WISE_90:
+ return Rotation::CLOCK_WISE_270;
+ case Rotation::CLOCK_WISE_180:
+ return Rotation::CLOCK_WISE_180;
+ case Rotation::CLOCK_WISE_270:
+ return Rotation::CLOCK_WISE_90;
+ }
+ RTC_NOTREACHED();
+ return Rotation::CLOCK_WISE_0;
+}
+
+// Returns a rotated DesktopSize of |size|.
+DesktopSize GetRotatedSize(DesktopSize size, Rotation rotation) {
+ switch (rotation) {
+ case Rotation::CLOCK_WISE_0:
+ case Rotation::CLOCK_WISE_180:
+ return size;
+ case Rotation::CLOCK_WISE_90:
+ case Rotation::CLOCK_WISE_270:
+ return DesktopSize(size.height(), size.width());
+ default:
Sergey Ulanov 2016/11/17 02:07:38 Please remove default case.
Hzj_jie 2016/11/17 07:14:55 Done.
+ RTC_NOTREACHED();
+ return DesktopSize();
+ }
+}
+
+libyuv::RotationMode ToLibyuvRotationMode(Rotation rotation) {
+ switch (rotation) {
+ case Rotation::CLOCK_WISE_0:
+ return libyuv::kRotate0;
+ case Rotation::CLOCK_WISE_90:
+ return libyuv::kRotate90;
+ case Rotation::CLOCK_WISE_180:
+ return libyuv::kRotate180;
+ case Rotation::CLOCK_WISE_270:
+ return libyuv::kRotate270;
+ default:
Sergey Ulanov 2016/11/17 02:07:39 Don't need this.
Hzj_jie 2016/11/17 07:14:55 Done.
+ RTC_NOTREACHED();
+ return libyuv::kRotate0;
+ }
+}
+
+} // namespace
+
+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.
+ DesktopRect rect,
+ Rotation rotation,
+ DesktopFrame* target) {
+ RTC_DCHECK(target);
+ 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.
+ return false;
+ }
+ if (rect.is_empty()) {
+ return true;
+ }
+
+ target->mutable_updated_region()->AddRect(rect);
+ // The rectangle in |source|.
+ const DesktopRect source_rect =
+ 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
+ Reverse(rotation));
+ return libyuv::ARGBRotate(
+ source.GetFrameDataAtPos(source_rect.top_left()), source.stride(),
+ target->GetFrameDataAtPos(rect.top_left()), target->stride(),
+ source_rect.width(), source_rect.height(),
+ ToLibyuvRotationMode(rotation)) == 0;
+}
+
+bool CopyUnrotatedRectTo(const DesktopFrame& source,
+ DesktopRect rect,
+ Rotation rotation,
+ DesktopFrame* target) {
+ return CopyRotatedRectTo(source, RotateRect(rect, source.size(), rotation),
+ rotation, target);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698