gallium/postprocess: share pipe_context and cso_context with the state tracker
[mesa.git] / src / gallium / include / state_tracker / st_api.h
index 70ad215bfce57f18321d8dcf220c5527127cb453..91c5529a1f5ed371c9603b57922858a0358f9943 100644 (file)
  * tracker managers.
  */
 
-/**
- * The entry points of the state trackers.
- */
-#define ST_MODULE_OPENGL_SYMBOL      "st_module_OpenGL"
-#define ST_MODULE_OPENGL_ES1_SYMBOL  "st_module_OpenGL_ES1"
-#define ST_MODULE_OPENGL_ES2_SYMBOL  "st_module_OpenGL_ES2"
-#define ST_MODULE_OPENVG_SYMBOL      "st_module_OpenVG"
-
 /**
  * The supported rendering API of a state tracker.
  */
 enum st_api_type {
    ST_API_OPENGL,
-   ST_API_OPENGL_ES1,
-   ST_API_OPENGL_ES2,
    ST_API_OPENVG,
 
    ST_API_COUNT
 };
 
+/**
+ * The profile of a context.
+ */
+enum st_profile_type
+{
+   ST_PROFILE_DEFAULT,                 /**< OpenGL compatibility profile */
+   ST_PROFILE_OPENGL_CORE,             /**< OpenGL 3.2+ core profile */
+   ST_PROFILE_OPENGL_ES1,              /**< OpenGL ES 1.x */
+   ST_PROFILE_OPENGL_ES2               /**< OpenGL ES 2.0 */
+};
+
+/* for profile_mask in st_api */
+#define ST_PROFILE_DEFAULT_MASK      (1 << ST_PROFILE_DEFAULT)
+#define ST_PROFILE_OPENGL_CORE_MASK  (1 << ST_PROFILE_OPENGL_CORE)
+#define ST_PROFILE_OPENGL_ES1_MASK   (1 << ST_PROFILE_OPENGL_ES1)
+#define ST_PROFILE_OPENGL_ES2_MASK   (1 << ST_PROFILE_OPENGL_ES2)
+
+/**
+ * Optional API/state tracker features.
+ */
+enum st_api_feature
+{
+   ST_API_FEATURE_MS_VISUALS  /**< support for multisample visuals */
+};
+
+/* for feature_mask in st_api */
+#define ST_API_FEATURE_MS_VISUALS_MASK (1 << ST_API_FEATURE_MS_VISUALS)
+
+/**
+ * New context flags for GL 3.0 and beyond.
+ *
+ * Profile information (core vs. compatibilty for OpenGL 3.2+) is communicated
+ * through the \c st_profile_type, not through flags.
+ */
+#define ST_CONTEXT_FLAG_DEBUG               (1 << 0)
+#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE  (1 << 1)
+#define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 2)
+
+/**
+ * Reasons that context creation might fail.
+ */
+enum st_context_error {
+   ST_CONTEXT_SUCCESS = 0,
+   ST_CONTEXT_ERROR_NO_MEMORY,
+   ST_CONTEXT_ERROR_BAD_API,
+   ST_CONTEXT_ERROR_BAD_VERSION,
+   ST_CONTEXT_ERROR_BAD_FLAG,
+   ST_CONTEXT_ERROR_UNKNOWN_ATTRIBUTE,
+   ST_CONTEXT_ERROR_UNKNOWN_FLAG
+};
+
 /**
  * Used in st_context_iface->teximage.
  */
