1
0
Fork 0
Commit graph

1415 commits

Author SHA1 Message Date
Chun-wei Fan
feaaaad6a0 Update cogl.symbols
There are numerous APIs added/removed in the following commits:
e7f15826 Add a CoglPrimitiveTexture interface
6197e3ab Add constructors which take a CoglBitmap to all primitive textures
bdb645e7 kms: defer setting crtc modes until first swap buffers
9a1f1df8 Rework sdl integration api
ac0c72ab Removed legacy cogl-fixed 1.x api
e8c4c80c Remove deprecated cogl_vertex_buffer api
06d522cb Remove the legacy CoglPath API
713a8f81 Replace cogl_path_{stroke,fill} with framebuffer API
6ed3aaf4 Removes all remaining use of CoglHandle
068b3b59 matrix: Add a init_translation() constructor

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2625354b8accaebe33ee2747ff03f665aea07e4f)
2012-08-06 14:27:42 +01:00
Chun-wei Fan
23becf67a7 Fix Visual C++ build
-Create a pre-defined cogl/cogl-gl-header.h(.win32) that is to be used on
 any Windows builds, and adapt the MSVC build process to set up and use
 that file.
-Fix up glib-mkenums code generation .bat file that is generated during
 "make"/"make dist", like the autotools-based builds.
-Since cogl/cogl-defines.h now contain versionioning info, and it no longer
 directly includes the GL headers, update the pre-configured
 cogl-defines.h[.win32|.win32_SDL] and use autotools to fill in the
 versioning info during "make"/"make dist".
-Fix up cogl/cogl-pango.rc.in so that they reflect the cogl-2.x versioning
 stuff correctly and versioning info can be filled in correctly during
 "make"/"make dist"

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 7ff42bb1c5280b0f53370f8d94ef5f10c9f39e2f)
2012-08-06 14:27:42 +01:00
Damien Lespiau
e6b75b6cfc quaternion: Fix typo in the init_from_z_rotation documentation
Clearly from a copy and paste from init_from_y_rotation().

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2f06f4d79e29bbf30a44edbf48e8eaa637e30930)
2012-08-06 14:27:42 +01:00
Damien Lespiau
542fdcd2b0 doc: Hide the private fields of CoglQuaternion
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit a98a69017cdf8879816c1a341e4982b57ef1bc32)
2012-08-06 14:27:41 +01:00
Damien Lespiau
86a5259578 doc: Include the documentation for CoglEuler
Several little changes were needed to make the CoglEuler documentation
appear:

  • Fix the embeded docbook snippet in the CoglEuler section header
  • Add the xinclude directive to the main document
  • Add the missing <SECTION> in -sections.txt

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit c7f6e07f7b8ba0d7dc9604e888c8a46165ec3ed4)
2012-08-06 14:27:41 +01:00
Damien Lespiau
e172cac480 quaternion: Document init_from_quaternion()
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 91c2a3580a6055fcb6902524d3e8354f27932e89)
2012-08-06 14:27:41 +01:00
Damien Lespiau
28655fd608 quaternion: Document init_from_euler()
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 018703a8e83835e7ab522f5e011fdd4a039523a2)
2012-08-06 14:27:41 +01:00
Damien Lespiau
7ff0b52d78 matrix: Add a init_translation() constructor
This allows people to initialize a matrix with a translation
transformation. The options to do it at the moment were:

* init_from_array() but it give cogl no information about the type of
  matrix.
* init_indentity() and then translate() but it means doing a lot of
  computations for no reason.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 068b3b59221e405dc288d434b0008464684a7c12)
