[PATCH r128 1/5] Unify allocators
Connor Behan
connor.behan at gmail.com
Tue Jul 22 02:49:47 PDT 2014
RandR and Xv were using almost the same code to grab offscreen memory
from EXA and XAA.
Signed-off-by: Connor Behan <connor.behan at gmail.com>
---
src/r128.h | 1 +
src/r128_crtc.c | 72 ++++----------------------------------
src/r128_probe.h | 7 +---
src/r128_video.c | 103 ++++++++++++++++++++++++++++---------------------------
4 files changed, 62 insertions(+), 121 deletions(-)
diff --git a/src/r128.h b/src/r128.h
index f361c2a..6df1b51 100644
--- a/src/r128.h
+++ b/src/r128.h
@@ -570,6 +570,7 @@ extern void r128_crtc_show_cursor(xf86CrtcPtr crtc);
extern void r128_crtc_hide_cursor(xf86CrtcPtr crtc);
extern void r128_crtc_load_cursor_image(xf86CrtcPtr crtc, unsigned char *src);
+extern uint32_t R128AllocateMemory(ScrnInfoPtr pScrn, void **mem_struct, int size, int align, Bool need_accel);
extern Bool R128SetupConnectors(ScrnInfoPtr pScrn);
extern Bool R128AllocateControllers(ScrnInfoPtr pScrn, int mask);
extern void R128Blank(ScrnInfoPtr pScrn);
diff --git a/src/r128_crtc.c b/src/r128_crtc.c
index 5f076cd..92a6c30 100644
--- a/src/r128_crtc.c
+++ b/src/r128_crtc.c
@@ -233,33 +233,9 @@ static void r128_crtc_unlock(xf86CrtcPtr crtc)
#endif
}
-#ifdef HAVE_XAA_H
-static FBLinearPtr r128_xf86AllocateOffscreenLinear(ScreenPtr pScreen, int length, int granularity,
- MoveLinearCallbackProcPtr moveCB,
- RemoveLinearCallbackProcPtr removeCB,
- pointer privData)
-{
- FBLinearPtr linear;
- int max_size;
-
- linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB, removeCB, privData);
- if (linear != NULL) return linear;
-
- /* The above allocation did not succeed, so purge unlocked stuff and try again. */
- xf86QueryLargestOffscreenLinear(pScreen, &max_size, granularity, PRIORITY_EXTREME);
-
- if (max_size < length) return NULL;
- xf86PurgeUnlockedOffscreenAreas(pScreen);
-
- linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB, removeCB, privData);
- return linear;
-}
-#endif
-
static void *r128_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
{
ScrnInfoPtr pScrn = crtc->scrn;
- ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
R128InfoPtr info = R128PTR(pScrn);
R128CrtcPrivatePtr r128_crtc = crtc->driver_private;
@@ -271,38 +247,7 @@ static void *r128_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
rotate_pitch = pScrn->displayWidth * cpp;
size = rotate_pitch * height;
-
-#ifdef USE_EXA
- if (info->ExaDriver) {
- assert(r128_crtc->rotate_mem_exa == NULL);
- r128_crtc->rotate_mem_exa = exaOffscreenAlloc(pScreen, size, align, TRUE, NULL, NULL);
-
- if (r128_crtc->rotate_mem_exa == NULL) {
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "Couldn't allocate shadow memory for rotated CRTC\n");
- return NULL;
- }
-
- rotate_offset = r128_crtc->rotate_mem_exa->offset;
- }
-#endif
-#ifdef HAVE_XAA_H
- if (info->accel) {
- size = (size + cpp - 1) / cpp;
- align = (align + cpp - 1) / cpp;
-
- assert(r128_crtc->rotate_mem_xaa == NULL);
- r128_crtc->rotate_mem_xaa = r128_xf86AllocateOffscreenLinear(pScreen, size, align, NULL, NULL, NULL);
-
- if (r128_crtc->rotate_mem_exa == NULL) {
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "Couldn't allocate shadow memory for rotated CRTC\n");
- return NULL;
- }
-
- rotate_offset = r128_crtc->rotate_mem_xaa->offset * cpp;
- }
-#endif
+ rotate_offset = R128AllocateMemory(pScrn, &(r128_crtc->rotate_mem), size, align, TRUE);
/* If allocations failed or if there was no accel. */
if (rotate_offset == 0)
@@ -347,19 +292,16 @@ static void r128_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap,
if (rotate_pixmap) FreeScratchPixmapHeader(rotate_pixmap);
- if (data) {
+ if (data && r128_crtc->rotate_mem != NULL) {
#ifdef USE_EXA
- if (info->ExaDriver && r128_crtc->rotate_mem_exa != NULL) {
- exaOffscreenFree(pScreen, r128_crtc->rotate_mem_exa);
- r128_crtc->rotate_mem_exa = NULL;
- }
+ if (info->ExaDriver)
+ exaOffscreenFree(pScreen, (ExaOffscreenArea *) r128_crtc->rotate_mem);
#endif
#ifdef HAVE_XAA_H
- if (info->accel) {
- xf86FreeOffscreenLinear(r128_crtc->rotate_mem_xaa);
- r128_crtc->rotate_mem_xaa = NULL;
- }
+ if (info->accel)
+ xf86FreeOffscreenLinear((FBLinearPtr) r128_crtc->rotate_mem);
#endif
+ r128_crtc->rotate_mem = NULL;
}
}
diff --git a/src/r128_probe.h b/src/r128_probe.h
index 40fe82b..433463b 100644
--- a/src/r128_probe.h
+++ b/src/r128_probe.h
@@ -137,12 +137,7 @@ typedef struct {
} R128I2CBusRec, *R128I2CBusPtr;
typedef struct _R128CrtcPrivateRec {
-#ifdef HAVE_XAA_H
- FBLinearPtr rotate_mem_xaa;
-#endif
-#ifdef USE_EXA
- ExaOffscreenArea *rotate_mem_exa;
-#endif
+ void *rotate_mem;
int crtc_id;
uint32_t cursor_offset;
/* Lookup table values to be set when the CRTC is enabled */
diff --git a/src/r128_video.c b/src/r128_video.c
index bcf36fc..b0059b5 100644
--- a/src/r128_video.c
+++ b/src/r128_video.c
@@ -572,76 +572,78 @@ R128CopyData420(
}
-static uint32_t
+uint32_t
R128AllocateMemory(
ScrnInfoPtr pScrn,
void **mem_struct,
- int size
+ int size,
+ int align,
+ Bool need_accel
){
R128InfoPtr info = R128PTR(pScrn);
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
- int offset = 0;
+ Bool do_linear = !need_accel;
+ uint32_t offset = 0;
- if(!info->useEXA) {
+#ifdef HAVE_XAA_H
+ if (!info->accel && need_accel)
+ do_linear = FALSE;
+ else
+ do_linear = TRUE;
+#endif
+#ifdef USE_EXA
+ if (info->ExaDriver) {
+ ExaOffscreenArea *area = *mem_struct;
+
+ if (area != NULL) {
+ if (area->size >= size) return area->offset;
+
+ exaOffscreenFree(pScreen, area);
+ }
+
+ area = exaOffscreenAlloc(pScreen, size, align, TRUE, NULL, NULL);
+ *mem_struct = area;
+
+ if (area == NULL) return 0;
+ offset = area->offset;
+ }
+#endif
+ if (!info->useEXA && do_linear) {
FBLinearPtr linear = *mem_struct;
int cpp = info->CurrentLayout.pixel_bytes;
- /* XAA allocates in units of pixels at the screen bpp, so adjust size appropriately. */
- size = (size + cpp - 1) / cpp;
+ /* XAA allocates in units of pixels at the screen bpp, so adjust size appropriately. */
+ size = (size + cpp - 1) / cpp;
+ align = (align + cpp - 1) / cpp;
if(linear) {
- if(linear->size >= size)
- return linear->offset * cpp;
+ if(linear->size >= size)
+ return linear->offset * cpp;
- if(xf86ResizeOffscreenLinear(linear, size))
- return linear->offset * cpp;
+ if(xf86ResizeOffscreenLinear(linear, size))
+ return linear->offset * cpp;
- xf86FreeOffscreenLinear(linear);
+ xf86FreeOffscreenLinear(linear);
}
-
- linear = xf86AllocateOffscreenLinear(pScreen, size, 8,
- NULL, NULL, NULL);
+ linear = xf86AllocateOffscreenLinear(pScreen, size, align, NULL, NULL, NULL);
*mem_struct = linear;
if(!linear) {
- int max_size;
-
- xf86QueryLargestOffscreenLinear(pScreen, &max_size, 8,
- PRIORITY_EXTREME);
+ int max_size;
- if(max_size < size)
- return 0;
+ xf86QueryLargestOffscreenLinear(pScreen, &max_size, align, PRIORITY_EXTREME);
+ if(max_size < size) return 0;
- xf86PurgeUnlockedOffscreenAreas(pScreen);
- linear = xf86AllocateOffscreenLinear(pScreen, size, 8,
- NULL, NULL, NULL);
+ xf86PurgeUnlockedOffscreenAreas(pScreen);
+ linear = xf86AllocateOffscreenLinear(pScreen, size, align, NULL, NULL, NULL);
- if(!linear) return 0;
+ *mem_struct = linear;
+ if(!linear) return 0;
}
- offset = linear->offset * cpp;
+ offset = linear->offset * cpp;
}
-#ifdef USE_EXA
- else {
- /* EXA support based on mga driver */
- ExaOffscreenArea *area = *mem_struct;
-
- if(area) {
- if(area->size >= size)
- return area->offset;
-
- exaOffscreenFree(pScrn->pScreen, area);
- }
-
- area = exaOffscreenAlloc(pScrn->pScreen, size, 64, TRUE, NULL, NULL);
- *mem_struct = area;
-
- if(!area) return 0;
-
- offset = area->offset;
- }
-#endif
return offset;
}
@@ -929,11 +931,12 @@ R128PutImage(
break;
}
- if(!(pPriv->videoOffset = R128AllocateMemory(pScrn, &(pPriv->BufferHandle),
- pPriv->doubleBuffer ? (new_size << 1) : new_size)))
- {
- return BadAlloc;
- }
+ pPriv->videoOffset = R128AllocateMemory(pScrn, &(pPriv->BufferHandle),
+ pPriv->doubleBuffer ? (new_size << 1) : new_size,
+ 64, FALSE);
+
+ if (pPriv->videoOffset == 0)
+ return BadAlloc;
pPriv->currentBuffer ^= 1;
--
2.0.0
More information about the xorg-driver-ati
mailing list