Commit Graph

4320 Commits

Author SHA1 Message Date
Robert Bragg
3b88029f38 actor: Cache per-actor transforms
Previously each time we needed to retrieve the model transform for a
given actor we would call the apply_transform vfunc which would build up
a transformation matrix based on the actor's current anchor point, its
scale, its allocation and rotation. The apply_transform implementation
would repeatedly call API like cogl_matrix_rotate, cogl_matrix_translate
and cogl_matrix_scale.

All this micro matrix manipulation APIs were starting to show up in the
profiles of dynamic applications so this adds priv->transform matrix
cache which maintains the combined result of the actors scale, rotation
and anchor point etc. Whenever something like the rotation changes then
then the matrix is marked as dirty, but so long as the matrix isn't
dirty then the apply_transform vfunc now just calls cogl_matrix_multiply
with the cached transform matrix.
2011-03-07 13:26:20 +00:00
Robert Bragg
19b8622983 Optimize culling by doing culling in eye-coordinates
This implements a variation of frustum culling whereby we convert screen
space clip rectangles into eye space mini-frustums so that we don't have
to repeatedly transform actor paint-volumes all the way into screen
coordinates to perform culling, we just have to apply the modelview
transform and then determine each points distance from the planes that
make up the clip frustum.

By avoiding the projective transform, perspective divide and viewport
scale for each point culled this makes culling much cheaper.
2011-03-07 13:26:20 +00:00
Robert Bragg
eef9078f89 stage: simplify apply_transform
This simplifies the implementation of the ClutterStage apply_transform
vfunc by using the new cogl_matrix_view_2d_in_perspective utility API
which can setup up a view transform for a given perspective so that a
cross section of the view frustum at an arbitrary depth can be mapped
directly to 2D stage coordinates with (0,0) at the top left.
2011-03-07 13:26:19 +00:00
Robert Bragg
ca30ac7835 matrix: adds 2d view transform conveniences
This adds two new experimental functions to cogl-matrix.c:
cogl_matrix_view_2d_in_perspective and cogl_matrix_view_2d_in_frustum
which can be used to setup a view transform that maps a 2D coordinate
system (0,0) top left and (width,height) bottom right to the current
viewport.

Toolkits such as Clutter that want to mix 2D and 3D drawing can use
these APIs to position a 2D coordinate system at an arbitrary depth
inside a 3D perspective projected viewing frustum.
2011-03-07 13:26:19 +00:00
Robert Bragg
1431b77747 stage: don't call glGetIntegerv in clutter_stage_read_pixels
Firstly Clutter shouldn't be using OpenGL directly so this needed
changing but also conceptually it doesn't make sense for
clutter_stage_read_pixels to validate the requested area to read against
the viewport it would make more sense to compare against the window
size. Finally checking that the width of the area is less than the
viewport or window width without considering the x isn't enough to know
if the area extends outside the windows bounds. (same for the height)

This patch removes the validation of the read area from
clutter_stage_read_pixels and instead we now simply rely on the
semantics of cogl_read_pixels for reading areas outside the window
bounds.
2011-03-07 13:26:19 +00:00
Robert Bragg
013b2433f0 viewport: consistently use floats for viewports
OpenGL < 4.0 only supports integer based viewports and internally we
have a mixture of code using floats and integers for viewports. This
patch switches all viewports throughout clutter and cogl to be
represented using floats considering that in the future we may want to
take advantage of floating point viewports with modern hardware/drivers.
2011-03-07 13:26:19 +00:00
Robert Bragg
54f85832b7 util: tune point_in_poly test for polys in screen coords
This makes a change to the original point_in_poly algorithm from:
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

The aim was to tune the test so that tests against screen aligned
rectangles are more resilient to some in-precision in how we transformed
that rectangle into screen coordinates. In particular gnome-shell was
finding that for some stage sizes then row 0 of the stage would become a
dead zone when going through the software picking fast-path and this was
because the y position of screen aligned rectangles could end up as
something like 0.00024 and the way the algorithm works it doesn't have
any epsilon/fuz factor to consider that in-precision.

We've avoided introducing an epsilon factor to the comparisons since we
feel there's a risk of changing some semantics in ways that might not be
desirable. One of those is that if you transform two polygons which
share an edge and test a point close to that edge then this algorithm
will currently give a positive result for only one polygon.

Another concern is the way this algorithm resolves the corner case where
the horizontal ray being cast to count edge crossings may cross directly
through a vertex. The solution is based on the "idea of Simulation of
Simplicity" and "pretends to shift the ray infinitesimally down so that
it either clearly intersects, or clearly doesn't touch". I'm not
familiar with the idea myself so I expect a misplaced epsilon is likely
to break that aspect of the algorithm.

