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