2012-08-06 14:27:41 +01:00
Neil Roberts
68a6e82828 Add support for the WebOS version of SDL
The stock 1.2.x version of SDL only supports regular OpenGL. The
version on WebOS is specially patched to add some extra API to request
a GLES1 or GLES2 context. This patch adds a configure check to detect
when Cogl is being built with the patched version of SDL. In that case
it will additionally allow the gles1 and gles2 drivers and set the
right video mode attributes to get the corresponding context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3726c60deab2bd94617a562abb63f735627a25e4)
2012-08-06 14:27:41 +01:00
Neil Roberts
1d3d1732bd Fixes for building with --disable-gl
This fixes a few problems that occur when only using a GLES2 header.

• The use of GL_CLAMP_TO_BORDER and GL_MIRRORED_REPEAT were moved from
  cogl-pipelinelayer-state.h to cogl-sampler-cache-private.h but the
  corresponding defines were not.

• cogl-sampler-cache.c was using GL_TEXTURE_WRAP_R but this is only
  defined as GL_TEXTURE_WRAP_R_OES from the GLES2 header so it needs a
  #define.

• cogl-framebuffer-private.h uses GLuint but it does not include
  cogl-gl-header.h. It gets away with this when GLX support is enabled
  because the GL header would be included via glx.h.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9cdb87c864fc262c4b26c13963670d60d7c18058)
2012-08-06 14:27:41 +01:00
Neil Roberts
d57fcd952e buffer: Use GL_STREAM_DRAW on GLES2
The function to convert the CoglBufferUpdateHint to a GL enum was
previously ifdef'd to only use GL_STREAM_DRAW when Cogl is compiled
with big GL support. One problem with this is that it would end up
trying to use it on GLES1 if support for both is compiled. The other
problem is that GLES2 seems to actually support GL_STREAM_DRAW so we
might as well use it in that case.

This patch also changes it so that if the hint is stream with GLES1
then it will default to GL_DYNAMIC_DRAW instead of GL_STATIC_DRAW
because I think that is closer to the meaning of the stream hint.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9e997476a7f9271bc000abdc82b1e343b92afb4c)
2012-08-06 14:27:41 +01:00
Neil Roberts
85efb7daba Don't typedef CoglMemoryStack twice
CoglMemoryStack was being typedef'd twice, once in the private header
as an incomplete struct and once in the C source with the actual
struct definition. This removes the second typedef so that it just
defines the struct.

This patch was written by Jack River.

https://bugzilla.gnome.org/show_bug.cgi?id=675119

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 75cd425a48e0fc403bf88eace212a6d37b65df11)
2012-08-06 14:27:41 +01:00
Robert Bragg
9cf7aac80f Allow npot Texture2D creation with only basic npot support
Cogl has feature flags for basic npot texture support and then separate
flags for npot + repeat and npot + mipmap. If those three features are
available then there is a feature for full-npot support too for
convenience. The cogl_texture_2d_new_ constructors were checking for
full npot support and failing if not available but since we expose the
fine grained features to the user the user should be able to check the
limitations of npot textures and still choose to allocate them.

_cogl_texture_2d_can_create() now only checks for basic npot support
when creating a npot texture.  Since this change also affects the
automagic cogl_texture_ constructors they now check for basic npot +
mipmap support before considering using a Texture2D.

Notably the cogl_texture_ constructors will try constructing a Texture2D
even if we don't have npot + repeat support since the alternative is a
sliced texture which will need manual repeating anyway. Accordingly the
Texture2D::can_hardware_repeat and ::transform_quad_coords_to_gl vfuncs
have been made aware of the npot + repeat feature flag.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6f6c5734d076372d98d0ec331b177ef7d65aa67d)
2012-08-06 14:27:40 +01:00
Neil Roberts
b6b9ac0b85 Add a cogl-version header
This adds a version header which contains macros to define which
version of Cogl the application is being compiled against. This helps
applications that want to support multiple incompatible versions of
Cogl at compile time.

The macros are called COGL_VERSION_{MAJOR,MINOR,MICRO}. This does not
match Clutter which names them CLUTTER_{MAJOR,MINOR,MICRO}_VERSION but
I think the former is nicer and it at least matches Cairo and Pango.

