180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkEvent_DEFINED
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkEvent_DEFINED
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDOM.h"
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMetaData.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkString.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** Unique 32bit id used to identify an instance of SkEventSink. When events are
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    posted, they are posted to a specific sinkID. When it is time to dispatch the
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    event, the sinkID is used to find the specific SkEventSink object. If it is found,
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    its doEvent() method is called with the event.
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutypedef uint32_t SkEventSinkID;
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  \class SkEvent
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  When an event is dispatched from the event queue, it is either sent to
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  the eventsink matching the target ID (if not 0), or the target proc is
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *  called (if not NULL).
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkEvent {
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Function pointer that takes an event, returns true if it "handled" it.
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef bool (*Proc)(const SkEvent& evt);
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEvent();
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    explicit SkEvent(const SkString& type, SkEventSinkID = 0);
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    explicit SkEvent(const char type[], SkEventSinkID = 0);
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEvent(const SkEvent& src);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ~SkEvent();
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Copy the event's type into the specified SkString parameter */
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void getType(SkString* str) const;
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if the event's type matches exactly the specified type (case sensitive) */
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isType(const SkString& str) const;
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if the event's type matches exactly the specified type (case sensitive) */
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isType(const char type[], size_t len = 0) const;
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Set the event's type to the specified string.
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setType(const SkString&);
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Set the event's type to the specified string.
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setType(const char type[], size_t len = 0);
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Return the target ID, or 0 if there is none.
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  When an event is dispatched from the event queue, it is either sent to
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the eventsink matching the targetID (if not 0), or the target proc is
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  called (if not NULL).
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEventSinkID getTargetID() const { return fTargetID; }
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Set the target ID for this event. 0 means none. Calling this will
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  automatically clear the targetProc to null.
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  When an event is dispatched from the event queue, it is either sent to
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the eventsink matching the targetID (if not 0), or the target proc is
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  called (if not NULL).
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEvent* setTargetID(SkEventSinkID targetID) {
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTargetProc = NULL;
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTargetID = targetID;
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return this;
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Return the target proc, or NULL if it has none.
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  When an event is dispatched from the event queue, it is either sent to
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the eventsink matching the targetID (if not 0), or the target proc is
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  called (if not NULL).
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Proc getTargetProc() const { return fTargetProc; }
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Set the target ID for this event. NULL means none. Calling this will
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  automatically clear the targetID to 0.
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  When an event is dispatched from the event queue, it is either sent to
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the eventsink matching the targetID (if not 0), or the target proc is
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  called (if not NULL).
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEvent* setTargetProc(Proc proc) {
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTargetID = 0;
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fTargetProc = proc;
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return this;
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Return the event's unnamed 32bit field. Default value is 0
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint32_t getFast32() const { return f32; }
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Set the event's unnamed 32bit field.
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setFast32(uint32_t x) { f32 = x; }
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return true if the event contains the named 32bit field, and return the field
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        in value (if value is non-null). If there is no matching named field, return false
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        and ignore the value parameter.
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool findS32(const char name[], int32_t* value = NULL) const { return fMeta.findS32(name, value); }
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return true if the event contains the named SkScalar field, and return the field
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        in value (if value is non-null). If there is no matching named field, return false
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        and ignore the value parameter.
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool findScalar(const char name[], SkScalar* value = NULL) const { return fMeta.findScalar(name, value); }
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return true if the event contains the named SkScalar field, and return the fields
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        in value[] (if value is non-null), and return the number of SkScalars in count (if count is non-null).
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        If there is no matching named field, return false and ignore the value and count parameters.
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = NULL) const { return fMeta.findScalars(name, count, values); }
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return the value of the named string field, or if no matching named field exists, return null.
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const char* findString(const char name[]) const { return fMeta.findString(name); }
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return true if the event contains the named pointer field, and return the field
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        in value (if value is non-null). If there is no matching named field, return false
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        and ignore the value parameter.
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); }
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); }
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const void* findData(const char name[], size_t* byteCount = NULL) const {
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return fMeta.findData(name, byteCount);
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if ethe event contains the named SkScalar field, and if it equals the specified value */
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); }
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if ethe event contains the named string field, and if it equals (using strcmp) the specified value */
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); }
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Returns true if ethe event contains the named pointer field, and if it equals the specified value */
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); }
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); }
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasData(const char name[], const void* data, size_t byteCount) const {
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return fMeta.hasData(name, data, byteCount);
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named SkScalar field to the event. In XML use the subelement <data name=... scalar=... /> */
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); }
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named SkScalar[] field to the event. */
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkScalar* setScalars(const char name[], int count, const SkScalar values[] = NULL) { return fMeta.setScalars(name, count, values); }
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setString(const char name[], const SkString& value) { fMeta.setString(name, value.c_str()); }
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setString(const char name[], const char value[]) { fMeta.setString(name, value); }
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); }
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setBool(const char name[], bool value) { fMeta.setBool(name, value); }
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setData(const char name[], const void* data, size_t byteCount) {
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fMeta.setData(name, data, byteCount);
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return the underlying metadata object */
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMetaData& getMetaData() { return fMeta; }
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return the underlying metadata object */
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkMetaData& getMetaData() const { return fMeta; }
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Call this to initialize the event from the specified XML node */
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void inflate(const SkDOM&, const SkDOM::Node*);
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDEBUGCODE(void dump(const char title[] = NULL);)
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ///////////////////////////////////////////////////////////////////////////
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Post to the event queue using the event's targetID or target-proc.
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  The event must be dynamically allocated, as ownership is transferred to
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the event queue. It cannot be allocated on the stack or in a global.
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void post() {
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return this->postDelay(0);
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Post to the event queue using the event's targetID or target-proc and
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the specifed millisecond delay.
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  The event must be dynamically allocated, as ownership is transferred to
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the event queue. It cannot be allocated on the stack or in a global.
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void postDelay(SkMSec delay);
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  Post to the event queue using the event's targetID or target-proc.
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  The event will be delivered no sooner than the specified millisecond
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  time, as measured by SkTime::GetMSecs().
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  The event must be dynamically allocated, as ownership is transferred to
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     *  the event queue. It cannot be allocated on the stack or in a global.
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void postTime(SkMSec time);
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ///////////////////////////////////////////////
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Porting layer must call these functions **/
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ///////////////////////////////////////////////
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Global initialization function for the SkEvent system. Should be called exactly
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        once before any other event method is called, and should be called after the
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        call to SkGraphics::Init().
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void Init();
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Global cleanup function for the SkEvent system. Should be called exactly once after
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        all event methods have been called, and should be called before calling SkGraphics::Term().
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void Term();
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Call this to process one event from the queue. If it returns true, there are more events
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        to process.
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool ProcessEvent();
23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Call this whenever the requested timer has expired (requested by a call to SetQueueTimer).
23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        It will post any delayed events whose time as "expired" onto the event queue.
23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        It may also call SignalQueueTimer() and SignalNonEmptyQueue().
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void ServiceQueueTimer();
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Return the number of queued events. note that this value may be obsolete
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        upon return, since another thread may have called ProcessEvent() or
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        Post() after the count was made.
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static int CountEventsOnQueue();
24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ////////////////////////////////////////////////////
24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Porting layer must implement these functions **/
24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ////////////////////////////////////////////////////
24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Called whenever an SkEvent is posted to an empty queue, so that the OS
25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        can be told to later call Dequeue().
25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void SignalNonEmptyQueue();
25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /** Called whenever the delay until the next delayed event changes. If zero is
25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        passed, then there are no more queued delay events.
25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    */
25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void SignalQueueTimer(SkMSec delay);
25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if defined(SK_BUILD_FOR_WIN)
26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMetaData      fMeta;
26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    mutable char*   fType;  // may be characters with low bit set to know that it is not a pointer
26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint32_t        f32;
26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // 'there can be only one' (non-zero) between target-id and target-proc
26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEventSinkID   fTargetID;
27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    Proc            fTargetProc;
27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // these are for our implementation of the event queue
27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkMSec          fTime;
27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkEvent*        fNextEvent; // either in the delay or normal event queue
27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void initialize(const char* type, size_t typeLen, SkEventSinkID);
27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool Enqueue(SkEvent* evt);
27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkMSec EnqueueTime(SkEvent* evt, SkMSec time);
28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static SkEvent* Dequeue();
28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool     QHasEvents();
28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
285