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 | |
brettw
2012/07/17 19:27:50
This seems kind of complicated. Can you separate t
Josh Horwich
2012/07/17 22:53:36
Done.
| |
354 // to include partially-covered logical pixels (aka DIPs) | |
355 gfx::Rect scaled_op_rect = op_rect; | |
356 bool scroll_use_invalidate = false; | |
357 int scaled_dx = operation.scroll_dx; | |
358 int scaled_dy = operation.scroll_dy; | |
359 if (scale_ != 1.0f && scale_ > 0.0f) { | |
360 scaled_op_rect.ScaleBounds(scale_); | |
361 if (operation.type == QueuedOperation::SCROLL) { | |
362 // For scrolling, we need to ensure that the entire area can be | |
363 // properly scrolled without including pixels outside of the requested | |
364 // scroll. We do this by reversing the scale and making sure the | |
365 // affected dimensions are exactly the original - the loss of | |
366 // fractional precision in intermediate calculations is intentional. | |
367 gfx::Rect unscaled_op_rect = scaled_op_rect; | |
368 unscaled_op_rect.ScaleBounds(1.0f / scale_); | |
369 scaled_dx = static_cast<int>(scaled_dx * scale_); | |
370 scaled_dy = static_cast<int>(scaled_dy * scale_); | |
371 if (unscaled_op_rect != op_rect || | |
372 static_cast<int>(scaled_dx / scale_) != operation.scroll_dx || | |
373 static_cast<int>(scaled_dy / scale_) != operation.scroll_dy) | |
374 scroll_use_invalidate = true; | |
375 } | |
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(scaled_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 (scaled_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 (operation.type == QueuedOperation::SCROLL && !scroll_use_invalidate) |
364 bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy, | 388 bound_instance_->ScrollRect(scaled_dx, scaled_dy, scaled_op_rect); |
365 op_rect); | 389 else |
366 } else { | 390 bound_instance_->InvalidateRect(scaled_op_rect); |
367 bound_instance_->InvalidateRect(op_rect); | |
368 } | |
369 } | 391 } |
370 } | 392 } |
371 queued_operations_.clear(); | 393 queued_operations_.clear(); |
372 | 394 |
373 if (nothing_visible) { | 395 if (nothing_visible) { |
374 // There's nothing visible to invalidate so just schedule the callback to | 396 // There's nothing visible to invalidate so just schedule the callback to |
375 // execute in the next round of the message loop. | 397 // execute in the next round of the message loop. |
376 ScheduleOffscreenCallback(FlushCallbackData(callback)); | 398 ScheduleOffscreenCallback(FlushCallbackData(callback)); |
377 } else { | 399 } else { |
378 unpainted_flush_callback_.Set(callback); | 400 unpainted_flush_callback_.Set(callback); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 | 539 |
518 CGRect bounds; | 540 CGRect bounds; |
519 bounds.origin.x = plugin_rect.origin().x(); | 541 bounds.origin.x = plugin_rect.origin().x(); |
520 bounds.origin.y = window_height - plugin_rect.origin().y() - | 542 bounds.origin.y = window_height - plugin_rect.origin().y() - |
521 plugin_rect.height(); | 543 plugin_rect.height(); |
522 bounds.size.width = plugin_rect.width(); | 544 bounds.size.width = plugin_rect.width(); |
523 bounds.size.height = plugin_rect.height(); | 545 bounds.size.height = plugin_rect.height(); |
524 | 546 |
525 CGContextClipToRect(canvas, bounds); | 547 CGContextClipToRect(canvas, bounds); |
526 | 548 |
549 // TODO(jhorwich) Figure out if this code is even active anymore, and if so | |
550 // how to properly handle scaling. | |
551 DCHECK_EQ(1.0f, scale_); | |
552 | |
527 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG | 553 // 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. | 554 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. |
529 | 555 |
530 CGContextDrawImage(canvas, bitmap_rect, image); | 556 CGContextDrawImage(canvas, bitmap_rect, image); |
531 CGContextRestoreGState(canvas); | 557 CGContextRestoreGState(canvas); |
532 #else | 558 #else |
533 SkRect sk_plugin_rect = SkRect::MakeXYWH( | 559 SkRect sk_plugin_rect = SkRect::MakeXYWH( |
534 SkIntToScalar(plugin_rect.origin().x()), | 560 SkIntToScalar(plugin_rect.origin().x()), |
535 SkIntToScalar(plugin_rect.origin().y()), | 561 SkIntToScalar(plugin_rect.origin().y()), |
536 SkIntToScalar(plugin_rect.width()), | 562 SkIntToScalar(plugin_rect.width()), |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 } | 726 } |
701 | 727 |
702 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 728 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
703 return !unpainted_flush_callback_.is_null() || | 729 return !unpainted_flush_callback_.is_null() || |
704 !painted_flush_callback_.is_null() || | 730 !painted_flush_callback_.is_null() || |
705 offscreen_flush_pending_; | 731 offscreen_flush_pending_; |
706 } | 732 } |
707 | 733 |
708 } // namespace ppapi | 734 } // namespace ppapi |
709 } // namespace webkit | 735 } // namespace webkit |
OLD | NEW |