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 14 matching lines...) Expand all Loading... |
25 #include "webkit/plugins/ppapi/gfx_conversion.h" | 25 #include "webkit/plugins/ppapi/gfx_conversion.h" |
26 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 26 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
27 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 27 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
28 #include "webkit/plugins/ppapi/resource_helper.h" | 28 #include "webkit/plugins/ppapi/resource_helper.h" |
29 | 29 |
30 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
31 #include "base/mac/mac_util.h" | 31 #include "base/mac/mac_util.h" |
32 #include "base/mac/scoped_cftyperef.h" | 32 #include "base/mac/scoped_cftyperef.h" |
33 #endif | 33 #endif |
34 | 34 |
| 35 using ppapi::ApiCallbackType; |
35 using ppapi::thunk::EnterResourceNoLock; | 36 using ppapi::thunk::EnterResourceNoLock; |
36 using ppapi::thunk::PPB_ImageData_API; | 37 using ppapi::thunk::PPB_ImageData_API; |
37 using ppapi::TrackedCallback; | 38 using ppapi::TrackedCallback; |
38 | 39 |
39 namespace webkit { | 40 namespace webkit { |
40 namespace ppapi { | 41 namespace ppapi { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 // Converts a rect inside an image of the given dimensions. The rect may be | 45 // Converts a rect inside an image of the given dimensions. The rect may be |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 "PPB_Graphics2D.ReplaceContents: Image size doesn't match " | 308 "PPB_Graphics2D.ReplaceContents: Image size doesn't match " |
308 "Graphics2D size."); | 309 "Graphics2D size."); |
309 return; | 310 return; |
310 } | 311 } |
311 | 312 |
312 QueuedOperation operation(QueuedOperation::REPLACE); | 313 QueuedOperation operation(QueuedOperation::REPLACE); |
313 operation.replace_image = image_resource; | 314 operation.replace_image = image_resource; |
314 queued_operations_.push_back(operation); | 315 queued_operations_.push_back(operation); |
315 } | 316 } |
316 | 317 |
317 int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) { | 318 int32_t PPB_Graphics2D_Impl::Flush(ApiCallbackType callback) { |
318 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Flush"); | 319 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. | 320 // Don't allow more than one pending flush at a time. |
323 if (HasPendingFlush()) | 321 if (HasPendingFlush()) |
324 return PP_ERROR_INPROGRESS; | 322 return PP_ERROR_INPROGRESS; |
325 | 323 |
326 bool nothing_visible = true; | 324 bool nothing_visible = true; |
327 for (size_t i = 0; i < queued_operations_.size(); i++) { | 325 for (size_t i = 0; i < queued_operations_.size(); i++) { |
328 QueuedOperation& operation = queued_operations_[i]; | 326 QueuedOperation& operation = queued_operations_[i]; |
329 gfx::Rect op_rect; | 327 gfx::Rect op_rect; |
330 switch (operation.type) { | 328 switch (operation.type) { |
331 case QueuedOperation::PAINT: | 329 case QueuedOperation::PAINT: |
(...skipping 30 matching lines...) Expand all Loading... |
362 bound_instance_->InvalidateRect(visible_changed_rect); | 360 bound_instance_->InvalidateRect(visible_changed_rect); |
363 } | 361 } |
364 nothing_visible = false; | 362 nothing_visible = false; |
365 } | 363 } |
366 } | 364 } |
367 queued_operations_.clear(); | 365 queued_operations_.clear(); |
368 | 366 |
369 if (nothing_visible) { | 367 if (nothing_visible) { |
370 // There's nothing visible to invalidate so just schedule the callback to | 368 // There's nothing visible to invalidate so just schedule the callback to |
371 // execute in the next round of the message loop. | 369 // execute in the next round of the message loop. |
372 ScheduleOffscreenCallback(FlushCallbackData( | 370 ScheduleOffscreenCallback(FlushCallbackData(callback)); |
373 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)))); | |
374 } else { | 371 } else { |
375 unpainted_flush_callback_.Set( | 372 unpainted_flush_callback_.Set(callback); |
376 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))); | |
377 } | 373 } |
378 return PP_OK_COMPLETIONPENDING; | 374 return PP_OK_COMPLETIONPENDING; |
379 } | 375 } |
380 | 376 |
381 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, | 377 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, |
382 const PP_Point* top_left) { | 378 const PP_Point* top_left) { |
383 // Get and validate the image object to paint into. | 379 // Get and validate the image object to paint into. |
384 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); | 380 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); |
385 if (enter.failed()) | 381 if (enter.failed()) |
386 return false; | 382 return false; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 676 } |
681 | 677 |
682 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 678 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
683 return !unpainted_flush_callback_.is_null() || | 679 return !unpainted_flush_callback_.is_null() || |
684 !painted_flush_callback_.is_null() || | 680 !painted_flush_callback_.is_null() || |
685 offscreen_flush_pending_; | 681 offscreen_flush_pending_; |
686 } | 682 } |
687 | 683 |
688 } // namespace ppapi | 684 } // namespace ppapi |
689 } // namespace webkit | 685 } // namespace webkit |
OLD | NEW |