The values of the macro are defined to COGL_VERSION_*_INTERNAL which
is generated by the configure script into cogl-defines.h.

There is also a macro for the entire version as a string called
COGL_VERSION_STRING.

The internal utility macros for encoding a 3 part version number into
a single integer have been moved into the new header so they can be
used publicly as a convenient way to check if the version is within a
particular range. There is also a COGL_VERSION_CHECK macro for the
very common case that a feature will be used since a particular
version of Cogl. There is a macro called COGL_VERSION which contains
the pre-encoded version of Cogl being compiled against for
convenience.

Unlike in Clutter this patch does not add any runtime version
identification mechanism.

A test case is also added which just contains static asserts to sanity
check the macros.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3480cf140dc355fa87ab3fbcf0aeeb0124798a8f)
2012-08-06 14:27:40 +01:00
Robert Bragg
8b22b0da65 journal: avoiding some _cogl_matrix_entry_get()'s
When uploading the vertices the journal calls _cogl_matrix_entry_get()
to get a CoglMatrix for each journal entry so that it can so a software
transform. Since _cogl_matrix_entry_get() can be a performance hot-spot
and since it's trivial to keep track of the last CoglMatrixEntry seen we
now avoid repeatedly calling _cogl_matrix_entry_get() for sequential
entries with the same transform.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 70cad61533316e2303b8e188f2f361701dfb0c61)
2012-08-06 14:27:40 +01:00
Robert Bragg
e3d6bc36d3 Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.

Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.

The first node in a matrix-stack is always a LOAD_IDENTITY operation.

As an example consider if an application where to draw three rectangles
A, B and C something like this:

cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);

  cogl_framebuffer_translate (fb, 10, 0, 0);

  cogl_framebuffer_push_matrix(fb);

    cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
    cogl_framebuffer_draw_rectangle (...); /* A */

  cogl_framebuffer_pop_matrix(fb);

  cogl_framebuffer_draw_rectangle (...); /* B */

cogl_framebuffer_pop_matrix(fb);

cogl_framebuffer_push_matrix(fb);
  cogl_framebuffer_set_modelview_matrix (fb, &mv);
  cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);

That would result in a graph of nodes like this:

LOAD_IDENTITY
      |
    SCALE
    /     \
SAVE       LOAD
  |           |
TRANSLATE    RECTANGLE(C)
  |     \
SAVE    RECTANGLE(B)
  |
ROTATE
  |
RECTANGLE(A)

Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.

Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
  complete, immutable transformation that can be logged for example
  into a journal. Previously we were storing a full CoglMatrix in
  each journal entry which is 16 floats for the matrix itself as well
  as space for flags and another 16 floats for possibly storing a
  cache of the inverse. This means that we significantly reduce
  the size of the journal when drawing lots of primitives and we also
  avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
  (unlikely) false negatives are allowed simply comparing the pointers
  of two matrix stack graph entries is enough. Previously we would use
  memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
  for the common ancestry between nodes we can determine the operations
  that differentiate the transforms and use those to gain a high level
  understanding of the differences. For example we use this in the
  journal to be able to efficiently determine when two rectangle
  transforms only differ by some translation so that we can perform
  software clipping.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-08-06 14:27:40 +01:00
Robert Bragg
882ff5612b Adds a "magazine" allocator for chunks of fixed size
This adds a very minimal and fast allocator for chunks of memory of a
predetermined size. This has some similarities to the glib slice
allocator although notably it is not thread safe and instead of
internally tracking multiple magazines for various sized allocations the
api lets you explicitly allocate a single magazine for a single specific
size and a pointer to the magazine is passed explicitly to the allocate
and free functions.

This allocator builds on the CoglMemoryStack allocator as an underlying
heap allocator and just never rewinds the stack. This means the heap is
effectively a grow only linked list of malloc()'d blocks of memory.

A CoglMagazine tracks a singly linked list of chunks of a predetermined
size and _cogl_magazine_chunk_alloc() simply unlinks and returns the
head of the list. If the list is empty it falls back to allocating from
the underlying stack.

