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

Unified Diff: native_client_sdk/src/examples/api/gamepad/gamepad.cc

Issue 14607005: [NaCl SDK] Cleanup examples. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698