Skip to content

Commit 065cf4f

Browse files
X547kallisti5
authored andcommittedJan 10, 2021
hgl: Major refactor and cleanup
* Drop old-timey GLDisplatcher * Refactor haiku-softpipe fixing some hacks * Bubble BBitmap up to winsys Reviewed-by: Alexander von Gluck IV <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8323>
1 parent bd6ea80 commit 065cf4f

18 files changed

+497
-674
lines changed
 

‎include/HaikuGL/GLRenderer.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class _EXPORT BGLRenderer
2727
BGLRenderer & operator=(const BGLRenderer &);
2828

2929
public:
30-
BGLRenderer(BGLView *view, ulong bgl_options,
31-
BGLDispatcher *dispatcher);
30+
BGLRenderer(BGLView *view, ulong bgl_options);
3231
virtual ~BGLRenderer();
3332

3433
void Acquire();
@@ -50,7 +49,6 @@ class _EXPORT BGLRenderer
5049
inline int32 ReferenceCount() const { return fRefCount; };
5150
inline ulong Options() const { return fOptions; };
5251
inline BGLView* GLView() { return fView; };
53-
inline BGLDispatcher* GLDispatcher() { return fDispatcher; };
5452

5553
private:
5654
friend class GLRendererRoster;
@@ -64,13 +62,12 @@ class _EXPORT BGLRenderer
6462
int32 fRefCount; // How much we're still useful
6563
BGLView* fView; // Never forget who is the boss!
6664
ulong fOptions; // Keep that tune in memory
67-
BGLDispatcher* fDispatcher;// Our personal GL API call dispatcher
6865

6966
GLRendererRoster* fOwningRoster;
7067
renderer_id fID;
7168
};
7269

73-
extern "C" _EXPORT BGLRenderer* instantiate_gl_renderer(BGLView *view, ulong options, BGLDispatcher *dispatcher);
70+
extern "C" _EXPORT BGLRenderer* instantiate_gl_renderer(BGLView *view, ulong options);
7471

7572

7673
#endif // GLRENDERER_H

‎include/HaikuGL/GLView.h

+13-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212

1313
#include <GL/gl.h>
1414

15-
#define BGL_RGB 0
16-
#define BGL_INDEX 1
17-
#define BGL_SINGLE 0
18-
#define BGL_DOUBLE 2
19-
#define BGL_DIRECT 0
20-
#define BGL_INDIRECT 4
21-
#define BGL_ACCUM 8
22-
#define BGL_ALPHA 16
23-
#define BGL_DEPTH 32
24-
#define BGL_OVERLAY 64
25-
#define BGL_UNDERLAY 128
26-
#define BGL_STENCIL 512
15+
#define BGL_RGB 0
16+
#define BGL_INDEX 1
17+
#define BGL_SINGLE 0
18+
#define BGL_DOUBLE 2
19+
#define BGL_DIRECT 0
20+
#define BGL_INDIRECT 4
21+
#define BGL_ACCUM 8
22+
#define BGL_ALPHA 16
23+
#define BGL_DEPTH 32
24+
#define BGL_OVERLAY 64
25+
#define BGL_UNDERLAY 128
26+
#define BGL_STENCIL 512
27+
#define BGL_SHARE_CONTEXT 1024
2728

2829
#ifdef __cplusplus
2930

‎src/gallium/frontends/hgl/hgl.c

+85-79
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,20 @@ hgl_st_framebuffer(struct st_framebuffer_iface *stfbi)
5757

5858

5959
static bool
60-
hgl_st_framebuffer_flush_front(struct st_context_iface *stctxi,
60+
hgl_st_framebuffer_flush_front(struct st_context_iface* stctxi,
6161
struct st_framebuffer_iface* stfbi, enum st_attachment_type statt)
6262
{
6363
CALLED();
6464

65-
//struct hgl_context* context = hgl_st_context(stctxi);
66-
// struct hgl_buffer* buffer = hgl_st_context(stfbi);
6765
struct hgl_buffer* buffer = hgl_st_framebuffer(stfbi);
68-
//buffer->surface
66+
struct pipe_resource* ptex = buffer->textures[statt];
6967

70-
#if 0
71-
struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb);
72-
mtx_lock(&stwfb->fb->mutex);
68+
if (!ptex)
69+
return true;
7370

74-
struct pipe_resource* resource = textures[statt];
75-
if (resource)
76-
stw_framebuffer_present_locked(...);
77-
#endif
71+
// TODO: pipe_context here??? Might be needed for hw renderers
72+
buffer->screen->flush_frontbuffer(buffer->screen, NULL, ptex, 0, 0,
73+
buffer->winsysContext, NULL);
7874

7975
return true;
8076
}
@@ -93,6 +89,8 @@ hgl_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
9389
buffer = hgl_st_framebuffer(stfbi);
9490

9591
if (buffer->width != width || buffer->height != height) {
92+
TRACE("validate_textures: size changed: %d, %d -> %d, %d\n",
93+
buffer->width, buffer->height, width, height);
9694
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
9795
pipe_resource_reference(&buffer->textures[i], NULL);
9896
}
@@ -109,31 +107,34 @@ hgl_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
109107
enum pipe_format format;
110108
unsigned bind;
111109

112-
switch (i) {
113-
case ST_ATTACHMENT_FRONT_LEFT:
114-
case ST_ATTACHMENT_BACK_LEFT:
115-
case ST_ATTACHMENT_FRONT_RIGHT:
116-
case ST_ATTACHMENT_BACK_RIGHT:
117-
format = buffer->visual->color_format;
118-
bind = PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_RENDER_TARGET;
119-
break;
120-
case ST_ATTACHMENT_DEPTH_STENCIL:
121-
format = buffer->visual->depth_stencil_format;
122-
bind = PIPE_BIND_DEPTH_STENCIL;
123-
break;
124-
default:
125-
format = PIPE_FORMAT_NONE;
126-
bind = 0;
127-
break;
128-
}
129-
130-
if (format != PIPE_FORMAT_NONE) {
131-
templat.format = format;
132-
templat.bind = bind;
133-
buffer->textures[i] = buffer->screen->resource_create(buffer->screen,
134-
&templat);
135-
if (!buffer->textures[i])
136-
return FALSE;
110+
if (((1 << i) & buffer->visual->buffer_mask) && buffer->textures[i] == NULL) {
111+
switch (i) {
112+
case ST_ATTACHMENT_FRONT_LEFT:
113+
case ST_ATTACHMENT_BACK_LEFT:
114+
case ST_ATTACHMENT_FRONT_RIGHT:
115+
case ST_ATTACHMENT_BACK_RIGHT:
116+
format = buffer->visual->color_format;
117+
bind = PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_RENDER_TARGET;
118+
break;
119+
case ST_ATTACHMENT_DEPTH_STENCIL:
120+
format = buffer->visual->depth_stencil_format;
121+
bind = PIPE_BIND_DEPTH_STENCIL;
122+
break;
123+
default:
124+
format = PIPE_FORMAT_NONE;
125+
bind = 0;
126+
break;
127+
}
128+
129+
if (format != PIPE_FORMAT_NONE) {
130+
templat.format = format;
131+
templat.bind = bind;
132+
TRACE("resource_create(%d, %d, %d)\n", i, format, bind);
133+
buffer->textures[i] = buffer->screen->resource_create(buffer->screen,
134+
&templat);
135+
if (!buffer->textures[i])
136+
return FALSE;
137+
}
137138
}
138139
}
139140

