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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 QueuedOperation operation(QueuedOperation::REPLACE); | 489 QueuedOperation operation(QueuedOperation::REPLACE); |
485 operation.replace_image = image_resource; | 490 operation.replace_image = image_resource; |
486 queued_operations_.push_back(operation); | 491 queued_operations_.push_back(operation); |
487 return PP_OK; | 492 return PP_OK; |
488 } | 493 } |
489 | 494 |
490 int32_t PepperGraphics2DHost::OnHostMsgFlush( | 495 int32_t PepperGraphics2DHost::OnHostMsgFlush( |
491 ppapi::host::HostMessageContext* context) { | 496 ppapi::host::HostMessageContext* context) { |
492 // Don't allow more than one pending flush at a time. | 497 // Don't allow more than one pending flush at a time. |
493 if (HasPendingFlush()) | 498 if (HasPendingFlush()) |
494 return PP_ERROR_INPROGRESS; | 499 return PP_ERROR_INPROGRESS; |
wjmaclean
2016/04/13 14:47:18
Please restore the blank line below.
alessandroa
2016/04/21 15:39:20
Done.
| |
495 | |
496 PP_Resource old_image_data = 0; | 500 PP_Resource old_image_data = 0; |
497 flush_reply_context_ = context->MakeReplyMessageContext(); | 501 flush_reply_context_ = context->MakeReplyMessageContext(); |
498 if (is_running_in_process_) | 502 if (is_running_in_process_) |
499 return Flush(NULL); | 503 return Flush(NULL); |
500 | 504 |
501 // Reuse image data when running out of process. | |
wjmaclean
2016/04/13 14:47:18
Why are you deleting this comment? Doesn't it appl
alessandroa
2016/04/21 15:39:20
It was a stupid mistake :) solved. I thought it wa
| |
502 int32_t result = Flush(&old_image_data); | 505 int32_t result = Flush(&old_image_data); |
503 | 506 |
504 if (old_image_data) { | 507 if (old_image_data) { |
505 // If the Graphics2D has an old image data it's not using any more, send | 508 // If the Graphics2D has an old image data it's not using any more, send |
506 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc | 509 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc |
507 // for a description how this process works. | 510 // for a description how this process works. |
508 ppapi::HostResource old_image_data_host_resource; | 511 ppapi::HostResource old_image_data_host_resource; |
509 old_image_data_host_resource.SetHostResource(pp_instance(), old_image_data); | 512 old_image_data_host_resource.SetHostResource(pp_instance(), old_image_data); |
510 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData( | 513 host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData( |
511 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource)); | 514 ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource)); |
512 } | 515 } |
513 | 516 |
514 return result; | 517 return result; |
515 } | 518 } |
516 | 519 |
517 int32_t PepperGraphics2DHost::OnHostMsgSetScale( | 520 int32_t PepperGraphics2DHost::OnHostMsgSetScale( |
518 ppapi::host::HostMessageContext* context, | 521 ppapi::host::HostMessageContext* context, |
519 float scale) { | 522 float scale) { |
520 if (scale > 0.0f) { | 523 if (scale > 0.0f) { |
521 scale_ = scale; | 524 scale_ = scale; |
522 return PP_OK; | 525 return PP_OK; |
523 } | 526 } |
524 return PP_ERROR_BADARGUMENT; | 527 return PP_ERROR_BADARGUMENT; |
525 } | 528 } |
526 | 529 |
530 int32_t PepperGraphics2DHost::OnHostMsgSetLayerTransform( | |
531 ppapi::host::HostMessageContext* context, | |
wjmaclean
2016/04/13 14:47:18
indenting looks wrong here ... the arguments shoul
alessandroa
2016/04/21 15:39:20
Done.
| |
532 float scale, | |
533 const PP_Point& origin, | |
534 const PP_Point& transform) { | |
wjmaclean
2016/04/13 14:47:18
'transform' seems like the wrong name here ... is
alessandroa
2016/04/21 15:39:20
Done.
alessandroa
2016/04/21 15:39:20
Done.
| |
535 TRACE_EVENT0("pepper", "PepperGraphics2DHost::OnHostMsgSetLayerTransform"); | |
536 | |
537 float S = scale; | |
538 gfx::Point P(origin.x, origin.y); | |
wjmaclean
2016/04/13 14:47:18
Call this 'origin' instead of 'P'
alessandroa
2016/04/21 15:39:20
Done.
| |
539 gfx::Point T(transform.x, transform.y); | |
wjmaclean
2016/04/13 14:47:18
Call this 'translation' instead of 'T'.
alessandroa
2016/04/21 15:39:20
Done.
| |
540 gfx::Transform transform_matrix; | |
541 | |
542 transform_matrix.Translate(SkFloatToScalar((1 - S) * P.x() - T.x()), | |
wjmaclean
2016/04/13 14:47:18
Perhaps add a comment explaining in words what the
alessandroa
2016/04/21 15:39:20
Done. I simplified all this part :) You will see i
| |
543 SkFloatToScalar((1 - S) * P.y() - T.y())); | |
wjmaclean
2016/04/13 14:47:18
this indentation is wrong
| |
544 transform_matrix.Scale(S, S); | |
545 | |
546 QueuedOperation operation(QueuedOperation::TRANSFORM); | |
547 operation.transform = transform_matrix; | |
548 queued_operations_.push_back(operation); | |
549 return PP_OK; | |
550 } | |
551 | |
552 | |
527 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( | 553 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( |
528 ppapi::host::HostMessageContext* context, | 554 ppapi::host::HostMessageContext* context, |
529 PP_Resource image, | 555 PP_Resource image, |
530 const PP_Point& top_left) { | 556 const PP_Point& top_left) { |
531 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); | 557 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); |
532 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; | 558 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; |
533 } | 559 } |
534 | 560 |
535 void PepperGraphics2DHost::ReleaseCallback( | 561 void PepperGraphics2DHost::ReleaseCallback( |
536 std::unique_ptr<cc::SharedBitmap> bitmap, | 562 std::unique_ptr<cc::SharedBitmap> bitmap, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 } | 609 } |
584 | 610 |
585 void PepperGraphics2DHost::AttachedToNewLayer() { | 611 void PepperGraphics2DHost::AttachedToNewLayer() { |
586 texture_mailbox_modified_ = true; | 612 texture_mailbox_modified_ = true; |
587 } | 613 } |
588 | 614 |
589 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { | 615 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
590 bool done_replace_contents = false; | 616 bool done_replace_contents = false; |
591 bool no_update_visible = true; | 617 bool no_update_visible = true; |
592 bool is_plugin_visible = true; | 618 bool is_plugin_visible = true; |
619 | |
593 for (size_t i = 0; i < queued_operations_.size(); i++) { | 620 for (size_t i = 0; i < queued_operations_.size(); i++) { |
594 QueuedOperation& operation = queued_operations_[i]; | 621 QueuedOperation& operation = queued_operations_[i]; |
595 gfx::Rect op_rect; | 622 gfx::Rect op_rect; |
596 switch (operation.type) { | 623 switch (operation.type) { |
624 case QueuedOperation::TRANSFORM: | |
625 ExecuteTransform(operation.transform); | |
626 no_update_visible = false; | |
627 break; | |
597 case QueuedOperation::PAINT: | 628 case QueuedOperation::PAINT: |
598 ExecutePaintImageData(operation.paint_image.get(), | 629 ExecutePaintImageData(operation.paint_image.get(), |
599 operation.paint_x, | 630 operation.paint_x, |
600 operation.paint_y, | 631 operation.paint_y, |
601 operation.paint_src_rect, | 632 operation.paint_src_rect, |
602 &op_rect); | 633 &op_rect); |
603 break; | 634 break; |
604 case QueuedOperation::SCROLL: | 635 case QueuedOperation::SCROLL: |
605 ExecuteScroll(operation.scroll_clip_rect, | 636 ExecuteScroll(operation.scroll_clip_rect, |
606 operation.scroll_dx, | 637 operation.scroll_dx, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 } | 703 } |
673 | 704 |
674 if (bound_instance_ && bound_instance_->throttler() && | 705 if (bound_instance_ && bound_instance_->throttler() && |
675 bound_instance_->throttler()->needs_representative_keyframe()) { | 706 bound_instance_->throttler()->needs_representative_keyframe()) { |
676 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); | 707 bound_instance_->throttler()->OnImageFlush(image_data_->GetMappedBitmap()); |
677 } | 708 } |
678 | 709 |
679 return PP_OK_COMPLETIONPENDING; | 710 return PP_OK_COMPLETIONPENDING; |
680 } | 711 } |
681 | 712 |
713 void PepperGraphics2DHost::ExecuteTransform(gfx::Transform transform) { | |
714 bound_instance_->SetLayerTransform(transform); | |
715 } | |
716 | |
682 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, | 717 void PepperGraphics2DHost::ExecutePaintImageData(PPB_ImageData_Impl* image, |
683 int x, | 718 int x, |
684 int y, | 719 int y, |
685 const gfx::Rect& src_rect, | 720 const gfx::Rect& src_rect, |
686 gfx::Rect* invalidated_rect) { | 721 gfx::Rect* invalidated_rect) { |
687 // Ensure the source image is mapped to read from it. | 722 // Ensure the source image is mapped to read from it. |
688 ImageDataAutoMapper auto_mapper(image); | 723 ImageDataAutoMapper auto_mapper(image); |
689 if (!auto_mapper.is_valid()) | 724 if (!auto_mapper.is_valid()) |
690 return; | 725 return; |
691 | 726 |
692 // Portion within the source image to cut out. | 727 // Portion within the source image to cut out. |
693 SkIRect src_irect = {src_rect.x(), src_rect.y(), src_rect.right(), | 728 SkIRect src_irect = {src_rect.x(), src_rect.y(), src_rect.right(), |
694 src_rect.bottom()}; | 729 src_rect.bottom()}; |
695 | 730 |
696 // Location within the backing store to copy to. | 731 // Location within the backing store to copy to. |
697 *invalidated_rect = src_rect; | 732 *invalidated_rect = src_rect; |
698 invalidated_rect->Offset(x, y); | 733 invalidated_rect->Offset(x, y); |
699 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()), | 734 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()), |
700 SkIntToScalar(invalidated_rect->y()), | 735 SkIntToScalar(invalidated_rect->y()), |
701 SkIntToScalar(invalidated_rect->right()), | 736 SkIntToScalar(invalidated_rect->right()), |
702 SkIntToScalar(invalidated_rect->bottom())}; | 737 SkIntToScalar(invalidated_rect->bottom())}; |
703 | 738 |
704 if (image->format() != image_data_->format()) { | 739 if (image->format() != image_data_->format()) { |
705 // Convert the image data if the format does not match. | 740 // Convert the image data if the format does not match. |
706 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); | 741 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
707 } else { | 742 } else { |
708 // We're guaranteed to have a mapped canvas since we mapped it in Init(). | 743 // We're guaranteed to have a mapped canvas since we mapped it in Init(). |
709 SkCanvas* backing_canvas = image_data_->GetCanvas(); | 744 SkCanvas* backing_canvas = image_data_->GetCanvas(); |
710 | |
wjmaclean
2016/04/13 14:47:18
please restore this blank line.
alessandroa
2016/04/21 15:39:20
Done.
| |
711 // We want to replace the contents of the bitmap rather than blend. | 745 // We want to replace the contents of the bitmap rather than blend. |
712 SkPaint paint; | 746 SkPaint paint; |
713 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 747 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
714 backing_canvas->drawBitmapRect( | 748 backing_canvas->drawBitmapRect( |
715 *image->GetMappedBitmap(), src_irect, dest_rect, &paint); | 749 *image->GetMappedBitmap(), src_irect, dest_rect, &paint); |
716 } | 750 } |
717 } | 751 } |
718 | 752 |
719 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip, | 753 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip, |
720 int dx, | 754 int dx, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 gfx::Point inverse_scaled_point = | 834 gfx::Point inverse_scaled_point = |
801 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 835 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
802 if (original_delta != inverse_scaled_point) | 836 if (original_delta != inverse_scaled_point) |
803 return false; | 837 return false; |
804 } | 838 } |
805 | 839 |
806 return true; | 840 return true; |
807 } | 841 } |
808 | 842 |
809 } // namespace content | 843 } // namespace content |
OLD | NEW |