17ec681f3Smrg/**********************************************************
27ec681f3Smrg * Copyright 2010 VMware, Inc.  All rights reserved.
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person
57ec681f3Smrg * obtaining a copy of this software and associated documentation
67ec681f3Smrg * files (the "Software"), to deal in the Software without
77ec681f3Smrg * restriction, including without limitation the rights to use, copy,
87ec681f3Smrg * modify, merge, publish, distribute, sublicense, and/or sell copies
97ec681f3Smrg * of the Software, and to permit persons to whom the Software is
107ec681f3Smrg * furnished to do so, subject to the following conditions:
117ec681f3Smrg *
127ec681f3Smrg * The above copyright notice and this permission notice shall be
137ec681f3Smrg * included in all copies or substantial portions of the Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
167ec681f3Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
177ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
187ec681f3Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
197ec681f3Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
207ec681f3Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
217ec681f3Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
227ec681f3Smrg * SOFTWARE.
237ec681f3Smrg *
247ec681f3Smrg **********************************************************/
257ec681f3Smrg
267ec681f3Smrg
277ec681f3Smrg#ifndef _API_H_
287ec681f3Smrg#define _API_H_
297ec681f3Smrg
307ec681f3Smrg#include "pipe/p_format.h"
317ec681f3Smrg
327ec681f3Smrg/**
337ec681f3Smrg * \file API for communication between gallium frontends and supporting
347ec681f3Smrg * frontends such as DRI.
357ec681f3Smrg *
367ec681f3Smrg * This file defines an API to be implemented by both gallium frontends and
377ec681f3Smrg * their managers.
387ec681f3Smrg */
397ec681f3Smrg
407ec681f3Smrg/**
417ec681f3Smrg * The supported rendering API.
427ec681f3Smrg */
437ec681f3Smrgenum st_api_type {
447ec681f3Smrg   ST_API_OPENGL,
457ec681f3Smrg   ST_API_OPENVG,
467ec681f3Smrg
477ec681f3Smrg   ST_API_COUNT
487ec681f3Smrg};
497ec681f3Smrg
507ec681f3Smrg/**
517ec681f3Smrg * The profile of a context.
527ec681f3Smrg */
537ec681f3Smrgenum st_profile_type
547ec681f3Smrg{
557ec681f3Smrg   ST_PROFILE_DEFAULT,			/**< OpenGL compatibility profile */
567ec681f3Smrg   ST_PROFILE_OPENGL_CORE,		/**< OpenGL 3.2+ core profile */
577ec681f3Smrg   ST_PROFILE_OPENGL_ES1,		/**< OpenGL ES 1.x */
587ec681f3Smrg   ST_PROFILE_OPENGL_ES2		/**< OpenGL ES 2.0 */
597ec681f3Smrg};
607ec681f3Smrg
617ec681f3Smrg/* for profile_mask in st_api */
627ec681f3Smrg#define ST_PROFILE_DEFAULT_MASK      (1 << ST_PROFILE_DEFAULT)
637ec681f3Smrg#define ST_PROFILE_OPENGL_CORE_MASK  (1 << ST_PROFILE_OPENGL_CORE)
647ec681f3Smrg#define ST_PROFILE_OPENGL_ES1_MASK   (1 << ST_PROFILE_OPENGL_ES1)
657ec681f3Smrg#define ST_PROFILE_OPENGL_ES2_MASK   (1 << ST_PROFILE_OPENGL_ES2)
667ec681f3Smrg
677ec681f3Smrg/**
687ec681f3Smrg * Optional API features.
697ec681f3Smrg */
707ec681f3Smrgenum st_api_feature
717ec681f3Smrg{
727ec681f3Smrg   ST_API_FEATURE_MS_VISUALS  /**< support for multisample visuals */
737ec681f3Smrg};
747ec681f3Smrg
757ec681f3Smrg/* for feature_mask in st_api */
767ec681f3Smrg#define ST_API_FEATURE_MS_VISUALS_MASK (1 << ST_API_FEATURE_MS_VISUALS)
777ec681f3Smrg
787ec681f3Smrg/**
797ec681f3Smrg * New context flags for GL 3.0 and beyond.
807ec681f3Smrg *
817ec681f3Smrg * Profile information (core vs. compatibilty for OpenGL 3.2+) is communicated
827ec681f3Smrg * through the \c st_profile_type, not through flags.
837ec681f3Smrg */
847ec681f3Smrg#define ST_CONTEXT_FLAG_DEBUG               (1 << 0)
857ec681f3Smrg#define ST_CONTEXT_FLAG_FORWARD_COMPATIBLE  (1 << 1)
867ec681f3Smrg#define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 2)
877ec681f3Smrg#define ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED (1 << 3)
887ec681f3Smrg#define ST_CONTEXT_FLAG_NO_ERROR            (1 << 4)
897ec681f3Smrg#define ST_CONTEXT_FLAG_RELEASE_NONE	    (1 << 5)
907ec681f3Smrg#define ST_CONTEXT_FLAG_HIGH_PRIORITY       (1 << 6)
917ec681f3Smrg#define ST_CONTEXT_FLAG_LOW_PRIORITY        (1 << 7)
927ec681f3Smrg
937ec681f3Smrg/**
947ec681f3Smrg * Reasons that context creation might fail.
957ec681f3Smrg */
967ec681f3Smrgenum st_context_error {
977ec681f3Smrg   ST_CONTEXT_SUCCESS = 0,
987ec681f3Smrg   ST_CONTEXT_ERROR_NO_MEMORY,
997ec681f3Smrg   ST_CONTEXT_ERROR_BAD_API,
1007ec681f3Smrg   ST_CONTEXT_ERROR_BAD_VERSION,
1017ec681f3Smrg   ST_CONTEXT_ERROR_BAD_FLAG,
1027ec681f3Smrg   ST_CONTEXT_ERROR_UNKNOWN_ATTRIBUTE,
1037ec681f3Smrg   ST_CONTEXT_ERROR_UNKNOWN_FLAG
1047ec681f3Smrg};
1057ec681f3Smrg
1067ec681f3Smrg/**
1077ec681f3Smrg * Used in st_context_iface->teximage.
1087ec681f3Smrg */
1097ec681f3Smrgenum st_texture_type {
1107ec681f3Smrg   ST_TEXTURE_1D,
1117ec681f3Smrg   ST_TEXTURE_2D,
1127ec681f3Smrg   ST_TEXTURE_3D,
1137ec681f3Smrg   ST_TEXTURE_RECT
1147ec681f3Smrg};
1157ec681f3Smrg
1167ec681f3Smrg/**
1177ec681f3Smrg * Available attachments of framebuffer.
1187ec681f3Smrg */
1197ec681f3Smrgenum st_attachment_type {
1207ec681f3Smrg   ST_ATTACHMENT_FRONT_LEFT,
1217ec681f3Smrg   ST_ATTACHMENT_BACK_LEFT,
1227ec681f3Smrg   ST_ATTACHMENT_FRONT_RIGHT,
1237ec681f3Smrg   ST_ATTACHMENT_BACK_RIGHT,
1247ec681f3Smrg   ST_ATTACHMENT_DEPTH_STENCIL,
1257ec681f3Smrg   ST_ATTACHMENT_ACCUM,
1267ec681f3Smrg
1277ec681f3Smrg   ST_ATTACHMENT_COUNT,
1287ec681f3Smrg   ST_ATTACHMENT_INVALID = -1
1297ec681f3Smrg};
1307ec681f3Smrg
1317ec681f3Smrg/* for buffer_mask in st_visual */
1327ec681f3Smrg#define ST_ATTACHMENT_FRONT_LEFT_MASK     (1 << ST_ATTACHMENT_FRONT_LEFT)
1337ec681f3Smrg#define ST_ATTACHMENT_BACK_LEFT_MASK      (1 << ST_ATTACHMENT_BACK_LEFT)
1347ec681f3Smrg#define ST_ATTACHMENT_FRONT_RIGHT_MASK    (1 << ST_ATTACHMENT_FRONT_RIGHT)
1357ec681f3Smrg#define ST_ATTACHMENT_BACK_RIGHT_MASK     (1 << ST_ATTACHMENT_BACK_RIGHT)
1367ec681f3Smrg#define ST_ATTACHMENT_DEPTH_STENCIL_MASK  (1 << ST_ATTACHMENT_DEPTH_STENCIL)
1377ec681f3Smrg#define ST_ATTACHMENT_ACCUM_MASK          (1 << ST_ATTACHMENT_ACCUM)
1387ec681f3Smrg
1397ec681f3Smrg/**
1407ec681f3Smrg * Flush flags.
1417ec681f3Smrg */
1427ec681f3Smrg#define ST_FLUSH_FRONT                    (1 << 0)
1437ec681f3Smrg#define ST_FLUSH_END_OF_FRAME             (1 << 1)
1447ec681f3Smrg#define ST_FLUSH_WAIT                     (1 << 2)
1457ec681f3Smrg#define ST_FLUSH_FENCE_FD                 (1 << 3)
1467ec681f3Smrg
1477ec681f3Smrg/**
1487ec681f3Smrg * State invalidation flags to notify frontends that states have been changed
1497ec681f3Smrg * behind their back.
1507ec681f3Smrg */
1517ec681f3Smrg#define ST_INVALIDATE_FS_SAMPLER_VIEWS    (1 << 0)
1527ec681f3Smrg#define ST_INVALIDATE_FS_CONSTBUF0        (1 << 1)
1537ec681f3Smrg#define ST_INVALIDATE_VS_CONSTBUF0        (1 << 2)
1547ec681f3Smrg#define ST_INVALIDATE_VERTEX_BUFFERS      (1 << 3)
1557ec681f3Smrg
1567ec681f3Smrg/**
1577ec681f3Smrg * Value to st_manager->get_param function.
1587ec681f3Smrg */
1597ec681f3Smrgenum st_manager_param {
1607ec681f3Smrg   /**
1617ec681f3Smrg    * The DRI frontend on old libGL's doesn't do the right thing
1627ec681f3Smrg    * with regards to invalidating the framebuffers.
1637ec681f3Smrg    *
1647ec681f3Smrg    * For the GL gallium frontend that means that it needs to invalidate
1657ec681f3Smrg    * the framebuffer in glViewport itself.
1667ec681f3Smrg    */
1677ec681f3Smrg   ST_MANAGER_BROKEN_INVALIDATE
1687ec681f3Smrg};
1697ec681f3Smrg
1707ec681f3Smrgstruct pipe_context;
1717ec681f3Smrgstruct pipe_resource;
1727ec681f3Smrgstruct pipe_fence_handle;
1737ec681f3Smrgstruct util_queue_monitoring;
1747ec681f3Smrg
1757ec681f3Smrg/**
1767ec681f3Smrg * Used in st_manager_iface->get_egl_image.
1777ec681f3Smrg */
1787ec681f3Smrgstruct st_egl_image
1797ec681f3Smrg{
1807ec681f3Smrg   /* this is owned by the caller */
1817ec681f3Smrg   struct pipe_resource *texture;
1827ec681f3Smrg
1837ec681f3Smrg   /* format only differs from texture->format for multi-planar (YUV): */
1847ec681f3Smrg   enum pipe_format format;
1857ec681f3Smrg
1867ec681f3Smrg   unsigned level;
1877ec681f3Smrg   unsigned layer;
1887ec681f3Smrg   /* GL internal format. */
1897ec681f3Smrg   unsigned internalformat;
1907ec681f3Smrg};
1917ec681f3Smrg
1927ec681f3Smrg/**
1937ec681f3Smrg * Represent the visual of a framebuffer.
1947ec681f3Smrg */
1957ec681f3Smrgstruct st_visual
1967ec681f3Smrg{
1977ec681f3Smrg   /**
1987ec681f3Smrg    * Available buffers.  Bitfield of ST_ATTACHMENT_*_MASK bits.
1997ec681f3Smrg    */
2007ec681f3Smrg   unsigned buffer_mask;
2017ec681f3Smrg
2027ec681f3Smrg   /**
2037ec681f3Smrg    * Buffer formats.  The formats are always set even when the buffer is
2047ec681f3Smrg    * not available.
2057ec681f3Smrg    */
2067ec681f3Smrg   enum pipe_format color_format;
2077ec681f3Smrg   enum pipe_format depth_stencil_format;
2087ec681f3Smrg   enum pipe_format accum_format;
2097ec681f3Smrg   unsigned samples;
2107ec681f3Smrg};
2117ec681f3Smrg
2127ec681f3Smrg
2137ec681f3Smrg/**
2147ec681f3Smrg * Configuration options from driconf
2157ec681f3Smrg */
2167ec681f3Smrgstruct st_config_options
2177ec681f3Smrg{
2187ec681f3Smrg   bool disable_blend_func_extended;
2197ec681f3Smrg   bool disable_glsl_line_continuations;
2207ec681f3Smrg   bool disable_arb_gpu_shader5;
2217ec681f3Smrg   bool force_glsl_extensions_warn;
2227ec681f3Smrg   unsigned force_glsl_version;
2237ec681f3Smrg   bool allow_extra_pp_tokens;
2247ec681f3Smrg   bool allow_glsl_extension_directive_midshader;
2257ec681f3Smrg   bool allow_glsl_120_subset_in_110;
2267ec681f3Smrg   bool allow_glsl_builtin_const_expression;
2277ec681f3Smrg   bool allow_glsl_relaxed_es;
2287ec681f3Smrg   bool allow_glsl_builtin_variable_redeclaration;
2297ec681f3Smrg   bool allow_higher_compat_version;
2307ec681f3Smrg   bool glsl_ignore_write_to_readonly_var;
2317ec681f3Smrg   bool glsl_zero_init;
2327ec681f3Smrg   bool vs_position_always_invariant;
2337ec681f3Smrg   bool vs_position_always_precise;
2347ec681f3Smrg   bool force_glsl_abs_sqrt;
2357ec681f3Smrg   bool allow_glsl_cross_stage_interpolation_mismatch;
2367ec681f3Smrg   bool allow_draw_out_of_order;
2377ec681f3Smrg   bool ignore_map_unsynchronized;
2387ec681f3Smrg   bool force_integer_tex_nearest;
2397ec681f3Smrg   bool force_gl_names_reuse;
2407ec681f3Smrg   bool transcode_etc;
2417ec681f3Smrg   bool transcode_astc;
2427ec681f3Smrg   char *force_gl_vendor;
2437ec681f3Smrg   char *force_gl_renderer;
2447ec681f3Smrg   unsigned char config_options_sha1[20];
2457ec681f3Smrg};
2467ec681f3Smrg
2477ec681f3Smrg/**
2487ec681f3Smrg * Represent the attributes of a context.
2497ec681f3Smrg */
2507ec681f3Smrgstruct st_context_attribs
2517ec681f3Smrg{
2527ec681f3Smrg   /**
2537ec681f3Smrg    * The profile and minimal version to support.
2547ec681f3Smrg    *
2557ec681f3Smrg    * The valid profiles and versions are rendering API dependent.  The latest
2567ec681f3Smrg    * version satisfying the request should be returned.
2577ec681f3Smrg    */
2587ec681f3Smrg   enum st_profile_type profile;
2597ec681f3Smrg   int major, minor;
2607ec681f3Smrg
2617ec681f3Smrg   /** Mask of ST_CONTEXT_FLAG_x bits */
2627ec681f3Smrg   unsigned flags;
2637ec681f3Smrg
2647ec681f3Smrg   /**
2657ec681f3Smrg    * The visual of the framebuffers the context will be bound to.
2667ec681f3Smrg    */
2677ec681f3Smrg   struct st_visual visual;
2687ec681f3Smrg
2697ec681f3Smrg   /**
2707ec681f3Smrg    * Configuration options.
2717ec681f3Smrg    */
2727ec681f3Smrg   struct st_config_options options;
2737ec681f3Smrg};
2747ec681f3Smrg
2757ec681f3Smrgstruct st_context_iface;
2767ec681f3Smrgstruct st_manager;
2777ec681f3Smrg
2787ec681f3Smrg/**
2797ec681f3Smrg * Represent a windowing system drawable.
2807ec681f3Smrg *
2817ec681f3Smrg * The framebuffer is implemented by the frontend manager and
2827ec681f3Smrg * used by gallium frontends.
2837ec681f3Smrg *
2847ec681f3Smrg * Instead of the winsys poking into the frontend context to figure
2857ec681f3Smrg * out what buffers that might be needed in the future by the frontend
2867ec681f3Smrg * context, it calls into the framebuffer to get the textures.
2877ec681f3Smrg *
2887ec681f3Smrg * This structure along with the notify_invalid_framebuffer
2897ec681f3Smrg * allows framebuffers to be shared between different threads
2907ec681f3Smrg * but at the same make the API context free from thread
2917ec681f3Smrg * synchronization primitves, with the exception of a small
2927ec681f3Smrg * atomic flag used for notification of framebuffer dirty status.
2937ec681f3Smrg *
2947ec681f3Smrg * The thread synchronization is put inside the framebuffer
2957ec681f3Smrg * and only called once the framebuffer has become dirty.
2967ec681f3Smrg */
2977ec681f3Smrgstruct st_framebuffer_iface
2987ec681f3Smrg{
2997ec681f3Smrg   /**
3007ec681f3Smrg    * Atomic stamp which changes when framebuffers need to be updated.
3017ec681f3Smrg    */
3027ec681f3Smrg   int32_t stamp;
3037ec681f3Smrg
3047ec681f3Smrg   /**
3057ec681f3Smrg    * Identifier that uniquely identifies the framebuffer interface object.
3067ec681f3Smrg    */
3077ec681f3Smrg   uint32_t ID;
3087ec681f3Smrg
3097ec681f3Smrg   /**
3107ec681f3Smrg    * The frontend manager that manages this object.
3117ec681f3Smrg    */
3127ec681f3Smrg   struct st_manager *state_manager;
3137ec681f3Smrg
3147ec681f3Smrg   /**
3157ec681f3Smrg    * Available for the frontend manager to use.
3167ec681f3Smrg    */
3177ec681f3Smrg   void *st_manager_private;
3187ec681f3Smrg
3197ec681f3Smrg   /**
3207ec681f3Smrg    * The visual of a framebuffer.
3217ec681f3Smrg    */
3227ec681f3Smrg   const struct st_visual *visual;
3237ec681f3Smrg
3247ec681f3Smrg   /**
3257ec681f3Smrg    * Flush the front buffer.
3267ec681f3Smrg    *
3277ec681f3Smrg    * On some window systems, changes to the front buffers are not immediately
3287ec681f3Smrg    * visible.  They need to be flushed.
3297ec681f3Smrg    *
3307ec681f3Smrg    * @att is one of the front buffer attachments.
3317ec681f3Smrg    */
3327ec681f3Smrg   bool (*flush_front)(struct st_context_iface *stctx,
3337ec681f3Smrg                       struct st_framebuffer_iface *stfbi,
3347ec681f3Smrg                       enum st_attachment_type statt);
3357ec681f3Smrg
3367ec681f3Smrg   /**
3377ec681f3Smrg    * the gallium frontend asks for the textures it needs.
3387ec681f3Smrg    *
3397ec681f3Smrg    * It should try to only ask for attachments that it currently renders
3407ec681f3Smrg    * to, thus allowing the winsys to delay the allocation of textures not
3417ec681f3Smrg    * needed. For example front buffer attachments are not needed if you
3427ec681f3Smrg    * only do back buffer rendering.
3437ec681f3Smrg    *
3447ec681f3Smrg    * The implementor of this function needs to also ensure
3457ec681f3Smrg    * thread safty as this call might be done from multiple threads.
3467ec681f3Smrg    *
3477ec681f3Smrg    * The returned textures are owned by the caller.  They should be
3487ec681f3Smrg    * unreferenced when no longer used.  If this function is called multiple
3497ec681f3Smrg    * times with different sets of attachments, those buffers not included in
3507ec681f3Smrg    * the last call might be destroyed.  This behavior might change in the
3517ec681f3Smrg    * future.
3527ec681f3Smrg    */
3537ec681f3Smrg   bool (*validate)(struct st_context_iface *stctx,
3547ec681f3Smrg                    struct st_framebuffer_iface *stfbi,
3557ec681f3Smrg                    const enum st_attachment_type *statts,
3567ec681f3Smrg                    unsigned count,
3577ec681f3Smrg                    struct pipe_resource **out);
3587ec681f3Smrg   bool (*flush_swapbuffers) (struct st_context_iface *stctx,
3597ec681f3Smrg                              struct st_framebuffer_iface *stfbi);
3607ec681f3Smrg};
3617ec681f3Smrg
3627ec681f3Smrg/**
3637ec681f3Smrg * Represent a rendering context.
3647ec681f3Smrg *
3657ec681f3Smrg * This entity is created from st_api and used by the frontend manager.
3667ec681f3Smrg */
3677ec681f3Smrgstruct st_context_iface
3687ec681f3Smrg{
3697ec681f3Smrg   /**
3707ec681f3Smrg    * Available for the gallium frontend and the manager to use.
3717ec681f3Smrg    */
3727ec681f3Smrg   void *st_context_private;
3737ec681f3Smrg   void *st_manager_private;
3747ec681f3Smrg
3757ec681f3Smrg   /**
3767ec681f3Smrg    * The frontend manager that manages this object.
3777ec681f3Smrg    */
3787ec681f3Smrg   struct st_manager *state_manager;
3797ec681f3Smrg
3807ec681f3Smrg   /**
3817ec681f3Smrg    * The CSO context associated with this context in case we need to draw
3827ec681f3Smrg    * something before swap buffers.
3837ec681f3Smrg    */
3847ec681f3Smrg   struct cso_context *cso_context;
3857ec681f3Smrg
3867ec681f3Smrg   /**
3877ec681f3Smrg    * The gallium context.
3887ec681f3Smrg    */
3897ec681f3Smrg   struct pipe_context *pipe;
3907ec681f3Smrg
3917ec681f3Smrg   /**
3927ec681f3Smrg    * Destroy the context.
3937ec681f3Smrg    */
3947ec681f3Smrg   void (*destroy)(struct st_context_iface *stctxi);
3957ec681f3Smrg
3967ec681f3Smrg   /**
3977ec681f3Smrg    * Flush all drawing from context to the pipe also flushes the pipe.
3987ec681f3Smrg    */
3997ec681f3Smrg   void (*flush)(struct st_context_iface *stctxi, unsigned flags,
4007ec681f3Smrg                 struct pipe_fence_handle **fence,
4017ec681f3Smrg                 void (*notify_before_flush_cb) (void*),
4027ec681f3Smrg                 void* notify_before_flush_cb_args);
4037ec681f3Smrg
4047ec681f3Smrg   /**
4057ec681f3Smrg    * Replace the texture image of a texture object at the specified level.
4067ec681f3Smrg    *
4077ec681f3Smrg    * This function is optional.
4087ec681f3Smrg    */
4097ec681f3Smrg   bool (*teximage)(struct st_context_iface *stctxi,
4107ec681f3Smrg                    enum st_texture_type target,
4117ec681f3Smrg                    int level, enum pipe_format internal_format,
4127ec681f3Smrg                    struct pipe_resource *tex, bool mipmap);
4137ec681f3Smrg
4147ec681f3Smrg   /**
4157ec681f3Smrg    * Used to implement glXCopyContext.
4167ec681f3Smrg    */
4177ec681f3Smrg   void (*copy)(struct st_context_iface *stctxi,
4187ec681f3Smrg                struct st_context_iface *stsrci, unsigned mask);
4197ec681f3Smrg
4207ec681f3Smrg   /**
4217ec681f3Smrg    * Used to implement wglShareLists.
4227ec681f3Smrg    */
4237ec681f3Smrg   bool (*share)(struct st_context_iface *stctxi,
4247ec681f3Smrg                 struct st_context_iface *stsrci);
4257ec681f3Smrg
4267ec681f3Smrg   /**
4277ec681f3Smrg    * Start the thread if the API has a worker thread.
4287ec681f3Smrg    * Called after the context has been created and fully initialized on both
4297ec681f3Smrg    * sides (e.g. st/mesa and st/dri).
4307ec681f3Smrg    */
4317ec681f3Smrg   void (*start_thread)(struct st_context_iface *stctxi);
4327ec681f3Smrg
4337ec681f3Smrg   /**
4347ec681f3Smrg    * If the API is multithreaded, wait for all queued commands to complete.
4357ec681f3Smrg    * Called from the main thread.
4367ec681f3Smrg    */
4377ec681f3Smrg   void (*thread_finish)(struct st_context_iface *stctxi);
4387ec681f3Smrg
4397ec681f3Smrg   /**
4407ec681f3Smrg    * Invalidate states to notify the frontend that states have been changed
4417ec681f3Smrg    * behind its back.
4427ec681f3Smrg    */
4437ec681f3Smrg   void (*invalidate_state)(struct st_context_iface *stctxi, unsigned flags);
4447ec681f3Smrg};
4457ec681f3Smrg
4467ec681f3Smrg
4477ec681f3Smrg/**
4487ec681f3Smrg * Represent a frontend manager.
4497ec681f3Smrg *
4507ec681f3Smrg * This interface is implemented by the frontend manager.  It corresponds
4517ec681f3Smrg * to a "display" in the window system.
4527ec681f3Smrg */
4537ec681f3Smrgstruct st_manager
4547ec681f3Smrg{
4557ec681f3Smrg   struct pipe_screen *screen;
4567ec681f3Smrg
4577ec681f3Smrg   /**
4587ec681f3Smrg    * Look up and return the info of an EGLImage.
4597ec681f3Smrg    *
4607ec681f3Smrg    * This is used to implement for example EGLImageTargetTexture2DOES.
4617ec681f3Smrg    * The GLeglImageOES agrument of that call is passed directly to this
4627ec681f3Smrg    * function call and the information needed to access this is returned
4637ec681f3Smrg    * in the given struct out.
4647ec681f3Smrg    *
4657ec681f3Smrg    * @smapi: manager owning the caller context
4667ec681f3Smrg    * @stctx: caller context
4677ec681f3Smrg    * @egl_image: EGLImage that caller recived
4687ec681f3Smrg    * @out: return struct filled out with access information.
4697ec681f3Smrg    *
4707ec681f3Smrg    * This function is optional.
4717ec681f3Smrg    */
4727ec681f3Smrg   bool (*get_egl_image)(struct st_manager *smapi,
4737ec681f3Smrg                         void *egl_image,
4747ec681f3Smrg                         struct st_egl_image *out);
4757ec681f3Smrg
4767ec681f3Smrg   /**
4777ec681f3Smrg    * Validate EGLImage passed to get_egl_image.
4787ec681f3Smrg    */
4797ec681f3Smrg   bool (*validate_egl_image)(struct st_manager *smapi,
4807ec681f3Smrg                              void *egl_image);
4817ec681f3Smrg
4827ec681f3Smrg   /**
4837ec681f3Smrg    * Query an manager param.
4847ec681f3Smrg    */
4857ec681f3Smrg   int (*get_param)(struct st_manager *smapi,
4867ec681f3Smrg                    enum st_manager_param param);
4877ec681f3Smrg
4887ec681f3Smrg   /**
4897ec681f3Smrg    * Call the loader function setBackgroundContext. Called from the worker
4907ec681f3Smrg    * thread.
4917ec681f3Smrg    */
4927ec681f3Smrg   void (*set_background_context)(struct st_context_iface *stctxi,
4937ec681f3Smrg                                  struct util_queue_monitoring *queue_info);
4947ec681f3Smrg
4957ec681f3Smrg   /**
4967ec681f3Smrg    * Destroy any private data used by the frontend manager.
4977ec681f3Smrg    */
4987ec681f3Smrg   void (*destroy)(struct st_manager *smapi);
4997ec681f3Smrg
5007ec681f3Smrg   /**
5017ec681f3Smrg    * Available for the frontend manager to use.
5027ec681f3Smrg    */
5037ec681f3Smrg   void *st_manager_private;
5047ec681f3Smrg};
5057ec681f3Smrg
5067ec681f3Smrg/**
5077ec681f3Smrg * Represent a rendering API such as OpenGL or OpenVG.
5087ec681f3Smrg *
5097ec681f3Smrg * Implemented by the gallium frontend and used by the frontend manager.
5107ec681f3Smrg */
5117ec681f3Smrgstruct st_api
5127ec681f3Smrg{
5137ec681f3Smrg   /**
5147ec681f3Smrg    * The name of the rendering API.  This is informative.
5157ec681f3Smrg    */
5167ec681f3Smrg   const char *name;
5177ec681f3Smrg
5187ec681f3Smrg   /**
5197ec681f3Smrg    * The supported rendering API.
5207ec681f3Smrg    */
5217ec681f3Smrg   enum st_api_type api;
5227ec681f3Smrg
5237ec681f3Smrg   /**
5247ec681f3Smrg    * The supported profiles.  Tested with ST_PROFILE_*_MASK.
5257ec681f3Smrg    */
5267ec681f3Smrg   unsigned profile_mask;
5277ec681f3Smrg
5287ec681f3Smrg   /**
5297ec681f3Smrg    * The supported optional features.  Tested with ST_FEATURE_*_MASK.
5307ec681f3Smrg    */
5317ec681f3Smrg   unsigned feature_mask;
5327ec681f3Smrg
5337ec681f3Smrg   /**
5347ec681f3Smrg    * Destroy the API.
5357ec681f3Smrg    */
5367ec681f3Smrg   void (*destroy)(struct st_api *stapi);
5377ec681f3Smrg
5387ec681f3Smrg   /**
5397ec681f3Smrg    * Query supported OpenGL versions. (if applicable)
5407ec681f3Smrg    * The format is (major*10+minor).
5417ec681f3Smrg    */
5427ec681f3Smrg   void (*query_versions)(struct st_api *stapi, struct st_manager *sm,
5437ec681f3Smrg                          struct st_config_options *options,
5447ec681f3Smrg                          int *gl_core_version,
5457ec681f3Smrg                          int *gl_compat_version,
5467ec681f3Smrg                          int *gl_es1_version,
5477ec681f3Smrg                          int *gl_es2_version);
5487ec681f3Smrg
5497ec681f3Smrg   /**
5507ec681f3Smrg    * Create a rendering context.
5517ec681f3Smrg    */
5527ec681f3Smrg   struct st_context_iface *(*create_context)(struct st_api *stapi,
5537ec681f3Smrg                                              struct st_manager *smapi,
5547ec681f3Smrg                                              const struct st_context_attribs *attribs,
5557ec681f3Smrg                                              enum st_context_error *error,
5567ec681f3Smrg                                              struct st_context_iface *stsharei);
5577ec681f3Smrg
5587ec681f3Smrg   /**
5597ec681f3Smrg    * Bind the context to the calling thread with draw and read as drawables.
5607ec681f3Smrg    *
5617ec681f3Smrg    * The framebuffers might be NULL, or might have different visuals than the
5627ec681f3Smrg    * context does.
5637ec681f3Smrg    */
5647ec681f3Smrg   bool (*make_current)(struct st_api *stapi,
5657ec681f3Smrg                        struct st_context_iface *stctxi,
5667ec681f3Smrg                        struct st_framebuffer_iface *stdrawi,
5677ec681f3Smrg                        struct st_framebuffer_iface *streadi);
5687ec681f3Smrg
5697ec681f3Smrg   /**
5707ec681f3Smrg    * Get the currently bound context in the calling thread.
5717ec681f3Smrg    */
5727ec681f3Smrg   struct st_context_iface *(*get_current)(struct st_api *stapi);
5737ec681f3Smrg
5747ec681f3Smrg   /**
5757ec681f3Smrg    * Notify the st manager the framebuffer interface object
5767ec681f3Smrg    * is no longer valid.
5777ec681f3Smrg    */
5787ec681f3Smrg   void (*destroy_drawable)(struct st_api *stapi,
5797ec681f3Smrg                            struct st_framebuffer_iface *stfbi);
5807ec681f3Smrg};
5817ec681f3Smrg
5827ec681f3Smrg/**
5837ec681f3Smrg * Return true if the visual has the specified buffers.
5847ec681f3Smrg */
5857ec681f3Smrgstatic inline bool
5867ec681f3Smrgst_visual_have_buffers(const struct st_visual *visual, unsigned mask)
5877ec681f3Smrg{
5887ec681f3Smrg   return ((visual->buffer_mask & mask) == mask);
5897ec681f3Smrg}
5907ec681f3Smrg
5917ec681f3Smrg#endif /* _API_H_ */
592