reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkEvent_DEFINED |
| 9 | #define SkEvent_DEFINED |
| 10 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | #include "SkMetaData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | class SkEvent { |
| 28 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | SkEvent(); |
Brian Osman | 4f99e58 | 2017-11-22 13:23:35 -0500 | [diff] [blame] | 30 | explicit SkEvent(const char type[]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | SkEvent(const SkEvent& src); |
| 32 | ~SkEvent(); |
| 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | /** Returns true if the event's type matches exactly the specified type (case sensitive) */ |
Brian Osman | 8ceee43 | 2017-12-01 10:52:28 -0500 | [diff] [blame^] | 35 | bool isType(const char type[]) const; |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Set the event's type to the specified string. |
| 39 | */ |
Brian Osman | 8ceee43 | 2017-12-01 10:52:28 -0500 | [diff] [blame^] | 40 | void setType(const char type[]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | |
reed@google.com | c514dde | 2011-08-03 19:41:24 +0000 | [diff] [blame] | 42 | /** |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 43 | * Return the event's unnamed 32bit field. Default value is 0 |
| 44 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | uint32_t getFast32() const { return f32; } |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Set the event's unnamed 32bit field. |
| 49 | */ |
| 50 | void setFast32(uint32_t x) { f32 = x; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 56 | bool findS32(const char name[], int32_t* value = nullptr) const { |
| 57 | return fMeta.findS32(name, value); |
| 58 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 63 | bool findScalar(const char name[], SkScalar* value = nullptr) const { |
| 64 | return fMeta.findScalar(name, value); |
| 65 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 70 | const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = nullptr) const { |
| 71 | return fMeta.findScalars(name, count, values); |
| 72 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | /** Return the value of the named string field, or if no matching named field exists, return null. |
| 74 | */ |
| 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 | */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 80 | bool findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); } |
| 81 | bool findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); } |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 82 | const void* findData(const char name[], size_t* byteCount = nullptr) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 83 | return fMeta.findData(name, byteCount); |
| 84 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | |
| 86 | /** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 87 | bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | /** Returns true if ethe event contains the named SkScalar field, and if it equals the specified value */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 89 | bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | /** Returns true if ethe event contains the named string field, and if it equals (using strcmp) the specified value */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 91 | bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | /** Returns true if ethe event contains the named pointer field, and if it equals the specified value */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 93 | bool hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); } |
| 94 | bool hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 95 | bool hasData(const char name[], const void* data, size_t byteCount) const { |
| 96 | return fMeta.hasData(name, data, byteCount); |
| 97 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | |
| 99 | /** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 100 | void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 101 | /** Add/replace the named SkScalar field to the event. In XML use the subelement <data name=... scalar=... /> */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 102 | void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | /** Add/replace the named SkScalar[] field to the event. */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 104 | SkScalar* setScalars(const char name[], int count, const SkScalar values[] = nullptr) { |
| 105 | return fMeta.setScalars(name, count, values); |
| 106 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 107 | /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 108 | void setString(const char name[], const char value[]) { fMeta.setString(name, value); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 109 | /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 110 | void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); } |
| 111 | void setBool(const char name[], bool value) { fMeta.setBool(name, value); } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 112 | void setData(const char name[], const void* data, size_t byteCount) { |
| 113 | fMeta.setData(name, data, byteCount); |
| 114 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | |
| 116 | /** Return the underlying metadata object */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 117 | SkMetaData& getMetaData() { return fMeta; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 118 | /** Return the underlying metadata object */ |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 119 | const SkMetaData& getMetaData() const { return fMeta; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 120 | |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 121 | /////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 122 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 123 | private: |
| 124 | SkMetaData fMeta; |
Brian Osman | 8ceee43 | 2017-12-01 10:52:28 -0500 | [diff] [blame^] | 125 | char* fType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 126 | uint32_t f32; |
reed@google.com | 87fac4a | 2011-08-04 13:50:17 +0000 | [diff] [blame] | 127 | |
Brian Osman | 8ceee43 | 2017-12-01 10:52:28 -0500 | [diff] [blame^] | 128 | void initialize(const char* type); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #endif |