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 bool scroll_valid = true; | |
354 gfx::Point scroll_delta(operation.scroll_dx, operation.scroll_dy); | |
brettw
2012/07/20 20:56:45
When I suggested a different function, I was hopin
Josh Horwich
2012/07/20 22:33:08
Done.
I didn't include the in/out of QueuedOperat
| |
355 if (scale_ != 1.0f && scale_ > 0.0f) { | |
356 // Convert |op_rect| from context coordinates to logical pixels, taking | |
357 // care to include partially-covered logical pixels (aka DIPs). If the | |
358 // operation is a scroll, we also find out if we need to fall back to | |
359 // InvalidateRect due to the possibility that the scroll cannot | |
360 // accurately be described in logical pixels due to rounding errors. | |
361 gfx::Rect original_rect = op_rect; | |
362 op_rect = ScaleRectBounds(op_rect, scale_); | |
363 if (operation.type == QueuedOperation::SCROLL) { | |
364 gfx::Point original_delta = scroll_delta; | |
365 float inverse_scale = 1.0f / scale_; | |
366 scroll_delta = scroll_delta.Scale(scale_); | |
367 if (original_rect != ScaleRectBounds(op_rect, inverse_scale) || | |
368 original_delta != scroll_delta.Scale(inverse_scale)) { | |
369 scroll_valid = false; | |
Wez
2012/07/20 05:31:16
You could just override operation.type to PAINT an
Josh Horwich
2012/07/20 22:33:08
Done.
| |
370 } | |
371 } | |
372 } | |
353 | 373 |
354 // Set |nothing_visible| to false if the change overlaps the visible area. | 374 // Set |nothing_visible| to false if the change overlaps the visible area. |
355 gfx::Rect visible_changed_rect = | 375 gfx::Rect visible_changed_rect = |
356 PP_ToGfxRect(bound_instance_->view_data().clip_rect). | 376 PP_ToGfxRect(bound_instance_->view_data().clip_rect). |
357 Intersect(op_rect); | 377 Intersect(op_rect); |
358 if (!visible_changed_rect.IsEmpty()) | 378 if (!visible_changed_rect.IsEmpty()) |
359 nothing_visible = false; | 379 nothing_visible = false; |
360 | 380 |
361 // Notify the plugin of the entire change (op_rect), even if it is | 381 // Notify the plugin of the entire change (op_rect), even if it is |
362 // partially or completely off-screen. | 382 // partially or completely off-screen. |
363 if (operation.type == QueuedOperation::SCROLL) { | 383 if (operation.type == QueuedOperation::SCROLL && scroll_valid) { |
364 bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy, | 384 bound_instance_->ScrollRect(scroll_delta.x(), scroll_delta.y(), |
365 op_rect); | 385 op_rect); |
366 } else { | 386 } else { |
367 bound_instance_->InvalidateRect(op_rect); | 387 bound_instance_->InvalidateRect(op_rect); |
368 } | 388 } |
369 } | 389 } |
370 } | 390 } |
371 queued_operations_.clear(); | 391 queued_operations_.clear(); |
372 | 392 |
373 if (nothing_visible) { | 393 if (nothing_visible) { |
374 // There's nothing visible to invalidate so just schedule the callback to | 394 // There's nothing visible to invalidate so just schedule the callback to |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 | 537 |
518 CGRect bounds; | 538 CGRect bounds; |
519 bounds.origin.x = plugin_rect.origin().x(); | 539 bounds.origin.x = plugin_rect.origin().x(); |
520 bounds.origin.y = window_height - plugin_rect.origin().y() - | 540 bounds.origin.y = window_height - plugin_rect.origin().y() - |
521 plugin_rect.height(); | 541 plugin_rect.height(); |
522 bounds.size.width = plugin_rect.width(); | 542 bounds.size.width = plugin_rect.width(); |
523 bounds.size.height = plugin_rect.height(); | 543 bounds.size.height = plugin_rect.height(); |
524 | 544 |
525 CGContextClipToRect(canvas, bounds); | 545 CGContextClipToRect(canvas, bounds); |
526 | 546 |
547 // TODO(jhorwich) Figure out if this code is even active anymore, and if so | |
548 // how to properly handle scaling. | |
549 DCHECK_EQ(1.0f, scale_); | |
550 | |
527 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG | 551 // 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. | 552 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. |
529 | 553 |
530 CGContextDrawImage(canvas, bitmap_rect, image); | 554 CGContextDrawImage(canvas, bitmap_rect, image); |
531 CGContextRestoreGState(canvas); | 555 CGContextRestoreGState(canvas); |
532 #else | 556 #else |
533 SkRect sk_plugin_rect = SkRect::MakeXYWH( | 557 SkRect sk_plugin_rect = SkRect::MakeXYWH( |
534 SkIntToScalar(plugin_rect.origin().x()), | 558 SkIntToScalar(plugin_rect.origin().x()), |
535 SkIntToScalar(plugin_rect.origin().y()), | 559 SkIntToScalar(plugin_rect.origin().y()), |
536 SkIntToScalar(plugin_rect.width()), | 560 SkIntToScalar(plugin_rect.width()), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 } | 627 } |
604 | 628 |
605 void PPB_Graphics2D_Impl::ViewFlushedPaint() { | 629 void PPB_Graphics2D_Impl::ViewFlushedPaint() { |
606 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::ViewFlushedPaint"); | 630 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::ViewFlushedPaint"); |
607 // Notify any "painted" callback. See |unpainted_flush_callback_| in the | 631 // Notify any "painted" callback. See |unpainted_flush_callback_| in the |
608 // header for more. | 632 // header for more. |
609 if (!painted_flush_callback_.is_null()) | 633 if (!painted_flush_callback_.is_null()) |
610 painted_flush_callback_.Execute(PP_OK); | 634 painted_flush_callback_.Execute(PP_OK); |
611 } | 635 } |
612 | 636 |
637 // static | |
638 gfx::Rect PPB_Graphics2D_Impl::ScaleRectBounds(const gfx::Rect& rect, | |
639 float scale) { | |
640 if (scale != 1.0f && scale > 0.0f) { | |
641 int left = static_cast<int>(floorf(rect.x() * scale)); | |
642 int top = static_cast<int>(floorf(rect.y() * scale)); | |
643 int right = static_cast<int>(ceilf((rect.x() + rect.width()) * scale)); | |
644 int bottom = static_cast<int>(ceilf((rect.y() + rect.height()) * scale)); | |
645 return gfx::Rect(left, top, right - left, bottom - top); | |
646 } | |
647 | |
648 return rect; | |
649 } | |
650 | |
613 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, | 651 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, |
614 int x, int y, | 652 int x, int y, |
615 const gfx::Rect& src_rect, | 653 const gfx::Rect& src_rect, |
616 gfx::Rect* invalidated_rect) { | 654 gfx::Rect* invalidated_rect) { |
617 // Ensure the source image is mapped to read from it. | 655 // Ensure the source image is mapped to read from it. |
618 ImageDataAutoMapper auto_mapper(image); | 656 ImageDataAutoMapper auto_mapper(image); |
619 if (!auto_mapper.is_valid()) | 657 if (!auto_mapper.is_valid()) |
620 return; | 658 return; |
621 | 659 |
622 // Portion within the source image to cut out. | 660 // Portion within the source image to cut out. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 } | 738 } |
701 | 739 |
702 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 740 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
703 return !unpainted_flush_callback_.is_null() || | 741 return !unpainted_flush_callback_.is_null() || |
704 !painted_flush_callback_.is_null() || | 742 !painted_flush_callback_.is_null() || |
705 offscreen_flush_pending_; | 743 offscreen_flush_pending_; |
706 } | 744 } |
707 | 745 |
708 } // namespace ppapi | 746 } // namespace ppapi |
709 } // namespace webkit | 747 } // namespace webkit |
OLD | NEW |