diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/dip_util.cc | 59 | ||||
-rw-r--r-- | content/browser/renderer_host/dip_util.h | 40 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.cc | 71 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.h | 8 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl.cc | 6 | ||||
-rw-r--r-- | content/common/view_messages.h | 1 | ||||
-rw-r--r-- | content/content_browser.gypi | 2 | ||||
-rw-r--r-- | content/port/browser/render_widget_host_view_port.h | 8 | ||||
-rw-r--r-- | content/public/browser/render_widget_host_view.h | 9 |
9 files changed, 165 insertions, 39 deletions
diff --git a/content/browser/renderer_host/dip_util.cc b/content/browser/renderer_host/dip_util.cc new file mode 100644 index 0000000..075c3c3 --- /dev/null +++ b/content/browser/renderer_host/dip_util.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/renderer_host/dip_util.h" + +#include "content/public/browser/render_widget_host_view.h" +#include "ui/gfx/monitor.h" +#include "ui/gfx/point.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/screen.h" +#include "ui/gfx/size.h" + +namespace content { + +float GetDIPScaleFactor(const RenderWidgetHostView* view) { + if (gfx::Screen::IsDIPEnabled()) { + gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow( + view ? view->GetNativeView() : NULL); + return monitor.device_scale_factor(); + } + return 1.0f; +} + +gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, + const gfx::Point& point_in_pixel) { + return point_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); +} + +gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, + const gfx::Size& size_in_pixel) { + return size_in_pixel.Scale(1.0f / GetDIPScaleFactor(view)); +} + +gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, + const gfx::Rect& rect_in_pixel) { + float scale = 1.0f / GetDIPScaleFactor(view); + return gfx::Rect(rect_in_pixel.origin().Scale(scale), + rect_in_pixel.size().Scale(scale)); +} + +gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, + const gfx::Point& point_in_dip) { + return point_in_dip.Scale(GetDIPScaleFactor(view)); +} + +gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, + const gfx::Size& size_in_dip) { + return size_in_dip.Scale(GetDIPScaleFactor(view)); +} + +gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, + const gfx::Rect& rect_in_dip) { + float scale = GetDIPScaleFactor(view); + return gfx::Rect(rect_in_dip.origin().Scale(scale), + rect_in_dip.size().Scale(scale)); +} + +} // namespace content diff --git a/content/browser/renderer_host/dip_util.h b/content/browser/renderer_host/dip_util.h new file mode 100644 index 0000000..ac9ba9d --- /dev/null +++ b/content/browser/renderer_host/dip_util.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_DIP_UTIL_H_ +#define CONTENT_BROWSER_RENDERER_HOST_DIP_UTIL_H_ +#pragma once + +#include "content/common/content_export.h" + +namespace gfx { +class Point; +class Rect; +class Size; +} // namespace gfx + +namespace content { +class RenderWidgetHostView; + +// Returns scale factor used to convert from DIP to pixel coordinate systems. +// Returns 1.0 if DIP is not enabled. +CONTENT_EXPORT float GetDIPScaleFactor(const RenderWidgetHostView* view); + +// Utility functions that convert point/size/rect between DIP and pixel +// coordinate system. +CONTENT_EXPORT gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view, + const gfx::Point& point_in_pixel); +CONTENT_EXPORT gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view, + const gfx::Size& size_in_pixel); +CONTENT_EXPORT gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view, + const gfx::Rect& rect_in_pixel); +CONTENT_EXPORT gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view, + const gfx::Point& point_in_dip); +CONTENT_EXPORT gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view, + const gfx::Size& size_in_dip); +CONTENT_EXPORT gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view, + const gfx::Rect& rect_in_dip); +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_DIP_UTIL_H_ diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index a61b5fa..5bb4f3b 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/string_number_conversions.h" #include "content/browser/renderer_host/backing_store_skia.h" +#include "content/browser/renderer_host/dip_util.h" #include "content/browser/renderer_host/image_transport_client.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/web_input_event_aura.h" @@ -269,9 +270,9 @@ void RenderWidgetHostViewAura::InitAsFullscreen( window_->SetName("RenderWidgetHostViewAura"); window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); window_->SetParent(NULL); - // Don't scale the canvas on high density screen because + // Don't scale the contents on high density screen because // the renderer takes care of it. - window_->layer()->set_scale_canvas(false); + window_->layer()->set_scale_content(false); Show(); Focus(); } @@ -452,7 +453,9 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurface( if (!container) return; - if (!output->initialize(size.width(), size.height(), true)) + gfx::Size size_in_pixel = content::ConvertSizeToPixel(this, size); + if (!output->initialize( + size_in_pixel.width(), size_in_pixel.height(), true)) return; ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); @@ -465,7 +468,7 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurface( scoped_callback_runner.Release(); gl_helper->CopyTextureTo(container->texture_id(), container->size(), - size, + size_in_pixel, addr, callback); } @@ -478,6 +481,13 @@ void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have // fewer inconsistent temporary states. needs_update_texture_ = true; + + // Don't scale contents on high density screen when content is accelerated + // because renderer takes care of it. + // TODO(pkotwicz): Implement DIP backing store such that renderer always + // scales web contents. + window_->layer()->set_scale_content( + !host_->is_accelerated_compositing_active()); } void RenderWidgetHostViewAura::UpdateExternalTexture() { @@ -497,7 +507,9 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList; ResizeLockList::iterator it = resize_locks_.begin(); while (it != resize_locks_.end()) { - if ((*it)->expected_size() == container->size()) + gfx::Size container_size = content::ConvertSizeToDIP(this, + container->size()); + if ((*it)->expected_size() == container_size) break; ++it; } @@ -529,19 +541,22 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { } void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( - const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, + const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, int gpu_host_id) { - current_surface_ = params.surface_handle; + current_surface_ = params_in_pixel.surface_handle; UpdateExternalTexture(); ui::Compositor* compositor = GetCompositor(); if (!compositor) { // We have no compositor, so we have no way to display the surface. // Must still send the ACK. - RenderWidgetHostImpl::AcknowledgeSwapBuffers(params.route_id, gpu_host_id); + RenderWidgetHostImpl::AcknowledgeSwapBuffers(params_in_pixel.route_id, + gpu_host_id); } else { - gfx::Size surface_size = - image_transport_clients_[params.surface_handle]->size(); + gfx::Size surface_size_in_pixel = + image_transport_clients_[params_in_pixel.surface_handle]->size(); + gfx::Size surface_size = content::ConvertSizeToDIP(this, + surface_size_in_pixel); window_->SchedulePaintInRect(gfx::Rect(surface_size)); if (!resize_locks_.empty() && !compositor->DrawPending()) { @@ -550,12 +565,12 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( // OnCompositingEnded(), because out-of-order execution in the GPU process // might corrupt the "front buffer" for the currently issued frame. RenderWidgetHostImpl::AcknowledgeSwapBuffers( - params.route_id, gpu_host_id); + params_in_pixel.route_id, gpu_host_id); } else { // Add sending an ACK to the list of things to do OnCompositingEnded on_compositing_ended_callbacks_.push_back( base::Bind(&RenderWidgetHostImpl::AcknowledgeSwapBuffers, - params.route_id, gpu_host_id)); + params_in_pixel.route_id, gpu_host_id)); if (!compositor->HasObserver(this)) compositor->AddObserver(this); } @@ -563,9 +578,9 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( } void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( - const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, + const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, int gpu_host_id) { - current_surface_ = params.surface_handle; + current_surface_ = params_in_pixel.surface_handle; UpdateExternalTexture(); ui::Compositor* compositor = GetCompositor(); @@ -573,18 +588,20 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( // We have no compositor, so we have no way to display the surface // Must still send the ACK RenderWidgetHostImpl::AcknowledgePostSubBuffer( - params.route_id, gpu_host_id); + params_in_pixel.route_id, gpu_host_id); } else { - gfx::Size surface_size = - image_transport_clients_[params.surface_handle]->size(); + gfx::Size surface_size_in_pixel = + image_transport_clients_[params_in_pixel.surface_handle]->size(); // Co-ordinates come in OpenGL co-ordinate space. // We need to convert to layer space. - window_->SchedulePaintInRect(gfx::Rect( - params.x, - surface_size.height() - params.y - params.height, - params.width, - params.height)); + gfx::Rect rect_to_paint = content::ConvertRectToDIP(this, gfx::Rect( + params_in_pixel.x, + surface_size_in_pixel.height() - params_in_pixel.y - + params_in_pixel.height, + params_in_pixel.width, + params_in_pixel.height)); + window_->SchedulePaintInRect(rect_to_paint); if (!resize_locks_.empty() && !compositor->DrawPending()) { // If we are waiting for the resize, fast-track the ACK. @@ -592,12 +609,12 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( // OnCompositingEnded(), because out-of-order execution in the GPU process // might corrupt the "front buffer" for the currently issued frame. RenderWidgetHostImpl::AcknowledgePostSubBuffer( - params.route_id, gpu_host_id); + params_in_pixel.route_id, gpu_host_id); } else { // Add sending an ACK to the list of things to do OnCompositingEnded on_compositing_ended_callbacks_.push_back( base::Bind(&RenderWidgetHostImpl::AcknowledgePostSubBuffer, - params.route_id, gpu_host_id)); + params_in_pixel.route_id, gpu_host_id)); if (!compositor->HasObserver(this)) compositor->AddObserver(this); } @@ -616,13 +633,13 @@ bool RenderWidgetHostViewAura::HasAcceleratedSurface( } void RenderWidgetHostViewAura::AcceleratedSurfaceNew( - int32 width, - int32 height, + int32 width_in_pixel, + int32 height_in_pixel, uint64* surface_handle, TransportDIB::Handle* shm_handle) { ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); scoped_refptr<ImageTransportClient> surface(factory->CreateTransportClient( - gfx::Size(width, height), surface_handle)); + gfx::Size(width_in_pixel, height_in_pixel), surface_handle)); if (!surface) { LOG(ERROR) << "Failed to create ImageTransportClient"; return; diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index 395b8b8..3e1cdfe 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -99,16 +99,16 @@ class RenderWidgetHostViewAura base::Callback<void(bool)> callback) OVERRIDE; virtual void OnAcceleratedCompositingStateChange() OVERRIDE; virtual void AcceleratedSurfaceBuffersSwapped( - const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, + const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, int gpu_host_id) OVERRIDE; virtual void AcceleratedSurfacePostSubBuffer( - const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, + const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, int gpu_host_id) OVERRIDE; virtual void AcceleratedSurfaceSuspend() OVERRIDE; virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; virtual void AcceleratedSurfaceNew( - int32 width, - int32 height, + int32 width_in_pixel, + int32 height_in_pixel, uint64* surface_id, TransportDIB::Handle* surface_handle) OVERRIDE; virtual void AcceleratedSurfaceRelease(uint64 surface_id) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 14f3b27..73d4e6e 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -548,6 +548,12 @@ WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, prefs.max_untiled_layer_height = GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1); + if (gfx::Screen::IsDIPEnabled()) { + // Only apply when using DIP coordinate system as this setting interferes + // with fixed layout mode. + prefs.apply_default_device_scale_factor_in_compositor = true; + } + content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs); return prefs; diff --git a/content/common/view_messages.h b/content/common/view_messages.h index ae5b913..10695487 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -137,6 +137,7 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::WebPreferences) IPC_STRUCT_TRAITS_MEMBER(default_font_size) IPC_STRUCT_TRAITS_MEMBER(default_fixed_font_size) IPC_STRUCT_TRAITS_MEMBER(default_device_scale_factor) + IPC_STRUCT_TRAITS_MEMBER(apply_default_device_scale_factor_in_compositor) IPC_STRUCT_TRAITS_MEMBER(minimum_font_size) IPC_STRUCT_TRAITS_MEMBER(minimum_logical_font_size) IPC_STRUCT_TRAITS_MEMBER(default_encoding) diff --git a/content/content_browser.gypi b/content/content_browser.gypi index dbba922..cbfcedc 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -482,6 +482,8 @@ 'browser/renderer_host/cross_site_resource_handler.h', 'browser/renderer_host/database_message_filter.cc', 'browser/renderer_host/database_message_filter.h', + 'browser/renderer_host/dip_util.cc', + 'browser/renderer_host/dip_util.h', 'browser/renderer_host/doomed_resource_handler.cc', 'browser/renderer_host/doomed_resource_handler.h', 'browser/renderer_host/file_utilities_message_filter.cc', diff --git a/content/port/browser/render_widget_host_view_port.h b/content/port/browser/render_widget_host_view_port.h index 0eaeece..605632d 100644 --- a/content/port/browser/render_widget_host_view_port.h +++ b/content/port/browser/render_widget_host_view_port.h @@ -162,12 +162,12 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { // too far ahead. They may all be zero, in which case no flow control is // enforced; this case is currently used for accelerated plugins. virtual void AcceleratedSurfaceBuffersSwapped( - const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, + const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, int gpu_host_id) = 0; // Similar to above, except |params.(x|y|width|height)| define the region // of the surface that changed. virtual void AcceleratedSurfacePostSubBuffer( - const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, + const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, int gpu_host_id) = 0; // Release the accelerated surface temporarily. It will be recreated on the @@ -221,8 +221,8 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { #if defined(USE_AURA) virtual void AcceleratedSurfaceNew( - int32 width, - int32 height, + int32 width_in_pixel, + int32 height_in_pixel, uint64* surface_id, TransportDIB::Handle* surface_handle) = 0; virtual void AcceleratedSurfaceRelease(uint64 surface_id) = 0; diff --git a/content/public/browser/render_widget_host_view.h b/content/public/browser/render_widget_host_view.h index f11a9f8..e4319ac 100644 --- a/content/public/browser/render_widget_host_view.h +++ b/content/public/browser/render_widget_host_view.h @@ -6,16 +6,17 @@ #define CONTENT_PUBLIC_BROWSER_RENDER_WIDGET_HOST_VIEW_H_ #pragma once -#if defined(TOOLKIT_GTK) -#include <gdk/gdk.h> -#endif - +#include "base/basictypes.h" #include "content/common/content_export.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkRegion.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "ui/gfx/native_widget_types.h" +#if defined(TOOLKIT_GTK) +#include <gdk/gdk.h> +#endif + class BrowserAccessibilityManager; namespace gfx { |