libgralloc-qsd8k: flush SW_WRITE cached pmem regions in unlock

Change-Id: I31d1257f031c6b9b8dae604c2c1a8aa246ce3b84
Signed-off-by: Dima Zavin <dima@android.com>
This commit is contained in:
Dima Zavin 2010-03-02 15:09:54 -08:00
parent a1b401cc89
commit 9df504747b
2 changed files with 20 additions and 0 deletions

View File

@ -71,6 +71,7 @@ struct private_handle_t {
enum {
PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
PRIV_FLAGS_USES_PMEM = 0x00000002,
PRIV_FLAGS_NEEDS_FLUSH = 0x00000004,
};
enum {

View File

@ -235,6 +235,13 @@ int gralloc_lock(gralloc_module_t const* module,
hnd->writeOwner = gettid();
}
// if requesting sw write for non-framebuffer handles, flag for
// flushing at unlock
if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) &&
!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
}
if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
if (!(current_value & private_handle_t::LOCK_STATE_MAPPED)) {
// we need to map for real
@ -264,6 +271,18 @@ int gralloc_unlock(gralloc_module_t const* module,
private_handle_t* hnd = (private_handle_t*)handle;
int32_t current_value, new_value;
if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
struct pmem_region region;
int err;
region.offset = hnd->offset;
region.len = hnd->size;
err = ioctl(hnd->fd, PMEM_CACHE_FLUSH, &region);
LOGE_IF(err < 0, "cannot flush handle %p (offs=%x len=%x)\n",
hnd, hnd->offset, hnd->size);
hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
}
do {
current_value = hnd->lockState;
new_value = current_value;