2 Copyright 2011-2015, The AROS Development Team. All rights reserved.
6 #include "hostgl_ctx_manager.h"
7 #include "hostgl_funcs.h"
8 #include <proto/exec.h>
9 #include <aros/debug.h>
10 #if defined(RENDERER_PBUFFER_WPA)
11 #include <proto/cybergraphics.h>
12 #include <proto/graphics.h>
13 #include <cybergraphx/cybergraphics.h>
14 static struct SignalSemaphore
* GetX11SemaphoreFromBitmap(struct BitMap
* bm
);
16 #if defined(RENDERER_PIXMAP_BLIT)
17 #include <proto/graphics.h>
19 /*****************************************************************************
29 Swaps the back with front buffers. MUST BE used to display the effect
30 of rendering onto the target RastPort, since GLA always work in
34 ctx - GL rendering context on which swap is to be performed.
44 *****************************************************************************/
46 struct hostgl_context
*_ctx
= (struct hostgl_context
*)ctx
;
48 D(bug("[HostGL] TASK: 0x%x, SWAP 0x%x\n", FindTask(NULL
), _ctx
->glXctx
));
52 #if defined(RENDERER_SEPARATE_X_WINDOW)
55 HostGL_UpdateGlobalGLXContext();
56 dsp
= HostGL_GetGlobalX11Display();
57 GLXCALL(glXSwapBuffers
, dsp
, _ctx
->glXWindow
);
60 #if defined(RENDERER_PBUFFER_WPA)
62 LONG width
= _ctx
->framebuffer
->width
;
63 LONG height
= _ctx
->framebuffer
->height
;
65 /* This codes works correct with both 16bpp and 32 bpp pixel buffers */
68 HostGL_UpdateGlobalGLXContext();
69 ObtainSemaphore(GetX11SemaphoreFromBitmap(_ctx
->visible_rp
->BitMap
));
70 GLCALL(glReadPixels
, 0, 0, width
, height
, GL_BGRA
, GL_UNSIGNED_BYTE
, _ctx
->swapbuffer
);
71 ReleaseSemaphore(GetX11SemaphoreFromBitmap(_ctx
->visible_rp
->BitMap
));
75 for (line
= 0; line
< height
/ 2; line
++)
77 ULONG
* start
= _ctx
->swapbuffer
+ (line
* width
);
78 ULONG
* end
= _ctx
->swapbuffer
+ ((height
- line
- 1) * width
);
79 CopyMem(start
, _ctx
->swapbufferline
, width
* SWAPBUFFER_BPP
);
80 CopyMem(end
, start
, width
* SWAPBUFFER_BPP
);
81 CopyMem(_ctx
->swapbufferline
, end
, width
* SWAPBUFFER_BPP
);
84 WritePixelArray(_ctx
->swapbuffer
, 0, 0, width
* SWAPBUFFER_BPP
, _ctx
->visible_rp
, _ctx
->left
, _ctx
->top
,
85 width
, height
, RECTFMT_BGRA32
);
87 #if defined(RENDERER_PIXMAP_BLIT)
89 HostGL_UpdateGlobalGLXContext();
93 BltBitMapRastPort(_ctx
->glXPixmapBM
, 0, 0,
94 _ctx
->visible_rp
, _ctx
->left
, _ctx
->top
,
95 _ctx
->framebuffer
->width
, _ctx
->framebuffer
->height
,
99 HostGL_UpdateGlobalGLXContext();
103 HostGL_CheckAndUpdateBufferSize(_ctx
);
107 #if defined(RENDERER_PBUFFER_WPA)
108 /* HACK: EVIL HACK TO GET ACCESS TO X11 HIDD INTERNALS */
109 #include <proto/oop.h>
110 #define HIDD_BM_OBJ(bitmap) (*(OOP_Object **)&((bitmap)->Planes[0]))
119 Window masterxwindow
;
121 unsigned long sysplanemask
;
123 GC gc
; /* !!! This is an X11 GC, NOT a HIDD gc */
131 OOP_Object
*framebuffer
;
132 OOP_Object
*fakegfxhidd
;
135 struct x11_staticdata
137 /* These two members MUST be in the beginning of this structure
138 because they are exposed to disk-based part (see x11_class.h) */
139 UBYTE keycode2rawkey
[256];
142 struct SignalSemaphore sema
; /* Protecting this whole struct */
143 struct SignalSemaphore x11sema
;
148 struct Library library
;
150 struct x11_staticdata xsd
;
153 #define XSD(cl) (&((struct x11clbase *)cl->UserData)->xsd)
155 static struct SignalSemaphore
* GetX11SemaphoreFromBitmap(struct BitMap
* bm
)
157 static struct SignalSemaphore
* x11sem
= NULL
;
161 OOP_Object
* hiddbm
= HIDD_BM_OBJ(bm
);
162 struct fakefb_data
* fakefb
= (struct fakefb_data
*)OOP_INST_DATA(OOP_OCLASS(hiddbm
), hiddbm
);
163 x11sem
= (&XSD(OOP_OCLASS(fakefb
->framebuffer
))->x11sema
);