2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkEvent_DEFINED
|
|
|
|
#define SkEvent_DEFINED
|
|
|
|
|
|
|
|
#include "SkMetaData.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2017-02-23 18:24:49 +00:00
|
|
|
class SkDOM;
|
|
|
|
struct SkDOMNode;
|
|
|
|
|
2016-06-08 00:21:10 +00:00
|
|
|
#include "../private/SkLeanWindows.h"
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Unique 32bit id used to identify an instance of SkEventSink. When events are
|
|
|
|
posted, they are posted to a specific sinkID. When it is time to dispatch the
|
|
|
|
event, the sinkID is used to find the specific SkEventSink object. If it is found,
|
|
|
|
its doEvent() method is called with the event.
|
|
|
|
*/
|
|
|
|
typedef uint32_t SkEventSinkID;
|
|
|
|
|
2011-08-04 13:50:17 +00:00
|
|
|
/**
|
|
|
|
* \class SkEvent
|
|
|
|
*
|
|
|
|
* When an event is dispatched from the event queue, it is either sent to
|
|
|
|
* the eventsink matching the target ID (if not 0), or the target proc is
|
|
|
|
* called (if not NULL).
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkEvent {
|
|
|
|
public:
|
2011-08-04 13:50:17 +00:00
|
|
|
/**
|
|
|
|
* Function pointer that takes an event, returns true if it "handled" it.
|
|
|
|
*/
|
|
|
|
typedef bool (*Proc)(const SkEvent& evt);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkEvent();
|
2011-08-04 13:50:17 +00:00
|
|
|
explicit SkEvent(const SkString& type, SkEventSinkID = 0);
|
|
|
|
explicit SkEvent(const char type[], SkEventSinkID = 0);
|
2008-12-17 15:59:43 +00:00
|
|
|
SkEvent(const SkEvent& src);
|
|
|
|
~SkEvent();
|
|
|
|
|
|
|
|
/** Copy the event's type into the specified SkString parameter */
|
2011-08-04 13:50:17 +00:00
|
|
|
void getType(SkString* str) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if the event's type matches exactly the specified type (case sensitive) */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool isType(const SkString& str) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if the event's type matches exactly the specified type (case sensitive) */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool isType(const char type[], size_t len = 0) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the event's type to the specified string.
|
|
|
|
*/
|
|
|
|
void setType(const SkString&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the event's type to the specified string.
|
|
|
|
*/
|
|
|
|
void setType(const char type[], size_t len = 0);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-08-03 19:41:24 +00:00
|
|
|
/**
|
|
|
|
* Return the target ID, or 0 if there is none.
|
2011-08-04 13:50:17 +00:00
|
|
|
*
|
|
|
|
* When an event is dispatched from the event queue, it is either sent to
|
|
|
|
* the eventsink matching the targetID (if not 0), or the target proc is
|
|
|
|
* called (if not NULL).
|
2011-08-03 19:41:24 +00:00
|
|
|
*/
|
|
|
|
SkEventSinkID getTargetID() const { return fTargetID; }
|
|
|
|
|
|
|
|
/**
|
2011-08-04 13:50:17 +00:00
|
|
|
* Set the target ID for this event. 0 means none. Calling this will
|
|
|
|
* automatically clear the targetProc to null.
|
|
|
|
*
|
|
|
|
* When an event is dispatched from the event queue, it is either sent to
|
|
|
|
* the eventsink matching the targetID (if not 0), or the target proc is
|
|
|
|
* called (if not NULL).
|
2011-08-03 19:41:24 +00:00
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
SkEvent* setTargetID(SkEventSinkID targetID) {
|
2017-08-28 14:34:05 +00:00
|
|
|
fTargetProc = nullptr;
|
2011-08-04 13:50:17 +00:00
|
|
|
fTargetID = targetID;
|
|
|
|
return this;
|
|
|
|
}
|
2011-08-03 19:41:24 +00:00
|
|
|
|
2011-08-04 13:50:17 +00:00
|
|
|
/**
|
|
|
|
* Return the target proc, or NULL if it has none.
|
|
|
|
*
|
|
|
|
* When an event is dispatched from the event queue, it is either sent to
|
|
|
|
* the eventsink matching the targetID (if not 0), or the target proc is
|
|
|
|
* called (if not NULL).
|
|
|
|
*/
|
|
|
|
Proc getTargetProc() const { return fTargetProc; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the target ID for this event. NULL means none. Calling this will
|
|
|
|
* automatically clear the targetID to 0.
|
|
|
|
*
|
|
|
|
* When an event is dispatched from the event queue, it is either sent to
|
|
|
|
* the eventsink matching the targetID (if not 0), or the target proc is
|
|
|
|
* called (if not NULL).
|
|
|
|
*/
|
|
|
|
SkEvent* setTargetProc(Proc proc) {
|
|
|
|
fTargetID = 0;
|
|
|
|
fTargetProc = proc;
|
|
|
|
return this;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-08-04 13:50:17 +00:00
|
|
|
/**
|
|
|
|
* Return the event's unnamed 32bit field. Default value is 0
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
uint32_t getFast32() const { return f32; }
|
2011-08-04 13:50:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the event's unnamed 32bit field.
|
|
|
|
*/
|
|
|
|
void setFast32(uint32_t x) { f32 = x; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return true if the event contains the named 32bit field, and return the field
|
|
|
|
in value (if value is non-null). If there is no matching named field, return false
|
|
|
|
and ignore the value parameter.
|
|
|
|
*/
|
2017-08-28 14:34:05 +00:00
|
|
|
bool findS32(const char name[], int32_t* value = nullptr) const {
|
|
|
|
return fMeta.findS32(name, value);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return true if the event contains the named SkScalar field, and return the field
|
|
|
|
in value (if value is non-null). If there is no matching named field, return false
|
|
|
|
and ignore the value parameter.
|
|
|
|
*/
|
2017-08-28 14:34:05 +00:00
|
|
|
bool findScalar(const char name[], SkScalar* value = nullptr) const {
|
|
|
|
return fMeta.findScalar(name, value);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return true if the event contains the named SkScalar field, and return the fields
|
|
|
|
in value[] (if value is non-null), and return the number of SkScalars in count (if count is non-null).
|
|
|
|
If there is no matching named field, return false and ignore the value and count parameters.
|
|
|
|
*/
|
2017-08-28 14:34:05 +00:00
|
|
|
const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = nullptr) const {
|
|
|
|
return fMeta.findScalars(name, count, values);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the value of the named string field, or if no matching named field exists, return null.
|
|
|
|
*/
|
|
|
|
const char* findString(const char name[]) const { return fMeta.findString(name); }
|
|
|
|
/** Return true if the event contains the named pointer field, and return the field
|
|
|
|
in value (if value is non-null). If there is no matching named field, return false
|
|
|
|
and ignore the value parameter.
|
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
bool findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); }
|
|
|
|
bool findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); }
|
2017-08-28 14:34:05 +00:00
|
|
|
const void* findData(const char name[], size_t* byteCount = nullptr) const {
|
2010-12-20 18:26:13 +00:00
|
|
|
return fMeta.findData(name, byteCount);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if ethe event contains the named SkScalar field, and if it equals the specified value */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if ethe event contains the named string field, and if it equals (using strcmp) the specified value */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if ethe event contains the named pointer field, and if it equals the specified value */
|
2011-08-04 13:50:17 +00:00
|
|
|
bool hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); }
|
|
|
|
bool hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); }
|
2010-12-20 18:26:13 +00:00
|
|
|
bool hasData(const char name[], const void* data, size_t byteCount) const {
|
|
|
|
return fMeta.hasData(name, data, byteCount);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */
|
2011-08-04 13:50:17 +00:00
|
|
|
void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add/replace the named SkScalar field to the event. In XML use the subelement <data name=... scalar=... /> */
|
2011-08-04 13:50:17 +00:00
|
|
|
void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add/replace the named SkScalar[] field to the event. */
|
2017-08-28 14:34:05 +00:00
|
|
|
SkScalar* setScalars(const char name[], int count, const SkScalar values[] = nullptr) {
|
|
|
|
return fMeta.setScalars(name, count, values);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
|
2011-08-04 13:50:17 +00:00
|
|
|
void setString(const char name[], const SkString& value) { fMeta.setString(name, value.c_str()); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */
|
2011-08-04 13:50:17 +00:00
|
|
|
void setString(const char name[], const char value[]) { fMeta.setString(name, value); }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add/replace the named pointer field to the event. There is no XML equivalent for this call */
|
2011-08-04 13:50:17 +00:00
|
|
|
void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); }
|
|
|
|
void setBool(const char name[], bool value) { fMeta.setBool(name, value); }
|
2010-12-20 18:26:13 +00:00
|
|
|
void setData(const char name[], const void* data, size_t byteCount) {
|
|
|
|
fMeta.setData(name, data, byteCount);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return the underlying metadata object */
|
2011-08-04 13:50:17 +00:00
|
|
|
SkMetaData& getMetaData() { return fMeta; }
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the underlying metadata object */
|
2011-08-04 13:50:17 +00:00
|
|
|
const SkMetaData& getMetaData() const { return fMeta; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Call this to initialize the event from the specified XML node */
|
2017-02-23 18:24:49 +00:00
|
|
|
void inflate(const SkDOM&, const SkDOMNode*);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-08-28 14:34:05 +00:00
|
|
|
SkDEBUGCODE(void dump(const char title[] = nullptr);)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-08-04 13:50:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-08-03 19:41:24 +00:00
|
|
|
/**
|
2011-08-04 13:50:17 +00:00
|
|
|
* Post to the event queue using the event's targetID or target-proc.
|
|
|
|
*
|
|
|
|
* The event must be dynamically allocated, as ownership is transferred to
|
|
|
|
* the event queue. It cannot be allocated on the stack or in a global.
|
2011-08-03 19:41:24 +00:00
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
void post() {
|
2011-08-03 19:41:24 +00:00
|
|
|
return this->postDelay(0);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-08-03 19:41:24 +00:00
|
|
|
/**
|
2011-08-04 13:50:17 +00:00
|
|
|
* Post to the event queue using the event's targetID or target-proc and
|
|
|
|
* the specifed millisecond delay.
|
|
|
|
*
|
|
|
|
* The event must be dynamically allocated, as ownership is transferred to
|
|
|
|
* the event queue. It cannot be allocated on the stack or in a global.
|
2011-08-03 19:41:24 +00:00
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
void postDelay(SkMSec delay);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-08-03 19:41:24 +00:00
|
|
|
/**
|
2011-08-04 13:50:17 +00:00
|
|
|
* Post to the event queue using the event's targetID or target-proc.
|
|
|
|
* The event will be delivered no sooner than the specified millisecond
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
* time, as measured by GetMSecsSinceStartup().
|
2011-08-04 13:50:17 +00:00
|
|
|
*
|
|
|
|
* The event must be dynamically allocated, as ownership is transferred to
|
|
|
|
* the event queue. It cannot be allocated on the stack or in a global.
|
2011-08-03 19:41:24 +00:00
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
void postTime(SkMSec time);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow.
The following are currently unused in Android, Google3, Chromium, and Mozilla:
- SkEvent
- SkTime::GetMSecs
- SK_TIME_FACTOR (also unused in Skia)
- SkAutoTime
I left uses of SkMSec more-or-less intact for SkEvent, SkAnimator, and SkInterpolator. SkInterpolator is used in Chromium, so I did not want to change the API. The views/ and animator/ code is crufty, so it didn't seem worthwhile to refactor it. Instead, I added SkEvent::GetMSecsSinceStartup, which is likely to be adequate for use in SampleApp.
I also left SkMSec where it is used to measure a duration rather than a timestamp. With the exception of SkMovie, which is used in Android, all of the uses appear to measure the execution time of a piece of code, which I would hope does not exceed 2^31 milliseconds.
Added skiatest::Timer to support a common idiom in tests where we want to measure the wallclock time in integer milliseconds. (Not used in tests/PathOpsSkpClipTest.cpp because it redefines things in Test.h.)
Removed tabs in tests/StrokerTest.cpp.
BUG=skia:4632
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1811613004
Review URL: https://codereview.chromium.org/1811613004
2016-03-25 19:59:53 +00:00
|
|
|
/**
|
|
|
|
* Returns ~zero the first time it's called, then returns the number of
|
|
|
|
* milliseconds since the first call. Behavior is undefined if the program
|
|
|
|
* runs more than ~25 days.
|
|
|
|
*/
|
|
|
|
static SkMSec GetMSecsSinceStartup();
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
///////////////////////////////////////////////
|
|
|
|
/** Porting layer must call these functions **/
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
|
|
/** Global initialization function for the SkEvent system. Should be called exactly
|
|
|
|
once before any other event method is called, and should be called after the
|
|
|
|
call to SkGraphics::Init().
|
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
static void Init();
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Global cleanup function for the SkEvent system. Should be called exactly once after
|
2015-09-09 14:35:42 +00:00
|
|
|
all event methods have been called.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
static void Term();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Call this to process one event from the queue. If it returns true, there are more events
|
|
|
|
to process.
|
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
static bool ProcessEvent();
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Call this whenever the requested timer has expired (requested by a call to SetQueueTimer).
|
|
|
|
It will post any delayed events whose time as "expired" onto the event queue.
|
|
|
|
It may also call SignalQueueTimer() and SignalNonEmptyQueue().
|
|
|
|
*/
|
2011-08-04 13:50:17 +00:00
|
|
|
static void ServiceQueueTimer();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
/** Return the number of queued events. note that this value may be obsolete
|
|
|
|
upon return, since another thread may have called ProcessEvent() or
|
|
|
|
Post() after the count was made.
|
|
|
|
*/
|
|
|
|
static int CountEventsOnQueue();
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
/** Porting layer must implement these functions **/
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/** Called whenever an SkEvent is posted to an empty queue, so that the OS
|
|
|
|
can be told to later call Dequeue().
|
|
|
|
*/
|
|
|
|
static void SignalNonEmptyQueue();
|
|
|
|
/** Called whenever the delay until the next delayed event changes. If zero is
|
|
|
|
passed, then there are no more queued delay events.
|
|
|
|
*/
|
|
|
|
static void SignalQueueTimer(SkMSec delay);
|
|
|
|
|
2012-10-01 16:14:21 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
2008-12-17 15:59:43 +00:00
|
|
|
static bool WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkMetaData fMeta;
|
|
|
|
mutable char* fType; // may be characters with low bit set to know that it is not a pointer
|
|
|
|
uint32_t f32;
|
2011-08-04 13:50:17 +00:00
|
|
|
|
|
|
|
// 'there can be only one' (non-zero) between target-id and target-proc
|
2011-08-03 19:41:24 +00:00
|
|
|
SkEventSinkID fTargetID;
|
2011-08-04 13:50:17 +00:00
|
|
|
Proc fTargetProc;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
// these are for our implementation of the event queue
|
|
|
|
SkMSec fTime;
|
|
|
|
SkEvent* fNextEvent; // either in the delay or normal event queue
|
2011-08-04 13:50:17 +00:00
|
|
|
|
|
|
|
void initialize(const char* type, size_t typeLen, SkEventSinkID);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static bool Enqueue(SkEvent* evt);
|
|
|
|
static SkMSec EnqueueTime(SkEvent* evt, SkMSec time);
|
2011-08-04 13:50:17 +00:00
|
|
|
static SkEvent* Dequeue();
|
2008-12-17 15:59:43 +00:00
|
|
|
static bool QHasEvents();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|