Fix high DPI with Surfaces by treating Surface size as content bounds of layer

The size of the surface can be different from the bounds of the layer, so set the contents scale to convert between the two.

Review URL: https://codereview.chromium.org/708693002

Cr-Commit-Position: refs/heads/master@{#303157}
diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc
index f1909b4b..ee376aa 100644
--- a/cc/layers/surface_layer.cc
+++ b/cc/layers/surface_layer.cc
@@ -53,9 +53,10 @@
   DCHECK(destroy_sequence_.is_null());
 }
 
-void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) {
+void SurfaceLayer::SetSurfaceId(SurfaceId surface_id, const gfx::Size& size) {
   SatisfyDestroySequence();
   surface_id_ = surface_id;
+  surface_size_ = size;
   CreateNewDestroySequence();
 
   UpdateDrawsContent(HasDrawableContent());
@@ -88,6 +89,19 @@
   layer_impl->SetSurfaceId(surface_id_);
 }
 
+void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale,
+                                          float* contents_scale_x,
+                                          float* contents_scale_y,
+                                          gfx::Size* content_bounds) {
+  *content_bounds = surface_size_;
+  *contents_scale_x =
+      bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->width()) /
+                                     bounds().width();
+  *contents_scale_y =
+      bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->height()) /
+                                     bounds().height();
+}
+
 void SurfaceLayer::CreateNewDestroySequence() {
   DCHECK(destroy_sequence_.is_null());
   if (layer_tree_host()) {