Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc

Issue 10823378: Cache image data objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
332 bool done_replace_contents = false;
331 bool nothing_visible = true; 333 bool nothing_visible = true;
332 for (size_t i = 0; i < queued_operations_.size(); i++) { 334 for (size_t i = 0; i < queued_operations_.size(); i++) {
333 QueuedOperation& operation = queued_operations_[i]; 335 QueuedOperation& operation = queued_operations_[i];
334 gfx::Rect op_rect; 336 gfx::Rect op_rect;
335 switch (operation.type) { 337 switch (operation.type) {
336 case QueuedOperation::PAINT: 338 case QueuedOperation::PAINT:
337 ExecutePaintImageData(operation.paint_image, 339 ExecutePaintImageData(operation.paint_image,
338 operation.paint_x, operation.paint_y, 340 operation.paint_x, operation.paint_y,
339 operation.paint_src_rect, 341 operation.paint_src_rect,
340 &op_rect); 342 &op_rect);
341 break; 343 break;
342 case QueuedOperation::SCROLL: 344 case QueuedOperation::SCROLL:
343 ExecuteScroll(operation.scroll_clip_rect, 345 ExecuteScroll(operation.scroll_clip_rect,
344 operation.scroll_dx, operation.scroll_dy, 346 operation.scroll_dx, operation.scroll_dy,
345 &op_rect); 347 &op_rect);
346 break; 348 break;
347 case QueuedOperation::REPLACE: 349 case QueuedOperation::REPLACE:
348 ExecuteReplaceContents(operation.replace_image, &op_rect); 350 // Since the out parameter |old_image_data| takes ownership of the
351 // reference, if there are more than one ReplaceContents calls queued
352 // the first |old_image_data| will get overwritten and leaked. So we
353 // only supply this for the first call.
354 ExecuteReplaceContents(operation.replace_image, &op_rect,
355 done_replace_contents ? NULL : old_image_data);
356 done_replace_contents = true;
349 break; 357 break;
350 } 358 }
351 359
352 // For correctness with accelerated compositing, we must issue an invalidate 360 // 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. 361 // 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 362 // However, if we issue an invalidate for a clipped-out region, WebKit will
355 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint 363 // do nothing and we won't get any ViewWillInitiatePaint/ViewFlushedPaint
356 // calls, leaving our callback stranded. So we still need to check whether 364 // 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. 365 // the repainted area is visible to determine how to deal with the callback.
358 if (bound_instance_ && !op_rect.IsEmpty()) { 366 if (bound_instance_ && !op_rect.IsEmpty()) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 696
689 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, 697 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip,
690 int dx, int dy, 698 int dx, int dy,
691 gfx::Rect* invalidated_rect) { 699 gfx::Rect* invalidated_rect) {
692 gfx::ScrollCanvas(image_data_->GetCanvas(), 700 gfx::ScrollCanvas(image_data_->GetCanvas(),
693 clip, gfx::Point(dx, dy)); 701 clip, gfx::Point(dx, dy));
694 *invalidated_rect = clip; 702 *invalidated_rect = clip;
695 } 703 }
696 704
697 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, 705 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image,
698 gfx::Rect* invalidated_rect) { 706 gfx::Rect* invalidated_rect,
707 PP_Resource* old_image_data) {
699 if (image->format() != image_data_->format()) { 708 if (image->format() != image_data_->format()) {
700 DCHECK(image->width() == image_data_->width() && 709 DCHECK(image->width() == image_data_->width() &&
701 image->height() == image_data_->height()); 710 image->height() == image_data_->height());
702 // Convert the image data if the format does not match. 711 // Convert the image data if the format does not match.
703 SkIRect src_irect = { 0, 0, image->width(), image->height() }; 712 SkIRect src_irect = { 0, 0, image->width(), image->height() };
704 SkRect dest_rect = { SkIntToScalar(0), 713 SkRect dest_rect = { SkIntToScalar(0),
705 SkIntToScalar(0), 714 SkIntToScalar(0),
706 SkIntToScalar(image_data_->width()), 715 SkIntToScalar(image_data_->width()),
707 SkIntToScalar(image_data_->height()) }; 716 SkIntToScalar(image_data_->height()) };
708 ConvertImageData(image, src_irect, image_data_, dest_rect); 717 ConvertImageData(image, src_irect, image_data_, dest_rect);
709 } else { 718 } else {
710 // The passed-in image may not be mapped in our process, and we need to 719 // 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. 720 // guarantee that the current backing store is always mapped.
712 if (!image->Map()) 721 if (!image->Map())
713 return; 722 return;
714 image_data_->Unmap(); 723
715 image_data_->Swap(image); 724 if (old_image_data)
725 *old_image_data = image_data_->GetReference();
726 image_data_ = image;
716 } 727 }
717 *invalidated_rect = gfx::Rect(0, 0, 728 *invalidated_rect = gfx::Rect(0, 0,
718 image_data_->width(), image_data_->height()); 729 image_data_->width(), image_data_->height());
719 } 730 }
720 731
721 void PPB_Graphics2D_Impl::ScheduleOffscreenCallback( 732 void PPB_Graphics2D_Impl::ScheduleOffscreenCallback(
722 const FlushCallbackData& callback) { 733 const FlushCallbackData& callback) {
723 DCHECK(!HasPendingFlush()); 734 DCHECK(!HasPendingFlush());
724 offscreen_flush_pending_ = true; 735 offscreen_flush_pending_ = true;
725 MessageLoop::current()->PostTask( 736 MessageLoop::current()->PostTask(
(...skipping 14 matching lines...) Expand all
740 } 751 }
741 752
742 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 753 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
743 return !unpainted_flush_callback_.is_null() || 754 return !unpainted_flush_callback_.is_null() ||
744 !painted_flush_callback_.is_null() || 755 !painted_flush_callback_.is_null() ||
745 offscreen_flush_pending_; 756 offscreen_flush_pending_;
746 } 757 }
747 758
748 } // namespace ppapi 759 } // namespace ppapi
749 } // namespace webkit 760 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698