Commit Graph

48790 Commits

Author SHA1 Message Date
Emmanuele Bassi
dace0791a9 gsk: Add the ability to create fallback renderers
While porting GTK to GskRenderer we noticed that the current fallback
code for widgets using Cairo to draw is not enough to cover all the
possible cases.

For instance, if a container widget still uses GtkWidget::draw to render
its children, and at least one of them has been ported to using render
nodes instead, the container won't know how to draw it.

For this reason we want to provide to layers above GSK the ability to
create a "fallback" renderer instance, created using a "parent"
GskRenderer instance, but using a Cairo context as the rendering target
instead of a GdkDrawingContext.

GTK will use this inside the gtk_widget_draw() implementation, if a
widget implements GtkWidgetClass.get_render_node().
2016-10-18 11:49:16 +01:00
Emmanuele Bassi
a9bbb020aa gsk: Update Cairo renderer
The Cairo renderer has been lagging behind a series of changes inside
GskRenderer, like surface-less nodes, so it needs to be updated.
2016-10-18 11:49:15 +01:00
Emmanuele Bassi
6b3c0052fc gsk: Make GskRenderer.render() drawing context-agnostic
We're going to need to allow rendering on a specific cairo_t in order to
implement fallback code paths inside GTK; this means that there will be
times when we have a transient GskRenderer instance that does not have a
GdkDrawingContext to draw on.

Instead of adding a new render() implementation for those cases and then
decide which one to use, we can remove the drawing context argument from
the virtual function itself, and allow using a NULL GdkDrawingContext
when calling gsk_renderer_render(). A later commit will add a generic
function to create a transient GskRenderer with a cairo_t attached to
it.

Renderers inside GSK will have to check whether we have access to a
GdkDrawingContext, in which case we're going to use it; or if we have
access to a cairo_t and a window.
2016-10-18 11:49:15 +01:00
Emmanuele Bassi
13f7f5bdfc docs: Update the GSK API reference section 2016-10-18 11:49:15 +01:00
Emmanuele Bassi
3aaae6c49c gsk: Move GskRenderNode getters to internal API
GskRenderNode is, at its core, a write-only API; you're supposed to set
up the render nodes instead of querying them for state.

Querying render nodes is left to the GskRenderer implementation.
2016-10-18 11:49:15 +01:00
Emmanuele Bassi
7de49fb7b2 gsk: Remove GskRenderer:auto-clear
We control the clearing inside each GskRenderer implementation, and we
don't allow providing a target surface any more.
2016-10-18 11:49:15 +01:00
Matthias Clasen
c5a2ae2f95 Convert GtkSpinner to indirect rendering 2016-10-18 11:49:15 +01:00
Matthias Clasen
8f5db4bc32 Convert GtkImage to indirect rendering 2016-10-18 11:49:15 +01:00
Matthias Clasen
bed5e6fb16 Convert GtkAccelLabel to indirect rendering 2016-10-18 11:49:15 +01:00
Matthias Clasen
be0de54237 Convert GtkLabel to indirect rendering
Warning! This breaks GtkAccelLabel. It will be fixed in the next
commit.
2016-10-18 11:49:15 +01:00
Matthias Clasen
f101ef7cd1 Convert GtkFlowBox to indirect rendering 2016-10-18 11:49:15 +01:00
Matthias Clasen
58b38d59c5 container: Prepare to prune render nodes
Add a should_propagate function for render nodes. Eventually,
this is meant to avoid creating render nodes for child widgets
that are outside the parents clip area. Since we don't have
that information available right now, just filter out nondrawable
children for now.
2016-10-18 11:49:15 +01:00
Matthias Clasen
39c1aa5e27 Split css background into individual render nodes
Use separate render nodes for each layer in a multi-image
background. WARNING: blend modes don't work right yet.
2016-10-18 11:49:15 +01:00
Matthias Clasen
9a2de80497 Add blend mode to debug spew 2016-10-18 11:49:14 +01:00
Matthias Clasen
b660361fb7 Don't create render nodes for empty backgrounds 2016-10-18 11:49:14 +01:00
Matthias Clasen
cffb8ae4b5 Break out the css background render node in a function
This is in preparation for creating separate render nodes
for individual backgrounds.
2016-10-18 11:49:14 +01:00
Matthias Clasen
f74dd416d6 Make outer shadows work again
Change get_render_node to return nodes that are sized to the clip
area and expect to be placed at the clip position; change
gtk_container_propagate_render_node to place child render nodes
accordingly, and change gtk_css_gadget_get_render_node to return
nodes that are sized accordingly as well.
2016-10-18 11:49:14 +01:00
Alexander Larsson
e0ab6d5a3c gsk: Fix hidpi scaling
We store the vertices in (unscaled) window coords (but the item size
is still scaled to match the texture size). Also, the
projection/model-view multiplication order is switched so that the scale
is applied at the right place.
2016-10-18 11:49:14 +01:00
Alexander Larsson
1c7c77bc94 gdk_cairo_surface_upload_to_gl: Don't apply device scale
The arguments to this function is the texture width/height, and these
are already scaled.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
f764d03cfd gsk: Remove :use-alpha from GskRenderer
It's unused, and we always assume we render with an alpha channel
enabled because it's 2016.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
387ed37f74 gsk: Move scaling filters to GskRenderNode
The renderer will always use nearest-neighbor filters because it renders
at 1:1 pixel to texel ratio.