_cogl_magazine_chunk_free() links the chunk back into the singly linked
list for re-use.

The chunk size passed to _cogl_magazine_new() is automatically rounded
to a multiple of 8 bytes to ensure that all stack allocations end up
aligned to 8 bytes. This also ensures that when a chunk is freed then it
will be large enough to store a pointer to the next free chunk as part
of a singly linked list.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 17799c2f109a008d6cf767f501b81aa9b32bbda8)
2012-08-06 14:27:40 +01:00
Robert Bragg
97d5406aef Adds internal CoglMemoryStack utility API
This adds a very minimal internal allocator api that lets us create a
dynamically growable (grow only) stack.

Underlying the allocator is the idea of "sub stacks" which are simply
malloc()'d chunks of memory kept in a linked list. The stack itself
maintains a pointer to the current sub-stack and a current
sub-stack-offset. 99% of the time allocating from the stack is just a
case of returning a pointer to the current sub-stack + sub-stack-offset
and bumping the offset by the allocation size. If there isn't room in
the current sub-stack then we walk through the list of free sub-stacks
looking for one that's big enough for the allocation and if we reach the
end of the list then we allocate a new sub-stack twice as big as the
last (or twice as big as the requested allocation if that's bigger).

Since it's a stack model there is no api to free allocations, just a
function to rewind the stack to the beginning.

We expect this to be useful in multiple places in Cogl as an extremely
fast allocator in cases when we know we can scrap all the allocations
after we're done figuring something out or as a building block for
other allocators.

For example the tessellator used for CoglPath allocates lots of tiny
structures that can all be freed after tessellation.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ee4a7a1b7f695bdfeb10ffa4112e776beea0a9d)
2012-08-06 14:27:40 +01:00
Robert Bragg
e58c7da9a8 build: Include stdint.h
Since 5967dad2400d32c we have stopped using glib types such as guint16
and guint32 in favour of the equivalent c99 types such as uint16_t and
uint32_t. When that patch was tested we must have used a configuration
that just happened to include <stdint.h> because we have since seen that
builds can fail due to missing c99 typedefs. This patch explicitly
includes stdint.h in cogl-types.h.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit c1e2220a4314071482d2d5638688b6bcf83882a2)
2012-08-06 14:27:39 +01:00
Neil Roberts
8dd77de009 Replace cogl_path_{stroke,fill} with framebuffer API
The existing functions for stroking and filling a path depend on the
global framebuffer and source stacks. These are now replaced with
cogl_framebuffer_{stroke,fill}_path which get explicitly passed the
framebuffer and pipeline.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 713a8f8160bc5884b091c69eb7a84b069e0950e6)
2012-08-06 14:27:39 +01:00
Robert Bragg
54735dec84 Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.

Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.

Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.

So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.

Instead of gsize we now use size_t

For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-08-06 14:27:39 +01:00
Robert Bragg
09642a83b5 Removes all remaining use of CoglHandle
Removing CoglHandle has been an on going goal for quite a long time now
and finally this patch removes the last remaining uses of the CoglHandle
type and the cogl_handle_ apis.

Since the big remaining users of CoglHandle were the cogl_program_ and
cogl_shader_ apis which have replaced with the CoglSnippets api this
patch removes both of these apis.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ed3aaf4be21d605a1ed3176b3ea825933f85cf0)

  Since the original patch was done after removing deprecated API
  this back ported patch doesn't affect deprecated API and so
  actually this cherry-pick doesn't remove all remaining use of
  CoglHandle as it did for the master branch of Cogl.
