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.
5 #ifndef EXAMPLES_GAMEPAD_GAMEPAD_H_
6 #define EXAMPLES_GAMEPAD_GAMEPAD_H_
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"
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
23 // type="application/x-nacl"
24 // nacl="pi_generator.nmf"
25 class Gamepad
: public pp::Instance
{
27 explicit Gamepad(PP_Instance instance
);
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
);
34 // Flushes its contents of |pixel_buffer_| to the 2D graphics context.
42 return pixel_buffer_
? pixel_buffer_
->size().width() : 0;
45 return pixel_buffer_
? pixel_buffer_
->size().height() : 0;
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_
;
53 void set_flush_pending(bool flag
) {
54 flush_pending_
= flag
;
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
65 void FlushPixelBuffer();
67 bool IsContextValid() const {
68 return graphics_2d_context_
!= NULL
;
71 pp::Graphics2D
* graphics_2d_context_
;
72 pp::ImageData
* pixel_buffer_
;
73 const PPB_Gamepad
* gamepad_
;
78 } // namespace gamepad
80 #endif // EXAMPLES_GAMEPAD_GAMEPAD_H_