• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkEvent_DEFINED
9 #define SkEvent_DEFINED
10 
11 #include "SkMetaData.h"
12 
13 /** Unique 32bit id used to identify an instance of SkEventSink. When events are
14     posted, they are posted to a specific sinkID. When it is time to dispatch the
15     event, the sinkID is used to find the specific SkEventSink object. If it is found,
16     its doEvent() method is called with the event.
17 */
18 typedef uint32_t SkEventSinkID;
19 
20 /**
21  *  \class SkEvent
22  *
23  *  When an event is dispatched from the event queue, it is either sent to
24  *  the eventsink matching the target ID (if not 0), or the target proc is
25  *  called (if not NULL).
26  */
27 class SkEvent {
28 public:
29     SkEvent();
30     explicit SkEvent(const char type[]);
31     SkEvent(const SkEvent& src);
32     ~SkEvent();
33 
34     /** Returns true if the event's type matches exactly the specified type (case sensitive) */
35     bool isType(const char type[]) const;
36 
37     /**
38      *  Set the event's type to the specified string.
39      */
40     void setType(const char type[]);
41 
42     /**
43      *  Return the event's unnamed 32bit field. Default value is 0
44      */
getFast32()45     uint32_t getFast32() const { return f32; }
46 
47     /**
48      *  Set the event's unnamed 32bit field.
49      */
setFast32(uint32_t x)50     void setFast32(uint32_t x) { f32 = x; }
51 
52     /** Return true if the event contains the named 32bit field, and return the field
53         in value (if value is non-null). If there is no matching named field, return false
54         and ignore the value parameter.
55     */
56     bool findS32(const char name[], int32_t* value = nullptr) const {
57         return fMeta.findS32(name, value);
58     }
59     /** Return true if the event contains the named SkScalar field, and return the field
60         in value (if value is non-null). If there is no matching named field, return false
61         and ignore the value parameter.
62     */
63     bool findScalar(const char name[], SkScalar* value = nullptr) const {
64         return fMeta.findScalar(name, value);
65     }
66     /** Return true if the event contains the named SkScalar field, and return the fields
67         in value[] (if value is non-null), and return the number of SkScalars in count (if count is non-null).
68         If there is no matching named field, return false and ignore the value and count parameters.
69     */
70     const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = nullptr) const {
71         return fMeta.findScalars(name, count, values);
72     }
73     /** Return the value of the named string field, or if no matching named field exists, return null.
74     */
findString(const char name[])75     const char* findString(const char name[]) const { return fMeta.findString(name); }
76     /** Return true if the event contains the named pointer field, and return the field
77         in value (if value is non-null). If there is no matching named field, return false
78         and ignore the value parameter.
79     */
findPtr(const char name[],void ** value)80     bool findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); }
findBool(const char name[],bool * value)81     bool findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); }
82     const void* findData(const char name[], size_t* byteCount = nullptr) const {
83         return fMeta.findData(name, byteCount);
84     }
85 
86     /** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */
hasS32(const char name[],int32_t value)87     bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
88     /** Returns true if ethe event contains the named SkScalar field, and if it equals the specified value */
hasScalar(const char name[],SkScalar value)89     bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); }
90     /** Returns true if ethe event contains the named string field, and if it equals (using strcmp) the specified value */
hasString(const char name[],const char value[])91     bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); }
92     /** Returns true if ethe event contains the named pointer field, and if it equals the specified value */
hasPtr(const char name[],void * value)93     bool hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); }
hasBool(const char name[],bool value)94     bool hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); }
hasData(const char name[],const void * data,size_t byteCount)95     bool hasData(const char name[], const void* data, size_t byteCount) const {
96         return fMeta.hasData(name, data, byteCount);
97     }
98 
99     /** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */
setS32(const char name[],int32_t value)100     void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
101     /** Add/replace the named SkScalar field to the event. In XML use the subelement <data name=... scalar=... /> */
setScalar(const char name[],SkScalar value)102     void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); }
103     /** Add/replace the named SkScalar[] field to the event. */
104     SkScalar* setScalars(const char name[], int count, const SkScalar values[] = nullptr) {
105         return fMeta.setScalars(name, count, values);
106     }
107     /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
setString(const char name[],const char value[])108     void setString(const char name[], const char value[]) { fMeta.setString(name, value); }
109     /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */
setPtr(const char name[],void * value)110     void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); }
setBool(const char name[],bool value)111     void setBool(const char name[], bool value) { fMeta.setBool(name, value); }
setData(const char name[],const void * data,size_t byteCount)112     void setData(const char name[], const void* data, size_t byteCount) {
113         fMeta.setData(name, data, byteCount);
114     }
115 
116     /** Return the underlying metadata object */
getMetaData()117     SkMetaData& getMetaData() { return fMeta; }
118     /** Return the underlying metadata object */
getMetaData()119     const SkMetaData& getMetaData() const { return fMeta; }
120 
121     ///////////////////////////////////////////////////////////////////////////
122 
123 private:
124     SkMetaData      fMeta;
125     char*           fType;
126     uint32_t        f32;
127 
128     void initialize(const char* type);
129 };
130 
131 #endif
132