summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/examples
diff options
context:
space:
mode:
authorjhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 19:09:43 +0000
committerjhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 19:09:43 +0000
commit97cecab5cfe38b69aba40b838841bb2b46d783f4 (patch)
tree0d8dda7c71a1462033d7f9780d42cd35a7fae237 /native_client_sdk/src/examples
parent5f81a66ed51e19114760cca36a0b5d7c87a18f63 (diff)
downloadchromium_src-97cecab5cfe38b69aba40b838841bb2b46d783f4.zip
chromium_src-97cecab5cfe38b69aba40b838841bb2b46d783f4.tar.gz
chromium_src-97cecab5cfe38b69aba40b838841bb2b46d783f4.tar.bz2
NaCl SDK: Demonstrate use of pp::Graphics2D::SetScale()
Demonstrate in the NaCl SDK API demo for pp::Graphics2D how to use full device resolution on HiDPI displays. For Graphics2D, the example now calls pp::View::GetDeviceScale(), and creates a Graphics 2D context with the correct number of pixels, as well as show when to call pp::Graphics2D::SetScale(). It also scales the mouse position to the correct location and increases the radius of the circle created in DrawMouse() to match. BUG=144071,392557 TEST=Build NaCl SDK, run with --force-device-scale-factor=2 Review URL: https://codereview.chromium.org/397173003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/examples')
-rw-r--r--native_client_sdk/src/examples/api/graphics_2d/graphics_2d.cc16
1 files changed, 12 insertions, 4 deletions
diff --git a/native_client_sdk/src/examples/api/graphics_2d/graphics_2d.cc b/native_client_sdk/src/examples/api/graphics_2d/graphics_2d.cc
index c519cfd..7a56619 100644
--- a/native_client_sdk/src/examples/api/graphics_2d/graphics_2d.cc
+++ b/native_client_sdk/src/examples/api/graphics_2d/graphics_2d.cc
@@ -48,7 +48,8 @@ class Graphics2DInstance : public pp::Instance {
: pp::Instance(instance),
callback_factory_(this),
mouse_down_(false),
- buffer_(NULL) {}
+ buffer_(NULL),
+ device_scale_(1.0f) {}
~Graphics2DInstance() { delete[] buffer_; }
@@ -62,7 +63,9 @@ class Graphics2DInstance : public pp::Instance {
}
virtual void DidChangeView(const pp::View& view) {
- pp::Size new_size = view.GetRect().size();
+ device_scale_ = view.GetDeviceScale();
+ pp::Size new_size = pp::Size(view.GetRect().width() * device_scale_,
+ view.GetRect().height() * device_scale_);
if (!CreateContext(new_size))
return;
@@ -86,7 +89,8 @@ class Graphics2DInstance : public pp::Instance {
if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_NONE)
return true;
- mouse_ = mouse_event.GetPosition();
+ mouse_ = pp::Point(mouse_event.GetPosition().x() * device_scale_,
+ mouse_event.GetPosition().y() * device_scale_);
mouse_down_ = true;
}
@@ -112,6 +116,9 @@ class Graphics2DInstance : public pp::Instance {
bool CreateContext(const pp::Size& new_size) {
const bool kIsAlwaysOpaque = true;
context_ = pp::Graphics2D(this, new_size, kIsAlwaysOpaque);
+ // Call SetScale before BindGraphics so the image is scaled correctly on
+ // HiDPI displays.
+ context_.SetScale(1.0f / device_scale_);
if (!BindGraphics(context_)) {
fprintf(stderr, "Unable to bind 2d context!\n");
context_ = pp::Graphics2D();
@@ -182,7 +189,7 @@ class Graphics2DInstance : public pp::Instance {
int height = size_.height();
// Draw a circle at the mouse position.
- int radius = kMouseRadius;
+ int radius = kMouseRadius * device_scale_;
int cx = mouse_.x();
int cy = mouse_.y();
int minx = cx - radius <= 0 ? 1 : cx - radius;
@@ -261,6 +268,7 @@ class Graphics2DInstance : public pp::Instance {
bool mouse_down_;
uint8_t* buffer_;
uint32_t palette_[256];
+ float device_scale_;
};
class Graphics2DModule : public pp::Module {