From patchwork Fri Mar 12 05:30:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 85200 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2C5UtA5003496 for ; Fri, 12 Mar 2010 05:31:32 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1946C9E8AB; Thu, 11 Mar 2010 21:30:54 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qy0-f189.google.com (mail-qy0-f189.google.com [209.85.221.189]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F7D29E75A for ; Thu, 11 Mar 2010 21:30:51 -0800 (PST) Received: by qyk27 with SMTP id 27so977653qyk.3 for ; Thu, 11 Mar 2010 21:30:50 -0800 (PST) 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=awlT8NSJ/tzNH7eNe6Y8OzigUXoHP+TN/uKobRWjmuw=; b=XRJEyNDm9FZ/w2rrzdGS8PZKyUhe74iEqnO/umQreEdjvicaWu2UenWAWAOW4EQ0l2 xqPLMBwbRM3IrClMJxZETVusOouUr+PTSGMN0OHQh52HhlF7gwRHXpQTxx4AVps1TKN+ RW1jafeU47uZoDwwzvHDqRUgwJ0x5cFGyXnYs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=nmjgd4UkgVWu4toKSk3GFLSk61ZPMX+I3CwRIiDnVeWusIalhoNCBiJheuEMBoQl0L 9bmapiPnCPyirwaXpAnEaVjueaGXT3IACKWGXLbpl2E+vJzx7U5jzHvBfsG3vmjkkgMT 6sKjIJYW1gEOMUG9xerKhp7qwxqi5lt5vHWCY= Received: by 10.220.127.72 with SMTP id f8mr740208vcs.109.1268371850678; Thu, 11 Mar 2010 21:30:50 -0800 (PST) Received: from mattst88@gmail.com ([204.84.232.251]) by mx.google.com with ESMTPS id 23sm263670ywh.45.2010.03.11.21.30.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 11 Mar 2010 21:30:49 -0800 (PST) Received: by mattst88@gmail.com (sSMTP sendmail emulation); Fri, 12 Mar 2010 00:30:48 -0500 From: Matt Turner To: intel-gfx@lists.freedesktop.org Date: Fri, 12 Mar 2010 00:30:23 -0500 Message-Id: <1268371823-6377-1-git-send-email-mattst88@gmail.com> X-Mailer: git-send-email 1.6.4.4 Subject: [Intel-gfx] [PATCH] 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@lists.freedesktop.org Errors-To: intel-gfx-bounces@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]); Fri, 12 Mar 2010 05:31:32 +0000 (UTC) diff --git a/src/common.h b/src/common.h index bc5d722..05041a3 100644 --- a/src/common.h +++ b/src/common.h @@ -395,10 +395,6 @@ extern int I810_DEBUG; #define SUPPORTS_YTILING(pI810) (IS_I965G(intel)) #define GTT_PAGE_SIZE KB(4) -#define ROUND_TO(x, y) (((x) + (y) - 1) / (y) * (y)) -#define ROUND_DOWN_TO(x, y) ((x) / (y) * (y)) -#define ROUND_TO_PAGE(x) ROUND_TO((x), GTT_PAGE_SIZE) -#define ROUND_TO_MB(x) ROUND_TO((x), MB(1)) #define PRIMARY_RINGBUFFER_SIZE KB(128) #define MIN_SCRATCH_BUFFER_SIZE KB(16) #define MAX_SCRATCH_BUFFER_SIZE KB(64) diff --git a/src/drmmode_display.c b/src/drmmode_display.c index 22c967a..a8b5df2 100644 --- a/src/drmmode_display.c +++ b/src/drmmode_display.c @@ -476,7 +476,7 @@ drmmode_crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) int size, ret; unsigned long rotate_pitch; - width = i830_pad_drawable_width(width, drmmode->cpp); + width = ALIGN(width, 64); rotate_pitch = width * drmmode->cpp; size = rotate_pitch * height; @@ -523,8 +523,7 @@ drmmode_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) } } - rotate_pitch = - i830_pad_drawable_width(width, drmmode->cpp) * drmmode->cpp; + rotate_pitch = ALIGN(width, 64) * drmmode->cpp; rotate_pixmap = GetScratchPixmapHeader(scrn->pScreen, width, height, scrn->depth, @@ -1261,7 +1260,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height) if (scrn->virtualX == width && scrn->virtualY == height) return TRUE; - pitch = i830_pad_drawable_width(width, intel->cpp); + pitch = ALIGN(width, 64); xf86DrvMsg(scrn->scrnIndex, X_INFO, "Allocate new frame buffer %dx%d stride %d\n", width, height, pitch); diff --git a/src/i810_accel.c b/src/i810_accel.c index ae4a654..9aa3e42 100644 --- a/src/i810_accel.c +++ b/src/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/i810_dri.c b/src/i810_dri.c index e566acf..cd73867 100644 --- a/src/i810_dri.c +++ b/src/i810_dri.c @@ -348,9 +348,8 @@ I810DRIScreenInit(ScreenPtr pScreen) pDRIInfo->ddxDriverMinorVersion = I810_MINOR_VERSION; pDRIInfo->ddxDriverPatchVersion = I810_PATCHLEVEL; pDRIInfo->frameBufferPhysicalAddress = (pointer) pI810->LinearAddr; - pDRIInfo->frameBufferSize = (((pScrn->displayWidth * - pScrn->virtualY * pI810->cpp) + - 4096 - 1) / 4096) * 4096; + pDRIInfo->frameBufferSize = ALIGN(pScrn->displayWidth * pScrn->virtualY * + pI810->cpp, 4096); pDRIInfo->frameBufferStride = pScrn->displayWidth * pI810->cpp; pDRIInfo->ddxDrawableTableEntry = I810_MAX_DRAWABLES; @@ -537,7 +536,7 @@ I810DRIScreenInit(ScreenPtr pScreen) * - airlied */ int lines = (pScrn->virtualY + 15) / 16 * 16; back_size = i810_pitches[pitch_idx] * lines; - back_size = ((back_size + 4096 - 1) / 4096) * 4096; + back_size = ALIGN(back_size, 4096); } sysmem_size = pScrn->videoRam * 1024; diff --git a/src/i810_driver.c b/src/i810_driver.c index 3109834..34a4413 100644 --- a/src/i810_driver.c +++ b/src/i810_driver.c @@ -1838,8 +1838,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/i810_video.c b/src/i810_video.c index 9bb9870..5f82392 100644 --- a/src/i810_video.c +++ b/src/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/i830.h b/src/i830.h index 7593cde..5c76c0a 100644 --- a/src/i830.h +++ b/src/i830.h @@ -429,8 +429,6 @@ void i830_init_bufmgr(ScrnInfoPtr scrn); Bool i830_tiled_width(intel_screen_private *intel, int *width, int cpp); -int i830_pad_drawable_width(int width, int cpp); - /* i830_memory.c */ unsigned long i830_get_fence_size(intel_screen_private *intel, unsigned long size); unsigned long i830_get_fence_pitch(intel_screen_private *intel, unsigned long pitch, diff --git a/src/i830_driver.c b/src/i830_driver.c index 53d8663..d9f2d2b 100644 --- a/src/i830_driver.c +++ b/src/i830_driver.c @@ -172,7 +172,7 @@ typedef enum { OPTION_DEBUG_FLUSH_BATCHES, OPTION_DEBUG_FLUSH_CACHES, OPTION_DEBUG_WAIT, -} I830Opts; +}I830Opts; static OptionInfoRec I830Options[] = { {OPTION_DRI, "DRI", OPTV_BOOLEAN, {0}, TRUE}, @@ -389,14 +389,6 @@ Bool i830_tiled_width(intel_screen_private *intel, int *width, int cpp) } /* - * Pad to accelerator requirement - */ -int i830_pad_drawable_width(int width, int cpp) -{ - return (width + 63) & ~63; -} - -/* * DRM mode setting Linux only at this point... later on we could * add a wrapper here. */ @@ -1100,8 +1092,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv) struct pci_device *const device = intel->PciInfo; int fb_bar = IS_I9XX(intel) ? 2 : 0; - scrn->displayWidth = - i830_pad_drawable_width(scrn->virtualX, intel->cpp); + scrn->displayWidth = ALIGN(scrn->virtualX, intel->cpp); /* * The "VideoRam" config file parameter specifies the maximum amount of diff --git a/src/i830_memory.c b/src/i830_memory.c index a21f29b..ba47714 100644 --- a/src/i830_memory.c +++ b/src/i830_memory.c @@ -129,7 +129,7 @@ i830_get_fence_pitch(intel_screen_private *intel, unsigned long pitch, /* 965 is flexible */ if (IS_I965G(intel)) - return ROUND_TO(pitch, tile_width); + return ALIGN(pitch, tile_width); /* Pre-965 needs power of two tile width */ for (i = tile_width; i < pitch; i <<= 1) ; @@ -232,7 +232,7 @@ drm_intel_bo *i830_allocate_framebuffer(ScrnInfoPtr scrn) */ fb_height = scrn->virtualY; - size = ROUND_TO_PAGE(pitch * fb_height); + size = ALIGN(pitch * fb_height, GTT_PAGE_SIZE); if (intel->tiling && IsTileable(scrn, pitch)) tiling_mode = I915_TILING_X; diff --git a/src/i830_uxa.c b/src/i830_uxa.c index 9904311..8fc9cc9 100644 --- a/src/i830_uxa.c +++ b/src/i830_uxa.c @@ -133,7 +133,7 @@ i830_uxa_pixmap_compute_size(PixmapPtr pixmap, if (*tiling != I915_TILING_NONE) { /* First check whether tiling is necessary. */ pitch_align = intel->accel_pixmap_pitch_alignment; - size = ROUND_TO((w * pixmap->drawable.bitsPerPixel + 7) / 8, + size = ALIGN((w * pixmap->drawable.bitsPerPixel + 7) / 8, pitch_align) * ALIGN (h, 2); if (size < 4096) *tiling = I915_TILING_NONE; @@ -146,7 +146,7 @@ i830_uxa_pixmap_compute_size(PixmapPtr pixmap, pitch_align = 512; } - *stride = ROUND_TO((w * pixmap->drawable.bitsPerPixel + 7) / 8, + *stride = ALIGN((w * pixmap->drawable.bitsPerPixel + 7) / 8, pitch_align); if (*tiling == I915_TILING_NONE) { diff --git a/src/i830_video.c b/src/i830_video.c index db72863..0c76908 100644 --- a/src/i830_video.c +++ b/src/i830_video.c @@ -1271,10 +1271,10 @@ i830_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; @@ -1351,24 +1351,24 @@ i830_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sho 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)) - pitchAlignMask = 255; + pitchAlign = 256; else - pitchAlignMask = 255; + pitchAlign = 256; } #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, @@ -1377,25 +1377,25 @@ i830_setup_dst_params(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, sho if (is_planar_fourcc(id)) { if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { *dstPitch = - ((height / 2) + pitchAlignMask) & ~pitchAlignMask; + ALIGN(height / 2, pitchAlign); *dstPitch2 = - (height + pitchAlignMask) & ~pitchAlignMask; + ALIGN(height, pitchAlign); *size = *dstPitch * width * 3; } else { *dstPitch = - ((width / 2) + pitchAlignMask) & ~pitchAlignMask; + ALIGN(width / 2, pitchAlign); *dstPitch2 = - (width + pitchAlignMask) & ~pitchAlignMask; + ALIGN(width, pitchAlign); *size = *dstPitch * height * 3; } } else { if (adaptor_priv->rotation & (RR_Rotate_90 | RR_Rotate_270)) { *dstPitch = - ((height << 1) + pitchAlignMask) & ~pitchAlignMask; + ALIGN(height << 1, pitchAlign); *size = *dstPitch * width; } else { *dstPitch = - ((width << 1) + pitchAlignMask) & ~pitchAlignMask; + ALIGN(width << 1, pitchAlign); *size = *dstPitch * height; } *dstPitch2 = 0; @@ -1426,16 +1426,9 @@ i830_copy_video_data(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, int top, int left, int npixels, int nlines, int id, unsigned char *buf) { - int srcPitch = 0, srcPitch2 = 0; + int srcPitch, srcPitch2; int size; - if (is_planar_fourcc(id)) { - srcPitch = (width + 0x3) & ~0x3; - srcPitch2 = ((width >> 1) + 0x3) & ~0x3; - } else { - srcPitch = width << 1; - } - i830_setup_dst_params(scrn, adaptor_priv, width, height, dstPitch, dstPitch2, &size, id); @@ -1444,11 +1437,14 @@ i830_copy_video_data(ScrnInfoPtr scrn, intel_adaptor_private *adaptor_priv, /* copy data */ if (is_planar_fourcc(id)) { + srcPitch = ALIGN(width, 0x4); + srcPitch2 = ALIGN(width >> 1, 0x4); I830CopyPlanarData(adaptor_priv, buf, srcPitch, srcPitch2, *dstPitch, *dstPitch2, height, top, left, nlines, npixels, id); } else { + srcPitch = width << 1; I830CopyPackedData(adaptor_priv, buf, srcPitch, *dstPitch, top, left, nlines, npixels); }