Don't use CPU adaptation for screen content in the new API.

BUG=4605
R=pbos@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/48309004

Cr-Commit-Position: refs/heads/master@{#9116}
diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc
index dd8de11..3eaa287 100644
--- a/talk/media/webrtc/webrtcvideoengine2.cc
+++ b/talk/media/webrtc/webrtcvideoengine2.cc
@@ -1416,8 +1416,12 @@
   rtc::CritScope stream_lock(&capturer_crit_);
   if (!signal_cpu_adaptation_)
     return;
+  // Do not adapt resolution for screen content as this will likely result in
+  // blurry and unreadable text.
   for (auto& kv : capturers_) {
-    if (kv.second != nullptr && kv.second->video_adapter() != nullptr) {
+    if (kv.second != nullptr
+        && !kv.second->IsScreencast()
+        && kv.second->video_adapter() != nullptr) {
       kv.second->video_adapter()->OnCpuResolutionRequest(
           load == kOveruse ? CoordinatedVideoAdapter::DOWNGRADE
                            : CoordinatedVideoAdapter::UPGRADE);
diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc
index 54e52c2..7bcab55 100644
--- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc
+++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc
@@ -973,7 +973,7 @@
     EXPECT_EQ(webrtc_ext, recv_stream->GetConfig().rtp.extensions[0].name);
   }
 
-  void TestCpuAdaptation(bool enable_overuse);
+  void TestCpuAdaptation(bool enable_overuse, bool is_screenshare);
 
   FakeVideoSendStream* SetDenoisingOption(bool enabled) {
     VideoOptions options;
@@ -1644,14 +1644,19 @@
 }
 
 TEST_F(WebRtcVideoChannel2Test, AdaptsOnOveruse) {
-  TestCpuAdaptation(true);
+  TestCpuAdaptation(true, false);
 }
 
 TEST_F(WebRtcVideoChannel2Test, DoesNotAdaptOnOveruseWhenDisabled) {
-  TestCpuAdaptation(false);
+  TestCpuAdaptation(false, false);
 }
 
-void WebRtcVideoChannel2Test::TestCpuAdaptation(bool enable_overuse) {
+TEST_F(WebRtcVideoChannel2Test, DoesNotAdaptOnOveruseWhenScreensharing) {
+  TestCpuAdaptation(true, true);
+}
+
+void WebRtcVideoChannel2Test::TestCpuAdaptation(bool enable_overuse,
+                                                bool is_screenshare) {
   cricket::VideoCodec codec = kVp8Codec720p;
   std::vector<cricket::VideoCodec> codecs;
   codecs.push_back(codec);
@@ -1666,6 +1671,7 @@
   AddSendStream();
 
   cricket::FakeVideoCapturer capturer;
+  capturer.SetScreencast(is_screenshare);
   EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, &capturer));
   EXPECT_EQ(cricket::CS_RUNNING,
             capturer.Start(capturer.GetSupportedFormats()->front()));
@@ -1684,7 +1690,7 @@
 
   EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames());
 
-  if (enable_overuse) {
+  if (enable_overuse && !is_screenshare) {
     EXPECT_LT(send_stream->GetLastWidth(), codec.width);
     EXPECT_LT(send_stream->GetLastHeight(), codec.height);
   } else {