Merge "BufferItemConsumer: add functions to set default buffer format/size" into jb-mr2-dev
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 76ba81f..06e9744 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -80,6 +80,7 @@
     { "video",      "Video",            ATRACE_TAG_VIDEO, { } },
     { "camera",     "Camera",           ATRACE_TAG_CAMERA, { } },
     { "hal",        "Hardware Modules", ATRACE_TAG_HAL, { } },
+    { "res",        "Resource Loading", ATRACE_TAG_RESOURCES, { } },
     { "sched",      "CPU Scheduling",   0, {
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_switch/enable" },
         { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable" },
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 18685f7..094dbc2 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -9,7 +9,7 @@
 
 LOCAL_MODULE := dumpstate
 
-LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_SHARED_LIBRARIES := libcutils liblog
 
 ifdef BOARD_LIB_DUMPSTATE
 LOCAL_STATIC_LIBRARIES := $(BOARD_LIB_DUMPSTATE)
diff --git a/cmds/dumpsys/Android.mk b/cmds/dumpsys/Android.mk
index 42b1b73..9be0901 100644
--- a/cmds/dumpsys/Android.mk
+++ b/cmds/dumpsys/Android.mk
@@ -6,6 +6,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
+	liblog \
 	libbinder
 	
 
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index 1dd4ee5..e11b4f8 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -30,6 +30,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
+    liblog \
     libselinux
 
 LOCAL_STATIC_LIBRARIES := \
diff --git a/cmds/ip-up-vpn/Android.mk b/cmds/ip-up-vpn/Android.mk
index de81889..36bbdf5 100644
--- a/cmds/ip-up-vpn/Android.mk
+++ b/cmds/ip-up-vpn/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := ip-up-vpn.c
-LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_SHARED_LIBRARIES := libcutils liblog
 LOCAL_MODULE := ip-up-vpn
 LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/ppp
 LOCAL_MODULE_TAGS := optional
diff --git a/cmds/screenshot/Android.mk b/cmds/screenshot/Android.mk
index 73a8e22..0afb2c5 100644
--- a/cmds/screenshot/Android.mk
+++ b/cmds/screenshot/Android.mk
@@ -5,7 +5,7 @@
 
 LOCAL_MODULE := screenshot
 
-LOCAL_SHARED_LIBRARIES := libcutils libz
+LOCAL_SHARED_LIBRARIES := libcutils libz liblog
 LOCAL_STATIC_LIBRARIES := libpng
 LOCAL_C_INCLUDES += external/zlib
 
diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h
index 6a86db6..6c1b691 100644
--- a/include/gui/BufferQueue.h
+++ b/include/gui/BufferQueue.h
@@ -48,7 +48,7 @@
     // ConsumerListener is the interface through which the BufferQueue notifies
     // the consumer of events that the consumer may wish to react to.  Because
     // the consumer will generally have a mutex that is locked during calls from
-    // teh consumer to the BufferQueue, these calls from the BufferQueue to the
+    // the consumer to the BufferQueue, these calls from the BufferQueue to the
     // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
     struct ConsumerListener : public virtual RefBase {
         // onFrameAvailable is called from queueBuffer each time an additional
@@ -104,66 +104,127 @@
             const sp<IGraphicBufferAlloc>& allocator = NULL);
     virtual ~BufferQueue();
 
+    // Query native window attributes.  The "what" values are enumerated in
+    // window.h (e.g. NATIVE_WINDOW_FORMAT).
     virtual int query(int what, int* value);
 
-    // setBufferCount updates the number of available buffer slots.  After
-    // calling this all buffer slots are both unallocated and owned by the
-    // BufferQueue object (i.e. they are not owned by the client).
+    // setBufferCount updates the number of available buffer slots.  If this
+    // method succeeds, buffer slots will be both unallocated and owned by
+    // the BufferQueue object (i.e. they are not owned by the producer or
+    // consumer).
+    //
+    // This will fail if the producer has dequeued any buffers, or if
+    // bufferCount is invalid.  bufferCount must generally be a value
+    // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS
+    // (inclusive).  It may also be set to zero (the default) to indicate
+    // that the producer does not wish to set a value.  The minimum value
+    // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
+    // ...).
+    //
+    // This may only be called by the producer.  The consumer will be told
+    // to discard buffers through the onBuffersReleased callback.
     virtual status_t setBufferCount(int bufferCount);
 
+    // requestBuffer returns the GraphicBuffer for slot N.
+    //
+    // In normal operation, this is called the first time slot N is returned
+    // by dequeueBuffer.  It must be called again if dequeueBuffer returns
+    // flags indicating that previously-returned buffers are no longer valid.
     virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
 
-    // dequeueBuffer gets the next buffer slot index for the client to use. If a
-    // buffer slot is available then that slot index is written to the location
-    // pointed to by the buf argument and a status of OK is returned.  If no
-    // slot is available then a status of -EBUSY is returned and buf is
+    // dequeueBuffer gets the next buffer slot index for the producer to use.
+    // If a buffer slot is available then that slot index is written to the
+    // location pointed to by the buf argument and a status of OK is returned.
+    // If no slot is available then a status of -EBUSY is returned and buf is
     // unmodified.
     //
     // The fence parameter will be updated to hold the fence associated with
     // the buffer. The contents of the buffer must not be overwritten until the
-    // fence signals. If the fence is NULL, the buffer may be written
-    // immediately.
+    // fence signals. If the fence is Fence::NO_FENCE, the buffer may be
+    // written immediately.
     //
     // The width and height parameters must be no greater than the minimum of
     // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
     // An error due to invalid dimensions might not be reported until
-    // updateTexImage() is called.
+    // updateTexImage() is called.  If width and height are both zero, the
+    // default values specified by setDefaultBufferSize() are used instead.
+    //
+    // The pixel formats are enumerated in graphics.h, e.g.
+    // HAL_PIXEL_FORMAT_RGBA_8888.  If the format is 0, the default format
+    // will be used.
+    //
+    // The usage argument specifies gralloc buffer usage flags.  The values
+    // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER.  These
+    // will be merged with the usage flags specified by setConsumerUsageBits.
+    //
+    // The return value may be a negative error value or a non-negative
+    // collection of flags.  If the flags are set, the return values are
+    // valid, but additional actions must be performed.
+    //
+    // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the
+    // producer must discard cached GraphicBuffer references for the slot
+    // returned in buf.
+    // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer
+    // must discard cached GraphicBuffer references for all slots.
+    //
+    // In both cases, the producer will need to call requestBuffer to get a
+    // GraphicBuffer handle for the returned slot.
     virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence,
             uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
 
-    // queueBuffer returns a filled buffer to the BufferQueue. In addition, a
-    // timestamp must be provided for the buffer. The timestamp is in
+    // queueBuffer returns a filled buffer to the BufferQueue.
+    //
+    // Additional data is provided in the QueueBufferInput struct.  Notably,
+    // a timestamp must be provided for the buffer. The timestamp is in
     // nanoseconds, and must be monotonically increasing. Its other semantics
-    // (zero point, etc) are client-dependent and should be documented by the
-    // client.
+    // (zero point, etc) are producer-specific and should be documented by the
+    // producer.
+    //
+    // The caller may provide a fence that signals when all rendering
+    // operations have completed.  Alternatively, NO_FENCE may be used,
+    // indicating that the buffer is ready immediately.
+    //
+    // Some values are returned in the output struct: the current settings
+    // for default width and height, the current transform hint, and the
+    // number of queued buffers.
     virtual status_t queueBuffer(int buf,
             const QueueBufferInput& input, QueueBufferOutput* output);
 
+    // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't
+    // queue it for use by the consumer.
+    //
+    // The buffer will not be overwritten until the fence signals.  The fence
+    // will usually be the one obtained from dequeueBuffer.
     virtual void cancelBuffer(int buf, const sp<Fence>& fence);
 
-    // setSynchronousMode set whether dequeueBuffer is synchronous or
+    // setSynchronousMode sets whether dequeueBuffer is synchronous or
     // asynchronous. In synchronous mode, dequeueBuffer blocks until
     // a buffer is available, the currently bound buffer can be dequeued and
-    // queued buffers will be retired in order.
+    // queued buffers will be acquired in order.  In asynchronous mode,
+    // a queued buffer may be replaced by a subsequently queued buffer.
+    //
     // The default mode is asynchronous.
     virtual status_t setSynchronousMode(bool enabled);
 
-    // connect attempts to connect a producer client API to the BufferQueue.
-    // This must be called before any other IGraphicBufferProducer methods are called
-    // except for getAllocator.
+    // connect attempts to connect a producer API to the BufferQueue.  This
+    // must be called before any other IGraphicBufferProducer methods are
+    // called except for getAllocator.  A consumer must already be connected.
     //
-    // This method will fail if the connect was previously called on the
-    // BufferQueue and no corresponding disconnect call was made.
+    // This method will fail if connect was previously called on the
+    // BufferQueue and no corresponding disconnect call was made (i.e. if
+    // it's still connected to a producer).
+    //
+    // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU).
     virtual status_t connect(int api, QueueBufferOutput* output);
 
-    // disconnect attempts to disconnect a producer client API from the
-    // BufferQueue. Calling this method will cause any subsequent calls to other
+    // disconnect attempts to disconnect a producer API from the BufferQueue.
+    // Calling this method will cause any subsequent calls to other
     // IGraphicBufferProducer methods to fail except for getAllocator and connect.
     // Successfully calling connect after this will allow the other methods to
     // succeed again.
     //
     // This method will fail if the the BufferQueue is not currently
-    // connected to the specified client API.
+    // connected to the specified producer API.
     virtual status_t disconnect(int api);
 
     // dump our state in a String
@@ -181,7 +242,7 @@
            mFrameNumber(0),
            mBuf(INVALID_BUFFER_SLOT) {
              mCrop.makeInvalid();
-         }
+        }
         // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
         // if the buffer in this slot has been acquired in the past (see
         // BufferSlot.mAcquireCalled).
@@ -210,7 +271,7 @@
         sp<Fence> mFence;
     };
 
-    // The following public functions is the consumer facing interface
+    // The following public functions are the consumer-facing interface
 
     // acquireBuffer attempts to acquire ownership of the next pending buffer in
     // the BufferQueue.  If no buffer is pending then it returns -EINVAL.  If a
@@ -222,7 +283,9 @@
     status_t acquireBuffer(BufferItem *buffer);
 
     // releaseBuffer releases a buffer slot from the consumer back to the
-    // BufferQueue pending a fence sync.
+    // BufferQueue.  This may be done while the buffer's contents are still
+    // being accessed.  The fence will signal when the buffer is no longer
+    // in use.
     //
     // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
     // any references to the just-released buffer that it might have, as if it
@@ -238,6 +301,8 @@
     // consumer may be connected, and when that consumer disconnects the
     // BufferQueue is placed into the "abandoned" state, causing most
     // interactions with the BufferQueue by the producer to fail.
+    //
+    // consumer may not be NULL.
     status_t consumerConnect(const sp<ConsumerListener>& consumer);
 
     // consumerDisconnect disconnects a consumer from the BufferQueue. All
@@ -247,22 +312,28 @@
     status_t consumerDisconnect();
 
     // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
-    // indicating which buffer slots the have been released by the BufferQueue
+    // indicating which buffer slots have been released by the BufferQueue
     // but have not yet been released by the consumer.
+    //
+    // This should be called from the onBuffersReleased() callback.
     status_t getReleasedBuffers(uint32_t* slotMask);
 
     // setDefaultBufferSize is used to set the size of buffers returned by
-    // requestBuffers when a with and height of zero is requested.
+    // dequeueBuffer when a width and height of zero is requested.  Default
+    // is 1x1.
     status_t setDefaultBufferSize(uint32_t w, uint32_t h);
 
-    // setDefaultBufferCount set the buffer count. If the client has requested
-    // a buffer count using setBufferCount, the server-buffer count will
-    // take effect once the client sets the count back to zero.
+    // setDefaultMaxBufferCount sets the default value for the maximum buffer
+    // count (the initial default is 2). If the producer has requested a
+    // buffer count using setBufferCount, the default buffer count will only
+    // take effect if the producer sets the count back to zero.
+    //
+    // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
     status_t setDefaultMaxBufferCount(int bufferCount);
 
     // setMaxAcquiredBufferCount sets the maximum number of buffers that can
-    // be acquired by the consumer at one time.  This call will fail if a
-    // producer is connected to the BufferQueue.
+    // be acquired by the consumer at one time (default 1).  This call will
+    // fail if a producer is connected to the BufferQueue.
     status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);
 
     // isSynchronousMode returns whether the BufferQueue is currently in
@@ -274,41 +345,48 @@
 
     // setDefaultBufferFormat allows the BufferQueue to create
     // GraphicBuffers of a defaultFormat if no format is specified
-    // in dequeueBuffer
+    // in dequeueBuffer.  Formats are enumerated in graphics.h; the
+    // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
     status_t setDefaultBufferFormat(uint32_t defaultFormat);
 
-    // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer
+    // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
+    // These are merged with the bits passed to dequeueBuffer.  The values are
+    // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
     status_t setConsumerUsageBits(uint32_t usage);
 
-    // setTransformHint bakes in rotation to buffers so overlays can be used
+    // setTransformHint bakes in rotation to buffers so overlays can be used.
+    // The values are enumerated in window.h, e.g.
+    // NATIVE_WINDOW_TRANSFORM_ROT_90.  The default is 0 (no transform).
     status_t setTransformHint(uint32_t hint);
 
 private:
-    // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
-    // for the given slot.
+    // freeBufferLocked frees the GraphicBuffer and sync resources for the
+    // given slot.
     void freeBufferLocked(int index);
 
-    // freeAllBuffersLocked frees the resources (both GraphicBuffer and
-    // EGLImage) for all slots.
+    // freeAllBuffersLocked frees the GraphicBuffer and sync resources for
+    // all slots.
     void freeAllBuffersLocked();
 
-    // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
-    // and EGLImage) for all slots except the head of mQueue
+    // freeAllBuffersExceptHeadLocked frees the GraphicBuffer and sync
+    // resources for all slots except the head of mQueue.
     void freeAllBuffersExceptHeadLocked();
 
-    // drainQueueLocked drains the buffer queue if we're in synchronous mode
-    // returns immediately otherwise. It returns NO_INIT if the BufferQueue
-    // became abandoned or disconnected during this call.
+    // drainQueueLocked waits for the buffer queue to empty if we're in
+    // synchronous mode, or returns immediately otherwise. It returns NO_INIT
+    // if the BufferQueue is abandoned (consumer disconnected) or disconnected
+    // (producer disconnected) during the call.
     status_t drainQueueLocked();
 
     // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
     // synchronous mode and free all buffers. In asynchronous mode, all buffers
-    // are freed except the current buffer.
+    // are freed except the currently queued buffer (if it exists).
     status_t drainQueueAndFreeBuffersLocked();
 
     // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
     // that will be used if the producer does not override the buffer slot
-    // count.
+    // count.  The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
+    // The initial default is 2.
     status_t setDefaultMaxBufferCountLocked(int count);
 
     // getMinBufferCountLocked returns the minimum number of buffers allowed
@@ -352,51 +430,56 @@
         // if no buffer has been allocated.
         sp<GraphicBuffer> mGraphicBuffer;
 
-        // mEglDisplay is the EGLDisplay used to create mEglImage.
+        // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects.
         EGLDisplay mEglDisplay;
 
         // BufferState represents the different states in which a buffer slot
-        // can be.
+        // can be.  All slots are initially FREE.
         enum BufferState {
-            // FREE indicates that the buffer is not currently being used and
-            // will not be used in the future until it gets dequeued and
-            // subsequently queued by the client.
-            // aka "owned by BufferQueue, ready to be dequeued"
+            // FREE indicates that the buffer is available to be dequeued
+            // by the producer.  The buffer may be in use by the consumer for
+            // a finite time, so the buffer must not be modified until the
+            // associated fence is signaled.
+            //
+            // The slot is "owned" by BufferQueue.  It transitions to DEQUEUED
+            // when dequeueBuffer is called.
             FREE = 0,
 
             // DEQUEUED indicates that the buffer has been dequeued by the
-            // client, but has not yet been queued or canceled. The buffer is
-            // considered 'owned' by the client, and the server should not use
-            // it for anything.
+            // producer, but has not yet been queued or canceled.  The
+            // producer may modify the buffer's contents as soon as the
+            // associated ready fence is signaled.
             //
-            // Note that when in synchronous-mode (mSynchronousMode == true),
-            // the buffer that's currently attached to the texture may be
-            // dequeued by the client.  That means that the current buffer can
-            // be in either the DEQUEUED or QUEUED state.  In asynchronous mode,
-            // however, the current buffer is always in the QUEUED state.
-            // aka "owned by producer, ready to be queued"
+            // The slot is "owned" by the producer.  It can transition to
+            // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer).
             DEQUEUED = 1,
 
-            // QUEUED indicates that the buffer has been queued by the client,
-            // and has not since been made available for the client to dequeue.
-            // Attaching the buffer to the texture does NOT transition the
-            // buffer away from the QUEUED state. However, in Synchronous mode
-            // the current buffer may be dequeued by the client under some
-            // circumstances. See the note about the current buffer in the
-            // documentation for DEQUEUED.
-            // aka "owned by BufferQueue, ready to be acquired"
+            // QUEUED indicates that the buffer has been filled by the
+            // producer and queued for use by the consumer.  The buffer
+            // contents may continue to be modified for a finite time, so
+            // the contents must not be accessed until the associated fence
+            // is signaled.
+            //
+            // The slot is "owned" by BufferQueue.  It can transition to
+            // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is
+            // queued in asynchronous mode).
             QUEUED = 2,
 
-            // aka "owned by consumer, ready to be released"
+            // ACQUIRED indicates that the buffer has been acquired by the
+            // consumer.  As with QUEUED, the contents must not be accessed
+            // by the consumer until the fence is signaled.
+            //
+            // The slot is "owned" by the consumer.  It transitions to FREE
+            // when releaseBuffer is called.
             ACQUIRED = 3
         };
 
         // mBufferState is the current state of this buffer slot.
         BufferState mBufferState;
 
-        // mRequestBufferCalled is used for validating that the client did
+        // mRequestBufferCalled is used for validating that the producer did
         // call requestBuffer() when told to do so. Technically this is not
-        // needed but useful for debugging and catching client bugs.
+        // needed but useful for debugging and catching producer bugs.
         bool mRequestBufferCalled;
 
         // mCrop is the current crop rectangle for this buffer slot.
@@ -414,13 +497,16 @@
         // to set by queueBuffer each time this slot is queued.
         int64_t mTimestamp;
 
-        // mFrameNumber is the number of the queued frame for this slot.
+        // mFrameNumber is the number of the queued frame for this slot.  This
+        // is used to dequeue buffers in LRU order (useful because buffers
+        // may be released before their release fence is signaled).
         uint64_t mFrameNumber;
 
         // mEglFence is the EGL sync object that must signal before the buffer
         // associated with this buffer slot may be dequeued. It is initialized
-        // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
-        // on a compile-time option) set to a new sync object in updateTexImage.
+        // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a
+        // new sync object in releaseBuffer.  (This is deprecated in favor of
+        // mFence, below.)
         EGLSyncKHR mEglFence;
 
         // mFence is a fence which will signal when work initiated by the
@@ -431,29 +517,32 @@
         // QUEUED, it indicates when the producer has finished filling the
         // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
         // passed to the consumer or producer along with ownership of the
-        // buffer, and mFence is empty.
+        // buffer, and mFence is set to NO_FENCE.
         sp<Fence> mFence;
 
         // Indicates whether this buffer has been seen by a consumer yet
         bool mAcquireCalled;
 
-        // Indicates whether this buffer needs to be cleaned up by consumer
+        // Indicates whether this buffer needs to be cleaned up by the
+        // consumer.  This is set when a buffer in ACQUIRED state is freed.
+        // It causes releaseBuffer to return STALE_BUFFER_SLOT.
         bool mNeedsCleanupOnRelease;
     };
 
-    // mSlots is the array of buffer slots that must be mirrored on the client
-    // side. This allows buffer ownership to be transferred between the client
-    // and server without sending a GraphicBuffer over binder. The entire array
-    // is initialized to NULL at construction time, and buffers are allocated
-    // for a slot when requestBuffer is called with that slot's index.
+    // mSlots is the array of buffer slots that must be mirrored on the
+    // producer side. This allows buffer ownership to be transferred between
+    // the producer and consumer without sending a GraphicBuffer over binder.
+    // The entire array is initialized to NULL at construction time, and
+    // buffers are allocated for a slot when requestBuffer is called with
+    // that slot's index.
     BufferSlot mSlots[NUM_BUFFER_SLOTS];
 
     // mDefaultWidth holds the default width of allocated buffers. It is used