@@ -165,10 +166,6 @@ hgl_st_framebuffer_validate(struct st_context_iface *stctxi,
165166
context = hgl_st_context(stctxi);
166167
buffer = hgl_st_framebuffer(stfbi);
167168

168-
//int32 width = 0;
169-
//int32 height = 0;
170-
//get_bitmap_size(context->bitmap, &width, &height);
171-
172169
// Build mask of current attachments
173170
stAttachmentMask = 0;
174171
for (i = 0; i < count; i++)
@@ -186,14 +183,9 @@ hgl_st_framebuffer_validate(struct st_context_iface *stctxi,
186183

187184
ret = hgl_st_framebuffer_validate_textures(stfbi,
188185
context->width, context->height, stAttachmentMask);
189-
186+
190187
if (!ret)
191188
return ret;
192-
193-
// TODO: Simply update attachments
194-
//if (!resized) {
195-
196-
//}
197189
}
198190

199191
for (i = 0; i < count; i++)
@@ -223,14 +215,14 @@ static uint32_t hgl_fb_ID = 0;
223215
* Create new framebuffer
224216
*/
225217
struct hgl_buffer *
226-
hgl_create_st_framebuffer(struct hgl_context* context)
218+
hgl_create_st_framebuffer(struct hgl_context* context, void *winsysContext)
227219
{
228220
struct hgl_buffer *buffer;
229221
CALLED();
230222

231223
// Our requires before creating a framebuffer
232224
assert(context);
233-
assert(context->screen);
225+
assert(context->display);
234226
assert(context->stVisual);
235227

236228
buffer = CALLOC_STRUCT(hgl_buffer);
@@ -242,9 +234,10 @@ hgl_create_st_framebuffer(struct hgl_context* context)
242234

243235
// Prepare our buffer
244236
buffer->visual = context->stVisual;
245-
buffer->screen = context->screen;
237+
buffer->screen = context->display->manager->screen;
238+
buffer->winsysContext = winsysContext;
246239

247-
if (context->screen->get_param(buffer->screen, PIPE_CAP_NPOT_TEXTURES))
240+
if (buffer->screen->get_param(buffer->screen, PIPE_CAP_NPOT_TEXTURES))
248241
buffer->target = PIPE_TEXTURE_2D;
249242
else
250243
buffer->target = PIPE_TEXTURE_RECT;
@@ -257,49 +250,31 @@ hgl_create_st_framebuffer(struct hgl_context* context)
257250
p_atomic_set(&buffer->stfbi->stamp, 1);
258251
buffer->stfbi->st_manager_private = (void*)buffer;
259252
buffer->stfbi->ID = p_atomic_inc_return(&hgl_fb_ID);
260-
buffer->stfbi->state_manager = context->manager;
253+
buffer->stfbi->state_manager = context->display->manager;
261254

262255
return buffer;
263256
}
264257

265258

266-
struct st_api*
267-
hgl_create_st_api()
268-
{
269-
CALLED();
270-
return st_gl_api_create();
271-
}
272-
273-
274-
struct st_manager *
275-
hgl_create_st_manager(struct hgl_context* context)
259+
void
260+
hgl_destroy_st_framebuffer(struct hgl_buffer *buffer)
276261
{
277-
struct st_manager* manager;
278-
279262
CALLED();
280263

281-
// Required things
282-
assert(context);
283-
assert(context->screen);
284-
285-
manager = CALLOC_STRUCT(st_manager);
286-
assert(manager);
264+
int i;
265+
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
266+
pipe_resource_reference(&buffer->textures[i], NULL);
287267

288-
//manager->display = dpy;
289-
manager->screen = context->screen;
290-
manager->get_param = hgl_st_manager_get_param;
291-
manager->st_manager_private = (void *)context;
292-
293-
return manager;
268+
FREE(buffer->stfbi);
269+
FREE(buffer);
294270
}
295271

296272

297-
void
298-
hgl_destroy_st_manager(struct st_manager *manager)
273+
struct st_api*
274+
hgl_create_st_api()
299275
{
300276
CALLED();
301-
302-
FREE(manager);
277+
return st_gl_api_create();
303278
}
304279

305280

@@ -335,6 +310,7 @@ hgl_create_st_visual(ulong options)
335310
visual->render_buffer = ST_ATTACHMENT_FRONT_LEFT;
336311

337312
if ((options & BGL_DOUBLE) != 0) {
313+
TRACE("double buffer enabled\n");
338314
visual->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
339315
visual->render_buffer = ST_ATTACHMENT_BACK_LEFT;
340316
}
@@ -364,3 +340,33 @@ hgl_destroy_st_visual(struct st_visual* visual)
364340

365341
FREE(visual);
366342
}
343+
344+
345+
struct hgl_display*
346+
hgl_create_display(struct pipe_screen* screen)
347+
{
348+
struct hgl_display* display;
349+
350+
display = CALLOC_STRUCT(hgl_display);
351+
assert(display);
352+
display->api = st_gl_api_create();
353+
display->manager = CALLOC_STRUCT(st_manager);
354+
assert(display->manager);
355+
display->manager->screen = screen;
356+
display->manager->get_param = hgl_st_manager_get_param;
357+
// display->manager->st_manager_private is used by llvmpipe
358+
359+
return display;
360+
}
361+
362+
363+
void
364+
hgl_destroy_display(struct hgl_display *display)
365+
{
366+
if (display->manager->destroy)
367+
display->manager->destroy(display->manager);
368+
FREE(display->manager);
369+
if (display->api->destroy)
370+
display->api->destroy(display->api);
371+
FREE(display);
372+
}

‎src/gallium/frontends/hgl/hgl_context.h

+18-21
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
#ifndef HGL_CONTEXT_H
99
#define HGL_CONTEXT_H
1010

11-
11+
#include "os/os_thread.h"
1212
#include "pipe/p_format.h"
1313
#include "pipe/p_compiler.h"
1414
#include "pipe/p_screen.h"
1515
#include "postprocess/filters.h"
1616

1717
#include "frontend/api.h"
18-
#include "frontend/st_manager.h"
19-
#include "os/os_thread.h"
2018

2119
#include "bitmap_wrapper.h"
2220

