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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 "PPB_Graphics2D.ReplaceContents: Image size doesn't match " | 315 "PPB_Graphics2D.ReplaceContents: Image size doesn't match " |
| 316 "Graphics2D size."); | 316 "Graphics2D size."); |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 | 319 |
| 320 QueuedOperation operation(QueuedOperation::REPLACE); | 320 QueuedOperation operation(QueuedOperation::REPLACE); |
| 321 operation.replace_image = image_resource; | 321 operation.replace_image = image_resource; |
| 322 queued_operations_.push_back(operation); | 322 queued_operations_.push_back(operation); |
| 323 } | 323 } |
| 324 | 324 |
| 325 int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback) { | 325 int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback, |
| 326 PP_Resource* old_image_data) { | |
| 326 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush"); | 327 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush"); |
| 327 // Don't allow more than one pending flush at a time. | 328 // Don't allow more than one pending flush at a time. |
| 328 if (HasPendingFlush()) | 329 if (HasPendingFlush()) |
| 329 return PP_ERROR_INPROGRESS; | 330 return PP_ERROR_INPROGRESS; |
| 330 | 331 |
| 331 bool nothing_visible = true; | 332 bool nothing_visible = true; |
| 332 for (size_t i = 0; i < queued_operations_.size(); i++) { | 333 for (size_t i = 0; i < queued_operations_.size(); i++) { |
| 333 QueuedOperation& operation = queued_operations_[i]; | 334 QueuedOperation& operation = queued_operations_[i]; |
| 334 gfx::Rect op_rect; | 335 gfx::Rect op_rect; |
| 335 switch (operation.type) { | 336 switch (operation.type) { |
| 336 case QueuedOperation::PAINT: | 337 case QueuedOperation::PAINT: |
| 337 ExecutePaintImageData(operation.paint_image, | 338 ExecutePaintImageData(operation.paint_image, |
| 338 operation.paint_x, operation.paint_y, | 339 operation.paint_x, operation.paint_y, |
| 339 operation.paint_src_rect, | 340 operation.paint_src_rect, |
| 340 &op_rect); | 341 &op_rect); |
| 341 break; | 342 break; |
| 342 case QueuedOperation::SCROLL: | 343 case QueuedOperation::SCROLL: |
| 343 ExecuteScroll(operation.scroll_clip_rect, | 344 ExecuteScroll(operation.scroll_clip_rect, |
| 344 operation.scroll_dx, operation.scroll_dy, | 345 operation.scroll_dx, operation.scroll_dy, |
| 345 &op_rect); | 346 &op_rect); |
| 346 break; | 347 break; |
| 347 case QueuedOperation::REPLACE: | 348 case QueuedOperation::REPLACE: |
| 348 ExecuteReplaceContents(operation.replace_image, &op_rect); | 349 ExecuteReplaceContents(operation.replace_image, &op_rect, |
| 350 old_image_data); | |
|
yzshen1
2012/08/21 22:07:24
There might be more than one ReplaceContents(). If
brettw
2012/08/21 23:24:58
Good catch!
| |
| 349 break; | 351 break; |
| 350 } | 352 } |
| 351 | 353 |
| 352 // For correctness with accelerated compositing, we must issue an invalidate | 354 // For correctness with accelerated compositing, we must issue an invalidate |
| 353 // on the full op_rect even if it is partially or completely off-screen. | 355 // on the full op_rect even if it is partially or completely off-screen. |
| 354 // However, if we issue an invalidate for a clipped-out region, WebKit will | 356 // However, if we issue an invalidate for a clipped-out region, WebKit will |
| 355 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint | 357 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint |
| 356 // calls, leaving our callback stranded. So we still need to check whether | 358 // calls, leaving our callback stranded. So we still need to check whether |
| 357 // the repainted area is visible to determine how to deal with the callback. | 359 // the repainted area is visible to determine how to deal with the callback. |
| 358 if (bound_instance_ && !op_rect.IsEmpty()) { | 360 if (bound_instance_ && !op_rect.IsEmpty()) { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 | 690 |
| 689 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, | 691 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, |
| 690 int dx, int dy, | 692 int dx, int dy, |
| 691 gfx::Rect* invalidated_rect) { | 693 gfx::Rect* invalidated_rect) { |
| 692 gfx::ScrollCanvas(image_data_->GetCanvas(), | 694 gfx::ScrollCanvas(image_data_->GetCanvas(), |
| 693 clip, gfx::Point(dx, dy)); | 695 clip, gfx::Point(dx, dy)); |
| 694 *invalidated_rect = clip; | 696 *invalidated_rect = clip; |
| 695 } | 697 } |
| 696 | 698 |
| 697 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, | 699 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, |
| 698 gfx::Rect* invalidated_rect) { | 700 gfx::Rect* invalidated_rect, |
| 701 PP_Resource* old_image_data) { | |
| 699 if (image->format() != image_data_->format()) { | 702 if (image->format() != image_data_->format()) { |
| 700 DCHECK(image->width() == image_data_->width() && | 703 DCHECK(image->width() == image_data_->width() && |
| 701 image->height() == image_data_->height()); | 704 image->height() == image_data_->height()); |
| 702 // Convert the image data if the format does not match. | 705 // Convert the image data if the format does not match. |
| 703 SkIRect src_irect = { 0, 0, image->width(), image->height() }; | 706 SkIRect src_irect = { 0, 0, image->width(), image->height() }; |
| 704 SkRect dest_rect = { SkIntToScalar(0), | 707 SkRect dest_rect = { SkIntToScalar(0), |
| 705 SkIntToScalar(0), | 708 SkIntToScalar(0), |
| 706 SkIntToScalar(image_data_->width()), | 709 SkIntToScalar(image_data_->width()), |
| 707 SkIntToScalar(image_data_->height()) }; | 710 SkIntToScalar(image_data_->height()) }; |
| 708 ConvertImageData(image, src_irect, image_data_, dest_rect); | 711 ConvertImageData(image, src_irect, image_data_, dest_rect); |
| 709 } else { | 712 } else { |
| 710 // The passed-in image may not be mapped in our process, and we need to | 713 // The passed-in image may not be mapped in our process, and we need to |
| 711 // guarantee that the current backing store is always mapped. | 714 // guarantee that the current backing store is always mapped. |
| 712 if (!image->Map()) | 715 if (!image->Map()) |
| 713 return; | 716 return; |
| 714 image_data_->Unmap(); | 717 |
| 715 image_data_->Swap(image); | 718 if (old_image_data) |
| 719 *old_image_data = image_data_->GetReference(); | |
| 720 image_data_ = image; | |
| 716 } | 721 } |
| 717 *invalidated_rect = gfx::Rect(0, 0, | 722 *invalidated_rect = gfx::Rect(0, 0, |
| 718 image_data_->width(), image_data_->height()); | 723 image_data_->width(), image_data_->height()); |
| 719 } | 724 } |
| 720 | 725 |
| 721 void PPB_Graphics2D_Impl::ScheduleOffscreenCallback( | 726 void PPB_Graphics2D_Impl::ScheduleOffscreenCallback( |
| 722 const FlushCallbackData& callback) { | 727 const FlushCallbackData& callback) { |
| 723 DCHECK(!HasPendingFlush()); | 728 DCHECK(!HasPendingFlush()); |
| 724 offscreen_flush_pending_ = true; | 729 offscreen_flush_pending_ = true; |
| 725 MessageLoop::current()->PostTask( | 730 MessageLoop::current()->PostTask( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 740 } | 745 } |
| 741 | 746 |
| 742 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 747 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
| 743 return !unpainted_flush_callback_.is_null() || | 748 return !unpainted_flush_callback_.is_null() || |
| 744 !painted_flush_callback_.is_null() || | 749 !painted_flush_callback_.is_null() || |
| 745 offscreen_flush_pending_; | 750 offscreen_flush_pending_; |
| 746 } | 751 } |
| 747 | 752 |
| 748 } // namespace ppapi | 753 } // namespace ppapi |
| 749 } // namespace webkit | 754 } // namespace webkit |
| OLD | NEW |