Merge "Partial revert of "Fix Surface slot caching"" into nyc-dev
diff --git a/cmds/flatland/Main.cpp b/cmds/flatland/Main.cpp
index 866203f..c47b0c8 100644
--- a/cmds/flatland/Main.cpp
+++ b/cmds/flatland/Main.cpp
@@ -206,8 +206,8 @@
 
 static const ShaderDesc shaders[] = {
     {
-        name: "Blit",
-        vertexShader: {
+        .name="Blit",
+        .vertexShader={
             "precision mediump float;",
             "",
             "attribute vec4 position;",
@@ -223,7 +223,7 @@
             "    texCoords = uvToTex * uv;",
             "}",
         },
-        fragmentShader: {
+        .fragmentShader={
             "#extension GL_OES_EGL_image_external : require",
             "precision mediump float;",
             "",
@@ -240,8 +240,8 @@
     },
 
     {
-        name: "Gradient",
-        vertexShader: {
+        .name="Gradient",
+        .vertexShader={
             "precision mediump float;",
             "",
             "attribute vec4 position;",
@@ -257,7 +257,7 @@
             "    interp = (uvToInterp * uv).x;",
             "}",
         },
-        fragmentShader: {
+        .fragmentShader={
             "precision mediump float;",
             "",
             "varying float interp;",
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 5956e13..44fd59e 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -126,6 +126,8 @@
 
     status_t            writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val);
     status_t            writeByteVector(const std::vector<int8_t>& val);
+    status_t            writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val);
+    status_t            writeByteVector(const std::vector<uint8_t>& val);
     status_t            writeInt32Vector(const std::unique_ptr<std::vector<int32_t>>& val);
     status_t            writeInt32Vector(const std::vector<int32_t>& val);
     status_t            writeInt64Vector(const std::unique_ptr<std::vector<int64_t>>& val);
@@ -271,6 +273,8 @@
 
     status_t            readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const;
     status_t            readByteVector(std::vector<int8_t>* val) const;
+    status_t            readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const;
+    status_t            readByteVector(std::vector<uint8_t>* val) const;
     status_t            readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const;
     status_t            readInt32Vector(std::vector<int32_t>* val) const;
     status_t            readInt64Vector(std::unique_ptr<std::vector<int64_t>>* val) const;
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 1008f02..678d98b 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -808,16 +808,10 @@
   return writeUtf8AsUtf16(*str);
 }
 
-status_t Parcel::writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val)
-{
-    if (!val) {
-        return writeInt32(-1);
-    }
+namespace {
 
-    return writeByteVector(*val);
-}
-
-status_t Parcel::writeByteVector(const std::vector<int8_t>& val)
+template<typename T>
+status_t writeByteVectorInternal(Parcel* parcel, const std::vector<T>& val)
 {
     status_t status;
     if (val.size() > std::numeric_limits<int32_t>::max()) {
@@ -825,12 +819,12 @@
         return status;
     }
 
-    status = writeInt32(val.size());
+    status = parcel->writeInt32(val.size());
     if (status != OK) {
         return status;
     }
 
-    void* data = writeInplace(val.size());
+    void* data = parcel->writeInplace(val.size());
     if (!data) {
         status = BAD_VALUE;
         return status;
@@ -840,6 +834,37 @@
     return status;
 }
 
+template<typename T>
+status_t writeByteVectorInternalPtr(Parcel* parcel,
+                                    const std::unique_ptr<std::vector<T>>& val)
+{
+    if (!val) {
+        return parcel->writeInt32(-1);
+    }
+
+    return writeByteVectorInternal(parcel, *val);
+}
+
+}  // namespace
+
+status_t Parcel::writeByteVector(const std::vector<int8_t>& val) {
+    return writeByteVectorInternal(this, val);
+}
+
+status_t Parcel::writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val)
+{
+    return writeByteVectorInternalPtr(this, val);
+}
+
+status_t Parcel::writeByteVector(const std::vector<uint8_t>& val) {
+    return writeByteVectorInternal(this, val);
+}
+
+status_t Parcel::writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val)
+{
+    return writeByteVectorInternalPtr(this, val);
+}
+
 status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val)
 {
     return writeTypedVector(val, &Parcel::writeInt32);
@@ -1406,11 +1431,15 @@
     return err;
 }
 
-status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
+namespace {
+
+template<typename T>
+status_t readByteVectorInternal(const Parcel* parcel,
+                                std::vector<T>* val) {
     val->clear();
 
     int32_t size;
-    status_t status = readInt32(&size);
+    status_t status = parcel->readInt32(&size);
 
     if (status != OK) {
         return status;
@@ -1420,12 +1449,12 @@
         status = UNEXPECTED_NULL;
         return status;
     }
-    if (size_t(size) > dataAvail()) {
+    if (size_t(size) > parcel->dataAvail()) {
         status = BAD_VALUE;
         return status;
     }
 
-    const void* data = readInplace(size);
+    const void* data = parcel->readInplace(size);
     if (!data) {
         status = BAD_VALUE;
         return status;
@@ -1436,20 +1465,23 @@
     return status;
 }
 
-status_t Parcel::readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const {
-    const int32_t start = dataPosition();
+template<typename T>
+status_t readByteVectorInternalPtr(
+        const Parcel* parcel,
+        std::unique_ptr<std::vector<T>>* val) {
+    const int32_t start = parcel->dataPosition();
     int32_t size;
-    status_t status = readInt32(&size);
+    status_t status = parcel->readInt32(&size);
     val->reset();
 
     if (status != OK || size < 0) {
         return status;
     }
 
-    setDataPosition(start);
-    val->reset(new std::vector<int8_t>());
+    parcel->setDataPosition(start);
+    val->reset(new std::vector<T>());
 
-    status = readByteVector(val->get());
+    status = readByteVectorInternal(parcel, val->get());
 
     if (status != OK) {
         val->reset();
@@ -1458,6 +1490,24 @@
     return status;
 }
 
+}  // namespace
+
+status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
+    return readByteVectorInternal(this, val);
+}
+
+status_t Parcel::readByteVector(std::vector<uint8_t>* val) const {
+    return readByteVectorInternal(this, val);
+}
+
+status_t Parcel::readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const {
+    return readByteVectorInternalPtr(this, val);
+}
+
+status_t Parcel::readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const {
+    return readByteVectorInternalPtr(this, val);
+}
+
 status_t Parcel::readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const {
     return readNullableTypedVector(val, &Parcel::readInt32);
 }
diff --git a/vulkan/patches/README b/vulkan/patches/README
deleted file mode 100644
index d424dd8..0000000
--- a/vulkan/patches/README
+++ /dev/null
@@ -1,26 +0,0 @@
-frameworks/native/vulkan/patches
-================================
-Each subdirectory corresponds to a sequence of patches. These are
-"virtual branches": we only have one shared branch, so these let us
-share experimental or auxiliary changes without disturbing the main
-branch.
-
-To apply:
-$ cd <somewhere in target git repo>
-$ git am $VULKAN_PATCHES/$PATCH_DIR/*
-
-
-frameworks_base-apk_library_dir
--------------------------------
-This branch is for $TOP/frameworks/base. It modifies the framework to
-inform the Vulkan loader, during activity startup, where the
-activity's native library directory. The loader will search this
-directory for layer libraries. Without this change, layers will only
-be loaded from a global location under /data.
-
-
-build-install_libvulkan
------------------------
-This branch is for $TOP/build. It adds libvulkan.so to the base
-PRODUCT_PACKAGES variable, so it will be built and installed on the system
-partition by default.
diff --git a/vulkan/patches/build-install_libvulkan/0001-Add-libvulkan-to-base-PRODUCT_PACKAGES.patch b/vulkan/patches/build-install_libvulkan/0001-Add-libvulkan-to-base-PRODUCT_PACKAGES.patch
deleted file mode 100644
index 9d214bd..0000000
--- a/vulkan/patches/build-install_libvulkan/0001-Add-libvulkan-to-base-PRODUCT_PACKAGES.patch
+++ /dev/null
@@ -1,25 +0,0 @@
-From a0aa01fb36a2769b7113316c86e902def62001d9 Mon Sep 17 00:00:00 2001
-From: Jesse Hall <jessehall@google.com>
-Date: Wed, 14 Oct 2015 15:20:34 -0700
-Subject: [PATCH] Add libvulkan to base PRODUCT_PACKAGES
-
-Change-Id: I6c3ad4732148888a88fe980bf8e2bedf26ee74c8
----
- target/product/base.mk | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/target/product/base.mk b/target/product/base.mk
-index 1699156..4b9ce92 100644
---- a/target/product/base.mk
-+++ b/target/product/base.mk
-@@ -94,6 +94,7 @@ PRODUCT_PACKAGES += \
-     libvisualizer \
-     libvorbisidec \
-     libmediandk \
-+    libvulkan \
-     libwifi-service \
-     media \
-     media_cmd \
--- 
-2.6.0.rc2.230.g3dd15c0
-
diff --git a/vulkan/patches/frameworks_base-apk_library_dir/0001-Adding-plumbing-for-passing-the-lib-directory.patch b/vulkan/patches/frameworks_base-apk_library_dir/0001-Adding-plumbing-for-passing-the-lib-directory.patch
deleted file mode 100644
index 81022d6..0000000
--- a/vulkan/patches/frameworks_base-apk_library_dir/0001-Adding-plumbing-for-passing-the-lib-directory.patch
+++ /dev/null
@@ -1,133 +0,0 @@
-From 5c7e465f1d11bccecdc5cacce87d1fd7deeb5adb Mon Sep 17 00:00:00 2001
-From: Michael Lentine <mlentine@google.com>
-Date: Mon, 14 Sep 2015 13:28:25 -0500
-Subject: [PATCH] Adding plumbing for passing the lib directory.
-
-Added call in handleBindApplication which will pass the library path into
-HardwareRender which then passes it to libvulkan through ThreadedRenderer's
-jni interface.
-
-Change-Id: Ie5709ac46f47c4af5c020d604a479e78745d7777
----
- core/java/android/app/ActivityThread.java    |  7 +++++--
- core/java/android/view/HardwareRenderer.java | 11 +++++++++++
- core/java/android/view/ThreadedRenderer.java |  1 +
- core/jni/Android.mk                          |  2 ++
- core/jni/android_view_ThreadedRenderer.cpp   | 15 +++++++++++++++
- 5 files changed, 34 insertions(+), 2 deletions(-)
-
-diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
-index da21eaf..76608c6 100644
---- a/core/java/android/app/ActivityThread.java
-+++ b/core/java/android/app/ActivityThread.java
-@@ -4520,8 +4520,11 @@ public final class ActivityThread {
-             } else {
-                 Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory");
-             }
--        }
--
-+        } 
-+        
-+        // Add the lib dir path to hardware renderer so that vulkan layers
-+        // can be searched for within that directory.
-+        HardwareRenderer.setLibDir(data.info.getLibDir());
- 
-         final boolean is24Hr = "24".equals(mCoreSettings.getString(Settings.System.TIME_12_24));
-         DateFormat.set24HourTimePref(is24Hr);
-diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
-index 5e58250..ed99115 100644
---- a/core/java/android/view/HardwareRenderer.java
-+++ b/core/java/android/view/HardwareRenderer.java
-@@ -301,6 +301,17 @@ public abstract class HardwareRenderer {
-     }
- 
-     /**
-+     * Sets the library directory to use as a search path for vulkan layers.
-+     *
-+     * @param libDir A directory that contains vulkan layers
-+     *
-+     * @hide
-+     */
-+    public static void setLibDir(String libDir) {
-+        ThreadedRenderer.setupVulkanLayerPath(libDir);
-+    }
-+
-+    /**
-      * Indicates that the specified hardware layer needs to be updated
-      * as soon as possible.
-      *
-diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
-index f6119e2..d3e5175 100644
---- a/core/java/android/view/ThreadedRenderer.java
-+++ b/core/java/android/view/ThreadedRenderer.java
-@@ -492,6 +492,7 @@ public class ThreadedRenderer extends HardwareRenderer {
-     }
- 
-     static native void setupShadersDiskCache(String cacheFile);
-+    static native void setupVulkanLayerPath(String layerPath);
- 
-     private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map);
-     private static native void nSetProcessStatsBuffer(long nativeProxy, int fd);
-diff --git a/core/jni/Android.mk b/core/jni/Android.mk
-index 6b07a47..438e95b 100644
---- a/core/jni/Android.mk
-+++ b/core/jni/Android.mk
-@@ -177,6 +177,7 @@ LOCAL_C_INCLUDES += \
-     $(LOCAL_PATH)/android/graphics \
-     $(LOCAL_PATH)/../../libs/hwui \
-     $(LOCAL_PATH)/../../../native/opengl/libs \
-+    $(LOCAL_PATH)/../../../native/vulkan/include \
-     $(call include-path-for, bluedroid) \
-     $(call include-path-for, libhardware)/hardware \
-     $(call include-path-for, libhardware_legacy)/hardware_legacy \
-@@ -225,6 +226,7 @@ LOCAL_SHARED_LIBRARIES := \
-     libEGL \
-     libGLESv1_CM \
-     libGLESv2 \
-+    libvulkan \
-     libETC1 \
-     libhardware \
-     libhardware_legacy \
-diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp
-index 47132f4..69e8ca6 100644
---- a/core/jni/android_view_ThreadedRenderer.cpp
-+++ b/core/jni/android_view_ThreadedRenderer.cpp
-@@ -27,6 +27,7 @@
- #include <EGL/egl.h>
- #include <EGL/eglext.h>
- #include <EGL/egl_cache.h>
-+#include <vulkan/vulkan_loader_data.h>
- 
- #include <utils/StrongPointer.h>
- #include <android_runtime/android_view_Surface.h>
-@@ -448,6 +449,18 @@ static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, job
- }
- 
- // ----------------------------------------------------------------------------
-+// Layers
-+// ----------------------------------------------------------------------------
-+
-+static void android_view_ThreadedRenderer_setupVulkanLayerPath(JNIEnv* env, jobject clazz,
-+        jstring layerPath) {
-+
-+    const char* layerArray = env->GetStringUTFChars(layerPath, NULL);
-+    vulkan::LoaderData::GetInstance().layer_path = layerArray;
-+    env->ReleaseStringUTFChars(layerPath, layerArray);
-+}
-+
-+// ----------------------------------------------------------------------------
- // JNI Glue
- // ----------------------------------------------------------------------------
- 
-@@ -487,6 +500,8 @@ static JNINativeMethod gMethods[] = {
-     { "nDumpProfileData", "([BLjava/io/FileDescriptor;)V", (void*) android_view_ThreadedRenderer_dumpProfileData },
-     { "setupShadersDiskCache", "(Ljava/lang/String;)V",
-                 (void*) android_view_ThreadedRenderer_setupShadersDiskCache },
-+    { "setupVulkanLayerPath", "(Ljava/lang/String;)V",
-+                (void*) android_view_ThreadedRenderer_setupVulkanLayerPath },
- };
- 
- int register_android_view_ThreadedRenderer(JNIEnv* env) {
--- 
-2.6.0.rc2.230.g3dd15c0
-