Merge branch '7.8'
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_driver.c
1 /*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a 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
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_fbo.h"
30 #include "nouveau_util.h"
31
32 #include "drivers/common/meta.h"
33
34 static const GLubyte *
35 nouveau_get_string(GLcontext *ctx, GLenum name)
36 {
37 static char buffer[128];
38 char hardware_name[32];
39
40 switch (name) {
41 case GL_VENDOR:
42 return (GLubyte *)"Nouveau";
43
44 case GL_RENDERER:
45 sprintf(hardware_name, "nv%02X", context_chipset(ctx));
46 driGetRendererString(buffer, hardware_name, DRIVER_DATE, 0);
47
48 return (GLubyte *)buffer;
49 default:
50 return NULL;
51 }
52 }
53
54 static void
55 nouveau_flush(GLcontext *ctx)
56 {
57 struct nouveau_context *nctx = to_nouveau_context(ctx);
58 struct nouveau_channel *chan = context_chan(ctx);
59
60 FIRE_RING(chan);
61
62 if (ctx->DrawBuffer->Name == 0 &&
63 ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
64 __DRIscreen *screen = nctx->screen->dri_screen;
65 __DRIdri2LoaderExtension *dri2 = screen->dri2.loader;
66 __DRIdrawable *drawable = nctx->dri_context->driDrawablePriv;
67
68 dri2->flushFrontBuffer(drawable, drawable->loaderPrivate);
69 }
70 }
71
72 static void
73 nouveau_finish(GLcontext *ctx)
74 {
75 nouveau_flush(ctx);
76 }
77
78 void
79 nouveau_clear(GLcontext *ctx, GLbitfield buffers)
80 {
81 struct gl_framebuffer *fb = ctx->DrawBuffer;
82 int x, y, w, h;
83 int i, buf;
84
85 nouveau_validate_framebuffer(ctx);
86 get_scissors(fb, &x, &y, &w, &h);
87
88 for (i = 0; i < BUFFER_COUNT; i++) {
89 struct nouveau_surface *s;
90 unsigned mask, value;
91
92 buf = buffers & (1 << i);
93 if (!buf)
94 continue;
95
96 s = &to_nouveau_renderbuffer(
97 fb->Attachment[i].Renderbuffer->Wrapped)->surface;
98
99 if (buf & BUFFER_BITS_COLOR) {
100 mask = pack_rgba_i(s->format, ctx->Color.ColorMask[0]);
101 value = pack_rgba_f(s->format, ctx->Color.ClearColor);
102
103 if (mask)
104 context_drv(ctx)->surface_fill(
105 ctx, s, mask, value, x, y, w, h);
106
107 buffers &= ~buf;
108
109 } else if (buf & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) {
110 mask = pack_zs_i(s->format,
111 (buffers & BUFFER_BIT_DEPTH &&
112 ctx->Depth.Mask) ? ~0 : 0,
113 (buffers & BUFFER_BIT_STENCIL ?
114 ctx->Stencil.WriteMask[0] : 0));
115 value = pack_zs_f(s->format,
116 ctx->Depth.Clear,
117 ctx->Stencil.Clear);
118
119 if (mask)
120 context_drv(ctx)->surface_fill(
121 ctx, s, mask, value, x, y, w, h);
122
123 buffers &= ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
124 }
125 }
126
127 if (buffers)
128 _mesa_meta_Clear(ctx, buffers);
129 }
130
131 void
132 nouveau_driver_functions_init(struct dd_function_table *functions)
133 {
134 functions->GetString = nouveau_get_string;
135 functions->Flush = nouveau_flush;
136 functions->Finish = nouveau_finish;
137 functions->Clear = nouveau_clear;
138 functions->DrawPixels = _mesa_meta_DrawPixels;
139 functions->CopyPixels = _mesa_meta_CopyPixels;
140 functions->Bitmap = _mesa_meta_Bitmap;
141 functions->BlitFramebuffer = _mesa_meta_BlitFramebuffer;
142 }