1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
2eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Use of this source code is governed by a BSD-style license that can be
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * found in the LICENSE file. */
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef PPAPI_SIMPLE_PS_EVENT_H_
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define PPAPI_SIMPLE_PS_EVENT_H_
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ppapi/c/pp_bool.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ppapi/c/pp_resource.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ppapi/c/pp_var.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "sdk_util/macros.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)EXTERN_C_BEGIN
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/**
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * PSEvent
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) *
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * The PSEvent system provides an in-order event processing mechanism.
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * As Pepper events such as input, or focus and view changes arrive on the
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * main pepper thread, they are placed on various FIFOs based on event type.
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * For any given event type, only a single thread will process those events.
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) *
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * By default, the "EventThread" will receive all messages.  However any thread
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * can call PSRequestEventsType to request that all new events of that type
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * are placed on that particular thread's queue.
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) *
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * This allows the developer to choose which threads handle which event types
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * while keeping all events belonging to a particular thread in order.  This
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * is useful, for example, in the case of graphics to synchronize the size
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * of the graphics context, with mouse clicks to correctly interpret location.
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)typedef enum {
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* Mask off all events. */
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_NONE = 0,
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* From HandleInputEvent, conatins an input resource. */
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_INSTANCE_HANDLEINPUT = 1,
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* From HandleMessage, contains a PP_Var. */
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_INSTANCE_HANDLEMESSAGE = 2,
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* From DidChangeView, contains a view resource */
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_INSTANCE_DIDCHANGEVIEW = 4,
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* From DidChangeFocus, contains a PP_Bool with the current focus state. */
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_INSTANCE_DIDCHANGEFOCUS = 8,
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* When the 3D context is lost, no resource. */
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST = 16,
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* When the mouse lock is lost. */
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_MOUSELOCK_MOUSELOCKLOST = 32,
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /* Enable all events. */
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSE_ALL = -1,
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} PSEventType;
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)typedef uint32_t PSEventTypeMask;
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Generic Event
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)typedef struct {
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PSEventType type;
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  union {
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    PP_Bool as_bool;
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    PP_Resource as_resource;
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    struct PP_Var as_var;
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} PSEvent;
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/**
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Function for queuing, acquiring, and releasing events.
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)PSEvent* PSEventTryAcquire();
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)PSEvent* PSEventWaitAcquire();
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventRelease(PSEvent* event);
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventSetFilter(PSEventTypeMask mask);
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/**
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Creates and adds an event of the specified type to the event queue if
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * that event type is not currently filtered.
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventPost(PSEventType type);
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventPostBool(PSEventType type, PP_Bool state);
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventPostVar(PSEventType type, struct PP_Var var);
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void PSEventPostResource(PSEventType type, PP_Resource resource);
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)EXTERN_C_END
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif  /* PPAPI_SIMPLE_PS_EVENT_H_ */
94