The simple solution this patch applies is to pixel align the polygon
vertices which should eradicate most noise due to in-precision.

https://bugzilla.gnome.org/show_bug.cgi?id=641197
2011-03-07 13:26:19 +00:00
Emmanuele Bassi
0194e9db2f glx: Use g_set_error_literal() where appropriate 2011-03-04 23:58:12 +00:00
Emmanuele Bassi
bed392b9a5 On error, return FALSE in the post_parse hook
Anything that is not CLUTTER_INIT_SUCCESS is to be considered an error.

This fixes the Clutter initialization sequence to actually error out
on pre-conditions and backend initialization failures.
2011-03-04 23:56:12 +00:00
Emmanuele Bassi
8bde5febd1 Clean up argument parsing GError handling
Pass a GError in, so that clutter_init() can effectively print out a
critical warning on initialization failure, like it used to do in the
olden days.
2011-03-04 23:55:02 +00:00
Emmanuele Bassi
4f3a4ab01b x11: Use g_set_error_literal()
The g_set_error() function takes a format string.
2011-03-04 23:53:45 +00:00
Neil Roberts
9e11aa3820 clutter-offscreen-effect: Use 0,0 as the offset if no actor box
clutter_offscreen_effect_pre_paint was using the unitialized value of
the ‘box’ variable whenever the actor doesn't have a paint
volume. This patch makes it just set the offset to 0,0 instead.
2011-03-04 17:04:02 +00:00
Neil Roberts
d306b4bb7d clutter-offscreen-effect: Preserve the old opacity override
When removing the opacity override in the post_paint implementation,
ClutterOffscreenEffect would always set the override back to -1. This
ends up cancelling out the effect of any overrides from outer effects
which means that if any actor has multiple effects attached then it
would apply the opacity multiple times.

To fix this, the effect now preserves the old value of the opacity
override and restores that instead of setting -1.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2541
2011-03-03 16:54:52 +00:00
Neil Roberts
3fab04805e clutter-actor: Add an internal _clutter_actor_get_opacity_override
This is needed if an effect wants to temporarily override the paint
opacity. It needs to be able to restore the old opacity override in
the post_paint handler otherwise it would replace the effect of the
opacity override from any outer effects.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2541
2011-03-03 16:54:51 +00:00
Jasper St. Pierre
0c576c0c33 Remove private helper #define's
Finish off the second half of 09a830d294.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2596
2011-03-03 11:47:49 +00:00
Dioselin
cfa32659e4 box: set default paint volume to allocation
http://bugzilla.clutter-project.org/show_bug.cgi?id=2589
2011-03-02 18:29:11 +00:00
Emmanuele Bassi
0be73bf401 effect: Queue a redraw on :enabled changes
ClutterEffect should queue a redraw if the :enabled property of its
parent class ClutterActorMeta changes.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2587
2011-03-01 19:04:31 +00:00
Emmanuele Bassi
bd8b09edda constraint: Queue a relayout on :enabled changes
ClutterConstraint should queue a relayout if the :enabled property of
its parent class ClutterActorMeta changes.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2587
2011-03-01 19:04:31 +00:00
Emmanuele Bassi
0c83e6a59a offscreen-effect: Add public accessor for target size
The OffscreenEffect class needs to expose a way for sub-classes to
track the size of FBO it creates, in case it has to do some geometry
deformations like the DeformEffect sub-classes.

Let's move the private symbol we used internally in 1.6 to fix
DeformEffect to the list of public symbols of OffscreenEffect.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2570
2011-02-28 14:34:36 +00:00
Emmanuele Bassi
e2b5762571 Move the keysym ↔ Unicode table to .rodata
The table we use for converting between keysyms and Unicode should be
static and constified, so that it can live in the .rodata section of
the ELF shared object, and be shared among processes.

