Chromium Code Reviews| 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_graphics_2d_host.h" | 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 src_bitmap->getAddr32(static_cast<int>(src_rect.fLeft), | 123 src_bitmap->getAddr32(static_cast<int>(src_rect.fLeft), |
| 124 static_cast<int>(src_rect.fTop + y)), | 124 static_cast<int>(src_rect.fTop + y)), |
| 125 src_rect.width()); | 125 src_rect.width()); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 struct PepperGraphics2DHost::QueuedOperation { | 132 struct PepperGraphics2DHost::QueuedOperation { |
| 133 enum Type { PAINT, SCROLL, REPLACE, }; | 133 enum Type { PAINT, SCROLL, REPLACE, TRANSFORM }; |
| 134 | 134 |
| 135 QueuedOperation(Type t) | 135 QueuedOperation(Type t) |
| 136 : type(t), paint_x(0), paint_y(0), scroll_dx(0), scroll_dy(0) {} | 136 : type(t), paint_x(0), paint_y(0), scroll_dx(0), scroll_dy(0) {} |
| 137 | 137 |
| 138 Type type; | 138 Type type; |
| 139 | 139 |
| 140 // Valid when type == PAINT. | 140 // Valid when type == PAINT. |
| 141 scoped_refptr<PPB_ImageData_Impl> paint_image; | 141 scoped_refptr<PPB_ImageData_Impl> paint_image; |
| 142 int paint_x, paint_y; | 142 int paint_x, paint_y; |
| 143 gfx::Rect paint_src_rect; | 143 gfx::Rect paint_src_rect; |
| 144 | 144 |
| 145 // Valid when type == SCROLL. | 145 // Valid when type == SCROLL. |
| 146 gfx::Rect scroll_clip_rect; | 146 gfx::Rect scroll_clip_rect; |
| 147 int scroll_dx, scroll_dy; | 147 int scroll_dx, scroll_dy; |
| 148 | 148 |
| 149 // Valid when type == REPLACE. | 149 // Valid when type == REPLACE. |
| 150 scoped_refptr<PPB_ImageData_Impl> replace_image; | 150 scoped_refptr<PPB_ImageData_Impl> replace_image; |
| 151 | |
| 152 // Valid when type == TRANSFORM | |
| 153 gfx::Transform transform; | |
| 151 }; | 154 }; |
| 152 | 155 |
| 153 // static | 156 // static |
| 154 PepperGraphics2DHost* PepperGraphics2DHost::Create( | 157 PepperGraphics2DHost* PepperGraphics2DHost::Create( |
| 155 RendererPpapiHost* host, | 158 RendererPpapiHost* host, |
| 156 PP_Instance instance, | 159 PP_Instance instance, |
| 157 PP_Resource resource, | 160 PP_Resource resource, |
| 158 const PP_Size& size, | 161 const PP_Size& size, |
| 159 PP_Bool is_always_opaque, | 162 PP_Bool is_always_opaque, |
| 160 scoped_refptr<PPB_ImageData_Impl> backing_store) { | 163 scoped_refptr<PPB_ImageData_Impl> backing_store) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_PaintImageData, | 219 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_PaintImageData, |
| 217 OnHostMsgPaintImageData) | 220 OnHostMsgPaintImageData) |
| 218 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_Scroll, | 221 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_Scroll, |
| 219 OnHostMsgScroll) | 222 OnHostMsgScroll) |
| 220 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReplaceContents, | 223 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReplaceContents, |
| 221 OnHostMsgReplaceContents) | 224 OnHostMsgReplaceContents) |
| 222 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Graphics2D_Flush, | 225 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Graphics2D_Flush, |
| 223 OnHostMsgFlush) | 226 OnHostMsgFlush) |
| 224 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetScale, | 227 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetScale, |
| 225 OnHostMsgSetScale) | 228 OnHostMsgSetScale) |
| 229 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetLayerTransform, | |
| 230 OnHostMsgSetLayerTransform) | |
| 226 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReadImageData, | 231 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReadImageData, |
| 227 OnHostMsgReadImageData) | 232 OnHostMsgReadImageData) |
| 228 PPAPI_END_MESSAGE_MAP() | 233 PPAPI_END_MESSAGE_MAP() |
| 229 return PP_ERROR_FAILED; | 234 return PP_ERROR_FAILED; |
| 230 } | 235 } |
| 231 | 236 |
| 232 bool PepperGraphics2DHost::IsGraphics2DHost() { return true; } | 237 bool PepperGraphics2DHost::IsGraphics2DHost() { return true; } |
| 233 | 238 |
| 234 bool PepperGraphics2DHost::ReadImageData(PP_Resource image, | 239 bool PepperGraphics2DHost::ReadImageData(PP_Resource image, |
| 235 const PP_Point* top_left) { | 240 const PP_Point* top_left) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 int32_t PepperGraphics2DHost::OnHostMsgSetScale( | 522 int32_t PepperGraphics2DHost::OnHostMsgSetScale( |
| 518 ppapi::host::HostMessageContext* context, | 523 ppapi::host::HostMessageContext* context, |
| 519 float scale) { | 524 float scale) { |
| 520 if (scale > 0.0f) { | 525 if (scale > 0.0f) { |
| 521 scale_ = scale; | 526 scale_ = scale; |
| 522 return PP_OK; | 527 return PP_OK; |
| 523 } | 528 } |
| 524 return PP_ERROR_BADARGUMENT; | 529 return PP_ERROR_BADARGUMENT; |
| 525 } | 530 } |
| 526 | 531 |
| 532 int32_t PepperGraphics2DHost::OnHostMsgSetLayerTransform( | |
| 533 ppapi::host::HostMessageContext* context, | |
| 534 float scale, | |
| 535 const PP_Point& origin, | |
| 536 const PP_Point& translation) { | |
| 537 if (scale < 0.0f) | |
| 538 return PP_ERROR_BADARGUMENT; | |
| 539 | |
| 540 gfx::Transform transform_matrix; | |
| 541 //Transform matrix contains the scale and translation applied | |
| 542 //conform the origin point given | |
|
wjmaclean
2016/04/14 20:14:16
Needs a period. I'm not sure I understand what "co
alessandroa
2016/04/21 15:39:21
Done.
alessandroa
2016/04/21 15:39:21
Done.
| |
| 543 transform_matrix.Translate((1 - scale) * origin.x - translation.x, | |
| 544 (1 - scale) * origin.y - translation.y); | |
| 545 transform_matrix.Scale(scale, scale); | |
| 546 | |
| 547 QueuedOperation operation(QueuedOperation::TRANSFORM); | |
| 548 operation.transform = transform_matrix; | |
| 549 queued_operations_.push_back(operation); | |
| 550 return PP_OK; | |
| 551 } | |
| 552 | |
| 553 | |
| 527 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( | 554 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( |
| 528 ppapi::host::HostMessageContext* context, | 555 ppapi::host::HostMessageContext* context, |
| 529 PP_Resource image, | 556 PP_Resource image, |
| 530 const PP_Point& top_left) { | 557 const PP_Point& top_left) { |
| 531 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); | 558 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); |
| 532 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; | 559 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; |
| 533 } | 560 } |
| 534 | 561 |
| 535 void PepperGraphics2DHost::ReleaseCallback( | 562 void PepperGraphics2DHost::ReleaseCallback( |
| 536 std::unique_ptr<cc::SharedBitmap> bitmap, | 563 std::unique_ptr<cc::SharedBitmap> bitmap, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 } | 610 } |
| 584 | 611 |
| 585 void PepperGraphics2DHost::AttachedToNewLayer() { | 612 void PepperGraphics2DHost::AttachedToNewLayer() { |
| 586 texture_mailbox_modified_ = true; | 613 texture_mailbox_modified_ = true; |
| 587 } | 614 } |
| 588 | 615 |
| 589 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { | 616 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
| 590 bool done_replace_contents = false; | 617 bool done_replace_contents = false; |
| 591 bool no_update_visible = true; | 618 bool no_update_visible = true; |
| 592 bool is_plugin_visible = true; | 619 bool is_plugin_visible = true; |
| 620 | |
| 593 for (size_t i = 0; i < queued_operations_.size(); i++) { | 621 for (size_t i = 0; i < queued_operations_.size(); i++) { |
| 594 QueuedOperation& operation = queued_operations_[i]; | 622 QueuedOperation& operation = queued_operations_[i]; |
| 595 gfx::Rect op_rect; | 623 gfx::Rect op_rect; |
| 596 switch (operation.type) { | 624 switch (operation.type) { |
| 625 case QueuedOperation::TRANSFORM: | |
| 626 ExecuteTransform(operation.transform); | |
| 627 no_update_visible = false; | |
| 628 break; | |
| 597 case QueuedOperation::PAINT: | 629 case QueuedOperation::PAINT: |
| 598 ExecutePaintImageData(operation.paint_image.get(), | 630 ExecutePaintImageData(operation.paint_image.get(), |
| 599 operation.paint_x, | 631 operation.paint_x, |
| 600 operation.paint_y, | 632 operation.paint_y, |
| 601 operation.paint_src_rect, | 633 operation.paint_src_rect, |
| 602 &op_rect); | 634 &op_rect); |
| 603 break; | 635 break; |
| 604 case QueuedOperation::SCROLL: | 636 case QueuedOperation::SCROLL: |
| 605 ExecuteScroll(operation.scroll_clip_rect, | 637 ExecuteScroll(operation.scroll_clip_rect, |
| 606 operation.scroll_dx, | 638 operation.scroll_dx, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 } | 704 } |
| 673 | 705 |
| 674 if (bound_instance_ && bound_instance_->throttler() && | 706 if (bound_instance_ && bound_instance_->throttler() && |
| 675 bound_instance_->throttler()->needs_representative_keyframe()) { | 707 bound_instance_->throttler()->needs_representative_keyframe()) { |
| 676 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); | 708 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); |
| 677 } | 709 } |
| 678 | 710 |
| 679 return PP_OK_COMPLETIONPENDING; | 711 return PP_OK_COMPLETIONPENDING; |
| 680 } | 712 } |
| 681 | 713 |
| 714 void PepperGraphics2DHost::ExecuteTransform(gfx::Transform transform) { | |
| 715 bound_instance_->SetLayerTransform(transform); | |
| 716 } | |
| 717 | |
| 682 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, | 718 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, |
| 683 int x, | 719 int x, |
| 684 int y, | 720 int y, |
| 685 const gfx::Rect& src_rect, | 721 const gfx::Rect& src_rect, |
| 686 gfx::Rect* invalidated_rect) { | 722 gfx::Rect* invalidated_rect) { |
| 687 // Ensure the source image is mapped to read from it. | 723 // Ensure the source image is mapped to read from it. |
| 688 ImageDataAutoMapper auto_mapper(image); | 724 ImageDataAutoMapper auto_mapper(image); |
| 689 if (!auto_mapper.is_valid()) | 725 if (!auto_mapper.is_valid()) |
| 690 return; | 726 return; |
| 691 | 727 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 gfx::Point inverse_scaled_point = | 836 gfx::Point inverse_scaled_point = |
| 801 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 837 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
| 802 if (original_delta != inverse_scaled_point) | 838 if (original_delta != inverse_scaled_point) |
| 803 return false; | 839 return false; |
| 804 } | 840 } |
| 805 | 841 |
| 806 return true; | 842 return true; |
| 807 } | 843 } |
| 808 | 844 |
| 809 } // namespace content | 845 } // namespace content |
| OLD | NEW |