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/mapper.cpp b/libgralloc/mapper.cpp
index 3053d47..bc98e07 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -237,36 +237,25 @@
             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 @@
         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;
 }