Platform.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style license that can be
  4. // found in the LICENSE file.
  5. // Platform.h: The public interface ANGLE exposes to the API layer, for
  6. // doing platform-specific tasks like gathering data, or for tracing.
  7. #ifndef ANGLE_PLATFORM_H
  8. #define ANGLE_PLATFORM_H
  9. #include <stdint.h>
  10. #include "../export.h"
  11. namespace angle
  12. {
  13. class Platform
  14. {
  15. public:
  16. // System --------------------------------------------------------------
  17. // Wall clock time in seconds since the epoch.
  18. // TODO(jmadill): investigate using an ANGLE internal time library
  19. virtual double currentTime() { return 0; }
  20. // Monotonically increasing time in seconds from an arbitrary fixed point in the past.
  21. // This function is expected to return at least millisecond-precision values. For this reason,
  22. // it is recommended that the fixed point be no further in the past than the epoch.
  23. virtual double monotonicallyIncreasingTime() { return 0; }
  24. // Tracing --------
  25. // Get a pointer to the enabled state of the given trace category. The
  26. // embedder can dynamically change the enabled state as trace event
  27. // recording is started and stopped by the application. Only long-lived
  28. // literal strings should be given as the category name. The implementation
  29. // expects the returned pointer to be held permanently in a local static. If
  30. // the unsigned char is non-zero, tracing is enabled. If tracing is enabled,
  31. // addTraceEvent is expected to be called by the trace event macros.
  32. virtual const unsigned char *getTraceCategoryEnabledFlag(const char *categoryName) { return 0; }
  33. typedef uint64_t TraceEventHandle;
  34. // Add a trace event to the platform tracing system. Depending on the actual
  35. // enabled state, this event may be recorded or dropped.
  36. // - phase specifies the type of event:
  37. // - BEGIN ('B'): Marks the beginning of a scoped event.
  38. // - END ('E'): Marks the end of a scoped event.
  39. // - COMPLETE ('X'): Marks the beginning of a scoped event, but doesn't
  40. // need a matching END event. Instead, at the end of the scope,
  41. // updateTraceEventDuration() must be called with the TraceEventHandle
  42. // returned from addTraceEvent().
  43. // - INSTANT ('I'): Standalone, instantaneous event.
  44. // - START ('S'): Marks the beginning of an asynchronous event (the end
  45. // event can occur in a different scope or thread). The id parameter is
  46. // used to match START/FINISH pairs.
  47. // - FINISH ('F'): Marks the end of an asynchronous event.
  48. // - COUNTER ('C'): Used to trace integer quantities that change over
  49. // time. The argument values are expected to be of type int.
  50. // - METADATA ('M'): Reserved for internal use.
  51. // - categoryEnabled is the pointer returned by getTraceCategoryEnabledFlag.
  52. // - name is the name of the event. Also used to match BEGIN/END and
  53. // START/FINISH pairs.
  54. // - id optionally allows events of the same name to be distinguished from
  55. // each other. For example, to trace the consutruction and destruction of
  56. // objects, specify the pointer as the id parameter.
  57. // - timestamp should be a time value returned from monotonicallyIncreasingTime.
  58. // - numArgs specifies the number of elements in argNames, argTypes, and
  59. // argValues.
  60. // - argNames is the array of argument names. Use long-lived literal strings
  61. // or specify the COPY flag.
  62. // - argTypes is the array of argument types:
  63. // - BOOL (1): bool
  64. // - UINT (2): unsigned long long
  65. // - INT (3): long long
  66. // - DOUBLE (4): double
  67. // - POINTER (5): void*
  68. // - STRING (6): char* (long-lived null-terminated char* string)
  69. // - COPY_STRING (7): char* (temporary null-terminated char* string)
  70. // - CONVERTABLE (8): WebConvertableToTraceFormat
  71. // - argValues is the array of argument values. Each value is the unsigned
  72. // long long member of a union of all supported types.
  73. // - flags can be 0 or one or more of the following, ORed together:
  74. // - COPY (0x1): treat all strings (name, argNames and argValues of type
  75. // string) as temporary so that they will be copied by addTraceEvent.
  76. // - HAS_ID (0x2): use the id argument to uniquely identify the event for
  77. // matching with other events of the same name.
  78. // - MANGLE_ID (0x4): specify this flag if the id parameter is the value
  79. // of a pointer.
  80. virtual TraceEventHandle addTraceEvent(char phase,
  81. const unsigned char *categoryEnabledFlag,
  82. const char *name,
  83. unsigned long long id,
  84. double timestamp,
  85. int numArgs,
  86. const char **argNames,
  87. const unsigned char *argTypes,
  88. const unsigned long long *argValues,
  89. unsigned char flags)
  90. {
  91. return 0;
  92. }
  93. // Set the duration field of a COMPLETE trace event.
  94. virtual void updateTraceEventDuration(const unsigned char *categoryEnabledFlag, const char *name, TraceEventHandle eventHandle) { }
  95. // Callbacks for reporting histogram data.
  96. // CustomCounts histogram has exponential bucket sizes, so that min=1, max=1000000, bucketCount=50 would do.
  97. virtual void histogramCustomCounts(const char *name, int sample, int min, int max, int bucketCount) { }
  98. // Enumeration histogram buckets are linear, boundaryValue should be larger than any possible sample value.
  99. virtual void histogramEnumeration(const char *name, int sample, int boundaryValue) { }
  100. // Unlike enumeration histograms, sparse histograms only allocate memory for non-empty buckets.
  101. virtual void histogramSparse(const char *name, int sample) { }
  102. // Boolean histograms track two-state variables.
  103. virtual void histogramBoolean(const char *name, bool sample) { }
  104. protected:
  105. virtual ~Platform() { }
  106. };
  107. }
  108. typedef void(*ANGLEPlatformInitializeFunc)(angle::Platform*);
  109. ANGLE_EXPORT void ANGLEPlatformInitialize(angle::Platform*);
  110. typedef void (*ANGLEPlatformShutdownFunc)();
  111. ANGLE_EXPORT void ANGLEPlatformShutdown();
  112. typedef angle::Platform *(*ANGLEPlatformCurrentFunc)();
  113. ANGLE_EXPORT angle::Platform *ANGLEPlatformCurrent();
  114. #endif // ANGLE_PLATFORM_H