From patchwork Sat Aug 21 21:32:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 122021 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7LLVPG0028411 for ; Sat, 21 Aug 2010 21:32:01 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 089AA9EAF1 for ; Sat, 21 Aug 2010 14:31:25 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-gw0-f49.google.com (mail-gw0-f49.google.com [74.125.83.49]) by gabe.freedesktop.org (Postfix) with ESMTP id D18509E7C3 for ; Sat, 21 Aug 2010 14:31:13 -0700 (PDT) Received: by gwb10 with SMTP id 10so1999701gwb.36 for ; Sat, 21 Aug 2010 14:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:to:cc:subject :date:message-id:x-mailer; bh=K/093UknAt6ekDHj4n/+Riu2UrnJLO2JV6YlqeRKlQo=; b=jEKcyH5iZger/63Jw1SUTC/DMHl3KBsGK/KJcmRcLtBs1dRJK4qJG8fkqkdP1p820s KvNw5qmN9p2oxNcZPiWQcGIxgs+Uu0SnYygDjJfScu7BU5RpulmrPz3Fu1AzBisBteFN VFK23rAHH5lL6paDM8/2w1wqIqZ12d5gIeK+Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=Jb6mciaQMPhixeLd0niPF8ojhmI8Mu1dIOQ9BZZLi4LJCT9BNizSvUu+GJZTcMOpf9 aNR4vh9cE3mFkM7gOfURAp5sOkwTQpqPkSP6A1okSXFFYYBugGzV3l4iOL4kC1jY8GAB vfAONYMSZtJBUNUoAaPMPj7MPKazuZ9iaMuBs= Received: by 10.150.203.1 with SMTP id a1mr3249100ybg.422.1282426273396; Sat, 21 Aug 2010 14:31:13 -0700 (PDT) Received: from mattst88@gmail.com (cpe-173-095-152-044.nc.res.rr.com [173.95.152.44]) by mx.google.com with ESMTPS id q31sm5439821ybk.13.2010.08.21.14.31.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 21 Aug 2010 14:31:12 -0700 (PDT) Received: by mattst88@gmail.com (sSMTP sendmail emulation); Sat, 21 Aug 2010 17:32:31 -0400 From: mattst88@gmail.com To: intel-gfx@lists.freedesktop.org Date: Sat, 21 Aug 2010 17:32:24 -0400 Message-Id: <1282426345-15853-1-git-send-email-mattst88@gmail.com> X-Mailer: git-send-email 1.7.1 Subject: [Intel-gfx] [PATCH 1/2] Use ALIGN macro instead of open coding it. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 21 Aug 2010 21:32:01 +0000 (UTC) diff --git a/src/intel_memory.c b/src/intel_memory.c index 47444eb..b42e6d7 100644 --- a/src/intel_memory.c +++ b/src/intel_memory.c @@ -167,7 +167,7 @@ intel_check_display_stride(ScrnInfoPtr scrn, int stride, Bool tiling) */ 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 e0a5c53..cde596c 100644 --- a/src/intel_video.c +++ b/src/intel_video.c @@ -1277,10 +1277,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; @@ -1385,32 +1385,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, @@ -1418,26 +1418,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; @@ -1472,8 +1466,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 ae4a654..9aa3e42 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 ea28f4a..a526f73 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 3fc9d04..3637e25 100644 --- a/src/legacy/i810/i810_driver.c +++ b/src/legacy/i810/i810_driver.c @@ -1545,8 +1545,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 7e3db8c..68dc471 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; size = ((pitch * h) + bpp - 1) / bpp; diff --git a/src/xvmc/i915_xvmc.c b/src/xvmc/i915_xvmc.c index 9ad8d01..21a1149 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)