Merge branch 'master' of git+ssh://michal@git.freedesktop.org/git/mesa/mesa into...
[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 static char *fake_span[1280*1024*4];
41
42 #define HW_CLIPLOOP() \
43 do { \
44 int _nc = nmesa->numClipRects; \
45 while ( _nc-- ) { \
46 int minx = nmesa->pClipRects[_nc].x1 - nmesa->drawX; \
47 int miny = nmesa->pClipRects[_nc].y1 - nmesa->drawY; \
48 int maxx = nmesa->pClipRects[_nc].x2 - nmesa->drawX; \
49 int maxy = nmesa->pClipRects[_nc].y2 - nmesa->drawY;
50
51 #define LOCAL_VARS \
52 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); \
53 nouveau_renderbuffer *nrb = (nouveau_renderbuffer *)rb; \
54 GLuint height = nrb->mesa.Height; \
55 GLubyte *map = (GLubyte *)(nrb->map ? nrb->map : nrb->mem->map) + \
56 (nmesa->drawY * nrb->pitch) + (nmesa->drawX * nrb->cpp); \
57 map = fake_span; \
58 GLuint p; \
59 (void) p;
60
61 #define Y_FLIP( _y ) (height - _y - 1)
62
63 #define HW_LOCK()
64
65 #define HW_UNLOCK()
66
67
68
69 /* ================================================================
70 * Color buffers
71 */
72
73 /* RGB565 */
74 #define SPANTMP_PIXEL_FMT GL_RGB
75 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
76
77 #define TAG(x) nouveau##x##_RGB565
78 #define TAG2(x,y) nouveau##x##_RGB565##y
79 #define GET_PTR(X,Y) (map + (Y)*nrb->pitch + (X)*nrb->cpp)
80 #include "spantmp2.h"
81
82
83 /* ARGB8888 */
84 #define SPANTMP_PIXEL_FMT GL_BGRA
85 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
86
87 #define TAG(x) nouveau##x##_ARGB8888
88 #define TAG2(x,y) nouveau##x##_ARGB8888##y
89 #define GET_PTR(X,Y) (map + (Y)*nrb->pitch + (X)*nrb->cpp)
90 #include "spantmp2.h"
91
92 static void
93 nouveauSpanRenderStart( GLcontext *ctx )
94 {
95 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
96 FIRE_RING();
97 LOCK_HARDWARE(nmesa);
98 nouveauWaitForIdleLocked( nmesa );
99 }
100
101 static void
102 nouveauSpanRenderFinish( GLcontext *ctx )
103 {
104 nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
105 _swrast_flush( ctx );
106 nouveauWaitForIdleLocked( nmesa );
107 UNLOCK_HARDWARE( nmesa );
108 }
109
110 void nouveauSpanInitFunctions( GLcontext *ctx )
111 {
112 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
113 swdd->SpanRenderStart = nouveauSpanRenderStart;
114 swdd->SpanRenderFinish = nouveauSpanRenderFinish;
115 }
116
117
118 /**
119 * Plug in the Get/Put routines for the given driRenderbuffer.
120 */
121 void
122 nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis)
123 {
124 if (nrb->mesa._ActualFormat == GL_RGBA8)
125 nouveauInitPointers_ARGB8888(&nrb->mesa);
126 else // if (nrb->mesa._ActualFormat == GL_RGB5)
127 nouveauInitPointers_RGB565(&nrb->mesa);
128 }