Merge "libagl: Transform the vertex if using eye space lighting with point lights"
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 3b28b22..ec529f3 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -292,7 +292,7 @@
 }
 
 static void usage() {
-    fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s]\n"
+    fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q]\n"
             "  -o: write to file (instead of stdout)\n"
             "  -d: append date to filename (requires -o)\n"
             "  -z: gzip output (requires -o)\n"
@@ -300,12 +300,14 @@
             "  -s: write output to control socket (for init)\n"
             "  -b: play sound file instead of vibrate, at beginning of job\n"
             "  -e: play sound file instead of vibrate, at end of job\n"
+            "  -q: disable vibrate\n"
 		);
 }
 
 int main(int argc, char *argv[]) {
     int do_add_date = 0;
     int do_compress = 0;
+    int do_vibrate = 1;
     char* use_outfile = 0;
     char* begin_sound = 0;
     char* end_sound = 0;
@@ -328,7 +330,7 @@
     dump_traces_path = dump_traces();
 
     int c;
-    while ((c = getopt(argc, argv, "b:de:ho:svzp")) != -1) {
+    while ((c = getopt(argc, argv, "b:de:ho:svqzp")) != -1) {
         switch (c) {
             case 'b': begin_sound = optarg;  break;
             case 'd': do_add_date = 1;       break;
@@ -336,6 +338,7 @@
             case 'o': use_outfile = optarg;  break;
             case 's': use_socket = 1;        break;
             case 'v': break;  // compatibility no-op
+            case 'q': do_vibrate = 0;        break;
             case 'z': do_compress = 6;       break;
             case 'p': do_fb = 1;             break;
             case '?': printf("\n");
@@ -345,9 +348,12 @@
         }
     }
 
-    /* open the vibrator before dropping root */
-    FILE *vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w");
-    if (vibrator) fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC);
+    FILE *vibrator = 0;
+    if (do_vibrate) {
+        /* open the vibrator before dropping root */
+        vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w");
+        if (vibrator) fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC);
+    }
 
     /* read /proc/cmdline before dropping root */
     FILE *cmdline = fopen("/proc/cmdline", "r");
diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
index 7320e4d..09e7771 100644
--- a/include/gui/ISurfaceComposer.h
+++ b/include/gui/ISurfaceComposer.h
@@ -96,6 +96,10 @@
         eElectronBeamAnimationOff = 0x10
     };
 
+    enum {
+        eDisplayIdMain = 0
+    };
+
     /* create connection with surface flinger, requires
      * ACCESS_SURFACE_FLINGER permission
      */
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index 3bd10de..295bc02 100644
--- a/include/gui/SurfaceComposerClient.h
+++ b/include/gui/SurfaceComposerClient.h
@@ -112,6 +112,14 @@
     static ssize_t getDisplayHeight(DisplayID dpy);
     static ssize_t getDisplayOrientation(DisplayID dpy);
 
+    static inline sp<IBinder> getBuiltInDisplay(int32_t dpy) {
+        return NULL;
+    }
+
+    static inline status_t getDisplayInfo(const sp<IBinder>& dpy, DisplayInfo* info) {
+        return getDisplayInfo(0, info);
+    }
+
     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
             void* cookie = NULL, uint32_t flags = 0);
 
diff --git a/include/utils/Singleton.h b/include/utils/Singleton.h
index a42ce21..c60680e 100644
--- a/include/utils/Singleton.h
+++ b/include/utils/Singleton.h
@@ -65,9 +65,9 @@
  */
 
 #define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE)                 \
-    template class Singleton< TYPE >;                           \
     template<> Mutex Singleton< TYPE >::sLock(Mutex::PRIVATE);  \
-    template<> TYPE* Singleton< TYPE >::sInstance(0);
+    template<> TYPE* Singleton< TYPE >::sInstance(0);           \
+    template class Singleton< TYPE >;
 
 
 // ---------------------------------------------------------------------------
diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp
index 36a81a6..f60f902 100644
--- a/libs/gui/SurfaceTextureClient.cpp
+++ b/libs/gui/SurfaceTextureClient.cpp
@@ -757,12 +757,16 @@
             ALOGW_IF(res, "failed locking buffer (handle = %p)",
                     backBuffer->handle);
 
-            mLockedBuffer = backBuffer;
-            outBuffer->width  = backBuffer->width;
-            outBuffer->height = backBuffer->height;
-            outBuffer->stride = backBuffer->stride;
-            outBuffer->format = backBuffer->format;
-            outBuffer->bits   = vaddr;
+            if (res != 0) {
+                err = INVALID_OPERATION;
+            } else {
+                mLockedBuffer = backBuffer;
+                outBuffer->width  = backBuffer->width;
+                outBuffer->height = backBuffer->height;
+                outBuffer->stride = backBuffer->stride;
+                outBuffer->format = backBuffer->format;
+                outBuffer->bits   = vaddr;
+            }
         }
     }
     return err;
diff --git a/opengl/libs/EGL/egl_cache.cpp b/opengl/libs/EGL/egl_cache.cpp
index c79fb5f..ed2bef3 100644
--- a/opengl/libs/EGL/egl_cache.cpp
+++ b/opengl/libs/EGL/egl_cache.cpp
@@ -241,19 +241,11 @@
         }
 
         size_t fileSize = headerSize + cacheSize;
-        if (ftruncate(fd, fileSize) == -1) {
-            ALOGE("error setting cache file size: %s (%d)", strerror(errno),
-                    errno);
-            close(fd);
-            unlink(fname);
-            return;
-        }
 
-        uint8_t* buf = reinterpret_cast<uint8_t*>(mmap(NULL, fileSize,
-                PROT_WRITE, MAP_SHARED, fd, 0));
-        if (buf == MAP_FAILED) {
-            ALOGE("error mmaping cache file: %s (%d)", strerror(errno),
-                    errno);
+        uint8_t* buf = new uint8_t [fileSize];
+        if (!buf) {
+            ALOGE("error allocating buffer for cache contents: %s (%d)",
+                    strerror(errno), errno);
             close(fd);
             unlink(fname);
             return;
@@ -264,7 +256,7 @@
         if (err != OK) {
             ALOGE("error writing cache contents: %s (%d)", strerror(-err),
                     -err);
-            munmap(buf, fileSize);
+            delete [] buf;
             close(fd);
             unlink(fname);
             return;
@@ -275,7 +267,16 @@
         uint32_t* crc = reinterpret_cast<uint32_t*>(buf + 4);
         *crc = crc32c(buf + headerSize, cacheSize);
 
-        munmap(buf, fileSize);
+        if (write(fd, buf, fileSize) == -1) {
+            ALOGE("error writing cache file: %s (%d)", strerror(errno),
+                    errno);
+            delete [] buf;
+            close(fd);
+            unlink(fname);
+            return;
+        }
+
+        delete [] buf;
         fchmod(fd, S_IRUSR);
         close(fd);
     }