Commit 4a5bb938 authored by ccameron@chromium.org's avatar ccameron@chromium.org

Use correct device scale factors in Aura

The image transport surface now passes a scale factor. Set
the current_surface_ to use this scale factor instead of the
view's scale factor.

Fix a number of situations where the correct scale factor
from rendering was available, but the view's scale factor
was used instead.

BUG=132714

Review URL: https://chromiumcodereview.appspot.com/15666007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202400 0039d316-1c4b-4281-b951-d872f2087c98
parent 15bb5fa8
......@@ -27,40 +27,40 @@ ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) {
return ui::GetScaleFactorForNativeView(view ? view->GetNativeView() : NULL);
}
gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view,
const gfx::Point& point_in_pixel) {
gfx::Point ConvertViewPointToDIP(const RenderWidgetHostView* view,
const gfx::Point& point_in_pixel) {
return gfx::ToFlooredPoint(
gfx::ScalePoint(point_in_pixel, 1.0f / GetScaleForView(view)));
}
gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view,
const gfx::Size& size_in_pixel) {
gfx::Size ConvertViewSizeToPixel(const RenderWidgetHostView* view,
const gfx::Size& size_in_dip) {
return gfx::ToFlooredSize(
gfx::ScaleSize(size_in_pixel, 1.0f / GetScaleForView(view)));
gfx::ScaleSize(size_in_dip, GetScaleForView(view)));
}
gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view,
const gfx::Rect& rect_in_pixel) {
float scale = 1.0f / GetScaleForView(view);
return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
gfx::Rect ConvertViewRectToPixel(const RenderWidgetHostView* view,
const gfx::Rect& rect_in_dip) {
return ConvertRectToPixel(GetScaleForView(view), rect_in_dip);
}
gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view,
const gfx::Point& point_in_dip) {
return gfx::ToFlooredPoint(
gfx::ScalePoint(point_in_dip, GetScaleForView(view)));
gfx::Size ConvertSizeToDIP(float scale_factor,
const gfx::Size& size_in_pixel) {
return gfx::ToFlooredSize(
gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor));
}
gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view,
const gfx::Size& size_in_dip) {
return gfx::ToFlooredSize(
gfx::ScaleSize(size_in_dip, GetScaleForView(view)));
gfx::Rect ConvertRectToDIP(float scale_factor,
const gfx::Rect& rect_in_pixel) {
return gfx::ToFlooredRectDeprecated(
gfx::ScaleRect(rect_in_pixel, 1.0f / scale_factor));
}
gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view,
gfx::Rect ConvertRectToPixel(float scale_factor,
const gfx::Rect& rect_in_dip) {
float scale = GetScaleForView(view);
return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale));
return gfx::ToFlooredRectDeprecated(
gfx::ScaleRect(rect_in_dip, scale_factor));
}
} // namespace content
......@@ -24,18 +24,20 @@ CONTENT_EXPORT ui::ScaleFactor GetScaleFactorForView(
// 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);
CONTENT_EXPORT gfx::Point ConvertViewPointToDIP(
const RenderWidgetHostView* view, const gfx::Point& point_in_pixel);
CONTENT_EXPORT gfx::Size ConvertViewSizeToPixel(
const RenderWidgetHostView* view, const gfx::Size& size_in_dip);
CONTENT_EXPORT gfx::Rect ConvertViewRectToPixel(
const RenderWidgetHostView* view, const gfx::Rect& rect_in_dip);
CONTENT_EXPORT gfx::Size ConvertSizeToDIP(
float scale_factor, const gfx::Size& size_in_pixel);
CONTENT_EXPORT gfx::Rect ConvertRectToDIP(
float scale_factor, const gfx::Rect& rect_in_pixel);
CONTENT_EXPORT gfx::Rect ConvertRectToPixel(
float scale_factor, const gfx::Rect& rect_in_dip);
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_DIP_UTIL_H_
......@@ -1347,7 +1347,7 @@ void RenderWidgetHostImpl::GetSnapshotFromRenderer(
gfx::Rect copy_rect = src_subrect.IsEmpty() ?
gfx::Rect(view_->GetViewBounds().size()) : src_subrect;
gfx::Rect copy_rect_in_pixel = ConvertRectToPixel(view_, copy_rect);
gfx::Rect copy_rect_in_pixel = ConvertViewRectToPixel(view_, copy_rect);
Send(new ViewMsg_Snapshot(GetRoutingID(), copy_rect_in_pixel));
}
......
......@@ -632,6 +632,7 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
can_compose_inline_(true),
has_composition_text_(false),
last_swapped_surface_scale_factor_(1.f),
paint_canvas_(NULL),
synthetic_move_sent_(false),
accelerated_compositing_state_changed_(false),
......@@ -1198,7 +1199,9 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHelper(
gfx::Rect src_subrect_in_gl = src_subrect;
src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom());
gfx::Rect src_subrect_in_pixel = ConvertRectToPixel(this, src_subrect_in_gl);
gfx::Rect src_subrect_in_pixel =
ConvertRectToPixel(current_surface_->device_scale_factor(),
src_subrect_in_gl);
gl_helper->CropScaleReadbackAndCleanTexture(
current_surface_->PrepareTexture(),
current_surface_->size(),
......@@ -1218,7 +1221,7 @@ void RenderWidgetHostViewAura::CopyFromCompositingSurface(
}
CopyFromCompositingSurfaceHelper(src_subrect,
ConvertSizeToPixel(this, dst_size),
ConvertViewSizeToPixel(this, dst_size),
callback);
}
......@@ -1319,11 +1322,13 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() {
bool is_compositing_active = host_->is_accelerated_compositing_active();
if (is_compositing_active && current_surface_) {
window_->SetExternalTexture(current_surface_.get());
current_frame_size_ = ConvertSizeToDIP(this, current_surface_->size());
current_frame_size_ = ConvertSizeToDIP(
current_surface_->device_scale_factor(), current_surface_->size());
CheckResizeLock();
} else if (is_compositing_active && current_dib_) {
window_->SetExternalTexture(NULL);
current_frame_size_ = ConvertSizeToDIP(this, last_swapped_surface_size_);
current_frame_size_ = ConvertSizeToDIP(last_swapped_surface_scale_factor_,
last_swapped_surface_size_);
CheckResizeLock();
} else {
window_->SetExternalTexture(NULL);
......@@ -1334,6 +1339,7 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() {
bool RenderWidgetHostViewAura::SwapBuffersPrepare(
const gfx::Rect& surface_rect,
float surface_scale_factor,
const gfx::Rect& damage_rect,
const std::string& mailbox_name,
const BufferPresentedCallback& ack_callback) {
......@@ -1343,9 +1349,11 @@ bool RenderWidgetHostViewAura::SwapBuffersPrepare(
DLOG_IF(ERROR, damage_rect != surface_rect) << "Expected full damage rect";
skipped_damage_.setEmpty();
last_swapped_surface_size_ = surface_rect.size();
last_swapped_surface_scale_factor_ = surface_scale_factor;
}
if (ShouldSkipFrame(ConvertSizeToDIP(this, surface_rect.size())) ||
if (ShouldSkipFrame(ConvertSizeToDIP(surface_scale_factor,
surface_rect.size())) ||
mailbox_name.empty()) {
skipped_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
ack_callback.Run(true, scoped_refptr<ui::Texture>());
......@@ -1354,7 +1362,7 @@ bool RenderWidgetHostViewAura::SwapBuffersPrepare(
ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
current_surface_ =
factory->CreateTransportClient(current_device_scale_factor_);
factory->CreateTransportClient(surface_scale_factor);
if (!current_surface_) {
LOG(ERROR) << "Failed to create ImageTransport texture";
ack_callback.Run(true, scoped_refptr<ui::Texture>());
......@@ -1380,7 +1388,8 @@ void RenderWidgetHostViewAura::SwapBuffersCompleted(
if (frame_subscriber()->ShouldCaptureFrame(present_time,
&frame, &callback)) {
CopyFromCompositingSurfaceToVideoFrame(
gfx::Rect(ConvertSizeToDIP(this, current_surface_->size())),
gfx::Rect(ConvertSizeToDIP(current_surface_->device_scale_factor(),
current_surface_->size())),
frame,
base::Bind(callback, present_time));
}
......@@ -1432,7 +1441,8 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
gpu_host_id,
params_in_pixel.mailbox_name);
BuffersSwapped(
params_in_pixel.size, params_in_pixel.mailbox_name, ack_callback);
params_in_pixel.size, params_in_pixel.scale_factor,
params_in_pixel.mailbox_name, ack_callback);
}
void RenderWidgetHostViewAura::SwapDelegatedFrame(
......@@ -1500,6 +1510,7 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame(
current_dib_.reset(dib.release());
current_dib_id_ = dib_id;
last_swapped_surface_size_ = frame_size;
last_swapped_surface_scale_factor_ = frame_device_scale_factor;
ui::Compositor* compositor = GetCompositor();
if (!compositor) {
......@@ -1507,8 +1518,8 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame(
return;
}
gfx::Size frame_size_in_dip = gfx::ToFlooredSize(
gfx::ScaleSize(frame_size, 1.0f / frame_device_scale_factor));
gfx::Size frame_size_in_dip =
ConvertSizeToDIP(frame_device_scale_factor, frame_size);
if (ShouldSkipFrame(frame_size_in_dip)) {
can_lock_compositor_ = NO_PENDING_COMMIT;
SendSoftwareFrameAck(last_dib_id);
......@@ -1522,7 +1533,8 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame(
CheckResizeLock();
released_front_lock_ = NULL;
window_->SetExternalTexture(NULL);
window_->SchedulePaintInRect(ConvertRectToDIP(this, damage_rect));
window_->SchedulePaintInRect(
ConvertRectToDIP(frame_device_scale_factor, damage_rect));
if (paint_observer_)
paint_observer_->OnUpdateCompositorContent();
......@@ -1571,7 +1583,8 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame(
reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name),
sizeof(frame->gl_frame_data->mailbox.name));
BuffersSwapped(
frame->gl_frame_data->size, mailbox_name, ack_callback);
frame->gl_frame_data->size, frame->metadata.device_scale_factor,
mailbox_name, ack_callback);
}
#if defined(OS_WIN)
......@@ -1586,12 +1599,13 @@ void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
void RenderWidgetHostViewAura::BuffersSwapped(
const gfx::Size& size,
float surface_scale_factor,
const std::string& mailbox_name,
const BufferPresentedCallback& ack_callback) {
scoped_refptr<ui::Texture> texture_to_return(current_surface_);
const gfx::Rect surface_rect = gfx::Rect(size);
if (!SwapBuffersPrepare(
surface_rect, surface_rect, mailbox_name, ack_callback)) {
if (!SwapBuffersPrepare(surface_rect, surface_scale_factor, surface_rect,
mailbox_name, ack_callback)) {
return;
}
......@@ -1600,7 +1614,7 @@ void RenderWidgetHostViewAura::BuffersSwapped(
ui::Compositor* compositor = GetCompositor();
if (compositor) {
gfx::Size surface_size = ConvertSizeToDIP(this, size);
gfx::Size surface_size = ConvertSizeToDIP(surface_scale_factor, size);
window_->SchedulePaintInRect(gfx::Rect(surface_size));
}
......@@ -1625,7 +1639,8 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
params_in_pixel.mailbox_name);
if (!SwapBuffersPrepare(
surface_rect, damage_rect, params_in_pixel.mailbox_name, ack_callback)) {
surface_rect, params_in_pixel.surface_scale_factor, damage_rect,
params_in_pixel.mailbox_name, ack_callback)) {
return;
}
......@@ -1659,12 +1674,13 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
if (compositor) {
// Co-ordinates come in OpenGL co-ordinate space.
// We need to convert to layer space.
gfx::Rect rect_to_paint = 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));
gfx::Rect rect_to_paint = ConvertRectToDIP(
params_in_pixel.surface_scale_factor,
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));
// Damage may not have been DIP aligned, so inflate damage to compensate
// for any round-off error.
......@@ -2241,7 +2257,8 @@ scoped_refptr<ui::Texture> RenderWidgetHostViewAura::CopyTexture() {
return scoped_refptr<ui::Texture>(
factory->CreateOwnedTexture(
current_surface_->size(), current_device_scale_factor_, texture_id));
current_surface_->size(),
current_surface_->device_scale_factor(), texture_id));
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -457,10 +457,12 @@ class RenderWidgetHostViewAura
// The common entry point for full buffer updates from renderer
// and GPU process.
void BuffersSwapped(const gfx::Size& size,
float surface_scale_factor,
const std::string& mailbox_name,
const BufferPresentedCallback& ack_callback);
bool SwapBuffersPrepare(const gfx::Rect& surface_rect,
float surface_scale_factor,
const gfx::Rect& damage_rect,
const std::string& mailbox_name,
const BufferPresentedCallback& ack_callback);
......@@ -572,6 +574,7 @@ class RenderWidgetHostViewAura
// Used to determine when the skipped_damage_ needs to be reset due to
// size changes between front- and backbuffer.
gfx::Size last_swapped_surface_size_;
float last_swapped_surface_scale_factor_;
int pending_thumbnail_tasks_;
......
......@@ -186,7 +186,7 @@ class WebDragSourceAura : public base::MessageLoopForUI::Observer,
rvh = contents_->GetRenderViewHost();
if (rvh) {
gfx::Point screen_loc_in_pixel = ui::EventLocationFromNative(event);
gfx::Point screen_loc = ConvertPointToDIP(rvh->GetView(),
gfx::Point screen_loc = ConvertViewPointToDIP(rvh->GetView(),
screen_loc_in_pixel);
gfx::Point client_loc = screen_loc;
aura::Window* window = rvh->GetView()->GetNativeView();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment