Merge branch 'i915tex_privbuffers' into softpipe_0_1_branch
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_lock.c
1 /**************************************************************************
2
3 Copyright 2006 Stephane Marchesin
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 "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
15 Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 **************************************************************************/
26
27
28 #include "nouveau_context.h"
29 #include "nouveau_lock.h"
30
31 #include "drirenderbuffer.h"
32 #include "framebuffer.h"
33
34
35 /* Update the hardware state. This is called if another context has
36 * grabbed the hardware lock, which includes the X server. This
37 * function also updates the driver's window state after the X server
38 * moves, resizes or restacks a window -- the change will be reflected
39 * in the drawable position and clip rects. Since the X server grabs
40 * the hardware lock when it changes the window state, this routine will
41 * automatically be called after such a change.
42 */
43 void nouveauGetLock( nouveauContextPtr nmesa, GLuint flags )
44 {
45 __DRIdrawablePrivate *dPriv = nmesa->driDrawable;
46 __DRIscreenPrivate *sPriv = nmesa->driScreen;
47 struct drm_nouveau_sarea *sarea = nmesa->sarea;
48
49 drmGetLock( nmesa->driFd, nmesa->hHWContext, flags );
50
51 /* The window might have moved, so we might need to get new clip
52 * rects.
53 *
54 * NOTE: This releases and regrabs the hw lock to allow the X server
55 * to respond to the DRI protocol request for new drawable info.
56 * Since the hardware state depends on having the latest drawable
57 * clip rects, all state checking must be done _after_ this call.
58 */
59 DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
60
61 /* If timestamps don't match, the window has been changed */
62 if (nmesa->lastStamp != dPriv->lastStamp) {
63 struct gl_framebuffer *fb = (struct gl_framebuffer *)dPriv->driverPrivate;
64
65 /* _mesa_resize_framebuffer will take care of calling the renderbuffer's
66 * AllocStorage function if we need more memory to hold it */
67 if (fb->Width != dPriv->w || fb->Height != dPriv->h) {
68 _mesa_resize_framebuffer(nmesa->glCtx, fb, dPriv->w, dPriv->h);
69 /* resize buffers, will call nouveau_window_moved */
70 nouveau_build_framebuffer(nmesa->glCtx, fb);
71 } else {
72 nouveau_window_moved(nmesa->glCtx);
73 }
74
75 nmesa->lastStamp = dPriv->lastStamp;
76 }
77
78 nmesa->numClipRects = dPriv->numClipRects;
79 nmesa->pClipRects = dPriv->pClipRects;
80
81 }