1
0
Fork 0

cogl/cleanup: Use construct-only properties instead of a custom init function

It only made sense pre-GObjectified Texture types

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3193>
This commit is contained in:
Bilal Elmoussaoui 2023-09-18 18:41:38 +02:00 committed by Marge Bot
parent 863163cc6e
commit 1d47e809e4
7 changed files with 152 additions and 91 deletions

View file

@ -867,28 +867,25 @@ _cogl_atlas_texture_create_base (CoglContext *ctx,
CoglTextureLoader *loader)
{
CoglAtlasTexture *atlas_tex;
CoglTexture *tex;
COGL_NOTE (ATLAS, "Adding texture of size %ix%i", width, height);
/* We need to allocate the texture now because we need the pointer
to set as the data for the rectangle in the atlas */
atlas_tex = g_object_new (COGL_TYPE_ATLAS_TEXTURE, NULL);
atlas_tex = g_object_new (COGL_TYPE_ATLAS_TEXTURE,
"context", ctx,
"width", width,
"height", height,
"loader", loader,
"format", internal_format,
NULL);
/* Mark it as having no atlas so we don't try to unref it in
_cogl_atlas_texture_post_reorganize_cb */
atlas_tex->atlas = NULL;
tex = COGL_TEXTURE (atlas_tex);
_cogl_texture_init (tex,
ctx,
width, height,
internal_format,
loader);
atlas_tex->sub_texture = NULL;
atlas_tex->atlas = NULL;
return tex;
return COGL_TEXTURE (atlas_tex);
}
CoglTexture *

View file

