Chromium Code Reviews| Index: native_client_sdk/src/examples/api/gamepad/gamepad.cc |
| diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad.cc b/native_client_sdk/src/examples/api/gamepad/gamepad.cc |
| index 8e8b588fda77631b01e9debc7a66900b95212cb6..d762a6a4ad1aedadd8306c55b9b9018909e9a4a1 100644 |
| --- a/native_client_sdk/src/examples/api/gamepad/gamepad.cc |
| +++ b/native_client_sdk/src/examples/api/gamepad/gamepad.cc |
| @@ -19,15 +19,13 @@ namespace { |
| // This is called by the browser when the 2D context has been flushed to the |
| // browser window. |
| void FlushCallback(void* data, int32_t result) { |
|
noelallen1
2013/05/07 19:07:29
Why isn't this the C++ callback? (Callback factor
binji
2013/05/07 20:37:35
Done.
|
| - static_cast<gamepad::Gamepad*>(data)->set_flush_pending(false); |
| - static_cast<gamepad::Gamepad*>(data)->Paint(); |
| + static_cast<GamepadInstance*>(data)->set_flush_pending(false); |
| + static_cast<GamepadInstance*>(data)->Paint(); |
| } |
| } // namespace |
| -namespace gamepad { |
| - |
| -Gamepad::Gamepad(PP_Instance instance) |
| +GamepadInstance::GamepadInstance(PP_Instance instance) |
| : pp::Instance(instance), |
| graphics_2d_context_(NULL), |
| pixel_buffer_(NULL), |
| @@ -40,13 +38,13 @@ Gamepad::Gamepad(PP_Instance instance) |
| assert(gamepad_); |
| } |
| -Gamepad::~Gamepad() { |
| +GamepadInstance::~GamepadInstance() { |
| quit_ = true; |
| DestroyContext(); |
| delete pixel_buffer_; |
| } |
| -void Gamepad::DidChangeView(const pp::View& view) { |
| +void GamepadInstance::DidChangeView(const pp::View& view) { |
| pp::Rect position = view.GetRect(); |
| if (position.size().width() == width() && |
| position.size().height() == height()) |
| @@ -83,7 +81,7 @@ void FillRect(pp::ImageData* image, |
| } |
| } |
| -void Gamepad::Paint() { |
| +void GamepadInstance::Paint() { |
| // Clear the background. |
| FillRect(pixel_buffer_, 0, 0, width(), height(), 0xfff0f0f0); |
| @@ -123,7 +121,7 @@ void Gamepad::Paint() { |
| FlushPixelBuffer(); |
| } |
| -void Gamepad::CreateContext(const pp::Size& size) { |
| +void GamepadInstance::CreateContext(const pp::Size& size) { |
| if (IsContextValid()) |
| return; |
| graphics_2d_context_ = new pp::Graphics2D(this, size, false); |
| @@ -132,14 +130,14 @@ void Gamepad::CreateContext(const pp::Size& size) { |
| } |
| } |
| -void Gamepad::DestroyContext() { |
| +void GamepadInstance::DestroyContext() { |
| if (!IsContextValid()) |
| return; |
| delete graphics_2d_context_; |
| graphics_2d_context_ = NULL; |
| } |
| -void Gamepad::FlushPixelBuffer() { |
| +void GamepadInstance::FlushPixelBuffer() { |
| if (!IsContextValid()) |
| return; |
| // Note that the pixel lock is held while the buffer is copied into the |
| @@ -151,4 +149,17 @@ void Gamepad::FlushPixelBuffer() { |
| graphics_2d_context_->Flush(pp::CompletionCallback(&FlushCallback, this)); |
| } |
| -} // namespace gamepad |
| +class GamepadModule : public pp::Module { |
| + public: |
| + GamepadModule() : pp::Module() {} |
| + virtual ~GamepadModule() {} |
| + |
| + // Create and return a GamepadInstance object. |
| + virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| + return new GamepadInstance(instance); |
| + } |
| +}; |
| + |
| +namespace pp { |
| +Module* CreateModule() { return new GamepadModule(); } |
| +} // namespace pp |