@@ -69,7 +110,7 @@ enum st_texture_type {
    ST_TEXTURE_1D,
    ST_TEXTURE_2D,
    ST_TEXTURE_3D,
-   ST_TEXTURE_RECT,
+   ST_TEXTURE_RECT
 };
 
 /**
@@ -110,7 +151,26 @@ enum st_context_resource_type {
    ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Z,
    ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    ST_CONTEXT_RESOURCE_OPENGL_RENDERBUFFER,
-   ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE,
+   ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE
+};
+
+/**
+ * Flush flags.
+ */
+#define ST_FLUSH_FRONT                    (1 << 0)
+
+/**
+ * Value to st_manager->get_param function.
+ */
+enum st_manager_param {
+   /**
+    * The dri state tracker on old libGL's doesn't do the right thing
+    * with regards to invalidating the framebuffers.
+    *
+    * For the mesa state tracker that means that it needs to invalidate
+    * the framebuffer in glViewport itself.
+    */
+   ST_MANAGER_BROKEN_INVALIDATE
 };
 
 /**
@@ -119,7 +179,7 @@ enum st_context_resource_type {
 typedef void (*st_proc_t)(void);
 
 struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
 struct pipe_fence_handle;
 
 /**
@@ -127,12 +187,12 @@ struct pipe_fence_handle;
  */
 struct st_context_resource
 {
-   /* these fields are filled by the caller */
+   /* these fields are filled in by the caller */
    enum st_context_resource_type type;
    void *resource;
 
    /* this is owned by the caller */
-   struct pipe_texture *texture;
+   struct pipe_resource *texture;
 };
 
 /**
@@ -140,16 +200,11 @@ struct st_context_resource
  */
 struct st_egl_image
 {
-   /* these fields are filled by the caller */
-   struct st_context_iface *stctxi;
-   void *egl_image;
-
    /* this is owned by the caller */
-   struct pipe_texture *texture;
+   struct pipe_resource *texture;
 
-   unsigned face;
    unsigned level;
-   unsigned zslice;
+   unsigned layer;
 };
 
 /**
@@ -177,27 +232,69 @@ struct st_visual
    enum st_attachment_type render_buffer;
 };
 
+
+/**
+ * Configuration options from driconf
+ */
+struct st_config_options
+{
+       boolean force_glsl_extensions_warn;
+};
+
+/**
+ * Represent the attributes of a context.
+ */
+struct st_context_attribs
+{
+   /**
+    * The profile and minimal version to support.
+    *
+    * The valid profiles and versions are rendering API dependent.  The latest
+    * version satisfying the request should be returned.
+    */
+   enum st_profile_type profile;
+   int major, minor;
+
+   /** Mask of ST_CONTEXT_FLAG_x bits */
+   unsigned flags;
+
+   /**
+    * The visual of the framebuffers the context will be bound to.
+    */
+   struct st_visual visual;
+
+   /**
+    * Configuration options.
+    */
+   struct st_config_options options;
+};
+
 /**
  * Represent a windowing system drawable.
  *
  * The framebuffer is implemented by the state tracker manager and
  * used by the state trackers.
  *
- * Instead of the winsys pokeing into the API context to figure
+ * Instead of the winsys poking into the API context to figure
  * out what buffers that might be needed in the future by the API
  * context, it calls into the framebuffer to get the textures.
  *
  * This structure along with the notify_invalid_framebuffer
  * allows framebuffers to be shared between different threads
  * but at the same make the API context free from thread
- * syncronisation primitves, with the exception of a small
+ * synchronization primitves, with the exception of a small
  * atomic flag used for notification of framebuffer dirty status.
  *
- * The thread syncronisation is put inside the framebuffer
+ * The thread synchronization is put inside the framebuffer
  * and only called once the framebuffer has become dirty.
  */
 struct st_framebuffer_iface
 {
+   /**
+    * Atomic stamp which changes when framebuffers need to be updated.
+    */
+   int32_t stamp;
+
    /**
     * Available for the state tracker manager to use.
     */
@@ -239,7 +336,7 @@ struct st_framebuffer_iface
    boolean (*validate)(struct st_framebuffer_iface *stfbi,
                        const enum st_attachment_type *statts,
                        unsigned count,
-                       struct pipe_texture **out);
+                       struct pipe_resource **out);
 };
 
 /**
@@ -256,28 +353,20 @@ struct st_context_iface
    void *st_manager_private;
 
    /**
-    * Destroy the context.
+    * The CSO context associated with this context in case we need to draw
+    * something before swap buffers.
     */
-   void (*destroy)(struct st_context_iface *stctxi);
+   struct cso_context *cso_context;
 
    /**
-    * Invalidate the current textures that was taken from a framebuffer.
-    *
-    * The state tracker manager calls this function to let the rendering
-    * context know that it should update the textures it got from
-    * st_framebuffer_iface::validate.  It should do so at the latest time possible.
-    * Possible right before sending triangles to the pipe context.
-    *
-    * For certain platforms this function might be called from a thread other
-    * than the thread that the context is currently bound in, and must
-    * therefore be thread safe. But it is the state tracker manager's
-    * responsibility to make sure that the framebuffer is bound to the context
-    * and the API context is current for the duration of this call.
-    *
-    * Thus reducing the sync primitive needed to a single atomic flag.
+    * The gallium context.
     */
-   void (*notify_invalid_framebuffer)(struct st_context_iface *stctxi,
-                                      struct st_framebuffer_iface *stfbi);
+   struct pipe_context *pipe;
+
+   /**
+    * Destroy the context.
+    */
+   void (*destroy)(struct st_context_iface *stctxi);
 
    /**
     * Flush all drawing from context to the pipe also flushes the pipe.
@@ -290,9 +379,10 @@ struct st_context_iface
     *
     * This function is optional.
     */