@ -394,7 +394,6 @@ cogl_sub_texture_new (CoglContext *ctx,
{
CoglTexture *full_texture;
CoglSubTexture *sub_tex;
CoglTexture *tex;
unsigned int next_width, next_height;
next_width = cogl_texture_get_width (next_texture);
@ -406,13 +405,12 @@ cogl_sub_texture_new (CoglContext *ctx,
g_return_val_if_fail (sub_x + sub_width <= next_width, NULL);
g_return_val_if_fail (sub_y + sub_height <= next_height, NULL);
sub_tex = g_object_new (COGL_TYPE_SUB_TEXTURE, NULL);
tex = COGL_TEXTURE (sub_tex);
_cogl_texture_init (tex, ctx, sub_width, sub_height,
_cogl_texture_get_format (next_texture),
NULL);
sub_tex = g_object_new (COGL_TYPE_SUB_TEXTURE,
"context", ctx,
"width", sub_width,
"height", sub_height,
"format", _cogl_texture_get_format (next_texture),
NULL);
/* If the next texture is also a sub texture we can avoid one level
of indirection by referencing the full texture of that texture
@ -433,7 +431,7 @@ cogl_sub_texture_new (CoglContext *ctx,
sub_tex->sub_x = sub_x;
sub_tex->sub_y = sub_y;
return tex;
return COGL_TEXTURE (sub_tex);
}
CoglTexture *

View file

@ -1217,10 +1217,13 @@ _cogl_texture_2d_sliced_create_base (CoglContext *ctx,
CoglPixelFormat internal_format,
CoglTextureLoader *loader)
{
CoglTexture2DSliced *tex_2ds = g_object_new (COGL_TYPE_TEXTURE_2D_SLICED, NULL);
_cogl_texture_init (COGL_TEXTURE (tex_2ds), ctx, width, height,
internal_format, loader);
CoglTexture2DSliced *tex_2ds = g_object_new (COGL_TYPE_TEXTURE_2D_SLICED,
"context", ctx,
"width", width,
"height", height,
"loader", loader,
"format", internal_format,
NULL);
tex_2ds->max_waste = max_waste;

View file

@ -85,11 +85,13 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
CoglPixelFormat internal_format,
CoglTextureLoader *loader)
{
CoglTexture2D *tex_2d = g_object_new (COGL_TYPE_TEXTURE_2D, NULL);
CoglTexture *tex = COGL_TEXTURE (tex_2d);
_cogl_texture_init (tex, ctx, width, height, internal_format, loader);
CoglTexture2D *tex_2d = g_object_new (COGL_TYPE_TEXTURE_2D,
"context", ctx,
"width", width,
"height", height,
"loader", loader,
"format", internal_format,
NULL);
tex_2d->mipmaps_dirty = TRUE;
tex_2d->auto_mipmap = TRUE;
tex_2d->is_get_data_supported = TRUE;
@ -98,7 +100,7 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
ctx->driver_vtable->texture_2d_init (tex_2d);
return tex;
return COGL_TEXTURE (tex_2d);
}
static gboolean

View file

@ -240,15 +240,6 @@ struct _CoglTexturePixel
uint8_t data[4];
};
void
_cogl_texture_init (CoglTexture *texture,
CoglContext *ctx,
int width,
int height,
CoglPixelFormat src_format,
CoglTextureLoader *loader);
COGL_EXPORT gboolean
_cogl_texture_can_hardware_repeat (CoglTexture *texture);

View file

@ -62,6 +62,21 @@
G_DEFINE_ABSTRACT_TYPE (CoglTexture, cogl_texture, G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_CONTEXT,
PROP_WIDTH,
PROP_HEIGHT,
PROP_LOADER,
PROP_FORMAT,
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
static void
_cogl_texture_free_loader (CoglTexture *texture)
{
@ -93,12 +108,95 @@ cogl_texture_dispose (GObject *object)
G_OBJECT_CLASS (cogl_texture_parent_class)->dispose (object);
}
static void
cogl_texture_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
CoglTexture *texture = COGL_TEXTURE (gobject);
switch (prop_id)
{
case PROP_CONTEXT:
texture->context = g_value_get_object (value);
break;
case PROP_WIDTH:
texture->width = g_value_get_int (value);
break;
case PROP_HEIGHT:
texture->height = g_value_get_int (value);
break;
case PROP_LOADER:
texture->loader = g_value_get_pointer (value);
break;
case PROP_FORMAT:
_cogl_texture_set_internal_format (texture, g_value_get_uint (value));
/* Although we want to initialize texture::components according
* to the source format, we always want the internal layout to
* be considered premultiplied by default.
*
* NB: this ->premultiplied state is user configurable so to avoid
* awkward documentation, setting this to 'true' does not depend on
* ->components having an alpha component (we will simply ignore the
* premultiplied status later if there is no alpha component).
* This way we don't have to worry about updating the
* ->premultiplied state in _set_components(). Similarly we don't
* have to worry about updating the ->components state in
* _set_premultiplied().
*/
texture->premultiplied = TRUE;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
cogl_texture_class_init (CoglTextureClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = cogl_texture_dispose;
gobject_class->set_property = cogl_texture_set_property;
obj_props[PROP_CONTEXT] =
g_param_spec_object ("context", NULL, NULL,
COGL_TYPE_CONTEXT,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_WIDTH] =
g_param_spec_int ("width", NULL, NULL,
-1, G_MAXINT,
-1,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_HEIGHT] =
g_param_spec_int ("height", NULL, NULL,
-1, G_MAXINT,
-1,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_LOADER] =
g_param_spec_pointer ("loader", NULL, NULL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_FORMAT] =
g_param_spec_uint ("format", NULL, NULL,
COGL_PIXEL_FORMAT_ANY, G_MAXINT,
COGL_PIXEL_FORMAT_ANY,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class,
PROP_LAST,
obj_props);
}
static void
@ -116,36 +214,6 @@ cogl_texture_error_quark (void)
return g_quark_from_static_string ("cogl-texture-error-quark");
}
void
_cogl_texture_init (CoglTexture *texture,
CoglContext *context,
int width,
int height,
CoglPixelFormat src_format,
CoglTextureLoader *loader)
{
texture->context = context;
texture->width = width;
texture->height = height;
texture->loader = loader;
_cogl_texture_set_internal_format (texture, src_format);
/* Although we want to initialize texture::components according
* to the source format, we always want the internal layout to
* be considered premultiplied by default.
*
* NB: this ->premultiplied state is user configurable so to avoid
* awkward documentation, setting this to 'true' does not depend on
* ->components having an alpha component (we will simply ignore the
* premultiplied status later if there is no alpha component).
* This way we don't have to worry about updating the
* ->premultiplied state in _set_components(). Similarly we don't
* have to worry about updating the ->components state in
* _set_premultiplied().
*/
texture->premultiplied = TRUE;
}
CoglTextureLoader *
_cogl_texture_create_loader (void)
{

View file

@ -904,20 +904,20 @@ cogl_texture_pixmap_x11_error_quark (void)
}
static CoglTexture *
_cogl_texture_pixmap_x11_new (CoglContext *ctxt,
_cogl_texture_pixmap_x11_new (CoglContext *ctx,
uint32_t pixmap,
gboolean automatic_updates,
CoglTexturePixmapStereoMode stereo_mode,
GError **error)
{
CoglTexturePixmapX11 *tex_pixmap = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11, NULL);
Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
CoglTexturePixmapX11 *tex_pixmap;
Display *display = cogl_xlib_renderer_get_display (ctx->display->renderer);
Window pixmap_root_window;
int pixmap_x, pixmap_y;
unsigned int pixmap_width, pixmap_height;
unsigned int pixmap_border_width;
unsigned int pixmap_depth;
CoglPixelFormat internal_format;
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
XWindowAttributes window_attributes;
int damage_base;
const CoglWinsysVtable *winsys;
@ -925,9 +925,8 @@ _cogl_texture_pixmap_x11_new (CoglContext *ctxt,
if (!XGetGeometry (display, pixmap, &pixmap_root_window,
&pixmap_x, &pixmap_y,
&pixmap_width, &pixmap_height,
&pixmap_border_width, &tex_pixmap->depth))
&pixmap_border_width, &pixmap_depth))
{
g_free (tex_pixmap);
g_set_error_literal (error,
COGL_TEXTURE_PIXMAP_X11_ERROR,
COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
@ -937,14 +936,18 @@ _cogl_texture_pixmap_x11_new (CoglContext *ctxt,
/* Note: the detailed pixel layout doesn't matter here, we are just
* interested in RGB vs RGBA... */
internal_format = (tex_pixmap->depth >= 32
internal_format = (pixmap_depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height,
internal_format,
NULL);
tex_pixmap = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11,
"context", ctx,
"width", pixmap_width,
"height", pixmap_height,
"format", internal_format,
NULL);
tex_pixmap->depth = pixmap_depth;
tex_pixmap->pixmap = pixmap;
tex_pixmap->stereo_mode = stereo_mode;
tex_pixmap->left = NULL;
@ -977,7 +980,7 @@ _cogl_texture_pixmap_x11_new (CoglContext *ctxt,
Damage damage = XDamageCreate (display,
pixmap,
XDamageReportBoundingBox);
set_damage_object_internal (ctxt,
set_damage_object_internal (ctx,
tex_pixmap,
damage,
COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX);
@ -1002,7 +1005,7 @@ _cogl_texture_pixmap_x11_new (CoglContext *ctxt,
if (!tex_pixmap->use_winsys_texture)
tex_pixmap->winsys = NULL;
_cogl_texture_set_allocated (tex, internal_format,
_cogl_texture_set_allocated (COGL_TEXTURE (tex_pixmap), internal_format,
pixmap_width, pixmap_height);
return COGL_TEXTURE (tex_pixmap);
@ -1040,19 +1043,18 @@ cogl_texture_pixmap_x11_new_right (CoglTexturePixmapX11 *tfp_left)
g_return_val_if_fail (tfp_left->stereo_mode == COGL_TEXTURE_PIXMAP_LEFT, NULL);
tfp_right = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11, NULL);
tfp_right->stereo_mode = COGL_TEXTURE_PIXMAP_RIGHT;
tfp_right->left = g_object_ref (tfp_left);
internal_format = (tfp_left->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (COGL_TEXTURE (tfp_right),
cogl_texture_get_context (texture_left),
cogl_texture_get_width (texture_left),
cogl_texture_get_height (texture_left),
internal_format,
NULL);
tfp_right = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11,
"context", cogl_texture_get_context (texture_left),
"width", cogl_texture_get_width (texture_left),
"height", cogl_texture_get_height (texture_left),
"format", internal_format,
NULL);
tfp_right->stereo_mode = COGL_TEXTURE_PIXMAP_RIGHT;
tfp_right->left = g_object_ref (tfp_left);
_cogl_texture_set_allocated (COGL_TEXTURE (tfp_right), internal_format,
cogl_texture_get_width (texture_left),