-    // in requestBuffers() if a width and height of zero is specified.
+    // in dequeueBuffer() if a width and height of zero is specified.
     uint32_t mDefaultWidth;
 
     // mDefaultHeight holds the default height of allocated buffers. It is used
-    // in requestBuffers() if a width and height of zero is specified.
+    // in dequeueBuffer() if a width and height of zero is specified.
     uint32_t mDefaultHeight;
 
     // mMaxAcquiredBufferCount is the number of buffers that the consumer may
@@ -490,12 +579,13 @@
     // mSynchronousMode whether we're in synchronous mode or not
     bool mSynchronousMode;
 
-    // mAllowSynchronousMode whether we allow synchronous mode or not
+    // mAllowSynchronousMode whether we allow synchronous mode or not.  Set
+    // when the BufferQueue is created (by the consumer).
     const bool mAllowSynchronousMode;
 
-    // mConnectedApi indicates the API that is currently connected to this
-    // BufferQueue.  It defaults to NO_CONNECTED_API (= 0), and gets updated
-    // by the connect and disconnect methods.
+    // mConnectedApi indicates the producer API that is currently connected
+    // to this BufferQueue.  It defaults to NO_CONNECTED_API (= 0), and gets
+    // updated by the connect and disconnect methods.
     int mConnectedApi;
 
     // mDequeueCondition condition used for dequeueBuffer in synchronous mode
@@ -506,14 +596,15 @@
     Fifo mQueue;
 
     // mAbandoned indicates that the BufferQueue will no longer be used to
-    // consume images buffers pushed to it using the IGraphicBufferProducer interface.
-    // It is initialized to false, and set to true in the abandon method.  A
-    // BufferQueue that has been abandoned will return the NO_INIT error from
-    // all IGraphicBufferProducer methods capable of returning an error.
+    // consume image buffers pushed to it using the IGraphicBufferProducer
+    // interface.  It is initialized to false, and set to true in the
+    // consumerDisconnect method.  A BufferQueue that has been abandoned will
+    // return the NO_INIT error from all IGraphicBufferProducer methods
+    // capable of returning an error.
     bool mAbandoned;
 
-    // mName is a string used to identify the BufferQueue in log messages.
-    // It is set by the setName method.
+    // mConsumerName is a string used to identify the BufferQueue in log
+    // messages.  It is set by the setConsumerName method.
     String8 mConsumerName;
 
     // mMutex is the mutex used to prevent concurrent access to the member
@@ -521,12 +612,13 @@
     // member variables are accessed.
     mutable Mutex mMutex;
 
-    // mFrameCounter is the free running counter, incremented for every buffer queued
-    // with the surface Texture.
+    // mFrameCounter is the free running counter, incremented on every
+    // successful queueBuffer call.
     uint64_t mFrameCounter;
 
-    // mBufferHasBeenQueued is true once a buffer has been queued.  It is reset
-    // by changing the buffer count.
+    // mBufferHasBeenQueued is true once a buffer has been queued.  It is
+    // reset when something causes all buffers to be freed (e.g. changing the
+    // buffer count).
     bool mBufferHasBeenQueued;
 
     // mDefaultBufferFormat can be set so it will override
diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h
index 78a3608..8a7545d 100644
--- a/include/gui/ConsumerBase.h
+++ b/include/gui/ConsumerBase.h
@@ -89,6 +89,18 @@
     // buffers from the given BufferQueue.
     ConsumerBase(const sp<BufferQueue> &bufferQueue);
 
+    // onLastStrongRef gets called by RefBase just before the dtor of the most
+    // derived class.  It is used to clean up the buffers so that ConsumerBase
+    // can coordinate the clean-up by calling into virtual methods implemented
+    // by the derived classes.  This would not be possible from the
+    // ConsuemrBase dtor because by the time that gets called the derived
+    // classes have already been destructed.
+    //
+    // This methods should not need to be overridden by derived classes, but
+    // if they are overridden the ConsumerBase implementation must be called
+    // from the derived class.
+    virtual void onLastStrongRef(const void* id);
+
     // Implementation of the BufferQueue::ConsumerListener interface.  These
     // calls are used to notify the ConsumerBase of asynchronous events in the
     // BufferQueue.  These methods should not need to be overridden by derived
diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk
index 8fcfa7d..c080f47 100644
--- a/libs/gui/Android.mk
+++ b/libs/gui/Android.mk
@@ -36,6 +36,7 @@
 	libsync \
 	libui \
 	libutils \
+	liblog
 
 
 LOCAL_MODULE:= libgui
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index 75a0296..b4c7231 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -106,7 +106,7 @@
     mDefaultMaxBufferCount = count;
     mDequeueCondition.broadcast();
 
-    return OK;
+    return NO_ERROR;
 }
 
 bool BufferQueue::isSynchronousMode() const {
@@ -122,20 +122,20 @@
 status_t BufferQueue::setDefaultBufferFormat(uint32_t defaultFormat) {
     Mutex::Autolock lock(mMutex);
     mDefaultBufferFormat = defaultFormat;
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::setConsumerUsageBits(uint32_t usage) {
     Mutex::Autolock lock(mMutex);
     mConsumerUsageBits = usage;
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::setTransformHint(uint32_t hint) {
     ST_LOGV("setTransformHint: %02x", hint);
     Mutex::Autolock lock(mMutex);
     mTransformHint = hint;
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::setBufferCount(int bufferCount) {
@@ -150,7 +150,8 @@
             return NO_INIT;
         }
         if (bufferCount > NUM_BUFFER_SLOTS) {
-            ST_LOGE("setBufferCount: bufferCount larger than slots available");
+            ST_LOGE("setBufferCount: bufferCount too large (max %d)",
+                    NUM_BUFFER_SLOTS);
             return BAD_VALUE;
         }
 
@@ -167,7 +168,7 @@
         if (bufferCount == 0) {
             mOverrideMaxBufferCount = 0;
             mDequeueCondition.broadcast();
-            return OK;
+            return NO_ERROR;
         }
 
         if (bufferCount < minBufferSlots) {
@@ -191,7 +192,7 @@
         listener->onBuffersReleased();
     }
 
-    return OK;
+    return NO_ERROR;
 }
 
 int BufferQueue::query(int what, int* outValue)
@@ -587,7 +588,7 @@
     if (listener != 0) {
         listener->onFrameAvailable();
     }
-    return OK;
+    return NO_ERROR;
 }
 
 void BufferQueue::cancelBuffer(int buf, const sp<Fence>& fence) {
@@ -858,7 +859,7 @@
         return NO_BUFFER_AVAILABLE;
     }
 
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::releaseBuffer(int buf, EGLDisplay display,
@@ -889,7 +890,7 @@
     }
 
     mDequeueCondition.broadcast();
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::consumerConnect(const sp<ConsumerListener>& consumerListener) {
@@ -900,10 +901,14 @@
         ST_LOGE("consumerConnect: BufferQueue has been abandoned!");
         return NO_INIT;
     }
+    if (consumerListener == NULL) {
+        ST_LOGE("consumerConnect: consumerListener may not be NULL");
+        return BAD_VALUE;
+    }
 
     mConsumerListener = consumerListener;
 
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::consumerDisconnect() {
@@ -920,7 +925,7 @@
     mQueue.clear();
     freeAllBuffersLocked();
     mDequeueCondition.broadcast();
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::getReleasedBuffers(uint32_t* slotMask) {
@@ -956,7 +961,7 @@
     Mutex::Autolock lock(mMutex);
     mDefaultWidth = w;
     mDefaultHeight = h;
-    return OK;
+    return NO_ERROR;
 }
 
 status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) {
@@ -977,7 +982,7 @@
         return INVALID_OPERATION;
     }
     mMaxAcquiredBufferCount = maxAcquiredBuffers;
-    return OK;
+    return NO_ERROR;
 }
 
 void BufferQueue::freeAllBuffersExceptHeadLocked() {
diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp
index 8694d21..4937b17 100644
--- a/libs/gui/ConsumerBase.cpp
+++ b/libs/gui/ConsumerBase.cpp
@@ -76,7 +76,18 @@
 }
 
 ConsumerBase::~ConsumerBase() {
-	CB_LOGV("~ConsumerBase");
+    CB_LOGV("~ConsumerBase");
+    Mutex::Autolock lock(mMutex);
+
+    // Verify that abandon() has been called before we get here.  This should
+    // be done by ConsumerBase::onLastStrongRef(), but it's possible for a
+    // derived class to override that method and not call
+    // ConsumerBase::onLastStrongRef().
+    LOG_ALWAYS_FATAL_IF(!mAbandoned, "[%s] ~ConsumerBase was called, but the "
+        "consumer is not abandoned!", mName.string());
+}
+
+void ConsumerBase::onLastStrongRef(const void* id) {
     abandon();
 }
 
diff --git a/libs/gui/tests/Android.mk b/libs/gui/tests/Android.mk
index 4a6f74f..21bd875 100644
--- a/libs/gui/tests/Android.mk
+++ b/libs/gui/tests/Android.mk
@@ -15,6 +15,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libEGL \
+	libGLESv1_CM \
 	libGLESv2 \
 	libbinder \
 	libcutils \
diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp
index ce96036..7376b4c 100644
--- a/libs/gui/tests/SurfaceTextureClient_test.cpp
+++ b/libs/gui/tests/SurfaceTextureClient_test.cpp
@@ -178,21 +178,21 @@
     EXPECT_EQ(EGL_SUCCESS, eglGetError());
 
     EGLBoolean success = eglMakeCurrent(mEglDisplay, eglSurface, eglSurface, mEglContext);
-    EXPECT_EQ(EGL_TRUE, success);
+    EXPECT_TRUE(success);
 
     glClear(GL_COLOR_BUFFER_BIT);
     success = eglSwapBuffers(mEglDisplay, eglSurface);
-    EXPECT_EQ(EGL_TRUE, success);
+    EXPECT_TRUE(success);
 
     mST->abandon();
 
     glClear(GL_COLOR_BUFFER_BIT);
     success = eglSwapBuffers(mEglDisplay, eglSurface);
-    EXPECT_EQ(EGL_FALSE, success);
+    EXPECT_FALSE(success);
     EXPECT_EQ(EGL_BAD_SURFACE, eglGetError());
 
     success = eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
-    ASSERT_EQ(EGL_TRUE, success);
+    ASSERT_TRUE(success);
 
     if (eglSurface != EGL_NO_SURFACE) {
         eglDestroySurface(mEglDisplay, eglSurface);
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index 2d30305..47f6df7 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -29,10 +29,14 @@
 
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
 #include <ui/FramebufferNativeWindow.h>
+#include <utils/UniquePtr.h>
+#include <android/native_window.h>
 
 namespace android {
 
@@ -375,6 +379,107 @@
 
 // XXX: Code above this point should live elsewhere
 
+class MultiTextureConsumerTest : public GLTest {
+protected:
+    enum { TEX_ID = 123 };
+
+    virtual void SetUp() {
+        GLTest::SetUp();
+        mGlConsumer = new GLConsumer(TEX_ID);
+        mSurface = new Surface(mGlConsumer->getBufferQueue());
+        mANW = mSurface.get();
+
+    }
+    virtual void TearDown() {
+        GLTest::TearDown();
+    }
+    virtual EGLint const* getContextAttribs() {
+        return NULL;
+    }
+    virtual EGLint const* getConfigAttribs() {
+        static EGLint sDefaultConfigAttribs[] = {
+            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+            EGL_RED_SIZE, 8,
+            EGL_GREEN_SIZE, 8,
+            EGL_BLUE_SIZE, 8,
+            EGL_ALPHA_SIZE, 8,
+            EGL_NONE };
+
+        return sDefaultConfigAttribs;
+    }
+    sp<GLConsumer> mGlConsumer;
+    sp<Surface> mSurface;
+    ANativeWindow* mANW;
+};
+
+
+TEST_F(MultiTextureConsumerTest, EGLImageTargetWorks) {
+    ANativeWindow_Buffer buffer;
+
+    ASSERT_EQ(native_window_set_usage(mANW, GRALLOC_USAGE_SW_WRITE_OFTEN), NO_ERROR);
+    ASSERT_EQ(native_window_set_buffers_format(mANW, HAL_PIXEL_FORMAT_RGBA_8888), NO_ERROR);
+
+    glShadeModel(GL_FLAT);
+    glDisable(GL_DITHER);
+    glDisable(GL_CULL_FACE);
+    glViewport(0, 0, getSurfaceWidth(), getSurfaceHeight());
+    glOrthof(0, getSurfaceWidth(), 0, getSurfaceHeight(), 0, 1);
+    glEnableClientState(GL_VERTEX_ARRAY);
+    glColor4f(1, 1, 1, 1);
+
+    glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
+    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+    uint32_t texel = 0x80808080;
+    glBindTexture(GL_TEXTURE_2D, TEX_ID+1);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &texel);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+    glActiveTexture(GL_TEXTURE1);
+    glBindTexture(GL_TEXTURE_2D, TEX_ID+1);
+    glEnable(GL_TEXTURE_2D);
+    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+    glActiveTexture(GL_TEXTURE0);
+    glBindTexture(GL_TEXTURE_EXTERNAL_OES, TEX_ID);
+    glEnable(GL_TEXTURE_EXTERNAL_OES);
+    glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+    glClear(GL_COLOR_BUFFER_BIT);
+    for (int i=0 ; i<8 ; i++) {
+        mSurface->lock(&buffer, NULL);
+        memset(buffer.bits, (i&7) * 0x20, buffer.stride * buffer.height * 4);
+        mSurface->unlockAndPost();
+
+        mGlConsumer->updateTexImage();
+
+        GLfloat vertices[][2] = { {i*16.0f, 0}, {(i+1)*16.0f, 0}, {(i+1)*16.0f, 16.0f}, {i*16.0f, 16.0f} };
+        glVertexPointer(2, GL_FLOAT, 0, vertices);
+        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+        ASSERT_EQ( glGetError(), GL_NO_ERROR );
+    }
+    ASSERT_TRUE( eglSwapBuffers(mEglDisplay, mEglSurface) );
+
+    uint32_t* pixels = new uint32_t[8*16*16];
+    glReadPixels(0, 0, 8*16, 16, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+    for (int i=0 ; i<8 ; i++) {
+        uint32_t p = pixels[i*16 + 8 + 8*(8*16)]; // center of each square
+        EXPECT_EQ(p, (i&7) * 0x10101010);
+    }
+
+    delete [] pixels;
+}
+
+
+
 class SurfaceTextureGLTest : public GLTest {
 protected:
     enum { TEX_ID = 123 };
@@ -716,18 +821,18 @@
     glViewport(0, 0, texWidth, texHeight);
     drawTexture();
 
-    EXPECT_TRUE(checkPixel( 0,  0, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(63,  0,   0, 133,   0, 255));
-    EXPECT_TRUE(checkPixel(63, 65,   0, 133,   0, 255));
-    EXPECT_TRUE(checkPixel( 0, 65, 255, 127, 255, 255));
+    EXPECT_TRUE(checkPixel( 0,  0, 255, 127, 255, 255, 3));
+    EXPECT_TRUE(checkPixel(63,  0,   0, 133,   0, 255, 3));
+    EXPECT_TRUE(checkPixel(63, 65,   0, 133,   0, 255, 3));
+    EXPECT_TRUE(checkPixel( 0, 65, 255, 127, 255, 255, 3));
 
-    EXPECT_TRUE(checkPixel(22, 44, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(45, 52, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(52, 51,  98, 255,  73, 255));
-    EXPECT_TRUE(checkPixel( 7, 31, 155,   0, 118, 255));
-    EXPECT_TRUE(checkPixel(31,  9, 107,  24,  87, 255));
-    EXPECT_TRUE(checkPixel(29, 35, 255, 127, 255, 255));
-    EXPECT_TRUE(checkPixel(36, 22, 155,  29,   0, 255));
+    EXPECT_TRUE(checkPixel(22, 44, 255, 127, 255, 255, 3));
+    EXPECT_TRUE(checkPixel(45, 52, 255, 127, 255, 255, 3));
+    EXPECT_TRUE(checkPixel(52, 51,  98, 255,  73, 255, 3));
+    EXPECT_TRUE(checkPixel( 7, 31, 155,   0, 118, 255, 3));
+    EXPECT_TRUE(checkPixel(31,  9, 107,  24,  87, 255, 3));
+    EXPECT_TRUE(checkPixel(29, 35, 255, 127, 255, 255, 3));
+    EXPECT_TRUE(checkPixel(36, 22, 155,  29,   0, 255, 3));
 }
 
 TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BufferPow2) {
diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk
index 0d2e44c..008446b 100644
--- a/libs/ui/Android.mk
+++ b/libs/ui/Android.mk
@@ -30,7 +30,8 @@
 	libcutils \
 	libhardware \
 	libsync \
-	libutils
+	libutils \
+	liblog
 
 ifneq ($(BOARD_FRAMEBUFFER_FORCE_FORMAT),)
 LOCAL_CFLAGS += -DFRAMEBUFFER_FORCE_FORMAT=$(BOARD_FRAMEBUFFER_FORCE_FORMAT)
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
index 9b8d3fe..9886bf0 100644
--- a/opengl/libagl/Android.mk
+++ b/opengl/libagl/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
 LOCAL_CFLAGS += -fvisibility=hidden
 
-LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils libpixelflinger libETC1 libui
+LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils liblog libpixelflinger libETC1 libui
 LOCAL_LDLIBS := -lpthread -ldl
 
 ifeq ($(TARGET_ARCH),arm)
diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk
index 581c4d4..b4756dd 100644
--- a/opengl/libs/Android.mk
+++ b/opengl/libs/Android.mk
@@ -32,7 +32,7 @@
 	EGL/Loader.cpp 	       \
 #
 
-LOCAL_SHARED_LIBRARIES += libcutils libutils libGLES_trace
+LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libGLES_trace
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libEGL
 LOCAL_LDFLAGS += -Wl,--exclude-libs=ALL
@@ -85,7 +85,7 @@
 	GLES_CM/gl.cpp.arm 	\
 #
 
-LOCAL_SHARED_LIBRARIES += libcutils libEGL
+LOCAL_SHARED_LIBRARIES += libcutils liblog libEGL
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libGLESv1_CM
 
@@ -110,7 +110,7 @@
 	GLES2/gl2.cpp.arm 	\
 #
 
-LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL
+LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libEGL
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE:= libGLESv2
 
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index f6bc069..9a214c2 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -960,6 +960,13 @@
 
     egl_surface_t const * const s = get_surface(draw);
 
+    if (CC_UNLIKELY(dp->traceGpuCompletion)) {
+        EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
+        if (sync != EGL_NO_SYNC_KHR) {
+            FrameCompletionThread::queueSync(sync);
+        }
+    }
+
     if (CC_UNLIKELY(dp->finishOnSwap)) {
         uint32_t pixel;
         egl_context_t * const c = get_context( egl_tls_t::getContext() );
@@ -970,19 +977,7 @@
         }
     }
 
-    EGLBoolean result = s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
-
-    if (CC_UNLIKELY(dp->traceGpuCompletion)) {
-        EGLSyncKHR sync = EGL_NO_SYNC_KHR;
-        {
-            sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
-        }
-        if (sync != EGL_NO_SYNC_KHR) {
-            FrameCompletionThread::queueSync(sync);
-        }
-    }
-
-    return result;
+    return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
 }
 
 EGLBoolean eglCopyBuffers(  EGLDisplay dpy, EGLSurface surface,
diff --git a/opengl/libs/GLES_trace/Android.mk b/opengl/libs/GLES_trace/Android.mk
index 9dec020..846932d 100644
--- a/opengl/libs/GLES_trace/Android.mk
+++ b/opengl/libs/GLES_trace/Android.mk
@@ -22,7 +22,7 @@
 
 LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI
 LOCAL_STATIC_LIBRARIES := libprotobuf-cpp-2.3.0-lite liblzf
-LOCAL_SHARED_LIBRARIES := libcutils libutils libstlport
+LOCAL_SHARED_LIBRARIES := libcutils libutils liblog libstlport
 
 LOCAL_CFLAGS += -DLOG_TAG=\"libGLES_trace\"
 
diff --git a/opengl/tests/gl2_jni/Android.mk b/opengl/tests/gl2_jni/Android.mk
index 25187c9..409bd73 100644
--- a/opengl/tests/gl2_jni/Android.mk
+++ b/opengl/tests/gl2_jni/Android.mk
@@ -37,6 +37,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
+	liblog \
 	libEGL \
 	libGLESv2
 
diff --git a/opengl/tests/gl_jni/Android.mk b/opengl/tests/gl_jni/Android.mk
index 80b4bac..11b4c8b 100644
--- a/opengl/tests/gl_jni/Android.mk
+++ b/opengl/tests/gl_jni/Android.mk
@@ -37,6 +37,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
+	liblog \
 	libEGL \
 	libGLESv1_CM
 
diff --git a/opengl/tests/gl_perf/Android.mk b/opengl/tests/gl_perf/Android.mk
index cfca089..b0f825c 100644
--- a/opengl/tests/gl_perf/Android.mk
+++ b/opengl/tests/gl_perf/Android.mk
@@ -6,7 +6,8 @@
 	filltest.cpp
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
+    libcutils \
+    liblog \
     libEGL \
     libGLESv2 \
     libui
diff --git a/opengl/tests/gl_perfapp/Android.mk b/opengl/tests/gl_perfapp/Android.mk
index 45a5516..854b54f 100644
--- a/opengl/tests/gl_perfapp/Android.mk
+++ b/opengl/tests/gl_perfapp/Android.mk
@@ -40,6 +40,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
+	liblog \
 	libEGL \
 	libGLESv2
 
diff --git a/opengl/tests/gldual/Android.mk b/opengl/tests/gldual/Android.mk
index 42094c8..1991ed9 100644
--- a/opengl/tests/gldual/Android.mk
+++ b/opengl/tests/gldual/Android.mk
@@ -37,6 +37,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libutils \
+	liblog \
 	libEGL \
 	libGLESv2
 
diff --git a/opengl/tests/hwc/Android.mk b/opengl/tests/hwc/Android.mk
index 177eb63..2fdfcf8 100644
--- a/opengl/tests/hwc/Android.mk
+++ b/opengl/tests/hwc/Android.mk
@@ -40,6 +40,7 @@
     libEGL \
     libGLESv2 \
     libutils \
+    liblog \
     libui \
     libhardware \
 
@@ -72,6 +73,7 @@
     libEGL \
     libGLESv2 \
     libutils \
+    liblog \
     libui \
     libhardware \
 
@@ -102,6 +104,7 @@
     libEGL \
     libGLESv2 \
     libutils \
+    liblog \
     libui \
     libhardware \
 
@@ -132,6 +135,7 @@
     libEGL \
     libGLESv2 \
     libutils \
+    liblog \
     libui \
     libhardware \
 
diff --git a/opengl/tools/glgen/gen b/opengl/tools/glgen/gen
index 7cb5a2d..29212c0 100755
--- a/opengl/tools/glgen/gen
+++ b/opengl/tools/glgen/gen
@@ -63,7 +63,12 @@
 popd > /dev/null
 
 echo "Generating JSR239-like APIs"
-java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 specs/jsr239/glspec-1.0ext specs/jsr239/glspec-1.1 specs/jsr239/glspec-1.1ext specs/jsr239/glspec-1.1extpack specs/jsr239/glspec-checks
+java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 \
+                                  specs/jsr239/glspec-1.0ext \
+                                  specs/jsr239/glspec-1.1 \
+                                  specs/jsr239/glspec-1.1ext \
+                                  specs/jsr239/glspec-1.1extpack \
+                                  specs/jsr239/glspec-checks
 JAVA_RESULT=$?
 if [ $JAVA_RESULT -ne 0 ]; then
     echo "Could not run GenerateGL."
@@ -90,7 +95,19 @@
 
 pushd out > /dev/null
 mkdir classes
-javac -d classes android/opengl/EGL14.java com/google/android/gles_jni/GLImpl.java javax/microedition/khronos/opengles/GL10.java javax/microedition/khronos/opengles/GL10Ext.java javax/microedition/khronos/opengles/GL11.java javax/microedition/khronos/opengles/GL11Ext.java javax/microedition/khronos/opengles/GL11ExtensionPack.java android/opengl/GLES10.java android/opengl/GLES10Ext.java android/opengl/GLES11.java android/opengl/GLES11Ext.java android/opengl/GLES20.java
+javac -d classes    android/opengl/EGL14.java \
+                    com/google/android/gles_jni/GLImpl.java \
+                    javax/microedition/khronos/opengles/GL10.java \
+                    javax/microedition/khronos/opengles/GL10Ext.java \
+                    javax/microedition/khronos/opengles/GL11.java \
+                    javax/microedition/khronos/opengles/GL11Ext.java \
+                    javax/microedition/khronos/opengles/GL11ExtensionPack.java \
+                    android/opengl/GLES10.java \
+                    android/opengl/GLES10Ext.java \
+                    android/opengl/GLES11.java \
+                    android/opengl/GLES11Ext.java \
+                    android/opengl/GLES20.java \
+                    android/opengl/GLES30.java
 popd > /dev/null
 JAVA_RESULT=$?
 if [ $JAVA_RESULT -ne 0 ]; then
@@ -137,7 +154,7 @@
     compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x
 done
 
-for x in EGL14 GLES10 GLES10Ext GLES11 GLES11Ext GLES20
+for x in EGL14 GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30
 do
     compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
     compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp
diff --git a/opengl/tools/glgen/specs/gles11/GLES20.spec b/opengl/tools/glgen/specs/gles11/GLES20.spec
index dda746e..68d146e 100644
--- a/opengl/tools/glgen/specs/gles11/GLES20.spec
+++ b/opengl/tools/glgen/specs/gles11/GLES20.spec
@@ -1,144 +1,144 @@
-void glActiveTexture ( GLenum texture )

-void glAttachShader ( GLuint program, GLuint shader )

-void glBindAttribLocation ( GLuint program, GLuint index, const char *name )

-void glBindBuffer ( GLenum target, GLuint buffer )

-void glBindFramebuffer ( GLenum target, GLuint framebuffer )

-void glBindRenderbuffer ( GLenum target, GLuint renderbuffer )

-void glBindTexture ( GLenum target, GLuint texture )

-void glBlendColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )

-void glBlendEquation ( GLenum mode )

-void glBlendEquationSeparate ( GLenum modeRGB, GLenum modeAlpha )

-void glBlendFunc ( GLenum sfactor, GLenum dfactor )

-void glBlendFuncSeparate ( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )

-void glBufferData ( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage )

-void glBufferSubData ( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data )

-GLenum glCheckFramebufferStatus ( GLenum target )

-void glClear ( GLbitfield mask )

-void glClearColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )

-void glClearDepthf ( GLclampf depth )

-void glClearStencil ( GLint s )

-void glColorMask ( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )

-void glCompileShader ( GLuint shader )

-void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data )

-void glCompressedTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data )

-void glCopyTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )

