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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 SkIRect src_irect = { x, y, | 271 SkIRect src_irect = { x, y, |
272 x + image_resource->width(), | 272 x + image_resource->width(), |
273 y + image_resource->height() }; | 273 y + image_resource->height() }; |
274 SkRect dest_rect = { SkIntToScalar(0), | 274 SkRect dest_rect = { SkIntToScalar(0), |
275 SkIntToScalar(0), | 275 SkIntToScalar(0), |
276 SkIntToScalar(image_resource->width()), | 276 SkIntToScalar(image_resource->width()), |
277 SkIntToScalar(image_resource->height()) }; | 277 SkIntToScalar(image_resource->height()) }; |
278 | 278 |
279 if (image_resource->format() != image_data_->format()) { | 279 if (image_resource->format() != image_data_->format()) { |
280 // Convert the image data if the format does not match. | 280 // Convert the image data if the format does not match. |
281 ConvertImageData(image_data_, src_irect, image_resource, dest_rect); | 281 ConvertImageData(image_data_.get(), src_irect, image_resource, dest_rect); |
282 } else { | 282 } else { |
283 SkCanvas* dest_canvas = image_resource->GetCanvas(); | 283 SkCanvas* dest_canvas = image_resource->GetCanvas(); |
284 | 284 |
285 // We want to replace the contents of the bitmap rather than blend. | 285 // We want to replace the contents of the bitmap rather than blend. |
286 SkPaint paint; | 286 SkPaint paint; |
287 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 287 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
288 dest_canvas->drawBitmapRect(*image_data_->GetMappedBitmap(), | 288 dest_canvas->drawBitmapRect(*image_data_->GetMappedBitmap(), |
289 &src_irect, dest_rect, &paint); | 289 &src_irect, dest_rect, &paint); |
290 } | 290 } |
291 return true; | 291 return true; |
(...skipping 23 matching lines...) Expand all Loading... |
315 return true; | 315 return true; |
316 } | 316 } |
317 | 317 |
318 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting | 318 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting |
319 // outside the plugin area. This can happen if the plugin has been resized since | 319 // outside the plugin area. This can happen if the plugin has been resized since |
320 // PaintImageData verified the image is within the plugin size. | 320 // PaintImageData verified the image is within the plugin size. |
321 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas, | 321 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas, |
322 const gfx::Rect& plugin_rect, | 322 const gfx::Rect& plugin_rect, |
323 const gfx::Rect& paint_rect) { | 323 const gfx::Rect& paint_rect) { |
324 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); | 324 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); |
325 ImageDataAutoMapper auto_mapper(image_data_); | 325 ImageDataAutoMapper auto_mapper(image_data_.get()); |
326 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); | 326 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); |
327 | 327 |
328 gfx::Rect invalidate_rect = plugin_rect; | 328 gfx::Rect invalidate_rect = plugin_rect; |
329 invalidate_rect.Intersect(paint_rect); | 329 invalidate_rect.Intersect(paint_rect); |
330 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); | 330 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); |
331 SkAutoCanvasRestore auto_restore(canvas, true); | 331 SkAutoCanvasRestore auto_restore(canvas, true); |
332 canvas->clipRect(sk_invalidate_rect); | 332 canvas->clipRect(sk_invalidate_rect); |
333 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); | 333 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); |
334 gfx::Size image_size = gfx::ToFlooredSize( | 334 gfx::Size image_size = gfx::ToFlooredSize( |
335 gfx::ScaleSize(pixel_image_size, scale_)); | 335 gfx::ScaleSize(pixel_image_size, scale_)); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { | 557 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
558 bool done_replace_contents = false; | 558 bool done_replace_contents = false; |
559 bool no_update_visible = true; | 559 bool no_update_visible = true; |
560 bool is_plugin_visible = true; | 560 bool is_plugin_visible = true; |
561 for (size_t i = 0; i < queued_operations_.size(); i++) { | 561 for (size_t i = 0; i < queued_operations_.size(); i++) { |
562 QueuedOperation& operation = queued_operations_[i]; | 562 QueuedOperation& operation = queued_operations_[i]; |
563 gfx::Rect op_rect; | 563 gfx::Rect op_rect; |
564 switch (operation.type) { | 564 switch (operation.type) { |
565 case QueuedOperation::PAINT: | 565 case QueuedOperation::PAINT: |
566 ExecutePaintImageData(operation.paint_image, | 566 ExecutePaintImageData(operation.paint_image.get(), |
567 operation.paint_x, operation.paint_y, | 567 operation.paint_x, |
| 568 operation.paint_y, |
568 operation.paint_src_rect, | 569 operation.paint_src_rect, |
569 &op_rect); | 570 &op_rect); |
570 break; | 571 break; |
571 case QueuedOperation::SCROLL: | 572 case QueuedOperation::SCROLL: |
572 ExecuteScroll(operation.scroll_clip_rect, | 573 ExecuteScroll(operation.scroll_clip_rect, |
573 operation.scroll_dx, operation.scroll_dy, | 574 operation.scroll_dx, operation.scroll_dy, |
574 &op_rect); | 575 &op_rect); |
575 break; | 576 break; |
576 case QueuedOperation::REPLACE: | 577 case QueuedOperation::REPLACE: |
577 // Since the out parameter |old_image_data| takes ownership of the | 578 // Since the out parameter |old_image_data| takes ownership of the |
578 // reference, if there are more than one ReplaceContents calls queued | 579 // reference, if there are more than one ReplaceContents calls queued |
579 // the first |old_image_data| will get overwritten and leaked. So we | 580 // the first |old_image_data| will get overwritten and leaked. So we |
580 // only supply this for the first call. | 581 // only supply this for the first call. |
581 ExecuteReplaceContents(operation.replace_image, &op_rect, | 582 ExecuteReplaceContents(operation.replace_image.get(), |
| 583 &op_rect, |
582 done_replace_contents ? NULL : old_image_data); | 584 done_replace_contents ? NULL : old_image_data); |
583 done_replace_contents = true; | 585 done_replace_contents = true; |
584 break; | 586 break; |
585 } | 587 } |
586 | 588 |
587 // For correctness with accelerated compositing, we must issue an invalidate | 589 // For correctness with accelerated compositing, we must issue an invalidate |
588 // on the full op_rect even if it is partially or completely off-screen. | 590 // on the full op_rect even if it is partially or completely off-screen. |
589 // However, if we issue an invalidate for a clipped-out region, WebKit will | 591 // However, if we issue an invalidate for a clipped-out region, WebKit will |
590 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint | 592 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint |
591 // calls, leaving our callback stranded. So we still need to check whether | 593 // calls, leaving our callback stranded. So we still need to check whether |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 // Location within the backing store to copy to. | 655 // Location within the backing store to copy to. |
654 *invalidated_rect = src_rect; | 656 *invalidated_rect = src_rect; |
655 invalidated_rect->Offset(x, y); | 657 invalidated_rect->Offset(x, y); |
656 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), | 658 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), |
657 SkIntToScalar(invalidated_rect->y()), | 659 SkIntToScalar(invalidated_rect->y()), |
658 SkIntToScalar(invalidated_rect->right()), | 660 SkIntToScalar(invalidated_rect->right()), |
659 SkIntToScalar(invalidated_rect->bottom()) }; | 661 SkIntToScalar(invalidated_rect->bottom()) }; |
660 | 662 |
661 if (image->format() != image_data_->format()) { | 663 if (image->format() != image_data_->format()) { |
662 // Convert the image data if the format does not match. | 664 // Convert the image data if the format does not match. |
663 ConvertImageData(image, src_irect, image_data_, dest_rect); | 665 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
664 } else { | 666 } else { |
665 // We're guaranteed to have a mapped canvas since we mapped it in Init(). | 667 // We're guaranteed to have a mapped canvas since we mapped it in Init(). |
666 SkCanvas* backing_canvas = image_data_->GetCanvas(); | 668 SkCanvas* backing_canvas = image_data_->GetCanvas(); |
667 | 669 |
668 // We want to replace the contents of the bitmap rather than blend. | 670 // We want to replace the contents of the bitmap rather than blend. |
669 SkPaint paint; | 671 SkPaint paint; |
670 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 672 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
671 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), | 673 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), |
672 &src_irect, dest_rect, &paint); | 674 &src_irect, dest_rect, &paint); |
673 } | 675 } |
(...skipping 12 matching lines...) Expand all Loading... |
686 PP_Resource* old_image_data) { | 688 PP_Resource* old_image_data) { |
687 if (image->format() != image_data_->format()) { | 689 if (image->format() != image_data_->format()) { |
688 DCHECK(image->width() == image_data_->width() && | 690 DCHECK(image->width() == image_data_->width() && |
689 image->height() == image_data_->height()); | 691 image->height() == image_data_->height()); |
690 // Convert the image data if the format does not match. | 692 // Convert the image data if the format does not match. |
691 SkIRect src_irect = { 0, 0, image->width(), image->height() }; | 693 SkIRect src_irect = { 0, 0, image->width(), image->height() }; |
692 SkRect dest_rect = { SkIntToScalar(0), | 694 SkRect dest_rect = { SkIntToScalar(0), |
693 SkIntToScalar(0), | 695 SkIntToScalar(0), |
694 SkIntToScalar(image_data_->width()), | 696 SkIntToScalar(image_data_->width()), |
695 SkIntToScalar(image_data_->height()) }; | 697 SkIntToScalar(image_data_->height()) }; |
696 ConvertImageData(image, src_irect, image_data_, dest_rect); | 698 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
697 } else { | 699 } else { |
698 // The passed-in image may not be mapped in our process, and we need to | 700 // The passed-in image may not be mapped in our process, and we need to |
699 // guarantee that the current backing store is always mapped. | 701 // guarantee that the current backing store is always mapped. |
700 if (!image->Map()) | 702 if (!image->Map()) |
701 return; | 703 return; |
702 | 704 |
703 if (old_image_data) | 705 if (old_image_data) |
704 *old_image_data = image_data_->GetReference(); | 706 *old_image_data = image_data_->GetReference(); |
705 image_data_ = image; | 707 image_data_ = image; |
706 } | 708 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 gfx::Point inverse_scaled_point = | 762 gfx::Point inverse_scaled_point = |
761 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); | 763 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); |
762 if (original_delta != inverse_scaled_point) | 764 if (original_delta != inverse_scaled_point) |
763 return false; | 765 return false; |
764 } | 766 } |
765 | 767 |
766 return true; | 768 return true; |
767 } | 769 } |
768 | 770 |
769 } // namespace content | 771 } // namespace content |
OLD | NEW |