blob: a2ccb0c74833e7bd7dca662e044c6f03803047af [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkEvent_DEFINED
9#define SkEvent_DEFINED
10
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkMetaData.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012
reed@android.com8a1c16f2008-12-17 15:59:43 +000013/** 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*/
18typedef uint32_t SkEventSinkID;
19
reed@google.com87fac4a2011-08-04 13:50:17 +000020/**
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.com8a1c16f2008-12-17 15:59:43 +000027class SkEvent {
28public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 SkEvent();
Brian Osman4f99e582017-11-22 13:23:35 -050030 explicit SkEvent(const char type[]);
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 SkEvent(const SkEvent& src);
32 ~SkEvent();
33
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 /** Returns true if the event's type matches exactly the specified type (case sensitive) */
Brian Osman8ceee432017-12-01 10:52:28 -050035 bool isType(const char type[]) const;
reed@google.com87fac4a2011-08-04 13:50:17 +000036
37 /**
38 * Set the event's type to the specified string.
39 */
Brian Osman8ceee432017-12-01 10:52:28 -050040 void setType(const char type[]);
reed@android.com8a1c16f2008-12-17 15:59:43 +000041
reed@google.comc514dde2011-08-03 19:41:24 +000042 /**
reed@google.com87fac4a2011-08-04 13:50:17 +000043 * Return the event's unnamed 32bit field. Default value is 0
44 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 uint32_t getFast32() const { return f32; }
reed@google.com87fac4a2011-08-04 13:50:17 +000046
47 /**
48 * Set the event's unnamed 32bit field.
49 */
50 void setFast32(uint32_t x) { f32 = x; }
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
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 Wagnera93a14a2017-08-28 10:34:05 -040056 bool findS32(const char name[], int32_t* value = nullptr) const {
57 return fMeta.findS32(name, value);
58 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 /** 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 Wagnera93a14a2017-08-28 10:34:05 -040063 bool findScalar(const char name[], SkScalar* value = nullptr) const {
64 return fMeta.findScalar(name, value);
65 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 /** 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 Wagnera93a14a2017-08-28 10:34:05 -040070 const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = nullptr) const {
71 return fMeta.findScalars(name, count, values);
72 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 /** 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.com87fac4a2011-08-04 13:50:17 +000080 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 Wagnera93a14a2017-08-28 10:34:05 -040082 const void* findData(const char name[], size_t* byteCount = nullptr) const {
reed@android.comf2b98d62010-12-20 18:26:13 +000083 return fMeta.findData(name, byteCount);
84 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000085
86 /** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */
reed@google.com87fac4a2011-08-04 13:50:17 +000087 bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000088 /** Returns true if ethe event contains the named SkScalar field, and if it equals the specified value */
reed@google.com87fac4a2011-08-04 13:50:17 +000089 bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000090 /** Returns true if ethe event contains the named string field, and if it equals (using strcmp) the specified value */
reed@google.com87fac4a2011-08-04 13:50:17 +000091 bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000092 /** Returns true if ethe event contains the named pointer field, and if it equals the specified value */
reed@google.com87fac4a2011-08-04 13:50:17 +000093 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.comf2b98d62010-12-20 18:26:13 +000095 bool hasData(const char name[], const void* data, size_t byteCount) const {
96 return fMeta.hasData(name, data, byteCount);
97 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000098
99 /** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */
reed@google.com87fac4a2011-08-04 13:50:17 +0000100 void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101 /** Add/replace the named SkScalar field to the event. In XML use the subelement <data name=... scalar=... /> */
reed@google.com87fac4a2011-08-04 13:50:17 +0000102 void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103 /** Add/replace the named SkScalar[] field to the event. */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400104 SkScalar* setScalars(const char name[], int count, const SkScalar values[] = nullptr) {
105 return fMeta.setScalars(name, count, values);
106 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000107 /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
reed@google.com87fac4a2011-08-04 13:50:17 +0000108 void setString(const char name[], const char value[]) { fMeta.setString(name, value); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000109 /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */
reed@google.com87fac4a2011-08-04 13:50:17 +0000110 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.comf2b98d62010-12-20 18:26:13 +0000112 void setData(const char name[], const void* data, size_t byteCount) {
113 fMeta.setData(name, data, byteCount);
114 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115
116 /** Return the underlying metadata object */
reed@google.com87fac4a2011-08-04 13:50:17 +0000117 SkMetaData& getMetaData() { return fMeta; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000118 /** Return the underlying metadata object */
reed@google.com87fac4a2011-08-04 13:50:17 +0000119 const SkMetaData& getMetaData() const { return fMeta; }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000120
reed@google.com87fac4a2011-08-04 13:50:17 +0000121 ///////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000122
reed@android.com8a1c16f2008-12-17 15:59:43 +0000123private:
124 SkMetaData fMeta;
Brian Osman8ceee432017-12-01 10:52:28 -0500125 char* fType;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000126 uint32_t f32;
reed@google.com87fac4a2011-08-04 13:50:17 +0000127
Brian Osman8ceee432017-12-01 10:52:28 -0500128 void initialize(const char* type);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129};
130
131#endif