-void glCopyTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )

-GLuint glCreateProgram ( void )

-GLuint glCreateShader ( GLenum type )

-void glCullFace ( GLenum mode )

-void glDeleteBuffers ( GLsizei n, const GLuint *buffers )

-void glDeleteFramebuffers ( GLsizei n, const GLuint *framebuffers )

-void glDeleteProgram ( GLuint program )

-void glDeleteRenderbuffers ( GLsizei n, const GLuint *renderbuffers )

-void glDeleteShader ( GLuint shader )

-void glDeleteTextures ( GLsizei n, const GLuint *textures )

-void glDepthFunc ( GLenum func )

-void glDepthMask ( GLboolean flag )

-void glDepthRangef ( GLclampf zNear, GLclampf zFar )

-void glDetachShader ( GLuint program, GLuint shader )

-void glDisable ( GLenum cap )

-void glDisableVertexAttribArray ( GLuint index )

-void glDrawArrays ( GLenum mode, GLint first, GLsizei count )

-void glDrawElements ( GLenum mode, GLsizei count, GLenum type, GLint offset )

-void glDrawElements ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )

-void glEnable ( GLenum cap )

-void glEnableVertexAttribArray ( GLuint index )

-void glFinish ( void )

-void glFlush ( void )

-void glFramebufferRenderbuffer ( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )

-void glFramebufferTexture2D ( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )

-void glFrontFace ( GLenum mode )

-void glGenBuffers ( GLsizei n, GLuint *buffers )

-void glGenerateMipmap ( GLenum target )

-void glGenFramebuffers ( GLsizei n, GLuint *framebuffers )

-void glGenRenderbuffers ( GLsizei n, GLuint *renderbuffers )

-void glGenTextures ( GLsizei n, GLuint *textures )

-void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )

-void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )

-void glGetAttachedShaders ( GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders )

-GLint glGetAttribLocation ( GLuint program, const char *name )

-void glGetBooleanv ( GLenum pname, GLboolean *params )

-void glGetBufferParameteriv ( GLenum target, GLenum pname, GLint *params )

-GLenum glGetError ( void )

-void glGetFloatv ( GLenum pname, GLfloat *params )

-void glGetFramebufferAttachmentParameteriv ( GLenum target, GLenum attachment, GLenum pname, GLint *params )

-void glGetIntegerv ( GLenum pname, GLint *params )

-void glGetProgramiv ( GLuint program, GLenum pname, GLint *params )

-void glGetProgramInfoLog ( GLuint program, GLsizei bufsize, GLsizei *length, char *infolog )

-void glGetRenderbufferParameteriv ( GLenum target, GLenum pname, GLint *params )

-void glGetShaderiv ( GLuint shader, GLenum pname, GLint *params )

-void glGetShaderInfoLog ( GLuint shader, GLsizei bufsize, GLsizei *length, char *infolog )

-void glGetShaderPrecisionFormat ( GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision )

-void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source )

-const GLubyte * glGetString ( GLenum name )

-void glGetTexParameterfv ( GLenum target, GLenum pname, GLfloat *params )

-void glGetTexParameteriv ( GLenum target, GLenum pname, GLint *params )

-void glGetUniformfv ( GLuint program, GLint location, GLfloat *params )

-void glGetUniformiv ( GLuint program, GLint location, GLint *params )

-GLint glGetUniformLocation ( GLuint program, const char *name )

-void glGetVertexAttribfv ( GLuint index, GLenum pname, GLfloat *params )

-void glGetVertexAttribiv ( GLuint index, GLenum pname, GLint *params )

-// void glGetVertexAttribPointerv ( GLuint index, GLenum pname, void **pointer )

-void glHint ( GLenum target, GLenum mode )

-GLboolean glIsBuffer ( GLuint buffer )

-GLboolean glIsEnabled ( GLenum cap )

-GLboolean glIsFramebuffer ( GLuint framebuffer )

-GLboolean glIsProgram ( GLuint program )

-GLboolean glIsRenderbuffer ( GLuint renderbuffer )

-GLboolean glIsShader ( GLuint shader )

-GLboolean glIsTexture ( GLuint texture )

-void glLineWidth ( GLfloat width )

-void glLinkProgram ( GLuint program )

-void glPixelStorei ( GLenum pname, GLint param )

-void glPolygonOffset ( GLfloat factor, GLfloat units )

-void glReadPixels ( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )

-void glReleaseShaderCompiler ( void )

-void glRenderbufferStorage ( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )

-void glSampleCoverage ( GLclampf value, GLboolean invert )

-void glScissor ( GLint x, GLint y, GLsizei width, GLsizei height )

-void glShaderBinary ( GLsizei n, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length )

-void glShaderSource ( GLuint shader )

-void glStencilFunc ( GLenum func, GLint ref, GLuint mask )

-void glStencilFuncSeparate ( GLenum face, GLenum func, GLint ref, GLuint mask )

-void glStencilMask ( GLuint mask )

-void glStencilMaskSeparate ( GLenum face, GLuint mask )

-void glStencilOp ( GLenum fail, GLenum zfail, GLenum zpass )

-void glStencilOpSeparate ( GLenum face, GLenum fail, GLenum zfail, GLenum zpass )

-void glTexImage2D ( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )

-void glTexParameterf ( GLenum target, GLenum pname, GLfloat param )

-void glTexParameterfv ( GLenum target, GLenum pname, const GLfloat *params )

-void glTexParameteri ( GLenum target, GLenum pname, GLint param )

-void glTexParameteriv ( GLenum target, GLenum pname, const GLint *params )

-void glTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )

-void glUniform1f ( GLint location, GLfloat x )

-void glUniform1fv ( GLint location, GLsizei count, const GLfloat *v )

-void glUniform1i ( GLint location, GLint x )

-void glUniform1iv ( GLint location, GLsizei count, const GLint *v )

-void glUniform2f ( GLint location, GLfloat x, GLfloat y )

-void glUniform2fv ( GLint location, GLsizei count, const GLfloat *v )

-void glUniform2i ( GLint location, GLint x, GLint y )

-void glUniform2iv ( GLint location, GLsizei count, const GLint *v )

-void glUniform3f ( GLint location, GLfloat x, GLfloat y, GLfloat z )

-void glUniform3fv ( GLint location, GLsizei count, const GLfloat *v )

-void glUniform3i ( GLint location, GLint x, GLint y, GLint z )

-void glUniform3iv ( GLint location, GLsizei count, const GLint *v )

-void glUniform4f ( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )

-void glUniform4fv ( GLint location, GLsizei count, const GLfloat *v )

-void glUniform4i ( GLint location, GLint x, GLint y, GLint z, GLint w )

-void glUniform4iv ( GLint location, GLsizei count, const GLint *v )

-void glUniformMatrix2fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )

-void glUniformMatrix3fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )

-void glUniformMatrix4fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )

-void glUseProgram ( GLuint program )

-void glValidateProgram ( GLuint program )

-void glVertexAttrib1f ( GLuint indx, GLfloat x )

-void glVertexAttrib1fv ( GLuint indx, const GLfloat *values )

-void glVertexAttrib2f ( GLuint indx, GLfloat x, GLfloat y )

-void glVertexAttrib2fv ( GLuint indx, const GLfloat *values )

-void glVertexAttrib3f ( GLuint indx, GLfloat x, GLfloat y, GLfloat z )

-void glVertexAttrib3fv ( GLuint indx, const GLfloat *values )

-void glVertexAttrib4f ( GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w )

-void glVertexAttrib4fv ( GLuint indx, const GLfloat *values )

-void glVertexAttribPointer ( GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLint offset )

-void glVertexAttribPointer ( GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *ptr )

-void glViewport ( GLint x, GLint y, GLsizei width, GLsizei height )