-   boolean (*teximage)(struct st_context_iface *stctxi, enum st_texture_type target,
+   boolean (*teximage)(struct st_context_iface *stctxi,
+                       enum st_texture_type target,
                        int level, enum pipe_format internal_format,
-                       struct pipe_texture *tex, boolean mipmap);
+                       struct pipe_resource *tex, boolean mipmap);
 
    /**
     * Used to implement glXCopyContext.
@@ -300,6 +390,12 @@ struct st_context_iface
    void (*copy)(struct st_context_iface *stctxi,
                 struct st_context_iface *stsrci, unsigned mask);
 
+   /**
+    * Used to implement wglShareLists.
+    */
+   boolean (*share)(struct st_context_iface *stctxi,
+                    struct st_context_iface *stsrci);
+
    /**
     * Look up and return the info of a resource for EGLImage.
     *
@@ -323,10 +419,27 @@ struct st_manager
    /**
     * Look up and return the info of an EGLImage.
     *
+    * This is used to implement for example EGLImageTargetTexture2DOES.
+    * The GLeglImageOES agrument of that call is passed directly to this
+    * function call and the information needed to access this is returned
+    * in the given struct out.
+    *
+    * @smapi: manager owning the caller context
+    * @stctx: caller context
+    * @egl_image: EGLImage that caller recived
+    * @out: return struct filled out with access information.
+    *
     * This function is optional.
     */
    boolean (*get_egl_image)(struct st_manager *smapi,
-                            struct st_egl_image *stimg);
+                            void *egl_image,
+                            struct st_egl_image *out);
+
+   /**
+    * Query an manager param.
+    */
+   int (*get_param)(struct st_manager *smapi,
+                    enum st_manager_param param);
 };
 
 /**
@@ -336,6 +449,26 @@ struct st_manager
  */
 struct st_api
 {
+   /**
+    * The name of the rendering API.  This is informative.
+    */
+   const char *name;
+
+   /**
+    * The supported rendering API.
+    */
+   enum st_api_type api;
+
+   /**
+    * The supported profiles.  Tested with ST_PROFILE_*_MASK.
+    */
+   unsigned profile_mask;
+
+   /**
+    * The supported optional features.  Tested with ST_FEATURE_*_MASK.
+    */
+   unsigned feature_mask;
+
    /**
     * Destroy the API.
     */
@@ -348,24 +481,20 @@ struct st_api
     */
    st_proc_t (*get_proc_address)(struct st_api *stapi, const char *procname);
 
-   /**
-    * Return true if the visual is supported by the state tracker.
-    */
-   boolean (*is_visual_supported)(struct st_api *stapi,
-                                  const struct st_visual *visual);
-
    /**
     * Create a rendering context.
     */
    struct st_context_iface *(*create_context)(struct st_api *stapi,
                                               struct st_manager *smapi,
-                                              const struct st_visual *visual,
+                                              const struct st_context_attribs *attribs,
+                                              enum st_context_error *error,
                                               struct st_context_iface *stsharei);
 
    /**
     * Bind the context to the calling thread with draw and read as drawables.
     *
-    * The framebuffers might have different visuals than the context does.
+    * The framebuffers might be NULL, or might have different visuals than the
+    * context does.
     */
    boolean (*make_current)(struct st_api *stapi,
                            struct st_context_iface *stctxi,
@@ -378,17 +507,6 @@ struct st_api
    struct st_context_iface *(*get_current)(struct st_api *stapi);
 };
 
-/**
- * Represent a state tracker.
- *
- * This is the entry point of a state tracker.
- */
-struct st_module
-{
-   enum st_api_type api;
-   struct st_api *(*create_api)(void);
-};
-
 /**
  * Return true if the visual has the specified buffers.
  */
@@ -398,10 +516,4 @@ st_visual_have_buffers(const struct st_visual *visual, unsigned mask)
    return ((visual->buffer_mask & mask) == mask);
 }
 
-/* these symbols may need to be dynamically lookup up */
-extern PUBLIC const struct st_module st_module_OpenGL;
-extern PUBLIC const struct st_module st_module_OpenGL_ES1;
-extern PUBLIC const struct st_module st_module_OpenGL_ES2;
-extern PUBLIC const struct st_module st_module_OpenVG;
-
 #endif /* _ST_API_H_ */