intel_buffers.c revision 4433b0302d0aa9dc61002e8bb4fd1b752b0be338
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/************************************************************************** 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * All Rights Reserved. 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * copy of this software and associated documentation files (the 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * "Software"), to deal in the Software without restriction, including 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish, 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the following conditions: 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The above copyright notice and this permission notice (including the 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * of the Software. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) **************************************************************************/ 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "intel_context.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "intel_buffers.h" 30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "intel_fbo.h" 31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "intel_mipmap_tree.h" 32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "main/fbobject.h" 34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "main/framebuffer.h" 35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "main/renderbuffer.h" 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Return pointer to current color drawing region, or NULL. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct intel_region * 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)intel_drawbuf_region(struct intel_context *intel) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){ 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct intel_renderbuffer *irbColor = 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) intel_renderbuffer(intel->ctx.DrawBuffer->_ColorDrawBuffers[0]); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (irbColor && irbColor->mt) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return irbColor->mt->region; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 49} 50 51/** 52 * Return pointer to current color reading region, or NULL. 53 */ 54struct intel_region * 55intel_readbuf_region(struct intel_context *intel) 56{ 57 struct intel_renderbuffer *irb 58 = intel_renderbuffer(intel->ctx.ReadBuffer->_ColorReadBuffer); 59 if (irb && irb->mt) 60 return irb->mt->region; 61 else 62 return NULL; 63} 64 65/** 66 * Check if we're about to draw into the front color buffer. 67 * If so, set the intel->front_buffer_dirty field to true. 68 */ 69void 70intel_check_front_buffer_rendering(struct intel_context *intel) 71{ 72 const struct gl_framebuffer *fb = intel->ctx.DrawBuffer; 73 if (fb->Name == 0) { 74 /* drawing to window system buffer */ 75 if (fb->_NumColorDrawBuffers > 0) { 76 if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) { 77 intel->front_buffer_dirty = true; 78 } 79 } 80 } 81} 82 83static void 84intelDrawBuffer(struct gl_context * ctx, GLenum mode) 85{ 86 if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) { 87 struct intel_context *const intel = intel_context(ctx); 88 const bool was_front_buffer_rendering = 89 intel->is_front_buffer_rendering; 90 91 intel->is_front_buffer_rendering = (mode == GL_FRONT_LEFT) 92 || (mode == GL_FRONT) || (mode == GL_FRONT_AND_BACK); 93 94 /* If we weren't front-buffer rendering before but we are now, 95 * invalidate our DRI drawable so we'll ask for new buffers 96 * (including the fake front) before we start rendering again. 97 */ 98 if (!was_front_buffer_rendering && intel->is_front_buffer_rendering) 99 dri2InvalidateDrawable(intel->driContext->driDrawablePriv); 100 } 101 102 intel_draw_buffer(ctx); 103} 104 105 106static void 107intelReadBuffer(struct gl_context * ctx, GLenum mode) 108{ 109 if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) { 110 struct intel_context *const intel = intel_context(ctx); 111 const bool was_front_buffer_reading = 112 intel->is_front_buffer_reading; 113 114 intel->is_front_buffer_reading = (mode == GL_FRONT_LEFT) 115 || (mode == GL_FRONT); 116 117 /* If we weren't front-buffer reading before but we are now, 118 * invalidate our DRI drawable so we'll ask for new buffers 119 * (including the fake front) before we start reading again. 120 */ 121 if (!was_front_buffer_reading && intel->is_front_buffer_reading) 122 dri2InvalidateDrawable(intel->driContext->driReadablePriv); 123 } 124} 125 126 127void 128intelInitBufferFuncs(struct dd_function_table *functions) 129{ 130 functions->DrawBuffer = intelDrawBuffer; 131 functions->ReadBuffer = intelReadBuffer; 132} 133