Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 1881603002: Added SetLayerTransform to PPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up the code Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 1538
1539 bool PepperPluginInstanceImpl::LoadTextInputInterface() { 1539 bool PepperPluginInstanceImpl::LoadTextInputInterface() {
1540 if (!plugin_textinput_interface_) { 1540 if (!plugin_textinput_interface_) {
1541 plugin_textinput_interface_ = static_cast<const PPP_TextInput_Dev*>( 1541 plugin_textinput_interface_ = static_cast<const PPP_TextInput_Dev*>(
1542 module_->GetPluginInterface(PPP_TEXTINPUT_DEV_INTERFACE)); 1542 module_->GetPluginInterface(PPP_TEXTINPUT_DEV_INTERFACE));
1543 } 1543 }
1544 1544
1545 return !!plugin_textinput_interface_; 1545 return !!plugin_textinput_interface_;
1546 } 1546 }
1547 1547
1548 void PepperPluginInstanceImpl::SetLayerTransform(gfx::Transform transform) {
1549 transform_ = transform;
1550 DCHECK(transform.IsScaleOrTranslation());
1551
1552 UpdateLayerTransform();
1553 }
1554
1548 void PepperPluginInstanceImpl::UpdateLayerTransform() { 1555 void PepperPluginInstanceImpl::UpdateLayerTransform() {
1549 if (!bound_graphics_2d_platform_ || !texture_layer_) { 1556 if (!bound_graphics_2d_platform_ || !texture_layer_) {
1550 // Currently the transform is only applied for Graphics2D. 1557 // Currently the transform is only applied for Graphics2D.
1551 return; 1558 return;
1552 } 1559 }
1553 // Set the UV coordinates of the texture based on the size of the Graphics2D 1560 // 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 1561 // 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 1562 // 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 1563 // 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 1564 // 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 1565 // 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 1566 // plugin to be rendered, then flickering behavior occurs as in
1560 // crbug.com/353453. 1567 // crbug.com/353453.
1561 gfx::SizeF graphics_2d_size_in_dip = 1568 gfx::SizeF graphics_2d_size_in_dip =
1562 gfx::ScaleSize(gfx::SizeF(bound_graphics_2d_platform_->Size()), 1569 gfx::ScaleSize(gfx::SizeF(bound_graphics_2d_platform_->Size()),
1563 bound_graphics_2d_platform_->GetScale()); 1570 bound_graphics_2d_platform_->GetScale());
1564 gfx::Size plugin_size_in_dip(view_data_.rect.size.width, 1571 gfx::Size plugin_size_in_dip(view_data_.rect.size.width,
1565 view_data_.rect.size.height); 1572 view_data_.rect.size.height);
1566 1573
1574 // Adding the SetLayerTransform from Graphics2D to the UV.
1575 // If the transform_ is the identity matrix
1576 // then UV will be top_left (0,0) and
1577 // lower_right (plugin_size_in_dip.width() / graphics_2d_size_in_dip.width(),
1578 // plugin_size_in_dip.height() / graphics_2d_size_in_dip.height())
1579 gfx::PointF Translate = gfx::PointF(transform_.matrix().getFloat(0,3),
1580 transform_.matrix().getFloat(1,3));
1581 float scale = transform_.matrix().getFloat(0,0);
1582 gfx::PointF top_left = gfx::PointF(-Translate.x() / scale ,
1583 -Translate.y() / scale);
1584 gfx::PointF lower_right = gfx::PointF((1 / scale) * plugin_size_in_dip.width()
1585 -Translate.x() / scale,
wjmaclean 2016/04/14 20:14:16 I hadn't realized this is the continuation of an e
alessandroa 2016/04/21 15:39:21 Acknowledged.
1586 (1 / scale) * plugin_size_in_dip.height( )
wjmaclean 2016/04/14 20:14:16 Why is this wrapping around? Is this line longer t
alessandroa 2016/04/21 15:39:21 Yep .. much longer but solved
1587 -Translate.y() / scale);
1567 texture_layer_->SetUV( 1588 texture_layer_->SetUV(
1568 gfx::PointF(0.0f, 0.0f), 1589 gfx::PointF(top_left.x() / graphics_2d_size_in_dip.width(),
1590 top_left.y() / graphics_2d_size_in_dip.height()),
1569 gfx::PointF( 1591 gfx::PointF(
1570 plugin_size_in_dip.width() / graphics_2d_size_in_dip.width(), 1592 lower_right.x() / graphics_2d_size_in_dip.width(),
1571 plugin_size_in_dip.height() / graphics_2d_size_in_dip.height())); 1593 lower_right.y() / graphics_2d_size_in_dip.height()));
1572 } 1594 }
1573 1595
1574 bool PepperPluginInstanceImpl::PluginHasFocus() const { 1596 bool PepperPluginInstanceImpl::PluginHasFocus() const {
1575 return flash_fullscreen_ || (has_webkit_focus_ && has_content_area_focus_); 1597 return flash_fullscreen_ || (has_webkit_focus_ && has_content_area_focus_);
1576 } 1598 }
1577 1599
1578 void PepperPluginInstanceImpl::SendFocusChangeNotification() { 1600 void PepperPluginInstanceImpl::SendFocusChangeNotification() {
1579 // Keep a reference on the stack. RenderViewImpl::PepperFocusChanged may 1601 // Keep a reference on the stack. RenderViewImpl::PepperFocusChanged may
1580 // remove the <embed> from the DOM, which will make the PepperWebPluginImpl 1602 // remove the <embed> from the DOM, which will make the PepperWebPluginImpl
1581 // drop its reference, usually the last one. This is similar to possible 1603 // drop its reference, usually the last one. This is similar to possible
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after
3324 } 3346 }
3325 3347
3326 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { 3348 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const {
3327 rect->set_x(rect->x() / viewport_to_dip_scale_); 3349 rect->set_x(rect->x() / viewport_to_dip_scale_);
3328 rect->set_y(rect->y() / viewport_to_dip_scale_); 3350 rect->set_y(rect->y() / viewport_to_dip_scale_);
3329 rect->set_width(rect->width() / viewport_to_dip_scale_); 3351 rect->set_width(rect->width() / viewport_to_dip_scale_);
3330 rect->set_height(rect->height() / viewport_to_dip_scale_); 3352 rect->set_height(rect->height() / viewport_to_dip_scale_);
3331 } 3353 }
3332 3354
3333 } // namespace content 3355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698