Commit Graph

50 Commits

Author SHA1 Message Date
Timm Bäder
4cfac3b91c snapshot: Remove new_with_parent
Unneeded now that we have push_collect()/pop_collect()
2020-02-07 13:16:32 -05:00
Timm Bäder
bf8fb2c1a5 snapshot: Add _push_collect() and _pop_collect()
These will replace the previous gtk_snapshot_new_with_parent(), which
allocated an entirely new GObject just to push()/pop() some state. This
is already a problem but will be more important in the future as we
start using this more.
2020-02-07 13:16:32 -05:00
Timm Bäder
ffab342fc4 snapshot: Stop exporting _append_node_internal
Unused outside of gtksnapshot.c
2019-09-09 17:36:23 +02:00
Benjamin Otte
b391aea2b3 widget: Make transform a GskTransform
This concludes pushing transforms down into GskTransform.

What's remaining is potentially pushing it further into the renderers.
2019-03-04 23:41:51 +01:00
Benjamin Otte
3cc84d2860 transform: Make category public API
Also rename it from GskMatrixCategory to GskTransformCategory.
2019-03-04 23:15:24 +01:00
Benjamin Otte
3a3c2d14ab rendernode: Make the transform node take a GskTransform
This is an attempt to push GskTransform deeper into the stack.
2019-03-04 23:15:07 +01:00
Benjamin Otte
0e1a50366a transform: Move to GSK
The renaming of the prefix makes this a large patch.
2019-03-04 23:09:02 +01:00
Benjamin Otte
4052bb2535 snapshot: Remove the old APIs
It's all using transforms now.
2019-02-21 19:47:28 +01:00
Benjamin Otte
51fac44ba5 snapshot: Introduce transform APIs
Instead of gtk_snapshot_offset(), provide a full set of functions
kept in sync with GtkTransform APIs.

On top of that, add gtk_snapshot_save() and gtk_snapshot_restore()
mirroring cairo_save()/restore() that allow saving a snapshot's
transform state.
2019-02-21 19:47:28 +01:00
Benjamin Otte
0d119f81c8 snapshot: Refactor text rendering
The code didn't change, it was just shuffled around to make the
with_bounds() versions of the text rendering unnecessary and instead
pass through the generic append_node() path.
2019-02-21 19:47:28 +01:00
Benjamin Otte
4a293aa762 snapshot: Store an actual GtkTransform
Instead of just tracking 2 integer translate_x/y coordinates, tracka a
full GtkTransform.

When creating actual nodes, if the transform is simple enough, just
create the node in a way that makes use of the transform. If the
node, can't represent the transform, just push a transform node instead
and automatically pop that node with the next gtk_snapshot_pop() call.
2019-02-21 19:47:28 +01:00
Benjamin Otte
f5b44c11c8 widget: Store category of widget transform
And pass that category through to the transform node that we create for
it.
2019-02-21 19:47:28 +01:00
Timm Bäder
cf1526cca6 snapshot: Add gtk_snapshot_from_parent
Most of the time, the GtkSnapshot objects we create while snapshotting
widgets don't end up containing all that many nodes or states in their
respective node or state stack. This undermines the amortized allocation
behavior of the G(Ptr)Array we use for the stacks. So instead, use the
(until now unused) parent_snapshot GtkSnapshot* passed to
gtk_widget_create_render_node and reuse its node and state stack.

We do not avoid allocating a new GtkSnapshot object, but we do avoid
allocating a ton of G(Ptr)Array objects and we also avoid realloc'ing
their storage.
2019-01-16 19:01:40 +01:00
Benjamin Otte
0b1f0984f5 Revert "Use aligned allocators for GtkSnapshot"
This reverts commit c02bc22cc5.

This code is not necessary.
The bug causing this problem ws prsent in the graphene library.
2018-06-19 19:52:52 +02:00
Mohammed Sadiq
d4693b2dc8 snapshot: Trivial typo fix in comment 2018-06-13 19:58:01 +05:30
Руслан Ижбулатов
c02bc22cc5 Use aligned allocators for GtkSnapshot
Any data that is later fed to graphene must be
allocated with proper alignment, if graphene
uses SSE2 or GCC vector instructions.

This adds custom array code (a streamlined copy
of GArray with all unnecessary bells and whistles removed),
which is then used for the state_stack instead of GArray.

There's also a runtime check for the size of GtkSnapshotState
itself being a multiple of 16. If that is not so, any array
elements past the 0th element will lose alignment.
There are probably struct attributes that can
make GtkSnapshotState always have size that is a multiple
of 16, but we'll burn that bridge if we cross it.
2018-06-10 20:35:54 +00:00
Benjamin Otte
1e0eed79b5 snapshot: Get rid of record_nodes flag
Instead, use GTK_DEBUG=snapshot for it.
2018-04-24 04:06:58 +02:00
Benjamin Otte
73b4a62f51 snapshot: Redo debug messages
Instead of every snapshot function having debug messages, have an
explicit gtk_snapshot_push_debug() function that appends a debug node.
2018-04-24 04:06:58 +02:00
Benjamin Otte
2db43edbd6 snapshot: Don't handle clip anymore
If widgets want to clip things, they now need to do it themselves.

