OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bit_cast.h" | 10 #include "base/bit_cast.h" |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 RenderFrameImpl* render_frame, | 472 RenderFrameImpl* render_frame, |
473 PluginModule* module, | 473 PluginModule* module, |
474 ppapi::PPP_Instance_Combined* instance_interface, | 474 ppapi::PPP_Instance_Combined* instance_interface, |
475 WebPluginContainer* container, | 475 WebPluginContainer* container, |
476 const GURL& plugin_url) | 476 const GURL& plugin_url) |
477 : RenderFrameObserver(render_frame), | 477 : RenderFrameObserver(render_frame), |
478 render_frame_(render_frame), | 478 render_frame_(render_frame), |
479 module_(module), | 479 module_(module), |
480 instance_interface_(instance_interface), | 480 instance_interface_(instance_interface), |
481 pp_instance_(0), | 481 pp_instance_(0), |
| 482 graphics2d_translation_(0, 0), |
| 483 graphics2d_scale_(1.f), |
482 container_(container), | 484 container_(container), |
483 layer_bound_to_fullscreen_(false), | 485 layer_bound_to_fullscreen_(false), |
484 layer_is_hardware_(false), | 486 layer_is_hardware_(false), |
485 plugin_url_(plugin_url), | 487 plugin_url_(plugin_url), |
486 document_url_(container ? GURL(container->element().document().url()) | 488 document_url_(container ? GURL(container->element().document().url()) |
487 : GURL()), | 489 : GURL()), |
488 is_flash_plugin_(module->name() == kFlashPluginName), | 490 is_flash_plugin_(module->name() == kFlashPluginName), |
489 has_been_clicked_(false), | 491 has_been_clicked_(false), |
490 javascript_used_(false), | 492 javascript_used_(false), |
491 full_frame_(false), | 493 full_frame_(false), |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 | 1540 |
1539 bool PepperPluginInstanceImpl::LoadTextInputInterface() { | 1541 bool PepperPluginInstanceImpl::LoadTextInputInterface() { |
1540 if (!plugin_textinput_interface_) { | 1542 if (!plugin_textinput_interface_) { |
1541 plugin_textinput_interface_ = static_cast<const PPP_TextInput_Dev*>( | 1543 plugin_textinput_interface_ = static_cast<const PPP_TextInput_Dev*>( |
1542 module_->GetPluginInterface(PPP_TEXTINPUT_DEV_INTERFACE)); | 1544 module_->GetPluginInterface(PPP_TEXTINPUT_DEV_INTERFACE)); |
1543 } | 1545 } |
1544 | 1546 |
1545 return !!plugin_textinput_interface_; | 1547 return !!plugin_textinput_interface_; |
1546 } | 1548 } |
1547 | 1549 |
| 1550 void PepperPluginInstanceImpl::SetGraphics2DTransform( |
| 1551 const float& scale, |
| 1552 const gfx::PointF& translation) { |
| 1553 graphics2d_scale_ = scale; |
| 1554 graphics2d_translation_ = translation; |
| 1555 |
| 1556 UpdateLayerTransform(); |
| 1557 } |
| 1558 |
1548 void PepperPluginInstanceImpl::UpdateLayerTransform() { | 1559 void PepperPluginInstanceImpl::UpdateLayerTransform() { |
1549 if (!bound_graphics_2d_platform_ || !texture_layer_) { | 1560 if (!bound_graphics_2d_platform_ || !texture_layer_) { |
1550 // Currently the transform is only applied for Graphics2D. | 1561 // Currently the transform is only applied for Graphics2D. |
1551 return; | 1562 return; |
1552 } | 1563 } |
1553 // Set the UV coordinates of the texture based on the size of the Graphics2D | 1564 // Set the UV coordinates of the texture based on the size of the Graphics2D |
1554 // context. By default a texture gets scaled to the size of the layer. But | 1565 // context. By default a texture gets scaled to the size of the layer. But |
1555 // if the size of the Graphics2D context doesn't match the size of the plugin | 1566 // if the size of the Graphics2D context doesn't match the size of the plugin |
1556 // then it will be incorrectly stretched. This also affects how the plugin | 1567 // then it will be incorrectly stretched. This also affects how the plugin |
1557 // is painted when it is being resized. If the Graphics2D contents are | 1568 // is painted when it is being resized. If the Graphics2D contents are |
1558 // stretched when a plugin is resized while waiting for a new frame from the | 1569 // stretched when a plugin is resized while waiting for a new frame from the |
1559 // plugin to be rendered, then flickering behavior occurs as in | 1570 // plugin to be rendered, then flickering behavior occurs as in |
1560 // crbug.com/353453. | 1571 // crbug.com/353453. |
1561 gfx::SizeF graphics_2d_size_in_dip = | 1572 gfx::SizeF graphics_2d_size_in_dip = |
1562 gfx::ScaleSize(gfx::SizeF(bound_graphics_2d_platform_->Size()), | 1573 gfx::ScaleSize(gfx::SizeF(bound_graphics_2d_platform_->Size()), |
1563 bound_graphics_2d_platform_->GetScale()); | 1574 bound_graphics_2d_platform_->GetScale()); |
1564 gfx::Size plugin_size_in_dip(view_data_.rect.size.width, | 1575 gfx::Size plugin_size_in_dip(view_data_.rect.size.width, |
1565 view_data_.rect.size.height); | 1576 view_data_.rect.size.height); |
1566 | 1577 |
| 1578 // Adding the SetLayerTransform from Graphics2D to the UV. |
| 1579 // If graphics2d_scale_ is 1.f and graphics2d_translation_ is 0 then UV will |
| 1580 // be top_left (0,0) and lower_right (plugin_size_in_dip.width() / |
| 1581 // graphics_2d_size_in_dip.width(), plugin_size_in_dip.height() / |
| 1582 // graphics_2d_size_in_dip.height()) |
| 1583 gfx::PointF top_left = |
| 1584 gfx::PointF(-graphics2d_translation_.x() / graphics2d_scale_, |
| 1585 -graphics2d_translation_.y() / graphics2d_scale_); |
| 1586 gfx::PointF lower_right = |
| 1587 gfx::PointF((1 / graphics2d_scale_) * plugin_size_in_dip.width() - |
| 1588 graphics2d_translation_.x() / graphics2d_scale_, |
| 1589 (1 / graphics2d_scale_) * plugin_size_in_dip.height() - |
| 1590 graphics2d_translation_.y() / graphics2d_scale_); |
1567 texture_layer_->SetUV( | 1591 texture_layer_->SetUV( |
1568 gfx::PointF(0.0f, 0.0f), | 1592 gfx::PointF(top_left.x() / graphics_2d_size_in_dip.width(), |
1569 gfx::PointF( | 1593 top_left.y() / graphics_2d_size_in_dip.height()), |
1570 plugin_size_in_dip.width() / graphics_2d_size_in_dip.width(), | 1594 gfx::PointF(lower_right.x() / graphics_2d_size_in_dip.width(), |
1571 plugin_size_in_dip.height() / graphics_2d_size_in_dip.height())); | 1595 lower_right.y() / graphics_2d_size_in_dip.height())); |
1572 } | 1596 } |
1573 | 1597 |
1574 bool PepperPluginInstanceImpl::PluginHasFocus() const { | 1598 bool PepperPluginInstanceImpl::PluginHasFocus() const { |
1575 return flash_fullscreen_ || (has_webkit_focus_ && has_content_area_focus_); | 1599 return flash_fullscreen_ || (has_webkit_focus_ && has_content_area_focus_); |
1576 } | 1600 } |
1577 | 1601 |
1578 void PepperPluginInstanceImpl::SendFocusChangeNotification() { | 1602 void PepperPluginInstanceImpl::SendFocusChangeNotification() { |
1579 // Keep a reference on the stack. RenderViewImpl::PepperFocusChanged may | 1603 // Keep a reference on the stack. RenderViewImpl::PepperFocusChanged may |
1580 // remove the <embed> from the DOM, which will make the PepperWebPluginImpl | 1604 // remove the <embed> from the DOM, which will make the PepperWebPluginImpl |
1581 // drop its reference, usually the last one. This is similar to possible | 1605 // drop its reference, usually the last one. This is similar to possible |
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 } | 3348 } |
3325 | 3349 |
3326 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { | 3350 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { |
3327 rect->set_x(rect->x() / viewport_to_dip_scale_); | 3351 rect->set_x(rect->x() / viewport_to_dip_scale_); |
3328 rect->set_y(rect->y() / viewport_to_dip_scale_); | 3352 rect->set_y(rect->y() / viewport_to_dip_scale_); |
3329 rect->set_width(rect->width() / viewport_to_dip_scale_); | 3353 rect->set_width(rect->width() / viewport_to_dip_scale_); |
3330 rect->set_height(rect->height() / viewport_to_dip_scale_); | 3354 rect->set_height(rect->height() / viewport_to_dip_scale_); |
3331 } | 3355 } |
3332 | 3356 |
3333 } // namespace content | 3357 } // namespace content |
OLD | NEW |