This change moves the table to a source file, instead of an header; the
change also requires the clutter_keysym_to_unicode() function to be
moved from clutter-event.c into this new source file. The declaration is
still in clutter-event.h, so we don't need to do anything special.
2011-02-28 14:16:24 +00:00
Emmanuele Bassi
d3a7b7502e event: Add setters for ClutterEvent members
Creating a synthetic event requires direct access to the ClutterEvent
union members; this access does not map in bindings to high-level
languages, especially run-time bindings using GObject-Introspection.
It's also midly annoying from C, as it unnecessarily exposes the guts of
ClutterEvent - something we might want to fix in the future.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2575
2011-02-28 14:16:23 +00:00
Neil Roberts
3d34d9fea1 Add G_GNUC_WARN_UNUSED_RESULT to clutter_init and init_with_args
Many people expect clutter_init to work the same way as gtk_init which
exits the program on init failure. clutter_init however returns a
status code on failure which applications need to handle because if
the init fails then any further Clutter calls are likely to crash. In
Clutter 2.0 we may want to change this to be more like GTK+.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2574
2011-02-28 14:10:05 +00:00
Neil Roberts
4dd20f2678 cogl-blit: Disable blending when using texture render
When using a pipeline and the journal to blit images between
framebuffers, it should disable blending. Otherwise it will end up
blending the source texture with uninitialised garbage in the
destination texture.
2011-02-24 20:45:19 +00:00
Emmanuele Bassi
4442ddde82 text: Round up the size
Converting from Pango units to pixels by using the C conventions might
cause us to lose a pixel; since we're doing the same for the height, we
should use ceilf() to round up the width and the line height.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2573
2011-02-21 17:34:45 +00:00
Emmanuele Bassi
0d17b1463b device-manager/xi2: Silence a compiler warning 2011-02-19 16:48:59 +00:00
Emmanuele Bassi
fd3462170f cally: Remove unused variables 2011-02-19 16:47:20 +00:00
Emmanuele Bassi
dfdcc20670 clutter: Remove unused variables 2011-02-19 16:47:20 +00:00
Emmanuele Bassi
f99d2336f0 x11: Remove unused variables 2011-02-19 16:47:20 +00:00
Emmanuele Bassi
23598ea74b cogl: Remove unused variables 2011-02-19 16:47:11 +00:00
Emmanuele Bassi
ec02a8808e deform-effect: Use the FBO target size
The ClutterDeformEffect sub-classes are effectively deforming the
texture target of an FBO, not the actor itself. Thus, we need to
use the FBO's size, and not the actor's allocated size, given that
the actor might be transformed prior to applying an effect.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2571
2011-02-19 09:19:07 +00:00
Emmanuele Bassi
20f19fe06c offscreen-effect: Add private API for getting the target size
Since the FBO target might have a different size than the mere paint box
of the actor, we need API to get it out of the ClutterOffscreenEffect
private data structure and on to sub-classes.

Since we cannot add new API in a stable cycle, we need a private
function; we'll leave it there even when opening 1.7, since it's useful
for internal purposes.
2011-02-19 09:15:34 +00:00
Emmanuele Bassi
a923375f0a drag-action: Use per-stage motion event toggle
Similar to what we did for the ClutterDeviceManager, use per-stage
granularity when toggling the motion event delivery while dragging.
2011-02-18 19:41:57 +00:00
Emmanuele Bassi
cca2e5bc9c device-manager: Use per-stage motion event toggle
Now that we have internal support for per-stage granularity of motion
event delivery, let's use it when updating the state of the input
devices.
2011-02-18 19:41:57 +00:00
Emmanuele Bassi
bc548dc862 Store the motion event deliver flag in ClutterStage
Once upon a time, the land of Clutter had a stage singleton. It was
created automatically at initialization time and stayed around even
after the main loop was terminated. The singleton was content in
being all there was. There also was a global API to handle the
configuration of the stage singleton that would affect the behaviour
on other classes, signals and properties.

Then, an evil wizard came along and locked the stage singleton in his
black tower, and twisted it until it was possible to create new stages.
These new stages were pesky, and didn't have the same semantics of the
singleton: they didn't stay around when closed, or terminate the main
loop on delete events.

The evil wizard also started moving all the stage-related API from the
global context into class-specific methods.

Finally, the evil wizard cast a spell, and the stage singleton was
demoted to creation on demand - and until somebody called the
clutter_stage_get_default() function, the singleton remained in a limbo
of NULL pointers and undefined memory areas.

There was a last bit - literally - of information still held by the
global API; a tiny, little flag that disabled per-actor motion events.
The evil wizard added private accessors for it, and stored it inside the
stage private structure, in preparation for a deprecation that would
come in a future development cycle.

The evil wizard looked down upon the land of Clutter from the height of
his black tower; the lay of the land had been reshaped into a crucible
of potential, and the last dregs of the original force of creation were
either molted into new, useful shapes, or blasted away by the sheer fury
of his will.

