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

Side by Side Diff: native_client_sdk/src/examples/gamepad/gamepad.h

Issue 9148086: Add simple NaCl gamepad example (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | native_client_sdk/src/examples/gamepad/gamepad.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXAMPLES_GAMEPAD_GAMEPAD_H_
6 #define EXAMPLES_GAMEPAD_GAMEPAD_H_
7
8 #include <map>
9 #include <vector>
10 #include "ppapi/c/dev/ppb_gamepad_dev.h"
11 #include "ppapi/cpp/graphics_2d.h"
12 #include "ppapi/cpp/image_data.h"
13 #include "ppapi/cpp/instance.h"
14 #include "ppapi/cpp/rect.h"
15 #include "ppapi/cpp/size.h"
16
17 namespace gamepad {
18
19 // The Instance class. One of these exists for each instance of your NaCl
20 // module on the web page. The browser will ask the Module object to create
21 // a new Instance for each occurrence of the <embed> tag that has these
22 // attributes:
23 // type="application/x-nacl"
24 // nacl="pi_generator.nmf"
25 class Gamepad : public pp::Instance {
26 public:
27 explicit Gamepad(PP_Instance instance);
28 virtual ~Gamepad();
29
30 // Update the graphics context to the new size, and regenerate |pixel_buffer_|
31 // to fit the new size as well.
32 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip);
33
34 // Flushes its contents of |pixel_buffer_| to the 2D graphics context.
35 void Paint();
36
37 bool quit() const {
38 return quit_;
39 }
40
41 int width() const {
42 return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
43 }
44 int height() const {
45 return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
46 }
47
48 // Indicate whether a flush is pending. This can only be called from the
49 // main thread; it is not thread safe.
50 bool flush_pending() const {
51 return flush_pending_;
52 }
53 void set_flush_pending(bool flag) {
54 flush_pending_ = flag;
55 }
56
57 private:
58 // Create and initialize the 2D context used for drawing.
59 void CreateContext(const pp::Size& size);
60 // Destroy the 2D drawing context.
61 void DestroyContext();
62 // Push the pixels to the browser, then attempt to flush the 2D context. If
63 // there is a pending flush on the 2D context, then update the pixels only
64 // and do not flush.
65 void FlushPixelBuffer();
66
67 bool IsContextValid() const {
68 return graphics_2d_context_ != NULL;
69 }
70
71 pp::Graphics2D* graphics_2d_context_;
72 pp::ImageData* pixel_buffer_;
73 const PPB_Gamepad_Dev* gamepad_;
74 bool flush_pending_;
75 bool quit_;
76 };
77
78 } // namespace gamepad
79
80 #endif // EXAMPLES_GAMEPAD_GAMEPAD_H_
81
bradn 2012/01/13 23:54:47 TRailing newline
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/examples/gamepad/gamepad.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698