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 "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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 break; | 343 break; |
| 344 } | 344 } |
| 345 | 345 |
| 346 // For correctness with accelerated compositing, we must issue an invalidate | 346 // For correctness with accelerated compositing, we must issue an invalidate |
| 347 // on the full op_rect even if it is partially or completely off-screen. | 347 // on the full op_rect even if it is partially or completely off-screen. |
| 348 // However, if we issue an invalidate for a clipped-out region, WebKit will | 348 // However, if we issue an invalidate for a clipped-out region, WebKit will |
| 349 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint | 349 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint |
| 350 // calls, leaving our callback stranded. So we still need to check whether | 350 // calls, leaving our callback stranded. So we still need to check whether |
| 351 // the repainted area is visible to determine how to deal with the callback. | 351 // the repainted area is visible to determine how to deal with the callback. |
| 352 if (bound_instance_ && !op_rect.IsEmpty()) { | 352 if (bound_instance_ && !op_rect.IsEmpty()) { |
| 353 // Convert op_rect from context coordinates to logical pixels, taking care | |
| 354 // to include partially-covered logical pixels (aka DIPs). If the | |
| 355 // operation is a scroll, we also find out if we need to fall back to | |
| 356 // InvalidateRect due to the possibility that the scroll cannot accurately | |
| 357 // be described in logical pixels due to rounding errors. | |
| 358 bool scroll = false; | |
| 359 if (operation.type == QueuedOperation::SCROLL) { | |
| 360 if (scale_ == 1.0f) { | |
| 361 scroll = true; | |
|
Wez
2012/07/20 00:01:41
Is the float multiplication overhead sufficient to
Josh Horwich
2012/07/20 02:30:22
Done.
This motivated me to refactor this section
| |
| 362 } else if (scale_ > 0.0f) { | |
| 363 gfx::Rect original_rect = op_rect; | |
| 364 gfx::Point original_delta(operation.scroll_dx, operation.scroll_dy); | |
| 365 gfx::Point delta_scaled = original_delta.Scale(scale_); | |
| 366 float inverse_scale = 1.0f / scale_; | |
| 367 op_rect = ScaleRectBounds(op_rect, scale_); | |
| 368 operation.scroll_dx = delta_scaled.x(); | |
| 369 operation.scroll_dy = delta_scaled.y(); | |
|
Wez
2012/07/20 00:01:41
nit: Rather than copy the point back into the oper
Josh Horwich
2012/07/20 02:30:22
Done.
| |
| 370 if (original_rect == ScaleRectBounds(op_rect, inverse_scale) && | |
| 371 original_delta == delta_scaled.Scale(inverse_scale)) | |
|
Wez
2012/07/20 00:01:41
nit: Put {} around the body of multi-line-conditio
Josh Horwich
2012/07/20 02:30:22
Done.
| |
| 372 scroll = true; | |
| 373 } | |
| 374 } else { | |
| 375 op_rect = ScaleRectBounds(op_rect, scale_); | |
| 376 } | |
| 353 | 377 |
| 354 // Set |nothing_visible| to false if the change overlaps the visible area. | 378 // Set |nothing_visible| to false if the change overlaps the visible area. |
| 355 gfx::Rect visible_changed_rect = | 379 gfx::Rect visible_changed_rect = |
| 356 PP_ToGfxRect(bound_instance_->view_data().clip_rect). | 380 PP_ToGfxRect(bound_instance_->view_data().clip_rect). |
| 357 Intersect(op_rect); | 381 Intersect(op_rect); |
| 358 if (!visible_changed_rect.IsEmpty()) | 382 if (!visible_changed_rect.IsEmpty()) |
| 359 nothing_visible = false; | 383 nothing_visible = false; |
| 360 | 384 |
| 361 // Notify the plugin of the entire change (op_rect), even if it is | 385 // Notify the plugin of the entire change (op_rect), even if it is |
| 362 // partially or completely off-screen. | 386 // partially or completely off-screen. |
| 363 if (operation.type == QueuedOperation::SCROLL) { | 387 if (scroll) { |
| 364 bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy, | 388 bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy, |
| 365 op_rect); | 389 op_rect); |
| 366 } else { | 390 } else { |
| 367 bound_instance_->InvalidateRect(op_rect); | 391 bound_instance_->InvalidateRect(op_rect); |
| 368 } | 392 } |
| 369 } | 393 } |
| 370 } | 394 } |
| 371 queued_operations_.clear(); | 395 queued_operations_.clear(); |
| 372 | 396 |
| 373 if (nothing_visible) { | 397 if (nothing_visible) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 541 |
| 518 CGRect bounds; | 542 CGRect bounds; |
| 519 bounds.origin.x = plugin_rect.origin().x(); | 543 bounds.origin.x = plugin_rect.origin().x(); |
| 520 bounds.origin.y = window_height - plugin_rect.origin().y() - | 544 bounds.origin.y = window_height - plugin_rect.origin().y() - |
| 521 plugin_rect.height(); | 545 plugin_rect.height(); |
| 522 bounds.size.width = plugin_rect.width(); | 546 bounds.size.width = plugin_rect.width(); |
| 523 bounds.size.height = plugin_rect.height(); | 547 bounds.size.height = plugin_rect.height(); |
| 524 | 548 |
| 525 CGContextClipToRect(canvas, bounds); | 549 CGContextClipToRect(canvas, bounds); |
| 526 | 550 |
| 551 // TODO(jhorwich) Figure out if this code is even active anymore, and if so | |
| 552 // how to properly handle scaling. | |
| 553 DCHECK_EQ(1.0f, scale_); | |
| 554 | |
| 527 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG | 555 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG |
| 528 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. | 556 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. |
| 529 | 557 |
| 530 CGContextDrawImage(canvas, bitmap_rect, image); | 558 CGContextDrawImage(canvas, bitmap_rect, image); |
| 531 CGContextRestoreGState(canvas); | 559 CGContextRestoreGState(canvas); |
| 532 #else | 560 #else |
| 533 SkRect sk_plugin_rect = SkRect::MakeXYWH( | 561 SkRect sk_plugin_rect = SkRect::MakeXYWH( |
| 534 SkIntToScalar(plugin_rect.origin().x()), | 562 SkIntToScalar(plugin_rect.origin().x()), |
| 535 SkIntToScalar(plugin_rect.origin().y()), | 563 SkIntToScalar(plugin_rect.origin().y()), |
| 536 SkIntToScalar(plugin_rect.width()), | 564 SkIntToScalar(plugin_rect.width()), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 } | 631 } |
| 604 | 632 |
| 605 void PPB_Graphics2D_Impl::ViewFlushedPaint() { | 633 void PPB_Graphics2D_Impl::ViewFlushedPaint() { |
| 606 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::ViewFlushedPaint"); | 634 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::ViewFlushedPaint"); |
| 607 // Notify any "painted" callback. See |unpainted_flush_callback_| in the | 635 // Notify any "painted" callback. See |unpainted_flush_callback_| in the |
| 608 // header for more. | 636 // header for more. |
| 609 if (!painted_flush_callback_.is_null()) | 637 if (!painted_flush_callback_.is_null()) |
| 610 painted_flush_callback_.Execute(PP_OK); | 638 painted_flush_callback_.Execute(PP_OK); |
| 611 } | 639 } |
| 612 | 640 |
| 641 // static | |
| 642 gfx::Rect PPB_Graphics2D_Impl::ScaleRectBounds(const gfx::Rect& rect, | |
| 643 float scale) { | |
| 644 // Scale the rectangle, taking care to round coordinates outward so a | |
| 645 // rectangle scaled down then scaled back up by the inverse scale would | |
| 646 // fully contain the entire area affected by the original rectangle. | |
|
Wez
2012/07/20 00:01:41
nit: Move this comment to the header, since it's a
Josh Horwich
2012/07/20 02:30:22
Done.
| |
| 647 if (scale != 1.0f && scale > 0.0f) { | |
| 648 int left = static_cast<int>(floorf(rect.x() * scale)); | |
| 649 int top = static_cast<int>(floorf(rect.y() * scale)); | |
| 650 int right = static_cast<int>(ceilf((rect.x() + rect.width()) * scale)); | |
| 651 int bottom = static_cast<int>(ceilf((rect.y() + rect.height()) * scale)); | |
| 652 return gfx::Rect(left, top, right - left, bottom - top); | |
| 653 } | |
| 654 | |
| 655 return rect; | |
| 656 } | |
| 657 | |
| 613 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, | 658 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, |
| 614 int x, int y, | 659 int x, int y, |
| 615 const gfx::Rect& src_rect, | 660 const gfx::Rect& src_rect, |
| 616 gfx::Rect* invalidated_rect) { | 661 gfx::Rect* invalidated_rect) { |
| 617 // Ensure the source image is mapped to read from it. | 662 // Ensure the source image is mapped to read from it. |
| 618 ImageDataAutoMapper auto_mapper(image); | 663 ImageDataAutoMapper auto_mapper(image); |
| 619 if (!auto_mapper.is_valid()) | 664 if (!auto_mapper.is_valid()) |
| 620 return; | 665 return; |
| 621 | 666 |
| 622 // Portion within the source image to cut out. | 667 // Portion within the source image to cut out. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 } | 745 } |
| 701 | 746 |
| 702 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 747 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
| 703 return !unpainted_flush_callback_.is_null() || | 748 return !unpainted_flush_callback_.is_null() || |
| 704 !painted_flush_callback_.is_null() || | 749 !painted_flush_callback_.is_null() || |
| 705 offscreen_flush_pending_; | 750 offscreen_flush_pending_; |
| 706 } | 751 } |
| 707 | 752 |
| 708 } // namespace ppapi | 753 } // namespace ppapi |
| 709 } // namespace webkit | 754 } // namespace webkit |
| OLD | NEW |