@@ -41,31 +39,29 @@ struct hgl_buffer
4139
unsigned mask;
4240

4341
struct pipe_screen* screen;
44-
struct pipe_surface* surface;
42+
void* winsysContext;
4543

4644
enum pipe_texture_target target;
4745
struct pipe_resource* textures[ST_ATTACHMENT_COUNT];
4846

4947
void *map;
50-
51-
//struct hgl_buffer *next; /**< next in linked list */
5248
};
5349

5450

55-
struct hgl_context
51+
struct hgl_display
5652
{
53+
mtx_t mutex;
54+
5755
struct st_api* api;
58-
// API
5956
struct st_manager* manager;
60-
// Manager
61-
struct st_context_iface* st;
62-
// Interface Object
63-
struct st_visual* stVisual;
64-
// Visual
57+
};
6558

66-
struct pipe_screen* screen;
6759

68-
//struct pipe_resource* textures[ST_ATTACHMENT_COUNT];
60+
struct hgl_context
61+
{
62+
struct hgl_display* display;
63+
struct st_context_iface* st;
64+
struct st_visual* stVisual;
6965

7066
// Post processing
7167
struct pp_queue_t* postProcess;
@@ -75,13 +71,9 @@ struct hgl_context
7571
unsigned width;
7672
unsigned height;
7773

78-
Bitmap* bitmap;
79-
color_space colorSpace;
80-
8174
mtx_t fbMutex;
8275

83-
struct hgl_buffer* draw;
84-
struct hgl_buffer* read;
76+
struct hgl_buffer* buffer;
8577
};
8678

8779
// hgl_buffer from statetracker interface
@@ -91,7 +83,8 @@ struct hgl_buffer* hgl_st_framebuffer(struct st_framebuffer_iface *stfbi);
9183
struct st_api* hgl_create_st_api(void);
9284

9385
// hgl framebuffer
94-
struct hgl_buffer* hgl_create_st_framebuffer(struct hgl_context* context);
86+
struct hgl_buffer* hgl_create_st_framebuffer(struct hgl_context* context, void *winsysContext);
87+
void hgl_destroy_st_framebuffer(struct hgl_buffer *buffer);
9588

9689
// hgl manager
9790
struct st_manager* hgl_create_st_manager(struct hgl_context* screen);
@@ -101,6 +94,10 @@ void hgl_destroy_st_manager(struct st_manager *manager);
10194
struct st_visual* hgl_create_st_visual(ulong options);
10295
void hgl_destroy_st_visual(struct st_visual* visual);
10396

97+
// hgl display
98+
struct hgl_display* hgl_create_display(struct pipe_screen* screen);
99+
void hgl_destroy_display(struct hgl_display *display);
100+
104101

105102
#ifdef __cplusplus
106103
}

‎src/gallium/targets/haiku-softpipe/GalliumContext.cpp

+103-79
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "GalliumContext.h"
1212

1313
#include <stdio.h>
14+
#include <algorithm>
1415

1516
#include "GLView.h"
1617

@@ -41,11 +42,12 @@
4142
#endif
4243
#define ERROR(x...) printf("GalliumContext: " x)
4344

45+
int32 GalliumContext::fDisplayRefCount = 0;
46+
hgl_display* GalliumContext::fDisplay = NULL;
4447

4548
GalliumContext::GalliumContext(ulong options)
4649
:
4750
fOptions(options),
48-
fScreen(NULL),
4951
fCurrentContext(0)
5052
{
5153
CALLED();
@@ -54,7 +56,7 @@ GalliumContext::GalliumContext(ulong options)
5456
for (context_id i = 0; i < CONTEXT_MAX; i++)
5557
fContext[i] = NULL;
5658

57-
CreateScreen();
59+
CreateDisplay();
5860

5961
(void) mtx_init(&fMutex, mtx_plain);
6062
}
@@ -70,17 +72,20 @@ GalliumContext::~GalliumContext()
7072
DestroyContext(i);
7173
Unlock();
7274

73-
mtx_destroy(&fMutex);
75+
DestroyDisplay();
7476

75-
// TODO: Destroy fScreen
77+
mtx_destroy(&fMutex);
7678
}
7779

7880

7981
status_t
80-
GalliumContext::CreateScreen()
82+
GalliumContext::CreateDisplay()
8183
{
8284
CALLED();
8385

86+
if (atomic_add(&fDisplayRefCount, 1) > 0)
87+
return B_OK;
88+
8489
// Allocate winsys and attach callback hooks
8590
struct sw_winsys* winsys = hgl_create_sw_winsys();
8691

@@ -89,25 +94,47 @@ GalliumContext::CreateScreen()
8994
return B_ERROR;
9095
}
9196

92-
fScreen = sw_screen_create(winsys);
97+
struct pipe_screen* screen = sw_screen_create(winsys);
9398

94-
if (fScreen == NULL) {
99+
if (screen == NULL) {
95100
ERROR("%s: Couldn't create screen!\n", __FUNCTION__);
96-
FREE(winsys);
101+
winsys->destroy(winsys);
97102
return B_ERROR;
98103
}
99104

100-
debug_screen_wrap(fScreen);
105+
debug_screen_wrap(screen);
101106

102-
const char* driverName = fScreen->get_name(fScreen);
107+
const char* driverName = screen->get_name(screen);
103108
ERROR("%s: Using %s driver.\n", __func__, driverName);
104109

110+
fDisplay = hgl_create_display(screen);
111+
112+
if (fDisplay == NULL) {
113+
ERROR("%s: Couldn't create display!\n", __FUNCTION__);
114+
screen->destroy(screen); // will also destroy winsys
115+
return B_ERROR;
116+
}
117+
105118
return B_OK;
106119
}
107120

108121

122+
void
123+
GalliumContext::DestroyDisplay()
124+
{
125+
if (atomic_add(&fDisplayRefCount, -1) > 1)
126+
return;
127+
128+
if (fDisplay != NULL) {
129+
struct pipe_screen* screen = fDisplay->manager->screen;
130+
hgl_destroy_display(fDisplay); fDisplay = NULL;
131+
screen->destroy(screen); // destroy will deallocate object
132+
}
133+
}
134+
135+
109136
context_id
110-
GalliumContext::CreateContext(Bitmap *bitmap)
137+
GalliumContext::CreateContext(HGLWinsysContext *wsContext)
111138
{
112139
CALLED();
113140

@@ -119,31 +146,15 @@ GalliumContext::CreateContext(Bitmap *bitmap)
119146
}
120147

