inspector: Require toggling on/off of recording

This way, we don't eat up all your memory every time you start the
inspector.
This commit is contained in:
Benjamin Otte 2016-11-01 18:03:16 +01:00
parent 4673318028
commit 3741e6906e
3 changed files with 112 additions and 6 deletions

View File

@ -38,6 +38,8 @@ struct _GtkInspectorRecorderPrivate
GtkWidget *recordings_list;
GtkWidget *render_node_view;
GtkWidget *render_node_tree;
guint recording : 1;
};
enum {
@ -47,6 +49,15 @@ enum {
N_NODE_COLUMNS
};
enum
{
PROP_0,
PROP_RECORDING,
LAST_PROP
};
static GParamSpec *props[LAST_PROP] = { NULL, };
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorRecorder, gtk_inspector_recorder, GTK_TYPE_BIN)
static void
@ -132,10 +143,64 @@ gtk_inspector_recorder_recordings_list_create_widget (gpointer item,
return widget;
}
static void
gtk_inspector_recorder_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GtkInspectorRecorder *recorder = GTK_INSPECTOR_RECORDER (object);
GtkInspectorRecorderPrivate *priv = gtk_inspector_recorder_get_instance_private (recorder);
switch (param_id)
{
case PROP_RECORDING:
g_value_set_boolean (value, priv->recording);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_inspector_recorder_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GtkInspectorRecorder *recorder = GTK_INSPECTOR_RECORDER (object);
switch (param_id)
{
case PROP_RECORDING:
gtk_inspector_recorder_set_recording (recorder, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_inspector_recorder_class_init (GtkInspectorRecorderClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gtk_inspector_recorder_get_property;
object_class->set_property = gtk_inspector_recorder_set_property;
props[PROP_RECORDING] =
g_param_spec_boolean ("recording",
"Recording",
"Whether the recorder is currently recording",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/recorder.ui");
@ -170,6 +235,28 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
}
void
gtk_inspector_recorder_set_recording (GtkInspectorRecorder *recorder,
gboolean recording)
{
GtkInspectorRecorderPrivate *priv = gtk_inspector_recorder_get_instance_private (recorder);
if (priv->recording == recording)
return;
priv->recording = recording;
g_object_notify_by_pspec (G_OBJECT (recorder), props[PROP_RECORDING]);
}
gboolean
gtk_inspector_recorder_is_recording (GtkInspectorRecorder *recorder)
{
GtkInspectorRecorderPrivate *priv = gtk_inspector_recorder_get_instance_private (recorder);
return priv->recording;
}
void
gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
GtkWidget *widget,
@ -181,6 +268,9 @@ gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
GtkInspectorRecording *recording;
GdkFrameClock *frame_clock;
if (!gtk_inspector_recorder_is_recording (recorder))
return;
frame_clock = gtk_widget_get_frame_clock (widget);
recording = gtk_inspector_render_recording_new (gdk_frame_clock_get_frame_time (frame_clock),

View File

@ -42,13 +42,17 @@ typedef struct _GtkInspectorRecorderClass
G_BEGIN_DECLS
GType gtk_inspector_recorder_get_type (void);
GType gtk_inspector_recorder_get_type (void);
void gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
GtkWidget *widget,
GdkWindow *window,
const cairo_region_t *region,
GskRenderNode *node);
void gtk_inspector_recorder_set_recording (GtkInspectorRecorder *recorder,
gboolean record);
gboolean gtk_inspector_recorder_is_recording (GtkInspectorRecorder *recorder);
void gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
GtkWidget *widget,
GdkWindow *window,
const cairo_region_t *region,
GskRenderNode *node);
G_END_DECLS

View File

@ -7,6 +7,18 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<child>
<object class="GtkToggleButton">
<property name="visible">True</property>
<property name="icon-name">media-record</property>
<property name="active" bind-source="GtkInspectorRecorder" bind-property="recording" bind-flags="bidirectional|sync-create"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkPaned">
<property name="visible">True</property>