summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaurabh Shah <saurshah@codeaurora.org>2014-12-19 10:05:41 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2014-12-19 18:30:00 -0800
commit1adcafe634716519f83141894a50d7faf4d2ef2b (patch)
treed4040a60dfb3a6921fa09df718cff6625af9eaf7
parent69574c0ce85635860c1529f397bff20c13fb77cb (diff)
downloaddisplay-1adcafe634716519f83141894a50d7faf4d2ef2b.tar.gz
gralloc: Allocate cached by default, don't use bitops on SW flags
Allocate gralloc buffers cached by default unless clients specify uncached using PRIVATE_UNCACHED or READ_RARELY or WRITE_RARELY at allocation time. Some clients could use gralloc for allocation but later won't use lock()/unlock() for CPU operations and likely use their own caching methods. Cached by default helps such clients. SW usage flags are not defined as bit values, so do not use bitops on those flags. Change-Id: Id371de2ec6efbfa0ed84172b3540f3ebc8f5d459
-rw-r--r--libcopybit/copybit.cpp3
-rw-r--r--libgralloc/alloc_controller.cpp26
-rw-r--r--libgralloc/gpu.cpp19
-rw-r--r--libgralloc/gr.h4
-rw-r--r--libgralloc/gralloc_priv.h6
-rw-r--r--libgralloc/mapper.cpp22
6 files changed, 34 insertions, 46 deletions
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index da18c7bf..e4624e0b 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -505,7 +505,8 @@ static int stretch_copybit(
int flags = 0;
private_handle_t* src_hnd = (private_handle_t*)src->handle;
- if(src_hnd != NULL && src_hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
+ if(src_hnd != NULL &&
+ (!(src_hnd->flags & private_handle_t::PRIV_FLAGS_CACHED))) {
flags |= MDP_BLIT_NON_CACHED;
}
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index cd6d5658..fd81c708 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -76,6 +76,21 @@ static bool canFallback(int usage, bool triedSystem)
return true;
}
+/* The default policy is to return cached buffers unless the client explicity
+ * sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely
+ * read or written in software. Any combination with a _RARELY_ flag will be
+ * treated as uncached. */
+static bool useUncached(const int& usage) {
+ if((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) or
+ ((usage & GRALLOC_USAGE_SW_WRITE_MASK) ==
+ GRALLOC_USAGE_SW_WRITE_RARELY) or
+ ((usage & GRALLOC_USAGE_SW_READ_MASK) ==
+ GRALLOC_USAGE_SW_READ_RARELY))
+ return true;
+
+ return false;
+}
+
//-------------- AdrenoMemInfo-----------------------//
AdrenoMemInfo::AdrenoMemInfo()
{
@@ -664,14 +679,3 @@ void free_buffer(private_handle_t *hnd)
delete hnd;
}
-
-bool useUncached(const int& usage) {
- if(usage & GRALLOC_USAGE_PRIVATE_UNCACHED)
- return true;
-
- if(not (usage & (GRALLOC_USAGE_SW_WRITE_OFTEN |
- GRALLOC_USAGE_SW_READ_OFTEN)))
- return true;
-
- return false;
-}
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 551f188e..5533ffb0 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -141,14 +141,6 @@ int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
}
- if (usage & GRALLOC_USAGE_HW_RENDER) {
- flags |= private_handle_t::PRIV_FLAGS_HW_RENDER;
- }
-
- if (usage & GRALLOC_USAGE_HW_FB) {
- flags |= private_handle_t::PRIV_FLAGS_HW_FB;
- }
-
if(usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
}
@@ -161,6 +153,17 @@ int gpu_context_t::gralloc_alloc_buffer(unsigned int size, int usage,
flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
}
+ if (usage & (GRALLOC_USAGE_HW_VIDEO_ENCODER |
+ GRALLOC_USAGE_HW_CAMERA_WRITE |
+ GRALLOC_USAGE_HW_RENDER |
+ GRALLOC_USAGE_HW_FB)) {
+ flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
+ }
+
+ if(false == data.uncached) {
+ flags |= private_handle_t::PRIV_FLAGS_CACHED;
+ }
+
flags |= data.allocType;
uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index 37ee4e52..797d57ee 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -71,10 +71,6 @@ int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
void free_buffer(private_handle_t *hnd);
int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr);
-// Use uncached for all scenarios except when the CPU needs to read or write
-// often
-bool useUncached(const int& usage);
-
/*****************************************************************************/
class Locker {
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 9e2a6cfd..d866ef4c 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -180,11 +180,9 @@ struct private_handle_t : public native_handle {
PRIV_FLAGS_USES_ION = 0x00000008,
PRIV_FLAGS_USES_ASHMEM = 0x00000010,
PRIV_FLAGS_NEEDS_FLUSH = 0x00000020,
- // Uncached memory or no CPU writers
- PRIV_FLAGS_DO_NOT_FLUSH = 0x00000040,
- PRIV_FLAGS_HW_RENDER = 0x00000080,
+ PRIV_FLAGS_NON_CPU_WRITER = 0x00000080,
PRIV_FLAGS_NONCONTIGUOUS_MEM = 0x00000100,
- PRIV_FLAGS_HW_FB = 0x00000200,
+ PRIV_FLAGS_CACHED = 0x00000200,
PRIV_FLAGS_SECURE_BUFFER = 0x00000400,
// For explicit synchronization
PRIV_FLAGS_UNSYNCHRONIZED = 0x00000800,
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 3053d473..bc98e07c 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -237,36 +237,25 @@ static int gralloc_map_and_invalidate (gralloc_module_t const* module,
pthread_mutex_unlock(lock);
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
- not useUncached(usage)) {
- bool nonCPUWriters = hnd->flags & (
- private_handle_t::PRIV_FLAGS_HW_RENDER |
- private_handle_t::PRIV_FLAGS_HW_FB |
- private_handle_t::PRIV_FLAGS_VIDEO_ENCODER |
- private_handle_t::PRIV_FLAGS_CAMERA_WRITE);
-
+ hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) {
//Invalidate if CPU reads in software and there are non-CPU
//writers. No need to do this for the metadata buffer as it is
//only read/written in software.
- //Corner case: If we reach here with a READ_RARELY, then there must
- //be a WRITE_OFTEN that caused caching to be used.
- if ((usage & GRALLOC_USAGE_SW_READ_MASK) and nonCPUWriters) {
+ if ((usage & GRALLOC_USAGE_SW_READ_MASK) and
+ (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER))
+ {
IMemAlloc* memalloc = getAllocator(hnd->flags) ;
err = memalloc->clean_buffer((void*)hnd->base,
hnd->size, hnd->offset, hnd->fd,
CACHE_INVALIDATE);
}
//Mark the buffer to be flushed after CPU write.
- //Corner case: If we reach here with a WRITE_RARELY, then there
- //must be a READ_OFTEN that caused caching to be used.
if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
}
}
}
- if(useUncached(usage))
- hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
-
return err;
}
@@ -314,9 +303,6 @@ int gralloc_unlock(gralloc_module_t const* module,
hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
}
- if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH)
- hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
-
return err;
}