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

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

Issue 14607005: [NaCl SDK] Cleanup examples. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium 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/ppb_gamepad.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::View& view);
33
34 // Flushes its contents of |pixel_buffer_| to the 2D graphics context.
35 void Paint();
36
37 bool quit() const { return quit_; }
38
39 int width() const {
40 return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
41 }
42 int height() const {
43 return pixel_buffer_ ? pixel_buffer_->size().height() : 0;
44 }
45
46 // Indicate whether a flush is pending. This can only be called from the
47 // main thread; it is not thread safe.
48 bool flush_pending() const { return flush_pending_; }
49 void set_flush_pending(bool flag) { flush_pending_ = flag; }
50
51 private:
52 // Create and initialize the 2D context used for drawing.
53 void CreateContext(const pp::Size& size);
54 // Destroy the 2D drawing context.
55 void DestroyContext();
56 // Push the pixels to the browser, then attempt to flush the 2D context. If
57 // there is a pending flush on the 2D context, then update the pixels only
58 // and do not flush.
59 void FlushPixelBuffer();
60
61 bool IsContextValid() const { return graphics_2d_context_ != NULL; }
62
63 pp::Graphics2D* graphics_2d_context_;
64 pp::ImageData* pixel_buffer_;
65 const PPB_Gamepad* gamepad_;
66 bool flush_pending_;
67 bool quit_;
68 };
69
70 } // namespace gamepad
71
72 #endif // EXAMPLES_GAMEPAD_GAMEPAD_H_
OLDNEW
« no previous file with comments | « native_client_sdk/src/examples/api/gamepad/example.dsc ('k') | native_client_sdk/src/examples/api/gamepad/gamepad.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698