121148
// Set up the initial things our context needs
122-
context->bitmap = bitmap;
123-
context->colorSpace = get_bitmap_color_space(bitmap);
124-
context->screen = fScreen;
125-
context->draw = NULL;
126-
context->read = NULL;
127-
context->st = NULL;
128-
129-
// Create st_gl_api
130-
context->api = hgl_create_st_api();
131-
if (!context->api) {
132-
ERROR("%s: Couldn't obtain Mesa state tracker API!\n", __func__);
133-
return -1;
134-
}
135-
136-
// Create state_tracker manager
137-
context->manager = hgl_create_st_manager(context);
149+
context->display = fDisplay;
138150

139151
// Create state tracker visual
140152
context->stVisual = hgl_create_st_visual(fOptions);
141153

142154
// Create state tracker framebuffers
143-
context->draw = hgl_create_st_framebuffer(context);
144-
context->read = hgl_create_st_framebuffer(context);
155+
context->buffer = hgl_create_st_framebuffer(context, wsContext);
145156

146-
if (!context->draw || !context->read) {
157+
if (!context->buffer) {
147158
ERROR("%s: Problem allocating framebuffer!\n", __func__);
148159
FREE(context->stVisual);
149160
return -1;
@@ -159,10 +170,17 @@ GalliumContext::CreateContext(Bitmap *bitmap)
159170
attribs.minor = 0;
160171
//attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
161172

173+
struct st_context_iface* shared = NULL;
174+
175+
if (fOptions & BGL_SHARE_CONTEXT) {
176+
shared = fDisplay->api->get_current(fDisplay->api);
177+
TRACE("shared context: %p\n", shared);
178+
}
179+
162180
// Create context using state tracker api call
163181
enum st_context_error result;
164-
context->st = context->api->create_context(context->api, context->manager,
165-
&attribs, &result, context->st);
182+
context->st = fDisplay->api->create_context(fDisplay->api, fDisplay->manager,
183+
&attribs, &result, shared);
166184

167185
if (!context->st) {
168186
ERROR("%s: Couldn't create mesa state tracker context!\n",
@@ -200,7 +218,7 @@ GalliumContext::CreateContext(Bitmap *bitmap)
200218
context->st->st_manager_private = (void*)context;
201219

202220
struct st_context *stContext = (struct st_context*)context->st;
203-
221+
204222
// Init Gallium3D Post Processing
205223
// TODO: no pp filters are enabled yet through postProcessEnable
206224
context->postProcess = pp_init(stContext->pipe, context->postProcessEnable,
@@ -243,31 +261,26 @@ GalliumContext::DestroyContext(context_id contextID)
243261
return;
244262

245263
if (fContext[contextID]->st) {
246-
fContext[contextID]->st->flush(fContext[contextID]->st, 0, NULL);
264+
fContext[contextID]->st->flush(fContext[contextID]->st, 0, NULL, NULL, NULL);
247265
fContext[contextID]->st->destroy(fContext[contextID]->st);
248266
}
249267

250268
if (fContext[contextID]->postProcess)
251269
pp_free(fContext[contextID]->postProcess);
252270

253271
// Delete state tracker framebuffer objects
254-
if (fContext[contextID]->read)
255-
delete fContext[contextID]->read;
256-
if (fContext[contextID]->draw)
257-
delete fContext[contextID]->draw;
272+
if (fContext[contextID]->buffer)
273+
hgl_destroy_st_framebuffer(fContext[contextID]->buffer);
258274

259275
if (fContext[contextID]->stVisual)
260276
hgl_destroy_st_visual(fContext[contextID]->stVisual);
261277

262-
if (fContext[contextID]->manager)
263-
hgl_destroy_st_manager(fContext[contextID]->manager);
264-
265278
FREE(fContext[contextID]);
266279
}
267280

268281

269282
status_t
270-
GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID)
283+
GalliumContext::SetCurrentContext(bool set, context_id contextID)
271284
{
272285
CALLED();
273286

@@ -279,16 +292,17 @@ GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID)
279292
Lock();
280293
context_id oldContextID = fCurrentContext;
281294
struct hgl_context* context = fContext[contextID];
282-
Unlock();
283295

284296
if (!context) {
285297
ERROR("%s: Invalid context provided (#%" B_PRIu64 ")!\n",
286298
__func__, contextID);
299+
Unlock();
287300
return B_ERROR;
288301
}
289302

290-
if (!bitmap) {
291-
context->api->make_current(context->api, NULL, NULL, NULL);
303+
if (!set) {
304+
fDisplay->api->make_current(fDisplay->api, NULL, NULL, NULL);
305+
Unlock();
292306
return B_OK;
293307
}
294308

@@ -297,24 +311,13 @@ GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID)
297311

298312
if (oldContextID > 0 && oldContextID != contextID) {
299313
fContext[oldContextID]->st->flush(fContext[oldContextID]->st,
300-
ST_FLUSH_FRONT, NULL);
314+
ST_FLUSH_FRONT, NULL, NULL, NULL);
301315
}
302316

303317
// We need to lock and unlock framebuffers before accessing them
304-
context->api->make_current(context->api, context->st, context->draw->stfbi,
305-
context->read->stfbi);
306-
307-
//if (context->textures[ST_ATTACHMENT_BACK_LEFT]
308-
// && context->textures[ST_ATTACHMENT_DEPTH_STENCIL]
309-
// && context->postProcess) {
310-
// TRACE("Postprocessing textures...\n");
311-
// pp_init_fbos(context->postProcess,
312-
// context->textures[ST_ATTACHMENT_BACK_LEFT]->width0,
313-
// context->textures[ST_ATTACHMENT_BACK_LEFT]->height0);
314-
//}
315-
316-
context->bitmap = bitmap;
317-
//context->st->pipe->priv = context;
318+
fDisplay->api->make_current(fDisplay->api, context->st, context->buffer->stfbi,
319+
context->buffer->stfbi);
320+
Unlock();
318321

319322
return B_OK;
320323
}
@@ -326,40 +329,62 @@ GalliumContext::SwapBuffers(context_id contextID)
326329
CALLED();
327330

328331
Lock();
329-
struct hgl_context *context = fContext[contextID];
330-
Unlock();
332+
struct hgl_context* context = fContext[contextID];
331333

332334
if (!context) {
333335
ERROR("%s: context not found\n", __func__);
336+
Unlock();
334337
return B_ERROR;
335338
}
336-
context->st->flush(context->st, ST_FLUSH_FRONT, NULL);
337339

338-
struct hgl_buffer* buffer = hgl_st_framebuffer(context->draw->stfbi);
339-
pipe_surface* surface = buffer->surface;
340-
if (!surface) {
341-
ERROR("%s: Invalid drawable surface!\n", __func__);
342-
return B_ERROR;
343-
}
340+
// will flush front buffer if no double buffering is used
341+
context->st->flush(context->st, ST_FLUSH_FRONT, NULL, NULL, NULL);
344342

345-
fScreen->flush_frontbuffer(fScreen, context->st->pipe, surface->texture, 0, 0,
346-
context->bitmap, NULL);
343+
struct hgl_buffer* buffer = context->buffer;
347344

345+
// flush back buffer and swap buffers if double buffering is used
346+
if (buffer->textures[ST_ATTACHMENT_BACK_LEFT] != NULL) {
347+
buffer->screen->flush_frontbuffer(buffer->screen, NULL, buffer->textures[ST_ATTACHMENT_BACK_LEFT],
348+
0, 0, buffer->winsysContext, NULL);
349+
std::swap(buffer->textures[ST_ATTACHMENT_FRONT_LEFT], buffer->textures[ST_ATTACHMENT_BACK_LEFT]);
350+
p_atomic_inc(&buffer->stfbi->stamp);
351+
}
352+
353+
Unlock();
348354
return B_OK;
349355
}
350356

