6d99728b852588c42fc19bc8a1b0cc223e4ab9c0
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_span.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_span.h"
30 #include "nouveau_fifo.h"
31 #include "nouveau_lock.h"
32
33 #include "swrast/swrast.h"
34
35 #define HAVE_HW_DEPTH_SPANS 0
36 #define HAVE_HW_DEPTH_PIXELS 0
37 #define HAVE_HW_STENCIL_SPANS 0
38 #define HAVE_HW_STENCIL_PIXELS 0
39
40 #define LOCAL_VARS \
41 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); \
42 __DRIscreenPrivate *sPriv = nmesa->driScreen; \
43 __DRIdrawablePrivate *dPriv = nmesa->driDrawable; \
44 driRenderbuffer *drb = (driRenderbuffer *) rb; \
45 GLuint height = dPriv->h; \
46 GLuint p; \
47 (void) p;
48
49 #define Y_FLIP( _y ) (height - _y - 1)
50
51 #define HW_LOCK()
52
53 #define HW_UNLOCK()
54
55
56
57 /* ================================================================
58 * Color buffers
59 */
60
61 /* RGB565 */
62 #define SPANTMP_PIXEL_FMT GL_RGB
63 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
64
65 #define TAG(x) nouveau##x##_RGB565
66 #define TAG2(x,y) nouveau##x##_RGB565##y
67 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
68 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
69 #include "spantmp2.h"
70
71
72 /* ARGB8888 */
73 #define SPANTMP_PIXEL_FMT GL_BGRA
74 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
75
76 #define TAG(x) nouveau##x##_ARGB8888
77 #define TAG2(x,y) nouveau##x##_ARGB8888##y
78 #define GET_PTR(X,Y) (sPriv->pFB + drb->flippedOffset \
79 + ((dPriv->y + (Y)) * drb->flippedPitch + (dPriv->x + (X))) * drb->cpp)
80 #include "spantmp2.h"
81
82 static void
83 nouveauSpanRenderStart( GLcontext *ctx )
84 {
85 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
86 FIRE_RING();
87 LOCK_HARDWARE(nmesa);
88 nouveauWaitForIdleLocked( nmesa );
89 }
90
91 static void
92 nouveauSpanRenderFinish( GLcontext *ctx )
93 {
94 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
95 _swrast_flush( ctx );
96 nouveauWaitForIdleLocked( nmesa );
97 UNLOCK_HARDWARE( nmesa );
98 }
99
100 void nouveauSpanInitFunctions( GLcontext *ctx )
101 {
102 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
103 swdd->SpanRenderStart = nouveauSpanRenderStart;
104 swdd->SpanRenderFinish = nouveauSpanRenderFinish;
105 }
106
107
108 /**
109 * Plug in the Get/Put routines for the given driRenderbuffer.
110 */
111 void
112 nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis)
113 {
114 if (nrb->mesa._ActualFormat == GL_RGBA8)
115 nouveauInitPointers_ARGB8888(&nrb->mesa);
116 else if (nrb->mesa._ActualFormat == GL_RGB5)
117 nouveauInitPointers_RGB565(&nrb->mesa);
118 }