Add Media.AudioRendererEvents histogram to measure how often OnRenderError() is called.
[chromium-blink-merge.git] / native_client_sdk / src / examples / gamepad / gamepad.h
blobdcb92de0f078eda44ea474e4f7ab8d1af419883c
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_
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"
17 namespace gamepad {
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();
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.
35 void Paint();
37 bool quit() const {
38 return quit_;
41 int width() const {
42 return pixel_buffer_ ? pixel_buffer_->size().width() : 0;
44 int height() const {
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;
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();
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_;
74 bool flush_pending_;
75 bool quit_;
78 } // namespace gamepad
80 #endif // EXAMPLES_GAMEPAD_GAMEPAD_H_