xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/dri/dri_drawable.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2009, VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #ifndef DRI_DRAWABLE_H
29 #define DRI_DRAWABLE_H
30 
31 #include "util/compiler.h"
32 #include "util/format/u_formats.h"
33 #include "frontend/api.h"
34 #include "dri_util.h"
35 
36 struct dri_context;
37 struct dri_screen;
38 
39 struct dri_drawable
40 {
41    struct pipe_frontend_drawable base;
42    struct st_visual stvis;
43 
44    struct dri_screen *screen;
45 
46    __DRIbuffer old[__DRI_BUFFER_COUNT];
47    unsigned old_num;
48    unsigned old_w;
49    unsigned old_h;
50 
51    struct pipe_box *damage_rects;
52    unsigned int num_damage_rects;
53 
54    struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
55    struct pipe_resource *msaa_textures[ST_ATTACHMENT_COUNT];
56    unsigned int texture_mask, texture_stamp;
57    int swap_interval;
58 
59    struct pipe_fence_handle *throttle_fence;
60    bool flushing; /* prevents recursion in dri_flush */
61 
62    /**
63     * Private data from the loader.  We just hold on to it and pass
64     * it back when calling into loader provided functions.
65     */
66    void *loaderPrivate;
67 
68    /**
69     * Reference count for number of context's currently bound to this
70     * drawable.
71     *
72     * Once it reaches zero, the drawable can be destroyed.
73     *
74     * \note This behavior will change with GLX 1.3.
75     */
76    int refcount;
77 
78    /**
79     * Increased when the loader calls invalidate.
80     *
81     * If this changes, the drawable information (below) should be retrieved
82     * from the loader.
83     */
84    unsigned int lastStamp;
85    int w, h;
86 
87    /* generic for swrast */
88    unsigned buffer_age;
89 
90    /* kopper */
91    struct kopper_loader_info info;
92    __DRIimage   *image; //texture_from_pixmap
93    bool is_window;
94    bool window_valid;
95 
96    /* hooks filled in by dri2 & drisw */
97    void (*allocate_textures)(struct dri_context *ctx,
98                              struct dri_drawable *drawable,
99                              const enum st_attachment_type *statts,
100                              unsigned count);
101 
102    void (*update_drawable_info)(struct dri_drawable *drawable);
103 
104    bool (*flush_frontbuffer)(struct dri_context *ctx,
105                              struct dri_drawable *drawable,
106                              enum st_attachment_type statt);
107 
108    void (*update_tex_buffer)(struct dri_drawable *drawable,
109                              struct dri_context *ctx,
110                              struct pipe_resource *res);
111    void (*flush_swapbuffers)(struct dri_context *ctx,
112                              struct dri_drawable *drawable);
113 
114    void (*swap_buffers)(struct dri_drawable *drawable);
115    void (*swap_buffers_with_damage)(struct dri_drawable *drawable, int nrects, const int *rects);
116 };
117 
118 /* Typecast the opaque pointer to our own type. */
119 static inline struct dri_drawable *
dri_drawable(__DRIdrawable * drawable)120 dri_drawable(__DRIdrawable *drawable)
121 {
122    return (struct dri_drawable *)drawable;
123 }
124 
125 /* Typecast our own type to the opaque pointer. */
126 static inline __DRIdrawable *
opaque_dri_drawable(struct dri_drawable * drawable)127 opaque_dri_drawable(struct dri_drawable *drawable)
128 {
129    return (__DRIdrawable *)drawable;
130 }
131 
132 static inline void
dri_get_drawable(struct dri_drawable * drawable)133 dri_get_drawable(struct dri_drawable *drawable)
134 {
135     drawable->refcount++;
136 }
137 
138 /***********************************************************************
139  * dri_drawable.c
140  */
141 void
142 dri_put_drawable(struct dri_drawable *drawable);
143 
144 void
145 dri_drawable_get_format(struct dri_drawable *drawable,
146                         enum st_attachment_type statt,
147                         enum pipe_format *format,
148                         unsigned *bind);
149 
150 void
151 dri_pipe_blit(struct pipe_context *pipe,
152               struct pipe_resource *dst,
153               struct pipe_resource *src);
154 
155 void
156 dri_flush(__DRIcontext *cPriv,
157           __DRIdrawable *dPriv,
158           unsigned flags,
159           enum __DRI2throttleReason reason);
160 
161 void
162 dri_flush_drawable(__DRIdrawable *dPriv);
163 
164 extern const __DRItexBufferExtension driTexBufferExtension;
165 
166 void
167 drisw_update_tex_buffer(struct dri_drawable *drawable,
168                         struct dri_context *ctx,
169                         struct pipe_resource *res);
170 
171 void
172 kopper_init_drawable(struct dri_drawable *drawable, bool isPixmap, int alphaBits);
173 void
174 drisw_init_drawable(struct dri_drawable *drawable, bool isPixmap, int alphaBits);
175 void
176 dri2_init_drawable(struct dri_drawable *drawable, bool isPixmap, int alphaBits);
177 #endif
178 
179 /* vim: set sw=3 ts=8 sts=3 expandtab: */
180