diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2013-03-27 14:34:49 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2013-03-27 14:34:49 -0700 |
commit | 86acaa7718a7dd3575fc21fa6a11231c7b80cfc5 (patch) | |
tree | d212d7622521ca131fea88fba9fcde6e08d7c20d | |
parent | c5821dc32d4fa097e155156a6b070ecc3a7de062 (diff) | |
parent | aeab91f9777e8e0b7ac85c7569514ce7fb80af66 (diff) | |
download | display-86acaa7718a7dd3575fc21fa6a11231c7b80cfc5.tar.gz |
Merge "display: Use cache invalidate and clean correctly"
-rw-r--r-- | libcopybit/copybit_c2d.cpp | 10 | ||||
-rw-r--r-- | libgralloc/ionalloc.cpp | 18 | ||||
-rw-r--r-- | libgralloc/ionalloc.h | 2 | ||||
-rw-r--r-- | libgralloc/mapper.cpp | 35 | ||||
-rw-r--r-- | libgralloc/memalloc.h | 8 |
5 files changed, 50 insertions, 23 deletions
diff --git a/libcopybit/copybit_c2d.cpp b/libcopybit/copybit_c2d.cpp index efbd350d..5c58dd36 100644 --- a/libcopybit/copybit_c2d.cpp +++ b/libcopybit/copybit_c2d.cpp @@ -1259,10 +1259,11 @@ static int stretch_copybit_internal( return status; } - // Flush the cache + // Clean the cache IMemAlloc* memalloc = sAlloc->getAllocator(src_hnd->flags); if (memalloc->clean_buffer((void *)(src_hnd->base), src_hnd->size, - src_hnd->offset, src_hnd->fd)) { + src_hnd->offset, src_hnd->fd, + gralloc::CACHE_CLEAN)) { ALOGE("%s: clean_buffer failed", __FUNCTION__); delete_handle(dst_hnd); delete_handle(src_hnd); @@ -1343,10 +1344,11 @@ static int stretch_copybit_internal( unmap_gpuaddr(ctx, mapped_src_idx); return status; } - // Invalidate the cache. + // Clean the cache. IMemAlloc* memalloc = sAlloc->getAllocator(dst_hnd->flags); memalloc->clean_buffer((void *)(dst_hnd->base), dst_hnd->size, - dst_hnd->offset, dst_hnd->fd); + dst_hnd->offset, dst_hnd->fd, + gralloc::CACHE_CLEAN); } delete_handle(dst_hnd); delete_handle(src_hnd); diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp index 8480f98b..83e62e74 100644 --- a/libgralloc/ionalloc.cpp +++ b/libgralloc/ionalloc.cpp @@ -145,7 +145,8 @@ int IonAlloc::alloc_buffer(alloc_data& data) } memset(base, 0, ionAllocData.len); // Clean cache after memset - clean_buffer(base, data.size, data.offset, fd_data.fd); + clean_buffer(base, data.size, data.offset, fd_data.fd, + CACHE_CLEAN_AND_INVALIDATE); } data.base = base; @@ -209,7 +210,7 @@ int IonAlloc::unmap_buffer(void *base, size_t size, int offset) return err; } -int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd) +int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd, int op) { struct ion_flush_data flush_data; struct ion_fd_data fd_data; @@ -237,7 +238,18 @@ int IonAlloc::clean_buffer(void *base, size_t size, int offset, int fd) #ifdef NEW_ION_API struct ion_custom_data d; - d.cmd = ION_IOC_CLEAN_INV_CACHES; + switch(op) { + case CACHE_CLEAN: + d.cmd = ION_IOC_CLEAN_CACHES; + break; + case CACHE_INVALIDATE: + d.cmd = ION_IOC_INV_CACHES; + break; + case CACHE_CLEAN_AND_INVALIDATE: + default: + d.cmd = ION_IOC_CLEAN_INV_CACHES; + } + d.arg = (unsigned long int)&flush_data; if(ioctl(mIonFd, ION_IOC_CUSTOM, &d)) { diff --git a/libgralloc/ionalloc.h b/libgralloc/ionalloc.h index 7a11a341..174f44b0 100644 --- a/libgralloc/ionalloc.h +++ b/libgralloc/ionalloc.h @@ -51,7 +51,7 @@ class IonAlloc : public IMemAlloc { int offset); virtual int clean_buffer(void*base, size_t size, - int offset, int fd); + int offset, int fd, int op); IonAlloc() { mIonFd = FD_INIT; } diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp index 9c97aae9..5a32975c 100644 --- a/libgralloc/mapper.cpp +++ b/libgralloc/mapper.cpp @@ -222,12 +222,19 @@ int gralloc_lock(gralloc_module_t const* module, pthread_mutex_unlock(lock); } *vaddr = (void*)hnd->base; - + //Invalidate if reading in software. No need to do this for the metadata + //buffer as it is only read/written in software. + IMemAlloc* memalloc = getAllocator(hnd->flags) ; + err = memalloc->clean_buffer((void*)hnd->base, + hnd->size, hnd->offset, hnd->fd, + CACHE_INVALIDATE); if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) && !(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { // Mark the buffer to be flushed after cpu read/write hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; } + } else { + hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH; } return err; } @@ -237,26 +244,26 @@ int gralloc_unlock(gralloc_module_t const* module, { if (private_handle_t::validate(handle) < 0) return -EINVAL; - + int err = 0; private_handle_t* hnd = (private_handle_t*)handle; + IMemAlloc* memalloc = getAllocator(hnd->flags); if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) { - int err; - IMemAlloc* memalloc = getAllocator(hnd->flags) ; err = memalloc->clean_buffer((void*)hnd->base, - hnd->size, hnd->offset, hnd->fd); - ALOGE_IF(err < 0, "cannot flush handle %p (offs=%x len=%x, flags = 0x%x) err=%s\n", - hnd, hnd->offset, hnd->size, hnd->flags, strerror(errno)); - unsigned long size = ROUND_UP_PAGESIZE(sizeof(MetaData_t)); - err = memalloc->clean_buffer((void*)hnd->base_metadata, size, - hnd->offset_metadata, hnd->fd_metadata); - ALOGE_IF(err < 0, "cannot flush handle %p (offs=%x len=%lu, " - "flags = 0x%x) err=%s\n", hnd, hnd->offset_metadata, size, - hnd->flags, strerror(errno)); + hnd->size, hnd->offset, hnd->fd, + CACHE_CLEAN_AND_INVALIDATE); hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; + } else if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) { + hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH; + } else { + //Probably a round about way to do this, but this avoids adding new + //flags + err = memalloc->clean_buffer((void*)hnd->base, + hnd->size, hnd->offset, hnd->fd, + CACHE_INVALIDATE); } - return 0; + return err; } /*****************************************************************************/ diff --git a/libgralloc/memalloc.h b/libgralloc/memalloc.h index 73ac6522..664bfa29 100644 --- a/libgralloc/memalloc.h +++ b/libgralloc/memalloc.h @@ -34,6 +34,12 @@ namespace gralloc { +enum { + CACHE_CLEAN = 0x1, + CACHE_INVALIDATE, + CACHE_CLEAN_AND_INVALIDATE, +}; + struct alloc_data { void *base; int fd; @@ -68,7 +74,7 @@ class IMemAlloc { // Clean and invalidate virtual int clean_buffer(void *base, size_t size, - int offset, int fd) = 0; + int offset, int fd, int op) = 0; // Destructor virtual ~IMemAlloc() {}; |