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/RTCI420Shader.mm b/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm
index 0618c1a..e0c9642 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm
@@ -15,6 +15,9 @@
 #import "RTCShader+Private.h"
 #import "WebRTC/RTCVideoFrame.h"
 
+#include "webrtc/base/optional.h"
+#include "webrtc/common_video/rotation.h"
+
 // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets
 // of 3 textures are used here, one for each of the Y, U and V planes. Having
 // two sets alleviates CPU blockage in the event that the GPU is asked to render
@@ -57,6 +60,9 @@
   GLint _ySampler;
   GLint _uSampler;
   GLint _vSampler;
+  // Store current rotation and only upload new vertex data when rotation
+  // changes.
+  rtc::Optional<webrtc::VideoRotation> _currentRotation;
   // Used to create a non-padded plane for GPU upload when we receive padded
   // frames.
   std::vector<uint8_t> _planeBuffer;
@@ -119,6 +125,11 @@
   glBindVertexArray(_vertexArray);
 #endif
   glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
+  if (!_currentRotation || frame.rotation != *_currentRotation) {
+    _currentRotation = rtc::Optional<webrtc::VideoRotation>(
+        static_cast<webrtc::VideoRotation>(frame.rotation));
+    RTCSetVertexData(*_currentRotation);
+  }
   glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
   return YES;