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 float scale; |
| 154 gfx::PointF translation; |
151 }; | 155 }; |
152 | 156 |
153 // static | 157 // static |
154 PepperGraphics2DHost* PepperGraphics2DHost::Create( | 158 PepperGraphics2DHost* PepperGraphics2DHost::Create( |
155 RendererPpapiHost* host, | 159 RendererPpapiHost* host, |
156 PP_Instance instance, | 160 PP_Instance instance, |
157 PP_Resource resource, | 161 PP_Resource resource, |
158 const PP_Size& size, | 162 const PP_Size& size, |
159 PP_Bool is_always_opaque, | 163 PP_Bool is_always_opaque, |
160 scoped_refptr<PPB_ImageData_Impl> backing_store) { | 164 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, | 220 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_PaintImageData, |
217 OnHostMsgPaintImageData) | 221 OnHostMsgPaintImageData) |
218 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_Scroll, | 222 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_Scroll, |
219 OnHostMsgScroll) | 223 OnHostMsgScroll) |
220 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReplaceContents, | 224 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReplaceContents, |
221 OnHostMsgReplaceContents) | 225 OnHostMsgReplaceContents) |
222 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Graphics2D_Flush, | 226 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Graphics2D_Flush, |
223 OnHostMsgFlush) | 227 OnHostMsgFlush) |
224 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetScale, | 228 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetScale, |
225 OnHostMsgSetScale) | 229 OnHostMsgSetScale) |
| 230 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_SetLayerTransform, |
| 231 OnHostMsgSetLayerTransform) |
226 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReadImageData, | 232 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Graphics2D_ReadImageData, |
227 OnHostMsgReadImageData) | 233 OnHostMsgReadImageData) |
228 PPAPI_END_MESSAGE_MAP() | 234 PPAPI_END_MESSAGE_MAP() |
229 return PP_ERROR_FAILED; | 235 return PP_ERROR_FAILED; |
230 } | 236 } |
231 | 237 |
232 bool PepperGraphics2DHost::IsGraphics2DHost() { return true; } | 238 bool PepperGraphics2DHost::IsGraphics2DHost() { return true; } |
233 | 239 |
234 bool PepperGraphics2DHost::ReadImageData(PP_Resource image, | 240 bool PepperGraphics2DHost::ReadImageData(PP_Resource image, |
235 const PP_Point* top_left) { | 241 const PP_Point* top_left) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 int32_t PepperGraphics2DHost::OnHostMsgSetScale( | 523 int32_t PepperGraphics2DHost::OnHostMsgSetScale( |
518 ppapi::host::HostMessageContext* context, | 524 ppapi::host::HostMessageContext* context, |
519 float scale) { | 525 float scale) { |
520 if (scale > 0.0f) { | 526 if (scale > 0.0f) { |
521 scale_ = scale; | 527 scale_ = scale; |
522 return PP_OK; | 528 return PP_OK; |
523 } | 529 } |
524 return PP_ERROR_BADARGUMENT; | 530 return PP_ERROR_BADARGUMENT; |
525 } | 531 } |
526 | 532 |
| 533 int32_t PepperGraphics2DHost::OnHostMsgSetLayerTransform( |
| 534 ppapi::host::HostMessageContext* context, |
| 535 float scale, |
| 536 const PP_FloatPoint& translation) { |
| 537 if (scale < 0.0f) |
| 538 return PP_ERROR_BADARGUMENT; |
| 539 |
| 540 QueuedOperation operation(QueuedOperation::TRANSFORM); |
| 541 operation.scale = scale; |
| 542 operation.translation = gfx::PointF(translation.x, translation.y); |
| 543 queued_operations_.push_back(operation); |
| 544 return PP_OK; |
| 545 } |
| 546 |
| 547 |
527 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( | 548 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( |
528 ppapi::host::HostMessageContext* context, | 549 ppapi::host::HostMessageContext* context, |
529 PP_Resource image, | 550 PP_Resource image, |
530 const PP_Point& top_left) { | 551 const PP_Point& top_left) { |
531 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); | 552 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); |
532 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; | 553 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; |
533 } | 554 } |
534 | 555 |
535 void PepperGraphics2DHost::ReleaseCallback( | 556 void PepperGraphics2DHost::ReleaseCallback( |
536 std::unique_ptr<cc::SharedBitmap> bitmap, | 557 std::unique_ptr<cc::SharedBitmap> bitmap, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 604 } |
584 | 605 |
585 void PepperGraphics2DHost::AttachedToNewLayer() { | 606 void PepperGraphics2DHost::AttachedToNewLayer() { |
586 texture_mailbox_modified_ = true; | 607 texture_mailbox_modified_ = true; |
587 } | 608 } |
588 | 609 |
589 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { | 610 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
590 bool done_replace_contents = false; | 611 bool done_replace_contents = false; |
591 bool no_update_visible = true; | 612 bool no_update_visible = true; |
592 bool is_plugin_visible = true; | 613 bool is_plugin_visible = true; |
| 614 |
593 for (size_t i = 0; i < queued_operations_.size(); i++) { | 615 for (size_t i = 0; i < queued_operations_.size(); i++) { |
594 QueuedOperation& operation = queued_operations_[i]; | 616 QueuedOperation& operation = queued_operations_[i]; |
595 gfx::Rect op_rect; | 617 gfx::Rect op_rect; |
596 switch (operation.type) { | 618 switch (operation.type) { |
| 619 case QueuedOperation::TRANSFORM: |
| 620 ExecuteTransform(operation.scale, operation.translation); |
| 621 no_update_visible = false; |
| 622 break; |
597 case QueuedOperation::PAINT: | 623 case QueuedOperation::PAINT: |
598 ExecutePaintImageData(operation.paint_image.get(), | 624 ExecutePaintImageData(operation.paint_image.get(), |
599 operation.paint_x, | 625 operation.paint_x, |
600 operation.paint_y, | 626 operation.paint_y, |
601 operation.paint_src_rect, | 627 operation.paint_src_rect, |
602 &op_rect); | 628 &op_rect); |
603 break; | 629 break; |
604 case QueuedOperation::SCROLL: | 630 case QueuedOperation::SCROLL: |
605 ExecuteScroll(operation.scroll_clip_rect, | 631 ExecuteScroll(operation.scroll_clip_rect, |
606 operation.scroll_dx, | 632 operation.scroll_dx, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 } | 698 } |
673 | 699 |
674 if (bound_instance_ && bound_instance_->throttler() && | 700 if (bound_instance_ && bound_instance_->throttler() && |
675 bound_instance_->throttler()->needs_representative_keyframe()) { | 701 bound_instance_->throttler()->needs_representative_keyframe()) { |
676 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); | 702 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); |
677 } | 703 } |
678 | 704 |
679 return PP_OK_COMPLETIONPENDING; | 705 return PP_OK_COMPLETIONPENDING; |
680 } | 706 } |
681 | 707 |
| 708 void PepperGraphics2DHost::ExecuteTransform(const float& scale, |
| 709 const gfx::PointF& translate) { |
| 710 bound_instance_->SetGraphics2DTransform(scale, translate); |
| 711 } |
| 712 |
682 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, | 713 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, |
683 int x, | 714 int x, |
684 int y, | 715 int y, |
685 const gfx::Rect& src_rect, | 716 const gfx::Rect& src_rect, |
686 gfx::Rect* invalidated_rect) { | 717 gfx::Rect* invalidated_rect) { |
687 // Ensure the source image is mapped to read from it. | 718 // Ensure the source image is mapped to read from it. |
688 ImageDataAutoMapper auto_mapper(image); | 719 ImageDataAutoMapper auto_mapper(image); |
689 if (!auto_mapper.is_valid()) | 720 if (!auto_mapper.is_valid()) |
690 return; | 721 return; |
691 | 722 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 gfx::Point inverse_scaled_point = | 831 gfx::Point inverse_scaled_point = |
801 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 832 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
802 if (original_delta != inverse_scaled_point) | 833 if (original_delta != inverse_scaled_point) |
803 return false; | 834 return false; |
804 } | 835 } |
805 | 836 |
806 return true; | 837 return true; |
807 } | 838 } |
808 | 839 |
809 } // namespace content | 840 } // namespace content |
OLD | NEW |