updated Animation Plugin for NativeWindow interface

bug:5114637

Uses new ANativeWindow plugin API, supports either software rendering or GL
rendering via flag in RenderingThread.h

Note: Currently crashes on close

Change-Id: Ia7338a6c38c0ca9db02c19814d99b29970cc7b8e
diff --git a/samples/BrowserPlugin/jni/animation/AnimationThread.cpp b/samples/BrowserPlugin/jni/animation/AnimationThread.cpp
index 9e6342d..1388fe3 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationThread.cpp
+++ b/samples/BrowserPlugin/jni/animation/AnimationThread.cpp
@@ -23,14 +23,12 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "AnimationThread.h"
-#include "ANPOpenGL_npapi.h"
 
-#include <EGL/egl.h>
-#include <GLES2/gl2.h>
 #include <utils/SystemClock.h>
+#include "ANPNativeWindow_npapi.h"
 
-extern ANPLogInterfaceV0       gLogI;
-extern ANPOpenGLInterfaceV0    gOpenGLI;
+extern ANPLogInterfaceV0           gLogI;
+extern ANPNativeWindowInterfaceV0  gNativeWindowI;
 
 AnimationThread::AnimationThread(NPP npp) : RenderingThread(npp) {
     m_counter = 0;
@@ -52,6 +50,8 @@
 
     m_startExecutionTime = 0;
     m_startTime = android::uptimeMillis();
+    m_stallTime = android::uptimeMillis();
+
 }
 
 AnimationThread::~AnimationThread() {
@@ -84,15 +84,14 @@
 }
 
 bool AnimationThread::threadLoop() {
-
-    m_startIdleTime = android::uptimeMillis();
-
-    ANPTextureInfo textureInfo = gOpenGLI.lockTexture(m_npp);
-    GLuint textureId = textureInfo.textureId;
+    if (android::uptimeMillis() - m_stallTime < MS_PER_FRAME)
+        return true;
+    m_stallTime = android::uptimeMillis();
 
     m_idleTime += android::uptimeMillis() - m_startIdleTime;
     m_startExecutionTime = android::uptimeMillis();
 
+    bool reCreateFlag = false;
     int width, height;
     getDimensions(width, height);
 
@@ -110,6 +109,7 @@
         // change the ball's speed to match the size
         m_dx = width * .005f;
         m_dy = height * .007f;
+        reCreateFlag = true;
     }
 
     // setup variables
@@ -131,20 +131,15 @@
     m_paint->setColor(0xAAFF0000);
     m_canvas->drawOval(m_oval, *m_paint);
 
-    if (textureInfo.width == width && textureInfo.height == height) {
-        updateTextureWithBitmap(textureId, *m_bitmap);
+    if (!reCreateFlag) {
+        updateNativeWindow(m_ANW, *m_bitmap);
     } else {
-        createTextureWithBitmap(textureId, *m_bitmap);
-        textureInfo.width = width;
-        textureInfo.height = height;
-        textureInfo.internalFormat = GL_RGBA;
+        setupNativeWindow(m_ANW, *m_bitmap);
     }
 
     m_executionTime += android::uptimeMillis() - m_startExecutionTime;
     m_counter++;
 
-    gOpenGLI.releaseTexture(m_npp, &textureInfo);
-
     if (android::uptimeMillis() - m_lastPrintTime > 5000) {
         float fps = m_counter / ((android::uptimeMillis() - m_startTime) / 1000);
         float spf = ((android::uptimeMillis() - m_startTime)) / m_counter;
@@ -160,5 +155,6 @@
         m_startTime = android::uptimeMillis();
     }
 
+    m_startIdleTime = android::uptimeMillis(); // count delay between frames
     return true;
 }
diff --git a/samples/BrowserPlugin/jni/animation/AnimationThread.h b/samples/BrowserPlugin/jni/animation/AnimationThread.h
index 4f74e94..e95ecce 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationThread.h
+++ b/samples/BrowserPlugin/jni/animation/AnimationThread.h
@@ -48,6 +48,7 @@
     int64_t m_startTime;
     int64_t m_startExecutionTime;
     int64_t m_startIdleTime;
+    int64_t m_stallTime;
 
     float m_x;
     float m_y;