Tizen 2.1 base
[sdk/emulator/qemu.git] / gl / mesa / src / mesa / drivers / dri / intel / intel_fbo.h
1 /**************************************************************************
2  * 
3  * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 INTEL_FBO_H
29 #define INTEL_FBO_H
30
31 #include <stdbool.h>
32 #include <assert.h>
33 #include "main/formats.h"
34 #include "intel_context.h"
35 #include "intel_screen.h"
36
37 struct intel_context;
38 struct intel_mipmap_tree;
39 struct intel_texture_image;
40
41 /**
42  * Intel renderbuffer, derived from gl_renderbuffer.
43  */
44 struct intel_renderbuffer
45 {
46    struct swrast_renderbuffer Base;
47    struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
48    drm_intel_bo *map_bo;
49
50    /* Current texture image this renderbuffer is attached to. */
51    struct gl_texture_image *tex_image;
52
53    /**
54     * \name Miptree view
55     * \{
56     *
57     * Multiple renderbuffers may simultaneously wrap a single texture and each
58     * provide a different view into that texture. The fields below indicate
59     * which miptree slice is wrapped by this renderbuffer.  The fields' values
60     * are consistent with the 'level' and 'layer' parameters of
61     * glFramebufferTextureLayer().
62     *
63     * For renderbuffers not created with glFramebufferTexture*(), mt_level and
64     * mt_layer are 0.
65     */
66    unsigned int mt_level;
67    unsigned int mt_layer;
68    /** \} */
69
70    GLuint draw_x, draw_y; /**< Offset of drawing within the region */
71 };
72
73
74 /**
75  * gl_renderbuffer is a base class which we subclass.  The Class field
76  * is used for simple run-time type checking.
77  */
78 #define INTEL_RB_CLASS 0x12345678
79
80
81 /**
82  * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
83  * NULL will be returned if the rb isn't really an intel_renderbuffer.
84  * This is determined by checking the ClassID.
85  */
86 static INLINE struct intel_renderbuffer *
87 intel_renderbuffer(struct gl_renderbuffer *rb)
88 {
89    struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
90    if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS) {
91       /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
92       return irb;
93    }
94    else
95       return NULL;
96 }
97
98
99 /**
100  * \brief Return the framebuffer attachment specified by attIndex.
101  *
102  * If the framebuffer lacks the specified attachment, then return null.
103  *
104  * If the attached renderbuffer is a wrapper, then return wrapped
105  * renderbuffer.
106  */
107 static INLINE struct intel_renderbuffer *
108 intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
109 {
110    struct gl_renderbuffer *rb;
111
112    assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment));
113
114    rb = fb->Attachment[attIndex].Renderbuffer;
115    if (!rb)
116       return NULL;
117
118    return intel_renderbuffer(rb);
119 }
120
121
122 static INLINE gl_format
123 intel_rb_format(const struct intel_renderbuffer *rb)
124 {
125    return rb->Base.Base.Format;
126 }
127
128
129 bool
130 intel_framebuffer_has_hiz(struct gl_framebuffer *fb);
131
132 extern struct intel_renderbuffer *
133 intel_create_renderbuffer(gl_format format);
134
135 struct gl_renderbuffer*
136 intel_create_wrapped_renderbuffer(struct gl_context * ctx,
137                                   int width, int height,
138                                   gl_format format);
139
140 GLboolean
141 intel_alloc_renderbuffer_storage(struct gl_context * ctx,
142                                  struct gl_renderbuffer *rb,
143                                  GLenum internalFormat,
144                                  GLuint width, GLuint height);
145
146 extern void
147 intel_fbo_init(struct intel_context *intel);
148
149
150 extern void
151 intel_flip_renderbuffers(struct gl_framebuffer *fb);
152
153 void
154 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb);
155
156 uint32_t
157 intel_renderbuffer_tile_offsets(struct intel_renderbuffer *irb,
158                                 uint32_t *tile_x,
159                                 uint32_t *tile_y);
160
161 struct intel_region*
162 intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex);
163
164 void
165 intel_renderbuffer_set_needs_hiz_resolve(struct intel_renderbuffer *irb);
166
167 void
168 intel_renderbuffer_set_needs_depth_resolve(struct intel_renderbuffer *irb);
169
170
171 /**
172  * \brief Perform a HiZ resolve on the renderbuffer.
173  *
174  * It is safe to call this function on a renderbuffer without HiZ. In that
175  * case, the function is a no-op.
176  *
177  * \return false if no resolve was needed
178  */
179 bool
180 intel_renderbuffer_resolve_hiz(struct intel_context *intel,
181                                struct intel_renderbuffer *irb);
182
183 /**
184  * \brief Perform a depth resolve on the renderbuffer.
185  *
186  * It is safe to call this function on a renderbuffer without HiZ. In that
187  * case, the function is a no-op.
188  *
189  * \return false if no resolve was needed
190  */
191 bool
192 intel_renderbuffer_resolve_depth(struct intel_context *intel,
193                                  struct intel_renderbuffer *irb);
194
195 #endif /* INTEL_FBO_H */