From 32a41ee5dc559f6e97e4c1e0c4c39dd39fcef2e6 Mon Sep 17 00:00:00 2001 From: Naomi Luis Date: Tue, 8 Feb 2011 11:29:43 -0800 Subject: [PATCH] libgralloc-qsd8k: Set the framebuffer offsets correctly The offsets for the framebuffer needs to start at a 4K aligned address. Calculate the additional delta for the yoffset, the virtual address for flipping as well as the total framebuffer size required to achieve this Change-Id: Idfd70be10a24ac464ec820494b66d506a03a983b CRs-fixed: 273888 --- framebuffer.cpp | 34 +++++++++++++++++++++++++--------- gpu.cpp | 3 ++- gralloc_priv.h | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/framebuffer.cpp b/framebuffer.cpp index 4a4b403..ab57a8d 100644 --- a/framebuffer.cpp +++ b/framebuffer.cpp @@ -694,26 +694,42 @@ int mapFrameBufferLocked(struct private_module_t* module) info.transp.length = 0; module->fbFormat = HAL_PIXEL_FORMAT_RGB_565; } + + // Calculate the FbSize to map. + int y = -1; + do { + y++; + } while (((finfo.line_length * (info.yres + y)) % 4096) != 0); + module->yres_delta = y; + /* * Request NUM_BUFFERS screens (at lest 2 for page flipping) */ - int numberOfBuffers = (int)(finfo.smem_len/(info.yres * info.xres * (info.bits_per_pixel/8))); + + // Calculate the number of buffers required + int numberOfBuffers = 0; + int requiredSize = info.xres * (info.bits_per_pixel/8) * + (info.yres + module->yres_delta); + for (int num = NUM_FRAMEBUFFERS_MAX; num > 0; num--) { + int totalSizeRequired = num * requiredSize; + if (finfo.smem_len >= totalSizeRequired) { + numberOfBuffers = num; + break; + } + } LOGV("num supported framebuffers in kernel = %d", numberOfBuffers); if (property_get("debug.gr.numframebuffers", property, NULL) > 0) { - int num = atoi(property); - if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) { - numberOfBuffers = num; + int reqNum = atoi(property); + if ((reqNum <= numberOfBuffers) && (reqNum >= NUM_FRAMEBUFFERS_MIN) + && (reqNum <= NUM_FRAMEBUFFERS_MAX)) { + numberOfBuffers = reqNum; } } - if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX) - numberOfBuffers = NUM_FRAMEBUFFERS_MAX; - + info.yres_virtual = numberOfBuffers*(info.yres + module->yres_delta); LOGD("We support %d buffers", numberOfBuffers); - info.yres_virtual = info.yres * numberOfBuffers; - uint32_t flags = PAGE_FLIP; if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) { info.yres_virtual = info.yres; diff --git a/gpu.cpp b/gpu.cpp index dd73a91..d7774bf 100644 --- a/gpu.cpp +++ b/gpu.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 The Android Open Source Project + * Copyright (c) 2011, Code Aurora Forum. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,7 +90,7 @@ int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage, m->bufferMask |= (1LU<finfo.line_length * (m->info.yres + m->yres_delta)); } hnd->base = vaddr; diff --git a/gralloc_priv.h b/gralloc_priv.h index 8ff2582..5b04c8e 100644 --- a/gralloc_priv.h +++ b/gralloc_priv.h @@ -212,6 +212,7 @@ struct private_module_t { struct avail_t avail[NUM_FRAMEBUFFERS_MAX]; pthread_mutex_t qlock; pthread_cond_t qpost; + uint32_t yres_delta; enum { // flag to indicate we'll post this buffer