iOS render: Handle frame rotation in OpenGL

This CL handles frame rotation by updating the OpenGL vertex data in
RTCOpenGLVideoRenderer, instead of calling the expensive
libyuv::I420Rotate that will rotate the actual memory. Also, we can
handle rotated native frames instead of falling back to
NativeToI420Buffer.

Review-Url: https://codereview.webrtc.org/2176623002
Cr-Commit-Position: refs/heads/master@{#13715}
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm b/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm
index a130d0e..73682d3 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm
@@ -27,27 +27,14 @@
   }
 
   void OnFrame(const cricket::VideoFrame& nativeVideoFrame) override {
-    RTCVideoFrame *videoFrame = nil;
-    // Rotation of native handles is unsupported right now. Convert to CPU
-    // I420 buffer for rotation before calling the rotation method otherwise
-    // it will hit a DCHECK.
-    if (nativeVideoFrame.rotation() != webrtc::kVideoRotation_0 &&
-        nativeVideoFrame.video_frame_buffer()->native_handle()) {
-      rtc::scoped_refptr<webrtc::VideoFrameBuffer> i420Buffer =
-          nativeVideoFrame.video_frame_buffer()->NativeToI420Buffer();
-      std::unique_ptr<cricket::VideoFrame> cpuFrame(
-          new cricket::WebRtcVideoFrame(i420Buffer, nativeVideoFrame.rotation(),
-                                        nativeVideoFrame.timestamp_us(),
-                                        nativeVideoFrame.transport_frame_id()));
-      const cricket::VideoFrame *rotatedFrame =
-          cpuFrame->GetCopyWithRotationApplied();
-      videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame];
-    } else {
-      const cricket::VideoFrame *rotatedFrame =
-          nativeVideoFrame.GetCopyWithRotationApplied();
-      videoFrame = [[RTCVideoFrame alloc] initWithNativeFrame:rotatedFrame];
-    }
-    CGSize current_size = CGSizeMake(videoFrame.width, videoFrame.height);
+    RTCVideoFrame* videoFrame = [[RTCVideoFrame alloc]
+        initWithVideoBuffer:nativeVideoFrame.video_frame_buffer()
+                   rotation:nativeVideoFrame.rotation()
+                timeStampNs:nativeVideoFrame.GetTimeStamp()];
+    CGSize current_size = (videoFrame.rotation % 180 == 0)
+                              ? CGSizeMake(videoFrame.width, videoFrame.height)
+                              : CGSizeMake(videoFrame.height, videoFrame.width);
+
     if (!CGSizeEqualToSize(size_, current_size)) {
       size_ = current_size;
       [adapter_.videoRenderer setSize:size_];