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