2008-12-16 21:30:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Eric Anholt <eric@anholt.net>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-16 23:00:05 +01:00
|
|
|
/** @file glamor.c
|
2008-12-16 21:30:14 +01:00
|
|
|
* This file covers the initialization and teardown of glamor, and has various
|
|
|
|
* functions not responsible for performing rendering.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2008-12-16 23:00:05 +01:00
|
|
|
|
2008-12-17 00:14:31 +01:00
|
|
|
#include "glamor_priv.h"
|
|
|
|
|
2011-04-08 09:24:55 +02:00
|
|
|
static DevPrivateKeyRec glamor_screen_private_key_index;
|
2008-12-17 00:14:31 +01:00
|
|
|
DevPrivateKey glamor_screen_private_key = &glamor_screen_private_key_index;
|
2011-04-08 09:24:55 +02:00
|
|
|
static DevPrivateKeyRec glamor_pixmap_private_key_index;
|
2009-08-21 00:28:13 +02:00
|
|
|
DevPrivateKey glamor_pixmap_private_key = &glamor_pixmap_private_key_index;
|
2008-12-17 00:14:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* glamor_get_drawable_pixmap() returns a backing pixmap for a given drawable.
|
|
|
|
*
|
|
|
|
* @param drawable the drawable being requested.
|
|
|
|
*
|
|
|
|
* This function returns the backing pixmap for a drawable, whether it is a
|
|
|
|
* redirected window, unredirected window, or already a pixmap. Note that
|
|
|
|
* coordinate translation is needed when drawing to the backing pixmap of a
|
|
|
|
* redirected window, and the translation coordinates are provided by calling
|
|
|
|
* exaGetOffscreenPixmap() on the drawable.
|
|
|
|
*/
|
|
|
|
PixmapPtr
|
|
|
|
glamor_get_drawable_pixmap(DrawablePtr drawable)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
if (drawable->type == DRAWABLE_WINDOW)
|
|
|
|
return drawable->
|
|
|
|
pScreen->GetWindowPixmap((WindowPtr) drawable);
|
|
|
|
else
|
|
|
|
return (PixmapPtr) drawable;
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|
|
|
|
|
2011-12-12 00:09:03 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type)
|
|
|
|
{
|
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(pixmap->drawable.pScreen);
|
|
|
|
|
2012-04-15 16:47:48 +02:00
|
|
|
pixmap_priv = dixLookupPrivate(&pixmap->devPrivates,
|
|
|
|
glamor_pixmap_private_key);
|
2011-12-12 00:09:03 +01:00
|
|
|
if (pixmap_priv == NULL) {
|
|
|
|
pixmap_priv = calloc(sizeof(*pixmap_priv), 1);
|
2012-02-02 02:34:42 +01:00
|
|
|
glamor_set_pixmap_private(pixmap, pixmap_priv);
|
2011-12-12 00:09:03 +01:00
|
|
|
pixmap_priv->container = pixmap;
|
|
|
|
pixmap_priv->glamor_priv = glamor_priv;
|
|
|
|
}
|
|
|
|
pixmap_priv->type = type;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
_X_EXPORT void
|
2012-01-18 10:12:32 +01:00
|
|
|
glamor_set_pixmap_texture(PixmapPtr pixmap, unsigned int tex)
|
2011-05-11 09:54:50 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
glamor_pixmap_private *pixmap_priv;
|
2012-01-18 10:12:32 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_pixmap_fbo *fbo;
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
GLenum format;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2012-01-18 10:12:32 +01:00
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
2011-11-02 06:44:50 +01:00
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2012-01-18 10:12:32 +01:00
|
|
|
|
2012-01-18 12:21:36 +01:00
|
|
|
if (pixmap_priv->fbo) {
|
|
|
|
fbo = glamor_pixmap_detach_fbo(pixmap_priv);
|
|
|
|
glamor_destroy_fbo(fbo);
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
gl_iformat_for_depth(pixmap->drawable.depth, &format);
|
2012-01-18 12:21:36 +01:00
|
|
|
fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap->drawable.width,
|
|
|
|
pixmap->drawable.height,
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
format, tex, 0);
|
2012-01-10 10:04:48 +01:00
|
|
|
|
2012-01-18 12:21:36 +01:00
|
|
|
if (fbo == NULL) {
|
|
|
|
ErrorF("XXX fail to create fbo.\n");
|
|
|
|
return;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_pixmap_attach_fbo(pixmap, fbo);
|
2011-05-11 09:54:50 +02:00
|
|
|
}
|
|
|
|
|
glamor : Add dynamic texture uploading feature.
Major refactoring.
1. Rewrite the pixmap texture uploading and downloading functions.
Add some new functions for both the prepare/finish access and
the new performance feature dynamic texture uploading, which
could download and upload the current image to/from a private
texture/fbo. In the uploading or downloading phase, we need to
handle two things:
The first is the yInverted option, If it set, then we don't need
to flip y. If not set, if it is from a dynamic texture uploading
then we don't need to flip either if the current drawing process
will flip it latter. If it is from finish_access, then we must
flip the y axis.
The second thing is the alpha channel hanlding, if the pixmap's
format is something like x8a8r8g8, x1r5g5b5 which means it doesn't
has alpha channel, but it do has those extra bits. Then we need to
wire those bits to 1.
2. Add almost all the required picture format support.
This is not as trivial as it looks like. The previous implementation
only support GL_a8,GL_a8r8g8b8,GL_x8r8g8b8. All the other format,
we have to fallback to cpu. The reason why we can't simply add those
other color format is because the exists of picture. one drawable
pixmap may has one or even more container pictures. The drawable pixmap's
depth can't map to a specified color format, for example depth 16 can
mapped to r5g6b5, x1r5g5b5, a1r5g5b5, or even b5g6r5. So we can't get
get the color format just from the depth value. But the pixmap do not
has a pict_format element. We have to make a new one in the pixmap
private data structure. Reroute the CreatePicture to glamor_create_picture
and then store the picture's format to the pixmap's private structure.
This is not an ideal solution, as there may be more than one pictures
refer to the same pixmap. Then we will have trouble. There is an example
in glamor_composite_with_shader. The source and mask often share the
same pixmap, but use different picture format. Our current solution is to
combine those two different picture formats to one which will not lose any
data. Then change the source's format to this new format and then upload
the pixmap to texture once. It works. If we fail to find a matched new
format then we fallback.
There still is a potential problem, if two pictures refer to the same
pixmap, and one of them destroy the picture, but the other still remained
to be used latter. We don't handle that situation currently. To be fixed.
3. Dynamic texture uploading.
This is a performance feature. Although we don't like the client to hold
a pixmap data to shared memory and we can't accelerate it. And even worse,
we may need to fallback all the required pixmaps to cpu memory and then
process them on CPU. This feature is to mitigate this penalty. When the
target pixmap has a valid gl fbo attached to it. But the other pixmaps are
not. Then it will be more efficient to upload the other pixmaps to GPU and
then do the blitting or rendering on GPU than fallback all the pixmaps to CPU.
To enable this feature, I experienced a significant performance improvement
in the Game "Mines" :).
4. Debug facility.
Modify the debug output mechanism. Now add a new macro:
glamor_debug_output(_level_, _format_,...) to conditional output some messages
according to the environment variable GLAMOR_DEBUG. We have the following
levels currently.
exports GLAMOR_DEBUG to 3 will enable all the above messages.
5. Changes in pixmap private data structure.
Add some for the full color format supports and relate it to the pictures which
already described. Also Add the following new elements:
gl_fbo - to indicates whether this pixmap is on gpu only.
gl_tex - to indicates whether the tex is valid and is containing the pixmap's
image originally.
As we bring the dynamic pixmap uploading feature, so a cpu memory pixmap may
also has a valid fbo or tex attached to it. So we will have to use the above
new element to check it true type.
After this commit, we can pass the rendercheck testing for all the picture formats.
And is much much fater than fallback to cpu when doing rendercheck testing.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-06-21 12:31:11 +02:00
|
|
|
void
|
2012-02-17 09:56:05 +01:00
|
|
|
glamor_set_screen_pixmap(PixmapPtr screen_pixmap, PixmapPtr *back_pixmap)
|
glamor : Add dynamic texture uploading feature.
Major refactoring.
1. Rewrite the pixmap texture uploading and downloading functions.
Add some new functions for both the prepare/finish access and
the new performance feature dynamic texture uploading, which
could download and upload the current image to/from a private
texture/fbo. In the uploading or downloading phase, we need to
handle two things:
The first is the yInverted option, If it set, then we don't need
to flip y. If not set, if it is from a dynamic texture uploading
then we don't need to flip either if the current drawing process
will flip it latter. If it is from finish_access, then we must
flip the y axis.
The second thing is the alpha channel hanlding, if the pixmap's
format is something like x8a8r8g8, x1r5g5b5 which means it doesn't
has alpha channel, but it do has those extra bits. Then we need to
wire those bits to 1.
2. Add almost all the required picture format support.
This is not as trivial as it looks like. The previous implementation
only support GL_a8,GL_a8r8g8b8,GL_x8r8g8b8. All the other format,
we have to fallback to cpu. The reason why we can't simply add those
other color format is because the exists of picture. one drawable
pixmap may has one or even more container pictures. The drawable pixmap's
depth can't map to a specified color format, for example depth 16 can
mapped to r5g6b5, x1r5g5b5, a1r5g5b5, or even b5g6r5. So we can't get
get the color format just from the depth value. But the pixmap do not
has a pict_format element. We have to make a new one in the pixmap
private data structure. Reroute the CreatePicture to glamor_create_picture
and then store the picture's format to the pixmap's private structure.
This is not an ideal solution, as there may be more than one pictures
refer to the same pixmap. Then we will have trouble. There is an example
in glamor_composite_with_shader. The source and mask often share the
same pixmap, but use different picture format. Our current solution is to
combine those two different picture formats to one which will not lose any
data. Then change the source's format to this new format and then upload
the pixmap to texture once. It works. If we fail to find a matched new
format then we fallback.
There still is a potential problem, if two pictures refer to the same
pixmap, and one of them destroy the picture, but the other still remained
to be used latter. We don't handle that situation currently. To be fixed.
3. Dynamic texture uploading.
This is a performance feature. Although we don't like the client to hold
a pixmap data to shared memory and we can't accelerate it. And even worse,
we may need to fallback all the required pixmaps to cpu memory and then
process them on CPU. This feature is to mitigate this penalty. When the
target pixmap has a valid gl fbo attached to it. But the other pixmaps are
not. Then it will be more efficient to upload the other pixmaps to GPU and
then do the blitting or rendering on GPU than fallback all the pixmaps to CPU.
To enable this feature, I experienced a significant performance improvement
in the Game "Mines" :).
4. Debug facility.
Modify the debug output mechanism. Now add a new macro:
glamor_debug_output(_level_, _format_,...) to conditional output some messages
according to the environment variable GLAMOR_DEBUG. We have the following
levels currently.
exports GLAMOR_DEBUG to 3 will enable all the above messages.
5. Changes in pixmap private data structure.
Add some for the full color format supports and relate it to the pictures which
already described. Also Add the following new elements:
gl_fbo - to indicates whether this pixmap is on gpu only.
gl_tex - to indicates whether the tex is valid and is containing the pixmap's
image originally.
As we bring the dynamic pixmap uploading feature, so a cpu memory pixmap may
also has a valid fbo or tex attached to it. So we will have to use the above
new element to check it true type.
After this commit, we can pass the rendercheck testing for all the picture formats.
And is much much fater than fallback to cpu when doing rendercheck testing.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-06-21 12:31:11 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_pixmap_private *pixmap_priv;
|
2012-01-18 10:12:32 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_priv = glamor_get_screen_private(screen_pixmap->drawable.pScreen);
|
2012-01-18 10:12:32 +01:00
|
|
|
pixmap_priv = glamor_get_pixmap_private(screen_pixmap);
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_priv->screen_fbo = pixmap_priv->fbo->fb;
|
|
|
|
|
|
|
|
pixmap_priv->fbo->width = screen_pixmap->drawable.width;
|
|
|
|
pixmap_priv->fbo->height = screen_pixmap->drawable.height;
|
2012-02-17 09:56:05 +01:00
|
|
|
|
|
|
|
glamor_priv->back_pixmap = back_pixmap;
|
glamor : Add dynamic texture uploading feature.
Major refactoring.
1. Rewrite the pixmap texture uploading and downloading functions.
Add some new functions for both the prepare/finish access and
the new performance feature dynamic texture uploading, which
could download and upload the current image to/from a private
texture/fbo. In the uploading or downloading phase, we need to
handle two things:
The first is the yInverted option, If it set, then we don't need
to flip y. If not set, if it is from a dynamic texture uploading
then we don't need to flip either if the current drawing process
will flip it latter. If it is from finish_access, then we must
flip the y axis.
The second thing is the alpha channel hanlding, if the pixmap's
format is something like x8a8r8g8, x1r5g5b5 which means it doesn't
has alpha channel, but it do has those extra bits. Then we need to
wire those bits to 1.
2. Add almost all the required picture format support.
This is not as trivial as it looks like. The previous implementation
only support GL_a8,GL_a8r8g8b8,GL_x8r8g8b8. All the other format,
we have to fallback to cpu. The reason why we can't simply add those
other color format is because the exists of picture. one drawable
pixmap may has one or even more container pictures. The drawable pixmap's
depth can't map to a specified color format, for example depth 16 can
mapped to r5g6b5, x1r5g5b5, a1r5g5b5, or even b5g6r5. So we can't get
get the color format just from the depth value. But the pixmap do not
has a pict_format element. We have to make a new one in the pixmap
private data structure. Reroute the CreatePicture to glamor_create_picture
and then store the picture's format to the pixmap's private structure.
This is not an ideal solution, as there may be more than one pictures
refer to the same pixmap. Then we will have trouble. There is an example
in glamor_composite_with_shader. The source and mask often share the
same pixmap, but use different picture format. Our current solution is to
combine those two different picture formats to one which will not lose any
data. Then change the source's format to this new format and then upload
the pixmap to texture once. It works. If we fail to find a matched new
format then we fallback.
There still is a potential problem, if two pictures refer to the same
pixmap, and one of them destroy the picture, but the other still remained
to be used latter. We don't handle that situation currently. To be fixed.
3. Dynamic texture uploading.
This is a performance feature. Although we don't like the client to hold
a pixmap data to shared memory and we can't accelerate it. And even worse,
we may need to fallback all the required pixmaps to cpu memory and then
process them on CPU. This feature is to mitigate this penalty. When the
target pixmap has a valid gl fbo attached to it. But the other pixmaps are
not. Then it will be more efficient to upload the other pixmaps to GPU and
then do the blitting or rendering on GPU than fallback all the pixmaps to CPU.
To enable this feature, I experienced a significant performance improvement
in the Game "Mines" :).
4. Debug facility.
Modify the debug output mechanism. Now add a new macro:
glamor_debug_output(_level_, _format_,...) to conditional output some messages
according to the environment variable GLAMOR_DEBUG. We have the following
levels currently.
exports GLAMOR_DEBUG to 3 will enable all the above messages.
5. Changes in pixmap private data structure.
Add some for the full color format supports and relate it to the pictures which
already described. Also Add the following new elements:
gl_fbo - to indicates whether this pixmap is on gpu only.
gl_tex - to indicates whether the tex is valid and is containing the pixmap's
image originally.
As we bring the dynamic pixmap uploading feature, so a cpu memory pixmap may
also has a valid fbo or tex attached to it. So we will have to use the above
new element to check it true type.
After this commit, we can pass the rendercheck testing for all the picture formats.
And is much much fater than fallback to cpu when doing rendercheck testing.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-06-21 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
2011-12-11 23:56:36 +01:00
|
|
|
PixmapPtr
|
2008-12-17 00:14:31 +01:00
|
|
|
glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
|
2009-08-21 00:28:13 +02:00
|
|
|
unsigned int usage)
|
2008-12-17 00:14:31 +01:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
PixmapPtr pixmap;
|
2011-12-12 00:09:03 +01:00
|
|
|
glamor_pixmap_type_t type = GLAMOR_TEXTURE_ONLY;
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_pixmap_fbo *fbo;
|
|
|
|
int pitch;
|
|
|
|
int flag;
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
GLenum format;
|
2012-01-18 12:21:36 +01:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (w > 32767 || h > 32767)
|
|
|
|
return NullPixmap;
|
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
if (usage == GLAMOR_CREATE_PIXMAP_CPU
|
|
|
|
|| (w == 0 && h == 0)
|
|
|
|
|| !glamor_check_pixmap_fbo_depth(depth))
|
2012-01-18 12:21:36 +01:00
|
|
|
return fbCreatePixmap(screen, w, h, depth, usage);
|
2012-01-21 06:22:14 +01:00
|
|
|
else
|
2011-11-02 06:44:50 +01:00
|
|
|
pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
|
2011-05-11 09:54:50 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
pixmap_priv = calloc(1, sizeof(*pixmap_priv));
|
2012-01-18 12:21:36 +01:00
|
|
|
|
2012-01-21 06:22:14 +01:00
|
|
|
if (!pixmap_priv) {
|
|
|
|
fbDestroyPixmap(pixmap);
|
2012-01-18 12:21:36 +01:00
|
|
|
return fbCreatePixmap(screen, w, h, depth, usage);
|
2012-01-21 06:22:14 +01:00
|
|
|
}
|
2012-02-02 02:34:42 +01:00
|
|
|
glamor_set_pixmap_private(pixmap, pixmap_priv);
|
2012-01-18 12:21:36 +01:00
|
|
|
|
2012-04-09 14:16:07 +02:00
|
|
|
if (usage == GLAMOR_CREATE_PIXMAP_MAP)
|
|
|
|
type = GLAMOR_MEMORY_MAP;
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
pixmap_priv->container = pixmap;
|
|
|
|
pixmap_priv->glamor_priv = glamor_priv;
|
2011-12-12 00:09:03 +01:00
|
|
|
pixmap_priv->type = type;
|
2012-01-18 12:21:36 +01:00
|
|
|
|
gles2: Fixed color conversion for the formats except 1555 and 2101010.
This patch fixed two major problems when we do the color convesion with
GLES2.
1. lack of necessary formats in FBO pool.
GLES2 has three different possible texture formats, GL_RGBA,
GL_BGRA and GL_ALPHA. Previous implementation only has one bucket
for all the three formats which may reuse a incorrect texture format
when do the cache lookup. After this fix, we can enable fbo safely
when running with GLES2.
2. Refine the format matching method in
glamor_get_tex_format_type_from_pictformat.
If both revertion and swap_rb are needed, for example use GL_RGBA
to represent PICT_b8g8r8a8. Then the downloading and uploading should
be handled differently.
The picture's format is PICT_b8g8r8a8,
Then the expecting color layout is as below (little endian):
0 1 2 3 : address
a r g b
Now the in GLES2 the supported color format is GL_RGBA, type is
GL_UNSIGNED_TYPE, then we need to shuffle the fragment
color as :
frag_color = sample(texture).argb;
before we use glReadPixel to get it back.
For the uploading process, the shuffle is a revert shuffle.
We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
to a texture, then let's see
0 1 2 3 : address
a r g b : correct colors
R G B A : GL_RGBA with GL_UNSIGNED_BYTE
Now we need to shuffle again, the mapping rule is
r = G, g = B, b = A, a = R. Then the uploading shuffle is as
below:
frag_color = sample(texture).gbar;
After this commit, gles2 version can pass render check with all
the formats except those 1555/2101010.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-04-05 15:53:44 +02:00
|
|
|
gl_iformat_for_depth(depth, &format);
|
|
|
|
fbo = glamor_create_fbo(glamor_priv, w, h, format, usage);
|
2012-01-18 12:21:36 +01:00
|
|
|
|
|
|
|
if (fbo == NULL) {
|
|
|
|
fbDestroyPixmap(pixmap);
|
|
|
|
free(pixmap_priv);
|
|
|
|
return fbCreatePixmap(screen, w, h, depth, usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_pixmap_attach_fbo(pixmap, fbo);
|
2011-12-12 00:09:03 +01:00
|
|
|
|
2012-01-18 12:21:36 +01:00
|
|
|
pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3;
|
|
|
|
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL);
|
2011-11-02 06:44:50 +01:00
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_destroy_textured_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
if (pixmap->refcnt == 1) {
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2011-11-02 06:44:50 +01:00
|
|
|
if (pixmap_priv != NULL) {
|
2012-01-18 12:21:36 +01:00
|
|
|
glamor_pixmap_fbo *fbo;
|
|
|
|
fbo = glamor_pixmap_detach_fbo(pixmap_priv);
|
|
|
|
if (fbo)
|
|
|
|
glamor_destroy_fbo(fbo);
|
2011-11-02 06:44:50 +01:00
|
|
|
free(pixmap_priv);
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|
|
|
|
|
2011-12-11 23:56:36 +01:00
|
|
|
Bool
|
2008-12-17 00:14:31 +01:00
|
|
|
glamor_destroy_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_destroy_textured_pixmap(pixmap);
|
|
|
|
return fbDestroyPixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_block_handler(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_gl_dispatch *dispatch;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2012-02-10 13:54:44 +01:00
|
|
|
dispatch = glamor_get_dispatch(glamor_priv);
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_priv->tick++;
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glFlush();
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_fbo_expire(glamor_priv);
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_put_dispatch(glamor_priv);
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|
2008-12-16 23:00:05 +01:00
|
|
|
|
2008-12-20 22:48:39 +01:00
|
|
|
static void
|
2011-11-02 06:44:50 +01:00
|
|
|
_glamor_block_handler(void *data, OSTimePtr timeout,
|
|
|
|
void *last_select_mask)
|
2008-12-20 22:48:39 +01:00
|
|
|
{
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_screen_private *glamor_priv = data;
|
|
|
|
glamor_gl_dispatch *dispatch = glamor_get_dispatch(glamor_priv);
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glFlush();
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_put_dispatch(glamor_priv);
|
2008-12-20 22:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-02 06:44:50 +01:00
|
|
|
_glamor_wakeup_handler(void *data, int result, void *last_select_mask)
|
2008-12-20 22:48:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
static void
|
glamor : Add dynamic texture uploading feature.
Major refactoring.
1. Rewrite the pixmap texture uploading and downloading functions.
Add some new functions for both the prepare/finish access and
the new performance feature dynamic texture uploading, which
could download and upload the current image to/from a private
texture/fbo. In the uploading or downloading phase, we need to
handle two things:
The first is the yInverted option, If it set, then we don't need
to flip y. If not set, if it is from a dynamic texture uploading
then we don't need to flip either if the current drawing process
will flip it latter. If it is from finish_access, then we must
flip the y axis.
The second thing is the alpha channel hanlding, if the pixmap's
format is something like x8a8r8g8, x1r5g5b5 which means it doesn't
has alpha channel, but it do has those extra bits. Then we need to
wire those bits to 1.
2. Add almost all the required picture format support.
This is not as trivial as it looks like. The previous implementation
only support GL_a8,GL_a8r8g8b8,GL_x8r8g8b8. All the other format,
we have to fallback to cpu. The reason why we can't simply add those
other color format is because the exists of picture. one drawable
pixmap may has one or even more container pictures. The drawable pixmap's
depth can't map to a specified color format, for example depth 16 can
mapped to r5g6b5, x1r5g5b5, a1r5g5b5, or even b5g6r5. So we can't get
get the color format just from the depth value. But the pixmap do not
has a pict_format element. We have to make a new one in the pixmap
private data structure. Reroute the CreatePicture to glamor_create_picture
and then store the picture's format to the pixmap's private structure.
This is not an ideal solution, as there may be more than one pictures
refer to the same pixmap. Then we will have trouble. There is an example
in glamor_composite_with_shader. The source and mask often share the
same pixmap, but use different picture format. Our current solution is to
combine those two different picture formats to one which will not lose any
data. Then change the source's format to this new format and then upload
the pixmap to texture once. It works. If we fail to find a matched new
format then we fallback.
There still is a potential problem, if two pictures refer to the same
pixmap, and one of them destroy the picture, but the other still remained
to be used latter. We don't handle that situation currently. To be fixed.
3. Dynamic texture uploading.
This is a performance feature. Although we don't like the client to hold
a pixmap data to shared memory and we can't accelerate it. And even worse,
we may need to fallback all the required pixmaps to cpu memory and then
process them on CPU. This feature is to mitigate this penalty. When the
target pixmap has a valid gl fbo attached to it. But the other pixmaps are
not. Then it will be more efficient to upload the other pixmaps to GPU and
then do the blitting or rendering on GPU than fallback all the pixmaps to CPU.
To enable this feature, I experienced a significant performance improvement
in the Game "Mines" :).
4. Debug facility.
Modify the debug output mechanism. Now add a new macro:
glamor_debug_output(_level_, _format_,...) to conditional output some messages
according to the environment variable GLAMOR_DEBUG. We have the following
levels currently.
exports GLAMOR_DEBUG to 3 will enable all the above messages.
5. Changes in pixmap private data structure.
Add some for the full color format supports and relate it to the pictures which
already described. Also Add the following new elements:
gl_fbo - to indicates whether this pixmap is on gpu only.
gl_tex - to indicates whether the tex is valid and is containing the pixmap's
image originally.
As we bring the dynamic pixmap uploading feature, so a cpu memory pixmap may
also has a valid fbo or tex attached to it. So we will have to use the above
new element to check it true type.
After this commit, we can pass the rendercheck testing for all the picture formats.
And is much much fater than fallback to cpu when doing rendercheck testing.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-06-21 12:31:11 +02:00
|
|
|
glamor_set_debug_level(int *debug_level)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
char *debug_level_string;
|
|
|
|
debug_level_string = getenv("GLAMOR_DEBUG");
|
|
|
|
if (debug_level_string
|
|
|
|
&& sscanf(debug_level_string, "%d", debug_level) == 1)
|
|
|
|
return;
|
|
|
|
*debug_level = 0;
|
glamor : Add dynamic texture uploading feature.
Major refactoring.
1. Rewrite the pixmap texture uploading and downloading functions.
Add some new functions for both the prepare/finish access and
the new performance feature dynamic texture uploading, which
could download and upload the current image to/from a private
texture/fbo. In the uploading or downloading phase, we need to
handle two things:
The first is the yInverted option, If it set, then we don't need
to flip y. If not set, if it is from a dynamic texture uploading
then we don't need to flip either if the current drawing process
will flip it latter. If it is from finish_access, then we must
flip the y axis.
The second thing is the alpha channel hanlding, if the pixmap's
format is something like x8a8r8g8, x1r5g5b5 which means it doesn't
has alpha channel, but it do has those extra bits. Then we need to
wire those bits to 1.
2. Add almost all the required picture format support.
This is not as trivial as it looks like. The previous implementation
only support GL_a8,GL_a8r8g8b8,GL_x8r8g8b8. All the other format,
we have to fallback to cpu. The reason why we can't simply add those
other color format is because the exists of picture. one drawable
pixmap may has one or even more container pictures. The drawable pixmap's
depth can't map to a specified color format, for example depth 16 can
mapped to r5g6b5, x1r5g5b5, a1r5g5b5, or even b5g6r5. So we can't get
get the color format just from the depth value. But the pixmap do not
has a pict_format element. We have to make a new one in the pixmap
private data structure. Reroute the CreatePicture to glamor_create_picture
and then store the picture's format to the pixmap's private structure.
This is not an ideal solution, as there may be more than one pictures
refer to the same pixmap. Then we will have trouble. There is an example
in glamor_composite_with_shader. The source and mask often share the
same pixmap, but use different picture format. Our current solution is to
combine those two different picture formats to one which will not lose any
data. Then change the source's format to this new format and then upload
the pixmap to texture once. It works. If we fail to find a matched new
format then we fallback.
There still is a potential problem, if two pictures refer to the same
pixmap, and one of them destroy the picture, but the other still remained
to be used latter. We don't handle that situation currently. To be fixed.
3. Dynamic texture uploading.
This is a performance feature. Although we don't like the client to hold
a pixmap data to shared memory and we can't accelerate it. And even worse,
we may need to fallback all the required pixmaps to cpu memory and then
process them on CPU. This feature is to mitigate this penalty. When the
target pixmap has a valid gl fbo attached to it. But the other pixmaps are
not. Then it will be more efficient to upload the other pixmaps to GPU and
then do the blitting or rendering on GPU than fallback all the pixmaps to CPU.
To enable this feature, I experienced a significant performance improvement
in the Game "Mines" :).
4. Debug facility.
Modify the debug output mechanism. Now add a new macro:
glamor_debug_output(_level_, _format_,...) to conditional output some messages
according to the environment variable GLAMOR_DEBUG. We have the following
levels currently.
exports GLAMOR_DEBUG to 3 will enable all the above messages.
5. Changes in pixmap private data structure.
Add some for the full color format supports and relate it to the pictures which
already described. Also Add the following new elements:
gl_fbo - to indicates whether this pixmap is on gpu only.
gl_tex - to indicates whether the tex is valid and is containing the pixmap's
image originally.
As we bring the dynamic pixmap uploading feature, so a cpu memory pixmap may
also has a valid fbo or tex attached to it. So we will have to use the above
new element to check it true type.
After this commit, we can pass the rendercheck testing for all the picture formats.
And is much much fater than fallback to cpu when doing rendercheck testing.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-06-21 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int glamor_debug_level;
|
|
|
|
|
2008-12-16 23:00:05 +01:00
|
|
|
/** Set up glamor for an already-configured GL context. */
|
|
|
|
Bool
|
2011-05-11 19:08:38 +02:00
|
|
|
glamor_init(ScreenPtr screen, unsigned int flags)
|
2008-12-16 23:00:05 +01:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
int gl_version;
|
2011-05-11 09:54:50 +02:00
|
|
|
|
2009-08-21 01:43:22 +02:00
|
|
|
#ifdef RENDER
|
2011-11-02 06:44:50 +01:00
|
|
|
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
2009-08-21 01:43:22 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
if (flags & ~GLAMOR_VALID_FLAGS) {
|
|
|
|
ErrorF("glamor_init: Invalid flags %x\n", flags);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
glamor_priv = calloc(1, sizeof(*glamor_priv));
|
|
|
|
if (glamor_priv == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (flags & GLAMOR_INVERTED_Y_AXIS) {
|
|
|
|
glamor_priv->yInverted = 1;
|
|
|
|
} else
|
|
|
|
glamor_priv->yInverted = 0;
|
|
|
|
|
|
|
|
if (!dixRegisterPrivateKey
|
|
|
|
(glamor_screen_private_key, PRIVATE_SCREEN, 0)) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate screen private\n",
|
|
|
|
screen->myNum);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:34:42 +01:00
|
|
|
glamor_set_screen_private(screen, glamor_priv);
|
2011-11-02 06:44:50 +01:00
|
|
|
|
|
|
|
if (!dixRegisterPrivateKey
|
|
|
|
(glamor_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate pixmap private\n",
|
|
|
|
screen->myNum);
|
|
|
|
goto fail;;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_version = glamor_gl_get_version();
|
2009-08-20 21:32:53 +02:00
|
|
|
|
2011-09-22 07:39:01 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) {
|
|
|
|
ErrorF("Require OpenGL version 1.3 or latter.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-09-22 07:39:01 +02:00
|
|
|
#else
|
2011-11-02 06:44:50 +01:00
|
|
|
if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) {
|
|
|
|
ErrorF("Require Open GLES2.0 or latter.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-09-22 07:39:01 +02:00
|
|
|
#endif
|
2011-08-02 09:51:46 +02:00
|
|
|
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_gl_dispatch_init(screen, &glamor_priv->_dispatch, gl_version);
|
2011-08-11 21:05:02 +02:00
|
|
|
|
|
|
|
#ifdef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
|
|
|
|
ErrorF("GL_EXT_texture_format_BGRA8888 required\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-08-03 04:49:18 +02:00
|
|
|
#endif
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_priv->has_pack_invert =
|
|
|
|
glamor_gl_has_extension("GL_MESA_pack_invert");
|
|
|
|
glamor_priv->has_fbo_blit =
|
|
|
|
glamor_gl_has_extension("GL_EXT_framebuffer_blit");
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_priv->_dispatch.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE,
|
|
|
|
&glamor_priv->max_fbo_size);
|
2011-08-03 04:49:18 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_set_debug_level(&glamor_debug_level);
|
2011-04-13 09:50:26 +02:00
|
|
|
|
2012-01-20 03:55:16 +01:00
|
|
|
#ifdef GLAMOR_GLES2
|
|
|
|
glamor_priv->gl_flavor = GLAMOR_GL_ES2;
|
|
|
|
#else
|
|
|
|
glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP;
|
|
|
|
#endif
|
2012-01-31 11:16:58 +01:00
|
|
|
/* If we are using egl screen, call egl screen init to
|
|
|
|
* register correct close screen function. */
|
|
|
|
if (flags & GLAMOR_USE_EGL_SCREEN)
|
|
|
|
glamor_egl_screen_init(screen);
|
|
|
|
|
|
|
|
glamor_priv->saved_procs.close_screen = screen->CloseScreen;
|
|
|
|
screen->CloseScreen = glamor_close_screen;
|
2012-01-20 03:55:16 +01:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (flags & GLAMOR_USE_SCREEN) {
|
2011-11-15 13:17:18 +01:00
|
|
|
if (!RegisterBlockAndWakeupHandlers(_glamor_block_handler,
|
|
|
|
_glamor_wakeup_handler,
|
2012-02-10 13:54:44 +01:00
|
|
|
glamor_priv)) {
|
2011-11-15 13:17:18 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.create_gc = screen->CreateGC;
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->CreateGC = glamor_create_gc;
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.create_pixmap = screen->CreatePixmap;
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->CreatePixmap = glamor_create_pixmap;
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->DestroyPixmap = glamor_destroy_pixmap;
|
2009-08-20 23:43:43 +02:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.get_spans = screen->GetSpans;
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->GetSpans = glamor_get_spans;
|
2009-08-24 16:22:14 +02:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.get_image = screen->GetImage;
|
2011-12-13 15:48:34 +01:00
|
|
|
screen->GetImage = glamor_get_image;
|
2009-09-22 21:08:19 +02:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.change_window_attributes =
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->ChangeWindowAttributes;
|
|
|
|
screen->ChangeWindowAttributes =
|
|
|
|
glamor_change_window_attributes;
|
2010-02-08 20:12:44 +01:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.copy_window = screen->CopyWindow;
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->CopyWindow = glamor_copy_window;
|
2009-09-22 21:08:19 +02:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.bitmap_to_region =
|
2011-11-02 06:44:50 +01:00
|
|
|
screen->BitmapToRegion;
|
|
|
|
screen->BitmapToRegion = glamor_bitmap_to_region;
|
|
|
|
}
|
2009-08-21 01:43:22 +02:00
|
|
|
#ifdef RENDER
|
2011-11-02 06:44:50 +01:00
|
|
|
if (flags & GLAMOR_USE_PICTURE_SCREEN) {
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.composite = ps->Composite;
|
2011-11-02 06:44:50 +01:00
|
|
|
ps->Composite = glamor_composite;
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.trapezoids = ps->Trapezoids;
|
2011-11-02 06:44:50 +01:00
|
|
|
ps->Trapezoids = glamor_trapezoids;
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.glyphs = ps->Glyphs;
|
2011-11-02 06:44:50 +01:00
|
|
|
ps->Glyphs = glamor_glyphs;
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.triangles = ps->Triangles;
|
2011-11-02 06:44:50 +01:00
|
|
|
ps->Triangles = glamor_triangles;
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.addtraps = ps->AddTraps;
|
2011-12-13 15:48:34 +01:00
|
|
|
ps->AddTraps = glamor_add_traps;
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.unrealize_glyph = ps->UnrealizeGlyph;
|
2011-11-02 06:44:50 +01:00
|
|
|
ps->UnrealizeGlyph = glamor_glyph_unrealize;
|
|
|
|
}
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.create_picture = ps->CreatePicture;
|
2011-12-09 07:57:24 +01:00
|
|
|
ps->CreatePicture = glamor_create_picture;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
glamor_priv->saved_procs.destroy_picture = ps->DestroyPicture;
|
2011-12-09 07:57:24 +01:00
|
|
|
ps->DestroyPicture = glamor_destroy_picture;
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_init_composite_shaders(screen);
|
2009-08-21 01:43:22 +02:00
|
|
|
#endif
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_init_pixmap_fbo(screen);
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_init_solid_shader(screen);
|
|
|
|
glamor_init_tile_shader(screen);
|
|
|
|
glamor_init_putimage_shaders(screen);
|
|
|
|
glamor_init_finish_access_shaders(screen);
|
2012-04-25 07:51:58 +02:00
|
|
|
#ifdef GLAMOR_GRADIENT_SHADER
|
2012-03-22 21:05:48 +01:00
|
|
|
glamor_init_gradient_shader(screen);
|
2012-04-25 07:51:58 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_pixmap_init(screen);
|
2010-02-10 06:17:09 +01:00
|
|
|
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_priv->flags = flags;
|
GLX: Enable glx support.
If we are using MESA as our GL library, then both xserver's
GLX and glamor are link to the same library. As xserver's
GLX has its own _glapi_get/set_context/dispatch etc, and it
is a simplified version derived from mesa thus is not
sufficient for mesa/egl's dri loader which is used by glamor.
Then if glx module is loaded before glamoregl module, the
initialization of mesa/egl/opengl will not be correct, and
will fail at a very early stage, most likely fail to map
the element buffer.
Two methodis to fix this problem, first is to modify the xserver's
glx's glapi.c to fit mesa's requirement. The second is to put
a glamor.conf as below, to the system's xorg.conf path.
Section "Module"
Load "glamoregl"
EndSection
Then glamor will be loaded firstly, and the mesa's libglapi.so
will be used. As current xserver's dispatch table is the same
as mesa's, then the glx's dri loader can work without problem.
We took the second method as it don't need any change to xorg.:)
Although this is not a graceful implementation as it depends
on the xserver's dispatch table and the mesa's dispatch table
is the same and the context set and get is using the same method.
Anyway it works.
As by default, xserver will enable GLX_USE_TLS. But mesa will not
enable it, you may need to enable that when build mesa.
Three pre-requirements to make this glamor version work:
0. Make sure xserver has commit 66e603, if not please pull the latest
master branch.
1. Rebuild mesa by enable GLX_USE_TLS.
2. Put the glamor.conf to your system's xorg.conf path and make sure
it loaded prior to glx module.
Preliminary testing shows indirect glxgears works fine.
If user want to use GLES2 for glamor by using MESA, GLX will not
work correctly.
If you are not using normal MESA, for example PVR's private GLES
implementation, then it should be ok to use GLES2 glamor and the
GLX should work as expected. In this commit, I use gbm to check
whether we are using MESA or non-mesa. Maybe not the best way.
Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2012-02-10 09:04:07 +01:00
|
|
|
glamor_priv->screen = screen;
|
2011-08-09 15:59:56 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
return TRUE;
|
2009-08-20 21:32:53 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
fail:
|
|
|
|
free(glamor_priv);
|
2012-02-02 02:34:42 +01:00
|
|
|
glamor_set_screen_private(screen, NULL);
|
2011-11-02 06:44:50 +01:00
|
|
|
return FALSE;
|
2008-12-16 23:00:05 +01:00
|
|
|
}
|
|
|
|
|
2012-01-19 13:47:55 +01:00
|
|
|
static void
|
|
|
|
glamor_release_screen_priv(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
|
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
#ifdef RENDER
|
|
|
|
glamor_fini_composite_shaders(screen);
|
|
|
|
#endif
|
|
|
|
glamor_fini_pixmap_fbo(screen);
|
|
|
|
glamor_fini_solid_shader(screen);
|
|
|
|
glamor_fini_tile_shader(screen);
|
|
|
|
glamor_fini_putimage_shaders(screen);
|
|
|
|
glamor_fini_finish_access_shaders(screen);
|
2012-03-22 21:05:48 +01:00
|
|
|
glamor_fini_gradient_shader(screen);
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_pixmap_fini(screen);
|
|
|
|
free(glamor_priv);
|
|
|
|
|
2012-02-02 02:34:42 +01:00
|
|
|
glamor_set_screen_private(screen, NULL);
|
2012-01-19 13:47:55 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 09:56:05 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv)
|
|
|
|
{
|
|
|
|
glamor_pixmap_private *old_priv;
|
|
|
|
glamor_pixmap_fbo *fbo;
|
|
|
|
|
|
|
|
old_priv = dixGetPrivate(&pixmap->devPrivates, glamor_pixmap_private_key);
|
|
|
|
|
|
|
|
if (priv) {
|
|
|
|
assert(old_priv == NULL);
|
|
|
|
} else {
|
|
|
|
if (old_priv == NULL)
|
|
|
|
return;
|
|
|
|
fbo = glamor_pixmap_detach_fbo(old_priv);
|
|
|
|
glamor_purge_fbo(fbo);
|
|
|
|
free(old_priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
dixSetPrivate(&pixmap->devPrivates,
|
|
|
|
glamor_pixmap_private_key,
|
|
|
|
priv);
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
Bool
|
2011-04-13 09:50:26 +02:00
|
|
|
glamor_close_screen(int idx, ScreenPtr screen)
|
2008-12-17 00:14:31 +01:00
|
|
|
{
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
2012-01-31 11:16:58 +01:00
|
|
|
PixmapPtr screen_pixmap;
|
|
|
|
glamor_pixmap_private *screen_pixmap_priv;
|
|
|
|
glamor_pixmap_fbo *fbo;
|
2012-01-19 13:47:55 +01:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
flags = glamor_priv->flags;
|
2009-08-21 01:43:22 +02:00
|
|
|
#ifdef RENDER
|
2011-11-02 06:44:50 +01:00
|
|
|
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
2009-08-21 01:43:22 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_glyphs_fini(screen);
|
2012-01-31 11:16:58 +01:00
|
|
|
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
|
2012-01-19 13:47:55 +01:00
|
|
|
if (flags & GLAMOR_USE_SCREEN) {
|
|
|
|
|
|
|
|
screen->CreateGC = glamor_priv->saved_procs.create_gc;
|
|
|
|
screen->CreatePixmap = glamor_priv->saved_procs.create_pixmap;
|
|
|
|
screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap;
|
|
|
|
screen->GetSpans = glamor_priv->saved_procs.get_spans;
|
|
|
|
screen->ChangeWindowAttributes =
|
|
|
|
glamor_priv->saved_procs.change_window_attributes;
|
|
|
|
screen->CopyWindow = glamor_priv->saved_procs.copy_window;
|
|
|
|
screen->BitmapToRegion = glamor_priv->saved_procs.bitmap_to_region;
|
|
|
|
}
|
2009-08-21 01:43:22 +02:00
|
|
|
#ifdef RENDER
|
2012-01-19 13:47:55 +01:00
|
|
|
if (ps && (flags & GLAMOR_USE_PICTURE_SCREEN)) {
|
|
|
|
|
2012-01-13 04:18:28 +01:00
|
|
|
ps->Composite = glamor_priv->saved_procs.composite;
|
|
|
|
ps->Trapezoids = glamor_priv->saved_procs.trapezoids;
|
|
|
|
ps->Glyphs = glamor_priv->saved_procs.glyphs;
|
|
|
|
ps->Triangles = glamor_priv->saved_procs.triangles;
|
|
|
|
ps->CreatePicture = glamor_priv->saved_procs.create_picture;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
2009-08-21 01:43:22 +02:00
|
|
|
#endif
|
2012-01-31 11:16:58 +01:00
|
|
|
screen_pixmap = screen->GetScreenPixmap(screen);
|
2012-02-17 09:56:05 +01:00
|
|
|
glamor_set_pixmap_private(screen_pixmap, NULL);
|
|
|
|
if (glamor_priv->back_pixmap && *glamor_priv->back_pixmap)
|
|
|
|
glamor_set_pixmap_private(*glamor_priv->back_pixmap, NULL);
|
|
|
|
|
2012-01-19 13:47:55 +01:00
|
|
|
glamor_release_screen_priv(screen);
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2012-01-31 11:16:58 +01:00
|
|
|
return screen->CloseScreen(idx, screen);
|
2011-04-13 09:50:26 +02:00
|
|
|
}
|
|
|
|
|
2012-01-19 13:47:55 +01:00
|
|
|
|
2011-04-13 09:50:26 +02:00
|
|
|
void
|
|
|
|
glamor_fini(ScreenPtr screen)
|
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
/* Do nothing currently. */
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|