diff options
Diffstat (limited to 'native_client_sdk')
14 files changed, 31 insertions, 41 deletions
diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc index a4fe68e..cf7d234f 100644 --- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc +++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.cc @@ -130,7 +130,8 @@ bool Tumbler::HandleInputEvent(const pp::InputEvent& event) { return false; } -void Tumbler::DidChangeView(const pp::Rect& position, const pp::Rect& clip) { +void Tumbler::DidChangeView(const pp::View& view) { + pp::Rect position = view.GetRect(); // Note: When switching to fullscreen, the new View position will be a // rectangle that encompasses the entire screen - e.g. 1900x1200 - with its // top-left corner at (0, 0). When switching back to the windowed screen the diff --git a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h index 35699d8..7b2a9c6 100644 --- a/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h +++ b/native_client_sdk/src/examples/fullscreen_tumbler/tumbler.h @@ -36,7 +36,7 @@ class Tumbler : public pp::Instance { virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); // Called whenever the in-browser window changes size. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); // Called by the browser when the NaCl canvas gets or loses focus. virtual void DidChangeFocus(bool has_focus); diff --git a/native_client_sdk/src/examples/gamepad/gamepad.cc b/native_client_sdk/src/examples/gamepad/gamepad.cc index 4fc70f9..9730e17 100644 --- a/native_client_sdk/src/examples/gamepad/gamepad.cc +++ b/native_client_sdk/src/examples/gamepad/gamepad.cc @@ -46,8 +46,8 @@ Gamepad::~Gamepad() { delete pixel_buffer_; } -void Gamepad::DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { +void Gamepad::DidChangeView(const pp::View& view) { + pp::Rect position = view.GetRect(); if (position.size().width() == width() && position.size().height() == height()) return; // Size didn't change, no need to update anything. diff --git a/native_client_sdk/src/examples/gamepad/gamepad.h b/native_client_sdk/src/examples/gamepad/gamepad.h index 4c9f367..dcb92de 100644 --- a/native_client_sdk/src/examples/gamepad/gamepad.h +++ b/native_client_sdk/src/examples/gamepad/gamepad.h @@ -29,7 +29,7 @@ class Gamepad : public pp::Instance { // Update the graphics context to the new size, and regenerate |pixel_buffer_| // to fit the new size as well. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); // Flushes its contents of |pixel_buffer_| to the 2D graphics context. void Paint(); diff --git a/native_client_sdk/src/examples/input_events/input_events.cc b/native_client_sdk/src/examples/input_events/input_events.cc index 026b1f7..f42bc4b 100644 --- a/native_client_sdk/src/examples/input_events/input_events.cc +++ b/native_client_sdk/src/examples/input_events/input_events.cc @@ -112,8 +112,7 @@ class EventInstance : public pp::Instance { } /// Scrolling the mouse wheel causes a DidChangeView event. - void DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { + void DidChangeView(const pp::View& view) { PostMessage(pp::Var(kDidChangeView)); } diff --git a/native_client_sdk/src/examples/mouselock/mouselock.cc b/native_client_sdk/src/examples/mouselock/mouselock.cc index 3d4db51..9a941dd 100644 --- a/native_client_sdk/src/examples/mouselock/mouselock.cc +++ b/native_client_sdk/src/examples/mouselock/mouselock.cc @@ -110,20 +110,15 @@ bool MouseLockInstance::HandleInputEvent(const pp::InputEvent& event) { } } -void MouseLockInstance::DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { - int width = position.size().width(); - int height = position.size().height(); - +void MouseLockInstance::DidChangeView(const pp::View& view) { // When entering into full-screen mode, DidChangeView() gets called twice. // The first time, any 2D context will fail to bind to this pp::Instacne. - if (width == width_ && height == height_ && is_context_bound_) { + if (view.GetRect().size() == size_ && is_context_bound_) { return; } - width_ = width; - height_ = height; + size_ = view.GetRect().size(); - device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), false); + device_context_ = pp::Graphics2D(this, size_, false); waiting_for_flush_completion_ = false; free(background_scanline_); background_scanline_ = NULL; @@ -133,9 +128,9 @@ void MouseLockInstance::DidChangeView(const pp::Rect& position, return; } background_scanline_ = static_cast<uint32_t*>( - malloc(width_ * sizeof(*background_scanline_))); + malloc(size_.width() * sizeof(*background_scanline_))); uint32_t* bg_pixel = background_scanline_; - for (int x = 0; x < width_; ++x) { + for (int x = 0; x < size_.width(); ++x) { *bg_pixel++ = kBackgroundColor; } Paint(); @@ -165,7 +160,7 @@ void MouseLockInstance::Paint() { if (waiting_for_flush_completion_) { return; } - pp::ImageData image = PaintImage(width_, height_); + pp::ImageData image = PaintImage(size_); if (image.is_null()) { Log("Could not create image data\n"); return; @@ -176,9 +171,8 @@ void MouseLockInstance::Paint() { callback_factory_.NewCallback(&MouseLockInstance::DidFlush)); } -pp::ImageData MouseLockInstance::PaintImage(int width, int height) { - pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, - pp::Size(width, height), false); +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) return image; diff --git a/native_client_sdk/src/examples/mouselock/mouselock.h b/native_client_sdk/src/examples/mouselock/mouselock.h index b31aaef..101bf96 100644 --- a/native_client_sdk/src/examples/mouselock/mouselock.h +++ b/native_client_sdk/src/examples/mouselock/mouselock.h @@ -15,6 +15,7 @@ #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/rect.h" +#include "ppapi/cpp/size.h" #include "ppapi/cpp/var.h" #include "ppapi/utility/completion_callback_factory.h" @@ -25,8 +26,6 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock { explicit MouseLockInstance(PP_Instance instance) : pp::Instance(instance), pp::MouseLock(this), - width_(0), - height_(0), mouse_locked_(false), waiting_for_flush_completion_(false), callback_factory_(this), @@ -43,7 +42,7 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock { virtual bool HandleInputEvent(const pp::InputEvent& event); // Called whenever the in-browser window changes size. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); // Called by the browser when mouselock is lost. This happens when the NaCl // module exits fullscreen mode. @@ -71,7 +70,7 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock { // Create a new pp::ImageData and paint the graphics that represent the mouse // movement in it. Return the new pp::ImageData. - pp::ImageData PaintImage(int width, int height); + pp::ImageData PaintImage(const pp::Size& size); // Fill the image with the backgroud color. void ClearToBackground(pp::ImageData* image); @@ -86,8 +85,7 @@ class MouseLockInstance : public pp::Instance, public pp::MouseLock { // Print the printf-style format to the "console" via PostMessage. void Log(const char* format, ...); - int width_; - int height_; + pp::Size size_; bool mouse_locked_; pp::Point mouse_movement_; diff --git a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.cc b/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.cc index bf20880..aa4c06d 100644 --- a/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.cc +++ b/native_client_sdk/src/examples/multithreaded_input_events/mt_input_events.cc @@ -109,8 +109,7 @@ class EventInstance : public pp::Instance { } /// Scrolling the mouse wheel causes a DidChangeView event. - void DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { + void DidChangeView(const pp::View& view) { PostMessage(pp::Var(kDidChangeView)); } diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.cc b/native_client_sdk/src/examples/pi_generator/pi_generator.cc index 3180d81..66b3058 100644 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.cc +++ b/native_client_sdk/src/examples/pi_generator/pi_generator.cc @@ -96,10 +96,9 @@ PiGenerator::~PiGenerator() { pthread_mutex_destroy(&pixel_buffer_mutex_); } -void PiGenerator::DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { - if (position.size().width() == width() && - position.size().height() == height()) +void PiGenerator::DidChangeView(const pp::View& view) { + pp::Rect position = view.GetRect(); + if (position.size() == pixel_buffer_->size()) return; // Size didn't change, no need to update anything. // Create a new device context with the new size. diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.h b/native_client_sdk/src/examples/pi_generator/pi_generator.h index f998d41..f69b1ff 100644 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.h +++ b/native_client_sdk/src/examples/pi_generator/pi_generator.h @@ -32,7 +32,7 @@ class PiGenerator : public pp::Instance { // Update the graphics context to the new size, and regenerate |pixel_buffer_| // to fit the new size as well. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); // Called by the browser to handle the postMessage() call in Javascript. // The message in this case is expected to contain the string 'paint', and diff --git a/native_client_sdk/src/examples/pong/pong.cc b/native_client_sdk/src/examples/pong/pong.cc index 1e6112f..8adf3fe 100644 --- a/native_client_sdk/src/examples/pong/pong.cc +++ b/native_client_sdk/src/examples/pong/pong.cc @@ -179,11 +179,10 @@ bool Pong::Init(uint32_t argc, const char* argn[], const char* argv[]) { return true; } -void Pong::DidChangeView(const pp::Rect& position, - const pp::Rect& clip) { +void Pong::DidChangeView(const pp::View& view) { pp::Size view_size = view_->GetSize(); const bool view_was_empty = view_size.IsEmpty(); - view_->UpdateView(position, clip, this); + view_->UpdateView(view.GetRect(), view.GetClipRect(), this); if (view_was_empty) ResetPositions(); } diff --git a/native_client_sdk/src/examples/pong/pong.h b/native_client_sdk/src/examples/pong/pong.h index 6b59901..5887a53 100644 --- a/native_client_sdk/src/examples/pong/pong.h +++ b/native_client_sdk/src/examples/pong/pong.h @@ -41,7 +41,7 @@ class Pong : public pp::Instance { // Update the graphics context to the new size, and regenerate |pixel_buffer_| // to fit the new size as well. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); virtual bool HandleInputEvent(const pp::InputEvent& event); diff --git a/native_client_sdk/src/examples/tumbler/tumbler.cc b/native_client_sdk/src/examples/tumbler/tumbler.cc index d711d20..5141292 100644 --- a/native_client_sdk/src/examples/tumbler/tumbler.cc +++ b/native_client_sdk/src/examples/tumbler/tumbler.cc @@ -89,7 +89,8 @@ void Tumbler::HandleMessage(const pp::Var& message) { scripting_bridge_.InvokeMethod(message.AsString()); } -void Tumbler::DidChangeView(const pp::Rect& position, const pp::Rect& clip) { +void Tumbler::DidChangeView(const pp::View& view) { + pp::Rect position = view.GetRect(); int cube_width = cube_ ? cube_->width() : 0; int cube_height = cube_ ? cube_->height() : 0; if (position.size().width() == cube_width && diff --git a/native_client_sdk/src/examples/tumbler/tumbler.h b/native_client_sdk/src/examples/tumbler/tumbler.h index 42317e6..4064799 100644 --- a/native_client_sdk/src/examples/tumbler/tumbler.h +++ b/native_client_sdk/src/examples/tumbler/tumbler.h @@ -30,7 +30,7 @@ class Tumbler : public pp::Instance { virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); // Called whenever the in-browser window changes size. - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); + virtual void DidChangeView(const pp::View& view); // Called by the browser to handle the postMessage() call in Javascript. virtual void HandleMessage(const pp::Var& message); |