diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 16:10:32 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 16:10:32 +0000 |
commit | fefe67840b2716b2569946fcfc4a19b55c312e20 (patch) | |
tree | c0f1ac1d4791e0559cc5020be07b76a92e1e0625 | |
parent | 46bc6b6b2d6ae156f76a1611362917b49eafc8cb (diff) | |
download | chromium_src-fefe67840b2716b2569946fcfc4a19b55c312e20.zip chromium_src-fefe67840b2716b2569946fcfc4a19b55c312e20.tar.gz chromium_src-fefe67840b2716b2569946fcfc4a19b55c312e20.tar.bz2 |
Chromium side changes to use PP_CompletionCallback as the Flush callback.
R=brettw
BUG=47461
TEST=none
Review URL: http://codereview.chromium.org/2852024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50851 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_plugin.cc | 7 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_device_context_2d.cc | 69 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_device_context_2d.h | 36 |
4 files changed, 60 insertions, 54 deletions
@@ -155,7 +155,7 @@ deps = { Var("libvpx_revision"), "src/third_party/ppapi": - "http://ppapi.googlecode.com/svn/trunk@73", + "http://ppapi.googlecode.com/svn/trunk@77", "src/third_party/libjingle/source": "http://libjingle.googlecode.com/svn/branches/nextsnap@" + diff --git a/remoting/client/plugin/chromoting_plugin.cc b/remoting/client/plugin/chromoting_plugin.cc index 1657e20..88b19cb 100644 --- a/remoting/client/plugin/chromoting_plugin.cc +++ b/remoting/client/plugin/chromoting_plugin.cc @@ -16,6 +16,7 @@ #include "remoting/jingle_glue/jingle_thread.h" #include "third_party/ppapi/c/pp_event.h" #include "third_party/ppapi/c/pp_rect.h" +#include "third_party/ppapi/cpp/completion_callback.h" #include "third_party/ppapi/cpp/image_data.h" using std::string; @@ -47,7 +48,9 @@ ChromotingPlugin::~ChromotingPlugin() { main_thread_->Stop(); } -bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { +bool ChromotingPlugin::Init(uint32_t argc, + const char* argn[], + const char* argv[]) { LOG(INFO) << "Started ChromotingPlugin::Init"; // Extract the URL from the arguments. @@ -126,7 +129,7 @@ void ChromotingPlugin::ViewChanged(const PP_Rect& position, } } device_context_.ReplaceContents(&image); - device_context_.Flush(NULL, this); + device_context_.Flush(pp::CompletionCallback(NULL, this)); } else { LOG(ERROR) << "Unable to allocate image."; } diff --git a/webkit/glue/plugins/pepper_device_context_2d.cc b/webkit/glue/plugins/pepper_device_context_2d.cc index 9eae9dc..3d81fcb 100644 --- a/webkit/glue/plugins/pepper_device_context_2d.cc +++ b/webkit/glue/plugins/pepper_device_context_2d.cc @@ -12,6 +12,7 @@ #include "gfx/point.h" #include "gfx/rect.h" #include "skia/ext/platform_canvas.h" +#include "third_party/ppapi/c/pp_errors.h" #include "third_party/ppapi/c/pp_module.h" #include "third_party/ppapi/c/pp_rect.h" #include "third_party/ppapi/c/pp_resource.h" @@ -119,14 +120,13 @@ bool ReplaceContents(PP_Resource device_context, PP_Resource image) { return context->ReplaceContents(image); } -bool Flush(PP_Resource device_context, - PPB_DeviceContext2D_FlushCallback callback, - void* callback_data) { +int32_t Flush(PP_Resource device_context, + PP_CompletionCallback callback) { scoped_refptr<DeviceContext2D> context( ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); if (!context.get()) - return false; - return context->Flush(callback, callback_data); + return PP_Error_BadResource; + return context->Flush(callback); } const PPB_DeviceContext2D ppb_devicecontext2d = { @@ -171,17 +171,6 @@ struct DeviceContext2D::QueuedOperation { scoped_refptr<ImageData> replace_image; }; -DeviceContext2D::FlushCallbackData::FlushCallbackData( - PPB_DeviceContext2D_FlushCallback c, - void* d) - : callback_(c), - callback_data_(d) { -} - -void DeviceContext2D::FlushCallbackData::Execute(PP_Resource device_context) { - callback_(device_context, callback_data_); -} - DeviceContext2D::DeviceContext2D(PluginModule* module) : Resource(module), bound_instance_(NULL), @@ -291,16 +280,15 @@ bool DeviceContext2D::ReplaceContents(PP_Resource image) { return true; } -bool DeviceContext2D::Flush(PPB_DeviceContext2D_FlushCallback callback, - void* callback_data) { +int32_t DeviceContext2D::Flush(const PP_CompletionCallback& callback) { // Don't allow more than one pending flush at a time. if (HasPendingFlush()) - return false; + return PP_Error_InProgress; // TODO(brettw) check that the current thread is not the main one and // implement blocking flushes in this case. - if (!callback) - return false; + if (!callback.func) + return PP_Error_BadArgument; gfx::Rect changed_rect; for (size_t i = 0; i < queued_operations_.size(); i++) { @@ -336,16 +324,14 @@ bool DeviceContext2D::Flush(PPB_DeviceContext2D_FlushCallback callback, visible_changed_rect = bound_instance_->clip().Intersect(changed_rect); if (bound_instance_ && !visible_changed_rect.IsEmpty()) { - unpainted_flush_callback_.reset(new FlushCallbackData(callback, - callback_data)); + unpainted_flush_callback_.Set(callback); bound_instance_->InvalidateRect(visible_changed_rect); } else { // There's nothing visible to invalidate so just schedule the callback to // execute in the next round of the message loop. - ScheduleOffscreenCallback( - FlushCallbackData(callback, callback_data)); + ScheduleOffscreenCallback(FlushCallbackData(callback)); } - return true; + return PP_Error_WouldBlock; } bool DeviceContext2D::ReadImageData(PP_Resource image, int32_t x, int32_t y) { @@ -398,13 +384,13 @@ bool DeviceContext2D::BindToInstance(PluginInstance* new_instance) { // When the device is detached, we'll not get any more paint callbacks so // we need to clear the list, but we still want to issue any pending // callbacks to the plugin. - if (unpainted_flush_callback_.get()) { - ScheduleOffscreenCallback(*unpainted_flush_callback_.get()); - unpainted_flush_callback_.reset(); + if (!unpainted_flush_callback_.is_null()) { + ScheduleOffscreenCallback(unpainted_flush_callback_); + unpainted_flush_callback_.Clear(); } - if (painted_flush_callback_.get()) { - ScheduleOffscreenCallback(*painted_flush_callback_.get()); - painted_flush_callback_.reset(); + if (!painted_flush_callback_.is_null()) { + ScheduleOffscreenCallback(painted_flush_callback_); + painted_flush_callback_.Clear(); } } else if (flushed_any_data_) { // Only schedule a paint if this backing store has had any data flushed to @@ -469,22 +455,22 @@ void DeviceContext2D::Paint(WebKit::WebCanvas* canvas, void DeviceContext2D::ViewInitiatedPaint() { // Move any "unpainted" callback to the painted state. See // |unpainted_flush_callback_| in the header for more. - if (unpainted_flush_callback_.get()) { - DCHECK(!painted_flush_callback_.get()); - painted_flush_callback_.swap(unpainted_flush_callback_); + if (!unpainted_flush_callback_.is_null()) { + DCHECK(painted_flush_callback_.is_null()); + std::swap(painted_flush_callback_, unpainted_flush_callback_); } } void DeviceContext2D::ViewFlushedPaint() { // Notify any "painted" callback. See |unpainted_flush_callback_| in the // header for more. - if (painted_flush_callback_.get()) { + if (!painted_flush_callback_.is_null()) { // We must clear this variable before issuing the callback. It will be // common for the plugin to issue another invalidate in response to a flush // callback, and we don't want to think that a callback is already pending. - scoped_ptr<FlushCallbackData> callback; - callback.swap(painted_flush_callback_); - callback->Execute(GetResource()); + FlushCallbackData callback; + std::swap(callback, painted_flush_callback_); + callback.Execute(PP_OK); } } @@ -549,11 +535,12 @@ void DeviceContext2D::ExecuteOffscreenCallback(FlushCallbackData data) { // common for the plugin to issue another invalidate in response to a flush // callback, and we don't want to think that a callback is already pending. offscreen_flush_pending_ = false; - data.Execute(GetResource()); + data.Execute(PP_OK); } bool DeviceContext2D::HasPendingFlush() const { - return unpainted_flush_callback_.get() || painted_flush_callback_.get() || + return !unpainted_flush_callback_.is_null() || + !painted_flush_callback_.is_null() || offscreen_flush_pending_; } diff --git a/webkit/glue/plugins/pepper_device_context_2d.h b/webkit/glue/plugins/pepper_device_context_2d.h index 2d5bbb3..87203c8 100644 --- a/webkit/glue/plugins/pepper_device_context_2d.h +++ b/webkit/glue/plugins/pepper_device_context_2d.h @@ -8,7 +8,7 @@ #include <vector> #include "base/basictypes.h" -#include "base/scoped_ptr.h" +#include "third_party/ppapi/c/pp_completion_callback.h" #include "third_party/ppapi/c/ppb_device_context_2d.h" #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" #include "webkit/glue/plugins/pepper_resource.h" @@ -46,8 +46,8 @@ class DeviceContext2D : public Resource { const PP_Rect* src_rect); bool Scroll(const PP_Rect* clip_rect, int32_t dx, int32_t dy); bool ReplaceContents(PP_Resource image); - bool Flush(PPB_DeviceContext2D_FlushCallback callback, - void* callback_data); + int32_t Flush(const PP_CompletionCallback& callback); + bool ReadImageData(PP_Resource image, int32_t x, int32_t y); // Assciates this device with the given plugin instance. You can pass NULL to @@ -69,16 +69,32 @@ class DeviceContext2D : public Resource { private: // Tracks a call to flush that requires a callback. - // See unpainted_flush_callbacks_ below. class FlushCallbackData { public: - FlushCallbackData(PPB_DeviceContext2D_FlushCallback c, void* d); + FlushCallbackData() { + Clear(); + } + + FlushCallbackData(const PP_CompletionCallback& callback) { + Set(callback); + } + + bool is_null() const { return !callback_.func; } + + void Set(const PP_CompletionCallback& callback) { + callback_ = callback; + } + + void Clear() { + callback_ = PP_MakeCompletionCallback(NULL, 0); + } - void Execute(PP_Resource device_context); + void Execute(int32_t result) { + PP_RunCompletionCallback(&callback_, result); + } private: - PPB_DeviceContext2D_FlushCallback callback_; - void* callback_data_; + PP_CompletionCallback callback_; }; // Called internally to execute the different queued commands. The @@ -141,8 +157,8 @@ class DeviceContext2D : public Resource { // the unpainted callbacks. When the renderer has initiated a paint, we'll // move it to the painted callbacks list. When the renderer receives a flush, // we'll execute the callback and remove it from the list. - scoped_ptr<FlushCallbackData> unpainted_flush_callback_; - scoped_ptr<FlushCallbackData> painted_flush_callback_; + FlushCallbackData unpainted_flush_callback_; + FlushCallbackData painted_flush_callback_; // When doing offscreen flushes, we issue a task that issues the callback // later. This is set when one of those tasks is pending so that we can |