1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
/*
* Copyright (C) 2019 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "clutter/clutter-paint-context-private.h"
#include "clutter/clutter-color-state.h"
#include "clutter/clutter-frame.h"
#include "clutter/clutter-stage-view-private.h"
struct _ClutterPaintContext
{
grefcount ref_count;
ClutterPaintFlag paint_flags;
GList *framebuffers;
ClutterStageView *view;
ClutterFrame *frame;
MtkRegion *redraw_clip;
GArray *clip_frusta;
GList *target_color_states;
GList *color_states;
ClutterColorState *framebuffer_color_state;
};
G_DEFINE_BOXED_TYPE (ClutterPaintContext, clutter_paint_context,
clutter_paint_context_ref,
clutter_paint_context_unref)
ClutterPaintContext *
clutter_paint_context_new_for_view (ClutterStageView *view,
const MtkRegion *redraw_clip,
GArray *clip_frusta,
ClutterPaintFlag paint_flags)
{
ClutterPaintContext *paint_context;
ClutterColorState *target_color_state;
CoglFramebuffer *framebuffer;
paint_context = g_new0 (ClutterPaintContext, 1);
g_ref_count_init (&paint_context->ref_count);
paint_context->view = view;
paint_context->redraw_clip = mtk_region_copy (redraw_clip);
paint_context->clip_frusta = g_array_ref (clip_frusta);
paint_context->paint_flags = paint_flags;
g_set_object (&paint_context->framebuffer_color_state,
clutter_stage_view_get_color_state (view));
target_color_state = paint_context->framebuffer_color_state;
clutter_paint_context_push_target_color_state (paint_context,
target_color_state);
framebuffer = clutter_stage_view_get_framebuffer (view);
clutter_paint_context_push_framebuffer (paint_context, framebuffer);
return paint_context;
}
/**
* clutter_paint_context_new_for_framebuffer: (skip)
*/
ClutterPaintContext *
clutter_paint_context_new_for_framebuffer (CoglFramebuffer *framebuffer,
const MtkRegion *redraw_clip,
ClutterPaintFlag paint_flags,
ClutterColorState *color_state)
{
ClutterPaintContext *paint_context;
ClutterColorState *target_color_state;
paint_context = g_new0 (ClutterPaintContext, 1);
g_ref_count_init (&paint_context->ref_count);
paint_context->paint_flags = paint_flags;
g_set_object (&paint_context->framebuffer_color_state, color_state);
target_color_state = paint_context->framebuffer_color_state;
clutter_paint_context_push_target_color_state (paint_context,
target_color_state);
if (redraw_clip)
paint_context->redraw_clip = mtk_region_copy (redraw_clip);
clutter_paint_context_push_framebuffer (paint_context, framebuffer);
return paint_context;
}
ClutterPaintContext *
clutter_paint_context_ref (ClutterPaintContext *paint_context)
{
g_ref_count_inc (&paint_context->ref_count);
return paint_context;
}
static void
clutter_paint_context_dispose (ClutterPaintContext *paint_context)
{
if (paint_context->framebuffer_color_state)
{
clutter_paint_context_pop_target_color_state (paint_context);
g_clear_object (&paint_context->framebuffer_color_state);
}
g_warn_if_fail (!paint_context->color_states);
g_warn_if_fail (!paint_context->target_color_states);
g_list_free_full (paint_context->framebuffers, g_object_unref);
paint_context->framebuffers = NULL;
g_clear_pointer (&paint_context->redraw_clip, mtk_region_unref);
g_clear_pointer (&paint_context->clip_frusta, g_array_unref);
g_clear_pointer (&paint_context->frame, clutter_frame_unref);
}
void
clutter_paint_context_unref (ClutterPaintContext *paint_context)
{
if (g_ref_count_dec (&paint_context->ref_count))
{
clutter_paint_context_dispose (paint_context);
g_free (paint_context);
}
}
void
clutter_paint_context_destroy (ClutterPaintContext *paint_context)
{
clutter_paint_context_dispose (paint_context);
clutter_paint_context_unref (paint_context);
}
void
clutter_paint_context_push_framebuffer (ClutterPaintContext *paint_context,
CoglFramebuffer *framebuffer)
{
paint_context->framebuffers = g_list_prepend (paint_context->framebuffers,
g_object_ref (framebuffer));
}
void
clutter_paint_context_pop_framebuffer (ClutterPaintContext *paint_context)
{
g_return_if_fail (paint_context->framebuffers);
g_object_unref (paint_context->framebuffers->data);
paint_context->framebuffers =
g_list_delete_link (paint_context->framebuffers,
paint_context->framebuffers);
}
const MtkRegion *
clutter_paint_context_get_redraw_clip (ClutterPaintContext *paint_context)
{
return paint_context->redraw_clip;
}
const GArray *
clutter_paint_context_get_clip_frusta (ClutterPaintContext *paint_context)
{
return paint_context->clip_frusta;
}
/**
* clutter_paint_context_get_framebuffer:
* @paint_context: The #ClutterPaintContext
*
* Returns: (transfer none): The #CoglFramebuffer used for drawing
*/
CoglFramebuffer *
clutter_paint_context_get_framebuffer (ClutterPaintContext *paint_context)
{
g_return_val_if_fail (paint_context->framebuffers, NULL);
return paint_context->framebuffers->data;
}
CoglFramebuffer *
clutter_paint_context_get_base_framebuffer (ClutterPaintContext *paint_context)
{
return g_list_last (paint_context->framebuffers)->data;
}
/**
* clutter_paint_context_get_stage_view: (skip)
*/
ClutterStageView *
clutter_paint_context_get_stage_view (ClutterPaintContext *paint_context)
{
return paint_context->view;
}
/**
* clutter_paint_context_is_drawing_off_stage: (skip)
*
* Return %TRUE if the paint context is currently drawing off stage.
* This happens if there are any framebuffers pushed, and the base framebuffer
* comes from the stage view.
*/
gboolean
clutter_paint_context_is_drawing_off_stage (ClutterPaintContext *paint_context)
{
if (g_list_length (paint_context->framebuffers) > 1)
return TRUE;
return !paint_context->view;
}
/**
* clutter_paint_context_get_paint_flags: (skip)
*/
ClutterPaintFlag
clutter_paint_context_get_paint_flags (ClutterPaintContext *paint_context)
{
return paint_context->paint_flags;
}
void
clutter_paint_context_assign_frame (ClutterPaintContext *paint_context,
ClutterFrame *frame)
{
g_assert (paint_context != NULL);
g_assert (paint_context->frame == NULL);
g_assert (frame != NULL);
paint_context->frame = clutter_frame_ref (frame);
}
/**
* clutter_paint_context_get_frame: (skip)
* @paint_context: The #ClutterPaintContext
*
* Retrieves the #ClutterFrame assigned to @paint_context, if any. A frame is
* only assigned when the paint context is created as part of a frame scheduled
* by the frame clock, and won't be assigned e.g. on offscreen paints.
*
* Returns: (transfer none)(nullable): The #ClutterFrame associated with the
* @paint_context, or %NULL
*/
ClutterFrame *
clutter_paint_context_get_frame (ClutterPaintContext *paint_context)
{
return paint_context->frame;
}
void
clutter_paint_context_push_target_color_state (ClutterPaintContext *paint_context,
ClutterColorState *color_state)
{
paint_context->target_color_states =
g_list_prepend (paint_context->target_color_states, color_state);
}
void
clutter_paint_context_pop_target_color_state (ClutterPaintContext *paint_context)
{
g_return_if_fail (paint_context->target_color_states);
paint_context->target_color_states =
g_list_delete_link (paint_context->target_color_states,
paint_context->target_color_states);
}
void
clutter_paint_context_push_color_state (ClutterPaintContext *paint_context,
ClutterColorState *color_state)
{
paint_context->color_states = g_list_prepend (paint_context->color_states,
color_state);
}
void
clutter_paint_context_pop_color_state (ClutterPaintContext *paint_context)
{
g_return_if_fail (paint_context->color_states);
paint_context->color_states =
g_list_delete_link (paint_context->color_states,
paint_context->color_states);
}
/**
* clutter_paint_context_get_target_color_state: (skip)
*/
ClutterColorState *
clutter_paint_context_get_target_color_state (ClutterPaintContext *paint_context)
{
return CLUTTER_COLOR_STATE (paint_context->target_color_states->data);
}
/**
* clutter_paint_context_get_color_state: (skip)
*/
ClutterColorState *
clutter_paint_context_get_color_state (ClutterPaintContext *paint_context)
{
g_return_val_if_fail (paint_context->color_states, NULL);
return CLUTTER_COLOR_STATE (paint_context->color_states->data);
}
|