All was good.
2011-02-18 19:41:41 +00:00
Emmanuele Bassi
7500b77b2b Assert if we call backend API without a valid backend
This is a backend programming error, and we should not tolerate
failures in these cases.
2011-02-18 17:51:01 +00:00
Emmanuele Bassi
7e42da123f Clean up clutter-private.h
Move macros at the top, and clean up whitespace.
2011-02-18 16:53:58 +00:00
Emmanuele Bassi
cdd9fd1af1 Move ActorMeta private function in the private header
No reason to leave it in the installed header.
2011-02-18 16:53:31 +00:00
Emmanuele Bassi
3e5aa9ed63 Add private header for event-related API 2011-02-18 16:35:36 +00:00
Emmanuele Bassi
d27b335b61 Move ClutterEffect private symbols to a private header
No point in cluttering up clutter-private.h even more than necessary.
2011-02-18 16:00:39 +00:00
Emmanuele Bassi
3addeb91cc Privatize all ClutterIdPool functions
The clutter-id-pool.h header is private and not installed; yet, all the
clutter_id_pool_* symbols are public. Let's correct this oversight we've
been stringing along since forever.
2011-02-18 15:53:27 +00:00
Emmanuele Bassi
37fe8c509a Clean up usage of CLUTTER_CONTEXT and remove the macro
Only allow access to the ClutterMainContext through the private
_clutter_context_get_default() function, so we can easily grep
it and remove the unwanted usage of the global context.
2011-02-18 15:47:35 +00:00
Emmanuele Bassi
689aac56c9 Wrap id-pool access
The ClutterIdPool is held by the ClutterMainContext; we should hide its
direct usage into sensible private API.
2011-02-18 15:46:13 +00:00
Emmanuele Bassi
2593bbaadc Wrap shader stack into private functions
The shader stack held by ClutterMainContext should only be accessed
using functions, and not directly.

Since it's a stack, we can use stack-like operations: push, pop and
peek.
2011-02-18 15:44:17 +00:00
Emmanuele Bassi
28b0f8b938 stage: Make the redraw_count a stage counter
We don't care about redraws issued on stages that are not currently
being repainted.
2011-02-18 14:38:54 +00:00
Emmanuele Bassi
4635c8f9fd Make _clutter_pixel_to_id() private
It's only used in the same file that declares it.
2011-02-18 14:38:24 +00:00
Emmanuele Bassi
92ddaa9c13 stage: Move stage redraw logic into clutter-stage.c
The _clutter_do_redraw() function should really be moved inside
ClutterStage, since all it does is calling private stage and
backend functions. This also allows us to change a long-standing
issue with a global fps counter for all stages, instead of a\
per-stage one.
2011-02-18 12:56:17 +00:00
Emmanuele Bassi
89a0d514b4 Continue hiding the ClutterMainContext
We should strive to make the main context as transparent as possible,
and hide accessing its data through private functions.
2011-02-18 12:56:13 +00:00
Emmanuele Bassi
fc89513295 actor: Move the ShaderData out of the private data
Let's try and start reducing the size of ClutterActorPrivate by moving
some optional, out-of-band data from it to GObject data.

The ShaderData structure is a prime candidate for this migration: it
does not need to be inspected by the actor, and its relationship with an
actor is transient and optional.

By attaching it to the actor's instance through g_object_set_data() we
neatly tie its lifetime to the instance, and we don't have to care
cleaning it up in the finalize()/dispose() implementation of
ClutterActor itself.
2011-02-18 11:43:27 +00:00
Neil Roberts
9ea2567a2f cogl-atlas-texture: Don't let textures be destroyed during migration
If an atlas texture's last reference is held by the journal or by the
last flushed pipeline then if an atlas migration is started it can
cause a crash. This is because the atlas migration will cause a
journal flush and can sometimes change the current pipeline which
means that the texture would be destroyed during migration.

This patch adds an extra 'post_reorganize' callback to the existing
'reorganize' callback (which is now renamed to 'pre_reorganize'). The
pre_reorganize callback is now called before the atlas grabs a list of
the current textures instead of after so that it doesn't matter if the
journal flush destroys some of those textures. The pre_reorganize
callback for CoglAtlasTexture grabs a reference to all of the textures
so that they can not be destroyed when the migration changes the
pipeline. In the post_reorganize callback the reference is removed
again.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2538
2011-02-17 13:39:30 +00:00
Neil Roberts
71f57eef1b clutter-actor: Free the paint volume when queue a clip redraw
In _clutter_actor_queue_redraw_with_clip it has a local variable to
mark when a new paint volume for the clip is created so that it can be
freed when the function returns. However the actual code to free the
paint volume went missing in 3b789490d2 so the variable did
nothing. This patch just adds the free back in.
2011-02-16 19:00:05 +00:00