summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-03 23:16:41 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-03 23:16:41 +0000
commita3c5ad52e9fe36a6c97a43794644fe7c5fd74358 (patch)
tree4a4972189eb6900479f5966fd5cfdcd4cfefe875 /native_client_sdk/src
parentb3685e85e624e4ee8a8fa50f44d9c533af2575fe (diff)
downloadchromium_src-a3c5ad52e9fe36a6c97a43794644fe7c5fd74358.zip
chromium_src-a3c5ad52e9fe36a6c97a43794644fe7c5fd74358.tar.gz
chromium_src-a3c5ad52e9fe36a6c97a43794644fe7c5fd74358.tar.bz2
[NaCl SDK] Ran clang-format on the SDK examples.
BUG=none R=noelallen@chromium.org Review URL: https://codereview.chromium.org/14061009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src')
-rw-r--r--native_client_sdk/src/examples/api/audio/sine_synth.cc21
-rw-r--r--native_client_sdk/src/examples/api/core/core.cc15
-rw-r--r--native_client_sdk/src/examples/api/file_io/file_io.cc45
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad.cc8
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad.h18
-rw-r--r--native_client_sdk/src/examples/api/gamepad/gamepad_module.cc6
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/hello_world.cc221
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/matrix.cc110
-rw-r--r--native_client_sdk/src/examples/api/graphics_3d/matrix.h20
-rw-r--r--native_client_sdk/src/examples/api/input_event/custom_events.cc53
-rw-r--r--native_client_sdk/src/examples/api/input_event/custom_events.h92
-rw-r--r--native_client_sdk/src/examples/api/input_event/input_events.cc215
-rw-r--r--native_client_sdk/src/examples/api/input_event/shared_queue.h169
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/mouselock.cc106
-rw-r--r--native_client_sdk/src/examples/api/mouse_lock/mouselock.h9
-rw-r--r--native_client_sdk/src/examples/api/url_loader/geturl.cc6
-rw-r--r--native_client_sdk/src/examples/api/url_loader/geturl_handler.cc21
-rw-r--r--native_client_sdk/src/examples/api/url_loader/geturl_handler.h8
-rw-r--r--native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc27
-rw-r--r--native_client_sdk/src/examples/api/websocket/websocket.cc15
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/handlers.c22
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/handlers.h2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/queue.c8
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/queue.h2
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc16
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator.h21
-rw-r--r--native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc4
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/callback.h32
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/cube.cc59
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/cube.h15
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.cc26
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.h18
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/opengl_context_ptrs.h1
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.cc9
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.h4
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/shader_util.cc6
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/shader_util.h6
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/transforms.cc14
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/transforms.h3
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc31
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h7
-rw-r--r--native_client_sdk/src/examples/fullscreen_tumbler/tumbler_module.cc9
-rw-r--r--native_client_sdk/src/examples/getting_started/hello_world/hello_world.c30
-rw-r--r--native_client_sdk/src/examples/getting_started/hello_world_ppapi_main/hello_world.c5
-rw-r--r--native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc152
-rw-r--r--native_client_sdk/src/examples/hello_world_instance3d/matrix.cc104
-rw-r--r--native_client_sdk/src/examples/hello_world_instance3d/matrix.h20
-rw-r--r--native_client_sdk/src/examples/hello_world_interactive/hello_world.cc13
-rw-r--r--native_client_sdk/src/examples/hello_world_interactive/helper_functions.cc5
-rw-r--r--native_client_sdk/src/examples/hello_world_interactive/helper_functions.h1
-rw-r--r--native_client_sdk/src/examples/pong/pong_input.cc7
-rw-r--r--native_client_sdk/src/examples/pong/pong_instance.cc26
-rw-r--r--native_client_sdk/src/examples/pong/pong_model.cc49
-rw-r--r--native_client_sdk/src/examples/pong/pong_module.cc4
-rw-r--r--native_client_sdk/src/examples/pong/pong_view.cc14
-rw-r--r--native_client_sdk/src/examples/pong/pong_view.h3
-rw-r--r--native_client_sdk/src/examples/tutorial/debugging/hello_world.c62
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc53
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/eightball.cc16
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/eightball.h3
-rw-r--r--native_client_sdk/src/examples/tutorial/dlopen/reverse.h4
-rw-r--r--native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc6
-rw-r--r--native_client_sdk/src/libraries/error_handling/string_stream.c11
-rw-r--r--native_client_sdk/src/libraries/error_handling/string_stream.h11
65 files changed, 966 insertions, 1135 deletions
diff --git a/native_client_sdk/src/examples/api/audio/sine_synth.cc b/native_client_sdk/src/examples/api/audio/sine_synth.cc
index 99bdf7f..3e31930 100644
--- a/native_client_sdk/src/examples/api/audio/sine_synth.cc
+++ b/native_client_sdk/src/examples/api/audio/sine_synth.cc
@@ -113,16 +113,13 @@ bool SineSynthInstance::Init(uint32_t argc,
const char* argn[],
const char* argv[]) {
// Ask the device for an appropriate sample count size.
- sample_frame_count_ =
- pp::AudioConfig::RecommendSampleFrameCount(this,
- PP_AUDIOSAMPLERATE_44100,
- kSampleFrameCount);
- audio_ = pp::Audio(this,
- pp::AudioConfig(this,
- PP_AUDIOSAMPLERATE_44100,
- sample_frame_count_),
- SineWaveCallback,
- this);
+ sample_frame_count_ = pp::AudioConfig::RecommendSampleFrameCount(
+ this, PP_AUDIOSAMPLERATE_44100, kSampleFrameCount);
+ audio_ = pp::Audio(
+ this,
+ pp::AudioConfig(this, PP_AUDIOSAMPLERATE_44100, sample_frame_count_),
+ SineWaveCallback,
+ this);
return true;
}
@@ -178,7 +175,5 @@ class SineSynthModule : public pp::Module {
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() {
- return new sine_synth::SineSynthModule();
-}
+Module* CreateModule() { return new sine_synth::SineSynthModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/core/core.cc b/native_client_sdk/src/examples/api/core/core.cc
index faf176b..5948969 100644
--- a/native_client_sdk/src/examples/api/core/core.cc
+++ b/native_client_sdk/src/examples/api/core/core.cc
@@ -9,7 +9,6 @@
#include "ppapi/cpp/var.h"
#include "ppapi/utility/completion_callback_factory.h"
-
/// The Instance class. One of these exists for each instance of your NaCl
/// module on the web page. The browser will ask the Module object to create
/// a new Instance for each occurrence of the <embed> tag that has these
@@ -21,9 +20,7 @@ class CoreInstance : public pp::Instance {
/// The constructor creates the plugin-side instance.
/// @param[in] instance the handle to the browser-side plugin instance.
explicit CoreInstance(PP_Instance instance)
- : pp::Instance(instance),
- callback_factory_(this) {
- }
+ : pp::Instance(instance), callback_factory_(this) {}
private:
/// Handler for messages coming in from the browser via postMessage(). The
@@ -36,8 +33,7 @@ class CoreInstance : public pp::Instance {
// If a delay is requested, issue a callback after delay ms.
last_receive_time_ = pp::Module::Get()->core()->GetTimeTicks();
pp::Module::Get()->core()->CallOnMainThread(
- delay, callback_factory_.NewCallback(&CoreInstance::DelayedPost),
- 0);
+ delay, callback_factory_.NewCallback(&CoreInstance::DelayedPost), 0);
} else {
// If no delay is requested, reply immediately with zero time elapsed.
pp::Var msg(0);
@@ -47,8 +43,7 @@ class CoreInstance : public pp::Instance {
void DelayedPost(int32_t) {
// Send the time elapsed until the callbacked fired.
- pp::Var msg(
- pp::Module::Get()->core()->GetTimeTicks() - last_receive_time_);
+ pp::Var msg(pp::Module::Get()->core()->GetTimeTicks() - last_receive_time_);
PostMessage(msg);
}
@@ -68,7 +63,5 @@ class CoreModule : public pp::Module {
};
namespace pp {
-Module* CreateModule() {
- return new CoreModule();
-}
+Module* CreateModule() { return new CoreModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/file_io/file_io.cc b/native_client_sdk/src/examples/api/file_io/file_io.cc
index 6803982..9de72f8 100644
--- a/native_client_sdk/src/examples/api/file_io/file_io.cc
+++ b/native_client_sdk/src/examples/api/file_io/file_io.cc
@@ -56,15 +56,13 @@ class FileIoInstance : public pp::Instance {
callback_factory_(this),
file_system_(this, PP_FILESYSTEMTYPE_LOCALPERSISTENT),
file_system_ready_(false),
- file_thread_(this) {
- }
+ file_thread_(this) {}
- virtual ~FileIoInstance() {
- file_thread_.Join();
- }
+ virtual ~FileIoInstance() { file_thread_.Join(); }
- virtual bool Init(uint32_t /*argc*/, const char* /*argn*/[],
- const char* /*argv*/[]) {
+ virtual bool Init(uint32_t /*argc*/,
+ const char * /*argn*/ [],
+ const char * /*argv*/ []) {
file_thread_.Start();
// Open the file system on the file_thread_. Since this is the first
// operation we perform there, and because we do everything on the
@@ -125,10 +123,8 @@ class FileIoInstance : public pp::Instance {
// Read the rest of the message as the file text
reader.ignore(1); // Eat the delimiter
std::string file_text = message.substr(reader.tellg());
- file_thread_.message_loop().PostWork(
- callback_factory_.NewCallback(&FileIoInstance::Save,
- file_name,
- file_text));
+ file_thread_.message_loop().PostWork(callback_factory_.NewCallback(
+ &FileIoInstance::Save, file_name, file_text));
return;
}
@@ -140,7 +136,7 @@ class FileIoInstance : public pp::Instance {
}
void OpenFileSystem(int32_t /* result */) {
- int32_t rv = file_system_.Open(1024*1024, pp::CompletionCallback());
+ int32_t rv = file_system_.Open(1024 * 1024, pp::CompletionCallback());
if (rv == PP_OK) {
file_system_ready_ = true;
// Notify the user interface that we're ready
@@ -150,7 +146,8 @@ class FileIoInstance : public pp::Instance {
}
}
- void Save(int32_t /* result */, const std::string& file_name,
+ void Save(int32_t /* result */,
+ const std::string& file_name,
const std::string& file_contents) {
if (!file_system_ready_) {
ShowErrorMessage("File system is not open", PP_ERROR_FAILED);
@@ -159,10 +156,11 @@ class FileIoInstance : public pp::Instance {
pp::FileRef ref(file_system_, file_name.c_str());
pp::FileIO file(this);
- int32_t open_result = file.Open(
- ref,
- PP_FILEOPENFLAG_WRITE|PP_FILEOPENFLAG_CREATE|PP_FILEOPENFLAG_TRUNCATE,
- pp::CompletionCallback());
+ int32_t open_result =
+ file.Open(ref,
+ PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE |
+ PP_FILEOPENFLAG_TRUNCATE,
+ pp::CompletionCallback());
if (open_result != PP_OK) {
ShowErrorMessage("File open for write failed", open_result);
return;
@@ -207,8 +205,8 @@ class FileIoInstance : public pp::Instance {
pp::FileRef ref(file_system_, file_name.c_str());
pp::FileIO file(this);
- int32_t open_result = file.Open(ref, PP_FILEOPENFLAG_READ,
- pp::CompletionCallback());
+ int32_t open_result =
+ file.Open(ref, PP_FILEOPENFLAG_READ, pp::CompletionCallback());
if (open_result == PP_ERROR_FILENOTFOUND) {
ShowStatusMessage("File not found");
return;
@@ -232,7 +230,9 @@ class FileIoInstance : public pp::Instance {
int64_t offset = 0;
int32_t bytes_read = 0;
do {
- bytes_read = file.Read(offset, &data[offset], data.size() - offset,
+ bytes_read = file.Read(offset,
+ &data[offset],
+ data.size() - offset,
pp::CompletionCallback());
if (bytes_read > 0)
offset += bytes_read;
@@ -304,8 +304,5 @@ namespace pp {
/// CreateInstance() method on the object you return to make instances. There
/// is one instance per <embed> tag on the page. This is the main binding
/// point for your NaCl module with the browser.
-Module* CreateModule() {
- return new FileIoModule();
-}
+Module* CreateModule() { return new FileIoModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad.cc b/native_client_sdk/src/examples/api/gamepad/gamepad.cc
index 9730e17..8e8b588 100644
--- a/native_client_sdk/src/examples/api/gamepad/gamepad.cc
+++ b/native_client_sdk/src/examples/api/gamepad/gamepad.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Native Client Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -67,7 +67,11 @@ void Gamepad::DidChangeView(const pp::View& view) {
Paint();
}
-void FillRect(pp::ImageData* image, int left, int top, int width, int height,
+void FillRect(pp::ImageData* image,
+ int left,
+ int top,
+ int width,
+ int height,
uint32_t color) {
for (int y = std::max(0, top);
y < std::min(image->size().height() - 1, top + height);
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad.h b/native_client_sdk/src/examples/api/gamepad/gamepad.h
index dcb92de..67649e0 100644
--- a/native_client_sdk/src/examples/api/gamepad/gamepad.h
+++ b/native_client_sdk/src/examples/api/gamepad/gamepad.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Native Client Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -34,9 +34,7 @@ class Gamepad : public pp::Instance {
// Flushes its contents of |pixel_buffer_| to the 2D graphics context.
void Paint();
- bool quit() const {
- return quit_;
- }
+ bool quit() const { return quit_; }
int width() const {
return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
@@ -47,12 +45,8 @@ class Gamepad : public pp::Instance {
// Indicate whether a flush is pending. This can only be called from the
// main thread; it is not thread safe.
- bool flush_pending() const {
- return flush_pending_;
- }
- void set_flush_pending(bool flag) {
- flush_pending_ = flag;
- }
+ bool flush_pending() const { return flush_pending_; }
+ void set_flush_pending(bool flag) { flush_pending_ = flag; }
private:
// Create and initialize the 2D context used for drawing.
@@ -64,9 +58,7 @@ class Gamepad : public pp::Instance {
// and do not flush.
void FlushPixelBuffer();
- bool IsContextValid() const {
- return graphics_2d_context_ != NULL;
- }
+ bool IsContextValid() const { return graphics_2d_context_ != NULL; }
pp::Graphics2D* graphics_2d_context_;
pp::ImageData* pixel_buffer_;
diff --git a/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc b/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc
index cac2570..f24968c 100644
--- a/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc
+++ b/native_client_sdk/src/examples/api/gamepad/gamepad_module.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Native Client Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -28,7 +28,5 @@ class GamepadModule : public pp::Module {
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() {
- return new gamepad::GamepadModule();
-}
+Module* CreateModule() { return new gamepad::GamepadModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc b/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc
index fc6e3df..9ba1941 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc
+++ b/native_client_sdk/src/examples/api/graphics_3d/hello_world.cc
@@ -57,12 +57,12 @@ static PPB_URLLoader* ppb_urlloader_interface = NULL;
static PP_Instance g_instance;
static PP_Resource g_context;
-GLuint g_positionLoc;
-GLuint g_texCoordLoc;
-GLuint g_colorLoc;
-GLuint g_MVPLoc;
-GLuint g_vboID;
-GLuint g_ibID;
+GLuint g_positionLoc;
+GLuint g_texCoordLoc;
+GLuint g_colorLoc;
+GLuint g_MVPLoc;
+GLuint g_vboID;
+GLuint g_ibID;
GLubyte g_Indices[36];
GLuint g_programObj;
@@ -78,24 +78,23 @@ float g_fSpinY = 0.0f;
//-----------------------------------------------------------------------------
// Rendering Assets
//-----------------------------------------------------------------------------
-struct Vertex
-{
+struct Vertex {
float tu, tv;
float color[3];
float loc[3];
};
-Vertex *g_quadVertices = NULL;
-const char *g_TextureData = NULL;
-const char *g_VShaderData = NULL;
-const char *g_FShaderData = NULL;
+Vertex* g_quadVertices = NULL;
+const char* g_TextureData = NULL;
+const char* g_VShaderData = NULL;
+const char* g_FShaderData = NULL;
int g_LoadCnt = 0;
//-----------------------------------------------------------------------------
// PROTOTYPES
//-----------------------------------------------------------------------------
-void PostMessage(const char *fmt, ...);
-char* LoadFile(const char *fileName);
+void PostMessage(const char* fmt, ...);
+char* LoadFile(const char* fileName);
void BuildQuad(Vertex* verts, int axis[3], float depth, float color[3]);
Vertex* BuildCube(void);
@@ -104,7 +103,6 @@ void InitGL(void);
void InitProgram(void);
void Render(void);
-
static struct PP_Var CStrToVar(const char* str) {
if (ppb_var_interface != NULL) {
return ppb_var_interface->VarFromUtf8(str, strlen(str));
@@ -112,8 +110,7 @@ static struct PP_Var CStrToVar(const char* str) {
return PP_MakeUndefined();
}
-
-void PostMessage(const char *fmt, ...) {
+void PostMessage(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
@@ -141,8 +138,7 @@ void MainLoop(void* foo, int bar) {
}
}
-void InitGL(void)
-{
+void InitGL(void) {
int32_t attribs[] = {
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
@@ -154,34 +150,30 @@ void InitGL(void)
PP_GRAPHICS3DATTRIB_NONE
};
- g_context = ppb_g3d_interface->Create(g_instance, 0, attribs);
+ g_context = ppb_g3d_interface->Create(g_instance, 0, attribs);
int32_t success = ppb_instance_interface->BindGraphics(g_instance, g_context);
- if (success == PP_FALSE)
- {
+ if (success == PP_FALSE) {
glSetCurrentContextPPAPI(0);
printf("Failed to set context.\n");
return;
}
glSetCurrentContextPPAPI(g_context);
- glViewport(0,0, 640,480);
- glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
+ glViewport(0, 0, 640, 480);
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
-
-GLuint compileShader(GLenum type, const char *data) {
- const char *shaderStrings[1];
+GLuint compileShader(GLenum type, const char* data) {
+ const char* shaderStrings[1];
shaderStrings[0] = data;
GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, shaderStrings, NULL );
+ glShaderSource(shader, 1, shaderStrings, NULL);
glCompileShader(shader);
return shader;
}
-
-void InitProgram( void )
-{
+void InitProgram(void) {
glSetCurrentContextPPAPI(g_context);
g_vertexShader = compileShader(GL_VERTEX_SHADER, g_VShaderData);
@@ -194,12 +186,16 @@ void InitProgram( void )
glGenBuffers(1, &g_vboID);
glBindBuffer(GL_ARRAY_BUFFER, g_vboID);
- glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(Vertex), (void*)&g_quadVertices[0],
+ glBufferData(GL_ARRAY_BUFFER,
+ 24 * sizeof(Vertex),
+ (void*)&g_quadVertices[0],
GL_STATIC_DRAW);
glGenBuffers(1, &g_ibID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ibID);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(char), (void*)&g_Indices[0],
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ 36 * sizeof(char),
+ (void*)&g_Indices[0],
GL_STATIC_DRAW);
//
@@ -207,9 +203,16 @@ void InitProgram( void )
//
glGenTextures(1, &g_textureID);
glBindTexture(GL_TEXTURE_2D, g_textureID);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE,
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D,
+ 0,
+ GL_RGB,
+ 128,
+ 128,
+ 0,
+ GL_RGB,
+ GL_UNSIGNED_BYTE,
g_TextureData);
//
@@ -222,7 +225,6 @@ void InitProgram( void )
g_MVPLoc = glGetUniformLocation(g_programObj, "a_MVP");
}
-
void BuildQuad(Vertex* verts, int axis[3], float depth, float color[3]) {
static float X[4] = { -1.0f, 1.0f, 1.0f, -1.0f };
static float Y[4] = { -1.0f, -1.0f, 1.0f, 1.0f };
@@ -233,14 +235,13 @@ void BuildQuad(Vertex* verts, int axis[3], float depth, float color[3]) {
verts[i].loc[axis[0]] = X[i] * depth;
verts[i].loc[axis[1]] = Y[i] * depth;
verts[i].loc[axis[2]] = depth;
- for (int j = 0; j < 3; j++)
+ for (int j = 0; j < 3; j++)
verts[i].color[j] = color[j] * (Y[i] + 1.0f) / 2.0f;
}
}
-
-Vertex *BuildCube() {
- Vertex *verts = new Vertex[24];
+Vertex* BuildCube() {
+ Vertex* verts = new Vertex[24];
for (int i = 0; i < 3; i++) {
int Faxis[3];
int Baxis[3];
@@ -258,38 +259,38 @@ Vertex *BuildCube() {
BuildQuad(&verts[12 + i * 4], Baxis, -1.0f, Bcolor);
}
- for(int i = 0; i < 6; i++) {
- g_Indices[i*6 + 0] = 2 + i * 4;
- g_Indices[i*6 + 1] = 1 + i * 4;
- g_Indices[i*6 + 2] = 0 + i * 4;
- g_Indices[i*6 + 3] = 3 + i * 4;
- g_Indices[i*6 + 4] = 2 + i * 4;
- g_Indices[i*6 + 5] = 0 + i * 4;
+ for (int i = 0; i < 6; i++) {
+ g_Indices[i * 6 + 0] = 2 + i * 4;
+ g_Indices[i * 6 + 1] = 1 + i * 4;
+ g_Indices[i * 6 + 2] = 0 + i * 4;
+ g_Indices[i * 6 + 3] = 3 + i * 4;
+ g_Indices[i * 6 + 4] = 2 + i * 4;
+ g_Indices[i * 6 + 5] = 0 + i * 4;
}
return verts;
}
-
-void Render( void )
-{
+void Render(void) {
static float xRot = 0.0;
static float yRot = 0.0;
xRot += 2.0f;
yRot += 0.5f;
- if (xRot >= 360.0f) xRot = 0.0;
- if (yRot >= 360.0f) yRot = 0.0;
+ if (xRot >= 360.0f)
+ xRot = 0.0;
+ if (yRot >= 360.0f)
+ yRot = 0.0;
- glClearColor(0.5,0.5,0.5,1);
+ glClearColor(0.5, 0.5, 0.5, 1);
glClearDepthf(1.0);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//set what program to use
- glUseProgram( g_programObj );
- glActiveTexture ( GL_TEXTURE0 );
- glBindTexture ( GL_TEXTURE_2D,g_textureID );
- glUniform1i ( g_textureLoc, 0 );
+ glUseProgram(g_programObj);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, g_textureID);
+ glUniform1i(g_textureLoc, 0);
//create our perspective matrix
float mpv[16];
@@ -297,32 +298,43 @@ void Render( void )
float rot[16];
identity_matrix(mpv);
- glhPerspectivef2(&mpv[0], 45.0f, 640.0f / 480.0f,1, 10);
+ glhPerspectivef2(&mpv[0], 45.0f, 640.0f / 480.0f, 1, 10);
translate_matrix(0, 0, -4.0, trs);
- rotate_matrix(xRot, yRot , 0.0f ,rot);
+ rotate_matrix(xRot, yRot, 0.0f, rot);
multiply_matrix(trs, rot, trs);
multiply_matrix(mpv, trs, mpv);
- glUniformMatrix4fv(g_MVPLoc, 1, GL_FALSE, (GLfloat*) mpv);
+ glUniformMatrix4fv(g_MVPLoc, 1, GL_FALSE, (GLfloat*)mpv);
//define the attributes of the vertex
glBindBuffer(GL_ARRAY_BUFFER, g_vboID);
- glVertexAttribPointer(g_positionLoc, 3, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,loc));
+ glVertexAttribPointer(g_positionLoc,
+ 3,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, loc));
glEnableVertexAttribArray(g_positionLoc);
- glVertexAttribPointer(g_texCoordLoc, 2, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,tu));
+ glVertexAttribPointer(g_texCoordLoc,
+ 2,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, tu));
glEnableVertexAttribArray(g_texCoordLoc);
- glVertexAttribPointer(g_colorLoc, 3, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,color));
+ glVertexAttribPointer(g_colorLoc,
+ 3,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, color));
glEnableVertexAttribArray(g_colorLoc);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ibID);
- glDrawElements ( GL_TRIANGLES, 36, GL_UNSIGNED_BYTE ,0 );
+ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0);
}
-
-typedef void (*OpenCB)(void *dataPtr);
+typedef void (*OpenCB)(void* dataPtr);
struct OpenRequest {
PP_Resource loader_;
PP_Resource request_;
@@ -333,7 +345,6 @@ struct OpenRequest {
OpenCB cb_;
};
-
void FreeRequest(OpenRequest* req) {
if (req) {
ppb_core_interface->ReleaseResource(req->request_);
@@ -342,9 +353,8 @@ void FreeRequest(OpenRequest* req) {
}
}
-
static void URLPartialRead(void* user_data, int mode) {
- OpenRequest* req = (OpenRequest *) user_data;
+ OpenRequest* req = (OpenRequest*)user_data;
int64_t total;
int32_t cnt;
@@ -361,8 +371,10 @@ static void URLPartialRead(void* user_data, int mode) {
cnt = (total > LONG_MAX) ? LONG_MAX : (int32_t) total;
// If we still have more to do, re-issue the read.
if (cnt > 0) {
- int32_t bytes = ppb_urlloader_interface->ReadResponseBody(req->loader_,
- (void *) &req->buf_[req->avail_], cnt,
+ int32_t bytes = ppb_urlloader_interface->ReadResponseBody(
+ req->loader_,
+ (void*)&req->buf_[req->avail_],
+ cnt,
PP_MakeCompletionCallback(URLPartialRead, req));
// If the reissue completes immediately, then process it.
@@ -370,17 +382,16 @@ static void URLPartialRead(void* user_data, int mode) {
URLPartialRead(user_data, bytes);
}
return;
- }
-
+ }
+
// Nothing left, so signal complete.
req->cb_(req);
FreeRequest(req);
printf("Loaded\n");
}
-
static void URLOpened(void* user_data, int mode) {
- OpenRequest* req = (OpenRequest *) user_data;
+ OpenRequest* req = (OpenRequest*)user_data;
int64_t cur, total;
int32_t cnt;
@@ -397,21 +408,25 @@ static void URLOpened(void* user_data, int mode) {
// Otherwise allocate a buffer with enough space for a terminating
// NULL in case we need one.
cnt = (total > LONG_MAX) ? LONG_MAX : (int32_t) total;
- req->buf_ = (char *) malloc(cnt + 1);
+ req->buf_ = (char*)malloc(cnt + 1);
req->buf_[cnt] = 0;
req->size_ = cnt;
- int32_t bytes = ppb_urlloader_interface->ReadResponseBody(req->loader_,
- req->buf_, cnt, PP_MakeCompletionCallback(URLPartialRead, req));
+ int32_t bytes = ppb_urlloader_interface->ReadResponseBody(
+ req->loader_,
+ req->buf_,
+ cnt,
+ PP_MakeCompletionCallback(URLPartialRead, req));
// Usually we are pending.
- if (bytes == PP_OK_COMPLETIONPENDING) return;
+ if (bytes == PP_OK_COMPLETIONPENDING)
+ return;
// But if we did complete the read, then dispatch the handler.
URLPartialRead(req, bytes);
}
-void LoadURL(PP_Instance inst, const char *url, OpenCB cb, void *data) {
- OpenRequest* req = (OpenRequest*) malloc(sizeof(OpenRequest));
+void LoadURL(PP_Instance inst, const char* url, OpenCB cb, void* data) {
+ OpenRequest* req = (OpenRequest*)malloc(sizeof(OpenRequest));
memset(req, 0, sizeof(OpenRequest));
req->loader_ = ppb_urlloader_interface->Create(inst);
@@ -425,15 +440,17 @@ void LoadURL(PP_Instance inst, const char *url, OpenCB cb, void *data) {
return;
}
- ppb_urlrequestinfo_interface->SetProperty(req->request_,
- PP_URLREQUESTPROPERTY_URL, CStrToVar(url));
- ppb_urlrequestinfo_interface->SetProperty(req->request_,
- PP_URLREQUESTPROPERTY_METHOD, CStrToVar("GET"));
- ppb_urlrequestinfo_interface->SetProperty(req->request_,
- PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, PP_MakeBool(PP_TRUE));
+ ppb_urlrequestinfo_interface->SetProperty(
+ req->request_, PP_URLREQUESTPROPERTY_URL, CStrToVar(url));
+ ppb_urlrequestinfo_interface->SetProperty(
+ req->request_, PP_URLREQUESTPROPERTY_METHOD, CStrToVar("GET"));
+ ppb_urlrequestinfo_interface->SetProperty(
+ req->request_,
+ PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS,
+ PP_MakeBool(PP_TRUE));
- int val = ppb_urlloader_interface->Open(req->loader_, req->request_,
- PP_MakeCompletionCallback(URLOpened, req));
+ int val = ppb_urlloader_interface->Open(
+ req->loader_, req->request_, PP_MakeCompletionCallback(URLOpened, req));
if (val != PP_OK_COMPLETIONPENDING) {
cb(NULL);
@@ -442,9 +459,9 @@ void LoadURL(PP_Instance inst, const char *url, OpenCB cb, void *data) {
}
void Loaded(void* data) {
- OpenRequest *req = (OpenRequest *) data;
+ OpenRequest* req = (OpenRequest*)data;
if (req && req->buf_) {
- char **pptr = (char **) req->data_;
+ char** pptr = (char**)req->data_;
*pptr = req->buf_;
g_LoadCnt++;
return;
@@ -452,7 +469,6 @@ void Loaded(void* data) {
PostMessage("Failed to load asset.\n");
}
-
/**
* Called when the NaCl module is instantiated on the web page. The identifier
* of the new instance will be passed in as the first argument (this value is
@@ -487,7 +503,6 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
return PP_TRUE;
}
-
/**
* Called when the NaCl module is destroyed. This will always be called,
* even if DidCreate returned failure. This routine should deallocate any data
@@ -539,9 +554,7 @@ static void Instance_DidChangeView(PP_Instance instance,
* @param[in] has_focus Indicates whether this NaCl module gained or lost
* event focus.
*/
-static void Instance_DidChangeFocus(PP_Instance instance,
- PP_Bool has_focus) {
-}
+static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus) {}
/**
* Handler that gets called after a full-frame module is instantiated based on
@@ -559,7 +572,6 @@ static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
return PP_FALSE;
}
-
/**
* Entry points for the module.
* Initialize needed interfaces: PPB_Core, PPB_Messaging and PPB_Var.
@@ -584,7 +596,6 @@ PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id,
return PP_OK;
}
-
/**
* Returns an interface pointer for the interface of the given name, or NULL
* if the interface is not supported.
@@ -605,9 +616,7 @@ PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
return NULL;
}
-
/**
* Called before the plugin module is unloaded.
*/
-PP_EXPORT void PPP_ShutdownModule() {
-}
+PP_EXPORT void PPP_ShutdownModule() {}
diff --git a/native_client_sdk/src/examples/api/graphics_3d/matrix.cc b/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
index ea6010b..b87d496 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
+++ b/native_client_sdk/src/examples/api/graphics_3d/matrix.cc
@@ -11,41 +11,47 @@
#include <stdlib.h>
#include <string.h>
#include "matrix.h"
-#define deg_to_rad(x) (x * (M_PI/180.0f))
-
-void glhFrustumf2(Matrix_t mat, GLfloat left, GLfloat right, GLfloat bottom,
- GLfloat top, GLfloat znear, GLfloat zfar)
-{
- float temp, temp2, temp3, temp4;
- temp = 2.0f * znear;
- temp2 = right - left;
- temp3 = top - bottom;
- temp4 = zfar - znear;
- mat[0] = temp / temp2;
- mat[1] = 0.0f;
- mat[2] = 0.0f;
- mat[3] = 0.0f;
- mat[4] = 0.0f;
- mat[5] = temp / temp3;
- mat[6] = 0.0f;
- mat[7] = 0.0f;
- mat[8] = (right + left) / temp2;
- mat[9] = (top + bottom) / temp3;
- mat[10] = (-zfar - znear) / temp4;
- mat[11] = -1.0f;
- mat[12] = 0.0f;
- mat[13] = 0.0f;
- mat[14] = (-temp * zfar) / temp4;
- mat[15] = 0.0f;
+#define deg_to_rad(x) (x * (M_PI / 180.0f))
+
+void glhFrustumf2(Matrix_t mat,
+ GLfloat left,
+ GLfloat right,
+ GLfloat bottom,
+ GLfloat top,
+ GLfloat znear,
+ GLfloat zfar) {
+ float temp, temp2, temp3, temp4;
+ temp = 2.0f * znear;
+ temp2 = right - left;
+ temp3 = top - bottom;
+ temp4 = zfar - znear;
+ mat[0] = temp / temp2;
+ mat[1] = 0.0f;
+ mat[2] = 0.0f;
+ mat[3] = 0.0f;
+ mat[4] = 0.0f;
+ mat[5] = temp / temp3;
+ mat[6] = 0.0f;
+ mat[7] = 0.0f;
+ mat[8] = (right + left) / temp2;
+ mat[9] = (top + bottom) / temp3;
+ mat[10] = (-zfar - znear) / temp4;
+ mat[11] = -1.0f;
+ mat[12] = 0.0f;
+ mat[13] = 0.0f;
+ mat[14] = (-temp * zfar) / temp4;
+ mat[15] = 0.0f;
}
-void glhPerspectivef2(Matrix_t mat, GLfloat fovyInDegrees,
- GLfloat aspectRatio, GLfloat znear, GLfloat zfar)
-{
- float ymax, xmax;
- ymax = znear * tanf(fovyInDegrees * 3.14f / 360.0f);
- xmax = ymax * aspectRatio;
- glhFrustumf2(mat, -xmax, xmax, -ymax, ymax, znear, zfar);
+void glhPerspectivef2(Matrix_t mat,
+ GLfloat fovyInDegrees,
+ GLfloat aspectRatio,
+ GLfloat znear,
+ GLfloat zfar) {
+ float ymax, xmax;
+ ymax = znear * tanf(fovyInDegrees * 3.14f / 360.0f);
+ xmax = ymax * aspectRatio;
+ glhFrustumf2(mat, -xmax, xmax, -ymax, ymax, znear, zfar);
}
void identity_matrix(Matrix_t mat) {
@@ -61,23 +67,23 @@ void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat) {
// matrix are the same.
Matrix_t out;
- out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
- out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
- out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
- out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
-
- out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
- out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
- out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
- out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
-
- out[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
- out[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
- out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
- out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
-
- out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
- out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
+ out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
+ out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
+ out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
+ out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
+
+ out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
+ out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
+ out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
+ out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
+
+ out[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
+ out[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
+ out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
+ out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
+
+ out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
+ out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
out[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15];
out[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15];
@@ -108,8 +114,7 @@ void rotate_z_matrix(GLfloat z_rad, Matrix_t mat) {
mat[5] = mat[0];
}
-void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg,
- Matrix_t mat) {
+void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg, Matrix_t mat) {
GLfloat x_rad = (GLfloat) deg_to_rad(x_deg);
GLfloat y_rad = (GLfloat) deg_to_rad(y_deg);
GLfloat z_rad = (GLfloat) deg_to_rad(z_deg);
@@ -133,4 +138,3 @@ void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat) {
mat[13] += y;
mat[14] += z;
}
-
diff --git a/native_client_sdk/src/examples/api/graphics_3d/matrix.h b/native_client_sdk/src/examples/api/graphics_3d/matrix.h
index 7db7985..ed094ed 100644
--- a/native_client_sdk/src/examples/api/graphics_3d/matrix.h
+++ b/native_client_sdk/src/examples/api/graphics_3d/matrix.h
@@ -21,12 +21,19 @@ typedef GLfloat Matrix_t[16];
/// Since GLES2 doesn't have all the nifty matrix transform functions that GL
/// has, we emulate some of them here for the sake of sanity from:
/// http://www.opengl.org/wiki/GluPerspective_code
-void glhFrustumf2(Matrix_t mat, GLfloat left, GLfloat right, GLfloat bottom,
- GLfloat top, GLfloat znear, GLfloat zfar);
-
-void glhPerspectivef2(Matrix_t mat, GLfloat fovyInDegrees,
- GLfloat aspectRatio, GLfloat znear, GLfloat zfar);
-
+void glhFrustumf2(Matrix_t mat,
+ GLfloat left,
+ GLfloat right,
+ GLfloat bottom,
+ GLfloat top,
+ GLfloat znear,
+ GLfloat zfar);
+
+void glhPerspectivef2(Matrix_t mat,
+ GLfloat fovyInDegrees,
+ GLfloat aspectRatio,
+ GLfloat znear,
+ GLfloat zfar);
void identity_matrix(Matrix_t mat);
void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat);
@@ -34,4 +41,3 @@ void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg, Matrix_t mat);
void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat);
#endif // EXAMPLES_HELLO_WORLD_GLES_MATRIX_H
-
diff --git a/native_client_sdk/src/examples/api/input_event/custom_events.cc b/native_client_sdk/src/examples/api/input_event/custom_events.cc
index fe304c5..9f2e6f4 100644
--- a/native_client_sdk/src/examples/api/input_event/custom_events.cc
+++ b/native_client_sdk/src/examples/api/input_event/custom_events.cc
@@ -50,15 +50,12 @@ std::string ModifierToString(uint32_t modifier) {
return s;
}
-
std::string KeyEvent::ToString() const {
std::ostringstream stream;
stream << "Key event:"
<< " modifier:" << string_event_modifiers()
- << " key_code:" << key_code_
- << " time:" << timestamp_
- << " text:" << text_
- << "\n";
+ << " key_code:" << key_code_ << " time:" << timestamp_
+ << " text:" << text_ << "\n";
return stream.str();
}
@@ -67,24 +64,18 @@ std::string MouseEvent::ToString() const {
stream << "Mouse event:"
<< " modifier:" << string_event_modifiers()
<< " button:" << MouseButtonToString(mouse_button_)
- << " x:" << x_position_
- << " y:" << y_position_
- << " click_count:" << click_count_
- << " time:" << timestamp_
- << "\n";
+ << " x:" << x_position_ << " y:" << y_position_
+ << " click_count:" << click_count_ << " time:" << timestamp_ << "\n";
return stream.str();
}
std::string WheelEvent::ToString() const {
std::ostringstream stream;
stream << "Wheel event:"
- << " modifier:" << string_event_modifiers()
- << " deltax:" << delta_x_
- << " deltay:" << delta_y_
- << " wheel_ticks_x:" << ticks_x_
+ << " modifier:" << string_event_modifiers() << " deltax:" << delta_x_
+ << " deltay:" << delta_y_ << " wheel_ticks_x:" << ticks_x_
<< " wheel_ticks_y:" << ticks_y_
- << " scroll_by_page: " << scroll_by_page_
- << " time:" << timestamp_
+ << " scroll_by_page: " << scroll_by_page_ << " time:" << timestamp_
<< "\n";
return stream.str();
}
@@ -101,9 +92,7 @@ std::string MouseEvent::MouseButtonToString(MouseButton button) const {
return "Right";
default:
std::ostringstream stream;
- stream << "Unrecognized ("
- << static_cast<int32_t>(button)
- << ")";
+ stream << "Unrecognized (" << static_cast<int32_t>(button) << ")";
return stream.str();
}
}
@@ -122,15 +111,18 @@ std::string TouchEvent::KindToString(Kind kind) const {
return "Cancel";
default:
std::ostringstream stream;
- stream << "Unrecognized ("
- << static_cast<int32_t>(kind)
- << ")";
+ stream << "Unrecognized (" << static_cast<int32_t>(kind) << ")";
return stream.str();
}
}
-void TouchEvent::AddTouch(uint32_t id, float x, float y, float radii_x,
- float radii_y, float angle, float pressure) {
+void TouchEvent::AddTouch(uint32_t id,
+ float x,
+ float y,
+ float radii_x,
+ float radii_y,
+ float angle,
+ float pressure) {
Touch touch;
touch.id = id;
touch.x = x;
@@ -148,16 +140,15 @@ std::string TouchEvent::ToString() const {
<< " modifier:" << string_event_modifiers();
for (size_t i = 0; i < touches.size(); ++i) {
const Touch& touch = touches[i];
- stream << " x[" << touch.id << "]:" << touch.x
- << " y[" << touch.id << "]:" << touch.y
- << " radii_x[" << touch.id << "]:" << touch.radii_x
- << " radii_y[" << touch.id << "]:" << touch.radii_y
- << " angle[" << touch.id << "]:" << touch.angle
- << " pressure[" << touch.id << "]:" << touch.pressure;
+ stream << " x[" << touch.id << "]:" << touch.x << " y[" << touch.id
+ << "]:" << touch.y << " radii_x[" << touch.id
+ << "]:" << touch.radii_x << " radii_y[" << touch.id
+ << "]:" << touch.radii_y << " angle[" << touch.id
+ << "]:" << touch.angle << " pressure[" << touch.id
+ << "]:" << touch.pressure;
}
stream << " time:" << timestamp_ << "\n";
return stream.str();
}
} // end namespace
-
diff --git a/native_client_sdk/src/examples/api/input_event/custom_events.h b/native_client_sdk/src/examples/api/input_event/custom_events.h
index 2f7b10c..fec2561 100644
--- a/native_client_sdk/src/examples/api/input_event/custom_events.h
+++ b/native_client_sdk/src/examples/api/input_event/custom_events.h
@@ -9,7 +9,6 @@
#include <string>
#include <vector>
-
namespace event_queue {
// These functions and classes are used to define a non-Pepper set of
@@ -43,9 +42,8 @@ class Event {
// |modifiers| is an int that uses bit fields to set specific
// changes, such as the Alt key, specific button, etc. See
// ModifierToString() and constants defined in custom_events.cc.
- explicit Event(uint32_t modifiers)
- : event_modifiers_(modifiers) {}
- uint32_t event_modifiers() const {return event_modifiers_;}
+ explicit Event(uint32_t modifiers) : event_modifiers_(modifiers) {}
+ uint32_t event_modifiers() const { return event_modifiers_; }
std::string string_event_modifiers() const {
return ModifierToString(event_modifiers_);
}
@@ -53,8 +51,8 @@ class Event {
virtual std::string ToString() const = 0;
virtual ~Event() {}
- private:
- uint32_t event_modifiers_;
+ private:
+ uint32_t event_modifiers_;
};
// Class for a keyboard event.
@@ -63,34 +61,44 @@ class KeyEvent : public Event {
// KeyEvent Constructor. |modifiers| is passed to Event base class.
// |keycode| is the ASCII value, |time| is a timestamp,
// |text| is the value as a string.
- KeyEvent(uint32_t modifiers, uint32_t keycode, double time,
- std::string text) :
- Event(modifiers), key_code_(keycode),
- timestamp_(time), text_(text) {}
+ KeyEvent(uint32_t modifiers, uint32_t keycode, double time, std::string text)
+ : Event(modifiers), key_code_(keycode), timestamp_(time), text_(text) {}
// Convert the WheelEvent to a string
virtual std::string ToString() const;
private:
- uint32_t key_code_;
- double timestamp_;
- std::string text_;
+ uint32_t key_code_;
+ double timestamp_;
+ std::string text_;
};
class MouseEvent : public Event {
public:
// Specify a mouse button, with kNone available for initialization.
- enum MouseButton {kNone, kLeft, kMiddle, kRight};
+ enum MouseButton {
+ kNone,
+ kLeft,
+ kMiddle,
+ kRight
+ };
// MouseEvent Constructor. |modifiers| is passed to Event base class.
// |button| specifies which button
// |xpos| and |ypos| give the location,
// |clicks| is how many times this same |xpos|,|ypos|
// has been clicked in a row. |time| is a timestamp,
- MouseEvent(uint32_t modifiers, MouseButton button, uint32_t xpos,
- uint32_t ypos, uint32_t clicks, double time)
- : Event(modifiers), mouse_button_(button),
- x_position_(xpos), y_position_(ypos),
- click_count_(clicks), timestamp_(time) {}
+ MouseEvent(uint32_t modifiers,
+ MouseButton button,
+ uint32_t xpos,
+ uint32_t ypos,
+ uint32_t clicks,
+ double time)
+ : Event(modifiers),
+ mouse_button_(button),
+ x_position_(xpos),
+ y_position_(ypos),
+ click_count_(clicks),
+ timestamp_(time) {}
// Convert the WheelEvent to a string
virtual std::string ToString() const;
@@ -104,19 +112,26 @@ class MouseEvent : public Event {
std::string MouseButtonToString(MouseButton button) const;
};
-
class WheelEvent : public Event {
public:
// WheelEvent Constructor. |modifiers| is passed to Event base class.
// |xticks| and |yticks| specify number of mouse wheel ticks.
// |scroll_by_page| indicates if we have scrolled past the current
// page. |time| is a timestamp,
- WheelEvent(int modifiers, uint32_t dx, uint32_t dy,
- uint32_t xticks, uint32_t yticks, bool scroll_by_page,
- float time) :
- Event(modifiers), delta_x_(dx), delta_y_(dy),
- ticks_x_(xticks), ticks_y_(yticks),
- scroll_by_page_(scroll_by_page), timestamp_(time) {}
+ WheelEvent(int modifiers,
+ uint32_t dx,
+ uint32_t dy,
+ uint32_t xticks,
+ uint32_t yticks,
+ bool scroll_by_page,
+ float time)
+ : Event(modifiers),
+ delta_x_(dx),
+ delta_y_(dy),
+ ticks_x_(xticks),
+ ticks_y_(yticks),
+ scroll_by_page_(scroll_by_page),
+ timestamp_(time) {}
// Convert the WheelEvent to a string
virtual std::string ToString() const;
@@ -129,20 +144,28 @@ class WheelEvent : public Event {
double timestamp_;
};
-
class TouchEvent : public Event {
public:
// The kind of touch event that occurred.
- enum Kind { kNone, kStart, kMove, kEnd, kCancel };
+ enum Kind {
+ kNone,
+ kStart,
+ kMove,
+ kEnd,
+ kCancel
+ };
// TouchEvent constructor.
- TouchEvent(int modifiers, Kind kind, float time) :
- Event(modifiers),
- kind_(kind),
- timestamp_(time) {}
+ TouchEvent(int modifiers, Kind kind, float time)
+ : Event(modifiers), kind_(kind), timestamp_(time) {}
// Add a changed touch to this touch event.
- void AddTouch(uint32_t id, float x, float y, float radii_x, float radii_y,
- float angle, float pressure);
+ void AddTouch(uint32_t id,
+ float x,
+ float y,
+ float radii_x,
+ float radii_y,
+ float angle,
+ float pressure);
// Convert the TouchEvent to a string
virtual std::string ToString() const;
@@ -164,7 +187,6 @@ class TouchEvent : public Event {
double timestamp_;
};
-
} // end namespace
#endif // CUSTOM_EVENTS_H
diff --git a/native_client_sdk/src/examples/api/input_event/input_events.cc b/native_client_sdk/src/examples/api/input_event/input_events.cc
index a216f0a..1a6b19085 100644
--- a/native_client_sdk/src/examples/api/input_event/input_events.cc
+++ b/native_client_sdk/src/examples/api/input_event/input_events.cc
@@ -77,19 +77,15 @@ unsigned int ConvertEventModifier(uint32_t pp_modifier) {
class EventInstance : public pp::Instance {
public:
explicit EventInstance(PP_Instance instance)
- : pp::Instance(instance),
- event_thread_(NULL),
- callback_factory_(this) {
- RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL
- | PP_INPUTEVENT_CLASS_TOUCH);
+ : pp::Instance(instance), event_thread_(NULL), callback_factory_(this) {
+ RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL |
+ PP_INPUTEVENT_CLASS_TOUCH);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
}
// Not guaranteed to be called in Pepper, but a good idea to cancel the
// queue and signal to workers to die if it is called.
- virtual ~EventInstance() {
- CancelQueueAndWaitForWorker();
- }
+ virtual ~EventInstance() { CancelQueueAndWaitForWorker(); }
// Create the 'worker thread'.
bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
@@ -128,7 +124,8 @@ class EventInstance : public pp::Instance {
virtual void HandleMessage(const pp::Var& var_message) {
std::string message = var_message.AsString();
if (kCancelMessage == message) {
- std::string reply = "Received cancel : only Focus events will be "
+ std::string reply =
+ "Received cancel : only Focus events will be "
"displayed. Worker thread for mouse/wheel/keyboard will exit.";
PostMessage(pp::Var(reply));
printf("Calling cancel queue\n");
@@ -153,104 +150,104 @@ class EventInstance : public pp::Instance {
case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
case PP_INPUTEVENT_TYPE_IME_TEXT:
- // these cases are not handled...fall through below...
+ // these cases are not handled...fall through below...
case PP_INPUTEVENT_TYPE_UNDEFINED:
break;
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
case PP_INPUTEVENT_TYPE_MOUSEUP:
case PP_INPUTEVENT_TYPE_MOUSEMOVE:
case PP_INPUTEVENT_TYPE_MOUSEENTER:
- case PP_INPUTEVENT_TYPE_MOUSELEAVE:
- {
- pp::MouseInputEvent mouse_event(event);
- PP_InputEvent_MouseButton pp_button = mouse_event.GetButton();
- MouseEvent::MouseButton mouse_button = MouseEvent::kNone;
- switch (pp_button) {
- case PP_INPUTEVENT_MOUSEBUTTON_NONE:
- mouse_button = MouseEvent::kNone;
- break;
- case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
- mouse_button = MouseEvent::kLeft;
- break;
- case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
- mouse_button = MouseEvent::kMiddle;
- break;
- case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
- mouse_button = MouseEvent::kRight;
- break;
- }
- event_ptr = new MouseEvent(
- ConvertEventModifier(mouse_event.GetModifiers()),
- mouse_button, mouse_event.GetPosition().x(),
- mouse_event.GetPosition().y(), mouse_event.GetClickCount(),
- mouse_event.GetTimeStamp());
- }
- break;
- case PP_INPUTEVENT_TYPE_WHEEL:
- {
- pp::WheelInputEvent wheel_event(event);
- event_ptr = new WheelEvent(
- ConvertEventModifier(wheel_event.GetModifiers()),
- wheel_event.GetDelta().x(), wheel_event.GetDelta().y(),
- wheel_event.GetTicks().x(), wheel_event.GetTicks().y(),
- wheel_event.GetScrollByPage(), wheel_event.GetTimeStamp());
+ case PP_INPUTEVENT_TYPE_MOUSELEAVE: {
+ pp::MouseInputEvent mouse_event(event);
+ PP_InputEvent_MouseButton pp_button = mouse_event.GetButton();
+ MouseEvent::MouseButton mouse_button = MouseEvent::kNone;
+ switch (pp_button) {
+ case PP_INPUTEVENT_MOUSEBUTTON_NONE:
+ mouse_button = MouseEvent::kNone;
+ break;
+ case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
+ mouse_button = MouseEvent::kLeft;
+ break;
+ case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
+ mouse_button = MouseEvent::kMiddle;
+ break;
+ case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
+ mouse_button = MouseEvent::kRight;
+ break;
}
- break;
+ event_ptr =
+ new MouseEvent(ConvertEventModifier(mouse_event.GetModifiers()),
+ mouse_button,
+ mouse_event.GetPosition().x(),
+ mouse_event.GetPosition().y(),
+ mouse_event.GetClickCount(),
+ mouse_event.GetTimeStamp());
+ } break;
+ case PP_INPUTEVENT_TYPE_WHEEL: {
+ pp::WheelInputEvent wheel_event(event);
+ event_ptr =
+ new WheelEvent(ConvertEventModifier(wheel_event.GetModifiers()),
+ wheel_event.GetDelta().x(),
+ wheel_event.GetDelta().y(),
+ wheel_event.GetTicks().x(),
+ wheel_event.GetTicks().y(),
+ wheel_event.GetScrollByPage(),
+ wheel_event.GetTimeStamp());
+ } break;
case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
case PP_INPUTEVENT_TYPE_KEYDOWN:
case PP_INPUTEVENT_TYPE_KEYUP:
case PP_INPUTEVENT_TYPE_CHAR:
- case PP_INPUTEVENT_TYPE_CONTEXTMENU:
- {
- pp::KeyboardInputEvent key_event(event);
- event_ptr = new KeyEvent(
- ConvertEventModifier(key_event.GetModifiers()),
- key_event.GetKeyCode(), key_event.GetTimeStamp(),
- key_event.GetCharacterText().DebugString());
- }
- break;
+ case PP_INPUTEVENT_TYPE_CONTEXTMENU: {
+ pp::KeyboardInputEvent key_event(event);
+ event_ptr = new KeyEvent(ConvertEventModifier(key_event.GetModifiers()),
+ key_event.GetKeyCode(),
+ key_event.GetTimeStamp(),
+ key_event.GetCharacterText().DebugString());
+ } break;
case PP_INPUTEVENT_TYPE_TOUCHSTART:
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
case PP_INPUTEVENT_TYPE_TOUCHEND:
- case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
- {
- pp::TouchInputEvent touch_event(event);
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL: {
+ pp::TouchInputEvent touch_event(event);
- TouchEvent::Kind touch_kind = TouchEvent::kNone;
- if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHSTART)
- touch_kind = TouchEvent::kStart;
- else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHMOVE)
- touch_kind = TouchEvent::kMove;
- else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHEND)
- touch_kind = TouchEvent::kEnd;
- else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHCANCEL)
- touch_kind = TouchEvent::kCancel;
+ TouchEvent::Kind touch_kind = TouchEvent::kNone;
+ if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHSTART)
+ touch_kind = TouchEvent::kStart;
+ else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHMOVE)
+ touch_kind = TouchEvent::kMove;
+ else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHEND)
+ touch_kind = TouchEvent::kEnd;
+ else if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHCANCEL)
+ touch_kind = TouchEvent::kCancel;
- TouchEvent* touch_event_ptr = new TouchEvent(
- ConvertEventModifier(touch_event.GetModifiers()),
- touch_kind, touch_event.GetTimeStamp());
- event_ptr = touch_event_ptr;
+ TouchEvent* touch_event_ptr =
+ new TouchEvent(ConvertEventModifier(touch_event.GetModifiers()),
+ touch_kind,
+ touch_event.GetTimeStamp());
+ event_ptr = touch_event_ptr;
- uint32_t touch_count =
- touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
- for (uint32_t i = 0; i < touch_count; ++i) {
- pp::TouchPoint point = touch_event.GetTouchByIndex(
- PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i);
- touch_event_ptr->AddTouch(point.id(), point.position().x(),
- point.position().y(), point.radii().x(), point.radii().y(),
- point.rotation_angle(), point.pressure());
- }
+ uint32_t touch_count =
+ touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
+ for (uint32_t i = 0; i < touch_count; ++i) {
+ pp::TouchPoint point =
+ touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i);
+ touch_event_ptr->AddTouch(point.id(),
+ point.position().x(),
+ point.position().y(),
+ point.radii().x(),
+ point.radii().y(),
+ point.rotation_angle(),
+ point.pressure());
}
- break;
- default:
- {
- // For any unhandled events, send a message to the browser
- // so that the user is aware of these and can investigate.
- std::stringstream oss;
- oss << "Default (unhandled) event, type=" << event.GetType();
- PostMessage(oss.str());
- }
- break;
+ } break;
+ default: {
+ // For any unhandled events, send a message to the browser
+ // so that the user is aware of these and can investigate.
+ std::stringstream oss;
+ oss << "Default (unhandled) event, type=" << event.GetType();
+ PostMessage(oss.str());
+ } break;
}
event_queue_.Push(event_ptr);
return true;
@@ -260,7 +257,7 @@ class EventInstance : public pp::Instance {
// to occur if the queue is empty. Set |was_queue_cancelled| to indicate
// whether the queue was cancelled. If it was cancelled, then the
// Event* will be NULL.
- const Event* GetEventFromQueue(bool *was_queue_cancelled) {
+ const Event* GetEventFromQueue(bool* was_queue_cancelled) {
Event* event = NULL;
QueueGetResult result = event_queue_.GetItem(&event, kWait);
if (result == kQueueWasCancelled) {
@@ -303,9 +300,8 @@ class EventInstance : public pp::Instance {
// Need to invoke callback on main thread.
pp::Module::Get()->core()->CallOnMainThread(
0,
- event_instance->callback_factory().NewCallback(
- &EventInstance::PostStringToBrowser,
- event_string));
+ event_instance->callback_factory()
+ .NewCallback(&EventInstance::PostStringToBrowser, event_string));
} // end of while loop.
return 0;
}
@@ -317,21 +313,21 @@ class EventInstance : public pp::Instance {
return callback_factory_;
}
- private:
- // Cancels the queue (which will cause the thread to exit).
- // Wait for the thread. Set |event_thread_| to NULL so we only
- // execute the body once.
- void CancelQueueAndWaitForWorker() {
- if (event_thread_) {
- event_queue_.CancelQueue();
- pthread_join(*event_thread_, NULL);
- delete event_thread_;
- event_thread_ = NULL;
- }
+ private:
+ // Cancels the queue (which will cause the thread to exit).
+ // Wait for the thread. Set |event_thread_| to NULL so we only
+ // execute the body once.
+ void CancelQueueAndWaitForWorker() {
+ if (event_thread_) {
+ event_queue_.CancelQueue();
+ pthread_join(*event_thread_, NULL);
+ delete event_thread_;
+ event_thread_ = NULL;
}
- pthread_t* event_thread_;
- LockingQueue<Event*> event_queue_;
- pp::CompletionCallbackFactory<EventInstance> callback_factory_;
+ }
+ pthread_t* event_thread_;
+ LockingQueue<Event*> event_queue_;
+ pp::CompletionCallbackFactory<EventInstance> callback_factory_;
};
// The EventModule provides an implementation of pp::Module that creates
@@ -353,8 +349,5 @@ class EventModule : public pp::Module {
// kind of Module (in this case, EventModule). This is part of the glue code
// that makes our example accessible to ppapi.
namespace pp {
- Module* CreateModule() {
- return new event_queue::EventModule();
- }
+Module* CreateModule() { return new event_queue::EventModule(); }
}
-
diff --git a/native_client_sdk/src/examples/api/input_event/shared_queue.h b/native_client_sdk/src/examples/api/input_event/shared_queue.h
index 48b70b3..ff13996 100644
--- a/native_client_sdk/src/examples/api/input_event/shared_queue.h
+++ b/native_client_sdk/src/examples/api/input_event/shared_queue.h
@@ -34,8 +34,7 @@ enum QueueGetResult {
// pthread_cond_wait so we reimplement a scoped lock here.
class ScopedLock {
public:
- explicit ScopedLock(pthread_mutex_t* mutex)
- : mutex_(mutex) {
+ explicit ScopedLock(pthread_mutex_t* mutex) : mutex_(mutex) {
const int kPthreadMutexSuccess = 0;
if (pthread_mutex_lock(mutex_) != kPthreadMutexSuccess) {
mutex_ = NULL;
@@ -51,7 +50,7 @@ class ScopedLock {
pthread_mutex_t* mutex_; // Weak reference, passed in to constructor.
// Disable copy and assign.
- ScopedLock& operator =(const ScopedLock&);
+ ScopedLock& operator=(const ScopedLock&);
ScopedLock(const ScopedLock&);
};
@@ -59,100 +58,94 @@ class ScopedLock {
// objects or pointers. The Push() method is used to add items to the
// queue in a thread-safe manner. The GetItem() is used to retrieve
// items from the queue in a thread-safe manner.
-template <class T>
-class LockingQueue {
- public:
- LockingQueue() : quit_(false) {
- int result = pthread_mutex_init(&queue_mutex_, NULL);
- assert(result == 0);
- result = pthread_cond_init(&queue_condition_var_, NULL);
- assert(result == 0);
- }
- ~LockingQueue() {
- pthread_mutex_destroy(&queue_mutex_);
- }
-
- // The producer (who instantiates the queue) calls this to tell the
- // consumer that the queue is no longer being used.
- void CancelQueue() {
- ScopedLock scoped_mutex(&queue_mutex_);
- quit_ = true;
- // Signal the condition var so that if a thread is waiting in
- // GetItem the thread will wake up and see that the queue has
- // been cancelled.
- pthread_cond_signal(&queue_condition_var_);
- }
+template <class T> class LockingQueue {
+ public:
+ LockingQueue() : quit_(false) {
+ int result = pthread_mutex_init(&queue_mutex_, NULL);
+ assert(result == 0);
+ result = pthread_cond_init(&queue_condition_var_, NULL);
+ assert(result == 0);
+ }
+ ~LockingQueue() { pthread_mutex_destroy(&queue_mutex_); }
+
+ // The producer (who instantiates the queue) calls this to tell the
+ // consumer that the queue is no longer being used.
+ void CancelQueue() {
+ ScopedLock scoped_mutex(&queue_mutex_);
+ quit_ = true;
+ // Signal the condition var so that if a thread is waiting in
+ // GetItem the thread will wake up and see that the queue has
+ // been cancelled.
+ pthread_cond_signal(&queue_condition_var_);
+ }
- // The consumer calls this to see if the queue has been cancelled by
- // the producer. If so, the thread should not call GetItem and may
- // need to terminate -- i.e. in a case where the producer created
- // the consumer thread.
- bool IsCancelled() {
- ScopedLock scoped_mutex(&queue_mutex_);
- return quit_;
- }
+ // The consumer calls this to see if the queue has been cancelled by
+ // the producer. If so, the thread should not call GetItem and may
+ // need to terminate -- i.e. in a case where the producer created
+ // the consumer thread.
+ bool IsCancelled() {
+ ScopedLock scoped_mutex(&queue_mutex_);
+ return quit_;
+ }
- // Grabs the mutex and pushes a new item to the end of the queue if the
- // queue is not full. Signals the condition variable so that a thread
- // that is waiting will wake up and grab the item.
- void Push(const T& item) {
- ScopedLock scoped_mutex(&queue_mutex_);
- the_queue_.push_back(item);
- pthread_cond_signal(&queue_condition_var_);
- }
+ // Grabs the mutex and pushes a new item to the end of the queue if the
+ // queue is not full. Signals the condition variable so that a thread
+ // that is waiting will wake up and grab the item.
+ void Push(const T& item) {
+ ScopedLock scoped_mutex(&queue_mutex_);
+ the_queue_.push_back(item);
+ pthread_cond_signal(&queue_condition_var_);
+ }
- // Tries to pop the front element from the queue; returns an enum:
- // kReturnedItem if an item is returned in |item_ptr|,
- // kDidNotWait if |wait| was kDontWait and the queue was empty,
- // kQueueWasCancelled if the producer called CancelQueue().
- // If |wait| is kWait, GetItem will wait to return until the queue
- // contains an item (unless the queue is cancelled).
- QueueGetResult GetItem(T* item_ptr, QueueWaitingFlag wait) {
- ScopedLock scoped_mutex(&queue_mutex_);
- // Use a while loop to get an item. If the user does not want to wait,
- // we will exit from the loop anyway, unlocking the mutex.
- // If the user does want to wait, we will wait for pthread_cond_wait,
- // and the while loop will check is_empty_no_locking() one more
- // time so that a spurious wake-up of pthread_cond_wait is handled.
- // If |quit_| has been set, break out of the loop.
- while (!quit_ && is_empty_no_locking()) {
- // If user doesn't want to wait, return...
- if (kDontWait == wait) {
- return kDidNotWait;
- }
- // Wait for signal to occur.
- pthread_cond_wait(&queue_condition_var_, &queue_mutex_);
- }
- // Check to see if quit_ woke us up
- if (quit_) {
- return kQueueWasCancelled;
+ // Tries to pop the front element from the queue; returns an enum:
+ // kReturnedItem if an item is returned in |item_ptr|,
+ // kDidNotWait if |wait| was kDontWait and the queue was empty,
+ // kQueueWasCancelled if the producer called CancelQueue().
+ // If |wait| is kWait, GetItem will wait to return until the queue
+ // contains an item (unless the queue is cancelled).
+ QueueGetResult GetItem(T* item_ptr, QueueWaitingFlag wait) {
+ ScopedLock scoped_mutex(&queue_mutex_);
+ // Use a while loop to get an item. If the user does not want to wait,
+ // we will exit from the loop anyway, unlocking the mutex.
+ // If the user does want to wait, we will wait for pthread_cond_wait,
+ // and the while loop will check is_empty_no_locking() one more
+ // time so that a spurious wake-up of pthread_cond_wait is handled.
+ // If |quit_| has been set, break out of the loop.
+ while (!quit_ && is_empty_no_locking()) {
+ // If user doesn't want to wait, return...
+ if (kDontWait == wait) {
+ return kDidNotWait;
}
-
- // At this point, the queue was either not empty or, if it was empty,
- // we called pthread_cond_wait (which released the mutex, waited for the
- // signal to occur, and then atomically reacquired the mutex).
- // Thus, if we are here, the queue cannot be empty because we either
- // had the mutex and verified it was not empty, or we waited for the
- // producer to put an item in and signal a single thread (us).
- T& item = the_queue_.front();
- *item_ptr = item;
- the_queue_.pop_front();
- return kReturnedItem;
+ // Wait for signal to occur.
+ pthread_cond_wait(&queue_condition_var_, &queue_mutex_);
+ }
+ // Check to see if quit_ woke us up
+ if (quit_) {
+ return kQueueWasCancelled;
}
- private:
- std::deque<T> the_queue_;
- bool quit_;
- pthread_mutex_t queue_mutex_;
- pthread_cond_t queue_condition_var_;
+ // At this point, the queue was either not empty or, if it was empty,
+ // we called pthread_cond_wait (which released the mutex, waited for the
+ // signal to occur, and then atomically reacquired the mutex).
+ // Thus, if we are here, the queue cannot be empty because we either
+ // had the mutex and verified it was not empty, or we waited for the
+ // producer to put an item in and signal a single thread (us).
+ T& item = the_queue_.front();
+ *item_ptr = item;
+ the_queue_.pop_front();
+ return kReturnedItem;
+ }
- // This is used by methods that already have the lock.
- bool is_empty_no_locking() const {
- return the_queue_.empty();
- }
+ private:
+ std::deque<T> the_queue_;
+ bool quit_;
+ pthread_mutex_t queue_mutex_;
+ pthread_cond_t queue_condition_var_;
+
+ // This is used by methods that already have the lock.
+ bool is_empty_no_locking() const { return the_queue_.empty(); }
};
} // end of unnamed namespace
#endif // SHARED_QUEUE_H
-
diff --git a/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc b/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc
index 9aefac1..4305b18 100644
--- a/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc
+++ b/native_client_sdk/src/examples/api/mouse_lock/mouselock.cc
@@ -22,10 +22,10 @@
// view. These values are used to determine which 2D quadrant the needle lies
// in.
typedef enum {
- kLeft = 0,
- kRight = 1,
- kUp = 2,
- kDown = 3
+ kLeft = 0,
+ kRight = 1,
+ kUp = 2,
+ kDown = 3
} MouseDirection;
namespace {
@@ -45,8 +45,7 @@ MouseLockInstance::~MouseLockInstance() {
bool MouseLockInstance::Init(uint32_t argc,
const char* argn[],
const char* argv[]) {
- RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE |
- PP_INPUTEVENT_CLASS_KEYBOARD);
+ RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_KEYBOARD);
return true;
}
@@ -56,8 +55,8 @@ bool MouseLockInstance::HandleInputEvent(const pp::InputEvent& event) {
if (mouse_locked_) {
UnlockMouse();
} else {
- LockMouse(callback_factory_.NewCallback(
- &MouseLockInstance::DidLockMouse));
+ LockMouse(
+ callback_factory_.NewCallback(&MouseLockInstance::DidLockMouse));
}
return true;
}
@@ -123,15 +122,17 @@ void MouseLockInstance::DidChangeView(const pp::View& view) {
if ((size_ == view.GetRect().size()) &&
(was_fullscreen_ == view.IsFullscreen()) && is_context_bound_) {
- Log("DidChangeView SKIP %d,%d FULL=%s CTX Bound=%s",
- view.GetRect().width(), view.GetRect().height(),
- view.IsFullscreen() ? "true" : "false",
- is_context_bound_ ? "true" : "false");
+ Log("DidChangeView SKIP %d,%d FULL=%s CTX Bound=%s",
+ view.GetRect().width(),
+ view.GetRect().height(),
+ view.IsFullscreen() ? "true" : "false",
+ is_context_bound_ ? "true" : "false");
return;
}
Log("DidChangeView DO %d,%d FULL=%s CTX Bound=%s",
- view.GetRect().width(), view.GetRect().height(),
+ view.GetRect().width(),
+ view.GetRect().height(),
view.IsFullscreen() ? "true" : "false",
is_context_bound_ ? "true" : "false");
@@ -181,7 +182,8 @@ void MouseLockInstance::DidLockMouse(int32_t result) {
}
void MouseLockInstance::DidFlush(int32_t result) {
- if (result != 0) Log("Flushed failed with error number %d.\n", result);
+ if (result != 0)
+ Log("Flushed failed with error number %d.\n", result);
waiting_for_flush_completion_ = false;
}
@@ -203,7 +205,6 @@ void MouseLockInstance::Paint() {
callback_factory_.NewCallback(&MouseLockInstance::DidFlush));
}
-
pp::ImageData MouseLockInstance::PaintImage(const pp::Size& size) {
pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false);
if (image.is_null() || image.data() == NULL) {
@@ -252,10 +253,9 @@ void MouseLockInstance::DrawCenterSpot(pp::ImageData* image,
pp::Point left_top(std::max(0, center_x - region_of_interest_radius),
std::max(0, center_y - region_of_interest_radius));
- pp::Point right_bottom(std::min(image->size().width(),
- center_x + region_of_interest_radius),
- std::min(image->size().height(),
- center_y + region_of_interest_radius));
+ pp::Point right_bottom(
+ std::min(image->size().width(), center_x + region_of_interest_radius),
+ std::min(image->size().height(), center_y + region_of_interest_radius));
for (int y = left_top.y(); y < right_bottom.y(); ++y) {
for (int x = left_top.x(); x < right_bottom.x(); ++x) {
if (GetDistance(x, y, center_x, center_y) < kCentralSpotRadius) {
@@ -287,42 +287,38 @@ void MouseLockInstance::DrawNeedle(pp::ImageData* image,
MouseDirection direction = kLeft;
if (abs_mouse_x >= abs_mouse_y) {
- anchor_1.set_x(center_x);
- anchor_1.set_y(center_y - kCentralSpotRadius);
- anchor_2.set_x(center_x);
- anchor_2.set_y(center_y + kCentralSpotRadius);
- direction = (mouse_movement_.x() < 0) ? kLeft : kRight;
- if (direction == kLeft)
- anchor_1.swap(anchor_2);
+ anchor_1.set_x(center_x);
+ anchor_1.set_y(center_y - kCentralSpotRadius);
+ anchor_2.set_x(center_x);
+ anchor_2.set_y(center_y + kCentralSpotRadius);
+ direction = (mouse_movement_.x() < 0) ? kLeft : kRight;
+ if (direction == kLeft)
+ anchor_1.swap(anchor_2);
} else {
- anchor_1.set_x(center_x + kCentralSpotRadius);
- anchor_1.set_y(center_y);
- anchor_2.set_x(center_x - kCentralSpotRadius);
- anchor_2.set_y(center_y);
- direction = (mouse_movement_.y() < 0) ? kUp : kDown;
- if (direction == kUp)
- anchor_1.swap(anchor_2);
+ anchor_1.set_x(center_x + kCentralSpotRadius);
+ anchor_1.set_y(center_y);
+ anchor_2.set_x(center_x - kCentralSpotRadius);
+ anchor_2.set_y(center_y);
+ direction = (mouse_movement_.y() < 0) ? kUp : kDown;
+ if (direction == kUp)
+ anchor_1.swap(anchor_2);
}
pp::Point left_top(std::max(0, center_x - abs_mouse_x),
std::max(0, center_y - abs_mouse_y));
- pp::Point right_bottom(std::min(image->size().width(),
- center_x + abs_mouse_x),
- std::min(image->size().height(),
- center_y + abs_mouse_y));
+ pp::Point right_bottom(
+ std::min(image->size().width(), center_x + abs_mouse_x),
+ std::min(image->size().height(), center_y + abs_mouse_y));
for (int y = left_top.y(); y < right_bottom.y(); ++y) {
for (int x = left_top.x(); x < right_bottom.x(); ++x) {
- bool within_bound_1 =
- ((y - anchor_1.y()) * (vertex.x() - anchor_1.x())) >
- ((vertex.y() - anchor_1.y()) * (x - anchor_1.x()));
- bool within_bound_2 =
- ((y - anchor_2.y()) * (vertex.x() - anchor_2.x())) <
- ((vertex.y() - anchor_2.y()) * (x - anchor_2.x()));
- bool within_bound_3 =
- (direction == kUp && y < center_y) ||
- (direction == kDown && y > center_y) ||
- (direction == kLeft && x < center_x) ||
- (direction == kRight && x > center_x);
+ bool within_bound_1 = ((y - anchor_1.y()) * (vertex.x() - anchor_1.x())) >
+ ((vertex.y() - anchor_1.y()) * (x - anchor_1.x()));
+ bool within_bound_2 = ((y - anchor_2.y()) * (vertex.x() - anchor_2.x())) <
+ ((vertex.y() - anchor_2.y()) * (x - anchor_2.x()));
+ bool within_bound_3 = (direction == kUp && y < center_y) ||
+ (direction == kDown && y > center_y) ||
+ (direction == kLeft && x < center_x) ||
+ (direction == kRight && x > center_x);
if (within_bound_1 && within_bound_2 && within_bound_3) {
*image->GetAddr32(pp::Point(x, y)) = needle_color;
@@ -331,12 +327,13 @@ void MouseLockInstance::DrawNeedle(pp::ImageData* image,
}
}
-
void MouseLockInstance::Log(const char* format, ...) {
- static PPB_Console* console = (PPB_Console*)
- pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE);
+ static PPB_Console* console =
+ (PPB_Console*)pp::Module::Get()->GetBrowserInterface(
+ PPB_CONSOLE_INTERFACE);
- if (NULL == console) return;
+ if (NULL == console)
+ return;
va_list args;
va_start(args, format);
char buf[512];
@@ -366,9 +363,6 @@ class MouseLockModule : public pp::Module {
namespace pp {
// Factory function for your specialization of the Module object.
-Module* CreateModule() {
- return new MouseLockModule();
-}
+Module* CreateModule() { return new MouseLockModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/examples/api/mouse_lock/mouselock.h b/native_client_sdk/src/examples/api/mouse_lock/mouselock.h
index 2844a03..2e1d190 100644
--- a/native_client_sdk/src/examples/api/mouse_lock/mouselock.h
+++ b/native_client_sdk/src/examples/api/mouse_lock/mouselock.h
@@ -37,8 +37,7 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock {
fullscreen_(this),
is_context_bound_(false),
was_fullscreen_(false),
- background_scanline_(NULL) {
- }
+ background_scanline_(NULL) {}
virtual ~MouseLockInstance();
// Called by the browser when the NaCl module is loaded and all ready to go.
@@ -56,8 +55,10 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock {
private:
// Return the Cartesian distance between two points.
- double GetDistance(int point_1_x, int point_1_y,
- int point_2_x, int point_2_y) {
+ double GetDistance(int point_1_x,
+ int point_1_y,
+ int point_2_x,
+ int point_2_y) {
return sqrt(pow(static_cast<double>(point_1_x - point_2_x), 2) +
pow(static_cast<double>(point_1_y - point_2_y), 2));
}
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl.cc b/native_client_sdk/src/examples/api/url_loader/geturl.cc
index fa3838d..db7abe2 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl.cc
+++ b/native_client_sdk/src/examples/api/url_loader/geturl.cc
@@ -69,7 +69,6 @@ void GetURLInstance::HandleMessage(const pp::Var& var_message) {
}
}
-
// The Module class. The browser calls the CreateInstance() method to create
// an instance of you NaCl module on the web page. The browser creates a new
// instance for each <embed> tag with type="application/x-nacl".
@@ -90,8 +89,5 @@ class GetURLModule : public pp::Module {
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() {
- return new GetURLModule();
-}
+Module* CreateModule() { return new GetURLModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc b/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc
index 2000854..e13ca1f 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc
+++ b/native_client_sdk/src/examples/api/url_loader/geturl_handler.cc
@@ -25,8 +25,7 @@ GetURLHandler* GetURLHandler::Create(pp::Instance* instance,
return new GetURLHandler(instance, url);
}
-GetURLHandler::GetURLHandler(pp::Instance* instance,
- const std::string& url)
+GetURLHandler::GetURLHandler(pp::Instance* instance, const std::string& url)
: instance_(instance),
url_(url),
url_request_(instance),
@@ -39,13 +38,12 @@ GetURLHandler::GetURLHandler(pp::Instance* instance,
}
GetURLHandler::~GetURLHandler() {
- delete [] buffer_;
+ delete[] buffer_;
buffer_ = NULL;
}
void GetURLHandler::Start() {
- pp::CompletionCallback cc =
- cc_factory_.NewCallback(&GetURLHandler::OnOpen);
+ pp::CompletionCallback cc = cc_factory_.NewCallback(&GetURLHandler::OnOpen);
url_loader_.Open(url_request_, cc);
}
@@ -87,16 +85,15 @@ void GetURLHandler::AppendDataBytes(const char* buffer, int32_t num_bytes) {
// Note that we do *not* try to minimally increase the amount of allocated
// memory here by calling url_response_body_.reserve(). Doing so causes a
// lot of string reallocations that kills performance for large files.
- url_response_body_.insert(url_response_body_.end(),
- buffer,
- buffer + num_bytes);
+ url_response_body_.insert(
+ url_response_body_.end(), buffer, buffer + num_bytes);
}
void GetURLHandler::OnRead(int32_t result) {
if (result == PP_OK) {
// Streaming the file is complete, delete the read buffer since it is
// no longer needed.
- delete [] buffer_;
+ delete[] buffer_;
buffer_ = NULL;
ReportResultAndDie(url_, url_response_body_, true);
} else if (result > 0) {
@@ -106,9 +103,8 @@ void GetURLHandler::OnRead(int32_t result) {
ReadBody();
} else {
// A read error occurred.
- ReportResultAndDie(url_,
- "pp::URLLoader::ReadResponseBody() result<0",
- false);
+ ReportResultAndDie(
+ url_, "pp::URLLoader::ReadResponseBody() result<0", false);
}
}
@@ -163,4 +159,3 @@ void GetURLHandler::ReportResult(const std::string& fname,
instance_->PostMessage(var_result);
}
}
-
diff --git a/native_client_sdk/src/examples/api/url_loader/geturl_handler.h b/native_client_sdk/src/examples/api/url_loader/geturl_handler.h
index b0ca684..cad71b0 100644
--- a/native_client_sdk/src/examples/api/url_loader/geturl_handler.h
+++ b/native_client_sdk/src/examples/api/url_loader/geturl_handler.h
@@ -34,8 +34,7 @@ class GetURLHandler {
// Creates instance of GetURLHandler on the heap.
// GetURLHandler objects shall be created only on the heap (they
// self-destroy when all data is in).
- static GetURLHandler* Create(pp::Instance* instance_,
- const std::string& url);
+ static GetURLHandler* Create(pp::Instance* instance_, const std::string& url);
// Initiates page (URL) download.
void Start();
@@ -74,10 +73,10 @@ class GetURLHandler {
bool success);
pp::Instance* instance_; // Weak pointer.
- std::string url_; // URL to be downloaded.
+ std::string url_; // URL to be downloaded.
pp::URLRequestInfo url_request_;
pp::URLLoader url_loader_; // URLLoader provides an API to download URLs.
- char* buffer_; // Temporary buffer for reads.
+ char* buffer_; // Temporary buffer for reads.
std::string url_response_body_; // Contains accumulated downloaded data.
pp::CompletionCallbackFactory<GetURLHandler> cc_factory_;
@@ -86,4 +85,3 @@ class GetURLHandler {
};
#endif // EXAMPLES_GETURL_GETURL_HANDLER_H_
-
diff --git a/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc b/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc
index ea8c8e0a..ce293e9 100644
--- a/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc
+++ b/native_client_sdk/src/examples/api/var_array_buffer/file_histogram.cc
@@ -69,10 +69,8 @@ class FileHistogramInstance : public pp::Instance {
: pp::Instance(instance),
callback_factory_(this),
flushing_(false),
- histogram_() {
- }
- virtual ~FileHistogramInstance() {
- }
+ histogram_() {}
+ virtual ~FileHistogramInstance() {}
private:
/// Handler for messages coming in from the browser via postMessage(). The
@@ -95,13 +93,11 @@ class FileHistogramInstance : public pp::Instance {
/// given <code>size</code>.
pp::ImageData MakeBlankImageData(const pp::Size& size) {
const bool init_to_zero = false;
- pp::ImageData image_data = pp::ImageData(this,
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- size,
- init_to_zero);
+ pp::ImageData image_data =
+ pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, init_to_zero);
uint32_t* image_buffer = static_cast<uint32_t*>(image_data.data());
for (int i = 0; i < size.GetArea(); ++i)
- image_buffer[i] = kBlack;
+ image_buffer[i] = kBlack;
return image_data;
}
@@ -147,8 +143,8 @@ class FileHistogramInstance : public pp::Instance {
if (size_ != view.GetRect().size()) {
size_ = view.GetRect().size();
const bool is_always_opaque = true;
- graphics_2d_context_ = pp::Graphics2D(this, view.GetRect().size(),
- is_always_opaque);
+ graphics_2d_context_ =
+ pp::Graphics2D(this, view.GetRect().size(), is_always_opaque);
BindGraphics(graphics_2d_context_);
// The images in our queue are the wrong size, so we won't paint them.
// We'll only draw the most recently computed histogram.
@@ -177,9 +173,8 @@ class FileHistogramInstance : public pp::Instance {
/// <code>paint_queue_</code> to paint later.
void DrawHistogram() {
pp::ImageData image_data = MakeBlankImageData(size_);
- for (int i = 0;
- i < std::min(static_cast<int>(kHistogramSize),
- image_data.size().width());
+ for (int i = 0; i < std::min(static_cast<int>(kHistogramSize),
+ image_data.size().width());
++i) {
DrawBar(i, histogram_[i], &image_data);
}
@@ -231,7 +226,5 @@ namespace pp {
/// CreateInstance() method on the object you return to make instances. There
/// is one instance per <embed> tag on the page. This is the main binding
/// point for your NaCl module with the browser.
-Module* CreateModule() {
- return new FileHistogramModule();
-}
+Module* CreateModule() { return new FileHistogramModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/api/websocket/websocket.cc b/native_client_sdk/src/examples/api/websocket/websocket.cc
index fd42934..bc5949b 100644
--- a/native_client_sdk/src/examples/api/websocket/websocket.cc
+++ b/native_client_sdk/src/examples/api/websocket/websocket.cc
@@ -12,8 +12,7 @@
class WebSocketInstance : public pp::Instance {
public:
explicit WebSocketInstance(PP_Instance instance)
- : pp::Instance(instance),
- websocket_(NULL) {}
+ : pp::Instance(instance), websocket_(NULL) {}
virtual ~WebSocketInstance() {}
virtual void HandleMessage(const pp::Var& var_message);
@@ -112,9 +111,7 @@ void WebSocketInstance::OnConnectCompletion(int32_t result) {
}
void WebSocketInstance::OnCloseCompletion(int32_t result) {
- PostMessage(pp::Var(PP_OK == result ?
- "closed" :
- "abnormally closed"));
+ PostMessage(pp::Var(PP_OK == result ? "closed" : "abnormally closed"));
}
void WebSocketInstance::OnReceiveCompletion(int32_t result) {
@@ -122,8 +119,7 @@ void WebSocketInstance::OnReceiveCompletion(int32_t result) {
if (receive_var_.is_array_buffer())
PostMessage(pp::Var("receive: binary data"));
else
- PostMessage(pp::Var(std::string("receive: ") +
- receive_var_.AsString()));
+ PostMessage(pp::Var(std::string("receive: ") + receive_var_.AsString()));
}
Receive();
}
@@ -158,11 +154,8 @@ class WebSocketModule : public pp::Module {
}
};
-
// Implement the required pp::CreateModule function that creates our specific
// kind of Module.
namespace pp {
-Module* CreateModule() {
- return new WebSocketModule();
-}
+Module* CreateModule() { return new WebSocketModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/demo/nacl_io/handlers.c b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
index c135b08..46d8594 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/handlers.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
@@ -21,7 +21,6 @@
* File. */
static FILE* g_OpenFiles[MAX_OPEN_FILES];
-
/**
* Add the file to the g_OpenFiles map.
* @param[in] file The file to add to g_OpenFiles.
@@ -77,7 +76,6 @@ static FILE* GetFileFromIndexString(const char* s, int* file_index) {
return GetFileFromMap(result);
}
-
/**
* Handle a call to fopen() made by JavaScript.
*
@@ -159,8 +157,8 @@ int HandleFwrite(int num_params, char** params, char** output) {
data_len = strlen(data);
if (!file) {
- *output = PrintfToNewString("Error: Unknown file handle %s.",
- file_index_string);
+ *output =
+ PrintfToNewString("Error: Unknown file handle %s.", file_index_string);
return 2;
}
@@ -172,8 +170,8 @@ int HandleFwrite(int num_params, char** params, char** output) {
return 3;
}
- *output = PrintfToNewString("fwrite\1%s\1%d", file_index_string,
- bytes_written);
+ *output =
+ PrintfToNewString("fwrite\1%s\1%d", file_index_string, bytes_written);
return 0;
}
@@ -210,8 +208,8 @@ int HandleFread(int num_params, char** params, char** output) {
data_len = strtol(params[1], NULL, 10);
if (!file) {
- *output = PrintfToNewString("Error: Unknown file handle %s.",
- file_index_string);
+ *output =
+ PrintfToNewString("Error: Unknown file handle %s.", file_index_string);
return 2;
}
@@ -268,8 +266,8 @@ int HandleFseek(int num_params, char** params, char** output) {
whence = strtol(params[2], NULL, 10);
if (!file) {
- *output = PrintfToNewString("Error: Unknown file handle %s.",
- file_index_string);
+ *output =
+ PrintfToNewString("Error: Unknown file handle %s.", file_index_string);
return 2;
}
@@ -318,8 +316,8 @@ int HandleFclose(int num_params, char** params, char** output) {
file_index_string = params[0];
file = GetFileFromIndexString(file_index_string, &file_index);
if (!file) {
- *output = PrintfToNewString("Error: Unknown file handle %s.",
- file_index_string);
+ *output =
+ PrintfToNewString("Error: Unknown file handle %s.", file_index_string);
return 2;
}
diff --git a/native_client_sdk/src/examples/demo/nacl_io/handlers.h b/native_client_sdk/src/examples/demo/nacl_io/handlers.h
index c059a43..d1cd37b 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/handlers.h
+++ b/native_client_sdk/src/examples/demo/nacl_io/handlers.h
@@ -17,4 +17,4 @@ int HandleFseek(int num_params, char** params, char** output);
int HandleFclose(int num_params, char** params, char** output);
int HandleStat(int num_params, char** params, char** output);
-#endif /* HANDLERS_H_ */
+#endif /* HANDLERS_H_ */
diff --git a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h b/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h
index 82bf056..f3bcd10 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h
+++ b/native_client_sdk/src/examples/demo/nacl_io/hello_nacl_io.h
@@ -15,4 +15,4 @@ char* PrintfToNewString(const char* format, ...);
struct PP_Var PrintfToVar(const char* format, ...);
uint32_t VarToCStr(struct PP_Var var, char* buffer, uint32_t length);
-#endif /* HELLO_NACL_IO_H_ */
+#endif /* HELLO_NACL_IO_H_ */
diff --git a/native_client_sdk/src/examples/demo/nacl_io/queue.c b/native_client_sdk/src/examples/demo/nacl_io/queue.c
index bd0c438..ab96440 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/queue.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/queue.c
@@ -42,17 +42,13 @@ static int g_queue_size = 0;
*
* NOTE: this function assumes g_queue_mutex lock is held.
* @return non-zero if the queue is empty. */
-static int IsQueueEmpty() {
- return g_queue_size == 0;
-}
+static int IsQueueEmpty() { return g_queue_size == 0; }
/** Return whether the queue is full.
*
* NOTE: this function assumes g_queue_mutex lock is held.
* @return non-zero if the queue is full. */
-static int IsQueueFull() {
- return g_queue_size == MAX_QUEUE_SIZE;
-}
+static int IsQueueFull() { return g_queue_size == MAX_QUEUE_SIZE; }
/** Initialize the message queue. */
void InitializeMessageQueue() {
diff --git a/native_client_sdk/src/examples/demo/nacl_io/queue.h b/native_client_sdk/src/examples/demo/nacl_io/queue.h
index f622ee5..c7aff06 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/queue.h
+++ b/native_client_sdk/src/examples/demo/nacl_io/queue.h
@@ -27,4 +27,4 @@ void InitializeMessageQueue();
int EnqueueMessage(char* message);
char* DequeueMessage();
-#endif /* QUEUE_H_ */
+#endif /* QUEUE_H_ */
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
index 1106343f..bada610 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
+++ b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.cc
@@ -46,9 +46,8 @@ class ScopedMutexLock {
if (mutex_)
pthread_mutex_unlock(mutex_);
}
- bool is_valid() const {
- return mutex_ != NULL;
- }
+ bool is_valid() const { return mutex_ != NULL; }
+
private:
pthread_mutex_t* mutex_; // Weak reference.
};
@@ -64,12 +63,11 @@ class ScopedPixelLock {
image_owner_->UnlockPixels();
}
- uint32_t* pixels() const {
- return pixels_;
- }
+ uint32_t* pixels() const { return pixels_; }
+
private:
PiGenerator* image_owner_; // Weak reference.
- uint32_t* pixels_; // Weak reference.
+ uint32_t* pixels_; // Weak reference.
ScopedPixelLock(); // Not implemented, do not use.
};
@@ -124,8 +122,8 @@ void PiGenerator::DidChangeView(const pp::View& view) {
}
bool PiGenerator::Init(uint32_t argc, const char* argn[], const char* argv[]) {
- thread_create_result_ = pthread_create(&compute_pi_thread_, NULL, ComputePi,
- this);
+ thread_create_result_ =
+ pthread_create(&compute_pi_thread_, NULL, ComputePi, this);
return thread_create_result_ == 0;
}
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h
index 50f2dbd..67b4781 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h
+++ b/native_client_sdk/src/examples/demo/pi_generator/pi_generator.h
@@ -56,14 +56,10 @@ class PiGenerator : public pp::Instance {
// method by posting the value back to the browser.
void Paint();
- bool quit() const {
- return quit_;
- }
+ bool quit() const { return quit_; }
// |pi_| is computed in the ComputePi() thread.
- double pi() const {
- return pi_;
- }
+ double pi() const { return pi_; }
int width() const {
return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
@@ -74,12 +70,8 @@ class PiGenerator : public pp::Instance {
// Indicate whether a flush is pending. This can only be called from the
// main thread; it is not thread safe.
- bool flush_pending() const {
- return flush_pending_;
- }
- void set_flush_pending(bool flag) {
- flush_pending_ = flag;
- }
+ bool flush_pending() const { return flush_pending_; }
+ void set_flush_pending(bool flag) { flush_pending_ = flag; }
private:
// Create and initialize the 2D context used for drawing.
@@ -91,9 +83,7 @@ class PiGenerator : public pp::Instance {
// and do not flush.
void FlushPixelBuffer();
- bool IsContextValid() const {
- return graphics_2d_context_ != NULL;
- }
+ bool IsContextValid() const { return graphics_2d_context_ != NULL; }
mutable pthread_mutex_t pixel_buffer_mutex_;
pp::Graphics2D* graphics_2d_context_;
@@ -116,4 +106,3 @@ class PiGenerator : public pp::Instance {
} // namespace pi_generator
#endif // EXAMPLES_PI_GENERATOR_PI_GENERATOR_H_
-
diff --git a/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc b/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc
index 2434a09..e5edebb 100644
--- a/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc
+++ b/native_client_sdk/src/examples/demo/pi_generator/pi_generator_module.cc
@@ -28,7 +28,5 @@ class PiGeneratorModule : public pp::Module {
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() {
- return new pi_generator::PiGeneratorModule();
-}
+Module* CreateModule() { return new pi_generator::PiGeneratorModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/callback.h b/native_client_sdk/src/examples/fullscreen_tumbler/callback.h
index b7664c2..781f759 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/callback.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/callback.h
@@ -35,24 +35,20 @@ typedef std::map<std::string, std::string> MethodParameter;
class MethodCallbackExecutor {
public:
virtual ~MethodCallbackExecutor() {}
- virtual void Execute(
- const ScriptingBridge& bridge,
- const MethodParameter& parameters) = 0;
+ virtual void Execute(const ScriptingBridge& bridge,
+ const MethodParameter& parameters) = 0;
};
-template <class T>
-class MethodCallback : public MethodCallbackExecutor {
+template <class T> class MethodCallback : public MethodCallbackExecutor {
public:
- typedef void (T::*Method)(
- const ScriptingBridge& bridge,
- const MethodParameter& parameters);
+ typedef void(T::* Method)(const ScriptingBridge& bridge,
+ const MethodParameter& parameters);
MethodCallback(T* instance, Method method)
: instance_(instance), method_(method) {}
virtual ~MethodCallback() {}
- virtual void Execute(
- const ScriptingBridge& bridge,
- const MethodParameter& parameters) {
+ virtual void Execute(const ScriptingBridge& bridge,
+ const MethodParameter& parameters) {
// Use "this->" to force C++ to look inside our templatized base class; see
// Effective C++, 3rd Ed, item 43, p210 for details.
((this->instance_)->*(this->method_))(bridge, parameters);
@@ -63,19 +59,16 @@ class MethodCallback : public MethodCallbackExecutor {
Method method_;
};
-template <class T>
-class ConstMethodCallback : public MethodCallbackExecutor {
+template <class T> class ConstMethodCallback : public MethodCallbackExecutor {
public:
- typedef void (T::*ConstMethod)(
- const ScriptingBridge& bridge,
- const MethodParameter& parameters) const;
+ typedef void(T::* ConstMethod)(const ScriptingBridge& bridge,
+ const MethodParameter& parameters) const;
ConstMethodCallback(const T* instance, ConstMethod method)
: instance_(instance), const_method_(method) {}
virtual ~ConstMethodCallback() {}
- virtual void Execute(
- const ScriptingBridge& bridge,
- const MethodParameter& parameters) {
+ virtual void Execute(const ScriptingBridge& bridge,
+ const MethodParameter& parameters) {
// Use "this->" to force C++ to look inside our templatized base class; see
// Effective C++, 3rd Ed, item 43, p210 for details.
((this->instance_)->*(this->const_method_))(bridge, parameters);
@@ -89,4 +82,3 @@ class ConstMethodCallback : public MethodCallbackExecutor {
} // namespace tumbler
#endif // EXAMPLES_TUMBLER_CALLBACK_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/cube.cc b/native_client_sdk/src/examples/fullscreen_tumbler/cube.cc
index d972030..3a790b7 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/cube.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/cube.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
#include <algorithm>
#include <GLES2/gl2.h>
@@ -12,16 +11,13 @@
#include "shader_util.h"
#include "transforms.h"
-
namespace tumbler {
static const size_t kVertexCount = 24;
static const int kIndexCount = 36;
Cube::Cube(SharedOpenGLContext opengl_context)
- : opengl_context_(opengl_context),
- width_(1),
- height_(1) {
+ : opengl_context_(opengl_context), width_(1), height_(1) {
eye_[0] = eye_[1] = 0.0f;
eye_[2] = 2.0f;
orientation_[0] = 0.0f;
@@ -65,20 +61,12 @@ void Cube::Draw() {
glBindBuffer(GL_ARRAY_BUFFER, cube_vbos_[0]);
glUseProgram(shader_program_object_);
glEnableVertexAttribArray(position_location_);
- glVertexAttribPointer(position_location_,
- 3,
- GL_FLOAT,
- GL_FALSE,
- 3 * sizeof(GLfloat),
- NULL);
+ glVertexAttribPointer(
+ position_location_, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL);
glEnableVertexAttribArray(color_location_);
glBindBuffer(GL_ARRAY_BUFFER, cube_vbos_[1]);
- glVertexAttribPointer(color_location_,
- 3,
- GL_FLOAT,
- GL_FALSE,
- 3 * sizeof(GLfloat),
- NULL);
+ glVertexAttribPointer(
+ color_location_, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL);
glUniformMatrix4fv(mvp_location_, 1, GL_FALSE, mvp_matrix_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cube_vbos_[2]);
glDrawElements(GL_TRIANGLES, kIndexCount, GL_UNSIGNED_SHORT, 0);
@@ -88,32 +76,32 @@ void Cube::Draw() {
bool Cube::CreateShaders() {
const char vertex_shader_src[] =
- "uniform mat4 u_mvpMatrix; \n"
- "attribute vec4 a_position; \n"
- "attribute vec3 a_color; \n"
- "varying lowp vec4 v_color; \n"
- "void main() \n"
- "{ \n"
- " v_color.xyz = a_color; \n"
- " v_color.w = 1.0; \n"
- " gl_Position = u_mvpMatrix * a_position; \n"
- "} \n";
+ "uniform mat4 u_mvpMatrix; \n"
+ "attribute vec4 a_position; \n"
+ "attribute vec3 a_color; \n"
+ "varying lowp vec4 v_color; \n"
+ "void main() \n"
+ "{ \n"
+ " v_color.xyz = a_color; \n"
+ " v_color.w = 1.0; \n"
+ " gl_Position = u_mvpMatrix * a_position; \n"
+ "} \n";
const char fragment_shader_src[] =
- "varying lowp vec4 v_color; \n"
- "void main() \n"
- "{ \n"
- " gl_FragColor = v_color; \n"
- "} \n";
+ "varying lowp vec4 v_color; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = v_color; \n"
+ "} \n";
// Load the shaders and get a linked program object
shader_program_object_ =
shader_util::CreateProgramFromVertexAndFragmentShaders(
- vertex_shader_src, fragment_shader_src);
+ vertex_shader_src, fragment_shader_src);
if (shader_program_object_ == 0)
return false;
- position_location_ = glGetAttribLocation(shader_program_object_,
- "a_position");
+ position_location_ =
+ glGetAttribLocation(shader_program_object_, "a_position");
color_location_ = glGetAttribLocation(shader_program_object_, "a_color");
mvp_location_ = glGetUniformLocation(shader_program_object_, "u_mvpMatrix");
return true;
@@ -269,4 +257,3 @@ void Cube::ComputeModelViewTransform(GLfloat* model_view) {
}
} // namespace tumbler
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/cube.h b/native_client_sdk/src/examples/fullscreen_tumbler/cube.h
index 38a0bff..dfe427f 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/cube.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/cube.h
@@ -37,13 +37,9 @@ class Cube {
void Draw();
// Accessor for width and height. To change these, call Resize.
- const int width() const {
- return width_;
- }
+ const int width() const { return width_; }
- const int height() const {
- return height_;
- }
+ const int height() const { return height_; }
// Accessor/mutator for the camera orientation.
void GetOrientation(std::vector<float>* orientation) const {
@@ -81,9 +77,9 @@ class Cube {
int width_;
int height_;
GLuint shader_program_object_; // The compiled shaders.
- GLint position_location_; // The position attribute location.
- GLint color_location_; // The color attribute location.
- GLint mvp_location_; // The Model-View-Projection composite matrix.
+ GLint position_location_; // The position attribute location.
+ GLint color_location_; // The color attribute location.
+ GLint mvp_location_; // The Model-View-Projection composite matrix.
GLuint cube_vbos_[3];
GLfloat eye_[3]; // The eye point of the virtual camera.
// The orientation of the virtual camera stored as a quaternion. The
@@ -96,4 +92,3 @@ class Cube {
} // namespace tumbler
#endif // EXAMPLES_TUMBLER_CUBE_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.cc b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.cc
index 5847756..153c7e3 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
#include <pthread.h>
#include "ppapi/c/pp_graphics_3d.h"
@@ -21,8 +20,7 @@ void FlushCallback(void* data, int32_t result) {
namespace tumbler {
OpenGLContext::OpenGLContext(pp::Instance* instance)
- : pp::Graphics3DClient(instance),
- flush_pending_(false) {
+ : pp::Graphics3DClient(instance), flush_pending_(false) {
pp::Module* module = pp::Module::Get();
assert(module);
gles2_interface_ = static_cast<const struct PPB_OpenGLES2*>(
@@ -30,9 +28,7 @@ OpenGLContext::OpenGLContext(pp::Instance* instance)
assert(gles2_interface_);
}
-OpenGLContext::~OpenGLContext() {
- glSetCurrentContextPPAPI(0);
-}
+OpenGLContext::~OpenGLContext() { glSetCurrentContextPPAPI(0); }
bool OpenGLContext::MakeContextCurrent(pp::Instance* instance) {
if (instance == NULL) {
@@ -42,14 +38,14 @@ bool OpenGLContext::MakeContextCurrent(pp::Instance* instance) {
// Lazily create the Pepper context.
if (context_.is_null()) {
int32_t attribs[] = {
- PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
- PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
- PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
- PP_GRAPHICS3DATTRIB_SAMPLES, 0,
- PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
- PP_GRAPHICS3DATTRIB_WIDTH, size_.width(),
- PP_GRAPHICS3DATTRIB_HEIGHT, size_.height(),
- PP_GRAPHICS3DATTRIB_NONE
+ PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
+ PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
+ PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
+ PP_GRAPHICS3DATTRIB_SAMPLES, 0,
+ PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
+ PP_GRAPHICS3DATTRIB_WIDTH, size_.width(),
+ PP_GRAPHICS3DATTRIB_HEIGHT, size_.height(),
+ PP_GRAPHICS3DATTRIB_NONE
};
context_ = pp::Graphics3D(instance, pp::Graphics3D(), attribs);
if (context_.is_null()) {
@@ -73,7 +69,6 @@ void OpenGLContext::ResizeContext(const pp::Size& size) {
}
}
-
void OpenGLContext::FlushContext() {
if (flush_pending()) {
// A flush is pending so do nothing; just drop this flush on the floor.
@@ -83,4 +78,3 @@ void OpenGLContext::FlushContext() {
context_.SwapBuffers(pp::CompletionCallback(&FlushCallback, this));
}
} // namespace tumbler
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.h b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.h
index f09832c..f2b284c 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context.h
@@ -62,23 +62,15 @@ class OpenGLContext : public pp::Graphics3DClient {
void ResizeContext(const pp::Size& size);
/// The OpenGL ES 2.0 interface.
- const struct PPB_OpenGLES2* gles2() const {
- return gles2_interface_;
- }
+ const struct PPB_OpenGLES2* gles2() const { return gles2_interface_; }
/// The PP_Resource needed to make GLES2 calls through the Pepper interface.
- const PP_Resource gl_context() const {
- return context_.pp_resource();
- }
+ const PP_Resource gl_context() const { return context_.pp_resource(); }
/// Indicate whether a flush is pending. This can only be called from the
/// main thread; it is not thread safe.
- bool flush_pending() const {
- return flush_pending_;
- }
- void set_flush_pending(bool flag) {
- flush_pending_ = flag;
- }
+ bool flush_pending() const { return flush_pending_; }
+ void set_flush_pending(bool flag) { flush_pending_ = flag; }
private:
pp::Size size_;
@@ -91,5 +83,3 @@ class OpenGLContext : public pp::Graphics3DClient {
} // namespace tumbler
#endif // EXAMPLES_TUMBLER_OPENGL_CONTEXT_H_
-
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context_ptrs.h b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context_ptrs.h
index 3a00d0b..d5da922 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context_ptrs.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/opengl_context_ptrs.h
@@ -19,4 +19,3 @@ typedef std::tr1::shared_ptr<OpenGLContext> SharedOpenGLContext;
} // namespace tumbler
#endif // EXAMPLES_TUMBLER_OPENGL_CONTEXT_PTRS_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.cc b/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.cc
index b44bb8e..0cd49cde 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.cc
@@ -17,10 +17,10 @@ const std::string ScanToken(const std::string& token_string, size_t* pos) {
if (*pos == std::string::npos) {
return token;
}
- size_t token_start_pos = token_string.find_first_not_of(kWhiteSpaceCharacters,
- *pos);
- size_t token_end_pos = token_string.find_first_of(kWhiteSpaceCharacters,
- token_start_pos);
+ size_t token_start_pos =
+ token_string.find_first_not_of(kWhiteSpaceCharacters, *pos);
+ size_t token_end_pos =
+ token_string.find_first_of(kWhiteSpaceCharacters, token_start_pos);
if (token_start_pos != std::string::npos) {
token = token_string.substr(token_start_pos, token_end_pos);
}
@@ -93,4 +93,3 @@ bool ScriptingBridge::InvokeMethod(const std::string& method) {
}
} // namespace tumbler
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.h b/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.h
index e89d157..f4ebfb4 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/scripting_bridge.h
@@ -32,7 +32,7 @@ class ScriptingBridge {
public:
// Shared pointer type used in the method map.
typedef std::tr1::shared_ptr<MethodCallbackExecutor>
- SharedMethodCallbackExecutor;
+ SharedMethodCallbackExecutor;
virtual ~ScriptingBridge() {}
@@ -50,5 +50,5 @@ class ScriptingBridge {
};
} // namespace tumbler
-#endif // EXAMPLES_TUMBLER_SCRIPTING_BRIDGE_H_
+#endif // EXAMPLES_TUMBLER_SCRIPTING_BRIDGE_H_
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.cc b/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.cc
index e6a4ae7..ad6f5e9 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.cc
@@ -11,7 +11,7 @@
namespace shader_util {
-GLuint CreateShaderOfType(GLenum type, const char *shader_src) {
+GLuint CreateShaderOfType(GLenum type, const char* shader_src) {
GLuint shader;
GLint compiled;
@@ -46,7 +46,8 @@ GLuint CreateShaderOfType(GLenum type, const char *shader_src) {
}
GLuint CreateProgramFromVertexAndFragmentShaders(
- const char *vertex_shader_src, const char *fragment_shader_src) {
+ const char* vertex_shader_src,
+ const char* fragment_shader_src) {
GLuint vertex_shader;
GLuint fragment_shader;
GLuint program_object;
@@ -96,4 +97,3 @@ GLuint CreateProgramFromVertexAndFragmentShaders(
}
} // namespace shader_util
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.h b/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.h
index a9c9088..f733603 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/shader_util.h
@@ -15,16 +15,16 @@ namespace shader_util {
// GL_FRAGMENT_SHADER. Returns a non-0 value representing the compiled
// shader on success, 0 on failure. The caller is responsible for deleting
// the returned shader using glDeleteShader().
-GLuint CreateShaderOfType(GLenum type, const char *shader_src);
+GLuint CreateShaderOfType(GLenum type, const char* shader_src);
// Load and compile the vertex and fragment shaders, then link these together
// into a complete program. Returns a non-0 value representing the program on,
// success or 0 on failure. The caller is responsible for deleting the
// returned program using glDeleteProgram().
GLuint CreateProgramFromVertexAndFragmentShaders(
- const char *vertex_shader_src, const char *fragment_shader_src);
+ const char* vertex_shader_src,
+ const char* fragment_shader_src);
} // namespace shader_util
#endif // EXAMPLES_TUMBLER_SHADER_UTIL_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/transforms.cc b/native_client_sdk/src/examples/fullscreen_tumbler/transforms.cc
index 75a7c2c..a15963f 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/transforms.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/transforms.cc
@@ -31,9 +31,9 @@ void Frustum(GLfloat* m,
GLfloat delta_z = far_z - near_z;
GLfloat frustum[16];
- if ((near_z <= 0.0f) || (far_z <= 0.0f) ||
- (delta_x <= 0.0f) || (delta_y <= 0.0f) || (delta_z <= 0.0f))
- return;
+ if ((near_z <= 0.0f) || (far_z <= 0.0f) || (delta_x <= 0.0f) ||
+ (delta_y <= 0.0f) || (delta_z <= 0.0f))
+ return;
frustum[0] = 2.0f * near_z / delta_x;
frustum[1] = frustum[2] = frustum[3] = 0.0f;
@@ -52,7 +52,6 @@ void Frustum(GLfloat* m,
transform_4x4::Multiply(m, frustum, m);
}
-
void Perspective(GLfloat* m,
GLfloat fovy,
GLfloat aspect,
@@ -62,11 +61,11 @@ void Perspective(GLfloat* m,
frustum_h = tanf((fovy * 0.5f) / 180.0f * kPI) * near_z;
frustum_w = frustum_h * aspect;
- transform_4x4::Frustum(m, -frustum_w, frustum_w, -frustum_h, frustum_h,
- near_z, far_z);
+ transform_4x4::Frustum(
+ m, -frustum_w, frustum_w, -frustum_h, frustum_h, near_z, far_z);
}
-void Multiply(GLfloat *m, GLfloat *a, GLfloat* b) {
+void Multiply(GLfloat* m, GLfloat* a, GLfloat* b) {
GLfloat tmp[16];
// tmp = a . b
GLfloat a0, a1, a2, a3;
@@ -114,4 +113,3 @@ void LoadIdentity(GLfloat* m) {
}
} // namespace transform_4x4
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/transforms.h b/native_client_sdk/src/examples/fullscreen_tumbler/transforms.h
index 8a222e6..70f6d10 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/transforms.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/transforms.h
@@ -26,7 +26,7 @@ void Frustum(GLfloat* m,
void LoadIdentity(GLfloat* m);
// |m| <- |a| . |b|. |m| can point at the same memory as either |a| or |b|.
-void Multiply(GLfloat *m, GLfloat *a, GLfloat* b);
+void Multiply(GLfloat* m, GLfloat* a, GLfloat* b);
// Pre-multiply |m| with a single-point perspective matrix based on the viewing
// frustum whose view angle is |fovy|.
@@ -42,4 +42,3 @@ void Translate(GLfloat* m, GLfloat tx, GLfloat ty, GLfloat tz);
} // namespace transform_4x4
#endif // EXAMPLES_TUMBLER_TRANSFORMS_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc
index 6640bf4..3725f3a 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
#include <stdio.h>
#include <cstdlib>
@@ -29,11 +28,9 @@ const char* const kArrayDelimiter = ",";
// Return the value of parameter named |param_name| from |parameters|. If
// |param_name| doesn't exist, then return an empty string.
-std::string GetParameterNamed(
- const std::string& param_name,
- const tumbler::MethodParameter& parameters) {
- tumbler::MethodParameter::const_iterator i =
- parameters.find(param_name);
+std::string GetParameterNamed(const std::string& param_name,
+ const tumbler::MethodParameter& parameters) {
+ tumbler::MethodParameter::const_iterator i = parameters.find(param_name);
if (i == parameters.end()) {
return "";
}
@@ -51,7 +48,7 @@ std::vector<float> CreateArrayFromJSON(const std::string& json_array) {
if (array_start_pos == std::string::npos ||
array_end_pos == std::string::npos)
return float_array; // Malformed JSON: missing '[' or ']'.
- // Pull out the array elements.
+ // Pull out the array elements.
size_t token_pos = array_start_pos + 1;
while (token_pos < array_end_pos) {
float_array.push_back(strtof(json_array.data() + token_pos, NULL));
@@ -82,14 +79,14 @@ Tumbler::~Tumbler() {
}
bool Tumbler::Init(uint32_t /* argc */,
- const char* /* argn */[],
- const char* /* argv */[]) {
+ const char * /* argn */ [],
+ const char * /* argv */ []) {
// Add all the methods to the scripting bridge.
ScriptingBridge::SharedMethodCallbackExecutor set_orientation_method(
- new tumbler::MethodCallback<Tumbler>(
- this, &Tumbler::SetCameraOrientation));
+ new tumbler::MethodCallback<Tumbler>(this,
+ &Tumbler::SetCameraOrientation));
scripting_bridge_.AddMethodNamed("setCameraOrientation",
- set_orientation_method);
+ set_orientation_method);
return true;
}
@@ -161,9 +158,7 @@ void Tumbler::DidChangeView(const pp::View& view) {
DrawSelf();
}
-void Tumbler::DidChangeFocus(bool focus) {
- has_focus_ = focus;
-}
+void Tumbler::DidChangeFocus(bool focus) { has_focus_ = focus; }
void Tumbler::DrawSelf() {
if (cube_ == NULL || opengl_context_ == NULL)
@@ -188,9 +183,8 @@ void Tumbler::HandleKeyDownEvent(const pp::KeyboardInputEvent& key_event) {
}
}
-void Tumbler::SetCameraOrientation(
- const tumbler::ScriptingBridge& bridge,
- const tumbler::MethodParameter& parameters) {
+void Tumbler::SetCameraOrientation(const tumbler::ScriptingBridge& bridge,
+ const tumbler::MethodParameter& parameters) {
// |parameters| is expected to contain one object named "orientation", whose
// value is a JSON string that represents an array of four floats.
if (parameters.size() != 1 || cube_ == NULL)
@@ -205,4 +199,3 @@ void Tumbler::SetCameraOrientation(
}
} // namespace tumbler
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h
index d261a4a..80b4ea9 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h
@@ -21,7 +21,6 @@ namespace pp {
class KeyboardInputEvent;
} // namespace pp
-
namespace tumbler {
class Tumbler : public pp::Instance {
@@ -56,9 +55,8 @@ class Tumbler : public pp::Instance {
// This method is bound to the JavaScript "setCameraOrientation" method and
// is called like this:
// module.setCameraOrientation([0.0, 1.0, 0.0, 0.0]);
- void SetCameraOrientation(
- const tumbler::ScriptingBridge& bridge,
- const tumbler::MethodParameter& parameters);
+ void SetCameraOrientation(const tumbler::ScriptingBridge& bridge,
+ const tumbler::MethodParameter& parameters);
// Called to draw the contents of the module's browser area.
void DrawSelf();
@@ -81,4 +79,3 @@ class Tumbler : public pp::Instance {
} // namespace tumbler
#endif // EXAMPLES_TUMBLER_TUMBLER_H_
-
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler_module.cc b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler_module.cc
index d1d103f..d34576e 100644
--- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler_module.cc
+++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler_module.cc
@@ -16,9 +16,7 @@
class TumberModule : public pp::Module {
public:
TumberModule() : pp::Module() {}
- virtual ~TumberModule() {
- glTerminatePPAPI();
- }
+ virtual ~TumberModule() { glTerminatePPAPI(); }
/// Called by the browser when the module is first loaded and ready to run.
/// This is called once per module, not once per instance of the module on
@@ -41,8 +39,5 @@ namespace pp {
/// CreateInstance() method on the object you return to make instances. There
/// is one instance per <embed> tag on the page. This is the main binding
/// point for your NaCl module with the browser.
-Module* CreateModule() {
- return new TumberModule();
-}
+Module* CreateModule() { return new TumberModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/examples/getting_started/hello_world/hello_world.c b/native_client_sdk/src/examples/getting_started/hello_world/hello_world.c
index 8c01be0..ddfc0ee 100644
--- a/native_client_sdk/src/examples/getting_started/hello_world/hello_world.c
+++ b/native_client_sdk/src/examples/getting_started/hello_world/hello_world.c
@@ -39,7 +39,6 @@ static PPB_Console* ppb_console_interface = NULL;
static PPB_Messaging* ppb_messaging_interface = NULL;
static PPB_Var* ppb_var_interface = NULL;
-
/**
* Creates new string PP_Var from C string. The resulting object will be a
* refcounted string object. It will be AddRef()ed for the caller. When the
@@ -54,11 +53,10 @@ static struct PP_Var CStrToVar(const char* str) {
return PP_MakeUndefined();
}
-
/**
* Post a message back to our JavaScript
*/
-static void SendMessage(PP_Instance instance, const char *str) {
+static void SendMessage(PP_Instance instance, const char* str) {
if (ppb_messaging_interface)
ppb_messaging_interface->PostMessage(instance, CStrToVar(str));
}
@@ -66,10 +64,9 @@ static void SendMessage(PP_Instance instance, const char *str) {
/**
* Send a message to the JavaScript Console
*/
-static void LogMessage(PP_Instance instance, const char *str) {
+static void LogMessage(PP_Instance instance, const char* str) {
if (ppb_console_interface)
- ppb_console_interface->Log(instance, PP_LOGLEVEL_ERROR,
- CStrToVar(str));
+ ppb_console_interface->Log(instance, PP_LOGLEVEL_ERROR, CStrToVar(str));
}
/**
@@ -108,7 +105,6 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
return PP_TRUE;
}
-
/**
* Called when the NaCl module is destroyed. This will always be called,
* even if DidCreate returned failure. This routine should deallocate any data
@@ -116,8 +112,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
* @param[in] instance The identifier of the instance representing this NaCl
* module.
*/
-static void Instance_DidDestroy(PP_Instance instance) {
-}
+static void Instance_DidDestroy(PP_Instance instance) {}
/**
* Called when the position, the size, or the clip rect of the element in the
@@ -132,8 +127,7 @@ static void Instance_DidDestroy(PP_Instance instance) {
* plugin is invisible, @a clip will be (0, 0, 0, 0).
*/
static void Instance_DidChangeView(PP_Instance instance,
- PP_Resource view_resource) {
-}
+ PP_Resource view_resource) {}
/**
* Notification that the given NaCl module has gained or lost focus.
@@ -152,9 +146,7 @@ static void Instance_DidChangeView(PP_Instance instance,
* @param[in] has_focus Indicates whether this NaCl module gained or lost
* event focus.
*/
-static void Instance_DidChangeFocus(PP_Instance instance,
- PP_Bool has_focus) {
-}
+static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus) {}
/**
* Handler that gets called after a full-frame module is instantiated based on
@@ -172,8 +164,6 @@ static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
return PP_FALSE;
}
-
-
/**
* Entry points for the module.
* Initialize needed interfaces: PPB_Core, PPB_Messaging and PPB_Var.
@@ -183,15 +173,13 @@ static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
*/
PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id,
PPB_GetInterface get_browser) {
- ppb_console_interface =
- (PPB_Console*)(get_browser(PPB_CONSOLE_INTERFACE));
+ ppb_console_interface = (PPB_Console*)(get_browser(PPB_CONSOLE_INTERFACE));
ppb_messaging_interface =
(PPB_Messaging*)(get_browser(PPB_MESSAGING_INTERFACE));
ppb_var_interface = (PPB_Var*)(get_browser(PPB_VAR_INTERFACE));
return PP_OK;
}
-
/**
* Returns an interface pointer for the interface of the given name, or NULL
* if the interface is not supported.
@@ -212,9 +200,7 @@ PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
return NULL;
}
-
/**
* Called before the plugin module is unloaded.
*/
-PP_EXPORT void PPP_ShutdownModule() {
-}
+PP_EXPORT void PPP_ShutdownModule() {}
diff --git a/native_client_sdk/src/examples/getting_started/hello_world_ppapi_main/hello_world.c b/native_client_sdk/src/examples/getting_started/hello_world_ppapi_main/hello_world.c
index e553da5..1d3d6f1 100644
--- a/native_client_sdk/src/examples/getting_started/hello_world_ppapi_main/hello_world.c
+++ b/native_client_sdk/src/examples/getting_started/hello_world_ppapi_main/hello_world.c
@@ -12,7 +12,6 @@
#include "ppapi_main/ppapi_main.h"
-
// The default arguments to PPAPI_MAIN maps:
// STDIN -> /dev/stdin
// STDOUT -> /dev/stdout
@@ -31,7 +30,7 @@ PPAPI_MAIN_WITH_ARGS("pm_stdout", "/dev/tty", NULL, NULL)
// argv[2] = "<VALUE>"
// Where the embed tag for this module uses KEY=VALUE
//
-int ppapi_main(int argc, const char *argv[]) {
+int ppapi_main(int argc, const char* argv[]) {
int index = 1;
// Use PostMessage to send "Hello World" to JavaScript.
@@ -44,7 +43,7 @@ int ppapi_main(int argc, const char *argv[]) {
// Print the arguments we received from the web page
printf("NAME: %s\n", argv[0]);
while (index + 2 < argc) {
- printf(" ARGS: %s=%s\n", argv[index+0], argv[index+1]);
+ printf(" ARGS: %s=%s\n", argv[index + 0], argv[index + 1]);
index += 2;
}
return 0;
diff --git a/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc b/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc
index 6aea13f..26515b7 100644
--- a/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc
+++ b/native_client_sdk/src/examples/hello_world_instance3d/hello_world.cc
@@ -49,12 +49,12 @@
#include <GLES2/gl2.h>
#include "matrix.h"
-GLuint g_positionLoc;
-GLuint g_texCoordLoc;
-GLuint g_colorLoc;
-GLuint g_MVPLoc;
-GLuint g_vboID;
-GLuint g_ibID;
+GLuint g_positionLoc;
+GLuint g_texCoordLoc;
+GLuint g_colorLoc;
+GLuint g_MVPLoc;
+GLuint g_vboID;
+GLuint g_ibID;
GLubyte g_Indices[36];
GLuint g_programObj;
@@ -70,37 +70,33 @@ float g_fSpinY = 0.0f;
//----------------------------------------------------------------------------
// Rendering Assets
//----------------------------------------------------------------------------
-struct Vertex
-{
+struct Vertex {
float tu, tv;
float color[3];
float loc[3];
};
-Vertex *g_quadVertices = NULL;
-const char *g_TextureData = NULL;
-const char *g_VShaderData = NULL;
-const char *g_FShaderData = NULL;
+Vertex* g_quadVertices = NULL;
+const char* g_TextureData = NULL;
+const char* g_VShaderData = NULL;
+const char* g_FShaderData = NULL;
bool g_Loaded = false;
bool g_Ready = false;
-
float g_xSpin = 2.0f;
float g_ySpin = 0.5f;
-
-GLuint compileShader(GLenum type, const char *data) {
- const char *shaderStrings[1];
+GLuint compileShader(GLenum type, const char* data) {
+ const char* shaderStrings[1];
shaderStrings[0] = data;
GLuint shader = glCreateShader(type);
- glShaderSource(shader, 1, shaderStrings, NULL );
+ glShaderSource(shader, 1, shaderStrings, NULL);
glCompileShader(shader);
return shader;
}
-
void InitProgram(void) {
g_vertexShader = compileShader(GL_VERTEX_SHADER, g_VShaderData);
g_fragmentShader = compileShader(GL_FRAGMENT_SHADER, g_FShaderData);
@@ -112,23 +108,27 @@ void InitProgram(void) {
glGenBuffers(1, &g_vboID);
glBindBuffer(GL_ARRAY_BUFFER, g_vboID);
- glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(Vertex),
- (void*)&g_quadVertices[0], GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER,
+ 24 * sizeof(Vertex),
+ (void*)&g_quadVertices[0],
+ GL_STATIC_DRAW);
glGenBuffers(1, &g_ibID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ibID);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(char),
- (void*)&g_Indices[0], GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER,
+ 36 * sizeof(char),
+ (void*)&g_Indices[0],
+ GL_STATIC_DRAW);
//
// Create a texture to test out our fragment shader...
//
glGenTextures(1, &g_textureID);
glBindTexture(GL_TEXTURE_2D, g_textureID);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB,
- GL_UNSIGNED_BYTE, g_TextureData);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE,
+ g_TextureData);
//
// Locate some parameters by name so we can set them later...
@@ -141,7 +141,6 @@ void InitProgram(void) {
printf("Program initialized.\n");
}
-
void BuildQuad(Vertex* verts, int axis[3], float depth, float color[3]) {
static float X[4] = { -1.0f, 1.0f, 1.0f, -1.0f };
static float Y[4] = { -1.0f, -1.0f, 1.0f, 1.0f };
@@ -157,9 +156,8 @@ void BuildQuad(Vertex* verts, int axis[3], float depth, float color[3]) {
}
}
-
-Vertex *BuildCube() {
- Vertex *verts = new Vertex[24];
+Vertex* BuildCube() {
+ Vertex* verts = new Vertex[24];
for (int i = 0; i < 3; i++) {
int Faxis[3];
int Baxis[3];
@@ -177,33 +175,33 @@ Vertex *BuildCube() {
BuildQuad(&verts[12 + i * 4], Baxis, -1.0f, Bcolor);
}
- for(int i = 0; i < 6; i++) {
- g_Indices[i*6 + 0] = 2 + i * 4;
- g_Indices[i*6 + 1] = 1 + i * 4;
- g_Indices[i*6 + 2] = 0 + i * 4;
- g_Indices[i*6 + 3] = 3 + i * 4;
- g_Indices[i*6 + 4] = 2 + i * 4;
- g_Indices[i*6 + 5] = 0 + i * 4;
+ for (int i = 0; i < 6; i++) {
+ g_Indices[i * 6 + 0] = 2 + i * 4;
+ g_Indices[i * 6 + 1] = 1 + i * 4;
+ g_Indices[i * 6 + 2] = 0 + i * 4;
+ g_Indices[i * 6 + 3] = 3 + i * 4;
+ g_Indices[i * 6 + 4] = 2 + i * 4;
+ g_Indices[i * 6 + 5] = 0 + i * 4;
}
return verts;
}
-
static float clamp(float val, float min, float max) {
- if (val < min) return min;
- if (val > max) return max;
+ if (val < min)
+ return min;
+ if (val > max)
+ return max;
return val;
}
-
void ProcessEvent(PPAPIEvent* event) {
if (event->event_type == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
- PPAPIMouseEvent* mouse = (PPAPIMouseEvent*) event;
+ PPAPIMouseEvent* mouse = (PPAPIMouseEvent*)event;
g_ySpin = clamp((float) mouse->delta.x / 2, -4.0, 4.0);
g_xSpin = clamp((float) mouse->delta.y / 2, -4.0, 4.0);
}
if (event->event_type == PP_INPUTEVENT_TYPE_KEYUP) {
- PPAPIKeyEvent* key = (PPAPIKeyEvent*) event;
+ PPAPIKeyEvent* key = (PPAPIKeyEvent*)event;
if (key->key_code == 13) {
PPAPIInstance3D::GetInstance3D()->ToggleFullscreen();
}
@@ -232,22 +230,26 @@ void PPAPIRender(PP_Resource ctx, uint32_t width, uint32_t height) {
xRot -= g_xSpin;
yRot -= g_ySpin;
- if (xRot >= 360.0f) xRot = 0.0;
- if (xRot <= -360.0f) xRot = 0.0;
+ if (xRot >= 360.0f)
+ xRot = 0.0;
+ if (xRot <= -360.0f)
+ xRot = 0.0;
- if (yRot >= 360.0f) yRot = 0.0;
- if (yRot <= -360.0f) yRot = 0.0;
+ if (yRot >= 360.0f)
+ yRot = 0.0;
+ if (yRot <= -360.0f)
+ yRot = 0.0;
- glClearColor(0.5,0.5,0.5,1);
+ glClearColor(0.5, 0.5, 0.5, 1);
glClearDepthf(1.0);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//set what program to use
- glUseProgram( g_programObj );
- glActiveTexture ( GL_TEXTURE0 );
- glBindTexture ( GL_TEXTURE_2D,g_textureID );
- glUniform1i ( g_textureLoc, 0 );
+ glUseProgram(g_programObj);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, g_textureID);
+ glUniform1i(g_textureLoc, 0);
//create our perspective matrix
float mpv[16];
@@ -255,33 +257,44 @@ void PPAPIRender(PP_Resource ctx, uint32_t width, uint32_t height) {
float rot[16];
identity_matrix(mpv);
- glhPerspectivef2(&mpv[0], 45.0f, (float) (width) / (float) height, 1, 10);
+ glhPerspectivef2(&mpv[0], 45.0f, (float)(width) / (float) height, 1, 10);
translate_matrix(0, 0, -4.0, trs);
- rotate_matrix(xRot, yRot , 0.0f ,rot);
+ rotate_matrix(xRot, yRot, 0.0f, rot);
multiply_matrix(trs, rot, trs);
multiply_matrix(mpv, trs, mpv);
- glUniformMatrix4fv(g_MVPLoc, 1, GL_FALSE, (GLfloat*) mpv);
+ glUniformMatrix4fv(g_MVPLoc, 1, GL_FALSE, (GLfloat*)mpv);
//define the attributes of the vertex
glBindBuffer(GL_ARRAY_BUFFER, g_vboID);
- glVertexAttribPointer(g_positionLoc, 3, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,loc));
+ glVertexAttribPointer(g_positionLoc,
+ 3,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, loc));
glEnableVertexAttribArray(g_positionLoc);
- glVertexAttribPointer(g_texCoordLoc, 2, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,tu));
+ glVertexAttribPointer(g_texCoordLoc,
+ 2,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, tu));
glEnableVertexAttribArray(g_texCoordLoc);
- glVertexAttribPointer(g_colorLoc, 3, GL_FLOAT, GL_FALSE,
- sizeof(Vertex), (void*)offsetof(Vertex,color));
+ glVertexAttribPointer(g_colorLoc,
+ 3,
+ GL_FLOAT,
+ GL_FALSE,
+ sizeof(Vertex),
+ (void*)offsetof(Vertex, color));
glEnableVertexAttribArray(g_colorLoc);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ibID);
- glDrawElements ( GL_TRIANGLES, 36, GL_UNSIGNED_BYTE ,0 );
+ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, 0);
}
-
-const char *LoadData(const char *url) {
- char *buf;
+const char* LoadData(const char* url) {
+ char* buf;
struct stat stat_buf;
int fp = open(url, O_RDONLY);
@@ -289,14 +302,13 @@ const char *LoadData(const char *url) {
int len = static_cast<int>(stat_buf.st_size);
buf = new char[len + 1];
- int read_size = read(fp, buf, len);
+ int read_size = read(fp, buf, len);
buf[len] = 0;
return buf;
}
-
PPAPI_MAIN_USE(PPAPI_CreateInstance3D, PPAPI_MAIN_DEFAULT_ARGS)
-int ppapi_main(int argc, const char *argv[]) {
+int ppapi_main(int argc, const char* argv[]) {
printf("Started main.\n");
// Mount URL loads to /http
@@ -307,7 +319,7 @@ int ppapi_main(int argc, const char *argv[]) {
g_FShaderData = LoadData("/http/fragment_shader_es2.frag");
g_quadVertices = BuildCube();
- fprintf(stderr,"Loaded\n");
+ fprintf(stderr, "Loaded\n");
g_Loaded = true;
return 0;
}
diff --git a/native_client_sdk/src/examples/hello_world_instance3d/matrix.cc b/native_client_sdk/src/examples/hello_world_instance3d/matrix.cc
index a389581..b87d496 100644
--- a/native_client_sdk/src/examples/hello_world_instance3d/matrix.cc
+++ b/native_client_sdk/src/examples/hello_world_instance3d/matrix.cc
@@ -11,41 +11,47 @@
#include <stdlib.h>
#include <string.h>
#include "matrix.h"
-#define deg_to_rad(x) (x * (M_PI/180.0f))
-
-void glhFrustumf2(Matrix_t mat, GLfloat left, GLfloat right, GLfloat bottom,
- GLfloat top, GLfloat znear, GLfloat zfar)
-{
- float temp, temp2, temp3, temp4;
- temp = 2.0f * znear;
- temp2 = right - left;
- temp3 = top - bottom;
- temp4 = zfar - znear;
- mat[0] = temp / temp2;
- mat[1] = 0.0f;
- mat[2] = 0.0f;
- mat[3] = 0.0f;
- mat[4] = 0.0f;
- mat[5] = temp / temp3;
- mat[6] = 0.0f;
- mat[7] = 0.0f;
- mat[8] = (right + left) / temp2;
- mat[9] = (top + bottom) / temp3;
- mat[10] = (-zfar - znear) / temp4;
- mat[11] = -1.0f;
- mat[12] = 0.0f;
- mat[13] = 0.0f;
- mat[14] = (-temp * zfar) / temp4;
- mat[15] = 0.0f;
+#define deg_to_rad(x) (x * (M_PI / 180.0f))
+
+void glhFrustumf2(Matrix_t mat,
+ GLfloat left,
+ GLfloat right,
+ GLfloat bottom,
+ GLfloat top,
+ GLfloat znear,
+ GLfloat zfar) {
+ float temp, temp2, temp3, temp4;
+ temp = 2.0f * znear;
+ temp2 = right - left;
+ temp3 = top - bottom;
+ temp4 = zfar - znear;
+ mat[0] = temp / temp2;
+ mat[1] = 0.0f;
+ mat[2] = 0.0f;
+ mat[3] = 0.0f;
+ mat[4] = 0.0f;
+ mat[5] = temp / temp3;
+ mat[6] = 0.0f;
+ mat[7] = 0.0f;
+ mat[8] = (right + left) / temp2;
+ mat[9] = (top + bottom) / temp3;
+ mat[10] = (-zfar - znear) / temp4;
+ mat[11] = -1.0f;
+ mat[12] = 0.0f;
+ mat[13] = 0.0f;
+ mat[14] = (-temp * zfar) / temp4;
+ mat[15] = 0.0f;
}
-void glhPerspectivef2(Matrix_t mat, GLfloat fovyInDegrees,
- GLfloat aspectRatio, GLfloat znear, GLfloat zfar)
-{
- float ymax, xmax;
- ymax = znear * tanf(fovyInDegrees * 3.14f / 360.0f);
- xmax = ymax * aspectRatio;
- glhFrustumf2(mat, -xmax, xmax, -ymax, ymax, znear, zfar);
+void glhPerspectivef2(Matrix_t mat,
+ GLfloat fovyInDegrees,
+ GLfloat aspectRatio,
+ GLfloat znear,
+ GLfloat zfar) {
+ float ymax, xmax;
+ ymax = znear * tanf(fovyInDegrees * 3.14f / 360.0f);
+ xmax = ymax * aspectRatio;
+ glhFrustumf2(mat, -xmax, xmax, -ymax, ymax, znear, zfar);
}
void identity_matrix(Matrix_t mat) {
@@ -61,23 +67,23 @@ void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat) {
// matrix are the same.
Matrix_t out;
- out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
- out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
- out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
- out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
+ out[0] = a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3];
+ out[1] = a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3];
+ out[2] = a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3];
+ out[3] = a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3];
- out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
- out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
- out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
- out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
+ out[4] = a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7];
+ out[5] = a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7];
+ out[6] = a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7];
+ out[7] = a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7];
- out[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
- out[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
- out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
- out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
+ out[8] = a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11];
+ out[9] = a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11];
+ out[10] = a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11];
+ out[11] = a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11];
- out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
- out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
+ out[12] = a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15];
+ out[13] = a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15];
out[14] = a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15];
out[15] = a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15];
@@ -108,8 +114,7 @@ void rotate_z_matrix(GLfloat z_rad, Matrix_t mat) {
mat[5] = mat[0];
}
-void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg,
- Matrix_t mat) {
+void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg, Matrix_t mat) {
GLfloat x_rad = (GLfloat) deg_to_rad(x_deg);
GLfloat y_rad = (GLfloat) deg_to_rad(y_deg);
GLfloat z_rad = (GLfloat) deg_to_rad(z_deg);
@@ -133,4 +138,3 @@ void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat) {
mat[13] += y;
mat[14] += z;
}
-
diff --git a/native_client_sdk/src/examples/hello_world_instance3d/matrix.h b/native_client_sdk/src/examples/hello_world_instance3d/matrix.h
index 7db7985..ed094ed 100644
--- a/native_client_sdk/src/examples/hello_world_instance3d/matrix.h
+++ b/native_client_sdk/src/examples/hello_world_instance3d/matrix.h
@@ -21,12 +21,19 @@ typedef GLfloat Matrix_t[16];
/// Since GLES2 doesn't have all the nifty matrix transform functions that GL
/// has, we emulate some of them here for the sake of sanity from:
/// http://www.opengl.org/wiki/GluPerspective_code
-void glhFrustumf2(Matrix_t mat, GLfloat left, GLfloat right, GLfloat bottom,
- GLfloat top, GLfloat znear, GLfloat zfar);
-
-void glhPerspectivef2(Matrix_t mat, GLfloat fovyInDegrees,
- GLfloat aspectRatio, GLfloat znear, GLfloat zfar);
-
+void glhFrustumf2(Matrix_t mat,
+ GLfloat left,
+ GLfloat right,
+ GLfloat bottom,
+ GLfloat top,
+ GLfloat znear,
+ GLfloat zfar);
+
+void glhPerspectivef2(Matrix_t mat,
+ GLfloat fovyInDegrees,
+ GLfloat aspectRatio,
+ GLfloat znear,
+ GLfloat zfar);
void identity_matrix(Matrix_t mat);
void multiply_matrix(const Matrix_t a, const Matrix_t b, Matrix_t mat);
@@ -34,4 +41,3 @@ void rotate_matrix(GLfloat x_deg, GLfloat y_deg, GLfloat z_deg, Matrix_t mat);
void translate_matrix(GLfloat x, GLfloat y, GLfloat z, Matrix_t mat);
#endif // EXAMPLES_HELLO_WORLD_GLES_MATRIX_H
-
diff --git a/native_client_sdk/src/examples/hello_world_interactive/hello_world.cc b/native_client_sdk/src/examples/hello_world_interactive/hello_world.cc
index de9541a..cd09c78 100644
--- a/native_client_sdk/src/examples/hello_world_interactive/hello_world.cc
+++ b/native_client_sdk/src/examples/hello_world_interactive/hello_world.cc
@@ -35,9 +35,7 @@ static const char kMessageArgumentSeparator = ':';
/// This is the module's function that invokes FortyTwo and converts the return
/// value from an int32_t to a pp::Var for return.
-pp::Var MarshallFortyTwo() {
- return pp::Var(FortyTwo());
-}
+pp::Var MarshallFortyTwo() { return pp::Var(FortyTwo()); }
/// This function is passed the arg list from the JavaScript call to
/// @a reverseText.
@@ -105,9 +103,7 @@ void HelloWorldInstance::HandleMessage(const pp::Var& var_message) {
/// <code>type="application/x-nacl"</code>.
class HelloWorldModule : public pp::Module {
public:
- HelloWorldModule() : pp::Module() {
- printf("Got here.\n");
- }
+ HelloWorldModule() : pp::Module() { printf("Got here.\n"); }
virtual ~HelloWorldModule() {}
/// Create and return a HelloWorldInstance object.
@@ -120,7 +116,6 @@ class HelloWorldModule : public pp::Module {
};
} // namespace hello_world
-
namespace pp {
/// Factory function called by the browser when the module is first loaded.
/// The browser keeps a singleton of this module. It calls the
@@ -129,7 +124,5 @@ namespace pp {
/// point for your NaCl module with the browser.
/// @return new HelloWorldModule.
/// @note The browser is responsible for deleting returned @a Module.
-Module* CreateModule() {
- return new hello_world::HelloWorldModule();
-}
+Module* CreateModule() { return new hello_world::HelloWorldModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/hello_world_interactive/helper_functions.cc b/native_client_sdk/src/examples/hello_world_interactive/helper_functions.cc
index 2b43c605..8987493 100644
--- a/native_client_sdk/src/examples/hello_world_interactive/helper_functions.cc
+++ b/native_client_sdk/src/examples/hello_world_interactive/helper_functions.cc
@@ -8,9 +8,7 @@
namespace hello_world {
-int32_t FortyTwo() {
- return 42;
-}
+int32_t FortyTwo() { return 42; }
std::string ReverseText(const std::string& text) {
std::string reversed_string(text);
@@ -19,4 +17,3 @@ std::string ReverseText(const std::string& text) {
return reversed_string;
}
} // namespace hello_world
-
diff --git a/native_client_sdk/src/examples/hello_world_interactive/helper_functions.h b/native_client_sdk/src/examples/hello_world_interactive/helper_functions.h
index 5076300..78b03f1 100644
--- a/native_client_sdk/src/examples/hello_world_interactive/helper_functions.h
+++ b/native_client_sdk/src/examples/hello_world_interactive/helper_functions.h
@@ -31,4 +31,3 @@ std::string ReverseText(const std::string& text);
} // namespace hello_world
#endif // EXAMPLES_HELLO_WORLD_HELPER_FUNCTIONS_H_
-
diff --git a/native_client_sdk/src/examples/pong/pong_input.cc b/native_client_sdk/src/examples/pong/pong_input.cc
index 4d3f903..be58f5d 100644
--- a/native_client_sdk/src/examples/pong/pong_input.cc
+++ b/native_client_sdk/src/examples/pong/pong_input.cc
@@ -21,8 +21,7 @@ const int kPaddleAIDeadZone = 20;
}
PongInputKeyboard::PongInputKeyboard(PongInputKeyboardDelegate* delegate)
- : delegate_(delegate) {
-}
+ : delegate_(delegate) {}
MoveDirection PongInputKeyboard::GetMove(const PongModel& model,
bool is_left_paddle) {
@@ -38,8 +37,8 @@ MoveDirection PongInputAI::GetMove(const PongModel& model,
bool is_left_paddle) {
// A highly advanced AI algorithm that moves the paddle toward the y position
// of the ball.
- const PaddleModel& paddle = is_left_paddle ? model.left_paddle() :
- model.right_paddle();
+ const PaddleModel& paddle =
+ is_left_paddle ? model.left_paddle() : model.right_paddle();
int ball_center_y = model.ball().rect.CenterPoint().y();
int paddle_center_y = paddle.rect.CenterPoint().y();
int distance_y = labs(paddle_center_y - ball_center_y);
diff --git a/native_client_sdk/src/examples/pong/pong_instance.cc b/native_client_sdk/src/examples/pong/pong_instance.cc
index 3da5df9..5f5cf62 100644
--- a/native_client_sdk/src/examples/pong/pong_instance.cc
+++ b/native_client_sdk/src/examples/pong/pong_instance.cc
@@ -55,8 +55,8 @@ bool PongInstance::Init(uint32_t argc, const char* argn[], const char* argv[]) {
void PongInstance::DidChangeView(const pp::View& view) {
if (!view_->DidChangeView(this, view, is_initial_view_change_)) {
- PostMessage(pp::Var(
- "ERROR DidChangeView failed. Could not bind graphics?"));
+ PostMessage(
+ pp::Var("ERROR DidChangeView failed. Could not bind graphics?"));
return;
}
@@ -106,18 +106,13 @@ void PongInstance::OnScoreChanged() {
UpdateScoreDisplay();
}
-void PongInstance::OnPlayerScored() {
- model_->ResetPositions();
-}
+void PongInstance::OnPlayerScored() { model_->ResetPositions(); }
-bool PongInstance::IsKeyDown(int key_code) {
- return key_map_[key_code];
-}
+bool PongInstance::IsKeyDown(int key_code) { return key_map_[key_code]; }
void PongInstance::ScheduleUpdate() {
pp::Module::Get()->core()->CallOnMainThread(
- kUpdateInterval,
- factory_.NewCallback(&PongInstance::UpdateCallback));
+ kUpdateInterval, factory_.NewCallback(&PongInstance::UpdateCallback));
}
void PongInstance::UpdateCallback(int32_t result) {
@@ -130,13 +125,14 @@ void PongInstance::UpdateCallback(int32_t result) {
model_->Update(left_move, right_move);
}
-void PongInstance::ResetScore() {
- model_->SetScore(0, 0);
-}
+void PongInstance::ResetScore() { model_->SetScore(0, 0); }
void PongInstance::UpdateScoreDisplay() {
char buffer[100];
- snprintf(&buffer[0], sizeof(buffer), "You %d: Computer %d",
- model_->left_score(), model_->right_score());
+ snprintf(&buffer[0],
+ sizeof(buffer),
+ "You %d: Computer %d",
+ model_->left_score(),
+ model_->right_score());
PostMessage(pp::Var(buffer));
}
diff --git a/native_client_sdk/src/examples/pong/pong_model.cc b/native_client_sdk/src/examples/pong/pong_model.cc
index 20592fa..6af4b11 100644
--- a/native_client_sdk/src/examples/pong/pong_model.cc
+++ b/native_client_sdk/src/examples/pong/pong_model.cc
@@ -60,11 +60,12 @@ const float kPaddleSpinDown = 0.8f;
* @return The left position of the object, in the range [0, region_max -
* object_width].
*/
-int GetFractionalPos(int region_min, int region_max,
+int GetFractionalPos(int region_min,
+ int region_max,
int object_width,
float fraction) {
return region_min +
- static_cast<int>((region_max - object_width - region_min) * fraction);
+ static_cast<int>((region_max - object_width - region_min) * fraction);
}
/**
@@ -77,22 +78,23 @@ int GetFractionalPos(int region_min, int region_max,
* @param[in] y_fraction A value in the range [0, 1]. 0 is on the top, 1 is on
* the bottom of the court.
*/
-void SetFractionalPosition(const pp::Rect& court, pp::Rect* object,
- float x_fraction, float y_fraction) {
- object->set_x(GetFractionalPos(court.x(), court.right(), object->width(),
- x_fraction));
- object->set_y(GetFractionalPos(court.y(), court.bottom(), object->height(),
- y_fraction));
+void SetFractionalPosition(const pp::Rect& court,
+ pp::Rect* object,
+ float x_fraction,
+ float y_fraction) {
+ object->set_x(
+ GetFractionalPos(court.x(), court.right(), object->width(), x_fraction));
+ object->set_y(GetFractionalPos(
+ court.y(), court.bottom(), object->height(), y_fraction));
}
} // namespace
-PaddleModel::PaddleModel()
- : rect(kPaddleWidth, kPaddleHeight) {
-}
+PaddleModel::PaddleModel() : rect(kPaddleWidth, kPaddleHeight) {}
void PaddleModel::SetPosition(const pp::Rect& court,
- float x_fraction, float y_fraction) {
+ float x_fraction,
+ float y_fraction) {
SetFractionalPosition(court, &rect, x_fraction, y_fraction);
}
@@ -131,11 +133,11 @@ PaddleCollision PaddleModel::GetPaddleCollision(float collision_y) const {
BallModel::BallModel()
: rect(kBallWidth, kBallHeight),
dx(kBallUpdateDistance),
- dy(kBallUpdateDistance) {
-}
+ dy(kBallUpdateDistance) {}
void BallModel::SetPosition(const pp::Rect& court,
- float x_fraction, float y_fraction) {
+ float x_fraction,
+ float y_fraction) {
SetFractionalPosition(court, &rect, x_fraction, y_fraction);
}
@@ -192,10 +194,10 @@ float BallModel::GetCourtCollisionTime(const pp::Rect& court) const {
// When the ball is moving up, only check for collision with the top of the
// court. Likewise, if the ball is moving down only check for collision with
// the bottom of the court.
- float y_collision_t = dy < 0 ?
- (court.y() - rect.y()) / static_cast<float>(dy) :
- (court.bottom() - rect.bottom()) / static_cast<float>(dy);
-
+ float y_collision_t =
+ dy < 0 ? (court.y() - rect.y()) / static_cast<float>(dy)
+ : (court.bottom() - rect.bottom()) / static_cast<float>(dy);
+
return y_collision_t;
}
@@ -218,14 +220,9 @@ void BallModel::ApplyPaddleCollision(PaddleCollision collision) {
}
PongModel::PongModel(PongModelDelegate* delegate)
- : delegate_(delegate),
- left_score_(0),
- right_score_(0) {
-}
+ : delegate_(delegate), left_score_(0), right_score_(0) {}
-void PongModel::SetCourtSize(const pp::Size& size) {
- court_.set_size(size);
-}
+void PongModel::SetCourtSize(const pp::Size& size) { court_.set_size(size); }
void PongModel::SetScore(int left_score, int right_score) {
left_score_ = left_score;
diff --git a/native_client_sdk/src/examples/pong/pong_module.cc b/native_client_sdk/src/examples/pong/pong_module.cc
index 2d05a29..9d99526 100644
--- a/native_client_sdk/src/examples/pong/pong_module.cc
+++ b/native_client_sdk/src/examples/pong/pong_module.cc
@@ -26,7 +26,5 @@ class PongModule : public pp::Module {
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
-Module* CreateModule() {
- return new PongModule();
-}
+Module* CreateModule() { return new PongModule(); }
} // namespace pp
diff --git a/native_client_sdk/src/examples/pong/pong_view.cc b/native_client_sdk/src/examples/pong/pong_view.cc
index 35fec2c..1c76d73 100644
--- a/native_client_sdk/src/examples/pong/pong_view.cc
+++ b/native_client_sdk/src/examples/pong/pong_view.cc
@@ -27,8 +27,7 @@ PongView::PongView(PongModel* model)
model_(model),
graphics_2d_(NULL),
pixel_buffer_(NULL),
- needs_erase_(false) {
-}
+ needs_erase_(false) {}
PongView::~PongView() {
delete graphics_2d_;
@@ -44,8 +43,8 @@ bool PongView::DidChangeView(pp::Instance* instance,
return true;
delete graphics_2d_;
- graphics_2d_ = new pp::Graphics2D(instance, new_size,
- true); // is_always_opaque
+ graphics_2d_ =
+ new pp::Graphics2D(instance, new_size, true); // is_always_opaque
if (!instance->BindGraphics(*graphics_2d_)) {
delete graphics_2d_;
graphics_2d_ = NULL;
@@ -56,7 +55,8 @@ bool PongView::DidChangeView(pp::Instance* instance,
// write to this buffer directly, and copy regions of it to the graphics
// context's backing store to draw to the screen.
delete pixel_buffer_;
- pixel_buffer_ = new pp::ImageData(instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
+ pixel_buffer_ = new pp::ImageData(instance,
+ PP_IMAGEDATAFORMAT_BGRA_PREMUL,
new_size,
true); // init_to_zero
@@ -177,9 +177,7 @@ void PongView::DrawPaddle(const PaddleModel& paddle) {
DrawRect(paddle.rect, kWhite);
}
-void PongView::EraseBall(const BallModel& ball) {
- DrawRect(ball.rect, kBlack);
-}
+void PongView::EraseBall(const BallModel& ball) { DrawRect(ball.rect, kBlack); }
void PongView::ErasePaddle(const PaddleModel& paddle) {
DrawRect(paddle.rect, kBlack);
diff --git a/native_client_sdk/src/examples/pong/pong_view.h b/native_client_sdk/src/examples/pong/pong_view.h
index 8f80e6f..7197d3a 100644
--- a/native_client_sdk/src/examples/pong/pong_view.h
+++ b/native_client_sdk/src/examples/pong/pong_view.h
@@ -22,7 +22,8 @@ class PongView {
explicit PongView(PongModel* model);
~PongView();
- bool DidChangeView(pp::Instance* instance, const pp::View& view,
+ bool DidChangeView(pp::Instance* instance,
+ const pp::View& view,
bool first_view_change);
pp::Size GetSize() const;
void StartDrawLoop();
diff --git a/native_client_sdk/src/examples/tutorial/debugging/hello_world.c b/native_client_sdk/src/examples/tutorial/debugging/hello_world.c
index 8cb9fdb3..2001651 100644
--- a/native_client_sdk/src/examples/tutorial/debugging/hello_world.c
+++ b/native_client_sdk/src/examples/tutorial/debugging/hello_world.c
@@ -37,35 +37,27 @@ PP_Instance g_Instance;
volatile int g_CrashTime = 0;
-
-void PostMessage(const char *str);
-
+void PostMessage(const char* str);
void layer5(int x, int y) {
if (g_CrashTime) {
- *(volatile int *) x = y;
+ *(volatile int*)x = y;
}
}
-void layer4(int x) {
- layer5(x, 1);
-}
+void layer4(int x) { layer5(x, 1); }
-void layer3(int a, int b, int c) {
- layer4(a + b + c);
-}
+void layer3(int a, int b, int c) { layer4(a + b + c); }
-void layer2(int i, int j) {
- layer3(i, j, 7);
-}
+void layer2(int i, int j) { layer3(i, j, 7); }
void layer1(int s, int t) {
- int *junk = (int*)alloca(sizeof(int)* 1234);
+ int* junk = (int*)alloca(sizeof(int) * 1234);
junk[0] = s + 5;
layer2(junk[0], t + 1);
}
-void *NexeMain(void *data) {
+void* NexeMain(void* data) {
PostMessage("Running Boom thread.");
while (1) {
layer1(2, 9);
@@ -87,25 +79,26 @@ static struct PP_Var CStrToVar(const char* str) {
return PP_MakeUndefined();
}
-
static void PostCompletionCallback(void* user_data, int32_t result) {
- const char *str = (const char *) user_data;
+ const char* str = (const char*)user_data;
ppb_messaging_interface->PostMessage(g_Instance, CStrToVar(str));
free(user_data);
}
-void PostMessage(const char *str) {
+void PostMessage(const char* str) {
struct PP_CompletionCallback cb;
- if (NULL == str) return;
- if (NULL == ppb_messaging_interface) return;
- if (0 == g_Instance) return;
+ if (NULL == str)
+ return;
+ if (NULL == ppb_messaging_interface)
+ return;
+ if (0 == g_Instance)
+ return;
if (strncmp(str, "ERR:", 4)) {
fprintf(stderr, "%s\n", str);
fflush(stderr);
- }
- else {
+ } else {
fprintf(stdout, "%s\n", str);
fflush(stdout);
}
@@ -122,14 +115,13 @@ void PostMessage(const char *str) {
}
void DumpJson(const char* json) {
- char* out = (char*) malloc(strlen(json) + 5);
+ char* out = (char*)malloc(strlen(json) + 5);
strcpy(out, "TRC: ");
strcat(out, json);
PostMessage(out);
free(out);
}
-
/**
* Called when the NaCl module is instantiated on the web page. The identifier
* of the new instance will be passed in as the first argument (this value is
@@ -167,15 +159,13 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
/* Report back if the request was honored. */
if (!EHHanderInstalled()) {
PostMessage("LOG: Stack traces not available, so don't expect them.\n");
- }
- else {
+ } else {
PostMessage("LOG: Stack traces are on.");
}
pthread_create(&g_NexeThread, NULL, NexeMain, NULL);
return PP_TRUE;
}
-
/**
* Called when the NaCl module is destroyed. This will always be called,
* even if DidCreate returned failure. This routine should deallocate any data
@@ -183,8 +173,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
* @param[in] instance The identifier of the instance representing this NaCl
* module.
*/
-static void Instance_DidDestroy(PP_Instance instance) {
-}
+static void Instance_DidDestroy(PP_Instance instance) {}
/**
* Called when the position, the size, or the clip rect of the element in the
@@ -199,8 +188,7 @@ static void Instance_DidDestroy(PP_Instance instance) {
* plugin is invisible, @a clip will be (0, 0, 0, 0).
*/
static void Instance_DidChangeView(PP_Instance instance,
- PP_Resource view_resource) {
-}
+ PP_Resource view_resource) {}
/**
* Notification that the given NaCl module has gained or lost focus.
@@ -219,9 +207,7 @@ static void Instance_DidChangeView(PP_Instance instance,
* @param[in] has_focus Indicates whether this NaCl module gained or lost
* event focus.
*/
-static void Instance_DidChangeFocus(PP_Instance instance,
- PP_Bool has_focus) {
-}
+static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus) {}
/**
* Handler that gets called after a full-frame module is instantiated based on
@@ -239,7 +225,6 @@ static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
return PP_FALSE;
}
-
/**
* Handles message from JavaScript.
*
@@ -267,7 +252,6 @@ PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id,
return PP_OK;
}
-
/**
* Returns an interface pointer for the interface of the given name, or NULL
* if the interface is not supported.
@@ -294,9 +278,7 @@ PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
return NULL;
}
-
/**
* Called before the plugin module is unloaded.
*/
-PP_EXPORT void PPP_ShutdownModule() {
-}
+PP_EXPORT void PPP_ShutdownModule() {}
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc b/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
index 0a4e68b..90a59fd 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
+++ b/native_client_sdk/src/examples/tutorial/dlopen/dlopen.cc
@@ -15,7 +15,7 @@
/// shared object on a worker thread. We use a worker because dlopen is
/// a blocking call, which is not allowed on the main thread.
-#include <dlfcn.h>
+#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -40,7 +40,6 @@
#define STRINGIFY(x) #x
#define NACL_ARCH_STRING XSTRINGIFY(NACL_ARCH)
-
class DlopenInstance : public pp::Instance {
public:
explicit DlopenInstance(PP_Instance instance)
@@ -51,16 +50,17 @@ class DlopenInstance : public pp::Instance {
reverse_(NULL),
tid_(NULL) {}
- virtual ~DlopenInstance(){};
+ virtual ~DlopenInstance() {}
+ ;
// Helper function to post a message back to the JS and stdout functions.
- void logmsg(const char* pStr){
+ void logmsg(const char* pStr) {
PostMessage(pp::Var(std::string("log:") + pStr));
fprintf(stdout, pStr);
}
// Initialize the module, staring a worker thread to load the shared object.
- virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]){
+ virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
nacl_io_init_ppapi(pp_instance(),
pp::Module::Get()->get_browser_interface());
// Mount a HTTP mount at /http. All reads from /http/* will read from the
@@ -85,7 +85,7 @@ class DlopenInstance : public pp::Instance {
eightball_so_ = dlopen("libeightball.so", RTLD_LAZY);
reverse_so_ = dlopen(reverse_so_path, RTLD_LAZY);
pp::CompletionCallback cc(LoadDoneCB, this);
- pp::Module::Get()->core()->CallOnMainThread(IMMEDIATELY, cc , 0);
+ pp::Module::Get()->core()->CallOnMainThread(IMMEDIATELY, cc, 0);
}
// This function will run on the main thread and use the handle it stored by
@@ -96,11 +96,11 @@ class DlopenInstance : public pp::Instance {
intptr_t offset = (intptr_t) dlsym(eightball_so_, "Magic8Ball");
eightball_ = (TYPE_eightball) offset;
if (NULL == eightball_) {
- std::string message = "dlsym() returned NULL: ";
- message += dlerror();
- message += "\n";
- logmsg(message.c_str());
- return;
+ std::string message = "dlsym() returned NULL: ";
+ message += dlerror();
+ message += "\n";
+ logmsg(message.c_str());
+ return;
}
logmsg("Loaded libeightball.so\n");
@@ -108,16 +108,15 @@ class DlopenInstance : public pp::Instance {
logmsg("libeightball.so did not load\n");
}
-
if (reverse_so_ != NULL) {
intptr_t offset = (intptr_t) dlsym(reverse_so_, "Reverse");
reverse_ = (TYPE_reverse) offset;
if (NULL == reverse_) {
- std::string message = "dlsym() returned NULL: ";
- message += dlerror();
- message += "\n";
- logmsg(message.c_str());
- return;
+ std::string message = "dlsym() returned NULL: ";
+ message += dlerror();
+ message += "\n";
+ logmsg(message.c_str());
+ return;
}
logmsg("Loaded libreverse.so\n");
} else {
@@ -134,7 +133,7 @@ class DlopenInstance : public pp::Instance {
std::string message = var_message.AsString();
if (message == "eightball") {
- if (NULL == eightball_){
+ if (NULL == eightball_) {
logmsg("Eightball library not loaded\n");
return;
}
@@ -167,14 +166,14 @@ class DlopenInstance : public pp::Instance {
}
}
- static void* LoadLibrariesOnWorker(void *pInst) {
- DlopenInstance *inst = static_cast<DlopenInstance *>(pInst);
+ static void* LoadLibrariesOnWorker(void* pInst) {
+ DlopenInstance* inst = static_cast<DlopenInstance*>(pInst);
inst->LoadLibrary();
return NULL;
}
- static void LoadDoneCB(void *pInst, int32_t result) {
- DlopenInstance *inst = static_cast<DlopenInstance *>(pInst);
+ static void LoadDoneCB(void* pInst, int32_t result) {
+ DlopenInstance* inst = static_cast<DlopenInstance*>(pInst);
inst->UseLibrary();
}
@@ -184,13 +183,13 @@ class DlopenInstance : public pp::Instance {
TYPE_eightball eightball_;
TYPE_reverse reverse_;
pthread_t tid_;
- };
+};
// The Module class. The browser calls the CreateInstance() method to create
// an instance of your NaCl module on the web page. The browser creates a new
// instance for each <embed> tag with type="application/x-nacl".
class dlOpenModule : public pp::Module {
- public:
+ public:
dlOpenModule() : pp::Module() {}
virtual ~dlOpenModule() {}
@@ -200,15 +199,11 @@ class dlOpenModule : public pp::Module {
}
};
-
// Factory function called by the browser when the module is first loaded.
// The browser keeps a singleton of this module. It calls the
// CreateInstance() method on the object you return to make instances. There
// is one instance per <embed> tag on the page. This is the main binding
// point for your NaCl module with the browser.
namespace pp {
- Module* CreateModule() {
- return new dlOpenModule();
- }
+Module* CreateModule() { return new dlOpenModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/eightball.cc b/native_client_sdk/src/examples/tutorial/dlopen/eightball.cc
index 531f8a61..bf7d352 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/eightball.cc
+++ b/native_client_sdk/src/examples/tutorial/dlopen/eightball.cc
@@ -7,18 +7,10 @@
#include "eightball.h"
-extern "C" const char *Magic8Ball() {
+extern "C" const char* Magic8Ball() {
const int NSIDES = 8;
- const char* answer[NSIDES] = {
- "YES",
- "NO",
- "MAYBE",
- "MAYBE NOT",
- "DEFINITELY",
- "ASK ME TOMORROW",
- "PARTLY CLOUDY",
- "42",
- };
+ const char* answer[NSIDES] = { "YES", "NO", "MAYBE", "MAYBE NOT",
+ "DEFINITELY", "ASK ME TOMORROW",
+ "PARTLY CLOUDY", "42", };
return answer[rand() % NSIDES];
}
-
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/eightball.h b/native_client_sdk/src/examples/tutorial/dlopen/eightball.h
index df3d997..0c818e5 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/eightball.h
+++ b/native_client_sdk/src/examples/tutorial/dlopen/eightball.h
@@ -9,5 +9,4 @@
typedef char* (*TYPE_eightball)(void);
extern "C" const char* Magic8Ball();
-#endif /* EIGHTBALL_H_ */
-
+#endif /* EIGHTBALL_H_ */
diff --git a/native_client_sdk/src/examples/tutorial/dlopen/reverse.h b/native_client_sdk/src/examples/tutorial/dlopen/reverse.h
index f0414ab..b4e4bba 100644
--- a/native_client_sdk/src/examples/tutorial/dlopen/reverse.h
+++ b/native_client_sdk/src/examples/tutorial/dlopen/reverse.h
@@ -7,6 +7,6 @@
/* Allocate a new string that is the reverse of the given string. */
typedef char* (*TYPE_reverse)(const char*);
-extern "C" char* Reverse(const char *);
+extern "C" char* Reverse(const char*);
-#endif /* REVERSE_H_ */
+#endif /* REVERSE_H_ */
diff --git a/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc b/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
index 0610c5e..3ed7583 100644
--- a/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
+++ b/native_client_sdk/src/examples/tutorial/load_progress/load_progress.cc
@@ -53,7 +53,6 @@ class LoadProgressModule : public pp::Module {
};
} // namespace load_progress
-
namespace pp {
/// Factory function called by the browser when the module is first loaded.
/// The browser keeps a singleton of this module. It calls the
@@ -62,8 +61,5 @@ namespace pp {
/// point for your NaCl module with the browser.
/// @return new LoadProgressModule.
/// @note The browser is responsible for deleting returned @a Module.
-Module* CreateModule() {
- return new load_progress::LoadProgressModule();
-}
+Module* CreateModule() { return new load_progress::LoadProgressModule(); }
} // namespace pp
-
diff --git a/native_client_sdk/src/libraries/error_handling/string_stream.c b/native_client_sdk/src/libraries/error_handling/string_stream.c
index 4c1f7ed..81046a9 100644
--- a/native_client_sdk/src/libraries/error_handling/string_stream.c
+++ b/native_client_sdk/src/libraries/error_handling/string_stream.c
@@ -9,22 +9,21 @@
#include <string.h>
#include "error_handling/string_stream.h"
-
-void ssinit(sstream_t *stream) {
+void ssinit(sstream_t* stream) {
stream->data = NULL;
stream->length = 0;
}
-void ssfree(sstream_t *stream) {
+void ssfree(sstream_t* stream) {
free(stream->data);
stream->data = 0;
stream->length = 0;
}
-int ssvprintf(sstream_t *stream, const char *format, va_list args) {
+int ssvprintf(sstream_t* stream, const char* format, va_list args) {
va_list hold;
int len;
- char *outstr;
+ char* outstr;
va_copy(hold, args);
len = vsnprintf(NULL, 0, format, args);
@@ -42,7 +41,7 @@ int ssvprintf(sstream_t *stream, const char *format, va_list args) {
return len;
}
-int ssprintf(sstream_t *stream, const char *format, ...) {
+int ssprintf(sstream_t* stream, const char* format, ...) {
int out;
va_list args;
va_start(args, format);
diff --git a/native_client_sdk/src/libraries/error_handling/string_stream.h b/native_client_sdk/src/libraries/error_handling/string_stream.h
index 3c68dd6..b35bc80 100644
--- a/native_client_sdk/src/libraries/error_handling/string_stream.h
+++ b/native_client_sdk/src/libraries/error_handling/string_stream.h
@@ -16,16 +16,15 @@
#include <stdint.h>
typedef struct {
- char *data;
+ char* data;
size_t length;
} sstream_t;
-void ssinit(sstream_t *stream);
-void ssfree(sstream_t *stream);
+void ssinit(sstream_t* stream);
+void ssfree(sstream_t* stream);
/* Returns the number of bytes added to the stream. */
-int ssvprintf(sstream_t *sstream, const char *format, va_list args);
-int ssprintf(sstream_t *sstream, const char *format, ...);
-
+int ssvprintf(sstream_t* sstream, const char* format, va_list args);
+int ssprintf(sstream_t* sstream, const char* format, ...);
#endif /* ERROR_HANDLING_STRING_STREAM_H */