Commit 355334fc authored by Zhigang Gong's avatar Zhigang Gong

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: 's avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent ba6dd8aa
......@@ -31,6 +31,8 @@ libglamor_la_SOURCES = \
glamor_render.c \
glamor_tile.c \
glamor_triangles.c\
glamor_pixmap.c\
glamor_picture.c\
glamor.h
libglamor_la_LIBADD = \
glu3/libglu3.la
......@@ -59,8 +59,7 @@ glamor_get_drawable_pixmap(DrawablePtr drawable)
return (PixmapPtr)drawable;
}
void
static void
glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex)
{
ScreenPtr screen = pixmap->drawable.pScreen;
......@@ -73,6 +72,8 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex)
/* Create a framebuffer object wrapping the texture so that we can render
* to it.
*/
pixmap_priv->gl_fbo = 1;
pixmap_priv->gl_tex = 1;
glGenFramebuffersEXT(1, &pixmap_priv->fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
......@@ -87,13 +88,24 @@ glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex)
NULL);
}
/* Set screen pixmap. If tex equal to 0, means it is called from ephyr. */
void
glamor_set_screen_pixmap_texture(ScreenPtr screen, int w, int h, unsigned int tex)
{
PixmapPtr pixmap = screen->GetScreenPixmap(screen);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_set_pixmap_texture(pixmap, w, h, tex);
glamor_priv->screen_fbo = pixmap_priv->fb;
}
#define GLAMOR_PIXMAP_MEMORY 0
#define GLAMOR_PIXMAP_TEXTURE 1
/* XXX For the screen pixmap, the w and h maybe 0,0 too, but it should
* be GLAMOR_GL pixmap. Now, all the pixmap will have a valid pixmap_priv.
* This is not good enough. After we can identify which is the screen
* pixmap and which is not, then we can split the pixmap to exclusive
* two types GLAMOR_GL and GLAMOR_FB, and for those GLAMOR_FB pixmaps,
* we don't need to allocate pixmap_priv. */
static PixmapPtr
glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
......@@ -102,22 +114,24 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
PixmapPtr pixmap;
GLenum format;
GLuint tex;
enum glamor_pixmap_type type = GLAMOR_GL;
int type = GLAMOR_PIXMAP_TEXTURE;
glamor_pixmap_private *pixmap_priv;
if (w > 32767 || h > 32767)
return NullPixmap;
if (w > MAX_WIDTH || h > MAX_HEIGHT || ( depth == 1 && w != 0 && h != 0)) {
if (!glamor_check_fbo_width_height(w,h) || !glamor_check_fbo_depth(depth)) {
/* MESA can only support upto MAX_WIDTH*MAX_HEIGHT fbo.
If we exceed such limitation, we have to use framebuffer.*/
type = GLAMOR_FB;
type = GLAMOR_PIXMAP_MEMORY;
pixmap = fbCreatePixmap (screen, w, h, depth, usage);
screen->ModifyPixmapHeader(pixmap, w, h, 0, 0,
(((w * pixmap->drawable.bitsPerPixel +
7) / 8) + 3) & ~3,
NULL);
glamor_fallback("fallback to software fb for pixmap %p , %d x %d depth %d\n", pixmap, w, h, depth);
glamor_fallback("choose cpu memory for pixmap %p ,"
" %d x %d depth %d\n", pixmap, w, h, depth);
} else
pixmap = fbCreatePixmap (screen, 0, 0, depth, usage);
......@@ -127,7 +141,10 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
return NullPixmap;
}
if (w == 0 || h == 0 || type == GLAMOR_FB)
pixmap_priv = glamor_get_pixmap_private(pixmap);
pixmap_priv->container = pixmap;
if (w == 0 || h == 0 || type == GLAMOR_PIXMAP_MEMORY)
return pixmap;
/* We should probably take advantage of ARB_fbo's allowance of GL_ALPHA.
......@@ -154,13 +171,51 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
return pixmap;
}
/**
* For Xephyr use only. set up the screen pixmap to correct state.
**/
static PixmapPtr
glamor_create_screen_pixmap(ScreenPtr screen, int w, int h, int depth,
unsigned int usage)
{
PixmapPtr pixmap;
glamor_pixmap_private *pixmap_priv;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
assert(w ==0 && h == 0);
glamor_priv->screen_fbo = 0;
pixmap = fbCreatePixmap (screen, 0, 0, depth, usage);
if (dixAllocatePrivates(&pixmap->devPrivates, PRIVATE_PIXMAP) != TRUE) {
fbDestroyPixmap(pixmap);
ErrorF("Fail to allocate privates for PIXMAP.\n");
return NullPixmap;
}
pixmap_priv = glamor_get_pixmap_private(pixmap);
pixmap_priv->tex = 0;
pixmap_priv->gl_fbo = 1;
pixmap_priv->gl_tex = 1;
screen->CreatePixmap = glamor_create_pixmap;
return pixmap;
}
static Bool
glamor_destroy_pixmap(PixmapPtr pixmap)
{
if (pixmap->refcnt == 1) {
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
if (pixmap_priv->fb)
glDeleteFramebuffersEXT(1, &pixmap_priv->fb);
if (pixmap_priv->tex)
glDeleteTextures(1, &pixmap_priv->tex);
if (pixmap_priv->pbo)
glDeleteBuffersARB(1, &pixmap_priv->pbo);
}
return fbDestroyPixmap(pixmap);
......@@ -177,6 +232,18 @@ glamor_wakeup_handler(void *data, int result, void *last_select_mask)
{
}
static void
glamor_set_debug_level(int *debug_level)
{
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;
}
int glamor_debug_level;
/** Set up glamor for an already-configured GL context. */
Bool
glamor_init(ScreenPtr screen, unsigned int flags)
......@@ -186,7 +253,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
#ifdef RENDER
PictureScreenPtr ps = GetPictureScreenIfSet(screen);
#endif
if (flags & ~GLAMOR_VALID_FLAGS) {
ErrorF("glamor_init: Invalid flags %x\n", flags);
return FALSE;
......@@ -205,7 +271,9 @@ glamor_init(ScreenPtr screen, unsigned int flags)
LogMessage(X_WARNING,
"glamor%d: Failed to allocate screen private\n",
screen->myNum);
return FALSE;
}
dixSetPrivate(&screen->devPrivates, glamor_screen_private_key, glamor_priv);
if (!dixRegisterPrivateKey(glamor_pixmap_private_key,PRIVATE_PIXMAP,
......@@ -213,6 +281,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
LogMessage(X_WARNING,
"glamor%d: Failed to allocate pixmap private\n",
screen->myNum);
return FALSE;
}
glewInit();
......@@ -243,7 +312,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
goto fail;
}
glamor_set_debug_level(&glamor_debug_level);
glamor_priv->saved_close_screen = screen->CloseScreen;
screen->CloseScreen = glamor_close_screen;
......@@ -251,6 +320,10 @@ glamor_init(ScreenPtr screen, unsigned int flags)
screen->CreateGC = glamor_create_gc;
glamor_priv->saved_create_pixmap = screen->CreatePixmap;
if (flags & GLAMOR_HOSTX)
screen->CreatePixmap = glamor_create_screen_pixmap;
else
screen->CreatePixmap = glamor_create_pixmap;
glamor_priv->saved_destroy_pixmap = screen->DestroyPixmap;
......@@ -281,6 +354,10 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_priv->saved_triangles = ps->Triangles;
ps->Triangles = glamor_triangles;
glamor_init_composite_shaders(screen);
glamor_priv->saved_create_picture = ps->CreatePicture;
ps->CreatePicture = glamor_create_picture;
glamor_priv->saved_destroy_picture = ps->DestroyPicture;
ps->DestroyPicture = glamor_destroy_picture;
#endif
glamor_init_solid_shader(screen);
glamor_init_tile_shader(screen);
......@@ -288,7 +365,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
glamor_init_finish_access_shaders(screen);
glamor_glyphs_init(screen);
return TRUE;
fail:
......@@ -319,6 +395,7 @@ glamor_close_screen(int idx, ScreenPtr screen)
ps->Trapezoids = glamor_priv->saved_trapezoids;
ps->Glyphs = glamor_priv->saved_glyphs;
ps->Triangles = glamor_priv->saved_triangles;
ps->CreatePicture = glamor_priv->saved_create_picture;
}
#endif
free(glamor_priv);
......
......@@ -39,9 +39,10 @@
#endif /* GLAMOR_H */
#define GLAMOR_INVERTED_Y_AXIS 0x1
#define GLAMOR_VALID_FLAGS (GLAMOR_INVERTED_Y_AXIS)
#define GLAMOR_INVERTED_Y_AXIS 1
#define GLAMOR_HOSTX 2
#define GLAMOR_VALID_FLAGS (GLAMOR_INVERTED_Y_AXIS | GLAMOR_HOSTX)
Bool glamor_init(ScreenPtr screen, unsigned int flags);
void glamor_fini(ScreenPtr screen);
void glamor_set_pixmap_texture(PixmapPtr pixmap, int w, int h, unsigned int tex);
void glamor_set_screen_pixmap_texture(ScreenPtr screen, int w, int h, unsigned int tex);
......@@ -31,7 +31,6 @@
*
* GC CopyArea implementation
*/
static Bool
glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
DrawablePtr dst,
......@@ -49,45 +48,36 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
if (src == dst) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_fbo_blit(): "
"src == dest\n");
glamor_delayed_fallback(screen,"src == dest\n");
return FALSE;
}
if (!GLEW_EXT_framebuffer_blit) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_fbo_blit(): "
"no EXT_framebuffer_blit\n");
glamor_delayed_fallback(screen,"no EXT_framebuffer_blit\n");
return FALSE;
}
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
if (src_pixmap_priv->fb == 0) {
PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen);
if (src_pixmap != screen_pixmap) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_fbo_blit(): "
"no src fbo\n");
return FALSE;
}
}
if (gc) {
if (gc->alu != GXcopy) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_fbo_blit(): "
"non-copy ALU\n");
glamor_delayed_fallback(screen, "non-copy ALU\n");
return FALSE;
}
if (!glamor_pm_is_solid(dst, gc->planemask)) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_fbo_blit(): "
"non-solid planemask\n");
glamor_delayed_fallback(screen, "non-solid planemask\n");
return FALSE;
}
}
if (!glamor_set_destination_pixmap(dst_pixmap))
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)) {
glamor_delayed_fallback(screen, "no src fbo\n");
return FALSE;
}
if (glamor_set_destination_pixmap(dst_pixmap)) {
return FALSE;
}
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->fb);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
......@@ -124,7 +114,6 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
GL_NEAREST);
}
}
return TRUE;
}
......@@ -142,29 +131,26 @@ glamor_copy_n_to_n_copypixels(DrawablePtr src,
glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen);
int x_off, y_off, i;
if (src != dst) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_copypixels(): "
"src != dest\n");
glamor_delayed_fallback(screen, "src != dest\n");
return FALSE;
}
if (gc) {
if (gc->alu != GXcopy) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_copypixels(): "
"non-copy ALU\n");
glamor_delayed_fallback(screen,"non-copy ALU\n");
return FALSE;
}
if (!glamor_pm_is_solid(dst, gc->planemask)) {
glamor_delayed_fallback(screen, "glamor_copy_n_to_n_copypixels(): "
"non-solid planemask\n");
glamor_delayed_fallback(screen,"non-solid planemask\n");
return FALSE;
}
}
if (!glamor_set_destination_pixmap(dst_pixmap))
if (glamor_set_destination_pixmap(dst_pixmap)) {
glamor_delayed_fallback(screen, "dst has no fbo.\n");
return FALSE;
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0, dst_pixmap->drawable.width,
......@@ -196,7 +182,6 @@ glamor_copy_n_to_n_copypixels(DrawablePtr src,
GL_COLOR);
}
}
return TRUE;
}
......@@ -216,22 +201,34 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
int i;
float vertices[4][2], texcoords[4][2];
glamor_pixmap_private *src_pixmap_priv;
glamor_pixmap_private *dst_pixmap_priv;
int src_x_off, src_y_off, dst_x_off, dst_y_off;
enum glamor_pixmap_status src_status = GLAMOR_NONE;
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
if (src == dst) {
glamor_fallback("glamor_copy_n_to_n with same src/dst\n");
glamor_delayed_fallback(dst->pScreen, "same src/dst\n");
goto fail;
}
if (!src_pixmap_priv || !src_pixmap_priv->tex) {
glamor_fallback("glamor_copy_n_to_n with non-texture src\n");
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) {
glamor_delayed_fallback(dst->pScreen, "dst has no fbo.\n");
goto fail;
}
if (!glamor_set_destination_pixmap(dst_pixmap))
if (!src_pixmap_priv->gl_tex) {
#ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n");
goto fail;
#else
/* XXX in yInverted mode we have bug here.*/
if (!glamor_priv->yInverted) goto fail;
src_status = glamor_upload_pixmap_to_texture(src_pixmap);
if (src_status != GLAMOR_UPLOAD_DONE)
goto fail;
#endif
}
if (gc) {
glamor_set_alu(gc->alu);
......@@ -239,6 +236,8 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
goto fail;
}
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
dx += src_x_off;
......@@ -258,7 +257,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
assert(GLEW_ARB_fragment_shader);
glUseProgramObjectARB(glamor_priv->finish_access_prog);
glUseProgramObjectARB(glamor_priv->finish_access_prog[0]);
for (i = 0; i < nbox; i++) {
......@@ -324,23 +323,23 @@ glamor_copy_n_to_n(DrawablePtr src,
void *closure)
{
if (glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) {
glamor_clear_delayed_fallbacks(dst->pScreen);
goto done;
return;
}
if (glamor_copy_n_to_n_copypixels(src, dst, gc, box, nbox, dx, dy)) {
glamor_clear_delayed_fallbacks(dst->pScreen);
if (glamor_copy_n_to_n_copypixels(src, dst, gc, box, nbox, dx, dy)){
goto done;
return;
}
if (glamor_copy_n_to_n_textured(src, dst, gc, box, nbox, dx, dy)) {
glamor_clear_delayed_fallbacks(dst->pScreen);
goto done;
return;
}
glamor_report_delayed_fallbacks(src->pScreen);
glamor_report_delayed_fallbacks(dst->pScreen);
glamor_fallback("glamor_copy_area() from %p to %p (%c,%c)\n", src, dst,
glamor_fallback("from %p to %p (%c,%c)\n", src, dst,
glamor_get_drawable_location(src),
glamor_get_drawable_location(dst));
if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW)) {
......@@ -352,6 +351,11 @@ glamor_copy_n_to_n(DrawablePtr src,
}
glamor_finish_access(dst);
}
return;
done:
glamor_clear_delayed_fallbacks(src->pScreen);
glamor_clear_delayed_fallbacks(dst->pScreen);
}
RegionPtr
......
This diff is collapsed.
#ifndef __GLAMOR_DEBUG_H__
#define __GLAMOR_DEBUG_H__
#define GLAMOR_DELAYED_STRING_MAX 64
#define GLAMOR_DEBUG_NONE 0
#define GLAMOR_DEBUG_FALLBACK 1
#define GLAMOR_DEBUG_TEXTURE_DYNAMIC_UPLOAD 2
#define GLAMOR_DEBUG_TEXTURE_DOWNLOAD 3
#define __debug_output_message(_format_, _prefix_, ...) \
LogMessageVerb(X_NONE, 0, \
"%32s:\t" _format_ , \
/*_prefix_,*/ \
__FUNCTION__, \
##__VA_ARGS__)
#define glamor_debug_output(_level_, _format_,...) \
do { \
if (glamor_debug_level >= _level_) \
__debug_output_message(_format_, \
"Glamor debug", \
##__VA_ARGS__); \
} while(0)
#define glamor_fallback(_format_,...) \
do { \
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) \
__debug_output_message(_format_, \
"Glamor fallback", \
##__VA_ARGS__);} while(0)
#define glamor_delayed_fallback(_screen_, _format_,...) \
do { \
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
glamor_screen_private *_glamor_priv_; \
_glamor_priv_ = glamor_get_screen_private(_screen_); \
_glamor_priv_->delayed_fallback_pending = 1; \
snprintf(_glamor_priv_->delayed_fallback_string, \
GLAMOR_DELAYED_STRING_MAX, \
"glamor delayed fallback: \t%s " _format_ , \
__FUNCTION__, ##__VA_ARGS__); } } while(0)
#define glamor_clear_delayed_fallbacks(_screen_) \
do { \
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
glamor_screen_private *_glamor_priv_; \
_glamor_priv_ = glamor_get_screen_private(_screen_); \
_glamor_priv_->delayed_fallback_pending = 0; } } while(0)
#define glamor_report_delayed_fallbacks(_screen_) \
do { \
if (glamor_debug_level >= GLAMOR_DEBUG_FALLBACK) { \
glamor_screen_private *_glamor_priv_; \
_glamor_priv_ = glamor_get_screen_private(_screen_); \
LogMessageVerb(X_INFO, 0, "%s", \
_glamor_priv_->delayed_fallback_string); \
_glamor_priv_->delayed_fallback_pending = 0; } } while(0)
#endif
......@@ -89,7 +89,6 @@ glamor_fill(DrawablePtr drawable,
}
return;
fail:
glamor_fallback("glamor_fill()");
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
if (glamor_prepare_access_gc(gc)) {
fbFill(drawable, gc, x, y, width, height);
......@@ -154,16 +153,22 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
GLfloat color[4];
float vertices[4][2];
if (!glamor_set_destination_pixmap(pixmap))
if (glamor_set_destination_pixmap(pixmap)) {
glamor_fallback("dest has no fbo.\n");
goto fail;
}
glamor_set_alu(alu);
if (!glamor_set_planemask(pixmap, planemask)) {
ErrorF("Failedto set planemask in glamor_solid.\n");
glamor_fallback("Failedto set planemask in glamor_solid.\n");
goto fail;
}
glUseProgramObjectARB(glamor_priv->solid_prog);
glamor_get_color_4f_from_pixel(pixmap, fg_pixel, color);
glamor_get_rgba_from_pixel(fg_pixel,
&color[0],
&color[1],
&color[2],
&color[3],
format_for_pixmap(pixmap));
glUniform4fvARB(glamor_priv->solid_color_uniform_location, 1, color);
glVertexPointer(2, GL_FLOAT, sizeof(float) * 2, vertices);
......@@ -196,22 +201,4 @@ fail:
return FALSE;
}
/* Highlight places where we're doing it wrong. */
void
glamor_solid_fail_region(PixmapPtr pixmap, int x, int y, int width, int height)
{
unsigned long pixel;
switch (pixmap->drawable.depth) {
case 24:
case 32:
pixel = 0x00ff00ff; /* our favorite color */
break;
default:
case 8:
pixel = 0xd0d0d0d0;
break;
}
glamor_solid(pixmap, x, y, width, height, GXcopy, ~0, pixel);
}
......@@ -50,7 +50,6 @@ glamor_fill_spans(DrawablePtr drawable,
if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled)
goto fail;
glamor_get_drawable_deltas(drawable, pixmap, &off_x, &off_y);
ppt = points;
while (n--) {
......@@ -82,7 +81,7 @@ glamor_fill_spans(DrawablePtr drawable,
}
return;
fail:
glamor_fallback("glamor_fillspans(): to %p (%c)\n", drawable,
glamor_fallback("to %p (%c)\n", drawable,
glamor_get_drawable_location(drawable));
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
if (glamor_prepare_access_gc(gc)) {
......
......@@ -31,18 +31,6 @@
#include "glamor_priv.h"
static void
set_bit(uint8_t *bitfield, unsigned int index, unsigned int val)
{
int i = index / 8;
int mask = 1 << (index % 8);
if (val)
bitfield[i] |= mask;
else
bitfield[i] &= ~mask;
}
void
glamor_get_spans(DrawablePtr drawable,
int wmax,
......@@ -53,39 +41,27 @@ glamor_get_spans(DrawablePtr drawable,
{
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
GLenum format, type;
int ax;
glamor_screen_private *glamor_priv =
glamor_get_screen_private(drawable->pScreen);
int i, j;
uint8_t *temp_dst = NULL, *readpixels_dst = (uint8_t *)dst;
int i;
uint8_t *readpixels_dst = (uint8_t *)dst;
int x_off, y_off;
switch (drawable->depth) {
case 1:
temp_dst = malloc(wmax);
format = GL_ALPHA;
type = GL_UNSIGNED_BYTE;
readpixels_dst = temp_dst;
break;
case 8:
format = GL_ALPHA;
type = GL_UNSIGNED_BYTE;
break;
case 24:
case 32:
format = GL_BGRA;
type = GL_UNSIGNED_INT_8_8_8_8_REV;
break;
default:
glamor_fallback("glamor_get_spans(): "
"Unknown getspans depth %d\n", drawable->depth);
if (glamor_get_tex_format_type_from_pixmap(pixmap,
&format,
&type,
&ax
)) {
glamor_fallback("unknown depth. %d \n",
drawable->depth);
goto fail;
}
if (!glamor_set_destination_pixmap(pixmap))
if (glamor_set_destination_pixmap(pixmap)) {
glamor_fallback("pixmap has no fbo.\n");
goto fail;
}
glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
for (i = 0; i < count; i++) {
if (glamor_priv->yInverted) {
glReadPixels(points[i].x + x_off,
......@@ -102,21 +78,12 @@ glamor_get_spans(DrawablePtr drawable,
format, type,
readpixels_dst);
}
if (temp_dst) {
for (j = 0; j < widths[i]; j++) {
set_bit((uint8_t *)dst, j, temp_dst[j] & 0x1);
}
dst += PixmapBytePad(widths[i], drawable->depth);
} else {
readpixels_dst += PixmapBytePad(widths[i], drawable->depth);
}
}
free(temp_dst);
return;
fail:
free(temp_dst);
glamor_fallback("glamor_get_spans() from %p (%c)\n", drawable,
glamor_fallback("from %p (%c)\n", drawable,
glamor_get_drawable_location(drawable));
if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) {
fbGetSpans(drawable, wmax, points, widths, count, dst);
......
......@@ -67,6 +67,7 @@
*/
#define GLYPH_BUFFER_SIZE 256
typedef struct {
PicturePtr source;
glamor_composite_rect_t rects[GLYPH_BUFFER_SIZE];
......@@ -573,6 +574,7 @@ static void glamor_glyphs_to_mask(PicturePtr mask,
glamor_glyph_buffer_t *buffer)
{
#ifdef RENDER
glamor_composite_rects(PictOpAdd, buffer->source, mask,
buffer->count, buffer->rects);
#endif
......
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <stdlib.h>
#include "glamor_priv.h"
/* Upload picture to texture. We may need to flip the y axis or
* wire alpha to 1. So we may conditional create fbo for the picture.
* */
enum glamor_pixmap_status
glamor_upload_picture_to_texture(PicturePtr picture)
{
PixmapPtr pixmap;
glamor_pixmap_private *pixmap_priv;
assert(picture->pDrawable);
pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
pixmap_priv = glamor_get_pixmap_private(pixmap);
assert(GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) == 1);
return glamor_upload_pixmap_to_texture(pixmap);
}