2012-08-06 14:27:39 +01:00
Robert Bragg
097d282b32 Add _COGL_STATIC_ASSERT macro
This adds a _COGL_STATIC_ASSERT macro that can be used for compile time
assertions in C code. If supported by the compiler this macro uses
_Static_assert so that a message can be printed out if the assertion
fails.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 465b39a764f2720e77678cafa56acb0e69007ffd)
2012-08-06 14:27:39 +01:00
Neil Roberts
eaf29af7ee bitmap-pixbuf: Fix the bitmap loader on Quartz
The code for loading a CoglBitmap from a file was missed when
upgrading to the new cogl_bitmap_new_for_data function in commit
d18b59d9e6 so it wouldn't compile. This changes it to use
_cogl_bitmap_new_with_malloc_buffer to allocate the buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=672533

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 5b785dd441a83024333e0a2f2b83d067f891194f)
2012-08-06 14:27:39 +01:00
Neil Roberts
d2a5d6f361 Add a context member to CoglPath
cogl_path_new now takes a CoglContext pointer which it keeps a pointer
to instead of relying on the global context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit afc63f8211c230f8fd1f7801f9085627c46a8661)

  Since we can't change the api on this branch this just applies
  the internal cleanups so we depend less on _COGL_GET_CONTEXT
2012-08-06 14:27:38 +01:00
Neil Roberts
6400b455b8 Don't include any GL header from the public GL headers
This splits the GL header inclusion from cogl-defines.h into a
separate headear called cogl-gl-header.h which we will only include
internally. That way we don't leak GL declarations out of our public
headers. The texture functions that were using GLenum and GLuint in
the public header have now changed to just use unsigned int. Note
however that if an EGL winsys is enabled then it will still publicly
include an EGL header. This is a bit more awkward to fix because we
have public API which returns an EGLDisplay and we can't determine
what type that is.

There is also a conformance test which just verifies that no GL header
has been included while compiling. The test isn't added to
test-conform-main because it doesn't actually test anything at
runtime.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
2012-08-06 14:27:38 +01:00
Chun-wei Fan
e85a04f0ce Fix cogl.symbols
cogl_framebuffer_draw_multitextured_rectangles is not in the public
API list, it is instead _cogl_framebuffer_draw_multitextured_rectangles,
which is private.

(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 4fc6cf5e3c1478bc0a29dfaf2f6d9e84b9d29ccd)
2012-08-06 14:27:38 +01:00
Chun-wei Fan
fa88ed8d74 cogl/Makefile.am: Fix filters for MSVC projects
We need to filter out all the *-egl-* sources as well, as the original
filter did not filter out the Wayland EGL sources

(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 3d4cb887a28d3bc2cde9e4e7cdd20a71c34a2eaa)
2012-08-06 14:27:38 +01:00
Damien Lespiau
943afe5711 winsys-glx: Remove unused variable
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 2cffcae81fd91d97bfa239e8c7c6a5b2cefb2653)
2012-08-06 14:27:38 +01:00
Robert Bragg
9a1f1df83f Rework sdl integration api
This re-works the SDL integration api to simplify the integration for
application developers and also allow Cogl to know when the application
is about to go idle waiting for events so it can perform idle
book-keeping work.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-12 12:31:46 +01:00
Robert Bragg
bdb645e7f5 kms: defer setting crtc modes until first swap buffers
Instead of creating a dummy framebuffer allocation just so we can setup
crtc modes during display_setup we now wait until the first swap_buffers
request before setting up the crtc modes.

This patch also adds a cogl_kms_display_queue_modes_reset() function
that allows developers to explicitly queue a reset of the crtc modes.
The idea is that applications that handle VT switching can use this for
VT enter events to explicitly ensure their mode is restored since modes
are often not automatically restored correctly.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Robert Bragg
125c31a70b kms: Add mirror support and env var configurability
This adds support for mirroring the display output on two KMS
connectors.

This patch also checks for a number of environment variables that can
influence how KMS is configured. The following variables can be set:

COGL_KMS_MIRROR: If this is set to anything then Cogl will try and setup
two connectors with the same resolution so that onscreen frame buffers
can be mirrored.

COGL_KMS_CONNECTOR0: This can be set to an integer identifier for a
specific KMS connector id to use for the first output.

