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 "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 &scroll_delta : NULL)) { | 369 &scroll_delta : NULL)) { |
370 // Conversion requires falling back to InvalidateRect. | 370 // Conversion requires falling back to InvalidateRect. |
371 operation.type = QueuedOperation::PAINT; | 371 operation.type = QueuedOperation::PAINT; |
372 } | 372 } |
373 | 373 |
374 gfx::Rect clip = PP_ToGfxRect(bound_instance_->view_data().clip_rect); | 374 gfx::Rect clip = PP_ToGfxRect(bound_instance_->view_data().clip_rect); |
375 is_plugin_visible = !clip.IsEmpty(); | 375 is_plugin_visible = !clip.IsEmpty(); |
376 | 376 |
377 // Set |no_update_visible| to false if the change overlaps the visible | 377 // Set |no_update_visible| to false if the change overlaps the visible |
378 // area. | 378 // area. |
379 gfx::Rect visible_changed_rect = clip; | 379 gfx::Rect visible_changed_rect = gfx::IntersectRects(clip, op_rect); |
380 visible_changed_rect.Intersect(op_rect); | |
381 if (!visible_changed_rect.IsEmpty()) | 380 if (!visible_changed_rect.IsEmpty()) |
382 no_update_visible = false; | 381 no_update_visible = false; |
383 | 382 |
384 // Notify the plugin of the entire change (op_rect), even if it is | 383 // Notify the plugin of the entire change (op_rect), even if it is |
385 // partially or completely off-screen. | 384 // partially or completely off-screen. |
386 if (operation.type == QueuedOperation::SCROLL) { | 385 if (operation.type == QueuedOperation::SCROLL) { |
387 bound_instance_->ScrollRect(scroll_delta.x(), scroll_delta.y(), | 386 bound_instance_->ScrollRect(scroll_delta.x(), scroll_delta.y(), |
388 op_rect); | 387 op_rect); |
389 } else { | 388 } else { |
390 bound_instance_->InvalidateRect(op_rect); | 389 bound_instance_->InvalidateRect(op_rect); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 | 553 |
555 // TODO(jhorwich) Figure out if this code is even active anymore, and if so | 554 // TODO(jhorwich) Figure out if this code is even active anymore, and if so |
556 // how to properly handle scaling. | 555 // how to properly handle scaling. |
557 DCHECK_EQ(1.0f, scale_); | 556 DCHECK_EQ(1.0f, scale_); |
558 | 557 |
559 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG | 558 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG |
560 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. | 559 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. |
561 | 560 |
562 CGContextDrawImage(canvas, bitmap_rect, image); | 561 CGContextDrawImage(canvas, bitmap_rect, image); |
563 #else | 562 #else |
564 gfx::Rect invalidate_rect = plugin_rect; | 563 gfx::Rect invalidate_rect = gfx::IntersectRects(plugin_rect, paint_rect); |
565 invalidate_rect.Intersect(paint_rect); | |
566 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); | 564 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); |
567 SkAutoCanvasRestore auto_restore(canvas, true); | 565 SkAutoCanvasRestore auto_restore(canvas, true); |
568 canvas->clipRect(sk_invalidate_rect); | 566 canvas->clipRect(sk_invalidate_rect); |
569 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); | 567 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); |
570 gfx::Size image_size = gfx::ToFlooredSize(pixel_image_size.Scale(scale_)); | 568 gfx::Size image_size = gfx::ToFlooredSize(pixel_image_size.Scale(scale_)); |
571 | 569 |
572 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 570 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
573 if (!plugin_instance) | 571 if (!plugin_instance) |
574 return; | 572 return; |
575 if (plugin_instance->IsFullPagePlugin()) { | 573 if (plugin_instance->IsFullPagePlugin()) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale, | 640 bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale, |
643 gfx::Rect* op_rect, | 641 gfx::Rect* op_rect, |
644 gfx::Point* delta) { | 642 gfx::Point* delta) { |
645 if (scale == 1.0f || scale <= 0.0f) | 643 if (scale == 1.0f || scale <= 0.0f) |
646 return true; | 644 return true; |
647 | 645 |
648 gfx::Rect original_rect = *op_rect; | 646 gfx::Rect original_rect = *op_rect; |
649 // Take the enclosing rectangle after scaling so a rectangle scaled down then | 647 // Take the enclosing rectangle after scaling so a rectangle scaled down then |
650 // scaled back up by the inverse scale would fully contain the entire area | 648 // scaled back up by the inverse scale would fully contain the entire area |
651 // affected by the original rectangle. | 649 // affected by the original rectangle. |
652 gfx::RectF scaled_rect = *op_rect; | 650 *op_rect = gfx::ToEnclosingRect(gfx::ScaleRect(*op_rect, scale)); |
653 scaled_rect.Scale(scale); | |
654 *op_rect = gfx::ToEnclosingRect(scaled_rect); | |
655 if (delta) { | 651 if (delta) { |
656 gfx::Point original_delta = *delta; | 652 gfx::Point original_delta = *delta; |
657 float inverse_scale = 1.0f / scale; | 653 float inverse_scale = 1.0f / scale; |
658 *delta = gfx::ToFlooredPoint(delta->Scale(scale)); | 654 *delta = gfx::ToFlooredPoint(delta->Scale(scale)); |
659 | 655 |
660 gfx::RectF inverse_scaled_rect = *op_rect; | 656 gfx::Rect inverse_scaled_rect = |
661 inverse_scaled_rect.Scale(inverse_scale); | 657 gfx::ToEnclosingRect(gfx::ScaleRect(*op_rect, inverse_scale)); |
662 if (original_rect != gfx::ToEnclosingRect(inverse_scaled_rect) || | 658 if (original_rect != inverse_scaled_rect) |
663 original_delta != gfx::ToFlooredPoint(delta->Scale(inverse_scale))) { | |
664 return false; | 659 return false; |
665 } | 660 gfx::Point inverse_scaled_point = |
| 661 gfx::ToFlooredPoint(delta->Scale(inverse_scale)); |
| 662 if (original_delta != inverse_scaled_point) |
| 663 return false; |
666 } | 664 } |
667 | 665 |
668 return true; | 666 return true; |
669 } | 667 } |
670 | 668 |
671 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, | 669 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, |
672 int x, int y, | 670 int x, int y, |
673 const gfx::Rect& src_rect, | 671 const gfx::Rect& src_rect, |
674 gfx::Rect* invalidated_rect) { | 672 gfx::Rect* invalidated_rect) { |
675 // Ensure the source image is mapped to read from it. | 673 // Ensure the source image is mapped to read from it. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 } | 760 } |
763 | 761 |
764 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 762 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
765 return !unpainted_flush_callback_.is_null() || | 763 return !unpainted_flush_callback_.is_null() || |
766 !painted_flush_callback_.is_null() || | 764 !painted_flush_callback_.is_null() || |
767 offscreen_flush_pending_; | 765 offscreen_flush_pending_; |
768 } | 766 } |
769 | 767 |
770 } // namespace ppapi | 768 } // namespace ppapi |
771 } // namespace webkit | 769 } // namespace webkit |
OLD | NEW |