2009-09-05 03:43:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Intel Corporation
|
|
|
|
* Copyright © 1998 Keith Packard
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Keith Packard not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Keith Packard makes no
|
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "glamor_priv.h"
|
|
|
|
|
|
|
|
/** @file glamor_copyarea.c
|
|
|
|
*
|
|
|
|
* GC CopyArea implementation
|
|
|
|
*/
|
2011-08-03 04:49:18 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2010-02-19 16:14:13 +01:00
|
|
|
static Bool
|
|
|
|
glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
|
|
|
|
DrawablePtr dst,
|
2011-11-02 06:44:50 +01:00
|
|
|
GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
|
2010-02-19 16:14:13 +01:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
ScreenPtr screen = dst->pScreen;
|
|
|
|
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
|
|
|
|
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
|
|
|
|
glamor_pixmap_private *src_pixmap_priv;
|
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(screen);
|
|
|
|
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
|
|
|
|
int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
|
|
|
|
|
|
|
|
if (!glamor_priv->has_fbo_blit) {
|
|
|
|
glamor_delayed_fallback(screen,
|
|
|
|
"no EXT_framebuffer_blit\n");
|
|
|
|
return FALSE;
|
2010-02-19 16:14:13 +01:00
|
|
|
}
|
2011-11-02 06:44:50 +01:00
|
|
|
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
|
|
|
|
|
|
|
if (src_pixmap_priv->pending_op.type == GLAMOR_PENDING_FILL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gc) {
|
|
|
|
if (gc->alu != GXcopy) {
|
|
|
|
glamor_delayed_fallback(screen, "non-copy ALU\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!glamor_pm_is_solid(dst, gc->planemask)) {
|
|
|
|
glamor_delayed_fallback(screen,
|
|
|
|
"non-solid planemask\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-02-19 16:14:13 +01:00
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)) {
|
|
|
|
glamor_delayed_fallback(screen, "no src fbo\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-02-19 16:14:13 +01:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (glamor_set_destination_pixmap(dst_pixmap)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
glamor_validate_pixmap(dst_pixmap);
|
|
|
|
|
|
|
|
dispatch->glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT,
|
|
|
|
src_pixmap_priv->fb);
|
|
|
|
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);
|
|
|
|
src_y_off += dy;
|
|
|
|
|
|
|
|
for (i = 0; i < nbox; i++) {
|
|
|
|
if (glamor_priv->yInverted) {
|
|
|
|
dispatch->glBlitFramebuffer((box[i].x1 + dx +
|
|
|
|
src_x_off),
|
|
|
|
(box[i].y1 +
|
|
|
|
src_y_off),
|
|
|
|
(box[i].x2 + dx +
|
|
|
|
src_x_off),
|
|
|
|
(box[i].y2 +
|
|
|
|
src_y_off),
|
|
|
|
(box[i].x1 +
|
|
|
|
dst_x_off),
|
|
|
|
(box[i].y1 +
|
|
|
|
dst_y_off),
|
|
|
|
(box[i].x2 +
|
|
|
|
dst_x_off),
|
|
|
|
(box[i].y2 +
|
|
|
|
dst_y_off),
|
|
|
|
GL_COLOR_BUFFER_BIT,
|
|
|
|
GL_NEAREST);
|
|
|
|
} else {
|
|
|
|
int flip_dst_y1 =
|
|
|
|
dst_pixmap->drawable.height - (box[i].y2 +
|
|
|
|
dst_y_off);
|
|
|
|
int flip_dst_y2 =
|
|
|
|
dst_pixmap->drawable.height - (box[i].y1 +
|
|
|
|
dst_y_off);
|
|
|
|
int flip_src_y1 =
|
|
|
|
src_pixmap->drawable.height - (box[i].y2 +
|
|
|
|
src_y_off);
|
|
|
|
int flip_src_y2 =
|
|
|
|
src_pixmap->drawable.height - (box[i].y1 +
|
|
|
|
src_y_off);
|
|
|
|
|
|
|
|
dispatch->glBlitFramebuffer(box[i].x1 + dx +
|
|
|
|
src_x_off,
|
|
|
|
flip_src_y1,
|
|
|
|
box[i].x2 + dx +
|
|
|
|
src_x_off,
|
|
|
|
flip_src_y2,
|
|
|
|
box[i].x1 +
|
|
|
|
dst_x_off,
|
|
|
|
flip_dst_y1,
|
|
|
|
box[i].x2 +
|
|
|
|
dst_x_off,
|
|
|
|
flip_dst_y2,
|
|
|
|
GL_COLOR_BUFFER_BIT,
|
|
|
|
GL_NEAREST);
|
|
|
|
}
|
2011-05-11 19:08:38 +02:00
|
|
|
}
|
2011-11-02 06:44:50 +01:00
|
|
|
return TRUE;
|
2010-02-19 16:14:13 +01:00
|
|
|
}
|
2011-08-03 04:49:18 +02:00
|
|
|
#endif
|
2010-02-19 16:14:13 +01:00
|
|
|
|
2010-02-11 18:47:38 +01:00
|
|
|
static Bool
|
|
|
|
glamor_copy_n_to_n_textured(DrawablePtr src,
|
2011-11-02 06:44:50 +01:00
|
|
|
DrawablePtr dst,
|
|
|
|
GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
|
2009-09-05 03:43:02 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_screen_private *glamor_priv =
|
|
|
|
glamor_get_screen_private(dst->pScreen);
|
|
|
|
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
|
|
|
|
PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
|
|
|
|
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
|
|
|
|
int i;
|
|
|
|
float vertices[8], texcoords[8];
|
|
|
|
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;
|
|
|
|
GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale;
|
|
|
|
int flush_needed = 0;
|
|
|
|
|
|
|
|
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
|
|
|
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
|
|
|
|
|
|
|
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) {
|
|
|
|
glamor_delayed_fallback(dst->pScreen, "dst has no fbo.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!src_pixmap_priv->gl_fbo) {
|
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
|
|
|
#ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n");
|
|
|
|
goto fail;
|
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
|
|
|
#else
|
2011-11-02 06:44:50 +01:00
|
|
|
src_status = glamor_upload_pixmap_to_texture(src_pixmap);
|
|
|
|
if (src_status != GLAMOR_UPLOAD_DONE)
|
|
|
|
goto fail;
|
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
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
} else
|
|
|
|
flush_needed = 1;
|
|
|
|
|
|
|
|
if (gc) {
|
|
|
|
glamor_set_alu(dispatch, gc->alu);
|
|
|
|
if (!glamor_set_planemask(dst_pixmap, gc->planemask))
|
|
|
|
goto fail;
|
|
|
|
if (gc->alu != GXcopy) {
|
|
|
|
glamor_set_destination_pixmap_priv_nc
|
|
|
|
(src_pixmap_priv);
|
|
|
|
glamor_validate_pixmap(src_pixmap);
|
|
|
|
}
|
|
|
|
}
|
2010-02-08 21:24:15 +01:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
|
|
|
|
glamor_validate_pixmap(dst_pixmap);
|
2011-07-20 07:06:23 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
pixmap_priv_get_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale);
|
|
|
|
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale);
|
2011-06-22 08:33:38 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
|
|
|
&dst_y_off);
|
2010-02-11 22:21:47 +01:00
|
|
|
|
2010-02-08 21:24:15 +01:00
|
|
|
|
2011-08-03 10:52:19 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
|
|
|
|
GL_FALSE, 2 * sizeof(float),
|
|
|
|
vertices);
|
|
|
|
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
2009-09-05 03:43:02 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (GLAMOR_PIXMAP_PRIV_NO_PENDING(src_pixmap_priv)) {
|
|
|
|
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
|
|
|
&src_y_off);
|
|
|
|
dx += src_x_off;
|
|
|
|
dy += src_y_off;
|
|
|
|
pixmap_priv_get_scale(src_pixmap_priv, &src_xscale,
|
|
|
|
&src_yscale);
|
2011-08-03 10:52:19 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glActiveTexture(GL_TEXTURE0);
|
|
|
|
dispatch->glBindTexture(GL_TEXTURE_2D,
|
|
|
|
src_pixmap_priv->tex);
|
2011-08-15 18:33:35 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glEnable(GL_TEXTURE_2D);
|
2011-08-15 18:33:35 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
|
|
|
GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
dispatch->glTexParameteri(GL_TEXTURE_2D,
|
|
|
|
GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
|
|
|
|
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
|
|
|
|
GL_FLOAT, GL_FALSE,
|
|
|
|
2 * sizeof(float),
|
|
|
|
texcoords);
|
|
|
|
dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
|
|
|
dispatch->glUseProgram(glamor_priv->finish_access_prog[0]);
|
|
|
|
dispatch->
|
|
|
|
glUniform1i(glamor_priv->finish_access_no_revert[0],
|
|
|
|
1);
|
|
|
|
dispatch->
|
|
|
|
glUniform1i(glamor_priv->finish_access_swap_rb[0], 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
GLAMOR_CHECK_PENDING_FILL(dispatch, glamor_priv,
|
|
|
|
src_pixmap_priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nbox; i++) {
|
|
|
|
|
|
|
|
glamor_set_normalize_vcoords(dst_xscale, dst_yscale,
|
|
|
|
box[i].x1 + dst_x_off,
|
|
|
|
box[i].y1 + dst_y_off,
|
|
|
|
box[i].x2 + dst_x_off,
|
|
|
|
box[i].y2 + dst_y_off,
|
|
|
|
glamor_priv->yInverted,
|
|
|
|
vertices);
|
|
|
|
|
|
|
|
if (GLAMOR_PIXMAP_PRIV_NO_PENDING(src_pixmap_priv))
|
|
|
|
glamor_set_normalize_tcoords(src_xscale,
|
|
|
|
src_yscale,
|
|
|
|
box[i].x1 + dx,
|
|
|
|
box[i].y1 + dy,
|
|
|
|
box[i].x2 + dx,
|
|
|
|
box[i].y2 + dy,
|
|
|
|
glamor_priv->yInverted,
|
|
|
|
texcoords);
|
|
|
|
|
|
|
|
dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
|
|
|
if (GLAMOR_PIXMAP_PRIV_NO_PENDING(src_pixmap_priv)) {
|
|
|
|
dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
|
2011-08-15 18:33:35 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
dispatch->glDisable(GL_TEXTURE_2D);
|
2011-08-15 18:33:35 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
}
|
|
|
|
dispatch->glUseProgram(0);
|
|
|
|
/* The source texture is bound to a fbo, we have to flush it here. */
|
|
|
|
if (flush_needed)
|
|
|
|
dispatch->glFlush();
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
glamor_set_alu(dispatch, GXcopy);
|
|
|
|
glamor_set_planemask(dst_pixmap, ~0);
|
|
|
|
return FALSE;
|
2010-02-11 18:47:38 +01:00
|
|
|
}
|
2010-02-08 21:24:15 +01:00
|
|
|
|
2011-12-09 08:58:19 +01:00
|
|
|
static Bool
|
|
|
|
_glamor_copy_n_to_n(DrawablePtr src,
|
|
|
|
DrawablePtr dst,
|
|
|
|
GCPtr gc,
|
|
|
|
BoxPtr box,
|
|
|
|
int nbox,
|
|
|
|
int dx,
|
|
|
|
int dy,
|
|
|
|
Bool reverse,
|
|
|
|
Bool upsidedown, Pixel bitplane,
|
|
|
|
void *closure, Bool fallback)
|
2010-02-11 18:47:38 +01:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_access_t dst_access;
|
|
|
|
PixmapPtr dst_pixmap, src_pixmap, temp_pixmap = NULL;
|
|
|
|
DrawablePtr temp_src = src;
|
|
|
|
glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
|
|
|
|
BoxRec bound;
|
|
|
|
ScreenPtr screen;
|
|
|
|
int temp_dx = dx;
|
|
|
|
int temp_dy = dy;
|
|
|
|
int src_x_off, src_y_off, dst_x_off, dst_y_off;
|
|
|
|
int i;
|
|
|
|
int overlaped = 0;
|
2011-12-09 08:58:19 +01:00
|
|
|
Bool ret = TRUE;
|
2011-11-02 06:44:50 +01:00
|
|
|
|
|
|
|
dst_pixmap = glamor_get_drawable_pixmap(dst);
|
|
|
|
dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
|
|
|
|
src_pixmap = glamor_get_drawable_pixmap(src);
|
|
|
|
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
|
|
|
|
screen = dst_pixmap->drawable.pScreen;
|
|
|
|
|
2011-12-09 08:58:19 +01:00
|
|
|
if (!dst_pixmap_priv || !src_pixmap_priv)
|
|
|
|
goto fail;
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv)) {
|
|
|
|
glamor_fallback("dest pixmap %p has no fbo. \n",
|
|
|
|
dst_pixmap);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off,
|
|
|
|
&src_y_off);
|
|
|
|
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off,
|
|
|
|
&dst_y_off);
|
|
|
|
|
|
|
|
if (src_pixmap_priv->fb == dst_pixmap_priv->fb) {
|
|
|
|
int x_shift = abs(src_x_off - dx - dst_x_off);
|
|
|
|
int y_shift = abs(src_y_off - dy - dst_y_off);
|
|
|
|
for (i = 0; i < nbox; i++) {
|
|
|
|
if (x_shift < abs(box[i].x2 - box[i].x1)
|
|
|
|
&& y_shift < abs(box[i].y2 - box[i].y1)) {
|
|
|
|
overlaped = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* XXX need revisit to handle overlapped area copying. */
|
2011-08-03 04:49:18 +02:00
|
|
|
#ifndef GLAMOR_GLES2
|
2011-11-02 06:44:50 +01:00
|
|
|
if ((overlaped
|
|
|
|
|| !src_pixmap_priv->gl_tex || !dst_pixmap_priv->gl_tex)
|
|
|
|
&& glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx,
|
|
|
|
dy)) {
|
|
|
|
goto done;
|
|
|
|
}
|
2011-08-03 04:49:18 +02:00
|
|
|
#endif
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_calculate_boxes_bound(&bound, box, nbox);
|
|
|
|
|
|
|
|
/* Overlaped indicate the src and dst are the same pixmap. */
|
|
|
|
if (overlaped || (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)
|
|
|
|
&& ((bound.x2 - bound.x1) * (bound.y2 - bound.y1)
|
|
|
|
* 4 >
|
|
|
|
src_pixmap->drawable.width *
|
|
|
|
src_pixmap->drawable.height))) {
|
|
|
|
|
|
|
|
temp_pixmap = (*screen->CreatePixmap) (screen,
|
|
|
|
bound.x2 - bound.x1,
|
|
|
|
bound.y2 - bound.y1,
|
|
|
|
src_pixmap->
|
|
|
|
drawable.depth,
|
|
|
|
overlaped ? 0 :
|
|
|
|
GLAMOR_CREATE_PIXMAP_CPU);
|
|
|
|
if (!temp_pixmap)
|
|
|
|
goto fail;
|
|
|
|
glamor_transform_boxes(box, nbox, -bound.x1, -bound.y1);
|
|
|
|
temp_src = &temp_pixmap->drawable;
|
|
|
|
|
|
|
|
if (overlaped)
|
|
|
|
glamor_copy_n_to_n_textured(src, temp_src, gc, box,
|
|
|
|
nbox,
|
|
|
|
temp_dx + bound.x1,
|
|
|
|
temp_dy + bound.y1);
|
|
|
|
else
|
|
|
|
fbCopyNtoN(src, temp_src, gc, box, nbox,
|
|
|
|
temp_dx + bound.x1, temp_dy + bound.y1,
|
|
|
|
reverse, upsidedown, bitplane, closure);
|
|
|
|
glamor_transform_boxes(box, nbox, bound.x1, bound.y1);
|
|
|
|
temp_dx = -bound.x1;
|
|
|
|
temp_dy = -bound.y1;
|
|
|
|
} else {
|
|
|
|
temp_dx = dx;
|
|
|
|
temp_dy = dy;
|
|
|
|
temp_src = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glamor_copy_n_to_n_textured
|
|
|
|
(temp_src, dst, gc, box, nbox, temp_dx, temp_dy)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fail:
|
2011-12-09 08:58:19 +01:00
|
|
|
|
|
|
|
if (!fallback) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
glamor_report_delayed_fallbacks(src->pScreen);
|
|
|
|
glamor_report_delayed_fallbacks(dst->pScreen);
|
|
|
|
|
|
|
|
glamor_fallback("from %p to %p (%c,%c)\n", src, dst,
|
|
|
|
glamor_get_drawable_location(src),
|
|
|
|
glamor_get_drawable_location(dst));
|
|
|
|
|
|
|
|
if (gc && gc->alu != GXcopy)
|
|
|
|
dst_access = GLAMOR_ACCESS_RW;
|
|
|
|
else
|
|
|
|
dst_access = GLAMOR_ACCESS_WO;
|
|
|
|
|
|
|
|
if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW)) {
|
|
|
|
if (dst == src
|
|
|
|
|| glamor_prepare_access(src, GLAMOR_ACCESS_RO)) {
|
|
|
|
fbCopyNtoN(src, dst, gc, box, nbox,
|
|
|
|
dx, dy, reverse, upsidedown, bitplane,
|
|
|
|
closure);
|
|
|
|
if (dst != src)
|
|
|
|
glamor_finish_access(src);
|
|
|
|
}
|
|
|
|
glamor_finish_access(dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
glamor_clear_delayed_fallbacks(src->pScreen);
|
|
|
|
glamor_clear_delayed_fallbacks(dst->pScreen);
|
|
|
|
if (temp_src != src) {
|
|
|
|
(*screen->DestroyPixmap) (temp_pixmap);
|
2010-02-08 20:12:44 +01:00
|
|
|
}
|
2011-12-09 08:58:19 +01:00
|
|
|
return ret;
|
2009-09-05 03:43:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RegionPtr
|
|
|
|
glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
|
2011-11-02 06:44:50 +01:00
|
|
|
int srcx, int srcy, int width, int height, int dstx,
|
|
|
|
int dsty)
|
2009-09-05 03:43:02 +02:00
|
|
|
{
|
2011-11-02 06:44:50 +01:00
|
|
|
RegionPtr region;
|
|
|
|
region = miDoCopy(src, dst, gc,
|
|
|
|
srcx, srcy, width, height,
|
|
|
|
dstx, dsty, glamor_copy_n_to_n, 0, NULL);
|
2009-09-05 03:43:02 +02:00
|
|
|
|
2011-11-02 06:44:50 +01:00
|
|
|
return region;
|
2009-09-05 03:43:02 +02:00
|
|
|
}
|
2011-12-09 08:58:19 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
glamor_copy_n_to_n(DrawablePtr src,
|
|
|
|
DrawablePtr dst,
|
|
|
|
GCPtr gc,
|
|
|
|
BoxPtr box,
|
|
|
|
int nbox,
|
|
|
|
int dx,
|
|
|
|
int dy,
|
|
|
|
Bool reverse,
|
|
|
|
Bool upsidedown, Pixel bitplane,
|
|
|
|
void *closure)
|
|
|
|
{
|
|
|
|
_glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
|
|
|
|
dy, reverse, upsidedown, bitplane, closure, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
glamor_copy_n_to_n_nf(DrawablePtr src,
|
|
|
|
DrawablePtr dst,
|
|
|
|
GCPtr gc,
|
|
|
|
BoxPtr box,
|
|
|
|
int nbox,
|
|
|
|
int dx,
|
|
|
|
int dy,
|
|
|
|
Bool reverse,
|
|
|
|
Bool upsidedown, Pixel bitplane,
|
|
|
|
void *closure)
|
|
|
|
{
|
|
|
|
return _glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
|
|
|
|
dy, reverse, upsidedown, bitplane, closure, FALSE);
|
|
|
|
}
|
|
|
|
|