On the other hand, render nodes may be scaled, so we need to offer a way
to control the minification and magnification filters.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
3bdd9c270a gsk: Allow adding a GL texture as a node content
If we already have a GL texture we definitely don't want to use
gdk_cairo_draw_from_gl() to draw on a Cairo context if we're going
to take the Cairo surface to which we draw and put it into an OpenGL
texture.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
ce67336577 gsk: Drop modelview/projection from GskRenderer API
The details of the modelview and projection matrices are only useful for
the GL renderer; there's really no point in having those details
available in the generic API — especially as the Cairo fallback renderer
cannot really set up a complex modelview or a projection matrix.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
23a009a408 gtk: Sort children by window depth when rendering
This makes popovers pop over instead of under.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
c9514b45ff gsk: Ensure that non-drawing nodes are supported
Non-drawing nodes should skip the texturing phase.
2016-10-18 11:49:14 +01:00
Emmanuele Bassi
b2f5a69742 gtk: Add a box render node for gadgets
Instead of using the background as the gadget's node, we add a
non-drawing node that can be used to apply offsets; all other nodes are
children of the "box" node.
2016-10-18 11:49:13 +01:00
Emmanuele Bassi
955d9a8463 gsk: Fix the blend mode
The default blend mode should be the equivalent of Cairo's OVER
operator.
2016-10-18 11:49:13 +01:00
Emmanuele Bassi
0812d691b3 gsk: Reuse VAOs with identical buffers
Just like we reuse texture ids with the same size we can, at the expense
of a little memory, reuse vertex buffers if they reference the same
attributes and contain the same data.

Each VAO is marked as free at the end of the frame, and if it's not
reused in the following frame, it gets dropped.
2016-10-18 11:49:13 +01:00
Emmanuele Bassi
56c93a7661 gsk: Remove child-transform from render nodes
The child-transform is useful only if we also provide clipping to the
parent nodes, otherwise children will just be drawn outside of the
parent's bounds.

We'll introduce child transforms either at a higher layer, or once we
add clipping support to GskRenderNode.
2016-10-18 11:49:13 +01:00
Matthias Clasen
fd4a1cdad6 Covert GtkOverlay to indirect rendering
There is no gadget, so we use the gtk_widget_create_render_node
function for the first time here.
2016-10-18 11:49:13 +01:00
Matthias Clasen
579b43b8e8 Convert GtkComboBox to indirect rendering
The removal of the draw method in GtkComboBox reveals another
instance of parent-child invariant violation in GtkComboBoxText.
2016-10-18 11:49:13 +01:00
Matthias Clasen
b8acd23a86 GtkButtonBox: Convert to indirect rendering 2016-10-18 11:49:13 +01:00
Matthias Clasen
53266e7a15 Small documentation additions 2016-10-18 11:49:13 +01:00
Matthias Clasen
7eb8646ace Small fixes for the docs
Set titles and short descriptions for the sections.
2016-10-18 11:49:13 +01:00
Matthias Clasen
d8dc6f0c81 gsk: Build docs 2016-10-18 11:49:13 +01:00
Matthias Clasen
ea549a3ce4 GtkListBox: Convert to indirect rendering
Note that there is a problem with the pixel cache that causes
listboxes to come out black when in a scrolled window.
2016-10-18 11:49:13 +01:00
Matthias Clasen
1046262048 gadget: Fix handling of custom content
The transformations here were wrong, causing content to go nowhere.
This patch fixes check and radio buttons to appear as expected.
2016-10-18 11:49:13 +01:00
Matthias Clasen
6a1edb0960 GtkCheckButton: Convert to indirect rendering
This is another example of indirect rendering with a box gadget.
There is currently still some positioning problem with the
checkmark.
2016-10-18 11:49:13 +01:00
Matthias Clasen
f68eaae581 Prevent box gadget content from being drawn twice
Now that we split out box gadget children into separate
render nodes, we must not draw them onto the box gadgets
node anymore.
2016-10-18 11:49:12 +01:00
Matthias Clasen
ac52abcedc GtkExpander: Convert to indirect rendering
This is the first example of indirect rendering involving
a box gadget. For now, we iterate the child gadgets manually,
and rely on gtk_container_propagate_render_node for the
child widgets. Eventually, we may want a better solution
here.
2016-10-18 11:49:12 +01:00
Matthias Clasen
62eb900b83 gadget: Add a has_content vfunc
...and implement it for GtkCssGadget and GtkCssCustomGadget.
This allows us to decide on a per-object basis if a custom
gadget needs a render node for content or not.
2016-10-18 11:49:12 +01:00
Matthias Clasen
9d06ee637b button: Restore focus
The custom gadget draw function has the side effect of informing
the gadget machinery wether to draw focus or not. Bring the
draw function back, just for its boolean return value. We may
want to find a better solution for this.
2016-10-18 11:49:12 +01:00
Matthias Clasen
7f86516c27 Allow selective debug spew
I don't think this should stay in the code long-term, but it
is useful for debugging. It helped me track down some suspicious
placements of render nodes.
2016-10-18 11:49:12 +01:00
Matthias Clasen
02187371a2 Add details to css render nodes
Give all nodes the same detail about the owner widget.
This reveals that every GtkCssCustomGadget gets a
DrawGadgetContents node, even if their draw_func is NULL.
We may want to come up with a better solution for that.
2016-10-18 11:49:12 +01:00
Matthias Clasen
bde55ccdce Some debug help
Make the bounds of drawing surfaces created by render nodes visible.

Trigger with GSK_DEBUG=surface.
2016-10-18 11:49:12 +01:00
Matthias Clasen
b371b5da42 Drop an unused variable 2016-10-18 11:49:12 +01:00
Emmanuele Bassi
9fe18f6561 gtk: Clean up render fallback node creation in GtkWidget 2016-10-18 11:49:12 +01:00
Emmanuele Bassi
e58965a3cc gtk: Port GtkHeaderBar to render nodes 2016-10-18 11:49:12 +01:00
Emmanuele Bassi
2e0d3ef866 gtk: Port GtkActionBar to render nodes 2016-10-18 11:49:12 +01:00
Emmanuele Bassi
abe19f1826 gtk: Attempt at handling CSS coordinates
When creating the GskRenderNodes for the gadgets we should not translate
the coordinates inside the Cairo context, but we should tweak the
coordinates of the anchor point.

This is still not enough to get an appropriate rendering, as the result
is still slightly offset to the left.
2016-10-18 11:49:12 +01:00