Scale Sky contents by the device pixel ratio On devices with a non-trivial device pixel ratio, we need to tell Sky about the device pixel ratio so that it can scale up its rendering to the appropriate size. R=eseidel@chromium.org, esprehn@chromium.org Review URL: https://codereview.chromium.org/851533002
diff --git a/sky/viewer/document_view.cc b/sky/viewer/document_view.cc index b8a9a22..8301174 100644 --- a/sky/viewer/document_view.cc +++ b/sky/viewer/document_view.cc
@@ -22,6 +22,7 @@ #include "sky/compositor/layer_host.h" #include "sky/engine/public/platform/Platform.h" #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" +#include "sky/engine/public/platform/WebScreenInfo.h" #include "sky/engine/public/web/Sky.h" #include "sky/engine/public/web/WebConsoleMessage.h" #include "sky/engine/public/web/WebDocument.h" @@ -109,8 +110,11 @@ Load(response_.Pass()); - gfx::Size size = root_->bounds().To<gfx::Rect>().size(); - web_view_->resize(size); + auto& bounds = root_->bounds(); + float device_pixel_ratio = GetDevicePixelRatio(); + web_view_->resize(blink::WebSize(bounds.width / device_pixel_ratio, + bounds.height / device_pixel_ratio)); + // TODO(abarth): We should ask the view whether it is focused instead of // assuming that we're focused. web_view_->setFocus(true); @@ -151,7 +155,9 @@ web_view_->beginFrame(web_begin_frame_args); web_view_->layout(); blink::WebSize size = web_view_->size(); - root_layer_->SetSize(gfx::Size(size.width, size.height)); + float device_pixel_ratio = GetDevicePixelRatio(); + root_layer_->SetSize(gfx::Size(size.width * device_pixel_ratio, + size.height * device_pixel_ratio)); } void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { @@ -169,6 +175,16 @@ layer_host_->SetNeedsAnimate(); } +blink::WebScreenInfo DocumentView::screenInfo() { + DCHECK(root_); + auto& metrics = root_->viewport_metrics(); + blink::WebScreenInfo screen; + screen.rect = blink::WebRect(0, 0, metrics.size->width, metrics.size->height); + screen.availableRect = screen.rect; + screen.deviceScaleFactor = metrics.device_pixel_ratio; + return screen; +} + mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { if (!root_) return nullptr; @@ -186,6 +202,12 @@ frame->close(); } +float DocumentView::GetDevicePixelRatio() const { + if (root_) + return root_->viewport_metrics().device_pixel_ratio; + return 1.f; +} + blink::WebNavigationPolicy DocumentView::decidePolicyForNavigation( const blink::WebFrameClient::NavigationPolicyInfo& info) {
diff --git a/sky/viewer/document_view.h b/sky/viewer/document_view.h index 6494d52..98d8513 100644 --- a/sky/viewer/document_view.h +++ b/sky/viewer/document_view.h
@@ -76,6 +76,7 @@ // WebWidgetClient methods: void initializeLayerTreeView() override; void scheduleAnimation() override; + blink::WebScreenInfo screenInfo() override; // WebFrameClient methods: mojo::View* createChildFrame(const blink::WebURL& url) override; @@ -115,6 +116,7 @@ void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; void Load(mojo::URLResponsePtr response); + float GetDevicePixelRatio() const; mojo::URLResponsePtr response_; mojo::ServiceProviderImpl exported_services_;