static EGLBoolean haiku_add_configs_for_visuals(_EGLDisplay *dpy) { printf("Adding configs\n"); struct haiku_egl_config* conf; conf = CALLOC_STRUCT(haiku_egl_config); _eglInitConfig(&conf->base, dpy, 1); _eglLog(_EGL_DEBUG,"Config inited\n"); _eglSetConfigKey(&conf->base, EGL_RED_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_BLUE_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_GREEN_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_LUMINANCE_SIZE, 0); _eglSetConfigKey(&conf->base, EGL_ALPHA_SIZE, 8); _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER); EGLint r = (_eglGetConfigKey(&conf->base, EGL_RED_SIZE) + _eglGetConfigKey(&conf->base, EGL_GREEN_SIZE) + _eglGetConfigKey(&conf->base, EGL_BLUE_SIZE) + _eglGetConfigKey(&conf->base, EGL_ALPHA_SIZE)); _eglSetConfigKey(&conf->base, EGL_BUFFER_SIZE, r); _eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, EGL_NONE); _eglSetConfigKey(&conf->base, EGL_CONFIG_ID, 1); _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE); _eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE); _eglSetConfigKey(&conf->base, EGL_STENCIL_SIZE, 0); _eglSetConfigKey(&conf->base, EGL_TRANSPARENT_TYPE, EGL_NONE); _eglSetConfigKey(&conf->base, EGL_NATIVE_RENDERABLE, EGL_TRUE); // Let's say yes _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID, 0); // No visual _eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE, EGL_NONE); // No visual _eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE, 0x8); _eglSetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_SAMPLES, _eglGetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0); _eglSetConfigKey(&conf->base, EGL_DEPTH_SIZE, 24); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_LEVEL, 0); _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_WIDTH, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_HEIGHT, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_PIXELS, 0); // TODO: How to get the right value ? _eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT /*| EGL_PIXMAP_BIT | EGL_PBUFFER_BIT*/); printf("Config configuated\n"); if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "Haiku failed to validate config"); return EGL_FALSE; } printf("Validated config\n"); _eglLinkConfig(&conf->base); if (!_eglGetArraySize(dpy->Configs)) { _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); return EGL_FALSE; } printf("Config successful!\n"); return EGL_TRUE; }
/** * Initialize a criteria config from the given attribute list. * Return EGL_FALSE if any of the attribute is invalid. */ EGLBoolean _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *dpy, const EGLint *attrib_list) { EGLint attr, val, i; _eglInitConfig(conf, dpy, EGL_DONT_CARE); /* reset to default values */ for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { attr = _eglValidationTable[i].attr; val = _eglValidationTable[i].default_value; _eglSetConfigKey(conf, attr, val); } /* parse the list */ for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i += 2) { attr = attrib_list[i]; val = attrib_list[i + 1]; if (!_eglIsConfigAttribValid(conf, attr)) return EGL_FALSE; _eglSetConfigKey(conf, attr, val); } if (!_eglValidateConfig(conf, EGL_TRUE)) return EGL_FALSE; /* EGL_LEVEL and EGL_MATCH_NATIVE_PIXMAP cannot be EGL_DONT_CARE */ if (conf->Level == EGL_DONT_CARE || conf->MatchNativePixmap == EGL_DONT_CARE) return EGL_FALSE; /* ignore other attributes when EGL_CONFIG_ID is given */ if (conf->ConfigID != EGL_DONT_CARE) { for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { attr = _eglValidationTable[i].attr; if (attr != EGL_CONFIG_ID) _eglSetConfigKey(conf, attr, EGL_DONT_CARE); } } else { if (!(conf->SurfaceType & EGL_WINDOW_BIT)) conf->NativeVisualType = EGL_DONT_CARE; if (conf->TransparentType == EGL_NONE) { conf->TransparentRedValue = EGL_DONT_CARE; conf->TransparentGreenValue = EGL_DONT_CARE; conf->TransparentBlueValue = EGL_DONT_CARE; } } return EGL_TRUE; }
static EGLBoolean convert_config(_EGLConfig *conf, EGLint id, const __GLcontextModes *m) { static const EGLint all_apis = (EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT | EGL_OPENGL_BIT); EGLint val; _eglInitConfig(conf, id); if (!_eglConfigFromContextModesRec(conf, m, all_apis, all_apis)) return EGL_FALSE; if (m->doubleBufferMode) { /* pixmap and pbuffer surfaces are always single-buffered */ val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); val &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, val); } else { /* EGL requires OpenGL ES context to be double-buffered */ val = GET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE); val &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT); SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, val); } /* skip "empty" config */ if (!val) return EGL_FALSE; val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); if (!(val & EGL_PBUFFER_BIT)) { /* bind-to-texture cannot be EGL_TRUE without pbuffer bit */ SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, EGL_FALSE); SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, EGL_FALSE); } /* EGL_NATIVE_RENDERABLE is a boolean */ val = GET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE); if (val != EGL_TRUE) SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, EGL_FALSE); return _eglValidateConfig(conf, EGL_FALSE); }
struct dri2_egl_config * dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, int depth, EGLint surface_type, const EGLint *attr_list, const unsigned int *rgba_masks) { struct dri2_egl_config *conf; struct dri2_egl_display *dri2_dpy; _EGLConfig base; unsigned int attrib, value, double_buffer; EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; unsigned int dri_masks[4] = { 0, 0, 0, 0 }; _EGLConfig *matching_config; EGLint num_configs = 0; EGLint config_id; int i; dri2_dpy = disp->DriverData; _eglInitConfig(&base, disp, id); i = 0; double_buffer = 0; bind_to_texture_rgb = 0; bind_to_texture_rgba = 0; while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { switch (attrib) { case __DRI_ATTRIB_RENDER_TYPE: if (value & __DRI_ATTRIB_RGBA_BIT) value = EGL_RGB_BUFFER; else if (value & __DRI_ATTRIB_LUMINANCE_BIT) value = EGL_LUMINANCE_BUFFER; else /* not valid */; _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); break; case __DRI_ATTRIB_CONFIG_CAVEAT: if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) value = EGL_NON_CONFORMANT_CONFIG; else if (value & __DRI_ATTRIB_SLOW_BIT) value = EGL_SLOW_CONFIG; else value = EGL_NONE; _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); break; case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: bind_to_texture_rgb = value; break; case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: bind_to_texture_rgba = value; break; case __DRI_ATTRIB_DOUBLE_BUFFER: double_buffer = value; break; case __DRI_ATTRIB_RED_MASK: dri_masks[0] = value; break; case __DRI_ATTRIB_GREEN_MASK: dri_masks[1] = value; break; case __DRI_ATTRIB_BLUE_MASK: dri_masks[2] = value; break; case __DRI_ATTRIB_ALPHA_MASK: dri_masks[3] = value; break; default: key = dri2_to_egl_attribute_map[attrib]; if (key != 0) _eglSetConfigKey(&base, key, value); break; } } if (attr_list) for (i = 0; attr_list[i] != EGL_NONE; i += 2) _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); if (depth > 0 && depth != base.BufferSize) return NULL; if (rgba_masks && memcmp(rgba_masks, dri_masks, sizeof(dri_masks))) return NULL; base.NativeRenderable = EGL_TRUE; base.SurfaceType = surface_type; if (surface_type & (EGL_PBUFFER_BIT | (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { base.BindToTextureRGB = bind_to_texture_rgb; if (base.AlphaSize > 0) base.BindToTextureRGBA = bind_to_texture_rgba; } base.RenderableType = disp->ClientAPIs; base.Conformant = disp->ClientAPIs; if (!_eglValidateConfig(&base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); return NULL; } config_id = base.ConfigID; base.ConfigID = EGL_DONT_CARE; base.SurfaceType = EGL_DONT_CARE; num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, (_EGLArrayForEach) dri2_match_config, &base); if (num_configs == 1) { conf = (struct dri2_egl_config *) matching_config; if (double_buffer && !conf->dri_double_config) conf->dri_double_config = dri_config; else if (!double_buffer && !conf->dri_single_config) conf->dri_single_config = dri_config; else /* a similar config type is already added (unlikely) => discard */ return NULL; } else if (num_configs == 0) { conf = malloc(sizeof *conf); if (conf == NULL) return NULL; memcpy(&conf->base, &base, sizeof base); if (double_buffer) { conf->dri_double_config = dri_config; conf->dri_single_config = NULL; } else { conf->dri_single_config = dri_config; conf->dri_double_config = NULL; } conf->base.SurfaceType = 0; conf->base.ConfigID = config_id; _eglLinkConfig(&conf->base); } else { assert(0); return NULL; } if (double_buffer) { surface_type &= ~EGL_PIXMAP_BIT; if (dri2_dpy->swap_available) { conf->base.MinSwapInterval = 0; conf->base.MaxSwapInterval = 1000; /* XXX arbitrary value */ } } conf->base.SurfaceType |= surface_type; return conf; }
/** * Initialize and validate the EGL config attributes. */ static EGLBoolean init_config_attributes(_EGLConfig *conf, const struct native_config *nconf, EGLint api_mask, enum pipe_format depth_stencil_format, EGLint preserve_buffer, EGLint max_swap_interval, EGLBoolean pre_alpha) { uint rgba[4], depth_stencil[2], buffer_size; EGLint surface_type; EGLint i; /* get the color and depth/stencil component sizes */ assert(nconf->color_format != PIPE_FORMAT_NONE); buffer_size = 0; for (i = 0; i < 4; i++) { rgba[i] = util_format_get_component_bits(nconf->color_format, UTIL_FORMAT_COLORSPACE_RGB, i); buffer_size += rgba[i]; } for (i = 0; i < 2; i++) { if (depth_stencil_format != PIPE_FORMAT_NONE) { depth_stencil[i] = util_format_get_component_bits(depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, i); } else { depth_stencil[i] = 0; } } surface_type = 0x0; /* pixmap surfaces should be EGL_SINGLE_BUFFER */ if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_LEFT)) { if (nconf->pixmap_bit) surface_type |= EGL_PIXMAP_BIT; } /* the others surfaces should be EGL_BACK_BUFFER (or settable) */ if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) { if (nconf->window_bit) surface_type |= EGL_WINDOW_BIT; #ifdef EGL_MESA_screen_surface if (nconf->scanout_bit) surface_type |= EGL_SCREEN_BIT_MESA; #endif surface_type |= EGL_PBUFFER_BIT; } if (preserve_buffer) surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; if (pre_alpha && rgba[3]) { surface_type |= EGL_VG_ALPHA_FORMAT_PRE_BIT; /* st/vega does not support premultiplied alpha yet */ api_mask &= ~EGL_OPENVG_BIT; } conf->Conformant = api_mask; conf->RenderableType = api_mask; conf->RedSize = rgba[0]; conf->GreenSize = rgba[1]; conf->BlueSize = rgba[2]; conf->AlphaSize = rgba[3]; conf->BufferSize = buffer_size; conf->DepthSize = depth_stencil[0]; conf->StencilSize = depth_stencil[1]; /* st/vega will allocate the mask on demand */ if (api_mask & EGL_OPENVG_BIT) conf->AlphaMaskSize = 8; conf->SurfaceType = surface_type; conf->NativeRenderable = EGL_TRUE; if (surface_type & EGL_WINDOW_BIT) { conf->NativeVisualID = nconf->native_visual_id; conf->NativeVisualType = nconf->native_visual_type; } if (surface_type & EGL_PBUFFER_BIT) { conf->BindToTextureRGB = EGL_TRUE; if (rgba[3]) conf->BindToTextureRGBA = EGL_TRUE; conf->MaxPbufferWidth = 4096; conf->MaxPbufferHeight = 4096; conf->MaxPbufferPixels = 4096 * 4096; } conf->Level = nconf->level; if (nconf->transparent_rgb) { conf->TransparentType = EGL_TRANSPARENT_RGB; conf->TransparentRedValue = nconf->transparent_rgb_values[0]; conf->TransparentGreenValue = nconf->transparent_rgb_values[1]; conf->TransparentBlueValue = nconf->transparent_rgb_values[2]; } conf->MinSwapInterval = 0; conf->MaxSwapInterval = max_swap_interval; return _eglValidateConfig(conf, EGL_FALSE); }
static void dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, int depth, xcb_visualtype_t *visual) { struct dri2_egl_config *conf; struct dri2_egl_display *dri2_dpy; _EGLConfig base; unsigned int attrib, value, double_buffer; EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; int i; dri2_dpy = disp->DriverData; _eglInitConfig(&base, disp, id); i = 0; while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { switch (attrib) { case __DRI_ATTRIB_RENDER_TYPE: if (value & __DRI_ATTRIB_RGBA_BIT) value = EGL_RGB_BUFFER; else if (value & __DRI_ATTRIB_LUMINANCE_BIT) value = EGL_LUMINANCE_BUFFER; else /* not valid */; _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); break; case __DRI_ATTRIB_CONFIG_CAVEAT: if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) value = EGL_NON_CONFORMANT_CONFIG; else if (value & __DRI_ATTRIB_SLOW_BIT) value = EGL_SLOW_CONFIG; else value = EGL_NONE; _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); break; case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: bind_to_texture_rgb = value; break; case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: bind_to_texture_rgba = value; break; case __DRI_ATTRIB_DOUBLE_BUFFER: double_buffer = value; break; default: key = dri2_to_egl_attribute_map[attrib]; if (key != 0) _eglSetConfigKey(&base, key, value); break; } } /* In EGL, double buffer or not isn't a config attribute. Pixmaps * surfaces are always single buffered, pbuffer surfaces are always * back buffers and windows can be either, selected by passing an * attribute at window surface construction time. To support this * we ignore all double buffer configs and manipulate the buffer we * return in the getBuffer callback to get the behaviour we want. */ if (double_buffer) return; if (visual != NULL) { if (depth != _eglGetConfigKey(&base, EGL_BUFFER_SIZE)) return; _eglSetConfigKey(&base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT); _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_ID, visual->visual_id); _eglSetConfigKey(&base, EGL_NATIVE_VISUAL_TYPE, visual->_class); } else { _eglSetConfigKey(&base, EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); } _eglSetConfigKey(&base, EGL_NATIVE_RENDERABLE, EGL_TRUE); _eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGB, bind_to_texture_rgb); if (_eglGetConfigKey(&base, EGL_ALPHA_SIZE) > 0) _eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGBA, bind_to_texture_rgba); /* EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT, EGL_OPENGL_ES2_BIT */ _eglSetConfigKey(&base, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT); _eglSetConfigKey(&base, EGL_CONFORMANT, EGL_OPENGL_BIT); if (!_eglValidateConfig(&base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); return; } conf = malloc(sizeof *conf); if (conf != NULL) { memcpy(&conf->base, &base, sizeof base); conf->dri_config = dri_config; _eglAddConfig(disp, &conf->base); } }
/** * Initialize a criteria config from the given attribute list. * Return EGL_FALSE if any of the attribute is invalid. */ EGLBoolean _eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list) { EGLint attr, val, i; EGLint config_id = 0, level = 0; EGLBoolean has_native_visual_type = EGL_FALSE; EGLBoolean has_transparent_color = EGL_FALSE; /* reset to default values */ for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { attr = _eglValidationTable[i].attr; val = _eglValidationTable[i].default_value; SET_CONFIG_ATTRIB(conf, attr, val); } /* parse the list */ for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i += 2) { EGLint idx; attr = attrib_list[i]; val = attrib_list[i + 1]; idx = _eglIndexConfig(conf, attr); if (idx < 0) return EGL_FALSE; conf->Storage[idx] = val; /* rememeber some attributes for post-processing */ switch (attr) { case EGL_CONFIG_ID: config_id = val; break; case EGL_LEVEL: level = val; break; case EGL_NATIVE_VISUAL_TYPE: has_native_visual_type = EGL_TRUE; break; case EGL_TRANSPARENT_RED_VALUE: case EGL_TRANSPARENT_GREEN_VALUE: case EGL_TRANSPARENT_BLUE_VALUE: has_transparent_color = EGL_TRUE; break; default: break; } } if (!_eglValidateConfig(conf, EGL_TRUE)) return EGL_FALSE; /* the spec says that EGL_LEVEL cannot be EGL_DONT_CARE */ if (level == EGL_DONT_CARE) return EGL_FALSE; /* ignore other attributes when EGL_CONFIG_ID is given */ if (config_id > 0) { _eglResetConfigKeys(conf, EGL_DONT_CARE); SET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID, config_id); } else { if (has_native_visual_type) { val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE); if (!(val & EGL_WINDOW_BIT)) SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE); } if (has_transparent_color) { val = GET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE); if (val == EGL_NONE) { SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE); SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE); SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE); } } } return EGL_TRUE; }