351357

358+
void
359+
GalliumContext::Draw(context_id contextID, BRect updateRect)
360+
{
361+
struct hgl_context *context = fContext[contextID];
362+
363+
if (!context) {
364+
ERROR("%s: context not found\n", __func__);
365+
return;
366+
}
367+
368+
struct hgl_buffer* buffer = context->buffer;
369+
370+
if (buffer->textures[ST_ATTACHMENT_FRONT_LEFT] == NULL)
371+
return;
372+
373+
buffer->screen->flush_frontbuffer(buffer->screen, NULL, buffer->textures[ST_ATTACHMENT_FRONT_LEFT],
374+
0, 0, buffer->winsysContext, NULL);
375+
}
376+
377+
352378
bool
353379
GalliumContext::Validate(uint32 width, uint32 height)
354380
{
355381
CALLED();
356382

357-
if (!fContext[fCurrentContext]) {
383+
if (!fContext[fCurrentContext])
358384
return false;
359-
}
360385

361-
if (fContext[fCurrentContext]->width != width
362-
|| fContext[fCurrentContext]->height != height) {
386+
if (fContext[fCurrentContext]->width != width + 1
387+
|| fContext[fCurrentContext]->height != height + 1) {
363388
Invalidate(width, height);
364389
return false;
365390
}
@@ -375,12 +400,11 @@ GalliumContext::Invalidate(uint32 width, uint32 height)
375400
assert(fContext[fCurrentContext]);
376401

377402
// Update st_context dimensions
378-
fContext[fCurrentContext]->width = width;
379-
fContext[fCurrentContext]->height = height;
403+
fContext[fCurrentContext]->width = width + 1;
404+
fContext[fCurrentContext]->height = height + 1;
380405

381406
// Is this the best way to invalidate?
382-
p_atomic_inc(&fContext[fCurrentContext]->read->stfbi->stamp);
383-
p_atomic_inc(&fContext[fCurrentContext]->draw->stfbi->stamp);
407+
p_atomic_inc(&fContext[fCurrentContext]->buffer->stfbi->stamp);
384408
}
385409

386410

‎src/gallium/targets/haiku-softpipe/GalliumContext.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
#include "pipe/p_screen.h"
1717
#include "postprocess/filters.h"
1818
#include "hgl_context.h"
19-
20-
#include "bitmap_wrapper.h"
19+
#include "sw/hgl/hgl_sw_winsys.h"
2120

2221

22+
class BBitmap;
2323

2424
class GalliumContext {
2525
public:
@@ -29,28 +29,30 @@ class GalliumContext {
2929
void Lock();
3030
void Unlock();
3131

32-
context_id CreateContext(Bitmap* bitmap);
32+
context_id CreateContext(HGLWinsysContext *wsContext);
3333
void DestroyContext(context_id contextID);
3434
context_id GetCurrentContext() { return fCurrentContext; };
35-
status_t SetCurrentContext(Bitmap *bitmap,
36-
context_id contextID);
35+
status_t SetCurrentContext(bool set, context_id contextID);
3736

3837
status_t SwapBuffers(context_id contextID);
38+
void Draw(context_id contextID, BRect updateRect);
3939

4040
bool Validate(uint32 width, uint32 height);
4141
void Invalidate(uint32 width, uint32 height);
4242

4343
private:
44-
status_t CreateScreen();
44+
status_t CreateDisplay();
45+
void DestroyDisplay();
4546
void Flush();
4647

4748
ulong fOptions;
48-
struct pipe_screen* fScreen;
49+
static int32 fDisplayRefCount;
50+
static hgl_display* fDisplay;
4951

5052
// Context Management
5153
struct hgl_context* fContext[CONTEXT_MAX];
5254
context_id fCurrentContext;
53-
mtx_t fMutex;
55+
mtx_t fMutex;
5456
};
5557

5658

‎src/gallium/targets/haiku-softpipe/SoftwareRenderer.cpp

+130-176
Large diffs are not rendered by default.

‎src/gallium/targets/haiku-softpipe/SoftwareRenderer.h

+14-17
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,34 @@
1818
#include "GalliumContext.h"
1919

2020

21-
class SoftwareRenderer : public BGLRenderer {
21+
class SoftwareRenderer : public BGLRenderer, public HGLWinsysContext {
2222
public:
2323
SoftwareRenderer(BGLView *view,
24-
ulong bgl_options,
25-
BGLDispatcher *dispatcher);
24+
ulong bgl_options);
2625
virtual ~SoftwareRenderer();
2726

28-
virtual void LockGL();
29-
virtual void UnlockGL();
27+
void LockGL();
28+
void UnlockGL();
3029

31-
virtual void SwapBuffers(bool vsync = false);
32-
virtual void Draw(BRect updateRect);
33-
virtual status_t CopyPixelsOut(BPoint source, BBitmap *dest);
34-
virtual status_t CopyPixelsIn(BBitmap *source, BPoint dest);
35-
virtual void FrameResized(float width, float height);
30+
void Display(BBitmap* bitmap, BRect* updateRect);
3631

37-
virtual void EnableDirectMode(bool enabled);
38-
virtual void DirectConnected(direct_buffer_info *info);
32+
void SwapBuffers(bool vsync = false);
33+
void Draw(BRect updateRect);
34+
status_t CopyPixelsOut(BPoint source, BBitmap *dest);
35+
status_t CopyPixelsIn(BBitmap *source, BPoint dest);
36+
void FrameResized(float width, float height);
3937

40-
private:
41-
42-
void _AllocateBitmap();
38+
void EnableDirectMode(bool enabled);
39+
void DirectConnected(direct_buffer_info *info);
4340

41+
private:
4442
GalliumContext* fContextObj;
45-
BBitmap* fBitmap;
4643
context_id fContextID;
4744

4845
bool fDirectModeEnabled;
4946
direct_buffer_info* fInfo;
5047
BLocker fInfoLocker;
51-
ulong fOptions;
48+
ulong fOptions;
5249
GLuint fWidth;
5350
GLuint fHeight;
5451
color_space fColorSpace;

‎src/gallium/winsys/sw/hgl/hgl_sw_winsys.c ‎src/gallium/winsys/sw/hgl/hgl_sw_winsys.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
#include "frontend/api.h"
3838
#include "frontend/sw_winsys.h"
3939

40-
#include "bitmap_wrapper.h"
4140
#include "hgl_sw_winsys.h"
4241

42+
#include <Bitmap.h>
43+
#include <OS.h>
4344

4445
#ifdef DEBUG
4546
# define TRACE(x...) printf("hgl:winsys: " x)
@@ -63,6 +64,7 @@ struct haiku_displaytarget
6364
unsigned size;
6465

6566
void* data;
67+
BBitmap* bitmap;
6668
};
6769

6870

@@ -126,10 +128,18 @@ hgl_winsys_displaytarget_create(struct sw_winsys* winsys,
126128
haikuDisplayTarget->stride = align(formatStride, alignment);
127129
haikuDisplayTarget->size = haikuDisplayTarget->stride * blockSize;
128130

129-
haikuDisplayTarget->data
130-
= align_malloc(haikuDisplayTarget->size, alignment);
131-
132-
assert(haikuDisplayTarget->data);
131+
if (textureUsage & PIPE_BIND_DISPLAY_TARGET) {
132+
haikuDisplayTarget->data = NULL;
133+
haikuDisplayTarget->bitmap = new BBitmap(
134+
BRect(0, 0, width - 1, height - 1),
135+
haikuDisplayTarget->colorSpace,
136+
haikuDisplayTarget->stride);
137+
} else {
138+
haikuDisplayTarget->data
139+
= align_malloc(haikuDisplayTarget->size, alignment);
140+
141+
haikuDisplayTarget->bitmap = NULL;
142+
}
133143

134144
*stride = haikuDisplayTarget->stride;
135145

@@ -151,6 +161,9 @@ hgl_winsys_displaytarget_destroy(struct sw_winsys* winsys,
151161
if (haikuDisplayTarget->data != NULL)
152162
align_free(haikuDisplayTarget->data);
153163

164+
if (haikuDisplayTarget->bitmap != NULL)
165+
delete haikuDisplayTarget->bitmap;
166+
154167
FREE(haikuDisplayTarget);
155168
}
156169

@@ -179,13 +192,16 @@ hgl_winsys_displaytarget_map(struct sw_winsys* winsys,
179192
struct haiku_displaytarget* haikuDisplayTarget
180193
= hgl_sw_displaytarget(displayTarget);
181194

195+
if (haikuDisplayTarget->bitmap != NULL)
196+
return haikuDisplayTarget->bitmap->Bits();
197+
182198
return haikuDisplayTarget->data;
183199
}
184200

185201

186202
static void
187203
hgl_winsys_displaytarget_unmap(struct sw_winsys* winsys,
188-
struct sw_displaytarget* disptarget)
204+
struct sw_displaytarget* displayTarget)
189205
{
190206
return;
191207
}
@@ -198,19 +214,11 @@ hgl_winsys_displaytarget_display(struct sw_winsys* winsys,
198214
{
199215
assert(contextPrivate);
200216

201-
Bitmap* bitmap = (Bitmap*)contextPrivate;
202-
203217
struct haiku_displaytarget* haikuDisplayTarget
204218
= hgl_sw_displaytarget(displayTarget);
205219

206-
import_bitmap_bits(bitmap, haikuDisplayTarget->data,
207-
haikuDisplayTarget->size, haikuDisplayTarget->stride,
208-
haikuDisplayTarget->colorSpace);
209-
210-
// Dump the rendered bitmap to disk for debugging
211-
//dump_bitmap(bitmap);
212-
213-
return;
220+
HGLWinsysContext *context = (HGLWinsysContext*)contextPrivate;
221+
context->Display(haikuDisplayTarget->bitmap, NULL);
214222
}
215223

216224

@@ -221,7 +229,7 @@ hgl_create_sw_winsys()
221229

222230
if (!winsys)
223231
return NULL;
224-
232+
225233
// Attach winsys hooks for Haiku
226234
winsys->destroy = hgl_winsys_destroy;
227235
winsys->is_displaytarget_format_supported

‎src/gallium/winsys/sw/hgl/hgl_sw_winsys.h

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
#ifndef _HGL_SOFTWAREWINSYS_H
2828
#define _HGL_SOFTWAREWINSYS_H
2929

30+
#ifdef __cplusplus
31+
class BBitmap;
32+
class BRect;
33+
34+
class HGLWinsysContext {
35+
public:
36+
virtual void Display(BBitmap *bitmap, BRect *updateRect) = 0;
37+
};
38+
#endif
39+
3040
#ifdef __cplusplus
3141
extern "C" {
3242
#endif

‎src/gallium/winsys/sw/hgl/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
libswhgl = static_library(
2222
'swhgl',
23-
files('hgl_sw_winsys.c'),
23+
files('hgl_sw_winsys.cpp'),
2424
gnu_symbol_visibility : 'hidden',
2525
include_directories : [inc_gallium, inc_include, inc_src, inc_gallium_aux,
2626
include_directories('../../../frontends/hgl')

‎src/hgl/GLDispatcher.cpp

-65
This file was deleted.

‎src/hgl/GLDispatcher.h

-105
This file was deleted.

‎src/hgl/GLRenderer.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@
88

99
#include "GLRenderer.h"
1010

11-
#include "GLDispatcher.h"
1211

13-
14-
BGLRenderer::BGLRenderer(BGLView* view, ulong glOptions,
15-
BGLDispatcher* dispatcher)
12+
BGLRenderer::BGLRenderer(BGLView* view, ulong glOptions)
1613
:
1714
fRefCount(1),
1815
fView(view),
19-
fOptions(glOptions),
20-
fDispatcher(dispatcher)
16+
fOptions(glOptions)
2117
{
2218
}
2319

2420

2521
BGLRenderer::~BGLRenderer()
2622
{
27-
delete fDispatcher;
2823
}
2924

3025

@@ -38,7 +33,7 @@ BGLRenderer::Acquire()
3833
void
3934
BGLRenderer::Release()
4035
{
41-
if (atomic_add(&fRefCount, -1) < 1)
36+
if (atomic_add(&fRefCount, -1) <= 1)
4237
delete this;
4338
}
4439

‎src/hgl/GLRendererRoster.cpp

+41-32
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,34 @@
1212
#include <image.h>
1313

1414
#include <kernel/image.h>
15-
#include <system/safemode_defs.h>
15+
#include <private/system/safemode_defs.h>
1616

1717
#include <Directory.h>
1818
#include <FindDirectory.h>
1919
#include <Path.h>
2020
#include <strings.h>
21-
#include "GLDispatcher.h"
2221
#include "GLRendererRoster.h"
2322

2423
#include <new>
2524
#include <string.h>
25+
#include <stdio.h>
2626

2727

2828
extern "C" status_t _kern_get_safemode_option(const char* parameter,
2929
char* buffer, size_t* _bufferSize);
3030

31+
GLRendererRoster *GLRendererRoster::fInstance = NULL;
3132

32-
GLRendererRoster::GLRendererRoster(BGLView* view, ulong options)
33+
GLRendererRoster *GLRendererRoster::Roster()
34+
{
35+
if (fInstance == NULL) {
36+
fInstance = new GLRendererRoster();
37+
}
38+
return fInstance;
39+
}
40+
41+
GLRendererRoster::GLRendererRoster()
3342
:
34-
fNextID(0),
35-
fView(view),
36-
fOptions(options),
3743
fSafeMode(false),
3844
fABISubDirectory(NULL)
3945
{
@@ -84,14 +90,19 @@ GLRendererRoster::~GLRendererRoster()
8490

8591

8692
BGLRenderer*
87-
GLRendererRoster::GetRenderer(int32 id)
93+
GLRendererRoster::GetRenderer(BGLView *view, ulong options)
8894
{
89-
RendererMap::const_iterator iterator = fRenderers.find(id);
90-
if (iterator == fRenderers.end())
91-
return NULL;
92-
93-
struct renderer_item item = iterator->second;
94-
return item.renderer;
95+
for (
96+
RendererMap::const_iterator iterator = fRenderers.begin();
97+
iterator != fRenderers.end();
98+
iterator++
99+
) {
100+
renderer_item item = *iterator;
101+
BGLRenderer* renderer;
102+
renderer = item.entry(view, options);
103+
return renderer;
104+
}
105+
return NULL;
95106
}
96107

97108

@@ -102,6 +113,7 @@ GLRendererRoster::AddDefaultPaths()
102113
const directory_which paths[] = {
103114
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
104115
B_USER_ADDONS_DIRECTORY,
116+
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
105117
B_SYSTEM_ADDONS_DIRECTORY,
106118
};
107119

@@ -162,24 +174,22 @@ GLRendererRoster::AddPath(const char* path)
162174

163175

164176
status_t
165-
GLRendererRoster::AddRenderer(BGLRenderer* renderer,
177+
GLRendererRoster::AddRenderer(InstantiateRenderer entry,
166178
image_id image, const entry_ref* ref, ino_t node)
167179
{
168180
renderer_item item;
169-
item.renderer = renderer;
181+
item.entry = entry;
170182
item.image = image;
171183
item.node = node;
172184
if (ref != NULL)
173185
item.ref = *ref;
174186

175187
try {
176-
fRenderers[fNextID] = item;
188+
fRenderers.push_back(item);
177189
} catch (...) {
178190
return B_NO_MEMORY;
179191
}
180192

181-
renderer->fOwningRoster = this;
182-
renderer->fID = fNextID++;
183193
return B_OK;
184194
}
185195

@@ -194,30 +204,29 @@ GLRendererRoster::CreateRenderer(const entry_ref& ref)
194204
return status;
195205

196206
BPath path(&ref);
207+
printf("OpenGL load add-on: %s\n", path.Path());
208+
197209
image_id image = load_add_on(path.Path());
198210
if (image < B_OK)
199211
return image;
200212

201-
BGLRenderer* (*instantiate_renderer)
202-
(BGLView* view, ulong options, BGLDispatcher* dispatcher);
213+
InstantiateRenderer instantiate_renderer;
203214

204-
status = get_image_symbol(image, "instantiate_gl_renderer",
205-
B_SYMBOL_TYPE_TEXT, (void**)&instantiate_renderer);
206-
if (status == B_OK) {
207-
BGLRenderer* renderer
208-
= instantiate_renderer(fView, fOptions, new BGLDispatcher());
209-
if (!renderer) {
210-
unload_add_on(image);
211-
return B_UNSUPPORTED;
212-
}
215+
status = get_image_symbol(
216+
image, "instantiate_gl_renderer",
217+
B_SYMBOL_TYPE_TEXT, (void**)&instantiate_renderer
218+
);
213219

214-
if (AddRenderer(renderer, image, &ref, nodeRef.node) != B_OK) {
215-
renderer->Release();
216-
// this will delete the renderer
220+
if (status == B_OK) {
221+
if ((status = AddRenderer(instantiate_renderer, image, &ref, nodeRef.node)) != B_OK) {
217222
unload_add_on(image);
223+
return status;
218224
}
225+
printf("OpenGL add-on registered: %s\n", path.Path());
219226
return B_OK;
220227
}
228+
229+
printf("OpenGL add-on failed to instantiate: %s\n", path.Path());
221230
unload_add_on(image);
222231

223232
return status;

‎src/hgl/GLRendererRoster.h

+15-14
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,43 @@
99
#define _GLRENDERER_ROSTER_H
1010

1111

12-
#include "GLRenderer.h"
12+
#include <GLRenderer.h>
1313

14-
#include <map>
14+
#include <vector>
1515

1616

17+
typedef BGLRenderer* (*InstantiateRenderer) (BGLView* view, ulong options);
18+
1719
struct renderer_item {
18-
BGLRenderer* renderer;
20+
InstantiateRenderer entry;
1921
entry_ref ref;
2022
ino_t node;
2123
image_id image;
2224
};
2325

24-
typedef std::map<renderer_id, renderer_item> RendererMap;
26+
typedef std::vector<renderer_item> RendererMap;
2527

2628

2729
class GLRendererRoster {
2830
public:
29-
GLRendererRoster(BGLView* view, ulong options);
30-
virtual ~GLRendererRoster();
31-
32-
BGLRenderer* GetRenderer(int32 id = 0);
31+
static GLRendererRoster *Roster();
32+
BGLRenderer* GetRenderer(BGLView *view, ulong options);
3333

3434
private:
35+
GLRendererRoster();
36+
virtual ~GLRendererRoster();
37+
3538
void AddDefaultPaths();
3639
status_t AddPath(const char* path);
37-
status_t AddRenderer(BGLRenderer* renderer,
38-
image_id image, const entry_ref* ref, ino_t node);
40+
status_t AddRenderer(InstantiateRenderer entry, image_id image,
41+
const entry_ref* ref, ino_t node);
3942
status_t CreateRenderer(const entry_ref& ref);
4043

41-
RendererMap fRenderers;
42-
int32 fNextID;
43-
BGLView* fView;
44-
ulong fOptions;
44+
static GLRendererRoster* fInstance;
4545
bool fSafeMode;
4646
const char* fABISubDirectory;
4747

48+
RendererMap fRenderers;
4849
};
4950

5051

‎src/hgl/GLView.cpp

+26-34
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <DirectWindow.h>
2121
#include "GLRenderer.h"
2222

23-
#include "interface/DirectWindowPrivate.h"
24-
#include "GLDispatcher.h"
23+
#include <private/interface/DirectWindowPrivate.h>
2524
#include "GLRendererRoster.h"
2625

26+
#include "glapi/glapi.h"
2727

2828
struct glview_direct_info {
2929
direct_buffer_info* direct_info;
@@ -39,19 +39,16 @@ BGLView::BGLView(BRect rect, const char* name, ulong resizingMode, ulong mode,
3939
ulong options)
4040
:
4141
BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS),
42-
// | B_FULL_UPDATE_ON_RESIZE)
4342
fGc(NULL),
4443
fOptions(options),
4544
fDitherCount(0),
4645
fDrawLock("BGLView draw lock"),
4746
fDisplayLock("BGLView display lock"),
4847
fClipInfo(NULL),
4948
fRenderer(NULL),
50-
fRoster(NULL),
5149
fDitherMap(NULL)
5250
{
53-
fRoster = new GLRendererRoster(this, options);
54-
fRenderer = fRoster->GetRenderer();
51+
fRenderer = GLRendererRoster::Roster()->GetRenderer(this, options);
5552
}
5653

5754

@@ -77,6 +74,15 @@ BGLView::LockGL()
7774
void
7875
BGLView::UnlockGL()
7976
{
77+
thread_id lockerThread = fDisplayLock.LockingThread();
78+
thread_id callerThread = find_thread(NULL);
79+
80+
if (lockerThread != B_ERROR && lockerThread != callerThread) {
81+
printf("UnlockGL is called from wrong thread, lockerThread: %d, callerThread: %d\n",
82+
(int)lockerThread, (int)callerThread);
83+
debugger("[!]");
84+
}
85+
8086
if (fRenderer != NULL && fDisplayLock.CountLocks() == 1)
8187
fRenderer->UnlockGL();
8288
fDisplayLock.Unlock();
@@ -113,15 +119,7 @@ BGLView::EmbeddedView()
113119
void*
114120
BGLView::GetGLProcAddress(const char* procName)
115121
{
116-
BGLDispatcher* glDispatcher = NULL;
117-
118-
if (fRenderer)
119-
glDispatcher = fRenderer->GLDispatcher();
120-
121-
if (glDispatcher)
122-
return (void*)glDispatcher->AddressOf(procName);
123-
124-
return NULL;
122+
return (void*)_glapi_get_proc_address(procName);
125123
}
126124

127125

@@ -170,9 +168,8 @@ void
170168
BGLView::Draw(BRect updateRect)
171169
{
172170
if (fRenderer) {
173-
_LockDraw();
174-
fRenderer->Draw(updateRect);
175-
_UnlockDraw();
171+
if (!fClipInfo || !fClipInfo->enable_direct_mode)
172+
fRenderer->Draw(updateRect);
176173
return;
177174
}
178175
// TODO: auto-size and center the string
@@ -237,10 +234,6 @@ BGLView::AllAttached()
237234
void
238235
BGLView::DetachedFromWindow()
239236
{
240-
if (fRenderer)
241-
fRenderer->Release();
242-
fRenderer = NULL;
243-
244237
BView::DetachedFromWindow();
245238
}
246239

@@ -260,12 +253,9 @@ BGLView::FrameResized(float width, float height)
260253
v->ConvertToParent(&fBounds);
261254

262255
if (fRenderer) {
263-
LockGL();
264-
_LockDraw();
265-
_CallDirectConnected();
256+
//_LockDraw();
266257
fRenderer->FrameResized(width, height);
267-
_UnlockDraw();
268-
UnlockGL();
258+
//_UnlockDraw();
269259
}
270260

271261
BView::FrameResized(width, height);
@@ -342,6 +332,7 @@ BGLView::GetSupportedSuites(BMessage* data)
342332
void
343333
BGLView::DirectConnected(direct_buffer_info* info)
344334
{
335+
printf("BGLView::DirectConnected\n");
345336
if (fClipInfo == NULL) {
346337
fClipInfo = new (std::nothrow) glview_direct_info();
347338
if (fClipInfo == NULL)
@@ -350,33 +341,33 @@ BGLView::DirectConnected(direct_buffer_info* info)
350341

351342
direct_buffer_info* localInfo = fClipInfo->direct_info;
352343

344+
_LockDraw();
353345
switch (info->buffer_state & B_DIRECT_MODE_MASK) {
354346
case B_DIRECT_START:
355347
fClipInfo->direct_connected = true;
356348
memcpy(localInfo, info, DIRECT_BUFFER_INFO_AREA_SIZE);
357-
_UnlockDraw();
358349
break;
359350

360351
case B_DIRECT_MODIFY:
361-
_LockDraw();
362352
memcpy(localInfo, info, DIRECT_BUFFER_INFO_AREA_SIZE);
363-
_UnlockDraw();
364353
break;
365354

366355
case B_DIRECT_STOP:
367356
fClipInfo->direct_connected = false;
368-
_LockDraw();
369357
break;
370358
}
371359

372360
if (fRenderer)
373361
_CallDirectConnected();
362+
363+
_UnlockDraw();
374364
}
375365

376366

377367
void
378368
BGLView::EnableDirectMode(bool enabled)
379369
{
370+
printf("BGLView::EnableDirectMode: %d\n", (int)enabled);
380371
if (fRenderer)
381372
fRenderer->EnableDirectMode(enabled);
382373
if (fClipInfo == NULL) {
@@ -412,8 +403,10 @@ BGLView::_UnlockDraw()
412403
void
413404
BGLView::_CallDirectConnected()
414405
{
415-
if (!fClipInfo)
406+
if (!fClipInfo || !fClipInfo->direct_connected) {
407+
fRenderer->DirectConnected(NULL);
416408
return;
409+
}
417410

418411
direct_buffer_info* localInfo = fClipInfo->direct_info;
419412
direct_buffer_info* info = (direct_buffer_info*)malloc(
@@ -472,10 +465,9 @@ BGLView::BGLView(BRect rect, char* name, ulong resizingMode, ulong mode,
472465
fDisplayLock("BGLView display lock"),
473466
fClipInfo(NULL),
474467
fRenderer(NULL),
475-
fRoster(NULL),
476468
fDitherMap(NULL)
477469
{
478-
fRoster = new GLRendererRoster(this, options);
470+
fRenderer = GLRendererRoster::Roster()->GetRenderer(this, options);
479471
}
480472

481473

‎src/hgl/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
libgl = shared_library(
2222
'GL',
2323
files(
24-
'GLView.cpp', 'GLRenderer.cpp', 'GLRendererRoster.cpp', 'GLDispatcher.cpp',
24+
'GLView.cpp', 'GLRenderer.cpp', 'GLRendererRoster.cpp',
2525
),
2626
link_args : [ld_args_bsymbolic, ld_args_gc_sections],
2727
include_directories : [

0 commit comments

Comments
 (0)
Please sign in to comment.