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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 "PPB_Graphics2D.ReplaceContents: Image size doesn't match " 307 "PPB_Graphics2D.ReplaceContents: Image size doesn't match "
308 "Graphics2D size."); 308 "Graphics2D size.");
309 return; 309 return;
310 } 310 }
311 311
312 QueuedOperation operation(QueuedOperation::REPLACE); 312 QueuedOperation operation(QueuedOperation::REPLACE);
313 operation.replace_image = image_resource; 313 operation.replace_image = image_resource;
314 queued_operations_.push_back(operation); 314 queued_operations_.push_back(operation);
315 } 315 }
316 316
317 int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) { 317 int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback) {
318 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush"); 318 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush");
319 if (!callback.func)
320 return PP_ERROR_BLOCKS_MAIN_THREAD;
321
322 // Don't allow more than one pending flush at a time. 319 // Don't allow more than one pending flush at a time.
323 if (HasPendingFlush()) 320 if (HasPendingFlush())
324 return PP_ERROR_INPROGRESS; 321 return PP_ERROR_INPROGRESS;
325 322
326 bool nothing_visible = true; 323 bool nothing_visible = true;
327 for (size_t i = 0; i < queued_operations_.size(); i++) { 324 for (size_t i = 0; i < queued_operations_.size(); i++) {
328 QueuedOperation& operation = queued_operations_[i]; 325 QueuedOperation& operation = queued_operations_[i];
329 gfx::Rect op_rect; 326 gfx::Rect op_rect;
330 switch (operation.type) { 327 switch (operation.type) {
331 case QueuedOperation::PAINT: 328 case QueuedOperation::PAINT:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } else { 364 } else {
368 bound_instance_->InvalidateRect(op_rect); 365 bound_instance_->InvalidateRect(op_rect);
369 } 366 }
370 } 367 }
371 } 368 }
372 queued_operations_.clear(); 369 queued_operations_.clear();
373 370
374 if (nothing_visible) { 371 if (nothing_visible) {
375 // There's nothing visible to invalidate so just schedule the callback to 372 // There's nothing visible to invalidate so just schedule the callback to
376 // execute in the next round of the message loop. 373 // execute in the next round of the message loop.
377 ScheduleOffscreenCallback(FlushCallbackData( 374 ScheduleOffscreenCallback(FlushCallbackData(callback));
378 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))));
379 } else { 375 } else {
380 unpainted_flush_callback_.Set( 376 unpainted_flush_callback_.Set(callback);
381 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)));
382 } 377 }
383 return PP_OK_COMPLETIONPENDING; 378 return PP_OK_COMPLETIONPENDING;
384 } 379 }
385 380
386 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, 381 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image,
387 const PP_Point* top_left) { 382 const PP_Point* top_left) {
388 // Get and validate the image object to paint into. 383 // Get and validate the image object to paint into.
389 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); 384 EnterResourceNoLock<PPB_ImageData_API> enter(image, true);
390 if (enter.failed()) 385 if (enter.failed())
391 return false; 386 return false;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 680 }
686 681
687 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 682 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
688 return !unpainted_flush_callback_.is_null() || 683 return !unpainted_flush_callback_.is_null() ||
689 !painted_flush_callback_.is_null() || 684 !painted_flush_callback_.is_null() ||
690 offscreen_flush_pending_; 685 offscreen_flush_pending_;
691 } 686 }
692 687
693 } // namespace ppapi 688 } // namespace ppapi
694 } // namespace webkit 689 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_graphics_2d_impl.h ('k') | webkit/plugins/ppapi/ppb_layer_compositor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698