Surface synchronization: Update compositor scale factor whenever changes

If device emulation was enabled then the WebViewImpl device scale
factor may not change as system device scale factor changes.

Surface synchronization expects that every surface have a fixed device
scale factor. Prior to this CL, the layer compositor's view of device
scale factor may not be updated as system device scale factor changes
when device emulation is enabled. This would cause the layer compositor
to submit a CompositorFrame with an incorrect device scale factor. This
resulted in two problems:

1. Surface invariants violation error could result if device emulation
is later disabled. This can happen if the system DSF changes but the
device emulated DSF does not and then device emulation is turned off
with the new system DSF.

2. SurfaceAggregator does relative scaling of surfaces based on their
reported device scale factor. If the CompositorFrame doesn't report its
device scale factor correctly, it will be scaled incorrectly.

TBR=fsamuel@chromium.org

(cherry picked from commit e24c90e284ccaae925132cc0271d9179b5560ec3)

Bug: 791154, 672962
TBR: bokan@chromium.org
Change-Id: I68be4142a83806b8893185ca9e542afada126b9f
Reviewed-on: https://chromium-review.googlesource.com/925682
Commit-Queue: Fady Samuel <fsamuel@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#538042}
Reviewed-on: https://chromium-review.googlesource.com/933106
Reviewed-by: Fady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#561}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 62c72c8..dd61861 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -618,10 +618,8 @@
   bool screen_info_changed = screen_info_ != screen_info;
 
   screen_info_ = screen_info;
-  if (device_scale_factor_ != screen_info_.device_scale_factor) {
-    device_scale_factor_ = screen_info_.device_scale_factor;
-    OnDeviceScaleFactorChanged();
-  }
+  device_scale_factor_ = screen_info_.device_scale_factor;
+  OnDeviceScaleFactorChanged();
 
   if (screen_info_changed) {
     for (auto& observer : render_frame_proxies_)
@@ -1321,10 +1319,8 @@
   if (render_thread)
     render_thread->SetRenderingColorSpace(screen_info_.color_space);
 
-  if (device_scale_factor_ != screen_info_.device_scale_factor) {
-    device_scale_factor_ = screen_info_.device_scale_factor;
-    OnDeviceScaleFactorChanged();
-  }
+  device_scale_factor_ = screen_info_.device_scale_factor;
+  OnDeviceScaleFactorChanged();
 
   if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
     // A resize ack shouldn't be requested if we have not ACK'd the previous
diff --git a/third_party/WebKit/Source/core/exported/WebViewImpl.cpp b/third_party/WebKit/Source/core/exported/WebViewImpl.cpp
index d91e3b1..8ab1976 100644
--- a/third_party/WebKit/Source/core/exported/WebViewImpl.cpp
+++ b/third_party/WebKit/Source/core/exported/WebViewImpl.cpp
@@ -2780,6 +2780,9 @@
   if (!GetPage())
     return;
 
+  if (GetPage()->DeviceScaleFactorDeprecated() == scale_factor)
+    return;
+
   GetPage()->SetDeviceScaleFactorDeprecated(scale_factor);
 
   if (layer_tree_view_)
@@ -2788,6 +2791,10 @@
 
 void WebViewImpl::SetZoomFactorForDeviceScaleFactor(
     float zoom_factor_for_device_scale_factor) {
+  if (zoom_factor_for_device_scale_factor_ ==
+      zoom_factor_for_device_scale_factor) {
+    return;
+  }
   zoom_factor_for_device_scale_factor_ = zoom_factor_for_device_scale_factor;
   if (!layer_tree_view_)
     return;
diff --git a/third_party/WebKit/Source/core/inspector/DevToolsEmulator.cpp b/third_party/WebKit/Source/core/inspector/DevToolsEmulator.cpp
index 3c8f7e8e..3e445ae 100644
--- a/third_party/WebKit/Source/core/inspector/DevToolsEmulator.cpp
+++ b/third_party/WebKit/Source/core/inspector/DevToolsEmulator.cpp
@@ -128,6 +128,9 @@
 }
 
 void DevToolsEmulator::SetPreferCompositingToLCDTextEnabled(bool enabled) {
+  if (embedder_prefer_compositing_to_lcd_text_enabled_ == enabled)
+    return;
+
   embedder_prefer_compositing_to_lcd_text_enabled_ = enabled;
   bool emulate_mobile_enabled =
       device_metrics_enabled_ && emulate_mobile_enabled_;