Commit ea2fc3e4 authored by Siarhei Siamashka's avatar Siarhei Siamashka
Browse files

Introduce experimental G2D acceleration



This initial G2D support code can speed up moving windows in XFCE. Currently
disabled by default, but can be enabled by editing /etc/X11/xorg.conf and
adding the following line to the "Device" section:

        Option          "AccelMethod" "G2D"
Signed-off-by: default avatarSiarhei Siamashka <siarhei.siamashka@gmail.com>
parent ba548ffb
......@@ -86,6 +86,13 @@ fancy desktop effects such as windows translucency or shadows. Maybe
some improvements are possible in this area. But if you really care
about the desktop performance, then you likely don't want to enable
any compositing effects in your window manager anyway.
.TP
.BI "Option \*qAccelMethod\*q \*q" "string" \*q
Chooses between available acceleration architectures. Currently the
only supported acceleration architecture is
.B G2D.
The default is
.B no 2D hardware acceleration
.SH "SEE ALSO"
__xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__),
......
......@@ -35,6 +35,8 @@ sunxifb_drv_la_SOURCES = \
fbdev_priv.h \
sunxi_disp.c \
sunxi_disp.h \
sunxi_x_g2d.c \
sunxi_x_g2d.h \
sunxi_disp_hwcursor.c \
sunxi_disp_hwcursor.h
......
......@@ -48,6 +48,7 @@
#include "sunxi_disp.h"
#include "sunxi_disp_hwcursor.h"
#include "sunxi_x_g2d.h"
#ifdef HAVE_LIBUMP
#include "sunxi_mali_ump_dri2.h"
......@@ -162,6 +163,7 @@ typedef enum {
OPTION_SW_CURSOR,
OPTION_DRI2,
OPTION_DRI2_OVERLAY,
OPTION_ACCELMETHOD,
} FBDevOpts;
static const OptionInfoRec FBDevOptions[] = {
......@@ -173,6 +175,7 @@ static const OptionInfoRec FBDevOptions[] = {
{ OPTION_SW_CURSOR, "SWCursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_DRI2, "DRI2", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_DRI2_OVERLAY, "DRI2HWOverlay",OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_ACCELMETHOD, "AccelMethod", OPTV_STRING, {0}, FALSE },
{ -1, NULL, OPTV_NONE, {0}, FALSE }
};
......@@ -501,8 +504,9 @@ FBDevPreInit(ScrnInfoPtr pScrn, int flags)
memcpy(fPtr->Options, FBDevOptions, sizeof(FBDevOptions));
xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options, fPtr->Options);
/* use shadow framebuffer by default */
fPtr->shadowFB = xf86ReturnOptValBool(fPtr->Options, OPTION_SHADOW_FB, TRUE);
/* use shadow framebuffer by default unless using HW acceleration */
fPtr->shadowFB = xf86ReturnOptValBool(fPtr->Options, OPTION_SHADOW_FB,
!xf86GetOptValString(fPtr->Options, OPTION_ACCELMETHOD));
debug = xf86ReturnOptValBool(fPtr->Options, OPTION_DEBUG, FALSE);
......@@ -682,6 +686,7 @@ FBDevScreenInit(SCREEN_INIT_ARGS_DECL)
int init_picture = 0;
int ret, flags;
int type;
char *accelmethod;
TRACE_ENTER("FBDevScreenInit");
......@@ -848,6 +853,29 @@ FBDevScreenInit(SCREEN_INIT_ARGS_DECL)
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Render extension initialisation failed\n");
fPtr->sunxi_disp_private = sunxi_disp_init(xf86FindOptionValue(
fPtr->pEnt->device->options,"fbdev"),
fPtr->fbmem);
if (!fPtr->sunxi_disp_private)
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"failed to enable the use of sunxi display controller\n");
if ((accelmethod = xf86GetOptValString(fPtr->Options, OPTION_ACCELMETHOD)) &&
strcasecmp(accelmethod, "g2d") == 0) {
if ((fPtr->SunxiG2D_private = SunxiG2D_Init(pScreen))) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"enabled G2D acceleration\n");
}
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"G2D hardware acceleration can't be enabled\n");
}
}
else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"no 2D acceleration selected via AccelMethod option\n");
}
if (fPtr->shadowFB && !FBDevShadowInit(pScreen)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"shadow framebuffer initialization failed\n");
......@@ -929,14 +957,6 @@ FBDevScreenInit(SCREEN_INIT_ARGS_DECL)
}
#endif
fPtr->sunxi_disp_private = sunxi_disp_init(xf86FindOptionValue(
fPtr->pEnt->device->options,"fbdev"),
fPtr->fbmem);
if (!fPtr->sunxi_disp_private)
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"failed to enable the use of sunxi display controller\n");
if (!xf86ReturnOptValBool(fPtr->Options, OPTION_SW_CURSOR, FALSE) &&
xf86ReturnOptValBool(fPtr->Options, OPTION_HW_CURSOR, TRUE)) {
......@@ -995,11 +1015,6 @@ FBDevCloseScreen(CLOSE_SCREEN_ARGS_DECL)
fPtr->SunxiDispHardwareCursor_private = NULL;
}
if (fPtr->sunxi_disp_private) {
sunxi_disp_close(fPtr->sunxi_disp_private);
fPtr->sunxi_disp_private = NULL;
}
fbdevHWRestore(pScrn);
fbdevHWUnmapVidmem(pScrn);
if (fPtr->shadow) {
......@@ -1007,6 +1022,17 @@ FBDevCloseScreen(CLOSE_SCREEN_ARGS_DECL)
free(fPtr->shadow);
fPtr->shadow = NULL;
}
if (fPtr->SunxiG2D_private) {
SunxiG2D_Close(pScreen);
free(fPtr->SunxiG2D_private);
fPtr->SunxiG2D_private = NULL;
}
if (fPtr->sunxi_disp_private) {
sunxi_disp_close(fPtr->sunxi_disp_private);
fPtr->sunxi_disp_private = NULL;
}
if (fPtr->pDGAMode) {
free(fPtr->pDGAMode);
fPtr->pDGAMode = NULL;
......
......@@ -51,6 +51,7 @@ typedef struct {
void *sunxi_disp_private;;
void *SunxiDispHardwareCursor_private;
void *SunxiMaliDRI2_private;
void *SunxiG2D_private;
} FBDevRec, *FBDevPtr;
#define FBDEVPTR(p) ((FBDevPtr)((p)->driverPrivate))
......@@ -58,6 +59,9 @@ typedef struct {
#define SUNXI_DISP(p) ((sunxi_disp_t *) \
(FBDEVPTR(p)->sunxi_disp_private))
#define SUNXI_G2D(p) ((SunxiG2D *) \
(FBDEVPTR(p)->SunxiG2D_private))
#define SUNXI_DISP_HWC(p) ((SunxiDispHardwareCursor *) \
(FBDEVPTR(p)->SunxiDispHardwareCursor_private))
......
/*
* Copyright © 2013 Siarhei Siamashka <siarhei.siamashka@gmail.com>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xorgVersion.h"
#include "xf86_OSproc.h"
#include "xf86.h"
#include "xf86drm.h"
#include "dri2.h"
#include "damage.h"
#include "fb.h"
#include "fbdev_priv.h"
#include "sunxi_disp.h"
#include "sunxi_x_g2d.h"
/*
* The code below is borrowed from "xserver/fb/fbwindow.c"
*/
static void
xCopyWindowProc(DrawablePtr pSrcDrawable,
DrawablePtr pDstDrawable,
GCPtr pGC,
BoxPtr pbox,
int nbox,
int dx,
int dy,
Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
{
FbBits *src;
FbStride srcStride;
int srcBpp;
int srcXoff, srcYoff;
FbBits *dst;
FbStride dstStride;
int dstBpp;
int dstXoff, dstYoff;
ScreenPtr pScreen = pDstDrawable->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
sunxi_disp_t *disp = SUNXI_DISP(pScrn);
fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
if (srcBpp == 32 && dstBpp == 32 &&
disp->framebuffer_addr == src && disp->framebuffer_addr == dst &&
(dy + srcYoff != dstYoff || dx + srcXoff + 1 >= dstXoff))
{
while (nbox--) {
sunxi_g2d_blit_a8r8g8b8(disp,
pbox->x1 + dstXoff, pbox->y1 + dstYoff,
pbox->x1 + dx + srcXoff, pbox->y1 + dy + srcYoff,
pbox->x2 - pbox->x1,
pbox->y2 - pbox->y1);
pbox++;
}
}
else {
while (nbox--) {
fbBlt(src + (pbox->y1 + dy + srcYoff) * srcStride,
srcStride,
(pbox->x1 + dx + srcXoff) * srcBpp,
dst + (pbox->y1 + dstYoff) * dstStride,
dstStride,
(pbox->x1 + dstXoff) * dstBpp,
(pbox->x2 - pbox->x1) * dstBpp,
(pbox->y2 - pbox->y1),
GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
pbox++;
}
}
fbFinishAccess(pDstDrawable);
fbFinishAccess(pSrcDrawable);
}
static void
xCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
{
RegionRec rgnDst;
int dx, dy;
PixmapPtr pPixmap = fbGetWindowPixmap(pWin);
DrawablePtr pDrawable = &pPixmap->drawable;
dx = ptOldOrg.x - pWin->drawable.x;
dy = ptOldOrg.y - pWin->drawable.y;
RegionTranslate(prgnSrc, -dx, -dy);
RegionNull(&rgnDst);
RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
#ifdef COMPOSITE
if (pPixmap->screen_x || pPixmap->screen_y)
RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
#endif
miCopyRegion(pDrawable, pDrawable,
0, &rgnDst, dx, dy, xCopyWindowProc, 0, 0);
RegionUninit(&rgnDst);
fbValidateDrawable(&pWin->drawable);
}
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
sunxi_disp_t *disp = SUNXI_DISP(pScrn);
SunxiG2D *private;
if (!disp || disp->fd_g2d < 0) {
xf86DrvMsg(pScreen->myNum, X_INFO,
"No sunxi-g2d hardware detected (check /dev/disp and /dev/g2d)\n");
return NULL;
}
private = calloc(1, sizeof(SunxiG2D));
if (!private) {
xf86DrvMsg(pScreen->myNum, X_INFO,
"SunxiG2D_Init: calloc failed\n");
return NULL;
}
/* Wrap the current CopyWindow function */
private->CopyWindow = pScreen->CopyWindow;
pScreen->CopyWindow = xCopyWindow;
return private;
}
void SunxiG2D_Close(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
SunxiG2D *private = SUNXI_G2D(pScrn);
pScreen->CopyWindow = private->CopyWindow;
}
/*
* Copyright © 2013 Siarhei Siamashka <siarhei.siamashka@gmail.com>
*
* 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.
*/
#ifndef SUNXI_X_G2D_H
#define SUNXI_X_G2D_H
typedef struct {
CopyWindowProcPtr CopyWindow;
} SunxiG2D;
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen);
void SunxiG2D_Close(ScreenPtr pScreen);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment