diff options
author | Matt Turner <mattst88@gmail.com> | 2010-08-21 17:32:24 -0400 |
---|---|---|
committer | Owain G. Ainsworth <oga@openbsd.org> | 2010-09-12 03:46:59 +0100 |
commit | 09440b13b9c7e1e1c67614bdaa49a7f6eab95668 (patch) | |
tree | 8bc95eff415f2d0bfca1c81ee4cc5e68d04bab34 | |
parent | ace06899e436e51b5f26e2a7b806187a68d85728 (diff) |
Use ALIGN macro instead of open coding it.
Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
(cherry picked from commit b611bced15c30f7bcd03106ce90668b684c1ada6)
Signed-off-by: Owain G. Ainsworth <oga@openbsd.org>
-rw-r--r-- | src/intel_memory.c | 2 | ||||
-rw-r--r-- | src/intel_video.c | 38 | ||||
-rw-r--r-- | src/legacy/i810/i810_accel.c | 2 | ||||
-rw-r--r-- | src/legacy/i810/i810_common.h | 2 | ||||
-rw-r--r-- | src/legacy/i810/i810_driver.c | 3 | ||||
-rw-r--r-- | src/legacy/i810/i810_video.c | 18 | ||||
-rw-r--r-- | src/xvmc/i915_xvmc.c | 4 |
7 files changed, 33 insertions, 36 deletions
diff --git a/src/intel_memory.c b/src/intel_memory.c index d9d85e28..97b528b9 100644 --- a/src/intel_memory.c +++ b/src/intel_memory.c @@ -879,7 +879,7 @@ static Bool i830_allocate_overlay(ScrnInfoPtr scrn) */ static inline int intel_pad_drawable_width(int width) { - return (width + 63) & ~63; + return ALIGN(width, 64); } /** diff --git a/src/intel_video.c b/src/intel_video.c index 1be2b8ef..76549d90 100644 --- a/src/intel_video.c +++ b/src/intel_video.c @@ -2172,10 +2172,10 @@ intel_clip_video_helper(ScrnInfoPtr scrn, *top = y1 >> 16; *left = (x1 >> 16) & ~1; - *npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - *left; + *npixels = ALIGN(((x2 + 0xffff) >> 16), 2) - *left; if (is_planar_fourcc(id)) { *top &= ~1; - *nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - *top; + *nlines = ALIGN(((y2 + 0xffff) >> 16), 2) - *top; } else *nlines = ((y2 + 0xffff) >> 16) - *top; @@ -2252,32 +2252,32 @@ intel_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sh int id) { intel_screen_private *intel = intel_get_screen_private(scrn); - int pitchAlignMask; + int pitchAlign; /* Only needs to be DWORD-aligned for textured on i915, but overlay has * stricter requirements. */ if (adaptor_priv->textured) { - pitchAlignMask = 3; + pitchAlign = 4; } else { if (IS_I965G(intel)) /* Actually the alignment is 64 bytes, too. But the * stride must be at least 512 bytes. Take the easy fix * and align on 512 bytes unconditionally. */ - pitchAlignMask = 511; + pitchAlign = 512; else if (IS_I830(intel) || IS_845G(intel)) /* Harsh, errata on these chipsets limit the stride to be * a multiple of 256 bytes. */ - pitchAlignMask = 255; + pitchAlign = 256; else - pitchAlignMask = 63; + pitchAlign = 64; } #if INTEL_XVMC /* for i915 xvmc, hw requires 1kb aligned surfaces */ if ((id == FOURCC_XVMC) && IS_I915(intel)) - pitchAlignMask = 0x3ff; + pitchAlign = 1024; #endif /* Determine the desired destination pitch (representing the chroma's pitch, @@ -2285,26 +2285,20 @@ intel_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sh */ if (is_planar_fourcc(id)) { if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - *dstPitch = - ((height / 2) + pitchAlignMask) & ~pitchAlignMask; - *dstPitch2 = - (height + pitchAlignMask) & ~pitchAlignMask; + *dstPitch = ALIGN((height / 2), pitchAlign); + *dstPitch2 = ALIGN(height, pitchAlign); *size = *dstPitch * width * 3; } else { - *dstPitch = - ((width / 2) + pitchAlignMask) & ~pitchAlignMask; - *dstPitch2 = - (width + pitchAlignMask) & ~pitchAlignMask; + *dstPitch = ALIGN((width / 2), pitchAlign); + *dstPitch2 = ALIGN(width, pitchAlign); *size = *dstPitch * height * 3; } } else { if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - *dstPitch = - ((height << 1) + pitchAlignMask) & ~pitchAlignMask; + *dstPitch = ALIGN((height << 1), pitchAlign); *size = *dstPitch * width; } else { - *dstPitch = - ((width << 1) + pitchAlignMask) & ~pitchAlignMask; + *dstPitch = ALIGN((width << 1), pitchAlign); *size = *dstPitch * height; } *dstPitch2 = 0; @@ -2339,8 +2333,8 @@ intel_copy_video_data(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, int size; if (is_planar_fourcc(id)) { - srcPitch = (width + 0x3) & ~0x3; - srcPitch2 = ((width >> 1) + 0x3) & ~0x3; + srcPitch = ALIGN(width, 0x4); + srcPitch2 = ALIGN((width >> 1), 0x4); } else { srcPitch = width << 1; } diff --git a/src/legacy/i810/i810_accel.c b/src/legacy/i810/i810_accel.c index ae4a6544..9aa3e42c 100644 --- a/src/legacy/i810/i810_accel.c +++ b/src/legacy/i810/i810_accel.c @@ -129,7 +129,7 @@ I810AccelInit(ScreenPtr pScreen) */ if (pI810->Scratch.Size != 0) { int i; - int width = ((pScrn->displayWidth + 31) & ~31) / 8; + int width = ALIGN(pScrn->displayWidth, 32) / 8; int nr_buffers = pI810->Scratch.Size / width; unsigned char *ptr = pI810->FbBase + pI810->Scratch.Start; diff --git a/src/legacy/i810/i810_common.h b/src/legacy/i810/i810_common.h index ea28f4ab..a526f736 100644 --- a/src/legacy/i810/i810_common.h +++ b/src/legacy/i810/i810_common.h @@ -50,6 +50,8 @@ #define KB(x) ((x) * 1024) #define MB(x) ((x) * KB(1024)) +#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) + /* Using usleep() makes things noticably slow. */ #if 0 #define DELAY(x) usleep(x) diff --git a/src/legacy/i810/i810_driver.c b/src/legacy/i810/i810_driver.c index 74b2fece..fa998962 100644 --- a/src/legacy/i810/i810_driver.c +++ b/src/legacy/i810/i810_driver.c @@ -1560,8 +1560,7 @@ I810AllocateFront(ScrnInfoPtr pScrn) if (!I810AllocLow(&(pI810->FrontBuffer), &(pI810->SysMem), - ((pI810->FbMemBox.x2 * - pI810->FbMemBox.y2 * pI810->cpp) + 4095) & ~4095)) { + ALIGN((pI810->FbMemBox.x2 * pI810->FbMemBox.y2 * pI810->cpp), 4096))) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Framebuffer allocation failed\n"); return FALSE; diff --git a/src/legacy/i810/i810_video.c b/src/legacy/i810/i810_video.c index 85b5b65c..91af7da5 100644 --- a/src/legacy/i810/i810_video.c +++ b/src/legacy/i810/i810_video.c @@ -750,14 +750,14 @@ I810DisplayVideo( switch(id) { case FOURCC_YV12: case FOURCC_I420: - swidth = (width + 7) & ~7; + swidth = ALIGN(width, 8); overlay->SWID = (swidth << 15) | swidth; overlay->SWIDQW = (swidth << 12) | (swidth >> 3); break; case FOURCC_UYVY: case FOURCC_YUY2: default: - swidth = ((width + 3) & ~3) << 1; + swidth = ALIGN(width, 4) << 1; overlay->SWID = swidth; overlay->SWIDQW = swidth >> 3; break; @@ -1013,15 +1013,15 @@ I810PutImage( switch(id) { case FOURCC_YV12: case FOURCC_I420: - srcPitch = (width + 3) & ~3; - dstPitch = ((width >> 1) + 7) & ~7; /* of chroma */ + srcPitch = ALIGN(width, 4); + dstPitch = ALIGN((width >> 1), 8); /* of chroma */ size = dstPitch * height * 3; break; case FOURCC_UYVY: case FOURCC_YUY2: default: srcPitch = (width << 1); - dstPitch = (srcPitch + 7) & ~7; + dstPitch = ALIGN(srcPitch, 8); size = dstPitch * height; break; } @@ -1062,13 +1062,13 @@ I810PutImage( /* copy data */ top = y1 >> 16; left = (x1 >> 16) & ~1; - npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - left; + npixels = ALIGN(((x2 + 0xffff) >> 16), 2) - left; switch(id) { case FOURCC_YV12: case FOURCC_I420: top &= ~1; - nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top; + nlines = ALIGN(((y2 + 0xffff) >> 16), 2) - top; I810CopyPlanarData(pScrn, buf, srcPitch, dstPitch, height, top, left, nlines, npixels, id); break; @@ -1213,8 +1213,8 @@ I810AllocateSurface( if((w > 1024) || (h > 1024)) return BadAlloc; - w = (w + 1) & ~1; - pitch = ((w << 1) + 15) & ~15; + w = ALIGN(w, 2); + pitch = ALIGN((w << 1), 16); bpp = pScrn->bitsPerPixel >> 3; fbpitch = bpp * pScrn->displayWidth; size = ((pitch * h) + bpp - 1) / bpp; diff --git a/src/xvmc/i915_xvmc.c b/src/xvmc/i915_xvmc.c index 9ad8d01a..21a11491 100644 --- a/src/xvmc/i915_xvmc.c +++ b/src/xvmc/i915_xvmc.c @@ -31,7 +31,9 @@ #include "i915_structs.h" #include "i915_program.h" -#define STRIDE(w) (((w) + 0x3ff) & ~0x3ff) +#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) + +#define STRIDE(w) (ALIGN((w), 1024)) #define SIZE_Y420(w, h) (h * STRIDE(w)) #define SIZE_UV420(w, h) ((h >> 1) * STRIDE(w >> 1)) #define SIZE_YUV420(w, h) (SIZE_Y420(w,h) + SIZE_UV420(w,h) * 2) |