COGL_KMS_CONNECTOR0_MODE: Can be set to a mode name like "1024x768"
explicitly select what mode should be used for the first output.

If COGL_KMS_MIRROR is set then COGL_KMS_CONNECTOR1 and
COGL_KMS_CONNECTOR1_MODE can optionally be set to specify a connector id
and mode name for the second output.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Neil Roberts
f9d3ea03ec kms: Implement the swap buffers notify feature
The KMS EGL platform now notifies when a swap is complete. The
notification is delayed until the application calls
cogl_context_dispatch. The GLX backend doesn't currently do this but I
think that is how it should behave to make it easier for the
application to handle locks and such.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:50 +01:00
Neil Roberts
cfefff1500 egl-kms: Use drmModePageFlip
The KMS platform now uses drmModePageFlip to present the buffer. The
main loop mechanism is used to poll for events on the DRM file
descriptor so that we notice when the page flip is complete. The
swap_buffers is throttled so that if there is a pending flip it will
block until it is complete before starting another flip.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:45 +01:00
Neil Roberts
d1d2120a91 kms: Use GBM surfaces
Instead of creating FBOs on the GL side, the KMS EGL platform uses the
latest changes to Mesa to create an EGL surface using a GBM surface as
the native surface type. This removes some of the special vtable hooks
that the KMS platform needed because it is now much more similar to
the other platforms.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:32 +01:00
Robert Bragg
cc4c578887 fix cogl_context_new crash if fail to connect renderer
If a NULL display is passed to cogl_context_new() then it has to
implicitly create a CoglRenderer and CoglDisplay and propagate any
resulting errors back to the user. Previously the implementation relied
on passing a NULL renderer to cogl_display_new() as the means for
implicitly connecting to a renderer. The problem with this though is
that cogl_display_new() isn't designed to ever return NULL but if it
failed to connect to a renderer automatically it would do and then
cogl_context_new would pass NULL to cogl_display_setup() leading to a
crash.

This patch changes the implementation of cogl_context_new() to now
explicitly create a CoglRenderer and connect to it if a NULL display is
given. This way we can easily propagate any errors. In addition
cogl_display_new has been changed to abort if it fails to implicitly
connect to a renderer due to a NULL renderer argument.

An application needing to gracefully handle problems connecting to a
renderer at runtime should manually instantiate and connect a renderer
passing a GError argument to cogl_renderer_connect.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 12:26:52 +01:00
Neil Roberts
f676785906 Fix including a non-existent header
cogl-sampler-cache-private.h was including a header which doesn't
exist so the build was broken. The header comes from a patch which
hasn't been pushed to master yet which splits including GL/gl.h out of
cogl-defines.h into a separate header. I added the inclusion to make
it pick up the GL defines but it doesn't need to do this yet because
cogl-context.h is still including the GL header. I didn't notice the
failure because I still had a cogl-gl-header.h lying around from a
previous build with the patch.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 15:35:01 +01:00
Neil Roberts
cb146dc515 Add a workaround for slow read pixels on Mesa
Mesa before version 8.0.2 has a slow read pixels path that gets used
with the Intel driver where it converts all of the pixels into a
floating point representation and back even if the data is being read
into exactly the same format. There is however a faster path using the
blitter when reading into a PBO with BGRA format. It works out faster
to read into a PBO and then memcpy back out into the application's
buffer even though it adds an extra memcpy. This patch adds a
workaround in cogl_framebuffer_read_pixels_into_bitmap when it detects
this situation. In that case it will create a temporary CoglBitmap
using cogl_bitmap_new_with_size, read into it and then memcpy the data
back out.

