Commit 1cd5f084 authored by Siarhei Siamashka's avatar Siarhei Siamashka
Browse files

G2D: Now sunxi_x_g2d.c code does not require sunxi disp anymore



The sunxi_x_g2d.c file contains the midlayer code for hooking the
G2D optimized blit into xserver. But in fact it does not strictly
need to depend on anything sunxi specific.

So now we introduce a simple "blt2d_i" interface struct which
specifically provides a pointer to the accelerated blit function.
And just use this interface struct instead of the whole "sunxi_disp_t".
This allows to easily reuse the same code for other non-G2D or even
non-sunxi blit implementations in the future.
Signed-off-by: default avatarSiarhei Siamashka <siarhei.siamashka@gmail.com>
parent 66f3e5cc
......@@ -33,6 +33,7 @@ sunxifb_drv_la_SOURCES = \
uthash.h \
cpuinfo.c \
cpuinfo.h \
interfaces.h \
fbdev.c \
fbdev_priv.h \
sunxi_disp.c \
......
......@@ -867,13 +867,17 @@ FBDevScreenInit(SCREEN_INIT_ARGS_DECL)
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");
sunxi_disp_t *disp = fPtr->sunxi_disp_private;
if (disp && disp->fd_g2d >= 0 &&
(fPtr->SunxiG2D_private = SunxiG2D_Init(pScreen, &disp->blt2d))) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "enabled G2D acceleration\n");
}
else {
xf86DrvMsg(pScreen->myNum, X_INFO,
"No sunxi-g2d hardware detected (check /dev/disp and /dev/g2d)\n");
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"G2D hardware acceleration can't be enabled\n");
"G2D hardware acceleration can't be enabled\n");
}
}
else {
......
/*
* 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 INTERFACES_H
#define INTERFACES_H
/* A simple interface for 2D graphics operations */
typedef struct {
void *self; /* The pointer which needs to be passed to functions */
/*
* A counterpart for "pixman_blt", which supports overlapped copies.
* Except for the new "self" pointer, the rest of arguments are
* exactly the same.
*/
int (*overlapped_blt)(void *self,
uint32_t *src_bits,
uint32_t *dst_bits,
int src_stride,
int dst_stride,
int src_bpp,
int dst_bpp,
int src_x,
int src_y,
int dst_x,
int dst_y,
int w,
int h);
} blt2d_i;
#endif
......@@ -141,6 +141,9 @@ sunxi_disp_t *sunxi_disp_init(const char *device, void *xserver_fbmem)
ctx->fd_g2d = open("/dev/g2d", O_RDWR);
ctx->blt2d.self = ctx;
ctx->blt2d.overlapped_blt = sunxi_g2d_blt;
return ctx;
}
......@@ -467,7 +470,7 @@ int sunxi_g2d_blit_a8r8g8b8(sunxi_disp_t *disp,
* Can do G2D accelerated blits only if both source and destination
* buffers are inside framebuffer. Returns FALSE (0) otherwise.
*/
int sunxi_g2d_blt(sunxi_disp_t *disp,
int sunxi_g2d_blt(void *self,
uint32_t *src_bits,
uint32_t *dst_bits,
int src_stride,
......@@ -481,6 +484,7 @@ int sunxi_g2d_blt(sunxi_disp_t *disp,
int w,
int h)
{
sunxi_disp_t *disp = (sunxi_disp_t *)self;
g2d_blt tmp;
/*
* Very minimal validation here. We just assume that if the begginging
......@@ -500,6 +504,10 @@ int sunxi_g2d_blt(sunxi_disp_t *disp,
if (w <= 0 || h <= 0)
return 1;
/* Unsupported overlapping type */
if (src_bits == dst_bits && src_y == dst_y && src_x + 1 < dst_x)
return 0;
if (disp->fd_g2d < 0)
return 0;
......
......@@ -26,6 +26,8 @@
#include <inttypes.h>
#include "interfaces.h"
/*
* Support for Allwinner A10 display controller features such as layers
* and hardware cursor
......@@ -52,6 +54,9 @@ typedef struct {
/* Layers support */
int layer_id;
int layer_has_scaler;
/* G2D accelerated implementation of blt2d_i interface */
blt2d_i blt2d;
} sunxi_disp_t;
sunxi_disp_t *sunxi_disp_init(const char *fb_device, void *xserver_fbmem);
......@@ -114,7 +119,7 @@ int sunxi_g2d_blit_a8r8g8b8(sunxi_disp_t *disp,
int h);
/* G2D counterpart for pixman_blt with the support for 16bpp and 32bpp */
int sunxi_g2d_blt(sunxi_disp_t *disp,
int sunxi_g2d_blt(void *disp,
uint32_t *src_bits,
uint32_t *dst_bits,
int src_stride,
......
......@@ -36,7 +36,6 @@
#include "fb.h"
#include "fbdev_priv.h"
#include "sunxi_disp.h"
#include "sunxi_x_g2d.h"
/*
......@@ -63,28 +62,20 @@ xCopyWindowProc(DrawablePtr pSrcDrawable,
int dstXoff, dstYoff;
ScreenPtr pScreen = pDstDrawable->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
sunxi_disp_t *disp = SUNXI_DISP(pScrn);
SunxiG2D *private = SUNXI_G2D(pScrn);
fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
if (srcBpp == dstBpp && (srcBpp == 32 || srcBpp == 16) &&
disp->framebuffer_addr == (void *)src &&
disp->framebuffer_addr == (void *)dst &&
(dy + srcYoff != dstYoff || dx + srcXoff + 1 >= dstXoff))
{
while (nbox--) {
sunxi_g2d_blt(disp, (uint32_t *)src, (uint32_t *)dst,
srcStride, dstStride,
srcBpp, dstBpp, (pbox->x1 + dx + srcXoff),
(pbox->y1 + dy + srcYoff), (pbox->x1 + dstXoff),
(pbox->y1 + dstYoff), (pbox->x2 - pbox->x1),
(pbox->y2 - pbox->y1));
pbox++;
}
}
else {
while (nbox--) {
while (nbox--) {
if (!private->blt2d_overlapped_blt(private->blt2d_self,
(uint32_t *)src, (uint32_t *)dst,
srcStride, dstStride,
srcBpp, dstBpp, (pbox->x1 + dx + srcXoff),
(pbox->y1 + dy + srcYoff), (pbox->x1 + dstXoff),
(pbox->y1 + dstYoff), (pbox->x2 - pbox->x1),
(pbox->y2 - pbox->y1))) {
/* fallback to fbBlt */
fbBlt(src + (pbox->y1 + dy + srcYoff) * srcStride,
srcStride,
(pbox->x1 + dx + srcXoff) * srcBpp,
......@@ -93,9 +84,9 @@ xCopyWindowProc(DrawablePtr pSrcDrawable,
(pbox->x1 + dstXoff) * dstBpp,
(pbox->x2 - pbox->x1) * dstBpp,
(pbox->y2 - pbox->y1),
GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
pbox++;
GXcopy, FB_ALLONES, dstBpp, reverse, upsidedown);
}
pbox++;
}
fbFinishAccess(pDstDrawable);
......@@ -155,27 +146,21 @@ xCopyNtoN(DrawablePtr pSrcDrawable,
int dstXoff, dstYoff;
ScreenPtr pScreen = pDstDrawable->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
sunxi_disp_t *disp = SUNXI_DISP(pScrn);
Bool bad_overlapping_for_g2d;
SunxiG2D *private = SUNXI_G2D(pScrn);
fbGetDrawable(pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
fbGetDrawable(pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
bad_overlapping_for_g2d = (src == dst) && (dy + srcYoff == dstYoff) &&
(dx + srcXoff + 1 < dstXoff);
while (nbox--) {
Bool done = FALSE;
/* first try G2D */
if (!bad_overlapping_for_g2d) {
done = sunxi_g2d_blt(disp, (uint32_t *)src, (uint32_t *)dst,
srcStride, dstStride,
srcBpp, dstBpp, (pbox->x1 + dx + srcXoff),
(pbox->y1 + dy + srcYoff), (pbox->x1 + dstXoff),
(pbox->y1 + dstYoff), (pbox->x2 - pbox->x1),
(pbox->y2 - pbox->y1));
}
Bool done = private->blt2d_overlapped_blt(
private->blt2d_self,
(uint32_t *)src, (uint32_t *)dst,
srcStride, dstStride,
srcBpp, dstBpp, (pbox->x1 + dx + srcXoff),
(pbox->y1 + dy + srcYoff), (pbox->x1 + dstXoff),
(pbox->y1 + dstYoff), (pbox->x2 - pbox->x1),
(pbox->y2 - pbox->y1));
/* then pixman (NEON) */
if (!done && !reverse && !upsidedown) {
......@@ -251,25 +236,19 @@ xCreateGC(GCPtr pGC)
/*****************************************************************************/
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen)
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen, blt2d_i *blt2d)
{
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));
SunxiG2D *private = calloc(1, sizeof(SunxiG2D));
if (!private) {
xf86DrvMsg(pScreen->myNum, X_INFO,
"SunxiG2D_Init: calloc failed\n");
return NULL;
}
/* Cache the pointers from blt2d_i here */
private->blt2d_self = blt2d->self;
private->blt2d_overlapped_blt = blt2d->overlapped_blt;
/* Wrap the current CopyWindow function */
private->CopyWindow = pScreen->CopyWindow;
pScreen->CopyWindow = xCopyWindow;
......
......@@ -24,14 +24,32 @@
#ifndef SUNXI_X_G2D_H
#define SUNXI_X_G2D_H
#include "interfaces.h"
typedef struct {
GCOps *pGCOps;
CopyWindowProcPtr CopyWindow;
CreateGCProcPtr CreateGC;
/* SunxiG2D_Init copies these pointers here from blt2d_i struct */
void *blt2d_self;
int (*blt2d_overlapped_blt)(void *self,
uint32_t *src_bits,
uint32_t *dst_bits,
int src_stride,
int dst_stride,
int src_bpp,
int dst_bpp,
int src_x,
int src_y,
int dst_x,
int dst_y,
int w,
int h);
} SunxiG2D;
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen);
SunxiG2D *SunxiG2D_Init(ScreenPtr pScreen, blt2d_i *blt2d);
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