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
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index cd6d565..fd81c70 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -76,6 +76,21 @@
     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 @@
         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;
-}