The main impetus for this patch is that Gnome Shell has implemented
this workaround directly using GL calls but it seems like the kind of
thing that would sit better at the Cogl layer.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:52:43 +01:00
Neil Roberts
2037e0f4f1 Add a mechanism for determining GPU driver details
This adds a CoglGpuInfo struct to the CoglContext which contains some
enums describing the GL driver in use. This currently includes the
driver package (ie, is it Mesa) the version number of the package and
the vendor of the GPU (ie, is it by Intel). There is also a bitmask
which will contain the workarounds that we should do for that
particular driver configuration. The struct is initialised on context
creation by using a series of string comparisons on the strings
returned from glGetString.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:52:43 +01:00
Neil Roberts
ec5009fa23 Use GL_PACK_ALIGNMENT of 1 whenever possible
The Intel driver currently has an optimisation when calling
glReadPixels into a PBO so that it will use a blit instead of the Mesa
fallback path. However this only works if the GL_PACK_ALIGNMENT is
exactly 1, even if this would be equivalent to a higher alignment
value because the bpp*width is already aligned. To make it more likely
to hit this fast path, we now detect this situation and explicitly use
an alignment of 1. To make this work the texture driver needs to be
passed down the bpp*width as well as the rowstride when configuring
the alignment.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:51:56 +01:00
Neil Roberts
d54111795f Use ffs to calculate the GL_{UN,}PACK_ALIGNMENT
Instead of having a series of if-statements this adds an inline
function to calculate the alignment directly using ffs which is
probably slightly faster. Admittedly this is a pointless
micro-optimisation but I think it makes the code looks a bit neater
anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:51:56 +01:00
Neil Roberts
c33ce5fc6b Use GL_ARB_sampler_objects
GL_ARB_sampler_objects provides a GL object which overrides the
sampler state part of a texture object with different values. The
sampler state that Cogl currently exposes is the wrap modes and
filters. Cogl exposes the state as part of the pipeline layer state
but without this extension GL only exposes it as part of the texture
object state. This means that it won't work to use a single texture
multiple times in one primitive with different sampler states. It also
makes switching between different sampler states with a single texture
not terribly efficient because it has to change the texture object
state every time.

This patch adds a cache for sampler states in a shared hash table
attached to the CoglContext. The entire set of parameters for the
sampler state is used as the key for the hash table. When a unique
state is encountered the sampler cache will create a new entry,
otherwise it will return a const pointer to an existing entry. That
means we can have a single pointer to represent any combination of
sampler state.

Pipeline layers now just store this single pointer rather than storing
all of the sampler state. The two separate state flags for wrap modes
and filters have now been combined into one. It should be faster to
compare the sampler state now because instead of comparing each value
it can just compare the pointers to the cached sampler entries. The
hash table of cached sampler states should only need to perform its
more expensive hash on the state when a property is changed on a
pipeline, not every time it is flushed.

When the sampler objects extension is available each cached sampler
state will also get a sampler object to represent it. The common code
to flush the GL state will now simply bind this object to a unit
instead of flushing the state though the CoglTexture when possible.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:36 +01:00
Neil Roberts
4229d61d3b Fix places that ignore the COGL_TEXTURE_NO_AUTO_MIPMAP flag
Two of the meta texture constructors which take a flags parameter were
ignoring the COGL_TEXTURE_NO_AUTO_MIPMAP flag when creating an
underlying CoglTexture2D. These have now been fixed to call
cogl_primitive_texture_set_auto_mipmap after constructing the texture.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:36 +01:00
Neil Roberts
6197e3abf3 Add constructors which take a CoglBitmap to all primitive textures
This adds public constructors which take a CoglBitmap to all primitive
texture types. This constructor should be considered the canonical
constructor for initializing the texture with data because it should
be possible to wrap any type of data in a CoglBitmap. Having at least
this single constructor avoids the need to have an explosion of
constructors such as new_from_data, new_from_pixel_buffer and
new_from_file etc.

