Merge branch 'gallium-polygon-stipple'
[mesa.git] / src / mesa / drivers / dri / intel / intel_buffers.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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 #include "intel_context.h"
29 #include "intel_buffers.h"
30 #include "intel_fbo.h"
31
32 #include "main/framebuffer.h"
33 #include "main/renderbuffer.h"
34
35 /**
36 * Return pointer to current color drawing region, or NULL.
37 */
38 struct intel_region *
39 intel_drawbuf_region(struct intel_context *intel)
40 {
41 struct intel_renderbuffer *irbColor =
42 intel_renderbuffer(intel->ctx.DrawBuffer->_ColorDrawBuffers[0]);
43 if (irbColor)
44 return irbColor->region;
45 else
46 return NULL;
47 }
48
49 /**
50 * Return pointer to current color reading region, or NULL.
51 */
52 struct intel_region *
53 intel_readbuf_region(struct intel_context *intel)
54 {
55 struct intel_renderbuffer *irb
56 = intel_renderbuffer(intel->ctx.ReadBuffer->_ColorReadBuffer);
57 if (irb)
58 return irb->region;
59 else
60 return NULL;
61 }
62
63 /**
64 * Check if we're about to draw into the front color buffer.
65 * If so, set the intel->front_buffer_dirty field to true.
66 */
67 void
68 intel_check_front_buffer_rendering(struct intel_context *intel)
69 {
70 const struct gl_framebuffer *fb = intel->ctx.DrawBuffer;
71 if (fb->Name == 0) {
72 /* drawing to window system buffer */
73 if (fb->_NumColorDrawBuffers > 0) {
74 if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
75 intel->front_buffer_dirty = GL_TRUE;
76 }
77 }
78 }
79 }
80
81 static void
82 intelDrawBuffer(struct gl_context * ctx, GLenum mode)
83 {
84 if ((ctx->DrawBuffer != NULL) && (ctx->DrawBuffer->Name == 0)) {
85 struct intel_context *const intel = intel_context(ctx);
86 const GLboolean was_front_buffer_rendering =
87 intel->is_front_buffer_rendering;
88
89 intel->is_front_buffer_rendering = (mode == GL_FRONT_LEFT)
90 || (mode == GL_FRONT);
91
92 /* If we weren't front-buffer rendering before but we are now,
93 * invalidate our DRI drawable so we'll ask for new buffers
94 * (including the fake front) before we start rendering again.
95 */
96 if (!was_front_buffer_rendering && intel->is_front_buffer_rendering)
97 dri2InvalidateDrawable(intel->driContext->driDrawablePriv);
98 }
99
100 intel_draw_buffer(ctx, ctx->DrawBuffer);
101 }
102
103
104 static void
105 intelReadBuffer(struct gl_context * ctx, GLenum mode)
106 {
107 if ((ctx->DrawBuffer != NULL) && (ctx->DrawBuffer->Name == 0)) {
108 struct intel_context *const intel = intel_context(ctx);
109 const GLboolean was_front_buffer_reading =
110 intel->is_front_buffer_reading;
111
112 intel->is_front_buffer_reading = (mode == GL_FRONT_LEFT)
113 || (mode == GL_FRONT);
114
115 /* If we weren't front-buffer reading before but we are now,
116 * invalidate our DRI drawable so we'll ask for new buffers
117 * (including the fake front) before we start reading again.
118 */
119 if (!was_front_buffer_reading && intel->is_front_buffer_reading)
120 dri2InvalidateDrawable(intel->driContext->driReadablePriv);
121 }
122 }
123
124
125 void
126 intelInitBufferFuncs(struct dd_function_table *functions)
127 {
128 functions->DrawBuffer = intelDrawBuffer;
129 functions->ReadBuffer = intelReadBuffer;
130 }