remove libagl's dependency on gralloc_priv.h
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
index d1ed82e..2522656 100644
--- a/opengl/libagl/Android.mk
+++ b/opengl/libagl/Android.mk
@@ -38,7 +38,6 @@
 ifeq ($(LIBAGL_USE_GRALLOC_COPYBITS),1)
     LOCAL_CFLAGS += -DLIBAGL_USE_GRALLOC_COPYBITS
     LOCAL_SRC_FILES += copybit.cpp
-    LOCAL_C_INCLUDES += hardware/libhardware/modules/gralloc
 endif
 
 LOCAL_CFLAGS += -DLOG_TAG=\"libagl\"
diff --git a/opengl/libagl/copybit.cpp b/opengl/libagl/copybit.cpp
index 3331026..3c5bcdf 100644
--- a/opengl/libagl/copybit.cpp
+++ b/opengl/libagl/copybit.cpp
@@ -295,6 +295,9 @@
 
     clipRectRegion it(c);
     status_t err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
+    if (err != NO_ERROR) {
+        c->textures.tmu[0].texture->try_copybit = false;
+    }
     return err == NO_ERROR ? true : false;
 }
 
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp
index 6f6656a..7afcae7 100644
--- a/opengl/libagl/egl.cpp
+++ b/opengl/libagl/egl.cpp
@@ -48,10 +48,6 @@
 #include "texture.h"
 #include "matrix.h"
 
-#ifdef LIBAGL_USE_GRALLOC_COPYBITS
-#include "gralloc_priv.h"
-#endif // LIBAGL_USE_GRALLOC_COPYBITS
-
 #undef NELEM
 #define NELEM(x) (sizeof(x)/sizeof(*(x)))
 
@@ -622,11 +618,10 @@
 
 #ifdef LIBAGL_USE_GRALLOC_COPYBITS
     gl->copybits.drawSurfaceBuffer = 0;
-    if (supportedCopybitsDestinationFormat(buffer.format)) {
-        buffer_handle_t handle = this->buffer->handle;
-        if (handle != NULL) {
-            private_handle_t* hand = private_handle_t::dynamicCast(handle);
-            if (hand != NULL && hand->usesPhysicallyContiguousMemory()) {
+    if (gl->copybits.blitEngine != NULL) {
+        if (supportedCopybitsDestinationFormat(buffer.format)) {
+            buffer_handle_t handle = this->buffer->handle;
+            if (handle != NULL) {
                 gl->copybits.drawSurfaceBuffer = handle;
             }
         }
diff --git a/opengl/libagl/texture.cpp b/opengl/libagl/texture.cpp
index d767c31..4d3c2f4 100644
--- a/opengl/libagl/texture.cpp
+++ b/opengl/libagl/texture.cpp
@@ -27,7 +27,6 @@
 
 #ifdef LIBAGL_USE_GRALLOC_COPYBITS
 #include "copybit.h"
-#include "gralloc_priv.h"
 #endif // LIBAGL_USE_GRALLOC_COPYBITS
 
 namespace android {
@@ -1540,20 +1539,9 @@
     sp<EGLTextureObject> tex = getAndBindActiveTextureObject(c);
     tex->setImage(native_buffer);
 
-    /*
-     * Here an implementation can retrieve the buffer_handle_t of this buffer
-     * which gives it access to an arbitrary-defined kernel resource
-     * (or anything else for that matter).
-     * There needs to be an intimate knowledge between GLES and buffer_handle_t,
-     * so make sure to validate the handle before using it.
-     * Typically, buffer_handle_t comes from the gralloc HAL which is provided
-     * by the implementor of GLES.
-     *
-     */
 #ifdef LIBAGL_USE_GRALLOC_COPYBITS
     tex->try_copybit = false;
-    private_handle_t* hnd = private_handle_t::dynamicCast(native_buffer->handle);
-    if (hnd && hnd->usesPhysicallyContiguousMemory()) {
+    if (c->copybits.blitEngine != NULL) {
         tex->try_copybit = true;
     }
 #endif // LIBAGL_USE_GRALLOC_COPYBITS