aboutsummaryrefslogtreecommitdiff
path: root/doc/nx-X11_vs_XOrg69_patches/context.c.NX.patch
blob: 92dedfc0ac160a1537364c65f5fbc76c7e715376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
--- ./nx-X11/extras/Mesa/src/mesa/main/context.c.X.original	2015-02-13 14:03:44.464447019 +0100
+++ ./nx-X11/extras/Mesa/src/mesa/main/context.c	2015-02-10 19:13:14.800648672 +0100
@@ -131,6 +131,10 @@
 #endif
 #include "shaderobjects.h"
 
+#ifdef NXAGENT_SERVER
+#include "WSDrawBuffer.h"
+#endif
+
 #ifdef USE_SPARC_ASM
 #include "sparc/sparc.h"
 #endif
@@ -143,6 +147,47 @@
 int MESA_DEBUG_FLAGS = 0;
 #endif
 
+#ifdef NXAGENT_SERVER
+extern WSDrawBufferPtr pWSDrawBuffer;
+
+int IsWSDrawBuffer(GLframebuffer *mesa_buffer)
+{
+  WSDrawBufferPtr p = pWSDrawBuffer;
+
+  while (p != NULL) {
+    if (p -> DrawBuffer == mesa_buffer) {
+      return 1;
+    }
+    p = p -> next;
+  }
+  return 0;
+}
+
+void FreeWSDrawBuffer(GLframebuffer *mesa_buffer)
+{
+  WSDrawBufferPtr p = pWSDrawBuffer;
+  WSDrawBufferPtr pOld = NULL;
+
+  if (p == NULL)
+    return;
+
+  if (p -> DrawBuffer == mesa_buffer) {
+    pWSDrawBuffer = p -> next;
+    free(p);
+    return;
+  }
+
+  while (p -> next != NULL) {
+    if (p -> next -> DrawBuffer == mesa_buffer) {
+      pOld = p -> next;
+      p -> next = p -> next -> next;
+      free(pOld);
+      return;
+    }
+    p = p -> next;
+  }
+}
+#endif
 
 /* ubyte -> float conversion */
 GLfloat _mesa_ubyte_to_float_color_tab[256];
@@ -1520,6 +1565,10 @@
 _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
                     GLframebuffer *readBuffer )
 {
+   #ifdef NXAGENT_SERVER
+   int flag;
+   #endif
+
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(newCtx, "_mesa_make_current()\n");
 
@@ -1558,11 +1607,30 @@
          ASSERT(readBuffer->Name == 0);
          newCtx->WinSysDrawBuffer = drawBuffer;
          newCtx->WinSysReadBuffer = readBuffer;
+
+#ifdef NXAGENT_SERVER
+         flag = 0;
+         if (newCtx->DrawBuffer) {
+           if (!IsWSDrawBuffer(newCtx->DrawBuffer)) {
+             if (newCtx->DrawBuffer->Name == 0) {
+               flag = 1;
+             }
+             FreeWSDrawBuffer(newCtx->DrawBuffer);
+           }
+           else flag = 1;
+         }
+
+         if (!newCtx->DrawBuffer || flag) {
+           newCtx->DrawBuffer = drawBuffer;
+           newCtx->ReadBuffer = readBuffer;
+         }
+#else
          /* don't replace user-buffer bindings with window system buffer */
          if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
             newCtx->DrawBuffer = drawBuffer;
             newCtx->ReadBuffer = readBuffer;
          }
+#endif
 
 	 newCtx->NewState |= _NEW_BUFFERS;