framebuffer: if size unknown; allocate for size/vp queries
This ensures framebuffers are implicitly allocated when querying the width, height or viewport width/height if the framebuffer's size is currently unknown. The plan is to allow texture backends to defer calculating the size of textures until they are allocated which in turn means we won't know the size of offscreen framebuffers until the texture has been allocated. Potentially we could be more specific about this in the future and only ensure the texture is allocated, but for now it will be simplest to just ensure the framebuffer is allocated. Note: in the case of onscreen buffers which are always initialized with a requested size we are careful to avoid triggering an allocation when this is queried otherwise we will see recursion when the winsys code queries the requested size during allocation. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f4b612f1b75e043f1852b9a32368cc37ab89308b)
This commit is contained in:
parent
a07d26e9ae
commit
08ba5c64b9
@ -451,15 +451,43 @@ cogl_framebuffer_clear (CoglFramebuffer *framebuffer,
|
|||||||
cogl_color_get_alpha_float (color));
|
cogl_color_get_alpha_float (color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We will lazily allocate framebuffers if necessary when querying
|
||||||
|
* their size/viewport but note we need to be careful in the case of
|
||||||
|
* onscreen framebuffers that are instantiated with an initial request
|
||||||
|
* size that we don't trigger an allocation when this is queried since
|
||||||
|
* that would lead to a recursion when the winsys backend queries this
|
||||||
|
* requested size during allocation. */
|
||||||
|
static void
|
||||||
|
ensure_size_initialized (CoglFramebuffer *framebuffer)
|
||||||
|
{
|
||||||
|
/* In the case of offscreen framebuffers backed by a texture then
|
||||||
|
* until that texture has been allocated we might not know the size
|
||||||
|
* of the framebuffer */
|
||||||
|
if (framebuffer->width < 0)
|
||||||
|
{
|
||||||
|
/* Currently we assume the size is always initialized for
|
||||||
|
* onscreen framebuffers. */
|
||||||
|
_COGL_RETURN_IF_FAIL (cogl_is_offscreen (framebuffer));
|
||||||
|
|
||||||
|
/* We also assume the size would have been initialized if the
|
||||||
|
* framebuffer were allocated. */
|
||||||
|
_COGL_RETURN_IF_FAIL (!framebuffer->allocated);
|
||||||
|
|
||||||
|
cogl_framebuffer_allocate (framebuffer, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cogl_framebuffer_get_width (CoglFramebuffer *framebuffer)
|
cogl_framebuffer_get_width (CoglFramebuffer *framebuffer)
|
||||||
{
|
{
|
||||||
|
ensure_size_initialized (framebuffer);
|
||||||
return framebuffer->width;
|
return framebuffer->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cogl_framebuffer_get_height (CoglFramebuffer *framebuffer)
|
cogl_framebuffer_get_height (CoglFramebuffer *framebuffer)
|
||||||
{
|
{
|
||||||
|
ensure_size_initialized (framebuffer);
|
||||||
return framebuffer->height;
|
return framebuffer->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,12 +555,14 @@ cogl_framebuffer_get_viewport_y (CoglFramebuffer *framebuffer)
|
|||||||
float
|
float
|
||||||
cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer)
|
cogl_framebuffer_get_viewport_width (CoglFramebuffer *framebuffer)
|
||||||
{
|
{
|
||||||
|
ensure_size_initialized (framebuffer);
|
||||||
return framebuffer->viewport_width;
|
return framebuffer->viewport_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer)
|
cogl_framebuffer_get_viewport_height (CoglFramebuffer *framebuffer)
|
||||||
{
|
{
|
||||||
|
ensure_size_initialized (framebuffer);
|
||||||
return framebuffer->viewport_height;
|
return framebuffer->viewport_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,6 +570,8 @@ void
|
|||||||
cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer,
|
cogl_framebuffer_get_viewport4fv (CoglFramebuffer *framebuffer,
|
||||||
float *viewport)
|
float *viewport)
|
||||||
{
|
{
|
||||||
|
ensure_size_initialized (framebuffer);
|
||||||
|
|
||||||
viewport[0] = framebuffer->viewport_x;
|
viewport[0] = framebuffer->viewport_x;
|
||||||
viewport[1] = framebuffer->viewport_y;
|
viewport[1] = framebuffer->viewport_y;
|
||||||
viewport[2] = framebuffer->viewport_width;
|
viewport[2] = framebuffer->viewport_width;
|
||||||
|
Loading…
Reference in New Issue
Block a user