Code changes for ANGLE GL interface. .gyp file changes will be delivered later.

http://codereview.appspot.com/5940046/



git-svn-id: http://skia.googlecode.com/svn/trunk@3519 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index ddd33ed..dc522b6 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -130,7 +130,11 @@
 class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
 public:
 
-    DefaultDeviceManager() {
+    DefaultDeviceManager()
+#if SK_ANGLE
+    : fUseAltContext(false) 
+#endif
+    {
         fGrRenderTarget = NULL;
         fGrContext = NULL;
         fGL = NULL;
@@ -146,12 +150,32 @@
         SkSafeUnref(fNullGrRenderTarget);
     }
 
-    virtual void init(SampleWindow* win) {
-        if (!win->attachGL()) {
+    virtual void init(SampleWindow* win, bool useAltContext) {
+#if SK_ANGLE
+        fUseAltContext = useAltContext;
+#endif
+        bool result;
+
+#if SK_ANGLE
+        if (useAltContext) {
+            result = win->attachANGLE();
+        } else 
+#endif
+        {
+            result = win->attachGL();
+        }
+        if (!result) {
             SkDebugf("Failed to initialize GL");
         }
         if (NULL == fGL) {
-            fGL = GrGLCreateNativeInterface();
+#if SK_ANGLE
+            if (useAltContext) {
+                fGL = GrGLCreateANGLEInterface();
+            } else 
+#endif
+            {
+                fGL = GrGLCreateNativeInterface();
+            }
             GrAssert(NULL == fGrContext);
             fGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine,
                                            (GrPlatform3DContext) fGL);
@@ -160,7 +184,14 @@
             SkSafeUnref(fGrContext);
             SkSafeUnref(fGL);
             SkDebugf("Failed to setup 3D");
-            win->detachGL();
+#if SK_ANGLE
+            if (useAltContext) {
+                win->detachANGLE();
+            } else 
+#endif
+            {
+                win->detachGL();
+            }
         }
         if (NULL == fNullGrContext) {
             const GrGLInterface* nullGL = GrGLCreateNullInterface();
@@ -231,12 +262,26 @@
                                              bm.rowBytes());
             }
         }
-        win->presentGL();
+#if SK_ANGLE
+        if (fUseAltContext) {
+            win->presentANGLE();
+        } else 
+#endif
+        {
+            win->presentGL();
+        }
     }
 
     virtual void windowSizeChanged(SampleWindow* win) {
         if (fGrContext) {
-            win->attachGL();
+#if SK_ANGLE
+            if (fUseAltContext) {
+                win->attachANGLE();
+            } else 
+#endif
+            {
+                win->attachGL();
+            }
 
             GrPlatformRenderTargetDesc desc;
             desc.fWidth = SkScalarRound(win->width());
@@ -271,6 +316,9 @@
         }
     }
 private:
+#if SK_ANGLE
+    bool fUseAltContext;
+#endif
     GrContext* fGrContext;
     const GrGLInterface* fGL;
     GrRenderTarget* fGrRenderTarget;
@@ -621,6 +669,7 @@
 
     const char* resourcePath = NULL;
     fCurrIndex = -1;
+    bool useAltContext = false;
 
     const char* const commandName = argv[0];
     char* const* stop = argv + argc;
@@ -638,7 +687,14 @@
                     fprintf(stderr, "Unknown sample \"%s\"\n", *argv);
                 }
             }
-        } else {
+        } 
+#if SK_ANGLE
+        else if (strcmp(*argv, "--angle") == 0) {
+            argv++;
+            useAltContext = true;
+        } 
+#endif
+        else {
             usage(commandName);
         }
     }
@@ -769,7 +825,7 @@
         devManager->ref();
         fDevManager = devManager;
     }
-    fDevManager->init(this);
+    fDevManager->init(this, useAltContext);
 
     // If another constructor set our dimensions, ensure that our
     // onSizeChange gets called.