2008-12-16 21:30:14 +01:00
|
|
|
/*
|
2014-10-21 06:31:56 +02:00
|
|
|
* Copyright © 2008,2011 Intel Corporation
|
2008-12-16 21:30:14 +01:00
|
|
|
*
|
|
|
|
* 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>
|
2012-04-28 08:13:47 +02:00
|
|
|
* Zhigang Gong <zhigang.gong@linux.intel.com>
|
2014-10-21 06:31:56 +02:00
|
|
|
* Chad Versace <chad.versace@linux.intel.com>
|
2008-12-16 21:30:14 +01:00
|
|
|
*/
|
|
|
|
|
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>
|
2018-02-28 02:19:43 +01:00
|
|
|
#include <unistd.h>
|
2008-12-16 23:00:05 +01:00
|
|
|
|
2008-12-17 00:14:31 +01:00
|
|
|
#include "glamor_priv.h"
|
2014-10-30 04:40:21 +01:00
|
|
|
#include "mipict.h"
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2014-04-02 23:05:35 +02:00
|
|
|
DevPrivateKeyRec glamor_screen_private_key;
|
|
|
|
DevPrivateKeyRec glamor_pixmap_private_key;
|
2014-04-02 23:07:20 +02:00
|
|
|
DevPrivateKeyRec glamor_gc_private_key;
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2017-07-14 20:52:01 +02:00
|
|
|
glamor_screen_private *
|
|
|
|
glamor_get_screen_private(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
return (glamor_screen_private *)
|
|
|
|
dixLookupPrivate(&screen->devPrivates, &glamor_screen_private_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_set_screen_private(ScreenPtr screen, glamor_screen_private *priv)
|
|
|
|
{
|
|
|
|
dixSetPrivate(&screen->devPrivates, &glamor_screen_private_key, priv);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2013-12-18 20:59:07 +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
|
|
|
}
|
|
|
|
|
2014-10-30 07:47:23 +01:00
|
|
|
static void
|
|
|
|
glamor_init_pixmap_private_small(PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv)
|
|
|
|
{
|
|
|
|
pixmap_priv->box.x1 = 0;
|
|
|
|
pixmap_priv->box.x2 = pixmap->drawable.width;
|
|
|
|
pixmap_priv->box.y1 = 0;
|
|
|
|
pixmap_priv->box.y2 = pixmap->drawable.height;
|
|
|
|
pixmap_priv->block_w = pixmap->drawable.width;
|
|
|
|
pixmap_priv->block_h = pixmap->drawable.height;
|
|
|
|
pixmap_priv->block_hcnt = 1;
|
|
|
|
pixmap_priv->block_wcnt = 1;
|
|
|
|
pixmap_priv->box_array = &pixmap_priv->box;
|
|
|
|
pixmap_priv->fbo_array = &pixmap_priv->fbo;
|
|
|
|
}
|
|
|
|
|
2011-12-12 00:09:03 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
|
2015-07-01 01:20:18 +02:00
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
pixmap_priv->type = type;
|
2014-10-30 07:47:23 +01:00
|
|
|
glamor_init_pixmap_private_small(pixmap, pixmap_priv);
|
2011-12-12 00:09:03 +01:00
|
|
|
}
|
|
|
|
|
2019-03-12 17:15:10 +01:00
|
|
|
_X_EXPORT Bool
|
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
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
glamor_pixmap_fbo *fbo;
|
|
|
|
|
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
if (pixmap_priv->fbo) {
|
2013-12-18 20:59:07 +01:00
|
|
|
fbo = glamor_pixmap_detach_fbo(pixmap_priv);
|
2014-10-30 06:50:53 +01:00
|
|
|
glamor_destroy_fbo(glamor_priv, fbo);
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
2019-03-27 00:57:24 +01:00
|
|
|
fbo = glamor_create_fbo_from_tex(glamor_priv, pixmap,
|
|
|
|
pixmap->drawable.width,
|
|
|
|
pixmap->drawable.height, tex, 0);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
if (fbo == NULL) {
|
|
|
|
ErrorF("XXX fail to create fbo.\n");
|
2019-03-12 17:15:10 +01:00
|
|
|
return FALSE;
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
glamor_pixmap_attach_fbo(pixmap, fbo);
|
2019-03-12 17:15:10 +01:00
|
|
|
|
|
|
|
return TRUE;
|
2011-05-11 09:54:50 +02:00
|
|
|
}
|
|
|
|
|
2019-11-07 12:25:42 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_clear_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
ScreenPtr screen = pixmap->drawable.pScreen;
|
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
const struct glamor_format *pixmap_format;
|
|
|
|
|
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
pixmap_format = glamor_format_for_pixmap(pixmap);
|
|
|
|
|
|
|
|
assert(pixmap_priv->fbo != NULL);
|
|
|
|
|
|
|
|
glamor_pixmap_clear_fbo(glamor_priv, pixmap_priv->fbo, pixmap_format);
|
|
|
|
}
|
|
|
|
|
2013-12-18 22:24:14 +01:00
|
|
|
uint32_t
|
|
|
|
glamor_get_pixmap_texture(PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
|
2017-03-14 15:22:31 +01:00
|
|
|
if (!pixmap_priv)
|
|
|
|
return 0;
|
|
|
|
|
2019-03-08 18:19:16 +01:00
|
|
|
if (!pixmap_priv->fbo)
|
|
|
|
return 0;
|
|
|
|
|
2013-12-18 22:24:14 +01:00
|
|
|
if (pixmap_priv->type != GLAMOR_TEXTURE_ONLY)
|
|
|
|
return 0;
|
|
|
|
|
2014-10-30 07:08:57 +01:00
|
|
|
return pixmap_priv->fbo->tex;
|
2013-12-18 22:24:14 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 01:19:38 +02:00
|
|
|
void
|
|
|
|
glamor_bind_texture(glamor_screen_private *glamor_priv, GLenum texture,
|
|
|
|
glamor_pixmap_fbo *fbo, Bool destination_red)
|
|
|
|
{
|
|
|
|
glActiveTexture(texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo->tex);
|
|
|
|
|
|
|
|
/* If we're pulling data from a GL_RED texture, then whether we
|
|
|
|
* want to make it an A,0,0,0 result or a 0,0,0,R result depends
|
|
|
|
* on whether the destination is also a GL_RED texture.
|
|
|
|
*
|
|
|
|
* For GL_RED destinations, we need to leave the bits in the R
|
|
|
|
* channel. For all other destinations, we need to clear out the R
|
|
|
|
* channel so that it returns zero for R, G and B.
|
|
|
|
*
|
|
|
|
* Note that we're leaving the SWIZZLE_A value alone; for GL_RED
|
|
|
|
* destinations, that means we'll actually be returning R,0,0,R,
|
|
|
|
* but it doesn't matter as the bits in the alpha channel aren't
|
|
|
|
* going anywhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Is the operand a GL_RED fbo?
|
|
|
|
*/
|
|
|
|
|
2019-03-26 23:58:59 +01:00
|
|
|
if (fbo->is_red) {
|
2016-05-14 01:19:38 +02:00
|
|
|
/* If destination is also GL_RED, then preserve the bits in
|
|
|
|
* the R channel */
|
|
|
|
|
|
|
|
if (destination_red)
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
|
|
|
|
else
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ZERO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2013-12-18 20:59:07 +01:00
|
|
|
unsigned int usage)
|
2008-12-17 00:14:31 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
PixmapPtr pixmap;
|
|
|
|
glamor_pixmap_private *pixmap_priv;
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
2014-04-23 11:54:43 +02:00
|
|
|
glamor_pixmap_fbo *fbo = NULL;
|
2013-12-18 20:59:07 +01:00
|
|
|
int pitch;
|
|
|
|
|
|
|
|
if (w > 32767 || h > 32767)
|
|
|
|
return NullPixmap;
|
|
|
|
|
|
|
|
if ((usage == GLAMOR_CREATE_PIXMAP_CPU
|
2015-06-01 00:28:39 +02:00
|
|
|
|| (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE &&
|
|
|
|
w <= glamor_priv->glyph_max_dim &&
|
|
|
|
h <= glamor_priv->glyph_max_dim)
|
2013-12-18 20:59:07 +01:00
|
|
|
|| (w == 0 && h == 0)
|
2019-03-26 23:10:49 +01:00
|
|
|
|| !glamor_priv->formats[depth].format))
|
2013-12-18 20:59:07 +01:00
|
|
|
return fbCreatePixmap(screen, w, h, depth, usage);
|
|
|
|
else
|
|
|
|
pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
|
|
|
|
|
2015-07-01 01:20:18 +02:00
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2018-09-07 00:38:14 +02:00
|
|
|
pixmap_priv->is_cbcr = (usage == GLAMOR_CREATE_FORMAT_CBCR);
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
pitch = (((w * pixmap->drawable.bitsPerPixel + 7) / 8) + 3) & ~3;
|
|
|
|
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, pitch, NULL);
|
|
|
|
|
2014-10-30 07:47:23 +01:00
|
|
|
pixmap_priv->type = GLAMOR_TEXTURE_ONLY;
|
|
|
|
|
2014-04-01 03:00:54 +02:00
|
|
|
if (usage == GLAMOR_CREATE_PIXMAP_NO_TEXTURE) {
|
2014-10-30 07:47:23 +01:00
|
|
|
glamor_init_pixmap_private_small(pixmap, pixmap_priv);
|
2014-04-01 03:00:54 +02:00
|
|
|
return pixmap;
|
|
|
|
}
|
2014-10-30 04:20:29 +01:00
|
|
|
else if (usage == GLAMOR_CREATE_NO_LARGE ||
|
2014-03-19 05:23:24 +01:00
|
|
|
glamor_check_fbo_size(glamor_priv, w, h))
|
|
|
|
{
|
2014-10-30 07:47:23 +01:00
|
|
|
glamor_init_pixmap_private_small(pixmap, pixmap_priv);
|
2019-03-27 00:57:24 +01:00
|
|
|
fbo = glamor_create_fbo(glamor_priv, pixmap, w, h, usage);
|
2014-04-23 11:54:43 +02:00
|
|
|
} else {
|
|
|
|
int tile_size = glamor_priv->max_fbo_size;
|
2014-10-30 07:47:23 +01:00
|
|
|
DEBUGF("Create LARGE pixmap %p width %d height %d, tile size %d\n",
|
|
|
|
pixmap, w, h, tile_size);
|
2019-03-27 00:57:24 +01:00
|
|
|
fbo = glamor_create_fbo_array(glamor_priv, pixmap, usage,
|
2014-04-23 11:54:43 +02:00
|
|
|
tile_size, tile_size, pixmap_priv);
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fbo == NULL) {
|
|
|
|
fbDestroyPixmap(pixmap);
|
|
|
|
return fbCreatePixmap(screen, w, h, depth, usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_pixmap_attach_fbo(pixmap, fbo);
|
|
|
|
|
|
|
|
return pixmap;
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
2015-10-19 06:34:45 +02:00
|
|
|
Bool
|
|
|
|
glamor_destroy_pixmap(PixmapPtr pixmap)
|
2011-11-02 06:44:50 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
if (pixmap->refcnt == 1) {
|
2015-07-08 02:21:55 +02:00
|
|
|
glamor_pixmap_destroy_fbo(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
2014-12-10 08:21:44 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
return fbDestroyPixmap(pixmap);
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_block_handler(ScreenPtr screen)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
2014-03-15 01:31:18 +01:00
|
|
|
glamor_make_current(glamor_priv);
|
2013-12-18 21:18:20 +01:00
|
|
|
glFlush();
|
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
|
2015-09-01 20:20:04 +02:00
|
|
|
_glamor_block_handler(ScreenPtr screen, void *timeout)
|
2008-12-20 22:48:39 +01:00
|
|
|
{
|
2015-01-23 07:28:28 +01:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
2016-05-26 21:11:46 +02:00
|
|
|
glamor_make_current(glamor_priv);
|
|
|
|
glFlush();
|
|
|
|
|
2015-01-23 07:28:28 +01:00
|
|
|
screen->BlockHandler = glamor_priv->saved_procs.block_handler;
|
2015-09-01 20:20:04 +02:00
|
|
|
screen->BlockHandler(screen, timeout);
|
2015-01-23 07:28:28 +01:00
|
|
|
glamor_priv->saved_procs.block_handler = screen->BlockHandler;
|
|
|
|
screen->BlockHandler = _glamor_block_handler;
|
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)
|
|
|
|
{
|
2013-12-18 20:59:07 +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;
|
|
|
|
|
2015-06-20 01:56:35 +02:00
|
|
|
void
|
|
|
|
glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
|
|
|
|
unsigned count)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* For a single quad, don't bother with an index buffer. */
|
|
|
|
if (count == 1)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
if (glamor_priv->ib_size < count) {
|
|
|
|
/* Basic GLES2 doesn't have any way to map buffer objects for
|
|
|
|
* writing, but it's long past time for drivers to have
|
|
|
|
* MapBufferRange.
|
|
|
|
*/
|
|
|
|
if (!glamor_priv->has_map_buffer_range)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
/* Lazy create the buffer name, and only bind it once since
|
|
|
|
* none of the glamor code binds it to anything else.
|
|
|
|
*/
|
|
|
|
if (!glamor_priv->ib) {
|
|
|
|
glGenBuffers(1, &glamor_priv->ib);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ib);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For now, only support GL_UNSIGNED_SHORTs. */
|
|
|
|
if (count > ((1 << 16) - 1) / 4) {
|
|
|
|
goto fallback;
|
|
|
|
} else {
|
|
|
|
uint16_t *data;
|
|
|
|
size_t size = count * 6 * sizeof(GLushort);
|
|
|
|
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
|
|
|
|
data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,
|
|
|
|
0, size,
|
|
|
|
GL_MAP_WRITE_BIT |
|
|
|
|
GL_MAP_INVALIDATE_BUFFER_BIT);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
data[i * 6 + 0] = i * 4 + 0;
|
|
|
|
data[i * 6 + 1] = i * 4 + 1;
|
|
|
|
data[i * 6 + 2] = i * 4 + 2;
|
|
|
|
data[i * 6 + 3] = i * 4 + 0;
|
|
|
|
data[i * 6 + 4] = i * 4 + 2;
|
|
|
|
data[i * 6 + 5] = i * 4 + 3;
|
|
|
|
}
|
|
|
|
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
|
|
|
|
glamor_priv->ib_size = count;
|
|
|
|
glamor_priv->ib_type = GL_UNSIGNED_SHORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawElements(GL_TRIANGLES, count * 6, glamor_priv->ib_type, NULL);
|
|
|
|
return;
|
|
|
|
|
|
|
|
fallback:
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-05 11:59:22 +01:00
|
|
|
static Bool
|
|
|
|
glamor_check_instruction_count(int gl_version)
|
|
|
|
{
|
|
|
|
GLint max_native_alu_instructions;
|
|
|
|
|
|
|
|
/* Avoid using glamor if the reported instructions limit is too low,
|
|
|
|
* as this would cause glamor to fallback on sw due to large shaders
|
|
|
|
* which ends up being unbearably slow.
|
|
|
|
*/
|
|
|
|
if (gl_version < 30) {
|
|
|
|
if (!epoxy_has_gl_extension("GL_ARB_fragment_program")) {
|
|
|
|
ErrorF("GL_ARB_fragment_program required\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB,
|
|
|
|
&max_native_alu_instructions);
|
|
|
|
if (max_native_alu_instructions < GLAMOR_MIN_ALU_INSTRUCTIONS) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor requires at least %d instructions (%d reported)\n",
|
|
|
|
GLAMOR_MIN_ALU_INSTRUCTIONS, max_native_alu_instructions);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:23:45 +02:00
|
|
|
static void GLAPIENTRY
|
|
|
|
glamor_debug_output_callback(GLenum source,
|
|
|
|
GLenum type,
|
|
|
|
GLuint id,
|
|
|
|
GLenum severity,
|
|
|
|
GLsizei length,
|
|
|
|
const GLchar *message,
|
|
|
|
const void *userParam)
|
|
|
|
{
|
|
|
|
ScreenPtr screen = (void *)userParam;
|
2015-11-05 23:47:42 +01:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
if (glamor_priv->suppress_gl_out_of_memory_logging &&
|
|
|
|
source == GL_DEBUG_SOURCE_API && type == GL_DEBUG_TYPE_ERROR) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:23:45 +02:00
|
|
|
LogMessageVerb(X_ERROR, 0, "glamor%d: GL error: %*s\n",
|
|
|
|
screen->myNum, length, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures GL_ARB_debug_output to give us immediate callbacks when
|
|
|
|
* GL errors occur, so that we can log them.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
glamor_setup_debug_output(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
if (!epoxy_has_gl_extension("GL_ARB_debug_output"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
2016-01-12 07:42:47 +01:00
|
|
|
/* Disable debugging messages other than GL API errors */
|
|
|
|
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL,
|
|
|
|
GL_FALSE);
|
2015-07-02 01:23:45 +02:00
|
|
|
glDebugMessageControl(GL_DEBUG_SOURCE_API,
|
|
|
|
GL_DEBUG_TYPE_ERROR,
|
|
|
|
GL_DONT_CARE,
|
|
|
|
0, NULL, GL_TRUE);
|
|
|
|
glDebugMessageCallback(glamor_debug_output_callback,
|
|
|
|
screen);
|
|
|
|
|
|
|
|
/* If KHR_debug is present, all debug output is disabled by
|
|
|
|
* default on non-debug contexts.
|
|
|
|
*/
|
|
|
|
if (epoxy_has_gl_extension("GL_KHR_debug"))
|
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
}
|
|
|
|
|
2019-03-26 23:10:49 +01:00
|
|
|
const struct glamor_format *
|
|
|
|
glamor_format_for_pixmap(PixmapPtr pixmap)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pixmap->drawable.pScreen;
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
|
|
|
|
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
|
|
|
|
if (pixmap_priv->is_cbcr)
|
|
|
|
return &glamor_priv->cbcr_format;
|
|
|
|
else
|
|
|
|
return &glamor_priv->formats[pixmap->drawable.depth];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
glamor_add_format(ScreenPtr screen, int depth, CARD32 render_format,
|
|
|
|
GLenum internalformat, GLenum format, GLenum type)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
struct glamor_format *f = &glamor_priv->formats[depth];
|
|
|
|
|
|
|
|
/* If we're trying to run on GLES, make sure that we get the read
|
|
|
|
* formats that we're expecting, since glamor_transfer relies on
|
|
|
|
* them matching to get data back out. To avoid this limitation, we
|
|
|
|
* would need to have a more general glReadPixels() path in
|
|
|
|
* glamor_transfer that re-encoded the bits to the pixel format that
|
|
|
|
* we intended after.
|
|
|
|
*
|
|
|
|
* Note that we can't just create a pixmap because we're in
|
|
|
|
* screeninit.
|
|
|
|
*/
|
|
|
|
if (glamor_priv->is_gles) {
|
|
|
|
unsigned fbo, tex;
|
|
|
|
int read_format, read_type;
|
|
|
|
GLenum status;
|
|
|
|
|
|
|
|
glGenTextures(1, &tex);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0,
|
|
|
|
format, type, NULL);
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &fbo);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_TEXTURE_2D, tex, 0);
|
|
|
|
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
|
|
|
ErrorF("glamor: Test fbo for depth %d incomplete. "
|
|
|
|
"Falling back to software.\n", depth);
|
|
|
|
glDeleteTextures(1, &tex);
|
|
|
|
glDeleteFramebuffers(1, &fbo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &read_format);
|
|
|
|
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &read_type);
|
|
|
|
|
|
|
|
glDeleteTextures(1, &tex);
|
|
|
|
glDeleteFramebuffers(1, &fbo);
|
|
|
|
|
|
|
|
if (format != read_format || type != read_type) {
|
|
|
|
ErrorF("glamor: Implementation returned 0x%x/0x%x read format/type "
|
|
|
|
"for depth %d, expected 0x%x/0x%x. "
|
|
|
|
"Falling back to software.\n",
|
|
|
|
read_format, read_type, depth, format, type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f->depth = depth;
|
|
|
|
f->render_format = render_format;
|
|
|
|
f->internalformat = internalformat;
|
|
|
|
f->format = format;
|
|
|
|
f->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the GL format/types that glamor will use for the various depths
|
|
|
|
*
|
|
|
|
* X11's pixel data doesn't have channels, but to store our data in GL
|
|
|
|
* we have to pick some sort of format to move X11 pixel data in and
|
|
|
|
* out with in glamor_transfer.c. For X11 core operations, other than
|
|
|
|
* GL logic ops (non-GXcopy GC ops) what the driver chooses internally
|
|
|
|
* doesn't matter as long as it doesn't drop any bits (we expect them
|
|
|
|
* to generally expand, if anything). For Render, we can expect
|
|
|
|
* clients to tend to render with PictFormats matching our channel
|
|
|
|
* layouts here since ultimately X11 pixels tend to end up on the
|
|
|
|
* screen. The render implementation will fall back to fb if the
|
|
|
|
* channels don't match.
|
|
|
|
*
|
|
|
|
* Note that these formats don't affect what glamor_egl.c or
|
|
|
|
* Xwayland's EGL layer choose for surfaces exposed through DRI or
|
|
|
|
* scanout. For now, those layers need to match what we're choosing
|
|
|
|
* here, or channels will end up swizzled around. Similarly, the
|
|
|
|
* driver's visual masks also need to match what we're doing here.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
glamor_setup_formats(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
/* Prefer r8 textures since they're required by GLES3 and core,
|
|
|
|
* only falling back to a8 if we can't do them.
|
|
|
|
*/
|
|
|
|
if (glamor_priv->is_gles || epoxy_has_gl_extension("GL_ARB_texture_rg")) {
|
|
|
|
glamor_add_format(screen, 8, PICT_a8,
|
|
|
|
GL_R8, GL_RED, GL_UNSIGNED_BYTE);
|
|
|
|
} else {
|
|
|
|
glamor_add_format(screen, 8, PICT_a8,
|
|
|
|
GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glamor_priv->is_gles) {
|
|
|
|
/* For 15bpp, GLES supports format/type RGBA/5551, rather than
|
|
|
|
* bgra/1555_rev. GL_EXT_bgra lets the impl say the color
|
|
|
|
* read format/type is bgra/1555 even if we had to create it
|
|
|
|
* with rgba/5551, with Mesa does. That means we can't use
|
|
|
|
* the same format/type for TexSubImage and readpixels.
|
|
|
|
*
|
|
|
|
* Instead, just store 16 bits using the trusted 565 path, and
|
|
|
|
* disable render accel for now.
|
|
|
|
*/
|
|
|
|
glamor_add_format(screen, 15, PICT_x1r5g5b5,
|
|
|
|
GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1);
|
|
|
|
} else {
|
|
|
|
glamor_add_format(screen, 15, PICT_x1r5g5b5,
|
|
|
|
GL_RGBA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV);
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_add_format(screen, 16, PICT_r5g6b5,
|
|
|
|
GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5);
|
|
|
|
|
|
|
|
if (glamor_priv->is_gles) {
|
|
|
|
assert(X_BYTE_ORDER == X_LITTLE_ENDIAN);
|
|
|
|
glamor_add_format(screen, 24, PICT_x8b8g8r8,
|
|
|
|
GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
|
|
|
|
glamor_add_format(screen, 32, PICT_a8b8g8r8,
|
|
|
|
GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
|
|
|
|
} else {
|
|
|
|
glamor_add_format(screen, 24, PICT_x8r8g8b8,
|
|
|
|
GL_RGBA, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV);
|
|
|
|
glamor_add_format(screen, 32, PICT_a8r8g8b8,
|
|
|
|
GL_RGBA, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glamor_priv->is_gles) {
|
|
|
|
glamor_add_format(screen, 30, PICT_x2b10g10r10,
|
|
|
|
GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV);
|
|
|
|
} else {
|
|
|
|
glamor_add_format(screen, 30, PICT_x2r10g10b10,
|
|
|
|
GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV);
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_priv->cbcr_format.depth = 16;
|
|
|
|
glamor_priv->cbcr_format.internalformat = GL_RG8;
|
|
|
|
glamor_priv->cbcr_format.format = GL_RG;
|
|
|
|
glamor_priv->cbcr_format.type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
int gl_version;
|
2014-10-21 06:31:56 +02:00
|
|
|
int glsl_major, glsl_minor;
|
2014-07-03 22:04:44 +02:00
|
|
|
int max_viewport_size[2];
|
2014-10-21 06:31:56 +02:00
|
|
|
const char *shading_version_string;
|
|
|
|
int shading_version_offset;
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
2014-10-30 04:30:12 +01:00
|
|
|
|
2013-12-18 20:59:07 +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;
|
|
|
|
|
2014-03-17 05:16:48 +01:00
|
|
|
glamor_priv->flags = flags;
|
2013-12-18 20:59:07 +01:00
|
|
|
|
2014-04-02 23:05:35 +02:00
|
|
|
if (!dixRegisterPrivateKey(&glamor_screen_private_key, PRIVATE_SCREEN, 0)) {
|
2013-12-18 20:59:07 +01:00
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate screen private\n",
|
|
|
|
screen->myNum);
|
2016-11-03 09:59:30 +01:00
|
|
|
goto free_glamor_private;
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
glamor_set_screen_private(screen, glamor_priv);
|
|
|
|
|
2015-07-01 01:20:18 +02:00
|
|
|
if (!dixRegisterPrivateKey(&glamor_pixmap_private_key, PRIVATE_PIXMAP,
|
|
|
|
sizeof(struct glamor_pixmap_private))) {
|
2013-12-18 20:59:07 +01:00
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate pixmap private\n",
|
|
|
|
screen->myNum);
|
2016-11-03 09:59:30 +01:00
|
|
|
goto free_glamor_private;
|
2014-04-02 23:07:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dixRegisterPrivateKey(&glamor_gc_private_key, PRIVATE_GC,
|
|
|
|
sizeof (glamor_gc_private))) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to allocate gc private\n",
|
|
|
|
screen->myNum);
|
2016-11-03 09:59:30 +01:00
|
|
|
goto free_glamor_private;
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:37:23 +02:00
|
|
|
glamor_priv->saved_procs.close_screen = screen->CloseScreen;
|
|
|
|
screen->CloseScreen = glamor_close_screen;
|
|
|
|
|
2015-10-19 04:26:14 +02:00
|
|
|
glamor_priv->saved_procs.destroy_pixmap = screen->DestroyPixmap;
|
|
|
|
screen->DestroyPixmap = glamor_destroy_pixmap;
|
|
|
|
|
2015-07-22 08:37:23 +02: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->ctx);
|
|
|
|
} else {
|
|
|
|
if (!glamor_glx_screen_init(&glamor_priv->ctx))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_make_current(glamor_priv);
|
|
|
|
|
2019-03-26 23:02:38 +01:00
|
|
|
if (!epoxy_is_desktop_gl())
|
|
|
|
glamor_priv->is_gles = TRUE;
|
2013-12-25 20:39:13 +01:00
|
|
|
|
2014-03-18 09:42:50 +01:00
|
|
|
gl_version = epoxy_gl_version();
|
2009-08-20 21:32:53 +02:00
|
|
|
|
2016-09-24 21:26:17 +02:00
|
|
|
/* assume a core profile if we are GL 3.1 and don't have ARB_compatibility */
|
|
|
|
glamor_priv->is_core_profile =
|
|
|
|
gl_version >= 31 && !epoxy_has_gl_extension("GL_ARB_compatibility");
|
|
|
|
|
2014-10-21 06:31:56 +02:00
|
|
|
shading_version_string = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
|
|
|
|
|
|
|
|
if (!shading_version_string) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to get GLSL version\n",
|
|
|
|
screen->myNum);
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-04-02 06:15:42 +02:00
|
|
|
|
2014-10-21 06:31:56 +02:00
|
|
|
shading_version_offset = 0;
|
|
|
|
if (strncmp("OpenGL ES GLSL ES ", shading_version_string, 18) == 0)
|
|
|
|
shading_version_offset = 18;
|
|
|
|
|
|
|
|
if (sscanf(shading_version_string + shading_version_offset,
|
|
|
|
"%i.%i",
|
|
|
|
&glsl_major,
|
|
|
|
&glsl_minor) != 2) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"glamor%d: Failed to parse GLSL version string %s\n",
|
|
|
|
screen->myNum, shading_version_string);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
glamor_priv->glsl_version = glsl_major * 100 + glsl_minor;
|
|
|
|
|
2019-03-26 23:02:38 +01:00
|
|
|
if (glamor_priv->is_gles) {
|
2014-10-21 06:31:56 +02:00
|
|
|
/* Force us back to the base version of our programs on an ES
|
|
|
|
* context, anyway. Basically glamor only uses desktop 1.20
|
|
|
|
* or 1.30 currently. 1.30's new features are also present in
|
|
|
|
* ES 3.0, but our glamor_program.c constructions use a lot of
|
|
|
|
* compatibility features (to reduce the diff between 1.20 and
|
|
|
|
* 1.30 programs).
|
|
|
|
*/
|
|
|
|
glamor_priv->glsl_version = 120;
|
|
|
|
}
|
2014-04-02 06:15:42 +02:00
|
|
|
|
2013-12-27 23:03:26 +01:00
|
|
|
/* We'd like to require GL_ARB_map_buffer_range or
|
|
|
|
* GL_OES_map_buffer_range, since it offers more information to
|
|
|
|
* the driver than plain old glMapBuffer() or glBufferSubData().
|
|
|
|
* It's been supported on Mesa on the desktop since 2009 and on
|
|
|
|
* GLES2 since October 2012. It's supported on Apple's iOS
|
|
|
|
* drivers for SGX535 and A7, but apparently not on most Android
|
|
|
|
* devices (the OES extension spec wasn't released until June
|
|
|
|
* 2012).
|
|
|
|
*
|
|
|
|
* 82% of 0 A.D. players (desktop GL) submitting hardware reports
|
|
|
|
* have support for it, with most of the ones lacking it being on
|
|
|
|
* Windows with Intel 4-series (G45) graphics or older.
|
|
|
|
*/
|
2019-03-26 23:02:38 +01:00
|
|
|
if (!glamor_priv->is_gles) {
|
2014-03-18 09:42:51 +01:00
|
|
|
if (gl_version < 21) {
|
|
|
|
ErrorF("Require OpenGL version 2.1 or later.\n");
|
2013-12-25 20:39:13 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2015-02-05 11:59:22 +01:00
|
|
|
|
2016-09-24 21:26:17 +02:00
|
|
|
if (!glamor_priv->is_core_profile &&
|
|
|
|
!epoxy_has_gl_extension("GL_ARB_texture_border_clamp")) {
|
|
|
|
ErrorF("GL_ARB_texture_border_clamp required\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-02-05 11:59:22 +01:00
|
|
|
if (!glamor_check_instruction_count(gl_version))
|
|
|
|
goto fail;
|
2018-05-15 21:51:56 +02:00
|
|
|
|
|
|
|
/* Glamor rendering assumes that platforms with GLSL 130+
|
|
|
|
* have instanced arrays, but this is not always the case.
|
|
|
|
* etnaviv offers GLSL 140 with OpenGL 2.1.
|
|
|
|
*/
|
|
|
|
if (glamor_priv->glsl_version >= 130 &&
|
|
|
|
!epoxy_has_gl_extension("GL_ARB_instanced_arrays"))
|
|
|
|
glamor_priv->glsl_version = 120;
|
2013-12-25 20:39:13 +01:00
|
|
|
} else {
|
2014-03-18 09:42:50 +01:00
|
|
|
if (gl_version < 20) {
|
2013-12-25 20:39:13 +01:00
|
|
|
ErrorF("Require Open GLES2.0 or later.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-08-02 09:51:46 +02:00
|
|
|
|
2014-03-18 09:42:49 +01:00
|
|
|
if (!epoxy_has_gl_extension("GL_EXT_texture_format_BGRA8888")) {
|
2013-12-25 20:39:13 +01:00
|
|
|
ErrorF("GL_EXT_texture_format_BGRA8888 required\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-09-24 21:26:17 +02:00
|
|
|
|
|
|
|
if (!epoxy_has_gl_extension("GL_OES_texture_border_clamp")) {
|
|
|
|
ErrorF("GL_OES_texture_border_clamp required\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-12-18 20:59:07 +01:00
|
|
|
}
|
2011-08-03 04:49:18 +02:00
|
|
|
|
2017-11-02 21:10:50 +01:00
|
|
|
if (!epoxy_has_gl_extension("GL_ARB_vertex_array_object") &&
|
|
|
|
!epoxy_has_gl_extension("GL_OES_vertex_array_object")) {
|
|
|
|
ErrorF("GL_{ARB,OES}_vertex_array_object required\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-03-15 21:27:14 +01:00
|
|
|
glamor_priv->has_rw_pbo = FALSE;
|
2019-03-26 23:02:38 +01:00
|
|
|
if (!glamor_priv->is_gles)
|
2014-03-15 21:27:14 +01:00
|
|
|
glamor_priv->has_rw_pbo = TRUE;
|
|
|
|
|
2014-03-18 09:42:49 +01:00
|
|
|
glamor_priv->has_khr_debug = epoxy_has_gl_extension("GL_KHR_debug");
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->has_pack_invert =
|
2014-03-18 09:42:49 +01:00
|
|
|
epoxy_has_gl_extension("GL_MESA_pack_invert");
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->has_fbo_blit =
|
2014-03-18 09:42:49 +01:00
|
|
|
epoxy_has_gl_extension("GL_EXT_framebuffer_blit");
|
2014-03-18 09:42:52 +01:00
|
|
|
glamor_priv->has_map_buffer_range =
|
2015-06-20 02:26:46 +02:00
|
|
|
epoxy_has_gl_extension("GL_ARB_map_buffer_range") ||
|
|
|
|
epoxy_has_gl_extension("GL_EXT_map_buffer_range");
|
2014-02-26 01:56:54 +01:00
|
|
|
glamor_priv->has_buffer_storage =
|
2014-03-18 09:42:49 +01:00
|
|
|
epoxy_has_gl_extension("GL_ARB_buffer_storage");
|
2017-07-27 01:54:40 +02:00
|
|
|
glamor_priv->has_mesa_tile_raster_order =
|
|
|
|
epoxy_has_gl_extension("GL_MESA_tile_raster_order");
|
2014-03-15 21:31:18 +01:00
|
|
|
glamor_priv->has_nv_texture_barrier =
|
|
|
|
epoxy_has_gl_extension("GL_NV_texture_barrier");
|
2015-01-19 12:32:54 +01:00
|
|
|
glamor_priv->has_unpack_subimage =
|
2019-03-26 23:02:38 +01:00
|
|
|
!glamor_priv->is_gles ||
|
2015-01-19 12:32:54 +01:00
|
|
|
epoxy_gl_version() >= 30 ||
|
|
|
|
epoxy_has_gl_extension("GL_EXT_unpack_subimage");
|
|
|
|
glamor_priv->has_pack_subimage =
|
2019-03-26 23:02:38 +01:00
|
|
|
!glamor_priv->is_gles ||
|
2015-01-19 12:32:54 +01:00
|
|
|
epoxy_gl_version() >= 30 ||
|
|
|
|
epoxy_has_gl_extension("GL_NV_pack_subimage");
|
2016-01-12 09:13:46 +01:00
|
|
|
glamor_priv->has_dual_blend =
|
2019-12-18 18:18:50 +01:00
|
|
|
glamor_priv->glsl_version >= 130 &&
|
2016-01-12 09:13:46 +01:00
|
|
|
epoxy_has_gl_extension("GL_ARB_blend_func_extended");
|
2019-11-07 12:25:42 +01:00
|
|
|
glamor_priv->has_clear_texture =
|
|
|
|
epoxy_gl_version() >= 44 ||
|
|
|
|
epoxy_has_gl_extension("GL_ARB_clear_texture");
|
2014-07-18 03:00:44 +02:00
|
|
|
|
2016-09-27 23:15:12 +02:00
|
|
|
glamor_priv->can_copyplane = (gl_version >= 30);
|
|
|
|
|
2015-07-02 01:23:45 +02:00
|
|
|
glamor_setup_debug_output(screen);
|
|
|
|
|
2019-03-26 23:02:38 +01:00
|
|
|
glamor_priv->use_quads = !glamor_priv->is_gles &&
|
2016-01-11 05:00:35 +01:00
|
|
|
!glamor_priv->is_core_profile;
|
|
|
|
|
2015-06-20 03:40:47 +02:00
|
|
|
/* Driver-specific hack: Avoid using GL_QUADS on VC4, where
|
|
|
|
* they'll be emulated more expensively than we can with our
|
|
|
|
* cached IB.
|
|
|
|
*/
|
|
|
|
if (strstr((char *)glGetString(GL_VENDOR), "Broadcom") &&
|
|
|
|
strstr((char *)glGetString(GL_RENDERER), "VC4"))
|
|
|
|
glamor_priv->use_quads = FALSE;
|
|
|
|
|
2013-12-18 21:18:20 +01:00
|
|
|
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size);
|
2014-05-14 23:08:18 +02:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glamor_priv->max_fbo_size);
|
2014-07-03 22:04:44 +02:00
|
|
|
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
|
|
|
|
glamor_priv->max_fbo_size = MIN(glamor_priv->max_fbo_size, max_viewport_size[0]);
|
|
|
|
glamor_priv->max_fbo_size = MIN(glamor_priv->max_fbo_size, max_viewport_size[1]);
|
2012-06-10 19:52:14 +02:00
|
|
|
#ifdef MAX_FBO_SIZE
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->max_fbo_size = MAX_FBO_SIZE;
|
2012-06-10 19:52:14 +02:00
|
|
|
#endif
|
2011-08-03 04:49:18 +02:00
|
|
|
|
2016-02-01 22:58:14 +01:00
|
|
|
glamor_priv->has_texture_swizzle =
|
|
|
|
(epoxy_has_gl_extension("GL_ARB_texture_swizzle") ||
|
2019-03-26 23:02:38 +01:00
|
|
|
(glamor_priv->is_gles && gl_version >= 30));
|
2016-02-01 22:58:14 +01:00
|
|
|
|
2019-03-26 23:10:49 +01:00
|
|
|
glamor_setup_formats(screen);
|
2014-09-11 04:02:55 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_set_debug_level(&glamor_debug_level);
|
2011-04-13 09:50:26 +02:00
|
|
|
|
2014-04-02 06:15:48 +02:00
|
|
|
if (!glamor_font_init(screen))
|
|
|
|
goto fail;
|
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.block_handler = screen->BlockHandler;
|
|
|
|
screen->BlockHandler = _glamor_block_handler;
|
2015-01-23 07:28:28 +01:00
|
|
|
|
2014-10-10 09:25:51 +02:00
|
|
|
if (!glamor_composite_glyphs_init(screen)) {
|
|
|
|
ErrorF("Failed to initialize composite masks\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.create_gc = screen->CreateGC;
|
|
|
|
screen->CreateGC = glamor_create_gc;
|
2011-11-15 13:17:18 +01:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.create_pixmap = screen->CreatePixmap;
|
|
|
|
screen->CreatePixmap = glamor_create_pixmap;
|
2008-12-17 00:14:31 +01:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.get_spans = screen->GetSpans;
|
|
|
|
screen->GetSpans = glamor_get_spans;
|
2009-08-20 23:43:43 +02:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.get_image = screen->GetImage;
|
|
|
|
screen->GetImage = glamor_get_image;
|
2009-08-24 16:22:14 +02:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.change_window_attributes =
|
|
|
|
screen->ChangeWindowAttributes;
|
|
|
|
screen->ChangeWindowAttributes = glamor_change_window_attributes;
|
2009-09-22 21:08:19 +02:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.copy_window = screen->CopyWindow;
|
|
|
|
screen->CopyWindow = glamor_copy_window;
|
2010-02-08 20:12:44 +01:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.bitmap_to_region = screen->BitmapToRegion;
|
|
|
|
screen->BitmapToRegion = glamor_bitmap_to_region;
|
2009-09-22 21:08:19 +02:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.composite = ps->Composite;
|
|
|
|
ps->Composite = glamor_composite;
|
2012-06-27 06:53:40 +02:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.trapezoids = ps->Trapezoids;
|
|
|
|
ps->Trapezoids = glamor_trapezoids;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.triangles = ps->Triangles;
|
|
|
|
ps->Triangles = glamor_triangles;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
glamor_priv->saved_procs.addtraps = ps->AddTraps;
|
|
|
|
ps->AddTraps = glamor_add_traps;
|
2011-12-13 15:48:34 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->saved_procs.composite_rects = ps->CompositeRects;
|
2015-06-30 23:41:27 +02:00
|
|
|
ps->CompositeRects = glamor_composite_rectangles;
|
2012-06-26 10:24:32 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->saved_procs.glyphs = ps->Glyphs;
|
2014-10-10 09:25:51 +02:00
|
|
|
ps->Glyphs = glamor_composite_glyphs;
|
2012-06-26 10:24:32 +02:00
|
|
|
|
2014-01-06 02:29:57 +01:00
|
|
|
glamor_init_vbo(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_init_gradient_shader(screen);
|
|
|
|
glamor_pixmap_init(screen);
|
2014-07-18 20:16:27 +02:00
|
|
|
glamor_sync_init(screen);
|
2010-02-10 06:17:09 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv->screen = screen;
|
2011-08-09 15:59:56 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
return TRUE;
|
2009-08-20 21:32:53 +02:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
fail:
|
2016-11-03 09:59:30 +01:00
|
|
|
/* Restore default CloseScreen and DestroyPixmap handlers */
|
|
|
|
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
|
|
|
|
screen->DestroyPixmap = glamor_priv->saved_procs.destroy_pixmap;
|
|
|
|
|
|
|
|
free_glamor_private:
|
2013-12-18 20:59:07 +01:00
|
|
|
free(glamor_priv);
|
|
|
|
glamor_set_screen_private(screen, NULL);
|
|
|
|
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)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
2012-01-19 13:47:55 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
2014-01-06 02:29:57 +01:00
|
|
|
glamor_fini_vbo(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_pixmap_fini(screen);
|
|
|
|
free(glamor_priv);
|
2012-01-19 13:47:55 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_set_screen_private(screen, NULL);
|
2012-01-19 13:47:55 +01:00
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
Bool
|
2013-12-18 01:32:17 +01:00
|
|
|
glamor_close_screen(ScreenPtr screen)
|
2008-12-17 00:14:31 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv;
|
|
|
|
PixmapPtr screen_pixmap;
|
|
|
|
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
|
2014-10-30 04:30:12 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_priv = glamor_get_screen_private(screen);
|
2014-07-18 20:16:27 +02:00
|
|
|
glamor_sync_close(screen);
|
2014-10-10 09:25:51 +02:00
|
|
|
glamor_composite_glyphs_fini(screen);
|
2013-12-18 20:59:07 +01:00
|
|
|
screen->CloseScreen = glamor_priv->saved_procs.close_screen;
|
|
|
|
|
2014-10-30 04:30:12 +01:00
|
|
|
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;
|
|
|
|
screen->BlockHandler = glamor_priv->saved_procs.block_handler;
|
|
|
|
|
|
|
|
ps->Composite = glamor_priv->saved_procs.composite;
|
|
|
|
ps->Trapezoids = glamor_priv->saved_procs.trapezoids;
|
|
|
|
ps->Triangles = glamor_priv->saved_procs.triangles;
|
2013-12-18 20:59:07 +01:00
|
|
|
ps->CompositeRects = glamor_priv->saved_procs.composite_rects;
|
|
|
|
ps->Glyphs = glamor_priv->saved_procs.glyphs;
|
2014-10-30 04:30:12 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
screen_pixmap = screen->GetScreenPixmap(screen);
|
2019-10-14 12:48:24 +02:00
|
|
|
glamor_pixmap_destroy_fbo(screen_pixmap);
|
2012-02-17 09:56:05 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_release_screen_priv(screen);
|
2011-11-02 06:44:50 +01:00
|
|
|
|
2013-12-18 01:32:17 +01:00
|
|
|
return screen->CloseScreen(screen);
|
2011-04-13 09:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_fini(ScreenPtr screen)
|
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
/* Do nothing currently. */
|
2008-12-17 00:14:31 +01:00
|
|
|
}
|
2013-12-05 08:49:15 +01:00
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
void
|
|
|
|
glamor_enable_dri3(ScreenPtr screen)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
glamor_priv->dri3_enabled = TRUE;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 20:59:07 +01:00
|
|
|
Bool
|
2013-12-31 03:49:46 +01:00
|
|
|
glamor_supports_pixmap_import_export(ScreenPtr screen)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
return glamor_priv->dri3_enabled;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 02:19:44 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
glamor_set_drawable_modifiers_func(ScreenPtr screen,
|
|
|
|
GetDrawableModifiersFuncPtr func)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
glamor_priv->get_drawable_modifiers = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT Bool
|
2018-05-08 01:46:17 +02:00
|
|
|
glamor_get_drawable_modifiers(DrawablePtr draw, uint32_t format,
|
|
|
|
uint32_t *num_modifiers, uint64_t **modifiers)
|
2018-02-28 02:19:44 +01:00
|
|
|
{
|
|
|
|
struct glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(draw->pScreen);
|
|
|
|
|
|
|
|
if (glamor_priv->get_drawable_modifiers) {
|
|
|
|
return glamor_priv->get_drawable_modifiers(draw, format,
|
|
|
|
num_modifiers, modifiers);
|
|
|
|
}
|
|
|
|
*num_modifiers = 0;
|
|
|
|
*modifiers = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-06-21 01:12:31 +02:00
|
|
|
static int
|
|
|
|
_glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
|
|
|
|
uint32_t *strides, uint32_t *offsets,
|
|
|
|
CARD32 *size, uint64_t *modifier)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2015-07-08 02:21:55 +02:00
|
|
|
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(pixmap->drawable.pScreen);
|
|
|
|
|
2015-07-08 02:21:55 +02:00
|
|
|
if (!glamor_priv->dri3_enabled)
|
2018-05-23 11:38:13 +02:00
|
|
|
return 0;
|
2013-12-18 20:59:07 +01:00
|
|
|
switch (pixmap_priv->type) {
|
|
|
|
case GLAMOR_TEXTURE_DRM:
|
|
|
|
case GLAMOR_TEXTURE_ONLY:
|
2019-03-27 00:57:24 +01:00
|
|
|
if (!glamor_pixmap_ensure_fbo(pixmap, 0))
|
2018-05-23 11:38:13 +02:00
|
|
|
return 0;
|
2018-06-21 01:12:31 +02:00
|
|
|
|
|
|
|
if (modifier) {
|
|
|
|
return glamor_egl_fds_from_pixmap(screen, pixmap, fds,
|
|
|
|
strides, offsets,
|
|
|
|
modifier);
|
|
|
|
} else {
|
|
|
|
CARD16 stride;
|
|
|
|
|
|
|
|
fds[0] = glamor_egl_fd_from_pixmap(screen, pixmap, &stride, size);
|
|
|
|
strides[0] = stride;
|
|
|
|
|
|
|
|
return fds[0] >= 0;
|
|
|
|
}
|
2013-12-18 20:59:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-05-23 11:38:13 +02:00
|
|
|
return 0;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 01:12:31 +02:00
|
|
|
_X_EXPORT int
|
|
|
|
glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
|
|
|
|
uint32_t *strides, uint32_t *offsets,
|
|
|
|
uint64_t *modifier)
|
|
|
|
{
|
|
|
|
return _glamor_fds_from_pixmap(screen, pixmap, fds, strides, offsets,
|
|
|
|
NULL, modifier);
|
|
|
|
}
|
|
|
|
|
2016-08-23 12:18:56 +02:00
|
|
|
_X_EXPORT int
|
2018-03-06 10:53:19 +01:00
|
|
|
glamor_fd_from_pixmap(ScreenPtr screen,
|
|
|
|
PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
|
2016-08-23 12:18:56 +02:00
|
|
|
{
|
2018-06-21 01:12:31 +02:00
|
|
|
int fd;
|
2016-08-23 12:18:56 +02:00
|
|
|
int ret;
|
2018-06-21 01:12:31 +02:00
|
|
|
uint32_t stride32;
|
2018-02-28 02:19:43 +01:00
|
|
|
|
2018-06-21 01:12:31 +02:00
|
|
|
ret = _glamor_fds_from_pixmap(screen, pixmap, &fd, &stride32, NULL, size,
|
|
|
|
NULL);
|
|
|
|
if (ret != 1)
|
2018-02-28 02:19:43 +01:00
|
|
|
return -1;
|
|
|
|
|
2018-06-21 01:12:31 +02:00
|
|
|
*stride = stride32;
|
|
|
|
return fd;
|
2018-03-06 10:53:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT int
|
|
|
|
glamor_shareable_fd_from_pixmap(ScreenPtr screen,
|
|
|
|
PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
|
|
|
|
{
|
|
|
|
unsigned orig_usage_hint = pixmap->usage_hint;
|
|
|
|
int ret;
|
2016-08-23 12:18:56 +02:00
|
|
|
|
2018-03-06 10:53:19 +01:00
|
|
|
/*
|
|
|
|
* The actual difference between a sharable and non sharable buffer
|
|
|
|
* is decided 4 call levels deep in glamor_make_pixmap_exportable()
|
|
|
|
* based on pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED
|
|
|
|
* 2 of those calls are also exported API, so we cannot just add a flag.
|
|
|
|
*/
|
|
|
|
pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
|
|
|
|
|
|
|
|
ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
|
|
|
|
|
|
|
|
pixmap->usage_hint = orig_usage_hint;
|
2016-08-23 12:18:56 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-05 08:49:15 +01:00
|
|
|
int
|
2013-12-31 03:41:57 +01:00
|
|
|
glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
|
2013-12-05 08:49:15 +01:00
|
|
|
{
|
2015-07-08 02:21:55 +02:00
|
|
|
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
|
2013-12-18 20:59:07 +01:00
|
|
|
|
|
|
|
switch (pixmap_priv->type) {
|
|
|
|
case GLAMOR_TEXTURE_DRM:
|
|
|
|
case GLAMOR_TEXTURE_ONLY:
|
2019-03-27 00:57:24 +01:00
|
|
|
if (!glamor_pixmap_ensure_fbo(pixmap, 0))
|
2014-04-23 11:54:43 +02:00
|
|
|
return -1;
|
2018-02-28 02:19:43 +01:00
|
|
|
return glamor_egl_fd_name_from_pixmap(pixmap->drawable.pScreen,
|
|
|
|
pixmap, stride, size);
|
2013-12-18 20:59:07 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
2013-12-05 08:49:15 +01:00
|
|
|
}
|
2016-03-11 00:22:00 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
glamor_finish(ScreenPtr screen)
|
|
|
|
{
|
|
|
|
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
|
|
|
|
|
|
|
|
glamor_make_current(glamor_priv);
|
|
|
|
glFinish();
|
|
|
|
}
|