By not taking care of clip, we avoid the need to track clip. And by not
tracking clip, we can avoid all unnecessary cache invalidations that we
were doing for render nodes whenever the clip changed.

And when you are scrolling, the clip changes *a lot*.
2018-04-17 23:21:37 +02:00
Benjamin Otte
4bf90633ea widget: Cache clip from creating render node
When the clip changes that is passed to a snapshot function, we need to
create eventual cached render nodes because they might not have drawn
their whole area before.

Fixes issues with redrawing when scrolling.
2018-04-05 14:56:38 +02:00
Benjamin Otte
278ab3c4de snapshot: Track clip as a rect only 2018-04-05 14:56:38 +02:00
Benjamin Otte
29111a16d4 widget: Cache the render node
This requires a bunch of refactorings:

1. Don't pass the current clip region to gtk_widget_snapshot()
   so we don't create full widget contents
3. Have a widget->priv->draw_needed that we invalidate on every
   queue_draw() call and set on every snapshot()
2. In queue_draw(), walk the widget chain to invalidate the
   render nodes of all parents
2018-04-05 14:56:38 +02:00
Benjamin Otte
e6d24f4c15 snapshot: Make gtk_snapshot_append_node() take care of offset
Push an offset node when append_node is called. That resets the offset.
2018-03-26 18:16:36 +02:00
Benjamin Otte
1cfa88ed91 snapshot: Remove renderer
Now that there's no longer a need to keep the renderer around for Cairo
rendering, don't do that then.
2018-03-24 21:57:20 +01:00
Benjamin Otte
ea84e974e6 snapshot: Turn into GObject
This makes GdkSnapshot the base class for GtkSnapshot and hopefully
stops confusing bindings.

C code should see no difference to before.
2018-03-18 19:21:33 +01:00
Benjamin Otte
d4764cc89b snapshot: "Inherit" from GdkSnapshot
This is a neat trick to get around the circularity between GDK, GSK and
GTK that we inherit with the GdkPaintable interface.

GdkPaintable uses GtkSnapshot
GtkSnapshot creates GskRenderNodes
GskRenderNodes use GdkTextures
GdkTexture will soon implement GdkPaintable

