Skip to content

Commit 15392a0

Browse files
committed
remove some debugging stuff
ready to be merged to master for pi 4 support
1 parent 673590d commit 15392a0

File tree

1 file changed

+105
-125
lines changed

1 file changed

+105
-125
lines changed

src/flutter-pi.c

Lines changed: 105 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -137,35 +137,35 @@ pthread_cond_t task_added = PTHREAD_COND_INITIALIZER;
137137
/*********************
138138
* FLUTTER CALLBACKS *
139139
*********************/
140-
bool make_current(void* userdata) {
140+
bool make_current(void* userdata) {
141141
if (eglMakeCurrent(egl.display, egl.surface, egl.surface, egl.context) != EGL_TRUE) {
142142
fprintf(stderr, "make_current: could not make the context current.\n");
143143
return false;
144144
}
145145

146146
return true;
147147
}
148-
bool clear_current(void* userdata) {
148+
bool clear_current(void* userdata) {
149149
if (eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) {
150150
fprintf(stderr, "clear_current: could not clear the current context.\n");
151151
return false;
152152
}
153153

154154
return true;
155155
}
156-
void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) {
156+
void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) {
157157
int *waiting_for_flip = data;
158158
*waiting_for_flip = 0;
159159
}
160-
void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) {
160+
void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) {
161161
struct drm_fb *fb = data;
162162

163163
if (fb->fb_id)
164164
drmModeRmFB(drm.fd, fb->fb_id);
165165

166166
free(fb);
167167
}
168-
struct drm_fb* drm_fb_get_from_bo(struct gbm_bo *bo) {
168+
struct drm_fb *drm_fb_get_from_bo(struct gbm_bo *bo) {
169169
uint32_t width, height, format, strides[4] = {0}, handles[4] = {0}, offsets[4] = {0}, flags = 0;
170170
int ok = -1;
171171

@@ -222,7 +222,7 @@ struct drm_fb* drm_fb_get_from_bo(struct gbm_bo *bo) {
222222

223223
return fb;
224224
}
225-
bool present(void* userdata) {
225+
bool present(void* userdata) {
226226
fd_set fds;
227227
struct gbm_bo *next_bo;
228228
struct drm_fb *fb;
@@ -232,8 +232,6 @@ bool present(void* userdata) {
232232
next_bo = gbm_surface_lock_front_buffer(gbm.surface);
233233
fb = drm_fb_get_from_bo(next_bo);
234234

235-
printf("***PRESENT***\n");
236-
237235
/* wait for vsync,
238236
ok = drmModePageFlip(drm.fd, drm.crtc_id, fb->fb_id, DRM_MODE_PAGE_FLIP_EVENT, &drm.waiting_for_flip);
239237
if (ok) {
@@ -274,12 +272,12 @@ bool present(void* userdata) {
274272

275273
return true;
276274
}
277-
uint32_t fbo_callback(void* userdata) {
275+
uint32_t fbo_callback(void* userdata) {
278276
return 0;
279277
}
280-
void cut_word_from_string(char* string, char* word) {
278+
void cut_word_from_string(char* string, char* word) {
281279
size_t word_length = strlen(word);
282-
char* word_in_str = strstr(string, word);
280+
char* word_in_str = strstr(string, word);
283281

284282
// check if the given word is surrounded by spaces in the string
285283
if (word_in_str
@@ -294,139 +292,123 @@ void cut_word_from_string(char* string, char* word) {
294292
} while (word_in_str[i++ + word_length] != 0);
295293
}
296294
}
297-
const GLubyte *hacked_glGetString(GLenum name) {
298-
if (name == GL_EXTENSIONS) {
299-
static GLubyte* extensions = NULL;
300-
301-
if (extensions == NULL) {
302-
GLubyte* orig_extensions = (GLubyte *) glGetString(GL_EXTENSIONS);
303-
size_t len_orig_extensions = strlen(orig_extensions);
304-
305-
extensions = malloc(len_orig_extensions+1);
306-
strcpy(extensions, orig_extensions);
307-
308-
/*
309-
* working (apparently)
310-
*/
311-
//cut_word_from_string(extensions, "GL_EXT_blend_minmax");
312-
//cut_word_from_string(extensions, "GL_EXT_multi_draw_arrays");
313-
//cut_word_from_string(extensions, "GL_EXT_texture_format_BGRA8888");
314-
//cut_word_from_string(extensions, "GL_OES_compressed_ETC1_RGB8_texture");
315-
//cut_word_from_string(extensions, "GL_OES_depth24");
316-
//cut_word_from_string(extensions, "GL_OES_texture_npot");
317-
//cut_word_from_string(extensions, "GL_OES_vertex_half_float");
318-
//cut_word_from_string(extensions, "GL_OES_EGL_image");
319-
//cut_word_from_string(extensions, "GL_OES_depth_texture");
320-
//cut_word_from_string(extensions, "GL_AMD_performance_monitor");
321-
//cut_word_from_string(extensions, "GL_OES_EGL_image_external");
322-
//cut_word_from_string(extensions, "GL_EXT_occlusion_query_boolean");
323-
//cut_word_from_string(extensions, "GL_KHR_texture_compression_astc_ldr");
324-
//cut_word_from_string(extensions, "GL_EXT_compressed_ETC1_RGB8_sub_texture");
325-
//cut_word_from_string(extensions, "GL_EXT_draw_elements_base_vertex");
326-
//cut_word_from_string(extensions, "GL_EXT_texture_border_clamp");
327-
//cut_word_from_string(extensions, "GL_OES_draw_elements_base_vertex");
328-
//cut_word_from_string(extensions, "GL_OES_texture_border_clamp");
329-
//cut_word_from_string(extensions, "GL_KHR_texture_compression_astc_sliced_3d");
330-
//cut_word_from_string(extensions, "GL_MESA_tile_raster_order");
331-
332-
/*
333-
* should be working, but isn't
334-
*/
335-
cut_word_from_string(extensions, "GL_EXT_map_buffer_range");
336-
337-
/*
338-
* definitely broken
339-
*/
340-
cut_word_from_string(extensions, "GL_OES_element_index_uint");
341-
cut_word_from_string(extensions, "GL_OES_fbo_render_mipmap");
342-
cut_word_from_string(extensions, "GL_OES_mapbuffer");
343-
cut_word_from_string(extensions, "GL_OES_rgb8_rgba8");
344-
cut_word_from_string(extensions, "GL_OES_stencil8");
345-
cut_word_from_string(extensions, "GL_OES_texture_3D");
346-
cut_word_from_string(extensions, "GL_OES_packed_depth_stencil");
347-
cut_word_from_string(extensions, "GL_OES_get_program_binary");
348-
cut_word_from_string(extensions, "GL_APPLE_texture_max_level");
349-
cut_word_from_string(extensions, "GL_EXT_discard_framebuffer");
350-
cut_word_from_string(extensions, "GL_EXT_read_format_bgra");
351-
cut_word_from_string(extensions, "GL_EXT_frag_depth");
352-
cut_word_from_string(extensions, "GL_NV_fbo_color_attachments");
353-
cut_word_from_string(extensions, "GL_OES_EGL_sync");
354-
cut_word_from_string(extensions, "GL_OES_vertex_array_object");
355-
cut_word_from_string(extensions, "GL_EXT_unpack_subimage");
356-
cut_word_from_string(extensions, "GL_NV_draw_buffers");
357-
cut_word_from_string(extensions, "GL_NV_read_buffer");
358-
cut_word_from_string(extensions, "GL_NV_read_depth");
359-
cut_word_from_string(extensions, "GL_NV_read_depth_stencil");
360-
cut_word_from_string(extensions, "GL_NV_read_stencil");
361-
cut_word_from_string(extensions, "GL_EXT_draw_buffers");
362-
cut_word_from_string(extensions, "GL_KHR_debug");
363-
cut_word_from_string(extensions, "GL_OES_required_internalformat");
364-
cut_word_from_string(extensions, "GL_OES_surfaceless_context");
365-
cut_word_from_string(extensions, "GL_EXT_separate_shader_objects");
366-
cut_word_from_string(extensions, "GL_KHR_context_flush_control");
367-
cut_word_from_string(extensions, "GL_KHR_no_error");
368-
cut_word_from_string(extensions, "GL_KHR_parallel_shader_compile");
369-
}
295+
const GLubyte *hacked_glGetString(GLenum name) {
296+
static GLubyte *extensions = NULL;
370297

371-
return extensions;
372-
} else {
298+
if (name != GL_EXTENSIONS)
373299
return glGetString(name);
374-
}
375-
}
376-
const GLubyte *hacked2_glGetString(GLenum name) {
377-
if (name == GL_EXTENSIONS) {
378-
static GLubyte* extensions = NULL;
379300

380-
// no extensions.
381-
return "";
382-
} else {
383-
return glGetString(name);
384-
}
385-
}
386-
void *proc_resolver(void* userdata, const char* name) {
387-
if (name == NULL) return NULL;
301+
if (extensions == NULL) {
302+
GLubyte *orig_extensions = (GLubyte *) glGetString(GL_EXTENSIONS);
303+
304+
extensions = malloc(strlen(orig_extensions) + 1);
305+
if (!extensions) {
306+
fprintf(stderr, "Could not allocate memory for modified GL_EXTENSIONS string\n");
307+
return NULL;
308+
}
388309

389-
static int is_videocore4 = -1;
390-
static int is_videocore6 = -1;
310+
strcpy(extensions, orig_extensions);
311+
312+
/*
313+
* working (apparently)
314+
*/
315+
//cut_word_from_string(extensions, "GL_EXT_blend_minmax");
316+
//cut_word_from_string(extensions, "GL_EXT_multi_draw_arrays");
317+
//cut_word_from_string(extensions, "GL_EXT_texture_format_BGRA8888");
318+
//cut_word_from_string(extensions, "GL_OES_compressed_ETC1_RGB8_texture");
319+
//cut_word_from_string(extensions, "GL_OES_depth24");
320+
//cut_word_from_string(extensions, "GL_OES_texture_npot");
321+
//cut_word_from_string(extensions, "GL_OES_vertex_half_float");
322+
//cut_word_from_string(extensions, "GL_OES_EGL_image");
323+
//cut_word_from_string(extensions, "GL_OES_depth_texture");
324+
//cut_word_from_string(extensions, "GL_AMD_performance_monitor");
325+
//cut_word_from_string(extensions, "GL_OES_EGL_image_external");
326+
//cut_word_from_string(extensions, "GL_EXT_occlusion_query_boolean");
327+
//cut_word_from_string(extensions, "GL_KHR_texture_compression_astc_ldr");
328+
//cut_word_from_string(extensions, "GL_EXT_compressed_ETC1_RGB8_sub_texture");
329+
//cut_word_from_string(extensions, "GL_EXT_draw_elements_base_vertex");
330+
//cut_word_from_string(extensions, "GL_EXT_texture_border_clamp");
331+
//cut_word_from_string(extensions, "GL_OES_draw_elements_base_vertex");
332+
//cut_word_from_string(extensions, "GL_OES_texture_border_clamp");
333+
//cut_word_from_string(extensions, "GL_KHR_texture_compression_astc_sliced_3d");
334+
//cut_word_from_string(extensions, "GL_MESA_tile_raster_order");
335+
336+
/*
337+
* should be working, but isn't
338+
*/
339+
cut_word_from_string(extensions, "GL_EXT_map_buffer_range");
340+
341+
/*
342+
* definitely broken
343+
*/
344+
cut_word_from_string(extensions, "GL_OES_element_index_uint");
345+
cut_word_from_string(extensions, "GL_OES_fbo_render_mipmap");
346+
cut_word_from_string(extensions, "GL_OES_mapbuffer");
347+
cut_word_from_string(extensions, "GL_OES_rgb8_rgba8");
348+
cut_word_from_string(extensions, "GL_OES_stencil8");
349+
cut_word_from_string(extensions, "GL_OES_texture_3D");
350+
cut_word_from_string(extensions, "GL_OES_packed_depth_stencil");
351+
cut_word_from_string(extensions, "GL_OES_get_program_binary");
352+
cut_word_from_string(extensions, "GL_APPLE_texture_max_level");
353+
cut_word_from_string(extensions, "GL_EXT_discard_framebuffer");
354+
cut_word_from_string(extensions, "GL_EXT_read_format_bgra");
355+
cut_word_from_string(extensions, "GL_EXT_frag_depth");
356+
cut_word_from_string(extensions, "GL_NV_fbo_color_attachments");
357+
cut_word_from_string(extensions, "GL_OES_EGL_sync");
358+
cut_word_from_string(extensions, "GL_OES_vertex_array_object");
359+
cut_word_from_string(extensions, "GL_EXT_unpack_subimage");
360+
cut_word_from_string(extensions, "GL_NV_draw_buffers");
361+
cut_word_from_string(extensions, "GL_NV_read_buffer");
362+
cut_word_from_string(extensions, "GL_NV_read_depth");
363+
cut_word_from_string(extensions, "GL_NV_read_depth_stencil");
364+
cut_word_from_string(extensions, "GL_NV_read_stencil");
365+
cut_word_from_string(extensions, "GL_EXT_draw_buffers");
366+
cut_word_from_string(extensions, "GL_KHR_debug");
367+
cut_word_from_string(extensions, "GL_OES_required_internalformat");
368+
cut_word_from_string(extensions, "GL_OES_surfaceless_context");
369+
cut_word_from_string(extensions, "GL_EXT_separate_shader_objects");
370+
cut_word_from_string(extensions, "GL_KHR_context_flush_control");
371+
cut_word_from_string(extensions, "GL_KHR_no_error");
372+
cut_word_from_string(extensions, "GL_KHR_parallel_shader_compile");
373+
}
374+
375+
return extensions;
376+
}
377+
void *proc_resolver(void* userdata, const char* name) {
378+
static int is_VC4 = -1;
379+
void *address;
391380

392381
/*
393382
* The mesa V3D driver reports some OpenGL ES extensions as supported and working
394383
* even though they aren't. hacked_glGetString is a workaround for this, which will
395384
* cut out the non-working extensions from the list of supported extensions.
396-
*/
385+
*/
397386

398-
if (is_videocore4 == -1) {
399-
is_videocore4 = strcmp(egl.renderer, "VC4 V3D 2.1") == 0;
400-
if (is_videocore4) printf("detected VideoCore IV as underlying graphics chip. Reporting modified GL_EXTENSIONS string that doesn't contain non-working extensions.\n");
401-
}
402-
if (is_videocore6 == -1) {
403-
is_videocore6 = strcmp(egl.renderer, "V3D 4.2") == 0;
404-
if (is_videocore6) printf("detected VideoCore VI as underlying graphics chip. Reporting no GL Extensions.\n");
405-
}
387+
if (name == NULL)
388+
return NULL;
406389

407-
if (strcmp(name, "glGetString") == 0) {
408-
if (is_videocore4) {
409-
return hacked_glGetString;
410-
} else if (is_videocore6) {
411-
return hacked2_glGetString;
412-
}
413-
}
390+
// first detect if we're running on a VideoCore 4 / using the VC4 driver.
391+
if ((is_VC4 == -1) && (is_VC4 = strcmp(egl.renderer, "VC4 V3D 2.1") == 0))
392+
printf( "detected VideoCore IV as underlying graphics chip, and VC4 as the driver.\n"
393+
"Reporting modified GL_EXTENSIONS string that doesn't contain non-working extensions.\n");
394+
395+
// if we do, and the symbol to resolve is glGetString, we return our hacked_glGetString.
396+
if (is_VC4 && (strcmp(name, "glGetString") == 0))
397+
return hacked_glGetString;
414398

415-
void* address;
416-
if ((address = dlsym(RTLD_DEFAULT, name)) || (address = eglGetProcAddress(name))) {
399+
if ((address = dlsym(RTLD_DEFAULT, name)) || (address = eglGetProcAddress(name)))
417400
return address;
418-
}
419401

420-
printf("could not resolve symbol %s\n", name);
402+
fprintf(stderr, "proc_resolver: could not resolve symbol \"%s\"\n", name);
421403

422404
return NULL;
423405
}
424-
void on_platform_message(const FlutterPlatformMessage* message, void* userdata) {
406+
void on_platform_message(const FlutterPlatformMessage* message, void* userdata) {
425407
int ok;
426408
if ((ok = PluginRegistry_onPlatformMessage((FlutterPlatformMessage *)message)) != 0)
427409
fprintf(stderr, "PluginRegistry_onPlatformMessage failed: %s\n", strerror(ok));
428410
}
429-
void vsync_callback(void* userdata, intptr_t baton) {
411+
void vsync_callback(void* userdata, intptr_t baton) {
430412
// not yet implemented
431413
fprintf(stderr, "flutter vsync callback not yet implemented\n");
432414
}
@@ -436,10 +418,8 @@ void vsync_callback(void* userdata, intptr_t baton) {
436418
/************************
437419
* PLATFORM TASK-RUNNER *
438420
************************/
439-
void handle_sigusr1(int _) {}
440421
bool init_message_loop() {
441422
platform_thread_id = pthread_self();
442-
443423
return true;
444424
}
445425
bool message_loop(void) {

0 commit comments

Comments
 (0)