Example #1
0
static bool
parse_bool(const int32_t attrib_list[],
		   int32_t attrib_name,
		   bool *value,
		   bool default_value)
{
	int32_t raw_value;

	wcore_attrib_list_get_with_default(attrib_list, attrib_name,
                                       &raw_value, default_value);

	if (raw_value == WAFFLE_DONT_CARE) {
		*value = default_value;
	} else if (raw_value == true || raw_value == false) {
		*value = raw_value;
	} else {
		wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
					 "%s has bad value 0x%x. "
					 "Must be true(1), false(0), or WAFFLE_DONT_CARE(-1)",
					 wcore_enum_to_string(attrib_name), raw_value);
		return false;
	}

    return true;
}
Example #2
0
struct wcore_config*
nacl_config_choose(struct wcore_platform *wc_plat,
                  struct wcore_display *wc_dpy,
                  const struct wcore_config_attrs *attrs)
{
    struct nacl_config *self;
    bool ok = true;

    self = wcore_calloc(sizeof(*self));
    if (self == NULL)
        return NULL;

    // Currently only OpenGL ES 2.0 is supported.
    if (attrs->context_api != WAFFLE_CONTEXT_OPENGL_ES2) {
        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
                     "NaCl does no support context type %s.",
                     wcore_enum_to_string(attrs->context_api));
        goto error;
    }

    if (attrs->context_robust) {
        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
                     "NaCl does not support robust contexts.");
        goto error;
    }

    unsigned attr = 0;

    // Max amount of attribs is hardcoded in nacl_config.h (64)
#define PUSH_ATTRIB(a, val) \
    if (val != WAFFLE_DONT_CARE) {\
        self->attribs[attr++] = a; \
        self->attribs[attr++] = val;\
    }

    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_ALPHA_SIZE,     attrs->alpha_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_BLUE_SIZE,      attrs->blue_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_GREEN_SIZE,     attrs->green_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_RED_SIZE,       attrs->red_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_DEPTH_SIZE,     attrs->depth_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_STENCIL_SIZE,   attrs->stencil_size);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_SAMPLES,        attrs->samples);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, attrs->sample_buffers);

    // Note, we have to have at least 1x1 size so that initial context
    // backing surface creation will succeed without errors. Later on
    // it is resized by window creation/resize.
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_WIDTH,  1);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_HEIGHT, 1);
    PUSH_ATTRIB(PP_GRAPHICS3DATTRIB_NONE, 0);

#undef PUSH_ATTRIB

    ok = wcore_config_init(&self->wcore, wc_dpy, attrs);
    if (!ok)
        goto error;

    return &self->wcore;

error:
    nacl_config_destroy(&self->wcore);
    self = NULL;
    return NULL;
}