+void glActiveTexture ( GLenum texture )
+void glAttachShader ( GLuint program, GLuint shader )
+void glBindAttribLocation ( GLuint program, GLuint index, const char *name )
+void glBindBuffer ( GLenum target, GLuint buffer )
+void glBindFramebuffer ( GLenum target, GLuint framebuffer )
+void glBindRenderbuffer ( GLenum target, GLuint renderbuffer )
+void glBindTexture ( GLenum target, GLuint texture )
+void glBlendColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
+void glBlendEquation ( GLenum mode )
+void glBlendEquationSeparate ( GLenum modeRGB, GLenum modeAlpha )
+void glBlendFunc ( GLenum sfactor, GLenum dfactor )
+void glBlendFuncSeparate ( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
+void glBufferData ( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage )
+void glBufferSubData ( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data )
+GLenum glCheckFramebufferStatus ( GLenum target )
+void glClear ( GLbitfield mask )
+void glClearColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
+void glClearDepthf ( GLclampf depth )
+void glClearStencil ( GLint s )
+void glColorMask ( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
+void glCompileShader ( GLuint shader )
+void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data )
+void glCompressedTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data )
+void glCopyTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border )
+void glCopyTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height )
+GLuint glCreateProgram ( void )
+GLuint glCreateShader ( GLenum type )
+void glCullFace ( GLenum mode )
+void glDeleteBuffers ( GLsizei n, const GLuint *buffers )
+void glDeleteFramebuffers ( GLsizei n, const GLuint *framebuffers )
+void glDeleteProgram ( GLuint program )
+void glDeleteRenderbuffers ( GLsizei n, const GLuint *renderbuffers )
+void glDeleteShader ( GLuint shader )
+void glDeleteTextures ( GLsizei n, const GLuint *textures )
+void glDepthFunc ( GLenum func )
+void glDepthMask ( GLboolean flag )
+void glDepthRangef ( GLclampf zNear, GLclampf zFar )
+void glDetachShader ( GLuint program, GLuint shader )
+void glDisable ( GLenum cap )
+void glDisableVertexAttribArray ( GLuint index )
+void glDrawArrays ( GLenum mode, GLint first, GLsizei count )
+void glDrawElements ( GLenum mode, GLsizei count, GLenum type, GLint offset )
+void glDrawElements ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
+void glEnable ( GLenum cap )
+void glEnableVertexAttribArray ( GLuint index )
+void glFinish ( void )
+void glFlush ( void )
+void glFramebufferRenderbuffer ( GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer )
+void glFramebufferTexture2D ( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level )
+void glFrontFace ( GLenum mode )
+void glGenBuffers ( GLsizei n, GLuint *buffers )
+void glGenerateMipmap ( GLenum target )
+void glGenFramebuffers ( GLsizei n, GLuint *framebuffers )
+void glGenRenderbuffers ( GLsizei n, GLuint *renderbuffers )
+void glGenTextures ( GLsizei n, GLuint *textures )
+void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
+void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
+void glGetAttachedShaders ( GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders )
+GLint glGetAttribLocation ( GLuint program, const char *name )
+void glGetBooleanv ( GLenum pname, GLboolean *params )
+void glGetBufferParameteriv ( GLenum target, GLenum pname, GLint *params )
+GLenum glGetError ( void )
+void glGetFloatv ( GLenum pname, GLfloat *params )
+void glGetFramebufferAttachmentParameteriv ( GLenum target, GLenum attachment, GLenum pname, GLint *params )
+void glGetIntegerv ( GLenum pname, GLint *params )
+void glGetProgramiv ( GLuint program, GLenum pname, GLint *params )
+void glGetProgramInfoLog ( GLuint program, GLsizei bufsize, GLsizei *length, char *infolog )
+void glGetRenderbufferParameteriv ( GLenum target, GLenum pname, GLint *params )
+void glGetShaderiv ( GLuint shader, GLenum pname, GLint *params )
+void glGetShaderInfoLog ( GLuint shader, GLsizei bufsize, GLsizei *length, char *infolog )
+void glGetShaderPrecisionFormat ( GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision )
+void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source )
+const GLubyte * glGetString ( GLenum name )
+void glGetTexParameterfv ( GLenum target, GLenum pname, GLfloat *params )
+void glGetTexParameteriv ( GLenum target, GLenum pname, GLint *params )
+void glGetUniformfv ( GLuint program, GLint location, GLfloat *params )
+void glGetUniformiv ( GLuint program, GLint location, GLint *params )
+GLint glGetUniformLocation ( GLuint program, const char *name )
+void glGetVertexAttribfv ( GLuint index, GLenum pname, GLfloat *params )
+void glGetVertexAttribiv ( GLuint index, GLenum pname, GLint *params )
+// void glGetVertexAttribPointerv ( GLuint index, GLenum pname, void **pointer )
+void glHint ( GLenum target, GLenum mode )
+GLboolean glIsBuffer ( GLuint buffer )
+GLboolean glIsEnabled ( GLenum cap )
+GLboolean glIsFramebuffer ( GLuint framebuffer )
+GLboolean glIsProgram ( GLuint program )
+GLboolean glIsRenderbuffer ( GLuint renderbuffer )
+GLboolean glIsShader ( GLuint shader )
+GLboolean glIsTexture ( GLuint texture )
+void glLineWidth ( GLfloat width )
+void glLinkProgram ( GLuint program )
+void glPixelStorei ( GLenum pname, GLint param )
+void glPolygonOffset ( GLfloat factor, GLfloat units )
+void glReadPixels ( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
+void glReleaseShaderCompiler ( void )
+void glRenderbufferStorage ( GLenum target, GLenum internalformat, GLsizei width, GLsizei height )
+void glSampleCoverage ( GLclampf value, GLboolean invert )
+void glScissor ( GLint x, GLint y, GLsizei width, GLsizei height )
+void glShaderBinary ( GLsizei n, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length )
+void glShaderSource ( GLuint shader )
+void glStencilFunc ( GLenum func, GLint ref, GLuint mask )
+void glStencilFuncSeparate ( GLenum face, GLenum func, GLint ref, GLuint mask )
+void glStencilMask ( GLuint mask )
+void glStencilMaskSeparate ( GLenum face, GLuint mask )
+void glStencilOp ( GLenum fail, GLenum zfail, GLenum zpass )
+void glStencilOpSeparate ( GLenum face, GLenum fail, GLenum zfail, GLenum zpass )
+void glTexImage2D ( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
+void glTexParameterf ( GLenum target, GLenum pname, GLfloat param )
+void glTexParameterfv ( GLenum target, GLenum pname, const GLfloat *params )
+void glTexParameteri ( GLenum target, GLenum pname, GLint param )
+void glTexParameteriv ( GLenum target, GLenum pname, const GLint *params )
+void glTexSubImage2D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
+void glUniform1f ( GLint location, GLfloat x )
+void glUniform1fv ( GLint location, GLsizei count, const GLfloat *v )
+void glUniform1i ( GLint location, GLint x )
+void glUniform1iv ( GLint location, GLsizei count, const GLint *v )
+void glUniform2f ( GLint location, GLfloat x, GLfloat y )
+void glUniform2fv ( GLint location, GLsizei count, const GLfloat *v )
+void glUniform2i ( GLint location, GLint x, GLint y )
+void glUniform2iv ( GLint location, GLsizei count, const GLint *v )
+void glUniform3f ( GLint location, GLfloat x, GLfloat y, GLfloat z )
+void glUniform3fv ( GLint location, GLsizei count, const GLfloat *v )
+void glUniform3i ( GLint location, GLint x, GLint y, GLint z )
+void glUniform3iv ( GLint location, GLsizei count, const GLint *v )
+void glUniform4f ( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
+void glUniform4fv ( GLint location, GLsizei count, const GLfloat *v )
+void glUniform4i ( GLint location, GLint x, GLint y, GLint z, GLint w )
+void glUniform4iv ( GLint location, GLsizei count, const GLint *v )
+void glUniformMatrix2fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix3fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix4fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUseProgram ( GLuint program )
+void glValidateProgram ( GLuint program )
+void glVertexAttrib1f ( GLuint indx, GLfloat x )
+void glVertexAttrib1fv ( GLuint indx, const GLfloat *values )
+void glVertexAttrib2f ( GLuint indx, GLfloat x, GLfloat y )
+void glVertexAttrib2fv ( GLuint indx, const GLfloat *values )
+void glVertexAttrib3f ( GLuint indx, GLfloat x, GLfloat y, GLfloat z )
+void glVertexAttrib3fv ( GLuint indx, const GLfloat *values )
+void glVertexAttrib4f ( GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
+void glVertexAttrib4fv ( GLuint indx, const GLfloat *values )
+void glVertexAttribPointer ( GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLint offset )
+void glVertexAttribPointer ( GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *ptr )
+void glViewport ( GLint x, GLint y, GLsizei width, GLsizei height )
diff --git a/opengl/tools/glgen/specs/gles11/GLES30.spec b/opengl/tools/glgen/specs/gles11/GLES30.spec
new file mode 100644
index 0000000..a426eb0
--- /dev/null
+++ b/opengl/tools/glgen/specs/gles11/GLES30.spec
@@ -0,0 +1,110 @@
+void glReadBuffer ( GLenum mode )
+void glDrawRangeElements ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
+void glDrawRangeElements ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, GLsizei offset )
+void glTexImage3D ( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
+void glTexImage3D ( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, GLsizei offset )
+void glTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels )
+void glTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei offset )
+void glCopyTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height )
+void glCompressedTexImage3D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data )
+void glCompressedTexImage3D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, GLsizei offset )
+void glCompressedTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data )
+void glCompressedTexSubImage3D ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, GLsizei offset )
+void glGenQueries ( GLsizei n, GLuint *ids )
+void glDeleteQueries ( GLsizei n, const GLuint *ids )
+GLboolean glIsQuery ( GLuint id )
+void glBeginQuery ( GLenum target, GLuint id )
+void glEndQuery ( GLenum target )
+void glGetQueryiv ( GLenum target, GLenum pname, GLint *params )
+void glGetQueryObjectuiv ( GLuint id, GLenum pname, GLuint *params )
+GLboolean glUnmapBuffer ( GLenum target )
+void glGetBufferPointerv ( GLenum target, GLenum pname, GLvoid **params )
+void glDrawBuffers ( GLsizei n, const GLenum *bufs )
+void glUniformMatrix2x3fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix3x2fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix2x4fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix4x2fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix3x4fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glUniformMatrix4x3fv ( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value )
+void glBlitFramebuffer ( GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter )
+void glRenderbufferStorageMultisample ( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height )
+void glFramebufferTextureLayer ( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer )
+GLvoid * glMapBufferRange ( GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access )
+void glFlushMappedBufferRange ( GLenum target, GLintptr offset, GLsizeiptr length )
+void glBindVertexArray ( GLuint array )
+void glDeleteVertexArrays ( GLsizei n, const GLuint *arrays )
+void glGenVertexArrays ( GLsizei n, GLuint *arrays )
+GLboolean glIsVertexArray ( GLuint array )
+void glGetIntegeri_v ( GLenum target, GLuint index, GLint *data )
+void glBeginTransformFeedback ( GLenum primitiveMode )
+void glEndTransformFeedback ( void )
+void glBindBufferRange ( GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size )
+void glBindBufferBase ( GLenum target, GLuint index, GLuint buffer )
+void glTransformFeedbackVaryings ( GLuint program, GLsizei count, const GLchar *varyings, GLenum bufferMode )
+void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name )
+void glVertexAttribIPointer ( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
+void glVertexAttribIPointer ( GLuint index, GLint size, GLenum type, GLsizei stride, GLsizei offset )
+void glGetVertexAttribIiv ( GLuint index, GLenum pname, GLint *params )
+void glGetVertexAttribIuiv ( GLuint index, GLenum pname, GLuint *params )
+void glVertexAttribI4i ( GLuint index, GLint x, GLint y, GLint z, GLint w )
+void glVertexAttribI4ui ( GLuint index, GLuint x, GLuint y, GLuint z, GLuint w )
+void glVertexAttribI4iv ( GLuint index, const GLint *v )
+void glVertexAttribI4uiv ( GLuint index, const GLuint *v )
+void glGetUniformuiv ( GLuint program, GLint location, GLuint *params )
+GLint glGetFragDataLocation ( GLuint program, const GLchar *name )
+void glUniform1ui ( GLint location, GLuint v0 )
+void glUniform2ui ( GLint location, GLuint v0, GLuint v1 )
+void glUniform3ui ( GLint location, GLuint v0, GLuint v1, GLuint v2 )
+void glUniform4ui ( GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3 )
+void glUniform1uiv ( GLint location, GLsizei count, const GLuint *value )
+void glUniform2uiv ( GLint location, GLsizei count, const GLuint *value )
+void glUniform3uiv ( GLint location, GLsizei count, const GLuint *value )
+void glUniform4uiv ( GLint location, GLsizei count, const GLuint *value )
+void glClearBufferiv ( GLenum buffer, GLint drawbuffer, const GLint *value )
+void glClearBufferuiv ( GLenum buffer, GLint drawbuffer, const GLuint *value )
+void glClearBufferfv ( GLenum buffer, GLint drawbuffer, const GLfloat *value )
+void glClearBufferfi ( GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil )
+const GLubyte * glGetStringi ( GLenum name, GLuint index )
+void glCopyBufferSubData ( GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size )
+void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices )
+void glGetActiveUniformsiv ( GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params )
+GLuint glGetUniformBlockIndex ( GLuint program, const GLchar *uniformBlockName )
+void glGetActiveUniformBlockiv ( GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params )
+void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName )
+void glUniformBlockBinding ( GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding )
+void glDrawArraysInstanced ( GLenum mode, GLint first, GLsizei count, GLsizei instanceCount )
+void glDrawElementsInstanced ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount )
+GLsync glFenceSync ( GLenum condition, GLbitfield flags )
+GLboolean glIsSync ( GLsync sync )
+void glDeleteSync ( GLsync sync )
+GLenum glClientWaitSync ( GLsync sync, GLbitfield flags, GLuint64 timeout )
+void glWaitSync ( GLsync sync, GLbitfield flags, GLuint64 timeout )
+void glGetInteger64v ( GLenum pname, GLint64 *params )
+void glGetSynciv ( GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values )
+void glGetInteger64i_v ( GLenum target, GLuint index, GLint64 *data )
+void glGetBufferParameteri64v ( GLenum target, GLenum pname, GLint64 *params )
+void glGenSamplers ( GLsizei count, GLuint *samplers )
+void glDeleteSamplers ( GLsizei count, const GLuint *samplers )
+GLboolean glIsSampler ( GLuint sampler )
+void glBindSampler ( GLuint unit, GLuint sampler )
+void glSamplerParameteri ( GLuint sampler, GLenum pname, GLint param )
+void glSamplerParameteriv ( GLuint sampler, GLenum pname, const GLint *param )
+void glSamplerParameterf ( GLuint sampler, GLenum pname, GLfloat param )
+void glSamplerParameterfv ( GLuint sampler, GLenum pname, const GLfloat *param )
+void glGetSamplerParameteriv ( GLuint sampler, GLenum pname, GLint *params )
+void glGetSamplerParameterfv ( GLuint sampler, GLenum pname, GLfloat *params )
+void glVertexAttribDivisor ( GLuint index, GLuint divisor )
+void glBindTransformFeedback ( GLenum target, GLuint id )
+void glDeleteTransformFeedbacks ( GLsizei n, const GLuint *ids )
+void glGenTransformFeedbacks ( GLsizei n, GLuint *ids )
+GLboolean glIsTransformFeedback ( GLuint id )
+void glPauseTransformFeedback ( void )
+void glResumeTransformFeedback ( void )
+void glGetProgramBinary ( GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary )
+void glProgramBinary ( GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length )
+void glProgramParameteri ( GLuint program, GLenum pname, GLint value )
+void glInvalidateFramebuffer ( GLenum target, GLsizei numAttachments, const GLenum *attachments )
+void glInvalidateSubFramebuffer ( GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height )
+void glTexStorage2D ( GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height )
+void glTexStorage3D ( GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth )
+void glGetInternalformativ ( GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params )
diff --git a/opengl/tools/glgen/src/CType.java b/opengl/tools/glgen/src/CType.java
index 92950ea..aba98af 100644
--- a/opengl/tools/glgen/src/CType.java
+++ b/opengl/tools/glgen/src/CType.java
@@ -70,7 +70,8 @@
     }
 
     public boolean isConstCharPointer() {
-        return isConst && isPointer && baseType.equals("char");
+        return isConst && isPointer &&
+            (baseType.equals("char") || baseType.equals("GLchar"));
     }
 
     public boolean isTypedPointer() {
diff --git a/opengl/tools/glgen/src/GenerateGLES.java b/opengl/tools/glgen/src/GenerateGLES.java
index 6f9da5d..c99c45d 100644
--- a/opengl/tools/glgen/src/GenerateGLES.java
+++ b/opengl/tools/glgen/src/GenerateGLES.java
@@ -84,7 +84,7 @@
 
         // Generate files
         for(String suffix: new String[] {"GLES10", "GLES10Ext",
-                "GLES11", "GLES11Ext", "GLES20"})
+                "GLES11", "GLES11Ext", "GLES20", "GLES30"})
         {
             BufferedReader spec11Reader =
                 new BufferedReader(new FileReader("specs/gles11/"
diff --git a/opengl/tools/glgen/src/JType.java b/opengl/tools/glgen/src/JType.java
index 994e609..b10e7e2 100644
--- a/opengl/tools/glgen/src/JType.java
+++ b/opengl/tools/glgen/src/JType.java
@@ -46,7 +46,10 @@
     typeMapping.put(new CType("GLubyte", true, true), new JType("String", false, false));
     typeMapping.put(new CType("char", false, true), new JType("byte"));
     typeMapping.put(new CType("char", true, true), new JType("String", false, false));
+    typeMapping.put(new CType("GLchar", true, true), new JType("String", false, false));
     typeMapping.put(new CType("int"), new JType("int"));
+    typeMapping.put(new CType("GLuint64"), new JType("long"));
+    typeMapping.put(new CType("GLsync"), new JType("long"));
 
     // EGL primitive types
     typeMapping.put(new CType("EGLint"), new JType("int"));
@@ -80,6 +83,8 @@
             new JType("java.nio.IntBuffer", true, false));
     typeMapping.put(new CType("GLenum", false, true),
             new JType("java.nio.IntBuffer", true, false));
+    typeMapping.put(new CType("GLenum", true, true),
+            new JType("java.nio.IntBuffer", true, false));
     typeMapping.put(new CType("GLfixed", false, true),
             new JType("java.nio.IntBuffer", true, false));
     typeMapping.put(new CType("GLfixed", true, true),
@@ -100,6 +105,8 @@
             new JType("java.nio.IntBuffer", true, false));
     typeMapping.put(new CType("GLshort", true, true),
             new JType("java.nio.ShortBuffer", true, false));
+    typeMapping.put(new CType("GLint64", false, true),
+            new JType("java.nio.LongBuffer", true, false));
 
     // Typed pointers map to arrays + offsets
     arrayTypeMapping.put(new CType("char", false, true),
@@ -107,6 +114,7 @@
     arrayTypeMapping.put(new CType("GLboolean", false, true),
             new JType("boolean", false, true));
     arrayTypeMapping.put(new CType("GLenum", false, true), new JType("int", false, true));
+    arrayTypeMapping.put(new CType("GLenum", true, true), new JType("int", false, true));
     arrayTypeMapping.put(new CType("GLfixed", true, true), new JType("int", false, true));
     arrayTypeMapping.put(new CType("GLfixed", false, true), new JType("int", false, true));
     arrayTypeMapping.put(new CType("GLfloat", false, true), new JType("float", false, true));
@@ -120,6 +128,7 @@
     arrayTypeMapping.put(new CType("GLuint", true, true), new JType("int", false, true));
     arrayTypeMapping.put(new CType("GLintptr"), new JType("int", false, true));
     arrayTypeMapping.put(new CType("GLsizeiptr"), new JType("int", false, true));
+    arrayTypeMapping.put(new CType("GLint64", false, true), new JType("long", false, true));
 
     //EGL typed pointers map to arrays + offsets
     arrayTypeMapping.put(new CType("EGLint", false, true), new JType("int", false, true));
diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java
index ffe3767..d5e2d34 100644
--- a/opengl/tools/glgen/src/JniCodeEmitter.java
+++ b/opengl/tools/glgen/src/JniCodeEmitter.java
@@ -749,10 +749,20 @@
 
         String outName = "android_" + jfunc.getName();
         boolean isPointerFunc = isPointerFunc(jfunc);
-        boolean isVBOPointerFunc = (outName.endsWith("Pointer") ||
-                outName.endsWith("PointerOES") ||
-            outName.endsWith("DrawElements") || outName.endsWith("VertexAttribPointer")) &&
-            !jfunc.getCFunc().hasPointerArg();
+        boolean isPointerOffsetFunc =
+            (outName.endsWith("Pointer") || outName.endsWith("PointerOES") ||
+             outName.endsWith("glDrawElements") ||
+             outName.endsWith("glDrawRangeElements") ||
+             outName.endsWith("glTexImage2D") ||
+             outName.endsWith("glTexSubImage2D") ||
+             outName.endsWith("glCompressedTexImage2D") ||
+             outName.endsWith("glCompressedTexSubImage2D") ||
+             outName.endsWith("glTexImage3D") ||
+             outName.endsWith("glTexSubImage3D") ||
+             outName.endsWith("glCompressedTexImage3D") ||
+             outName.endsWith("glCompressedTexSubImage3D") ||
+             outName.endsWith("glReadPixels"))
+            && !jfunc.getCFunc().hasPointerArg();
         if (isPointerFunc) {
             outName += "Bounds";
         }
@@ -1271,8 +1281,8 @@
             }
             for (int i = 0; i < numArgs; i++) {
                 String typecast;
-                if (i == numArgs - 1 && isVBOPointerFunc) {
-                    typecast = "(const GLvoid *)";
+                if (i == numArgs - 1 && isPointerOffsetFunc) {
+                    typecast = "(GLvoid *)";
                 } else {
                     typecast = "(" + cfunc.getArgType(i).getDeclaration() + ")";
                 }
@@ -1421,7 +1431,8 @@
                             "return toEGLHandle(_env, " + baseType + "Class, " +
                             baseType + "Constructor, _returnValue);");
             } else {
-                out.println(indent + "return _returnValue;");
+                out.println(indent + "return (" +
+                            getJniType(jfunc.getType()) + ")_returnValue;");
             }
         }
 
diff --git a/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if b/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if
index 7a7dccd..9ce6728 100644
--- a/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if
+++ b/opengl/tools/glgen/stubs/gles11/GLES20Header.java-if
@@ -296,6 +296,10 @@
     public static final int GL_RGB5_A1                                 = 0x8057;
     public static final int GL_RGB565                                  = 0x8D62;
     public static final int GL_DEPTH_COMPONENT16                       = 0x81A5;
+    // GL_STENCIL_INDEX does not appear in gl2.h or gl2ext.h, and there is no
+    // token with value 0x1901.
+    //
+    @Deprecated
     public static final int GL_STENCIL_INDEX                           = 0x1901;
     public static final int GL_STENCIL_INDEX8                          = 0x8D48;
     public static final int GL_RENDERBUFFER_WIDTH                      = 0x8D42;
@@ -327,5 +331,5 @@
 
     native private static void _nativeClassInit();
     static {
-	    _nativeClassInit();
+        _nativeClassInit();
     }
diff --git a/opengl/tools/glgen/stubs/gles11/GLES30Header.java-if b/opengl/tools/glgen/stubs/gles11/GLES30Header.java-if
new file mode 100644
index 0000000..747dbd3
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/GLES30Header.java-if
@@ -0,0 +1,337 @@
+/*
+**
+** Copyright 2013, 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.
+*/
+
+// This source file is automatically generated
+
+package android.opengl;
+
+/** OpenGL ES 3.0
+ */
+public class GLES30 extends GLES20 {
+    public static final int GL_READ_BUFFER                             = 0x0C02;
+    public static final int GL_UNPACK_ROW_LENGTH                       = 0x0CF2;
+    public static final int GL_UNPACK_SKIP_ROWS                        = 0x0CF3;
+    public static final int GL_UNPACK_SKIP_PIXELS                      = 0x0CF4;
+    public static final int GL_PACK_ROW_LENGTH                         = 0x0D02;
+    public static final int GL_PACK_SKIP_ROWS                          = 0x0D03;
+    public static final int GL_PACK_SKIP_PIXELS                        = 0x0D04;
+    public static final int GL_COLOR                                   = 0x1800;
+    public static final int GL_DEPTH                                   = 0x1801;
+    public static final int GL_STENCIL                                 = 0x1802;
+    public static final int GL_RED                                     = 0x1903;
+    public static final int GL_RGB8                                    = 0x8051;
+    public static final int GL_RGBA8                                   = 0x8058;
+    public static final int GL_RGB10_A2                                = 0x8059;
+    public static final int GL_TEXTURE_BINDING_3D                      = 0x806A;
+    public static final int GL_UNPACK_SKIP_IMAGES                      = 0x806D;
+    public static final int GL_UNPACK_IMAGE_HEIGHT                     = 0x806E;
+    public static final int GL_TEXTURE_3D                              = 0x806F;
+    public static final int GL_TEXTURE_WRAP_R                          = 0x8072;
+    public static final int GL_MAX_3D_TEXTURE_SIZE                     = 0x8073;
+    public static final int GL_UNSIGNED_INT_2_10_10_10_REV             = 0x8368;
+    public static final int GL_MAX_ELEMENTS_VERTICES                   = 0x80E8;
+    public static final int GL_MAX_ELEMENTS_INDICES                    = 0x80E9;
+    public static final int GL_TEXTURE_MIN_LOD                         = 0x813A;
+    public static final int GL_TEXTURE_MAX_LOD                         = 0x813B;
+    public static final int GL_TEXTURE_BASE_LEVEL                      = 0x813C;
+    public static final int GL_TEXTURE_MAX_LEVEL                       = 0x813D;
+    public static final int GL_MIN                                     = 0x8007;
+    public static final int GL_MAX                                     = 0x8008;
+    public static final int GL_DEPTH_COMPONENT24                       = 0x81A6;
+    public static final int GL_MAX_TEXTURE_LOD_BIAS                    = 0x84FD;
+    public static final int GL_TEXTURE_COMPARE_MODE                    = 0x884C;
+    public static final int GL_TEXTURE_COMPARE_FUNC                    = 0x884D;
+    public static final int GL_CURRENT_QUERY                           = 0x8865;
+    public static final int GL_QUERY_RESULT                            = 0x8866;
+    public static final int GL_QUERY_RESULT_AVAILABLE                  = 0x8867;
+    public static final int GL_BUFFER_MAPPED                           = 0x88BC;
+    public static final int GL_BUFFER_MAP_POINTER                      = 0x88BD;
+    public static final int GL_STREAM_READ                             = 0x88E1;
+    public static final int GL_STREAM_COPY                             = 0x88E2;
+    public static final int GL_STATIC_READ                             = 0x88E5;
+    public static final int GL_STATIC_COPY                             = 0x88E6;
+    public static final int GL_DYNAMIC_READ                            = 0x88E9;
+    public static final int GL_DYNAMIC_COPY                            = 0x88EA;
+    public static final int GL_MAX_DRAW_BUFFERS                        = 0x8824;
+    public static final int GL_DRAW_BUFFER0                            = 0x8825;
+    public static final int GL_DRAW_BUFFER1                            = 0x8826;
+    public static final int GL_DRAW_BUFFER2                            = 0x8827;
+    public static final int GL_DRAW_BUFFER3                            = 0x8828;
+    public static final int GL_DRAW_BUFFER4                            = 0x8829;
+    public static final int GL_DRAW_BUFFER5                            = 0x882A;
+    public static final int GL_DRAW_BUFFER6                            = 0x882B;
+    public static final int GL_DRAW_BUFFER7                            = 0x882C;
+    public static final int GL_DRAW_BUFFER8                            = 0x882D;
+    public static final int GL_DRAW_BUFFER9                            = 0x882E;
+    public static final int GL_DRAW_BUFFER10                           = 0x882F;
+    public static final int GL_DRAW_BUFFER11                           = 0x8830;
+    public static final int GL_DRAW_BUFFER12                           = 0x8831;
+    public static final int GL_DRAW_BUFFER13                           = 0x8832;
+    public static final int GL_DRAW_BUFFER14                           = 0x8833;
+    public static final int GL_DRAW_BUFFER15                           = 0x8834;
+    public static final int GL_MAX_FRAGMENT_UNIFORM_COMPONENTS         = 0x8B49;
+    public static final int GL_MAX_VERTEX_UNIFORM_COMPONENTS           = 0x8B4A;
+    public static final int GL_SAMPLER_3D                              = 0x8B5F;
+    public static final int GL_SAMPLER_2D_SHADOW                       = 0x8B62;
+    public static final int GL_FRAGMENT_SHADER_DERIVATIVE_HINT         = 0x8B8B;
+    public static final int GL_PIXEL_PACK_BUFFER                       = 0x88EB;
+    public static final int GL_PIXEL_UNPACK_BUFFER                     = 0x88EC;
+    public static final int GL_PIXEL_PACK_BUFFER_BINDING               = 0x88ED;
+    public static final int GL_PIXEL_UNPACK_BUFFER_BINDING             = 0x88EF;
+    public static final int GL_FLOAT_MAT2x3                            = 0x8B65;
+    public static final int GL_FLOAT_MAT2x4                            = 0x8B66;
+    public static final int GL_FLOAT_MAT3x2                            = 0x8B67;
+    public static final int GL_FLOAT_MAT3x4                            = 0x8B68;
+    public static final int GL_FLOAT_MAT4x2                            = 0x8B69;
+    public static final int GL_FLOAT_MAT4x3                            = 0x8B6A;
+    public static final int GL_SRGB                                    = 0x8C40;
+    public static final int GL_SRGB8                                   = 0x8C41;
+    public static final int GL_SRGB8_ALPHA8                            = 0x8C43;
+    public static final int GL_COMPARE_REF_TO_TEXTURE                  = 0x884E;
+    public static final int GL_MAJOR_VERSION                           = 0x821B;
+    public static final int GL_MINOR_VERSION                           = 0x821C;
+    public static final int GL_NUM_EXTENSIONS                          = 0x821D;
+    public static final int GL_RGBA32F                                 = 0x8814;
+    public static final int GL_RGB32F                                  = 0x8815;
+    public static final int GL_RGBA16F                                 = 0x881A;
+    public static final int GL_RGB16F                                  = 0x881B;
+    public static final int GL_VERTEX_ATTRIB_ARRAY_INTEGER             = 0x88FD;
+    public static final int GL_MAX_ARRAY_TEXTURE_LAYERS                = 0x88FF;
+    public static final int GL_MIN_PROGRAM_TEXEL_OFFSET                = 0x8904;
+    public static final int GL_MAX_PROGRAM_TEXEL_OFFSET                = 0x8905;
+    public static final int GL_MAX_VARYING_COMPONENTS                  = 0x8B4B;
+    public static final int GL_TEXTURE_2D_ARRAY                        = 0x8C1A;
+    public static final int GL_TEXTURE_BINDING_2D_ARRAY                = 0x8C1D;
+    public static final int GL_R11F_G11F_B10F                          = 0x8C3A;
+    public static final int GL_UNSIGNED_INT_10F_11F_11F_REV            = 0x8C3B;
+    public static final int GL_RGB9_E5                                 = 0x8C3D;
+    public static final int GL_UNSIGNED_INT_5_9_9_9_REV                = 0x8C3E;
+    public static final int GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH   = 0x8C76;
+    public static final int GL_TRANSFORM_FEEDBACK_BUFFER_MODE          = 0x8C7F;
+    public static final int GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS   = 0x8C80;
+    public static final int GL_TRANSFORM_FEEDBACK_VARYINGS             = 0x8C83;
+    public static final int GL_TRANSFORM_FEEDBACK_BUFFER_START         = 0x8C84;
+    public static final int GL_TRANSFORM_FEEDBACK_BUFFER_SIZE          = 0x8C85;
+    public static final int GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN   = 0x8C88;
+    public static final int GL_RASTERIZER_DISCARD                      = 0x8C89;
+    public static final int GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS    = 0x8C8A;
+    public static final int GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B;
+    public static final int GL_INTERLEAVED_ATTRIBS                     = 0x8C8C;
+    public static final int GL_SEPARATE_ATTRIBS                        = 0x8C8D;
+    public static final int GL_TRANSFORM_FEEDBACK_BUFFER               = 0x8C8E;
+    public static final int GL_TRANSFORM_FEEDBACK_BUFFER_BINDING       = 0x8C8F;
+    public static final int GL_RGBA32UI                                = 0x8D70;
+    public static final int GL_RGB32UI                                 = 0x8D71;
+    public static final int GL_RGBA16UI                                = 0x8D76;
+    public static final int GL_RGB16UI                                 = 0x8D77;
+    public static final int GL_RGBA8UI                                 = 0x8D7C;
+    public static final int GL_RGB8UI                                  = 0x8D7D;
+    public static final int GL_RGBA32I                                 = 0x8D82;
+    public static final int GL_RGB32I                                  = 0x8D83;
+    public static final int GL_RGBA16I                                 = 0x8D88;
+    public static final int GL_RGB16I                                  = 0x8D89;
+    public static final int GL_RGBA8I                                  = 0x8D8E;
+    public static final int GL_RGB8I                                   = 0x8D8F;
+    public static final int GL_RED_INTEGER                             = 0x8D94;
+    public static final int GL_RGB_INTEGER                             = 0x8D98;
+    public static final int GL_RGBA_INTEGER                            = 0x8D99;
+    public static final int GL_SAMPLER_2D_ARRAY                        = 0x8DC1;
+    public static final int GL_SAMPLER_2D_ARRAY_SHADOW                 = 0x8DC4;
+    public static final int GL_SAMPLER_CUBE_SHADOW                     = 0x8DC5;
+    public static final int GL_UNSIGNED_INT_VEC2                       = 0x8DC6;
+    public static final int GL_UNSIGNED_INT_VEC3                       = 0x8DC7;
+    public static final int GL_UNSIGNED_INT_VEC4                       = 0x8DC8;
+    public static final int GL_INT_SAMPLER_2D                          = 0x8DCA;
+    public static final int GL_INT_SAMPLER_3D                          = 0x8DCB;
+    public static final int GL_INT_SAMPLER_CUBE                        = 0x8DCC;
+    public static final int GL_INT_SAMPLER_2D_ARRAY                    = 0x8DCF;
+    public static final int GL_UNSIGNED_INT_SAMPLER_2D                 = 0x8DD2;
+    public static final int GL_UNSIGNED_INT_SAMPLER_3D                 = 0x8DD3;
+    public static final int GL_UNSIGNED_INT_SAMPLER_CUBE               = 0x8DD4;
+    public static final int GL_UNSIGNED_INT_SAMPLER_2D_ARRAY           = 0x8DD7;
+    public static final int GL_BUFFER_ACCESS_FLAGS                     = 0x911F;
+    public static final int GL_BUFFER_MAP_LENGTH                       = 0x9120;
+    public static final int GL_BUFFER_MAP_OFFSET                       = 0x9121;
+    public static final int GL_DEPTH_COMPONENT32F                      = 0x8CAC;
+    public static final int GL_DEPTH32F_STENCIL8                       = 0x8CAD;
+    public static final int GL_FLOAT_32_UNSIGNED_INT_24_8_REV          = 0x8DAD;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING   = 0x8210;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE   = 0x8211;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE         = 0x8212;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE       = 0x8213;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE        = 0x8214;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE       = 0x8215;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE       = 0x8216;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE     = 0x8217;
+    public static final int GL_FRAMEBUFFER_DEFAULT                     = 0x8218;
+    public static final int GL_FRAMEBUFFER_UNDEFINED                   = 0x8219;
+    public static final int GL_DEPTH_STENCIL_ATTACHMENT                = 0x821A;
+    public static final int GL_DEPTH_STENCIL                           = 0x84F9;
+    public static final int GL_UNSIGNED_INT_24_8                       = 0x84FA;
+    public static final int GL_DEPTH24_STENCIL8                        = 0x88F0;
+    public static final int GL_UNSIGNED_NORMALIZED                     = 0x8C17;
+    public static final int GL_DRAW_FRAMEBUFFER_BINDING                = GL_FRAMEBUFFER_BINDING;
+    public static final int GL_READ_FRAMEBUFFER                        = 0x8CA8;
+    public static final int GL_DRAW_FRAMEBUFFER                        = 0x8CA9;
+    public static final int GL_READ_FRAMEBUFFER_BINDING                = 0x8CAA;
+    public static final int GL_RENDERBUFFER_SAMPLES                    = 0x8CAB;
+    public static final int GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER    = 0x8CD4;
+    public static final int GL_MAX_COLOR_ATTACHMENTS                   = 0x8CDF;
+    public static final int GL_COLOR_ATTACHMENT1                       = 0x8CE1;
+    public static final int GL_COLOR_ATTACHMENT2                       = 0x8CE2;
+    public static final int GL_COLOR_ATTACHMENT3                       = 0x8CE3;
+    public static final int GL_COLOR_ATTACHMENT4                       = 0x8CE4;
+    public static final int GL_COLOR_ATTACHMENT5                       = 0x8CE5;
+    public static final int GL_COLOR_ATTACHMENT6                       = 0x8CE6;
+    public static final int GL_COLOR_ATTACHMENT7                       = 0x8CE7;
+    public static final int GL_COLOR_ATTACHMENT8                       = 0x8CE8;
+    public static final int GL_COLOR_ATTACHMENT9                       = 0x8CE9;
+    public static final int GL_COLOR_ATTACHMENT10                      = 0x8CEA;
+    public static final int GL_COLOR_ATTACHMENT11                      = 0x8CEB;
+    public static final int GL_COLOR_ATTACHMENT12                      = 0x8CEC;
+    public static final int GL_COLOR_ATTACHMENT13                      = 0x8CED;
+    public static final int GL_COLOR_ATTACHMENT14                      = 0x8CEE;
+    public static final int GL_COLOR_ATTACHMENT15                      = 0x8CEF;
+    public static final int GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE      = 0x8D56;
+    public static final int GL_MAX_SAMPLES                             = 0x8D57;
+    public static final int GL_HALF_FLOAT                              = 0x140B;
+    public static final int GL_MAP_READ_BIT                            = 0x0001;
+    public static final int GL_MAP_WRITE_BIT                           = 0x0002;
+    public static final int GL_MAP_INVALIDATE_RANGE_BIT                = 0x0004;
+    public static final int GL_MAP_INVALIDATE_BUFFER_BIT               = 0x0008;
+    public static final int GL_MAP_FLUSH_EXPLICIT_BIT                  = 0x0010;
+    public static final int GL_MAP_UNSYNCHRONIZED_BIT                  = 0x0020;
+    public static final int GL_RG                                      = 0x8227;
+    public static final int GL_RG_INTEGER                              = 0x8228;
+    public static final int GL_R8                                      = 0x8229;
+    public static final int GL_RG8                                     = 0x822B;
+    public static final int GL_R16F                                    = 0x822D;
+    public static final int GL_R32F                                    = 0x822E;
+    public static final int GL_RG16F                                   = 0x822F;
+    public static final int GL_RG32F                                   = 0x8230;
+    public static final int GL_R8I                                     = 0x8231;
+    public static final int GL_R8UI                                    = 0x8232;
+    public static final int GL_R16I                                    = 0x8233;
+    public static final int GL_R16UI                                   = 0x8234;
+    public static final int GL_R32I                                    = 0x8235;
+    public static final int GL_R32UI                                   = 0x8236;
+    public static final int GL_RG8I                                    = 0x8237;
+    public static final int GL_RG8UI                                   = 0x8238;
+    public static final int GL_RG16I                                   = 0x8239;
+    public static final int GL_RG16UI                                  = 0x823A;
+    public static final int GL_RG32I                                   = 0x823B;
+    public static final int GL_RG32UI                                  = 0x823C;
+    public static final int GL_VERTEX_ARRAY_BINDING                    = 0x85B5;
+    public static final int GL_R8_SNORM                                = 0x8F94;
+    public static final int GL_RG8_SNORM                               = 0x8F95;
+    public static final int GL_RGB8_SNORM                              = 0x8F96;
+    public static final int GL_RGBA8_SNORM                             = 0x8F97;
+    public static final int GL_SIGNED_NORMALIZED                       = 0x8F9C;
+    public static final int GL_PRIMITIVE_RESTART_FIXED_INDEX           = 0x8D69;
+    public static final int GL_COPY_READ_BUFFER                        = 0x8F36;
+    public static final int GL_COPY_WRITE_BUFFER                       = 0x8F37;
+    public static final int GL_COPY_READ_BUFFER_BINDING                = GL_COPY_READ_BUFFER;
+    public static final int GL_COPY_WRITE_BUFFER_BINDING               = GL_COPY_WRITE_BUFFER;
+    public static final int GL_UNIFORM_BUFFER                          = 0x8A11;
+    public static final int GL_UNIFORM_BUFFER_BINDING                  = 0x8A28;
+    public static final int GL_UNIFORM_BUFFER_START                    = 0x8A29;
+    public static final int GL_UNIFORM_BUFFER_SIZE                     = 0x8A2A;
+    public static final int GL_MAX_VERTEX_UNIFORM_BLOCKS               = 0x8A2B;
+    public static final int GL_MAX_FRAGMENT_UNIFORM_BLOCKS             = 0x8A2D;
+    public static final int GL_MAX_COMBINED_UNIFORM_BLOCKS             = 0x8A2E;
+    public static final int GL_MAX_UNIFORM_BUFFER_BINDINGS             = 0x8A2F;
+    public static final int GL_MAX_UNIFORM_BLOCK_SIZE                  = 0x8A30;
+    public static final int GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS  = 0x8A31;
+    public static final int GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS     = 0x8A33;
+    public static final int GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT         = 0x8A34;
+    public static final int GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH    = 0x8A35;
+    public static final int GL_ACTIVE_UNIFORM_BLOCKS                   = 0x8A36;
+    public static final int GL_UNIFORM_TYPE                            = 0x8A37;
+    public static final int GL_UNIFORM_SIZE                            = 0x8A38;
+    public static final int GL_UNIFORM_NAME_LENGTH                     = 0x8A39;
+    public static final int GL_UNIFORM_BLOCK_INDEX                     = 0x8A3A;
+    public static final int GL_UNIFORM_OFFSET                          = 0x8A3B;
+    public static final int GL_UNIFORM_ARRAY_STRIDE                    = 0x8A3C;
+    public static final int GL_UNIFORM_MATRIX_STRIDE                   = 0x8A3D;
+    public static final int GL_UNIFORM_IS_ROW_MAJOR                    = 0x8A3E;
+    public static final int GL_UNIFORM_BLOCK_BINDING                   = 0x8A3F;
+    public static final int GL_UNIFORM_BLOCK_DATA_SIZE                 = 0x8A40;
+    public static final int GL_UNIFORM_BLOCK_NAME_LENGTH               = 0x8A41;
+    public static final int GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS           = 0x8A42;
+    public static final int GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES    = 0x8A43;
+    public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER    = 0x8A44;
+    public static final int GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER  = 0x8A46;
+    // GL_INVALID_INDEX is defined as 0xFFFFFFFFu in C.
+    public static final int GL_INVALID_INDEX                           = -1;
+    public static final int GL_MAX_VERTEX_OUTPUT_COMPONENTS            = 0x9122;
+    public static final int GL_MAX_FRAGMENT_INPUT_COMPONENTS           = 0x9125;
+    public static final int GL_MAX_SERVER_WAIT_TIMEOUT                 = 0x9111;
+    public static final int GL_OBJECT_TYPE                             = 0x9112;
+    public static final int GL_SYNC_CONDITION                          = 0x9113;
+    public static final int GL_SYNC_STATUS                             = 0x9114;
+    public static final int GL_SYNC_FLAGS                              = 0x9115;
+    public static final int GL_SYNC_FENCE                              = 0x9116;
+    public static final int GL_SYNC_GPU_COMMANDS_COMPLETE              = 0x9117;
+    public static final int GL_UNSIGNALED                              = 0x9118;
+    public static final int GL_SIGNALED                                = 0x9119;
+    public static final int GL_ALREADY_SIGNALED                        = 0x911A;
+    public static final int GL_TIMEOUT_EXPIRED                         = 0x911B;
+    public static final int GL_CONDITION_SATISFIED                     = 0x911C;
+    public static final int GL_WAIT_FAILED                             = 0x911D;
+    public static final int GL_SYNC_FLUSH_COMMANDS_BIT                 = 0x00000001;
+    // GL_TIMEOUT_IGNORED is defined as 0xFFFFFFFFFFFFFFFFull in C.
+    public static final long GL_TIMEOUT_IGNORED                         = -1;
+    public static final int GL_VERTEX_ATTRIB_ARRAY_DIVISOR             = 0x88FE;
+    public static final int GL_ANY_SAMPLES_PASSED                      = 0x8C2F;
+    public static final int GL_ANY_SAMPLES_PASSED_CONSERVATIVE         = 0x8D6A;
+    public static final int GL_SAMPLER_BINDING                         = 0x8919;
+    public static final int GL_RGB10_A2UI                              = 0x906F;
+    public static final int GL_TEXTURE_SWIZZLE_R                       = 0x8E42;
+    public static final int GL_TEXTURE_SWIZZLE_G                       = 0x8E43;
+    public static final int GL_TEXTURE_SWIZZLE_B                       = 0x8E44;
+    public static final int GL_TEXTURE_SWIZZLE_A                       = 0x8E45;
+    public static final int GL_GREEN                                   = 0x1904;
+    public static final int GL_BLUE                                    = 0x1905;
+    public static final int GL_INT_2_10_10_10_REV                      = 0x8D9F;
+    public static final int GL_TRANSFORM_FEEDBACK                      = 0x8E22;
+    public static final int GL_TRANSFORM_FEEDBACK_PAUSED               = 0x8E23;
+    public static final int GL_TRANSFORM_FEEDBACK_ACTIVE               = 0x8E24;
+    public static final int GL_TRANSFORM_FEEDBACK_BINDING              = 0x8E25;
+    public static final int GL_PROGRAM_BINARY_RETRIEVABLE_HINT         = 0x8257;
+    public static final int GL_PROGRAM_BINARY_LENGTH                   = 0x8741;
+    public static final int GL_NUM_PROGRAM_BINARY_FORMATS              = 0x87FE;
+    public static final int GL_PROGRAM_BINARY_FORMATS                  = 0x87FF;
+    public static final int GL_COMPRESSED_R11_EAC                      = 0x9270;
+    public static final int GL_COMPRESSED_SIGNED_R11_EAC               = 0x9271;
+    public static final int GL_COMPRESSED_RG11_EAC                     = 0x9272;
+    public static final int GL_COMPRESSED_SIGNED_RG11_EAC              = 0x9273;
+    public static final int GL_COMPRESSED_RGB8_ETC2                    = 0x9274;
+    public static final int GL_COMPRESSED_SRGB8_ETC2                   = 0x9275;
+    public static final int GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2     = 0x9276;
+    public static final int GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2    = 0x9277;
+    public static final int GL_COMPRESSED_RGBA8_ETC2_EAC               = 0x9278;
+    public static final int GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC        = 0x9279;
+    public static final int GL_TEXTURE_IMMUTABLE_FORMAT                = 0x912F;
+    public static final int GL_MAX_ELEMENT_INDEX                       = 0x8D6B;
+    public static final int GL_NUM_SAMPLE_COUNTS                       = 0x9380;
+    public static final int GL_TEXTURE_IMMUTABLE_LEVELS                = 0x82DF;
+
+    native private static void _nativeClassInit();
+    static {
+        _nativeClassInit();
+    }
+
diff --git a/opengl/tools/glgen/stubs/gles11/GLES30cHeader.cpp b/opengl/tools/glgen/stubs/gles11/GLES30cHeader.cpp
new file mode 100644
index 0000000..f5ec455
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/GLES30cHeader.cpp
@@ -0,0 +1,22 @@
+/*
+**
+** Copyright 2013, 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.
+*/
+
+// This source file is automatically generated
+
+#include <GLES3/gl3.h>
+#include <GLES3/gl3ext.h>
+
diff --git a/opengl/tools/glgen/stubs/gles11/common.cpp b/opengl/tools/glgen/stubs/gles11/common.cpp
index 106dbdc..579d573 100644
--- a/opengl/tools/glgen/stubs/gles11/common.cpp
+++ b/opengl/tools/glgen/stubs/gles11/common.cpp
@@ -41,6 +41,12 @@
     glVertexAttribPointer(indx, size, type, normalized, stride, pointer);
 }
 #endif
+#ifdef GL_ES_VERSION_3_0
+static void glVertexAttribIPointerBounds(GLuint indx, GLint size, GLenum type,
+        GLsizei stride, const GLvoid *pointer, GLsizei count) {
+    glVertexAttribIPointer(indx, size, type, stride, pointer);
+}
+#endif
 }
 
 /* Cache method IDs each time the class is loaded. */
