OSDN Git Service

Add message callbacks for drivers to use
authorMark Thompson <sw@jkqxz.net>
Mon, 2 Oct 2017 22:50:26 +0000 (23:50 +0100)
committerXiang, Haihao <haihao.xiang@intel.com>
Wed, 22 Nov 2017 05:38:52 +0000 (21:38 -0800)
This adds a mechanism for drivers to propagate arbitrary log messages
back to the API user.  It is intended to be used to replace all use of
logging to stdout/stderr in drivers.

Signed-off-by: Mark Thompson <sw@jkqxz.net>
va/va.c
va/va_backend.h

diff --git a/va/va.c b/va/va.c
index 257b241..f29e306 100644 (file)
--- a/va/va.c
+++ b/va/va.c
@@ -261,6 +261,24 @@ void va_infoMessage(VADisplay dpy, const char *msg, ...)
 #endif
 }
 
+static void va_driverErrorCallback(VADriverContextP ctx,
+                                   const char *message)
+{
+    VADisplayContextP dctx = ctx->pDisplayContext;
+    if (!dctx)
+        return;
+    dctx->error_callback(dctx->error_callback_user_context, message);
+}
+
+static void va_driverInfoCallback(VADriverContextP ctx,
+                                  const char *message)
+{
+    VADisplayContextP dctx = ctx->pDisplayContext;
+    if (!dctx)
+        return;
+    dctx->info_callback(dctx->info_callback_user_context, message);
+}
+
 VADisplayContextP va_newDisplayContext(void)
 {
     VADisplayContextP dctx = calloc(1, sizeof(*dctx));
@@ -282,6 +300,10 @@ VADriverContextP va_newDriverContext(VADisplayContextP dctx)
         return NULL;
 
     dctx->pDriverContext = ctx;
+    ctx->pDisplayContext = dctx;
+
+    ctx->error_callback = va_driverErrorCallback;
+    ctx->info_callback  = va_driverInfoCallback;
 
     return ctx;
 }
index a48c6ca..d6f1782 100644 (file)
@@ -552,7 +552,48 @@ struct VADriverContext
 
     char *override_driver_name;
 
-    unsigned long reserved[41];         /* reserve for future add-ins, decrease the subscript accordingly */
+    void *pDisplayContext;
+
+    /**
+     * Error callback.
+     *
+     * This is set by libva when the driver is opened, and will not be
+     * changed thereafter.  The driver can call it with an error message,
+     * which will be propagated to the API user through their error
+     * callbacks, or sent to a default output if no callback is available.
+     *
+     * It is expected that end users will always be able to see these
+     * messages, so it should be called only for serious errors.  For
+     * example, hardware problems or fatal configuration errors.
+     *
+     * @param pDriverContext  Pointer to the driver context structure
+     *                        being used by the current driver.
+     * @param message  Message to send to the API user.  This must be a
+     *                 null-terminated string.
+     */
+    void (*error_callback)(VADriverContextP pDriverContext,
+                           const char *message);
+    /**
+     * Info callback.
+     *
+     * This has the same behaviour as the error callback, but has its
+     * own set of callbacks to the API user.
+     *
+     * It should be used for informational messages which may be useful
+     * for an application programmer or for debugging.  For example, minor
+     * configuration errors, or information about the reason when another
+     * API call generates an error return.  It is not expected that end
+     * users will see these messages.
+     *
+     * @param pDriverContext  Pointer to the driver context structure
+     *                        being used by the current driver.
+     * @param message  Message to send to the API user.  This must be a
+     *                 null-terminated string.
+     */
+    void (*info_callback)(VADriverContextP pDriverContext,
+                          const char *message);
+
+    unsigned long reserved[38];         /* reserve for future add-ins, decrease the subscript accordingly */
 };
 
 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */