Commit Graph

48578 Commits

Author SHA1 Message Date
Emmanuele Bassi
ed087f2a30 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-17 16:22:02 +01:00
Emmanuele Bassi
df54c81d7f 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-17 16:22:02 +01:00
Emmanuele Bassi
3ccd45b9e0 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-17 16:22:02 +01:00
Emmanuele Bassi
0d08d2d63a docs: Update the GSK API reference section 2016-10-17 16:22:01 +01:00
Emmanuele Bassi
40de4d590a 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-17 16:22:01 +01:00
Emmanuele Bassi
111a440dda 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-17 16:22:01 +01:00
Matthias Clasen
9df3067bb8 Convert GtkSpinner to indirect rendering 2016-10-17 16:22:01 +01:00
Matthias Clasen
46c7128094 Convert GtkImage to indirect rendering 2016-10-17 16:22:01 +01:00
Matthias Clasen
781b5aac86 Convert GtkAccelLabel to indirect rendering 2016-10-17 16:22:01 +01:00
Matthias Clasen
df28f92187 Convert GtkLabel to indirect rendering
Warning! This breaks GtkAccelLabel. It will be fixed in the next
commit.
2016-10-17 16:22:01 +01:00
Matthias Clasen
59f95e1e1f Convert GtkFlowBox to indirect rendering 2016-10-17 16:22:01 +01:00
Matthias Clasen
0a2467ce3b 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-17 16:22:01 +01:00
Matthias Clasen
d6acfd81c7 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-17 16:22:01 +01:00
Matthias Clasen
697d0e9ed9 Add blend mode to debug spew 2016-10-17 16:22:01 +01:00
Matthias Clasen
a21409c61b Don't create render nodes for empty backgrounds 2016-10-17 16:22:01 +01:00
Matthias Clasen
e825ca92e7 Break out the css background render node in a function
This is in preparation for creating separate render nodes
for individual backgrounds.
2016-10-17 16:22:00 +01:00
Matthias Clasen
ed3740933e 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-17 16:22:00 +01:00
Alexander Larsson
0f1a8bfe20 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-17 16:22:00 +01:00
Alexander Larsson
f78330139f 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-17 16:22:00 +01:00
Emmanuele Bassi
5e973006b4 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-17 16:22:00 +01:00
Emmanuele Bassi
b1c5475046 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-17 16:22:00 +01:00
Emmanuele Bassi
ea3c2f4889 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-17 16:22:00 +01:00
Emmanuele Bassi
2aeb9f61a6 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-17 16:22:00 +01:00
Emmanuele Bassi
11151379df gtk: Sort children by window depth when rendering
This makes popovers pop over instead of under.
2016-10-17 16:22:00 +01:00
Emmanuele Bassi
fc15f027ec gsk: Ensure that non-drawing nodes are supported
Non-drawing nodes should skip the texturing phase.
2016-10-17 16:22:00 +01:00
Emmanuele Bassi
63dc543d0e 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-17 16:22:00 +01:00
Emmanuele Bassi
4befa6b653 gsk: Fix the blend mode
The default blend mode should be the equivalent of Cairo's OVER
operator.
2016-10-17 16:22:00 +01:00
Emmanuele Bassi
c454c1ad2c 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-17 16:21:59 +01:00
Emmanuele Bassi
84c5472752 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-17 16:21:59 +01:00
Matthias Clasen
88d02b8f91 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-17 16:21:59 +01:00
Matthias Clasen
8c9717119d 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-17 16:21:59 +01:00
Matthias Clasen
b3063fe3a0 GtkButtonBox: Convert to indirect rendering 2016-10-17 16:21:59 +01:00
Matthias Clasen
bf4c44fbf1 Small documentation additions 2016-10-17 16:21:59 +01:00
Matthias Clasen
92273b5d19 Small fixes for the docs
Set titles and short descriptions for the sections.
2016-10-17 16:21:59 +01:00
Matthias Clasen
710a326db2 gsk: Build docs 2016-10-17 16:21:59 +01:00
Matthias Clasen
8851d75ba8 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-17 16:21:59 +01:00
Matthias Clasen
ed8db31f81 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-17 16:21:59 +01:00
Matthias Clasen
d40636b6b0 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-17 16:21:59 +01:00
Matthias Clasen
fddc1a9708 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-17 16:21:59 +01:00
Matthias Clasen
4ea6ee4567 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-17 16:21:58 +01:00
Matthias Clasen
9286c1c0fa 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-17 16:21:58 +01:00
Matthias Clasen
82166f8d72 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-17 16:21:58 +01:00
Matthias Clasen
cf96e92b8b 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-17 16:21:58 +01:00
Matthias Clasen
1140c20309 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-17 16:21:58 +01:00
Matthias Clasen
5228506b6f Some debug help
Make the bounds of drawing surfaces created by render nodes visible.

Trigger with GSK_DEBUG=surface.
2016-10-17 16:21:58 +01:00
Matthias Clasen
6fd807ae0d Drop an unused variable 2016-10-17 16:21:58 +01:00
Emmanuele Bassi
cd78d1a69a gtk: Clean up render fallback node creation in GtkWidget 2016-10-17 16:21:58 +01:00
Emmanuele Bassi
fe590578f9 gtk: Port GtkHeaderBar to render nodes 2016-10-17 16:21:58 +01:00
Emmanuele Bassi
ae4e72d944 gtk: Port GtkActionBar to render nodes 2016-10-17 16:21:58 +01:00
Emmanuele Bassi
00d4b62dce 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-17 16:21:58 +01:00