diff --git a/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.cpp b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.cpp
new file mode 100644
index 0000000..41df486
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.cpp
@@ -0,0 +1,39 @@
+/* void glDrawElementsInstanced ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount ) */
+static void
+android_glDrawElementsInstanced__IIILjava_nio_Buffer_2I
+  (JNIEnv *_env, jobject _this, jint mode, jint count, jint type, jobject indices_buf, jint instanceCount) {
+    jarray _array = (jarray) 0;
+    jint _bufferOffset = (jint) 0;
+    jint _remaining;
+    GLvoid *indices = (GLvoid *) 0;
+
+    indices = (GLvoid *)getPointer(_env, indices_buf, &_array, &_remaining, &_bufferOffset);
+    if (indices == NULL) {
+        char * _indicesBase = (char *)_env->GetPrimitiveArrayCritical(_array, (jboolean *) 0);
+        indices = (GLvoid *) (_indicesBase + _bufferOffset);
+    }
+    glDrawElementsInstanced(
+        (GLenum)mode,
+        (GLsizei)count,
+        (GLenum)type,
+        (GLvoid *)indices,
+        (GLsizei)instanceCount
+    );
+    if (_array) {
+        releasePointer(_env, _array, indices, JNI_FALSE);
+    }
+}
+
+/* void glDrawElementsInstanced ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount ) */
+static void
+android_glDrawElementsInstanced__IIIII
+  (JNIEnv *_env, jobject _this, jint mode, jint count, jint type, jint indicesOffset, jint instanceCount) {
+    glDrawElementsInstanced(
+        (GLenum)mode,
+        (GLsizei)count,
+        (GLenum)type,
+        (GLvoid *)indicesOffset,
+        (GLsizei)instanceCount
+    );
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.java b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.java
new file mode 100644
index 0000000..53651ce
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.java
@@ -0,0 +1,20 @@
+    // C function void glDrawElementsInstanced ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount )
+
+    public static native void glDrawElementsInstanced(
+        int mode,
+        int count,
+        int type,
+        java.nio.Buffer indices,
+        int instanceCount
+    );
+
+    // C function void glDrawElementsInstanced ( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount )
+
+    public static native void glDrawElementsInstanced(
+        int mode,
+        int count,
+        int type,
+        int indicesOffset,
+        int instanceCount
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.nativeReg b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.nativeReg
new file mode 100644
index 0000000..3b7424c
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glDrawElementsInstanced.nativeReg
@@ -0,0 +1,2 @@
+{"glDrawElementsInstanced", "(IIILjava/nio/Buffer;I)V", (void *) android_glDrawElementsInstanced__IIILjava_nio_Buffer_2I },
+{"glDrawElementsInstanced", "(IIIII)V", (void *) android_glDrawElementsInstanced__IIIII },
diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.cpp b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.cpp
new file mode 100644
index 0000000..bb6ae7c
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.cpp
@@ -0,0 +1,127 @@
+/* void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName ) */
+static void
+android_glGetActiveUniformBlockName_III_3II_3BI
+    (JNIEnv* _env, jobject _this, jint program, jint uniformBlockIndex, int bufSize, jintArray length_ref, jint lengthOffset, jbyteArray name_ref, jint nameOffset) {
+    jint _exception = 0;
+    const char* _exceptionType;
+    const char* _exceptionMessage;
+    GLsizei* _length_base = (GLsizei*)0;
+    jint _lengthRemaining;
+    GLsizei* _length = (GLsizei*)0;
+    GLchar* _name_base = (GLchar*)0;
+    jint _nameRemaining;
+    GLchar* _name = (GLchar*)0;
+
+    if (!length_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "length == null";
+        goto exit;
+    }
+    if (lengthOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "lengthOffset < 0";
+        goto exit;
+    }
+    _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset;
+    _length_base = (GLsizei*)_env->GetPrimitiveArrayCritical(
+            length_ref, (jboolean*)0);
+    _length = _length_base + lengthOffset;
+
+    if (!name_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformBlockName == null";
+        goto exit;
+    }
+    if (nameOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformBlockNameOffset < 0";
+        goto exit;
+    }
+    _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset;
+    _name_base = (GLchar*)_env->GetPrimitiveArrayCritical(
+            name_ref, (jboolean*)0);
+    _name = _name_base + nameOffset;
+
+    glGetActiveUniformBlockName(
+        (GLuint)program,
+        (GLuint)uniformBlockIndex,
+        (GLsizei)bufSize,
+        (GLsizei*)_length,
+        (GLchar*)_name
+    );
+
+exit:
+    if (_name_base) {
+        _env->ReleasePrimitiveArrayCritical(name_ref, _name_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (_length_base) {
+        _env->ReleasePrimitiveArrayCritical(length_ref, _length_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+}
+
+/* void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName ) */
+static void
+android_glGetActiveUniformBlockName_IILjava_nio_Buffer_2Ljava_nio_Buffer_2
+    (JNIEnv* _env, jobject _this, jint program, jint uniformBlockIndex, jobject length_buf, jobject uniformBlockName_buf) {
+    jint _exception = 0;
+    const char* _exceptionType;
+    const char* _exceptionMessage;
+    jarray _lengthArray = (jarray)0;
+    jint _lengthBufferOffset = (jint)0;
+    GLsizei* _length = (GLsizei*)0;
+    jint _lengthRemaining;
+    jarray _nameArray = (jarray)0;
+    jint _nameBufferOffset = (jint)0;
+    GLchar* _name = (GLchar*)0;
+    jint _nameRemaining;
+
+    _length = (GLsizei*)getPointer(_env, length_buf, &_lengthArray, &_lengthRemaining, &_lengthBufferOffset);
+    if (_length == NULL) {
+        GLsizei* _lengthBase = (GLsizei*)_env->GetPrimitiveArrayCritical(_lengthArray, (jboolean*)0);
+        _length = (GLsizei*)(_lengthBase + _lengthBufferOffset);
+    }
+
+    _name = (GLchar*)getPointer(_env, uniformBlockName_buf, &_nameArray, &_nameRemaining, &_nameBufferOffset);
+    if (_name == NULL) {
+        GLchar* _nameBase = (GLchar*)_env->GetPrimitiveArrayCritical(_nameArray, (jboolean*)0);
+        _name = (GLchar*)(_nameBase + _nameBufferOffset);
+    }
+
+    glGetActiveUniformBlockName(
+        (GLuint)program,
+        (GLuint)uniformBlockIndex,
+        (GLsizei)_nameRemaining,
+        _length, _name
+    );
+    if (_nameArray) {
+        releasePointer(_env, _nameArray, _name, JNI_TRUE);
+    }
+    if (_lengthArray) {
+        releasePointer(_env, _lengthArray, _length, JNI_TRUE);
+    }
+}
+
+/* void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName ) */
+static jstring
+android_glGetActiveUniformBlockName_II
+    (JNIEnv *_env, jobject _this, jint program, jint uniformBlockIndex) {
+    GLint len = 0;
+    glGetActiveUniformBlockiv((GLuint)program, (GLuint)uniformBlockIndex,
+            GL_UNIFORM_BLOCK_NAME_LENGTH, &len);
+    GLchar* name = (GLchar*)malloc(len);
+    glGetActiveUniformBlockName((GLuint)program, (GLuint)uniformBlockIndex,
+        len, NULL, name);
+    jstring result = _env->NewStringUTF(name);
+    free(name);
+    return result;
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.java b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.java
new file mode 100644
index 0000000..3d9ed0f
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.java
@@ -0,0 +1,28 @@
+    // C function void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName )
+
+    public static native void glGetActiveUniformBlockName(
+        int program,
+        int uniformBlockIndex,
+        int bufSize,
+        int[] length,
+        int lengthOffset,
+        byte[] uniformBlockName,
+        int uniformBlockNameOffset
+    );
+
+    // C function void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName )
+
+    public static native void glGetActiveUniformBlockName(
+        int program,
+        int uniformBlockIndex,
+        java.nio.Buffer length,
+        java.nio.Buffer uniformBlockName
+    );
+
+    // C function void glGetActiveUniformBlockName ( GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName )
+
+    public static native String glGetActiveUniformBlockName(
+        int program,
+        int uniformBlockIndex
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.nativeReg
new file mode 100644
index 0000000..fb37689
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniformBlockName.nativeReg
@@ -0,0 +1,3 @@
+{"glGetActiveUniformBlockName", "(III[II[BI)V", (void *) android_glGetActiveUniformBlockName_III_3II_3BI },
+{"glGetActiveUniformBlockName", "(IILjava/nio/Buffer;Ljava/nio/Buffer;)V", (void *) android_glGetActiveUniformBlockName_IILjava_nio_Buffer_2Ljava_nio_Buffer_2 },
+{"glGetActiveUniformBlockName", "(II)Ljava/lang/String;", (void *) android_glGetActiveUniformBlockName_II },
\ No newline at end of file
diff --git a/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.cpp b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.cpp
new file mode 100644
index 0000000..7016c4b
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.cpp
@@ -0,0 +1,11 @@
+/* void glGetBufferPointerv ( GLenum target, GLenum pname, GLvoid** params ) */
+static jobject
+android_glGetBufferPointerv__II
+  (JNIEnv *_env, jobject _this, jint target, jint pname) {
+    GLint64 _mapLength;
+    GLvoid* _p;
+    glGetBufferParameteri64v((GLenum)target, GL_BUFFER_MAP_LENGTH, &_mapLength);
+    glGetBufferPointerv((GLenum)target, (GLenum)pname, &_p);
+    return _env->NewDirectByteBuffer(_p, _mapLength);
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.java b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.java
new file mode 100644
index 0000000..c966e11
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.java
@@ -0,0 +1,7 @@
+    // C function void glGetBufferPointerv ( GLenum target, GLenum pname, GLvoid** params )
+
+    public static native java.nio.Buffer glGetBufferPointerv(
+        int target,
+        int pname
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.nativeReg
new file mode 100644
index 0000000..7886451
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetBufferPointerv.nativeReg
@@ -0,0 +1 @@
+{"glGetBufferPointerv", "(II)Ljava/nio/Buffer;", (void *) android_glGetBufferPointerv__II },
\ No newline at end of file
diff --git a/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java b/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java
index 19504f2..da0a1fd 100644
--- a/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java
+++ b/opengl/tools/glgen/stubs/gles11/glGetProgramInfoLog.java
@@ -1,5 +1,5 @@
     // C function void glGetProgramInfoLog( GLuint program, GLsizei maxLength, GLsizei * length,
- 	//     GLchar * infoLog);
+    //     GLchar * infoLog);
 
     public static native String glGetProgramInfoLog(
         int program
diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java b/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java
index 1fac6be..dc1db5b 100644
--- a/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java
+++ b/opengl/tools/glgen/stubs/gles11/glGetShaderInfoLog.java
@@ -1,5 +1,5 @@
     // C function void glGetShaderInfoLog( GLuint shader, GLsizei maxLength, GLsizei * length,
- 	//     GLchar * infoLog);
+    //     GLchar * infoLog);
 
     public static native String glGetShaderInfoLog(
         int shader
diff --git a/opengl/tools/glgen/stubs/gles11/glGetStringi.cpp b/opengl/tools/glgen/stubs/gles11/glGetStringi.cpp
new file mode 100644
index 0000000..1611539
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetStringi.cpp
@@ -0,0 +1,8 @@
+/* const GLubyte * glGetStringi ( GLenum name, GLuint index ) */
+static jstring
+android_glGetStringi__II
+  (JNIEnv *_env, jobject _this, jint name, jint index) {
+    const GLubyte* _chars = glGetStringi((GLenum)name, (GLuint)index);
+    return _env->NewStringUTF((const char*)_chars);
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetStringi.java b/opengl/tools/glgen/stubs/gles11/glGetStringi.java
new file mode 100644
index 0000000..523d4c7
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetStringi.java
@@ -0,0 +1,7 @@
+    // C function const GLubyte * glGetStringi ( GLenum name, GLuint index )
+
+    public static native String glGetStringi(
+        int name,
+        int index
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetStringi.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetStringi.nativeReg
new file mode 100644
index 0000000..e7ee353
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetStringi.nativeReg
@@ -0,0 +1 @@
+{"glGetStringi", "(II)Ljava/lang/String;", (void *) android_glGetStringi__II },
\ No newline at end of file
diff --git a/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.cpp b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.cpp
new file mode 100644
index 0000000..0514fe9
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.cpp
@@ -0,0 +1,328 @@
+/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
+static void
+android_glGetTransformFeedbackVarying__III_3II_3II_3II_3BI
+  (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jintArray length_ref, jint lengthOffset, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset, jbyteArray name_ref, jint nameOffset) {
+    jint _exception = 0;
+    const char * _exceptionType;
+    const char * _exceptionMessage;
+    GLsizei *length_base = (GLsizei *) 0;
+    jint _lengthRemaining;
+    GLsizei *length = (GLsizei *) 0;
+    GLint *size_base = (GLint *) 0;
+    jint _sizeRemaining;
+    GLint *size = (GLint *) 0;
+    GLenum *type_base = (GLenum *) 0;
+    jint _typeRemaining;
+    GLenum *type = (GLenum *) 0;
+    char *name_base = (char *) 0;
+    jint _nameRemaining;
+    char *name = (char *) 0;
+
+    if (!length_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "length == null";
+        goto exit;
+    }
+    if (lengthOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "lengthOffset < 0";
+        goto exit;
+    }
+    _lengthRemaining = _env->GetArrayLength(length_ref) - lengthOffset;
+    length_base = (GLsizei *)
+        _env->GetPrimitiveArrayCritical(length_ref, (jboolean *)0);
+    length = length_base + lengthOffset;
+
+    if (!size_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "size == null";
+        goto exit;
+    }
+    if (sizeOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "sizeOffset < 0";
+        goto exit;
+    }
+    _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset;
+    size_base = (GLint *)
+        _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0);
+    size = size_base + sizeOffset;
+
+    if (!type_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "type == null";
+        goto exit;
+    }
+    if (typeOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "typeOffset < 0";
+        goto exit;
+    }
+    _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset;
+    type_base = (GLenum *)
+        _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0);
+    type = type_base + typeOffset;
+
+    if (!name_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "name == null";
+        goto exit;
+    }
+    if (nameOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "nameOffset < 0";
+        goto exit;
+    }
+    _nameRemaining = _env->GetArrayLength(name_ref) - nameOffset;
+    name_base = (char *)
+        _env->GetPrimitiveArrayCritical(name_ref, (jboolean *)0);
+    name = name_base + nameOffset;
+
+    glGetTransformFeedbackVarying(
+        (GLuint)program,
+        (GLuint)index,
+        (GLsizei)bufsize,
+        (GLsizei *)length,
+        (GLint *)size,
+        (GLenum *)type,
+        (char *)name
+    );
+
+exit:
+    if (name_base) {
+        _env->ReleasePrimitiveArrayCritical(name_ref, name_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (type_base) {
+        _env->ReleasePrimitiveArrayCritical(type_ref, type_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (size_base) {
+        _env->ReleasePrimitiveArrayCritical(size_ref, size_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (length_base) {
+        _env->ReleasePrimitiveArrayCritical(length_ref, length_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+}
+
+/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
+static void
+android_glGetTransformFeedbackVarying__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B
+  (JNIEnv *_env, jobject _this, jint program, jint index, jint bufsize, jobject length_buf, jobject size_buf, jobject type_buf, jbyte name) {
+    jarray _lengthArray = (jarray) 0;
+    jint _lengthBufferOffset = (jint) 0;
+    jarray _sizeArray = (jarray) 0;
+    jint _sizeBufferOffset = (jint) 0;
+    jarray _typeArray = (jarray) 0;
+    jint _typeBufferOffset = (jint) 0;
+    jint _lengthRemaining;
+    GLsizei *length = (GLsizei *) 0;
+    jint _sizeRemaining;
+    GLint *size = (GLint *) 0;
+    jint _typeRemaining;
+    GLenum *type = (GLenum *) 0;
+
+    length = (GLsizei *)getPointer(_env, length_buf, &_lengthArray, &_lengthRemaining, &_lengthBufferOffset);
+    size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset);
+    type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset);
+    if (length == NULL) {
+        char * _lengthBase = (char *)_env->GetPrimitiveArrayCritical(_lengthArray, (jboolean *) 0);
+        length = (GLsizei *) (_lengthBase + _lengthBufferOffset);
+    }
+    if (size == NULL) {
+        char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0);
+        size = (GLint *) (_sizeBase + _sizeBufferOffset);
+    }
+    if (type == NULL) {
+        char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0);
+        type = (GLenum *) (_typeBase + _typeBufferOffset);
+    }
+    glGetTransformFeedbackVarying(
+        (GLuint)program,
+        (GLuint)index,
+        (GLsizei)bufsize,
+        (GLsizei *)length,
+        (GLint *)size,
+        (GLenum *)type,
+        (char *)name
+    );
+    if (_typeArray) {
+        releasePointer(_env, _typeArray, type, JNI_TRUE);
+    }
+    if (_sizeArray) {
+        releasePointer(_env, _sizeArray, size, JNI_TRUE);
+    }
+    if (_lengthArray) {
+        releasePointer(_env, _lengthArray, length, JNI_TRUE);
+    }
+}
+
+/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
+static jstring
+android_glGetTransformFeedbackVarying1
+  (JNIEnv *_env, jobject _this, jint program, jint index, jintArray size_ref, jint sizeOffset, jintArray type_ref, jint typeOffset) {
+    jint _exception = 0;
+    const char * _exceptionType;
+    const char * _exceptionMessage;
+    GLint *size_base = (GLint *) 0;
+    jint _sizeRemaining;
+    GLint *size = (GLint *) 0;
+    GLenum *type_base = (GLenum *) 0;
+    jint _typeRemaining;
+    GLenum *type = (GLenum *) 0;
+
+    jstring result = 0;
+
+    GLint len = 0;
+    glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
+    if (!len) {
+        return _env->NewStringUTF("");
+    }
+    char* buf = (char*) malloc(len);
+
+    if (buf == NULL) {
+        jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
+        return NULL;
+    }
+    if (!size_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "size == null";
+        goto exit;
+    }
+    if (sizeOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "sizeOffset < 0";
+        goto exit;
+    }
+    _sizeRemaining = _env->GetArrayLength(size_ref) - sizeOffset;
+    size_base = (GLint *)
+        _env->GetPrimitiveArrayCritical(size_ref, (jboolean *)0);
+    size = size_base + sizeOffset;
+
+    if (!type_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "type == null";
+        goto exit;
+    }
+    if (typeOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "typeOffset < 0";
+        goto exit;
+    }
+    _typeRemaining = _env->GetArrayLength(type_ref) - typeOffset;
+    type_base = (GLenum *)
+        _env->GetPrimitiveArrayCritical(type_ref, (jboolean *)0);
+    type = type_base + typeOffset;
+
+    glGetTransformFeedbackVarying(
+        (GLuint)program,
+        (GLuint)index,
+        (GLsizei)len,
+        NULL,
+        (GLint *)size,
+        (GLenum *)type,
+        (char *)buf
+    );
+exit:
+    if (type_base) {
+        _env->ReleasePrimitiveArrayCritical(type_ref, type_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (size_base) {
+        _env->ReleasePrimitiveArrayCritical(size_ref, size_base,
+            _exception ? JNI_ABORT: 0);
+    }
+    if (_exception != 1) {
+        result = _env->NewStringUTF(buf);
+    }
+    if (buf) {
+        free(buf);
+    }
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+    if (result == 0) {
+        result = _env->NewStringUTF("");
+    }
+
+    return result;
+}
+
+/* void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name ) */
+static jstring
+android_glGetTransformFeedbackVarying2
+  (JNIEnv *_env, jobject _this, jint program, jint index, jobject size_buf, jobject type_buf) {
+    jarray _sizeArray = (jarray) 0;
+    jint _sizeBufferOffset = (jint) 0;
+    jarray _typeArray = (jarray) 0;
+    jint _typeBufferOffset = (jint) 0;
+    jint _lengthRemaining;
+    GLsizei *length = (GLsizei *) 0;
+    jint _sizeRemaining;
+    GLint *size = (GLint *) 0;
+    jint _typeRemaining;
+    GLenum *type = (GLenum *) 0;
+
+    jstring result = 0;
+
+    GLint len = 0;
+    glGetProgramiv((GLuint)program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
+    if (!len) {
+        return _env->NewStringUTF("");
+    }
+    char* buf = (char*) malloc(len);
+
+    if (buf == NULL) {
+        jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
+        return NULL;
+    }
+
+    size = (GLint *)getPointer(_env, size_buf, &_sizeArray, &_sizeRemaining, &_sizeBufferOffset);
+    type = (GLenum *)getPointer(_env, type_buf, &_typeArray, &_typeRemaining, &_typeBufferOffset);
+    if (size == NULL) {
+        char * _sizeBase = (char *)_env->GetPrimitiveArrayCritical(_sizeArray, (jboolean *) 0);
+        size = (GLint *) (_sizeBase + _sizeBufferOffset);
+    }
+    if (type == NULL) {
+        char * _typeBase = (char *)_env->GetPrimitiveArrayCritical(_typeArray, (jboolean *) 0);
+        type = (GLenum *) (_typeBase + _typeBufferOffset);
+    }
+    glGetTransformFeedbackVarying(
+        (GLuint)program,
+        (GLuint)index,
+        (GLsizei)len,
+        NULL,
+        (GLint *)size,
+        (GLenum *)type,
+        (char *)buf
+    );
+
+    if (_typeArray) {
+        releasePointer(_env, _typeArray, type, JNI_TRUE);
+    }
+    if (_sizeArray) {
+        releasePointer(_env, _sizeArray, size, JNI_TRUE);
+    }
+    result = _env->NewStringUTF(buf);
+    if (buf) {
+        free(buf);
+    }
+    return result;
+}
diff --git a/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.java b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.java
new file mode 100644
index 0000000..f73bbfe
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.java
@@ -0,0 +1,48 @@
+    // C function void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name )
+
+    public static native void glGetTransformFeedbackVarying(
+        int program,
+        int index,
+        int bufsize,
+        int[] length,
+        int lengthOffset,
+        int[] size,
+        int sizeOffset,
+        int[] type,
+        int typeOffset,
+        byte[] name,
+        int nameOffset
+    );
+
+    // C function void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name )
+
+    public static native void glGetTransformFeedbackVarying(
+        int program,
+        int index,
+        int bufsize,
+        java.nio.IntBuffer length,
+        java.nio.IntBuffer size,
+        java.nio.IntBuffer type,
+        byte name
+    );
+
+    // C function void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name )
+
+    public static native String glGetTransformFeedbackVarying(
+        int program,
+        int index,
+        int[] size,
+        int sizeOffset,
+        int[] type,
+        int typeOffset
+    );
+
+    // C function void glGetTransformFeedbackVarying ( GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name )
+
+    public static native String glGetTransformFeedbackVarying(
+        int program,
+        int index,
+        java.nio.IntBuffer size,
+        java.nio.IntBuffer type
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.nativeReg
new file mode 100644
index 0000000..412d04c
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetTransformFeedbackVarying.nativeReg
@@ -0,0 +1,4 @@
+{"glGetTransformFeedbackVarying", "(III[II[II[II[BI)V", (void *) android_glGetTransformFeedbackVarying__III_3II_3II_3II_3BI },
+{"glGetTransformFeedbackVarying", "(IIILjava/nio/IntBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;B)V", (void *) android_glGetTransformFeedbackVarying__IIILjava_nio_IntBuffer_2Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2B },
+{"glGetTransformFeedbackVarying", "(II[II[II)Ljava/lang/String;", (void *) android_glGetTransformFeedbackVarying1 },
+{"glGetTransformFeedbackVarying", "(IILjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/lang/String;", (void *) android_glGetTransformFeedbackVarying2 },
diff --git a/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.cpp b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.cpp
new file mode 100644
index 0000000..fb137ab
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.cpp
@@ -0,0 +1,154 @@
+/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
+static
+void
+android_glGetUniformIndices_array
+    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jintArray uniformIndices_ref, jint uniformIndicesOffset) {
+    jint _exception = 0;
+    const char* _exceptionType = NULL;
+    const char* _exceptionMessage = NULL;
+    jint _count = 0;
+    jint _i;
+    const char** _names = NULL;
+    GLuint* _indices_base = NULL;
+    GLuint* _indices = NULL;
+
+    if (!uniformNames_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformNames == null";
+        goto exit;
+    }
+    _count = _env->GetArrayLength(uniformNames_ref);
+    _names = (const char**)calloc(_count, sizeof(const char*));
+    for (_i = 0; _i < _count; _i++) {
+        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
+        if (!_name) {
+            _exception = 1;
+            _exceptionType = "java/lang/IllegalArgumentException";
+            _exceptionMessage = "null uniformNames element";
+            goto exit;
+        }
+        _names[_i] = _env->GetStringUTFChars(_name, 0);
+    }
+
+    if (!uniformIndices_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformIndices == null";
+        goto exit;
+    }
+    if (uniformIndicesOffset < 0) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformIndicesOffset < 0";
+        goto exit;
+    }
+    if (_env->GetArrayLength(uniformIndices_ref) - uniformIndicesOffset < _count) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "not enough space in uniformIndices";
+        goto exit;
+    }
+    _indices_base = (GLuint*)_env->GetPrimitiveArrayCritical(
+            uniformIndices_ref, 0);
+    _indices = _indices_base + uniformIndicesOffset;
+
+    glGetUniformIndices(program, _count, _names, _indices);
+
+exit:
+    if (_indices_base) {
+        _env->ReleasePrimitiveArrayCritical(uniformIndices_ref, _indices_base,
+                _exception ? JNI_ABORT : 0);
+    }
+    for (_i = _count - 1; _i >= 0; _i--) {
+        if (_names[_i]) {
+            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
+            if (_name) {
+                _env->ReleaseStringUTFChars(_name, _names[_i]);
+            }
+        }
+    }
+    free(_names);
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+}
+
+/* void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices ) */
+static
+void
+android_glGetUniformIndices_buffer
+    (JNIEnv *_env, jobject _this, jint program, jobjectArray uniformNames_ref, jobject uniformIndices_buf) {
+    jint _exception = 0;
+    const char* _exceptionType = NULL;
+    const char* _exceptionMessage = NULL;
+    jint _count = 0;
+    jint _i;
+    const char** _names = NULL;
+    jarray _uniformIndicesArray = (jarray)0;
+    jint _uniformIndicesRemaining;
+    jint _uniformIndicesOffset = 0;
+    GLuint* _indices = NULL;
+    char* _indicesBase = NULL;
+
+    if (!uniformNames_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformNames == null";
+        goto exit;
+    }
+    if (!uniformIndices_buf) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "uniformIndices == null";
+        goto exit;
+    }
+
+    _count = _env->GetArrayLength(uniformNames_ref);
+    _names = (const char**)calloc(_count, sizeof(const char*));
+    for (_i = 0; _i < _count; _i++) {
+        jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
+        if (!_name) {
+            _exception = 1;
+            _exceptionType = "java/lang/IllegalArgumentException";
+            _exceptionMessage = "null uniformNames element";
+            goto exit;
+        }
+        _names[_i] = _env->GetStringUTFChars(_name, 0);
+    }
+
+    _indices = (GLuint*)getPointer(_env, uniformIndices_buf,
+            &_uniformIndicesArray, &_uniformIndicesRemaining,
+            &_uniformIndicesOffset);
+    if (!_indices) {
+        _indicesBase = (char*)_env->GetPrimitiveArrayCritical(
+                _uniformIndicesArray, 0);
+        _indices = (GLuint*)(_indicesBase + _uniformIndicesOffset);
+    }
+    if (_uniformIndicesRemaining < _count) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "not enough space in uniformIndices";
+        goto exit;
+    }
+
+    glGetUniformIndices(program, _count, _names, _indices);
+
+exit:
+    if (_uniformIndicesArray) {
+        releasePointer(_env, _uniformIndicesArray, _indicesBase, JNI_TRUE);
+    }
+    for (_i = _count - 1; _i >= 0; _i--) {
+        if (_names[_i]) {
+            jstring _name = (jstring)_env->GetObjectArrayElement(uniformNames_ref, _i);
+            if (_name) {
+                _env->ReleaseStringUTFChars(_name, _names[_i]);
+            }
+        }
+    }
+    free(_names);
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.java b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.java
new file mode 100644
index 0000000..719429b
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.java
@@ -0,0 +1,17 @@
+	// C function void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices )
+
+	public static native void glGetUniformIndices(
+        int program,
+        String[] uniformNames,
+        int[] uniformIndices,
+        int uniformIndicesOffset
+	);
+
+    // C function void glGetUniformIndices ( GLuint program, GLsizei uniformCount, const GLchar *const *uniformNames, GLuint *uniformIndices )
+
+    public static native void glGetUniformIndices(
+        int program,
+        String[] uniformNames,
+        java.nio.IntBuffer uniformIndices
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.nativeReg b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.nativeReg
new file mode 100644
index 0000000..c711307
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glGetUniformIndices.nativeReg
@@ -0,0 +1,2 @@
+{"glGetUniformIndices", "(I[Ljava/lang/String;[II)V", (void *) android_glGetUniformIndices_array },
+{"glGetUniformIndices", "(I[Ljava/lang/String;[Ljava/nio/IntBuffer)V", (void *) android_glGetUniformIndices_buffer },
diff --git a/opengl/tools/glgen/stubs/gles11/glMapBufferRange.cpp b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.cpp
new file mode 100644
index 0000000..2485642
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.cpp
@@ -0,0 +1,13 @@
+/* GLvoid * glMapBufferRange ( GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access ) */
+static jobject
+android_glMapBufferRange__IIII
+  (JNIEnv *_env, jobject _this, jint target, jint offset, jint length, jint access) {
+    GLvoid* _p = glMapBufferRange((GLenum)target,
+            (GLintptr)offset, (GLsizeiptr)length, (GLbitfield)access);
+    jobject _buf = (jobject)0;
+    if (_p) {
+        _buf = _env->NewDirectByteBuffer(_p, length);
+    }
+    return _buf;
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glMapBufferRange.java b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.java
new file mode 100644
index 0000000..482ea99
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.java
@@ -0,0 +1,9 @@
+    // C function GLvoid * glMapBufferRange ( GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access )
+
+    public static native java.nio.Buffer glMapBufferRange(
+        int target,
+        int offset,
+        int length,
+        int access
+    );
+
diff --git a/opengl/tools/glgen/stubs/gles11/glMapBufferRange.nativeReg b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.nativeReg
new file mode 100644
index 0000000..ad5c077
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glMapBufferRange.nativeReg
@@ -0,0 +1 @@
+{"glMapBufferRange", "(IIII)Ljava/nio/Buffer;", (void *) android_glMapBufferRange__IIII },
\ No newline at end of file
diff --git a/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.cpp b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.cpp
new file mode 100644
index 0000000..0dedd0f
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.cpp
@@ -0,0 +1,49 @@
+/* void glTransformFeedbackVaryings ( GLuint program, GLsizei count, const GLchar *varyings, GLenum bufferMode ) */
+static
+void
+android_glTransformFeedbackVaryings
+    (JNIEnv *_env, jobject _this, jint program, jobjectArray varyings_ref, jint bufferMode) {
+    jint _exception = 0;
+    const char* _exceptionType = NULL;
+    const char* _exceptionMessage = NULL;
+    jint _count = 0, _i;
+    const char** _varyings = NULL;
+    const char* _varying = NULL;
+
+    if (!varyings_ref) {
+        _exception = 1;
+        _exceptionType = "java/lang/IllegalArgumentException";
+        _exceptionMessage = "varyings == null";
+        goto exit;
+    }
+
+    _count = _env->GetArrayLength(varyings_ref);
+    _varyings = (const char**)calloc(_count, sizeof(const char*));
+    for (_i = 0; _i < _count; _i++) {
+        jstring _varying = (jstring)_env->GetObjectArrayElement(varyings_ref, _i);
+        if (!_varying) {
+            _exception = 1;
+            _exceptionType = "java/lang/IllegalArgumentException";
+            _exceptionMessage = "null varyings element";
+            goto exit;
+        }
+        _varyings[_i] = _env->GetStringUTFChars(_varying, 0);
+    }
+
+    glTransformFeedbackVaryings(program, _count, _varyings, bufferMode);
+
+exit:
+    for (_i = _count - 1; _i >= 0; _i--) {
+        if (_varyings[_i]) {
+            jstring _varying = (jstring)_env->GetObjectArrayElement(varyings_ref, _i);
+            if (_varying) {
+                _env->ReleaseStringUTFChars(_varying, _varyings[_i]);
+            }
+        }
+    }
+    free(_varyings);
+    if (_exception) {
+        jniThrowException(_env, _exceptionType, _exceptionMessage);
+    }
+}
+
diff --git a/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.java b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.java
new file mode 100644
index 0000000..c824344
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.java
@@ -0,0 +1,8 @@
+	// C function void glTransformFeedbackVaryings ( GLuint program, GLsizei count, const GLchar *varyings, GLenum bufferMode )
+
+	public static native void glTransformFeedbackVaryings(
+        int program,
+        String[] varyings,
+        int bufferMode
+	);
+
diff --git a/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.nativeReg b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.nativeReg
new file mode 100644
index 0000000..24f2b77
--- /dev/null
+++ b/opengl/tools/glgen/stubs/gles11/glTransformFeedbackVaryings.nativeReg
@@ -0,0 +1 @@
+{"glTransformFeedbackVaryings", "(I[Ljava/lang/String;I)V", (void *) android_glTransformFeedbackVaryings },
diff --git a/services/sensorservice/Android.mk b/services/sensorservice/Android.mk
index e0cfaa6..dd698c5 100644
--- a/services/sensorservice/Android.mk
+++ b/services/sensorservice/Android.mk
@@ -20,7 +20,9 @@
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
 	libhardware \
+	libhardware_legacy \
 	libutils \
+	liblog \
 	libbinder \
 	libui \
 	libgui
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index a9e3ef4..b256cce 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -181,6 +181,12 @@
     return mSensorDevice->setDelay(mSensorDevice, handle, ns);
 }
 
+int SensorDevice::getHalDeviceVersion() const {
+    if (!mSensorDevice) return -1;
+
+    return mSensorDevice->common.version;
+}
+
 // ---------------------------------------------------------------------------
 
 status_t SensorDevice::Info::setDelayForIdent(void* ident, int64_t ns)
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 728b6cb..b423f40 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -52,6 +52,7 @@
 public:
     ssize_t getSensorList(sensor_t const** list);
     status_t initCheck() const;
+    int getHalDeviceVersion() const;
     ssize_t poll(sensors_event_t* buffer, size_t count);
     status_t activate(void* ident, int handle, int enabled);
     status_t setDelay(void* ident, int handle, int64_t ns);
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index e3dcd02..9ca6b45 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -38,6 +38,7 @@
 #include <gui/SensorEventQueue.h>
 
 #include <hardware/sensors.h>
+#include <hardware_legacy/power.h>
 
 #include "BatteryService.h"
 #include "CorrectedGyroSensor.h"
@@ -60,6 +61,8 @@
  *
  */
 
+const char* SensorService::WAKE_LOCK_NAME = "SensorService";
+
 SensorService::SensorService()
     : mInitCheck(NO_INIT)
 {
@@ -237,6 +240,18 @@
     return NO_ERROR;
 }
 
+void SensorService::cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,
+        sensors_event_t const* buffer, const int count) {
+    for (int i=0 ; i<count ; i++) {
+        int handle = buffer[i].sensor;
+        if (getSensorType(handle) == SENSOR_TYPE_SIGNIFICANT_MOTION) {
+            if (connection->hasSensor(handle)) {
+                cleanupWithoutDisable(connection, handle);
+            }
+        }
+    }
+}
+
 bool SensorService::threadLoop()
 {
     ALOGD("nuSensorService thread starting...");
@@ -249,6 +264,8 @@
     const size_t vcount = mVirtualSensorList.size();
 
     ssize_t count;
+    bool wakeLockAcquired = false;
+    const int halVersion = device.getHalDeviceVersion();
     do {
         count = device.poll(buffer, numEventMax);
         if (count<0) {
@@ -256,6 +273,17 @@
             break;
         }
 
+        // Poll has returned. Hold a wakelock.
+        // Todo(): add a flag to the sensors definitions to indicate
+        // the sensors which can wake up the AP
+        for (int i = 0; i < count; i++) {
+            if (getSensorType(buffer[i].sensor) == SENSOR_TYPE_SIGNIFICANT_MOTION) {
+                 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
+                 wakeLockAcquired = true;
+                 break;
+            }
+        }
+
         recordLastValue(buffer, count);
 
         // handle virtual sensors
@@ -298,6 +326,17 @@
             }
         }
 
+        // handle backward compatibility for RotationVector sensor
+        if (halVersion < SENSORS_DEVICE_API_VERSION_1_0) {
+            for (int i = 0; i < count; i++) {
+                if (getSensorType(buffer[i].sensor) == SENSOR_TYPE_ROTATION_VECTOR) {
+                    // All the 4 components of the quaternion should be available
+                    // No heading accuracy. Set it to -1
+                    buffer[i].data[4] = -1;
+                }
+            }
+        }
+
         // send our events to clients...
         const SortedVector< wp<SensorEventConnection> > activeConnections(
                 getActiveConnections());
@@ -307,8 +346,14 @@
                     activeConnections[i].promote());
             if (connection != 0) {
                 connection->sendEvents(buffer, count, scratch);
+                // Some sensors need to be auto disabled after the trigger
+                cleanupAutoDisabledSensor(connection, buffer, count);
             }
         }
+
+        // We have read the data, upper layers should hold the wakelock.
+        if (wakeLockAcquired) release_wake_lock(WAKE_LOCK_NAME);
+
     } while (count >= 0 || Thread::exitPending());
 
     ALOGW("Exiting SensorService::threadLoop => aborting...");
@@ -372,6 +417,18 @@
     return result;
 }
 
+int SensorService::getSensorType(int handle) const {
+    size_t count = mUserSensorList.size();
+    for (size_t i=0 ; i<count ; i++) {
+        const Sensor& sensor(mUserSensorList[i]);
+        if (sensor.getHandle() == handle) {
+            return sensor.getType();
+        }
+    }
+    return -1;
+}
+
+
 Vector<Sensor> SensorService::getSensorList()
 {
     char value[PROPERTY_VALUE_MAX];
@@ -433,44 +490,48 @@
 
     Mutex::Autolock _l(mLock);
     SensorInterface* sensor = mSensorMap.valueFor(handle);
+    SensorRecord* rec = mActiveSensors.valueFor(handle);
+    if (rec == 0) {
+        rec = new SensorRecord(connection);
+        mActiveSensors.add(handle, rec);
+        if (sensor->isVirtual()) {
+            mActiveVirtualSensors.add(handle, sensor);
+        }
+    } else {
+        if (rec->addConnection(connection)) {
+            // this sensor is already activated, but we are adding a
+            // connection that uses it. Immediately send down the last
+            // known value of the requested sensor if it's not a
+            // "continuous" sensor.
+            if (sensor->getSensor().getMinDelay() == 0) {
+                sensors_event_t scratch;
+                sensors_event_t& event(mLastEventSeen.editValueFor(handle));
+                if (event.version == sizeof(sensors_event_t)) {
+                    connection->sendEvents(&event, 1);
+                }
+            }
+        }
+    }
+
+    if (connection->addSensor(handle)) {
+        BatteryService::enableSensor(connection->getUid(), handle);
+        // the sensor was added (which means it wasn't already there)
+        // so, see if this connection becomes active
+        if (mActiveConnections.indexOf(connection) < 0) {
+            mActiveConnections.add(connection);
+        }
+    } else {
+        ALOGW("sensor %08x already enabled in connection %p (ignoring)",
+            handle, connection.get());
+    }
+
+
+    // we are setup, now enable the sensor.
     status_t err = sensor ? sensor->activate(connection.get(), true) : status_t(BAD_VALUE);
-    if (err == NO_ERROR) {
-        SensorRecord* rec = mActiveSensors.valueFor(handle);
-        if (rec == 0) {
-            rec = new SensorRecord(connection);
-            mActiveSensors.add(handle, rec);
-            if (sensor->isVirtual()) {
-                mActiveVirtualSensors.add(handle, sensor);
-            }
-        } else {
-            if (rec->addConnection(connection)) {
-                // this sensor is already activated, but we are adding a
-                // connection that uses it. Immediately send down the last
-                // known value of the requested sensor if it's not a
-                // "continuous" sensor.
-                if (sensor->getSensor().getMinDelay() == 0) {
-                    sensors_event_t scratch;
-                    sensors_event_t& event(mLastEventSeen.editValueFor(handle));
-                    if (event.version == sizeof(sensors_event_t)) {
-                        connection->sendEvents(&event, 1);
-                    }
-                }
-            }
-        }
-        if (err == NO_ERROR) {
-            // connection now active
-            if (connection->addSensor(handle)) {
-                BatteryService::enableSensor(connection->getUid(), handle);
-                // the sensor was added (which means it wasn't already there)
-                // so, see if this connection becomes active
-                if (mActiveConnections.indexOf(connection) < 0) {
-                    mActiveConnections.add(connection);
-                }
-            } else {
-                ALOGW("sensor %08x already enabled in connection %p (ignoring)",
-                        handle, connection.get());
-            }
-        }
+
+    if (err != NO_ERROR) {
+        // enable has failed, reset our state.
+        cleanupWithoutDisable(connection, handle);
     }
     return err;
 }
@@ -481,7 +542,16 @@
     if (mInitCheck != NO_ERROR)
         return mInitCheck;
 
-    status_t err = NO_ERROR;
+    status_t err = cleanupWithoutDisable(connection, handle);
+    if (err == NO_ERROR) {
+        SensorInterface* sensor = mSensorMap.valueFor(handle);
+        err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE);
+    }
+    return err;
+}
+
+status_t SensorService::cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
+        int handle) {
     Mutex::Autolock _l(mLock);
     SensorRecord* rec = mActiveSensors.valueFor(handle);
     if (rec) {
@@ -498,10 +568,9 @@
             mActiveVirtualSensors.removeItem(handle);
             delete rec;
         }
-        SensorInterface* sensor = mSensorMap.valueFor(handle);
-        err = sensor ? sensor->activate(connection.get(), false) : status_t(BAD_VALUE);
+        return NO_ERROR;
     }
-    return err;
+    return BAD_VALUE;
 }
 
 status_t SensorService::setEventRate(const sp<SensorEventConnection>& connection,
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 18591bf..25e5f76 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -53,6 +53,7 @@
    friend class BinderService<SensorService>;
 
    static const nsecs_t MINIMUM_EVENTS_PERIOD =   1000000; // 1000 Hz
+   static const char* WAKE_LOCK_NAME;
 
             SensorService();
     virtual ~SensorService();
@@ -109,10 +110,15 @@
     DefaultKeyedVector<int, SensorInterface*> getActiveVirtualSensors() const;
 
     String8 getSensorName(int handle) const;
+    int getSensorType(int handle) const;
     void recordLastValue(sensors_event_t const * buffer, size_t count);
     static void sortEventBuffer(sensors_event_t* buffer, size_t count);
     void registerSensor(SensorInterface* sensor);
     void registerVirtualSensor(SensorInterface* sensor);
+    status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection,
+        int handle);
+    void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection,
+        sensors_event_t const* buffer, const int count);
 
     // constants
     Vector<Sensor> mSensorList;
diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
index 30a01be..f36e1bf 100644
--- a/services/surfaceflinger/Android.mk
+++ b/services/surfaceflinger/Android.mk
@@ -44,6 +44,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
+	liblog \
 	libdl \
 	libhardware \
 	libutils \
@@ -68,6 +69,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
+	liblog \
 	libdl
 
 LOCAL_MODULE:= libsurfaceflinger_ddmconnection
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 2302367..4779804 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1067,6 +1067,16 @@
                 if (!front.activeTransparentRegion.isTriviallyEqual(
                         front.requestedTransparentRegion)) {
                     front.activeTransparentRegion = front.requestedTransparentRegion;
+
+                    // We also need to update the current state so that
+                    // we don't end-up overwriting the drawing state with
+                    // this stale current state during the next transaction
+                    //
+                    // NOTE: We don't need to hold the transaction lock here
+                    // because State::active is only accessed from this thread.
+                    current.activeTransparentRegion = front.activeTransparentRegion;
+
+                    // recompute visible region
                     recomputeVisibleRegions = true;
                 }
 
diff --git a/services/surfaceflinger/MessageQueue.cpp b/services/surfaceflinger/MessageQueue.cpp
index 3f77f74..c9c7b96 100644
--- a/services/surfaceflinger/MessageQueue.cpp
+++ b/services/surfaceflinger/MessageQueue.cpp
@@ -61,6 +61,12 @@
     }
 }
 
+void MessageQueue::Handler::dispatchTransaction() {
+    if ((android_atomic_or(eventMaskTransaction, &mEventMask) & eventMaskTransaction) == 0) {
+        mQueue.mLooper->sendMessage(this, Message(MessageQueue::TRANSACTION));
+    }
+}
+
 void MessageQueue::Handler::handleMessage(const Message& message) {
     switch (message.what) {
         case INVALIDATE:
@@ -71,6 +77,10 @@
             android_atomic_and(~eventMaskRefresh, &mEventMask);
             mQueue.mFlinger->onMessageReceived(message.what);
             break;
+        case TRANSACTION:
+            android_atomic_and(~eventMaskTransaction, &mEventMask);
+            mQueue.mFlinger->onMessageReceived(message.what);
+            break;
     }
 }
 
@@ -132,6 +142,7 @@
     return NO_ERROR;
 }
 
+
 /* when INVALIDATE_ON_VSYNC is set SF only processes
  * buffer updates on VSYNC and performs a refresh immediately
  * after.
@@ -143,6 +154,10 @@
  */
 #define INVALIDATE_ON_VSYNC 1
 
+void MessageQueue::invalidateTransactionNow() {
+    mHandler->dispatchTransaction();
+}
+
 void MessageQueue::invalidate() {
 #if INVALIDATE_ON_VSYNC
     mEvents->requestNextVsync();
diff --git a/services/surfaceflinger/MessageQueue.h b/services/surfaceflinger/MessageQueue.h
index 710b2c2..b77e08e 100644
--- a/services/surfaceflinger/MessageQueue.h
+++ b/services/surfaceflinger/MessageQueue.h
@@ -62,8 +62,9 @@
 class MessageQueue {
     class Handler : public MessageHandler {
         enum {
-            eventMaskInvalidate = 0x1,
-            eventMaskRefresh    = 0x2
+            eventMaskInvalidate     = 0x1,
+            eventMaskRefresh        = 0x2,
+            eventMaskTransaction    = 0x4
         };
         MessageQueue& mQueue;
         int32_t mEventMask;
@@ -72,6 +73,7 @@
         virtual void handleMessage(const Message& message);
         void dispatchRefresh();
         void dispatchInvalidate();
+        void dispatchTransaction();
     };
 
     friend class Handler;
@@ -89,8 +91,9 @@
 
 public:
     enum {
-        INVALIDATE = 0,
-        REFRESH    = 1,
+        INVALIDATE  = 0,
+        REFRESH     = 1,
+        TRANSACTION = 2
     };
 
     MessageQueue();
@@ -100,8 +103,13 @@
 
     void waitMessage();
     status_t postMessage(const sp<MessageBase>& message, nsecs_t reltime=0);
+
+    // sends INVALIDATE message at next VSYNC
     void invalidate();
+    // sends REFRESH message at next VSYNC
     void refresh();
+    // sends TRANSACTION message immediately
+    void invalidateTransactionNow();
 };
 
 // ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index a4426cd..dc29e48 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -744,6 +744,9 @@
 void SurfaceFlinger::onMessageReceived(int32_t what) {
     ATRACE_CALL();
     switch (what) {
+    case MessageQueue::TRANSACTION:
+        handleMessageTransaction();
+        break;
     case MessageQueue::INVALIDATE:
         handleMessageTransaction();
         handleMessageInvalidate();
@@ -1242,17 +1245,22 @@
                         if (disp == NULL) {
                             disp = hw;
                         } else {
-                            disp = getDefaultDisplayDevice();
+                            disp = NULL;
                             break;
                         }
                     }
                 }
             }
-            if (disp != NULL) {
-                // presumably this means this layer is using a layerStack
-                // that is not visible on any display
-                layer->updateTransformHint(disp);
+            if (disp == NULL) {
+                // NOTE: TEMPORARY FIX ONLY. Real fix should cause layers to
+                // redraw after transform hint changes. See bug 8508397.
+
+                // could be null when this layer is using a layerStack
+                // that is not visible on any display. Also can occur at
+                // screen off/on times.
+                disp = getDefaultDisplayDevice();
             }
+            layer->updateTransformHint(disp);
         }
     }
 
@@ -2626,6 +2634,13 @@
         }
     };
 
+    // make sure to process transactions before screenshots -- a transaction
+    // might already be pending but scheduled for VSYNC; this guarantees we
+    // will handle it before the screenshot. When VSYNC finally arrives
+    // the scheduled transaction will be a no-op. If no transactions are
+    // scheduled at this time, this will end-up being a no-op as well.
+    mEventQueue.invalidateTransactionNow();
+
     sp<MessageBase> msg = new MessageCaptureScreen(this,
             display, producer, reqWidth, reqHeight, minLayerZ, maxLayerZ,
             isCpuConsumer);
@@ -2636,6 +2651,61 @@
     return res;
 }
 
+
+void SurfaceFlinger::renderScreenImplLocked(
+        const sp<const DisplayDevice>& hw,
+        uint32_t reqWidth, uint32_t reqHeight,
+        uint32_t minLayerZ, uint32_t maxLayerZ,
+        bool yswap)
+{
+    ATRACE_CALL();
+
+    // get screen geometry
+    const uint32_t hw_w = hw->getWidth();
+    const uint32_t hw_h = hw->getHeight();
+
+    const bool filtering = reqWidth != hw_w || reqWidth != hw_h;
+
+    // make sure to clear all GL error flags
+    while ( glGetError() != GL_NO_ERROR ) ;
+
+    // set-up our viewport
+    glViewport(0, 0, reqWidth, reqHeight);
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    if (yswap)  glOrthof(0, hw_w, hw_h, 0, 0, 1);
+    else        glOrthof(0, hw_w, 0, hw_h, 0, 1);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+
+    // redraw the screen entirely...
+    glDisable(GL_SCISSOR_TEST);
+    glClearColor(0,0,0,1);
+    glClear(GL_COLOR_BUFFER_BIT);
+    glDisable(GL_TEXTURE_EXTERNAL_OES);
+    glDisable(GL_TEXTURE_2D);
+
+    const LayerVector& layers( mDrawingState.layersSortedByZ );
+    const size_t count = layers.size();
+    for (size_t i=0 ; i<count ; ++i) {
+        const sp<Layer>& layer(layers[i]);
+        const Layer::State& state(layer->drawingState());
+        if (state.layerStack == hw->getLayerStack()) {
+            if (state.z >= minLayerZ && state.z <= maxLayerZ) {
+                if (layer->isVisible()) {
+                    if (filtering) layer->setFiltering(true);
+                    layer->draw(hw);
+                    if (filtering) layer->setFiltering(false);
+                }
+            }
+        }
+    }
+
+    // compositionComplete is needed for older driver
+    hw->compositionComplete();
+}
+
+
 status_t SurfaceFlinger::captureScreenImplLocked(
         const sp<const DisplayDevice>& hw,
         const sp<IGraphicBufferProducer>& producer,
@@ -2662,7 +2732,6 @@
 
     reqWidth = (!reqWidth) ? hw_w : reqWidth;
     reqHeight = (!reqHeight) ? hw_h : reqHeight;
-    const bool filtering = reqWidth != hw_w || reqWidth != hw_h;
 
     // Create a surface to render into
     sp<Surface> surface = new Surface(producer);
@@ -2687,41 +2756,7 @@
         return BAD_VALUE;
     }
 
-    // make sure to clear all GL error flags
-    while ( glGetError() != GL_NO_ERROR ) ;
-
-    // set-up our viewport
-    glViewport(0, 0, reqWidth, reqHeight);
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    glOrthof(0, hw_w, 0, hw_h, 0, 1);
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity();
-
-    // redraw the screen entirely...
-    glDisable(GL_TEXTURE_EXTERNAL_OES);
-    glDisable(GL_TEXTURE_2D);
-    glClearColor(0,0,0,1);
-    glClear(GL_COLOR_BUFFER_BIT);
-
-    const LayerVector& layers( mDrawingState.layersSortedByZ );
-    const size_t count = layers.size();
-    for (size_t i=0 ; i<count ; ++i) {
-        const sp<Layer>& layer(layers[i]);
-        const Layer::State& state(layer->drawingState());
-        if (state.layerStack == hw->getLayerStack()) {
-            if (state.z >= minLayerZ && state.z <= maxLayerZ) {
-                if (layer->isVisible()) {
-                    if (filtering) layer->setFiltering(true);
-                    layer->draw(hw);
-                    if (filtering) layer->setFiltering(false);
-                }
-            }
-        }
-    }
-
-    // compositionComplete is needed for older driver
-    hw->compositionComplete();
+    renderScreenImplLocked(hw, reqWidth, reqHeight, minLayerZ, maxLayerZ, false);
 
     // and finishing things up...
     if (eglSwapBuffers(mEGLDisplay, eglSurface) != EGL_TRUE) {
@@ -2749,102 +2784,87 @@
         return INVALID_OPERATION;
     }
 
-    // create the texture that will receive the screenshot, later we'll
-    // attach a FBO to it so we can call glReadPixels().
-    GLuint tname;
-    glGenTextures(1, &tname);
-    glBindTexture(GL_TEXTURE_2D, tname);
-    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    // get screen geometry
+    const uint32_t hw_w = hw->getWidth();
+    const uint32_t hw_h = hw->getHeight();
 
-    // the GLConsumer will provide the BufferQueue
-    sp<GLConsumer> consumer = new GLConsumer(tname, true, GL_TEXTURE_2D);
-    consumer->getBufferQueue()->setDefaultBufferFormat(HAL_PIXEL_FORMAT_RGBA_8888);
-
-    // call the new screenshot taking code, passing a BufferQueue to it
-    status_t result = captureScreenImplLocked(hw,
-            consumer->getBufferQueue(), reqWidth, reqHeight, minLayerZ, maxLayerZ);
-
-    if (result == NO_ERROR) {
-        result = consumer->updateTexImage();
-        if (result == NO_ERROR) {
-            // create a FBO
-            GLuint name;
-            glGenFramebuffersOES(1, &name);
-            glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
-            glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
-                    GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
-
-            reqWidth = consumer->getCurrentBuffer()->getWidth();
-            reqHeight = consumer->getCurrentBuffer()->getHeight();
-
-            {
-                // in this block we render the screenshot into the
-                // CpuConsumer using glReadPixels from our GLConsumer,
-                // Some older drivers don't support the GL->CPU path so
-                // have to wrap it with a CPU->CPU path, which is what
-                // glReadPixels essentially is
-
-                sp<Surface> sur = new Surface(producer);
-                ANativeWindow* window = sur.get();
-                ANativeWindowBuffer* buffer;
-                void* vaddr;
-
-                if (native_window_api_connect(window,
-                        NATIVE_WINDOW_API_CPU) == NO_ERROR) {
-                    int err = 0;
-                    err = native_window_set_buffers_dimensions(window,
-                            reqWidth, reqHeight);
-                    err |= native_window_set_buffers_format(window,
-                            HAL_PIXEL_FORMAT_RGBA_8888);
-                    err |= native_window_set_usage(window,
-                            GRALLOC_USAGE_SW_READ_OFTEN |
-                            GRALLOC_USAGE_SW_WRITE_OFTEN);
-
-                    if (err == NO_ERROR) {
-                        if (native_window_dequeue_buffer_and_wait(window,
-                                &buffer) == NO_ERROR) {
-                            sp<GraphicBuffer> buf =
-                                    static_cast<GraphicBuffer*>(buffer);
-                            if (buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN,
-                                    &vaddr) == NO_ERROR) {
-                                if (buffer->stride != int(reqWidth)) {
-                                    // we're unlucky here, glReadPixels is
-                                    // not able to deal with a stride not
-                                    // equal to the width.
-                                    uint32_t* tmp = new uint32_t[reqWidth*reqHeight];
-                                    if (tmp != NULL) {
-                                        glReadPixels(0, 0, reqWidth, reqHeight,
-                                                GL_RGBA, GL_UNSIGNED_BYTE, tmp);
-                                        for (size_t y=0 ; y<reqHeight ; y++) {
-                                            memcpy((uint32_t*)vaddr + y*buffer->stride,
-                                                    tmp + y*reqWidth, reqWidth*4);
-                                        }
-                                        delete [] tmp;
-                                    }
-                                } else {
-                                    glReadPixels(0, 0, reqWidth, reqHeight,
-                                            GL_RGBA, GL_UNSIGNED_BYTE, vaddr);
-                                }
-                                buf->unlock();
-                            }
-                            window->queueBuffer(window, buffer, -1);
-                        }
-                    }
-                    native_window_api_disconnect(window, NATIVE_WINDOW_API_CPU);
-                }
-            }
-
-            // back to main framebuffer
-            glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
-            glDeleteFramebuffersOES(1, &name);
-        }
+    // if we have secure windows on this display, never allow the screen capture
+    if (hw->getSecureLayerVisible()) {
+        ALOGW("FB is protected: PERMISSION_DENIED");
+        return PERMISSION_DENIED;
     }
 
-    glDeleteTextures(1, &tname);
+    if ((reqWidth > hw_w) || (reqHeight > hw_h)) {
+        ALOGE("size mismatch (%d, %d) > (%d, %d)",
+                reqWidth, reqHeight, hw_w, hw_h);
+        return BAD_VALUE;
+    }
 
-    DisplayDevice::makeCurrent(mEGLDisplay,
-            getDefaultDisplayDevice(), mEGLContext);
+    reqWidth  = (!reqWidth)  ? hw_w : reqWidth;
+    reqHeight = (!reqHeight) ? hw_h : reqHeight;
+
+    GLuint tname;
+    glGenRenderbuffersOES(1, &tname);
+    glBindRenderbufferOES(GL_RENDERBUFFER_OES, tname);
+    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, reqWidth, reqHeight);
+
+    // create a FBO
+    GLuint name;
+    glGenFramebuffersOES(1, &name);
+    glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
+    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
+            GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, tname);
+
+    GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
+
+    status_t result = NO_ERROR;
+    if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
+
+        renderScreenImplLocked(hw, reqWidth, reqHeight, minLayerZ, maxLayerZ, true);
+
+        // Below we render the screenshot into the
+        // CpuConsumer using glReadPixels from our FBO.
+        // Some older drivers don't support the GL->CPU path so we
+        // have to wrap it with a CPU->CPU path, which is what
+        // glReadPixels essentially is.
+
+        sp<Surface> sur = new Surface(producer);
+        ANativeWindow* window = sur.get();
+
+        if (native_window_api_connect(window, NATIVE_WINDOW_API_CPU) == NO_ERROR) {
+            int err = 0;
+            err = native_window_set_buffers_dimensions(window, reqWidth, reqHeight);
+            err |= native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
+            err |= native_window_set_usage(window,
+                    GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
+
+            if (err == NO_ERROR) {
+                ANativeWindowBuffer* buffer;
+                if (native_window_dequeue_buffer_and_wait(window,  &buffer) == NO_ERROR) {
+                    sp<GraphicBuffer> buf = static_cast<GraphicBuffer*>(buffer);
+                    void* vaddr;
+                    if (buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, &vaddr) == NO_ERROR) {
+                        glReadPixels(0, 0, buffer->stride, reqHeight,
+                                GL_RGBA, GL_UNSIGNED_BYTE, vaddr);
+                        buf->unlock();
+                    }
+                    window->queueBuffer(window, buffer, -1);
+                }
+            }
+            native_window_api_disconnect(window, NATIVE_WINDOW_API_CPU);
+        }
+
+    } else {
+        ALOGE("got GL_FRAMEBUFFER_COMPLETE_OES while taking screenshot");
+        result = INVALID_OPERATION;
+    }
+
+    // back to main framebuffer
+    glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
+    glDeleteRenderbuffersOES(1, &tname);
+    glDeleteFramebuffersOES(1, &name);
+
+    DisplayDevice::setViewportAndProjection(hw);
 
     return result;
 }
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 57ee8b9..739099c 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -288,6 +288,12 @@
 
     void startBootAnim();
 
+    void renderScreenImplLocked(
+            const sp<const DisplayDevice>& hw,
+            uint32_t reqWidth, uint32_t reqHeight,
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool yswap);
+
     status_t captureScreenImplLocked(
             const sp<const DisplayDevice>& hw,
             const sp<IGraphicBufferProducer>& producer,