i965: Shorten context base class dereference chains.
[mesa.git] / src / mesa / drivers / dri / i965 / 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 "brw_context.h"
29 #include "intel_buffers.h"
30 #include "intel_fbo.h"
31 #include "intel_mipmap_tree.h"
32
33 #include "main/fbobject.h"
34 #include "main/framebuffer.h"
35 #include "main/renderbuffer.h"
36
37 /**
38 * Check if we're about to draw into the front color buffer.
39 * If so, set the brw->front_buffer_dirty field to true.
40 */
41 void
42 intel_check_front_buffer_rendering(struct brw_context *brw)
43 {
44 struct gl_context *ctx = &brw->intel.ctx;
45 const struct gl_framebuffer *fb = ctx->DrawBuffer;
46 if (_mesa_is_winsys_fbo(fb)) {
47 /* drawing to window system buffer */
48 if (fb->_NumColorDrawBuffers > 0) {
49 if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
50 brw->front_buffer_dirty = true;
51 }
52 }
53 }
54 }
55
56 static void
57 intelDrawBuffer(struct gl_context * ctx, GLenum mode)
58 {
59 if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) {
60 struct brw_context *const brw = brw_context(ctx);
61 const bool was_front_buffer_rendering = brw->is_front_buffer_rendering;
62
63 brw->is_front_buffer_rendering = (mode == GL_FRONT_LEFT)
64 || (mode == GL_FRONT) || (mode == GL_FRONT_AND_BACK);
65
66 /* If we weren't front-buffer rendering before but we are now,
67 * invalidate our DRI drawable so we'll ask for new buffers
68 * (including the fake front) before we start rendering again.
69 */
70 if (!was_front_buffer_rendering && brw->is_front_buffer_rendering)
71 dri2InvalidateDrawable(brw->driContext->driDrawablePriv);
72 }
73 }
74
75
76 static void
77 intelReadBuffer(struct gl_context * ctx, GLenum mode)
78 {
79 if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) {
80 struct brw_context *const brw = brw_context(ctx);
81 const bool was_front_buffer_reading = brw->is_front_buffer_reading;
82
83 brw->is_front_buffer_reading = mode == GL_FRONT_LEFT || mode == GL_FRONT;
84
85 /* If we weren't front-buffer reading before but we are now,
86 * invalidate our DRI drawable so we'll ask for new buffers
87 * (including the fake front) before we start reading again.
88 */
89 if (!was_front_buffer_reading && brw->is_front_buffer_reading)
90 dri2InvalidateDrawable(brw->driContext->driReadablePriv);
91 }
92 }
93
94
95 void
96 intelInitBufferFuncs(struct dd_function_table *functions)
97 {
98 functions->DrawBuffer = intelDrawBuffer;
99 functions->ReadBuffer = intelReadBuffer;
100 }