The already available internal bitmap constructor for CoglTexture2D
has had its flags parameter removed under the assumption that flags do
not make sense for primitive textures. The meta constructor
cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap
after constructing the texture depending on the value of the
COGL_TEXTURE_NO_AUTO_MIPMAP flag.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-05 13:47:32 +01:00
Neil Roberts
e7f1582630 Add a CoglPrimitiveTexture interface
This interface represents any textures that are backed by a single
texture in GL and that can be used directly with the
cogl_framebuffer_draw_attributes family of functions. This currently
equates to CoglTexture2D, CoglTexture3D and CoglTextureRectangle.

The interface currently has only one method called
cogl_primitive_set_auto_mipmap. This replaces the
COGL_TEXTURE_NO_AUTO_MIPMAP flag from the CoglTextureFlags parameter
in the constructors. None of the other flags in CoglTextureFlags make
sense for primitive textures so it doesn't seem like a good idea to
need them for primitive constructors.

There is a boolean in the vtable to mark whether a texture type is
primitive which the new cogl_is_primitive function uses. There is also
a new texture virtual called set_auto_mipmap which is only required to
be implemented for primitive textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 17:02:23 +01:00
Neil Roberts
e7df2dbf79 bitmap: Store a pointer to the context
This adds a context member to CoglBitmap which stores the context it
was created with. That way it can be used in texture constructors
which use a bitmap. There is also an internal private function to get
the context out of the bitmap which all of the texture constructors
now use. _cogl_texture_3d_new_from_bitmap has had its context
parameter removed so that it more closely matches the other bitmap
constructors.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 14:24:01 +01:00
Neil Roberts
be9d5b34c6 pipeline: Use cogl_depth_state_init to init default depth state
The previous code to initialise the depth state on the default
pipeline wasn't initialising the magic number. If you later tried to
retrieve the depth state using cogl_pipeline_get_depth_state you would
end up with an invalid depth state struct and you would just get
warnings if you tried to use it for anything. This patch just replaces
the initialisation with a call to cogl_depth_state_init because it
uses the same values anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-03 16:36:54 +01:00
Adel Gadllah
a000189c68 texture: Fix error handling in get_texture_bits_via_offscreen
get_texture_bits_via_offscreen does not check the return value of
cogl_framebuffer_read_pixels_into_bitmap which results into never
using the fallback path texture_get_cb.

cogl_framebuffer_read_pixels_into_bitmap does not check whether the framebuffer
is properly allocated though; so fix that as well.

https://bugzilla.gnome.org/show_bug.cgi?id=673137

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-02 23:32:53 +01:00
Neil Roberts
ae5f8323c1 gles2: Support the GL_EXT_unpack_subimage extension
This extension lets you upload texture data from a subregion of a
buffer by passing GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS and
GL_UNPACK_SKIP_ROWS to glPixelStore. When this extension is available
the GLES texture driver will now avoid making a copy of the bitmap
when a subregion is used.

Note that Mesa doesn't currently advertise this extension but I've
made a patch to propose it:

http://lists.freedesktop.org/archives/mesa-dev/2012-March/020191.html
2012-03-23 13:51:08 +00:00
Neil Roberts
21e304b339 gles: Support the GL_EXT_texture_format_BGRA8888 extension
This extension allows an application to upload data in BGRA format. We
can use this to avoid a conversion in Cogl whenever it is given BGRA
data. This is quite useful when uploading data generated by Cairo
because at least on little-endian architectures that ends up as BGRA.

The patch just makes the pixel_format_to_gl implementation return
GL_BGRA_EXT for the data format and internal format whenever
COGL_PIXEL_FORMAT_BGRA_8888{,_PRE} is used.

A small caveat with this patch is that once a texture is created as
GL_BGRA, when later using glTexSubImage2D to update the texture it
must always be given data as GL_BGRA. Currently this just works out
because we store the internal format of a texture as a CoglPixelFormat
and we already swizzle the data if it does not match exactly on GLES.
However if we later switch to using a different enum for internal
formats then we might lose the ability to store the component ordering
so we'll have to think of another way to do this.
2012-03-23 13:51:08 +00:00