Merge "reduce PB size from 2MB to 512KB" into jb-dev
diff --git a/build/tablet-7in-hdpi-1024-dalvik-heap.mk b/build/tablet-7in-hdpi-1024-dalvik-heap.mk
new file mode 100644
index 0000000..63aede6
--- /dev/null
+++ b/build/tablet-7in-hdpi-1024-dalvik-heap.mk
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Provides overrides to configure the Dalvik heap for a standard tablet device.
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    dalvik.vm.heapstartsize=8m \
+    dalvik.vm.heapgrowthlimit=64m \
+    dalvik.vm.heapsize=384m
+    
\ No newline at end of file
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index d602500..18685f7 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -16,4 +16,6 @@
 LOCAL_CFLAGS += -DBOARD_HAS_DUMPSTATE
 endif
 
+LOCAL_CFLAGS += -Wall -Wno-unused-parameter -std=gnu99
+
 include $(BUILD_EXECUTABLE)
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 165f11c..3b28b22 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -324,8 +324,8 @@
         fclose(oom_adj);
     }
 
-    /* very first thing, collect VM traces from Dalvik (needs root) */
-    dump_traces_path = dump_vm_traces();
+    /* very first thing, collect stack traces from Dalvik and native processes (needs root) */
+    dump_traces_path = dump_traces();
 
     int c;
     while ((c = getopt(argc, argv, "b:de:ho:svzp")) != -1) {
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index c1c2ad8..45247cd 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -38,8 +38,8 @@
 /* redirect output to a file, optionally gzipping; returns gzip pid */
 pid_t redirect_to_file(FILE *redirect, char *path, int gzip_level);
 
-/* dump Dalvik stack traces, return the trace file location (NULL if none) */
-const char *dump_vm_traces();
+/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
+const char *dump_traces();
 
 /* for each process in the system, run the specified function */
 void for_each_pid(void (*func)(int, const char *), const char *header);
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 4556505..da00846 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -32,12 +32,21 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <cutils/debugger.h>
 #include <cutils/properties.h>
 #include <cutils/sockets.h>
 #include <private/android_filesystem_config.h>
 
 #include "dumpstate.h"
 
+/* list of native processes to include in the native dumps */
+static const char* native_processes_to_dump[] = {
+        "/system/bin/mediaserver",
+        "/system/bin/sdcard",
+        "/system/bin/surfaceflinger",
+        NULL,
+};
+
 void for_each_pid(void (*func)(int, const char *), const char *header) {
     DIR *d;
     struct dirent *de;
@@ -352,8 +361,19 @@
     return gzip_pid;
 }
 
-/* dump Dalvik stack traces, return the trace file location (NULL if none) */
-const char *dump_vm_traces() {
+static bool should_dump_native_traces(const char* path) {
+    for (const char** p = native_processes_to_dump; *p; p++) {
+        if (!strcmp(*p, path)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+/* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
+const char *dump_traces() {
+    const char* result = NULL;
+
     char traces_path[PROPERTY_VALUE_MAX] = "";
     property_get("dalvik.vm.stack-trace-file", traces_path, "");
     if (!traces_path[0]) return NULL;
@@ -394,26 +414,25 @@
         close(fd);
         return NULL;
     }
-    close(fd);
 
     /* walk /proc and kill -QUIT all Dalvik processes */
     DIR *proc = opendir("/proc");
     if (proc == NULL) {
         fprintf(stderr, "/proc: %s\n", strerror(errno));
-        return NULL;
+        goto error_close_fd;
     }
 
     /* use inotify to find when processes are done dumping */
     int ifd = inotify_init();
     if (ifd < 0) {
         fprintf(stderr, "inotify_init: %s\n", strerror(errno));
-        return NULL;
+        goto error_close_fd;
     }
 
     int wfd = inotify_add_watch(ifd, traces_path, IN_CLOSE_WRITE);
     if (wfd < 0) {
         fprintf(stderr, "inotify_add_watch(%s): %s\n", traces_path, strerror(errno));
-        return NULL;
+        goto error_close_ifd;
     }
 
     struct dirent *d;
@@ -422,39 +441,56 @@
         int pid = atoi(d->d_name);
         if (pid <= 0) continue;
 
-        /* identify Dalvik: /proc/(pid)/exe = /system/bin/app_process */
-        char path[PATH_MAX], data[PATH_MAX];
+        char path[PATH_MAX];
+        char data[PATH_MAX];
         snprintf(path, sizeof(path), "/proc/%d/exe", pid);
-        size_t len = readlink(path, data, sizeof(data) - 1);
-        if (len <= 0 || memcmp(data, "/system/bin/app_process", 23)) continue;
-
-        /* skip zygote -- it won't dump its stack anyway */
-        snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
-        int fd = open(path, O_RDONLY);
-        len = read(fd, data, sizeof(data) - 1);
-        close(fd);
-        if (len <= 0 || !memcmp(data, "zygote", 6)) continue;
-
-        ++dalvik_found;
-        if (kill(pid, SIGQUIT)) {
-            fprintf(stderr, "kill(%d, SIGQUIT): %s\n", pid, strerror(errno));
+        ssize_t len = readlink(path, data, sizeof(data) - 1);
+        if (len <= 0) {
             continue;
         }
+        data[len] = '\0';
 
-        /* wait for the writable-close notification from inotify */
-        struct pollfd pfd = { ifd, POLLIN, 0 };
-        int ret = poll(&pfd, 1, 200);  /* 200 msec timeout */
-        if (ret < 0) {
-            fprintf(stderr, "poll: %s\n", strerror(errno));
-        } else if (ret == 0) {
-            fprintf(stderr, "warning: timed out dumping pid %d\n", pid);
-        } else {
-            struct inotify_event ie;
-            read(ifd, &ie, sizeof(ie));
+        if (!strcmp(data, "/system/bin/app_process")) {
+            /* skip zygote -- it won't dump its stack anyway */
+            snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
+            int fd = open(path, O_RDONLY);
+            len = read(fd, data, sizeof(data) - 1);
+            close(fd);
+            if (len <= 0) {
+                continue;
+            }
+            data[len] = '\0';
+            if (!strcmp(data, "zygote")) {
+                continue;
+            }
+
+            ++dalvik_found;
+            if (kill(pid, SIGQUIT)) {
+                fprintf(stderr, "kill(%d, SIGQUIT): %s\n", pid, strerror(errno));
+                continue;
+            }
+
+            /* wait for the writable-close notification from inotify */
+            struct pollfd pfd = { ifd, POLLIN, 0 };
+            int ret = poll(&pfd, 1, 200);  /* 200 msec timeout */
+            if (ret < 0) {
+                fprintf(stderr, "poll: %s\n", strerror(errno));
+            } else if (ret == 0) {
+                fprintf(stderr, "warning: timed out dumping pid %d\n", pid);
+            } else {
+                struct inotify_event ie;
+                read(ifd, &ie, sizeof(ie));
+            }
+        } else if (should_dump_native_traces(data)) {
+            /* dump native process if appropriate */
+            if (lseek(fd, 0, SEEK_END) < 0) {
+                fprintf(stderr, "lseek: %s\n", strerror(errno));
+            } else {
+                dump_backtrace_to_file(pid, fd);
+            }
         }
     }
 
-    close(ifd);
     if (dalvik_found == 0) {
         fprintf(stderr, "Warning: no Dalvik processes found to dump stacks\n");
     }
@@ -464,12 +500,18 @@
     strlcat(dump_traces_path, ".bugreport", sizeof(dump_traces_path));
     if (rename(traces_path, dump_traces_path)) {
         fprintf(stderr, "rename(%s, %s): %s\n", traces_path, dump_traces_path, strerror(errno));
-        return NULL;
+        goto error_close_ifd;
     }
+    result = dump_traces_path;
 
     /* replace the saved [ANR] traces.txt file */
     rename(anr_traces_path, traces_path);
-    return dump_traces_path;
+
+error_close_ifd:
+    close(ifd);
+error_close_fd:
+    close(fd);
+    return result;
 }
 
 void play_sound(const char* path) {
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 593f178..4062340 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -469,18 +469,31 @@
                 front.requested.crop.getWidth(),
                 front.requested.crop.getHeight());
 
-        if (!isFixedSize()) {
-            // this will make sure LayerBase::doTransaction doesn't update
-            // the drawing state's geometry
-            flags |= eDontUpdateGeometryState;
-        }
-
         // record the new size, form this point on, when the client request
         // a buffer, it'll get the new size.
         mSurfaceTexture->setDefaultBufferSize(
                 temp.requested.w, temp.requested.h);
     }
 
+    if (!isFixedSize()) {
+
+        const bool resizePending = (temp.requested.w != temp.active.w) ||
+                                   (temp.requested.h != temp.active.h);
+
+        if (resizePending) {
+            // don't let LayerBase::doTransaction update the drawing state
+            // if we have a pending resize, unless we are in fixed-size mode.
+            // the drawing state will be updated only once we receive a buffer
+            // with the correct size.
+            //
+            // in particular, we want to make sure the clip (which is part
+            // of the geometry state) is latched together with the size but is
+            // latched immediately when no resizing is involved.
+
+            flags |= eDontUpdateGeometryState;
+        }
+    }
+
     return LayerBase::doTransaction(flags);
 }
 
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index f4779e7..25e80d7 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -960,7 +960,6 @@
     glDisable(GL_TEXTURE_EXTERNAL_OES);
     glDisable(GL_TEXTURE_2D);
     glDisable(GL_BLEND);
-    glDisable(GL_SCISSOR_TEST);
 
     static int toggle = 0;
     toggle = 1 - toggle;
@@ -1819,7 +1818,6 @@
     // redraw the screen entirely...
     glDisable(GL_TEXTURE_EXTERNAL_OES);
     glDisable(GL_TEXTURE_2D);
-    glDisable(GL_SCISSOR_TEST);
     glClearColor(0,0,0,1);
     glClear(GL_COLOR_BUFFER_BIT);
     glMatrixMode(GL_MODELVIEW);
@@ -1835,7 +1833,6 @@
 
     // back to main framebuffer
     glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
-    glDisable(GL_SCISSOR_TEST);
     glDeleteFramebuffersOES(1, &name);
 
     *textureName = tname;
@@ -2048,7 +2045,6 @@
     glDeleteTextures(1, &tname);
     glDisable(GL_TEXTURE_2D);
     glDisable(GL_BLEND);
-    glDisable(GL_SCISSOR_TEST);
     return NO_ERROR;
 }
 
@@ -2200,7 +2196,6 @@
     glDeleteTextures(1, &tname);
     glDisable(GL_TEXTURE_2D);
     glDisable(GL_BLEND);
-    glDisable(GL_SCISSOR_TEST);
 
     return NO_ERROR;
 }
@@ -2228,7 +2223,6 @@
 
     // always clear the whole screen at the end of the animation
     glClearColor(0,0,0,1);
-    glDisable(GL_SCISSOR_TEST);
     glClear(GL_COLOR_BUFFER_BIT);
     hw.flip( Region(hw.bounds()) );
 
@@ -2366,7 +2360,6 @@
 
         // invert everything, b/c glReadPixel() below will invert the FB
         glViewport(0, 0, sw, sh);
-        glScissor(0, 0, sw, sh);
         glMatrixMode(GL_PROJECTION);
         glPushMatrix();
         glLoadIdentity();
@@ -2390,10 +2383,6 @@
             }
         }
 
-        // XXX: this is needed on tegra
-        glEnable(GL_SCISSOR_TEST);
-        glScissor(0, 0, sw, sh);
-
         // check for errors and return screen capture
         if (glGetError() != GL_NO_ERROR) {
             // error while rendering
@@ -2419,7 +2408,6 @@
                 result = NO_MEMORY;
             }
         }
-        glDisable(GL_SCISSOR_TEST);
         glViewport(0, 0, hw_w, hw_h);
         glMatrixMode(GL_PROJECTION);
         glPopMatrix();