This causes a loop that spans GDK, GSK and GTK and this is the easiest
way to resolve it without breaking bindings (at least that's the idea).
2018-03-16 06:04:44 +01:00
Matthias Clasen
7c18911c00 GtkSnapshot: Add getters
These getters can be useful when creating new snapshots
in a snapshot() vfunc.
2018-03-11 00:31:44 -05:00
Matthias Clasen
eed279ad91 GtkSnapshot: Drop init/finish
We are ont using stack-allocated snapshots anymore.
2018-03-11 00:31:44 -05:00
Matthias Clasen
e23f641e49 GtkSnapshot: Implement the builder pattern
Make GtkSnapshot a refcounted boxed type, and add
public API that follows the builder pattern described
here: https://blogs.gnome.org/otte/2018/02/03/builders/
2018-03-11 00:31:44 -05:00
Timm Bäder
f5297e6f4b snapshot: Use one GPtrArray for all nodes
Instead of creating one GPtrArray per GtkSnapshotState and saving nodes
in there, create one GPtrArray per snapshot and assign a
start_node_index to every GtkSnapshotState as well as a n_nodes variable
so every state knows which nodes belong to it.
2017-10-02 14:34:47 +02:00
Timm Bäder
8e59b3b387 snapshot: Use one large GArray for all states
Allocating all of them separately shows up in profiles.
2017-10-02 14:34:47 +02:00
Matthias Clasen
d6be42203b Add gtk_snapshot_push_blur()
This function is similar to the other push functions.
This one uses the newly created blur node.
2017-09-04 14:28:16 -04:00
Benjamin Otte
bc3ba68641 snapshot: Add gtk_snapshot_push_blend()
and use it for backgrounds.
2017-01-13 03:38:36 +01:00
Benjamin Otte
d9b0685b49 Add gtk_snapshot_push_cross_fade()
... and use it.

The function is a bit awkward because it requires 2 calls to
gtk_snapshot_pop(), but once you accept that, it's very convenient to
use, as can be seen by the 2 implementations.
2017-01-13 03:38:36 +01:00
Alexander Larsson
c00f8dce9f GtkSnapshot: Always use int for the translation
We already take ints when setting the translation, so it can't
currently take any other values. Additionally, I was seeing large
costs in int -> double -> int for the rects in
gtk_snapshot_clips_rect(), as all callers really are ints (widget
allocations) and the clip region is int-based.

This change completely cleared a 2% rectangle_init_from_graphene from
the profile and is likely to have nice performance effects elsewhere
too.
2017-01-11 16:14:03 +01:00
Alexander Larsson
6341fab985 GtkSnapshot: Reuse snapshot state objects
Rather than allocate new ones all the time we reuse the previous ones.
We just clear them and save them in the parent for later reuse.
2017-01-11 11:41:46 +01:00
Alexander Larsson
f67ae85b7a GtkSnapshot: Move collect data to a union in the state
This means we allocate the collect data with the state, avoiding
an extra allocation. Also, a union means every state object
is the same size and we could reuse the state objects.
2017-01-11 11:21:27 +01:00
Alexander Larsson
65ad2541d7 Snapshot: Only record names if inspector is recording
Otherwise we do a lot of allocations and vprintf calls which are
not used.
2017-01-11 10:22:40 +01:00
Benjamin Otte
1137483d15 snapshot: Work on pushing and popping again
It is now possible to call push() subfunctions for simple container
nodes with just a single child. So you can for example
gtk_snapshot_push_clip() a clip region that all the nodes that get
appended later will then obey.

gtk_snapshot_pop() will then not return a container node, but a clip
node containing the container node (and similar for the transform
example).

This is implemented internally by providing a "collect function" when
pushing that is called when popping to collects all the accumulated
nodes and combine them into the single node that gets returned.

To simplify things even more, gtk_snapshot_pop_and_append() has been
added, which pops the currently pushed node and appends it to the
parent.

The icon rendering code has been converted to this approach.
2016-12-20 18:01:10 +01:00
Benjamin Otte
c258ee403a snapshot: Make gtk_snapshot_get_renderer() private
Public API doesn't need to be concerned with renderers. Worst case, they
can use NULL instead of the actual renderer.
2016-12-20 18:01:10 +01:00
Benjamin Otte
02131d590e snapshot: Change how gtk_snapshot_push/pop works
Instead of appending a container node and adding the nodes to it as they
come in, we now collect the nodes until gtk_snapshot_pop() is called and
then hand them out in a container node.

The caller of gtk_snapshot_push() is then responsible for doing whatever
he wants with the created node.

Another addigion is the keep_coordinates flag to gtk_snapshot_push()
which allows callers to keep the current offset and clip region or
discard it. Discarding is useful when doing transforms, keeping it is
useful when inserting effect nodes (like the ones I'm about to add).
2016-12-20 18:01:10 +01:00
Benjamin Otte
ca80e9decf snapshot: Handle clip region as part of the state
This is in preparation for further changes.
2016-12-20 18:01:10 +01:00
Benjamin Otte
67fb129ed7 gsk: gsk_render_node_set_transform() => GskTransformNode
Instead of having a setter for the transform, have a GskTransformNode.

Most of the oprations that GTK does do not require a transform, so it
doesn't make sense to have it as a primary attribute.

Also, changing the transform requires updating the uniforms of the GL
renderer, so we're happy if we can avoid that.
2016-12-20 18:01:10 +01:00
Benjamin Otte
f8932d643d snapshot: Always create an initial node
This way we ensure that there is only one root node and everybody can
append() with impunity.
2016-12-09 21:39:43 +01:00
Benjamin Otte
ab60cbd86a snapshot: Implement gtk_snapshot_clips_rect()
And use this to cull widgets and gadgets that are completely outside the
clip region.

A potential optimization is to apply this clip region to cairo contexts
created with gtk_snapshot_append_cairo_node(), but for that we'd need to
apply the inverse matrix to the clip region, and that causes rounding
errors.

Plus, I hope that cairo drawing becomes exceedingly rare so it won't be
used for the whole widget factory like today (which might also explain
why no culling happens in the widget factory outside the header bar.
2016-11-17 03:33:50 +01:00
Benjamin Otte
28b32d336f snapshot: Pass the clip region to the snapshot 2016-11-17 02:14:10 +01:00
Benjamin Otte
7493f90662 snapshot: Add GtkSnapshotState
Essentially copies cairo_gstate_t.

This is in preparation for attaching more information to the snapshot.
2016-11-17 01:55:26 +01:00
Benjamin Otte
d1fec79c00 snapshot: Completely reengineer API
We now try to emulate cairo_t:

We keep a stack of nodes via push/pop and a transform matrix.

So whenever a new node is added to the snapshot, we transform it
by the current transform matrix and append it to the current node.
2016-11-15 17:48:45 +01:00
Benjamin Otte
bb9626dc29 window: Implement snapshot() 2016-11-15 17:48:45 +01:00
Benjamin Otte
93cbba6c3e gtk: Add gtk_widget_snapshot()
It's functionally equivalent to gtk_widget_get_render_node() but uses a
GtkSnapshot argument to carry the state.
2016-11-15 17:48:45 +01:00