Merge branch 'master' of ../mesa into vulkan
[mesa.git] / src / mesa / drivers / dri / i965 / intel_buffers.c
1 /*
2 * Copyright 2003 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "brw_context.h"
27 #include "intel_buffers.h"
28 #include "intel_fbo.h"
29 #include "intel_mipmap_tree.h"
30
31 #include "main/fbobject.h"
32 #include "main/framebuffer.h"
33 #include "main/renderbuffer.h"
34
35
36 bool
37 brw_is_front_buffer_reading(struct gl_framebuffer *fb)
38 {
39 if (!fb || _mesa_is_user_fbo(fb))
40 return false;
41
42 return fb->_ColorReadBufferIndex == BUFFER_FRONT_LEFT;
43 }
44
45 bool
46 brw_is_front_buffer_drawing(struct gl_framebuffer *fb)
47 {
48 if (!fb || _mesa_is_user_fbo(fb))
49 return false;
50
51 return (fb->_NumColorDrawBuffers >= 1 &&
52 fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT);
53 }
54
55 static void
56 intelDrawBuffer(struct gl_context * ctx, GLenum mode)
57 {
58 if (brw_is_front_buffer_drawing(ctx->DrawBuffer)) {
59 struct brw_context *const brw = brw_context(ctx);
60
61 /* If we might be front-buffer rendering on this buffer for the first
62 * time, invalidate our DRI drawable so we'll ask for new buffers
63 * (including the fake front) before we start rendering again.
64 */
65 dri2InvalidateDrawable(brw->driContext->driDrawablePriv);
66 intel_prepare_render(brw);
67 }
68 }
69
70
71 static void
72 intelReadBuffer(struct gl_context * ctx, GLenum mode)
73 {
74 if (brw_is_front_buffer_reading(ctx->ReadBuffer)) {
75 struct brw_context *const brw = brw_context(ctx);
76
77 /* If we might be front-buffer reading on this buffer for the first
78 * time, invalidate our DRI drawable so we'll ask for new buffers
79 * (including the fake front) before we start reading again.
80 */
81 dri2InvalidateDrawable(brw->driContext->driReadablePriv);
82 intel_prepare_render(brw);
83 }
84 }
85
86
87 void
88 intelInitBufferFuncs(struct dd_function_table *functions)
89 {
90 functions->DrawBuffer = intelDrawBuffer;
91 functions->ReadBuffer = intelReadBuffer;
92 }