Merge changes from mozilla-central to electrolysis
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 30 Jun 2009 12:04:18 -0400
changeset 35738 b44e0c08c4cf52b7a5a87049ef5e1565cb439f54
parent 35737 df1133412587e158f5965b9f423b27f51896f240 (current diff)
parent 29849 98175b57424c6e02fe600dcc8a628f4996ccfc5f (diff)
child 35739 f5675fec1a8d6998c5d753aad794b3e3e951a5f7
push idunknown
push userunknown
push dateunknown
milestone1.9.2a1pre
Merge changes from mozilla-central to electrolysis
accessible/public/nsIAccessibleTreeCache.idl
config/autoconf.mk.in
configure.in
content/html/document/reftests/bug448564-2_malformed.html
content/html/document/reftests/bug448564-2_well-formed.html
content/html/document/reftests/bug448564-3_malformed.html
content/html/document/reftests/bug448564-3_well-formed.html
content/html/document/reftests/bug448564-5_malformed.html
content/html/document/reftests/bug448564-5_well-formed.html
dom/public/coreEvents/nsIDOMXULListener.h
modules/plugin/base/public/nsIPluginInstancePeer.idl
modules/plugin/base/public/nsIPluginInstancePeer2.idl
modules/plugin/base/public/nsPIPluginInstancePeer.idl
modules/plugin/base/public/nsplugin.h
modules/plugin/base/src/nsPluginInstancePeer.cpp
modules/plugin/base/src/nsPluginInstancePeer.h
toolkit/library/libxul-config.mk
toolkit/toolkit-tiers.mk
--- a/accessible/public/Makefile.in
+++ b/accessible/public/Makefile.in
@@ -68,16 +68,10 @@ XPIDLSRCS = \
       nsIAccessibleHyperText.idl \
       nsIAccessibleTable.idl \
       nsIAccessibleText.idl \
       nsIAccessibleValue.idl \
       nsIAccessibleImage.idl \
       nsIXBLAccessible.idl \
       $(NULL)
 
-ifdef MOZ_XUL
-XPIDLSRCS += \
-      nsIAccessibleTreeCache.idl \
-      $(NULL)
-endif
-
 include $(topsrcdir)/config/rules.mk
 
deleted file mode 100644
--- a/accessible/public/nsIAccessibleTreeCache.idl
+++ /dev/null
@@ -1,101 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Louie Zhao <Louie.Zhao@sun.com> (original author)
- *   Alexander Surkov <surkov.alexander@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.idl"
-#include "nsITreeColumns.idl"
-
-interface nsIAccessible;
-
-/**
- * A private interface to operate with tree accessible.
- *
- * @status UNDER_REVIEW
- */
-[uuid(1dde5c3b-bede-43d1-aabf-dabc461113bd)]
-interface nsIAccessibleTreeCache : nsISupports
-{
-  /**
-   * Get tree item from cache according to row and column, create if doesn't
-   * exist in cache.
-   *
-   * @param aRow     the given row index
-   * @param aColumn  the given column object. If is is nsnull then primary
-   *                 column is used. It makes sense for ATK only.
-   */
-  nsIAccessible getCachedTreeitemAccessible(in long aRow,
-                                            in nsITreeColumn aColumn);
-
-  /**
-   * Invalidates the number of cached treeitem accessibles.
-   *
-   * @param aRow    row index the invalidation starts from
-   * @param aCount  the number of treeitem accessibles to invalidate,
-   *                the number sign specifies whether rows have been
-   *                inserted (plus) or removed (minus)
-   */
-  void invalidateCache(in long aRow, in long aCount);
-
-  /**
-   * Fires name change events for invalidated area of tree.
-   *
-   * @param aStartRow  row index invalidation starts from
-   * @param aEndRow    row index invalidation ends, -1 means last row index
-   * @param aStartCol  column index invalidation starts from
-   * @param aEndCol    column index invalidation ends, -1 mens last column
-   *                   index
-   */
-  void treeViewInvalidated(in long aStartRow, in long aEndRow,
-                           in long aStartCol, in long aEndCol);
-
-  /**
-   * Invalidates children created for previous tree view.
-   */
-  void treeViewChanged();
-
-};
-
-[uuid(b71532f9-53b2-4647-a5b2-1c5f57e9aed6)]
-interface nsPIAccessibleTreeItem : nsISupports
-{
-  /**
-   * Get/set cached name.
-   */
-  attribute AString cachedName;
-};
-
--- a/accessible/src/base/nsARIAMap.cpp
+++ b/accessible/src/base/nsARIAMap.cpp
@@ -118,17 +118,17 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
   {
     "columnheader",
     nsIAccessibleRole::ROLE_COLUMNHEADER,
     kUseMapRole,
     eNoValue,
     eSortAction,
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected,
+    eARIASelectable,
     eARIAReadonly
   },
   {
     "combobox",
     nsIAccessibleRole::ROLE_COMBOBOX,
     kUseMapRole,
     eHasValueMinMax,
     eOpenCloseAction,
@@ -169,17 +169,17 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
   {
     "gridcell",
     nsIAccessibleRole::ROLE_GRID_CELL,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected,
+    eARIASelectable,
     eARIAReadonly
   },
   {
     "group",
     nsIAccessibleRole::ROLE_GROUPING,
     kUseMapRole,
     eNoValue,
     eNoAction,
@@ -246,17 +246,17 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
   {
     "listitem",
     nsIAccessibleRole::ROLE_LISTITEM,
     kUseMapRole,
     eNoValue,
     eNoAction, // XXX: should depend on state, parent accessible
     eNoLiveAttr,
     nsIAccessibleStates::STATE_READONLY,
-    eARIASelected,
+    eARIASelectable,
     eARIACheckedMixed
   },
   {
     "log",
     nsIAccessibleRole::ROLE_NOTHING,
     kUseNativeRole,
     eNoValue,
     eNoAction,
@@ -333,17 +333,17 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
   {
     "option",
     nsIAccessibleRole::ROLE_OPTION,
     kUseMapRole,
     eNoValue,
     eSelectAction,
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected,
+    eARIASelectable,
     eARIACheckedMixed
   },
   {
     "presentation",
     nsIAccessibleRole::ROLE_NOTHING,
     kUseMapRole,
     eNoValue,
     eNoAction,
@@ -390,27 +390,27 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
   {
     "row",
     nsIAccessibleRole::ROLE_ROW,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected
+    eARIASelectable
   },
   {
     "rowheader",
     nsIAccessibleRole::ROLE_ROWHEADER,
     kUseMapRole,
     eNoValue,
     eSortAction,
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected,
+    eARIASelectable,
     eARIAReadonly
   },
   {
     "section",
     nsIAccessibleRole::ROLE_SECTION,
     kUseMapRole,
     eNoValue,
     eNoAction,
@@ -547,17 +547,17 @@ nsRoleMapEntry nsARIAMap::gWAIRoleMap[] 
     "treeitem",
     nsIAccessibleRole::ROLE_OUTLINEITEM,
     kUseMapRole,
     eNoValue,
     eActivateAction, // XXX: should expose second 'expand/collapse' action based
                      // on states
     eNoLiveAttr,
     kNoReqStates,
-    eARIASelected,
+    eARIASelectable,
     eARIACheckedMixed
   }
 };
 
 PRUint32 nsARIAMap::gWAIRoleMapLength = NS_ARRAY_LENGTH(nsARIAMap::gWAIRoleMap);
 
 nsRoleMapEntry nsARIAMap::gLandmarkRoleMap = {
   "",
@@ -650,20 +650,21 @@ nsStateMapEntry nsARIAMap::gWAIStateMap[
   nsStateMapEntry(&nsAccessibilityAtoms::aria_readonly, kBoolType, 0,
                   nsIAccessibleStates::STATE_READONLY, 0,
                   0, nsIAccessibleStates::EXT_STATE_EDITABLE, PR_TRUE),
 
   // eARIARequired
   nsStateMapEntry(&nsAccessibilityAtoms::aria_required, kBoolType, 0,
                   nsIAccessibleStates::STATE_REQUIRED, 0),
 
-  // eARIASelected
+  // eARIASelectable
   nsStateMapEntry(&nsAccessibilityAtoms::aria_selected, kBoolType,
                   nsIAccessibleStates::STATE_SELECTABLE,
-                  nsIAccessibleStates::STATE_SELECTED, 0)
+                  nsIAccessibleStates::STATE_SELECTED, 0,
+                  0, 0, PR_TRUE)
 };
 
 /**
  * Universal states:
  * The following state rules are applied to any accessible element,
  * whether there is an ARIA role or not:
  */
 eStateMapEntryID nsARIAMap::gWAIUnivStateMap[] = {
--- a/accessible/src/base/nsARIAMap.h
+++ b/accessible/src/base/nsARIAMap.h
@@ -173,17 +173,17 @@ enum eStateMapEntryID
   eARIAHasPopup,
   eARIAInvalid,
   eARIAMultiline,
   eARIAMultiSelectable,
   eARIAPressed,
   eARIAReadonly,
   eARIAReadonlyOrEditable,
   eARIARequired,
-  eARIASelected
+  eARIASelectable
 };
 
 class nsStateMapEntry
 {
 public:
   /**
    * Used to create stub.
    */
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -45,16 +45,17 @@
 #include "nsAccessibleEventData.h"
 #include "nsHyperTextAccessible.h"
 #include "nsHTMLTableAccessible.h"
 #include "nsDocAccessible.h"
 #include "nsAccessibilityAtoms.h"
 #include "nsAccessibleTreeWalker.h"
 #include "nsAccessible.h"
 #include "nsARIAMap.h"
+#include "nsXULTreeAccessible.h"
 
 #include "nsIDOMXULContainerElement.h"
 #include "nsIDOMXULSelectCntrlEl.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsWhitespaceTokenizer.h"
 
 void
 nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
@@ -763,16 +764,38 @@ nsAccUtils::QueryAccessibleDocument(nsIA
 {
   nsDocAccessible* accessible = nsnull;
   if (aAccessibleDocument)
     CallQueryInterface(aAccessibleDocument, &accessible);
 
   return accessible;
 }
 
+#ifdef MOZ_XUL
+already_AddRefed<nsXULTreeAccessible>
+nsAccUtils::QueryAccessibleTree(nsIAccessible *aAccessible)
+{
+  nsXULTreeAccessible* accessible = nsnull;
+  if (aAccessible)
+    CallQueryInterface(aAccessible, &accessible);
+
+  return accessible;
+}
+
+already_AddRefed<nsXULTreeitemAccessible>
+nsAccUtils::QueryAccessibleTreeitem(nsIAccessNode *aAccessNode)
+{
+  nsXULTreeitemAccessible* accessible = nsnull;
+  if (aAccessNode)
+    CallQueryInterface(aAccessNode, &accessible);
+
+  return accessible;
+}
+#endif
+
 #ifdef DEBUG_A11Y
 
 PRBool
 nsAccUtils::IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible)
 {
   PRBool foundText = PR_FALSE;
   
   nsCOMPtr<nsIAccessibleDocument> accDoc = do_QueryInterface(aAccessible);
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -51,16 +51,20 @@
 #include "nsIPersistentProperties2.h"
 #include "nsIContent.h"
 #include "nsPoint.h"
 
 class nsAccessNode;
 class nsAccessible;
 class nsHTMLTableAccessible;
 class nsDocAccessible;
+#ifdef MOZ_XUL
+class nsXULTreeAccessible;
+class nsXULTreeitemAccessible;
+#endif
 
 class nsAccUtils
 {
 public:
   /**
    * Returns value of attribute from the given attributes container.
    *
    * @param aAttributes - attributes container
@@ -349,16 +353,30 @@ public:
     QueryAccessibleDocument(nsIAccessible *aAccessible);
 
   /**
    * Query nsDocAccessible from the given nsIAccessibleDocument.
    */
   static already_AddRefed<nsDocAccessible>
     QueryAccessibleDocument(nsIAccessibleDocument *aAccessibleDocument);
 
+#ifdef MOZ_XUL
+  /**
+   * Query nsXULTreeAccessible from the given nsIAccessible.
+   */
+  static already_AddRefed<nsXULTreeAccessible>
+    QueryAccessibleTree(nsIAccessible *aAccessible);
+
+  /**
+   * Query nsXULTreeitemAccessible from the given nsIAccessNode.
+   */
+  static already_AddRefed<nsXULTreeitemAccessible>
+    QueryAccessibleTreeitem(nsIAccessNode *aAccessNode);
+#endif
+
 #ifdef DEBUG_A11Y
   /**
    * Detect whether the given accessible object implements nsIAccessibleText,
    * when it is text or has text child node.
    */
   static PRBool IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible);
 #endif
 
--- a/accessible/src/base/nsAccessibleEventData.cpp
+++ b/accessible/src/base/nsAccessibleEventData.cpp
@@ -263,42 +263,37 @@ nsAccEvent::GetAccessibleByNode()
 
   nsCOMPtr<nsIAccessibilityService> accService = 
     do_GetService("@mozilla.org/accessibilityService;1");
   if (!accService)
     return nsnull;
 
   nsIAccessible *accessible = nsnull;
   accService->GetAccessibleFor(mDOMNode, &accessible);
+
 #ifdef MOZ_XUL
   // hack for xul tree table. We need a better way for firing delayed event
   // against xul tree table. see bug 386821.
   // There will be problem if some day we want to fire delayed event against
   // the xul tree itself or an unselected treeitem.
   nsAutoString localName;
   mDOMNode->GetLocalName(localName);
   if (localName.EqualsLiteral("tree")) {
     nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
       do_QueryInterface(mDOMNode);
     if (multiSelect) {
       PRInt32 treeIndex = -1;
       multiSelect->GetCurrentIndex(&treeIndex);
       if (treeIndex >= 0) {
-        nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(accessible));
-        NS_IF_RELEASE(accessible);
-        nsCOMPtr<nsIAccessible> treeItemAccessible;
-        if (!treeCache ||
-            NS_FAILED(treeCache->GetCachedTreeitemAccessible(
-                      treeIndex,
-                      nsnull,
-                      getter_AddRefs(treeItemAccessible))) ||
-                      !treeItemAccessible) {
-          return nsnull;
+        nsRefPtr<nsXULTreeAccessible> treeCache =
+          nsAccUtils::QueryAccessibleTree(accessible);
+        if (treeCache) {
+          treeCache->GetCachedTreeitemAccessible(treeIndex, nsnull,
+                                                 &accessible);
         }
-        NS_IF_ADDREF(accessible = treeItemAccessible);
       }
     }
   }
 #endif
 
   return accessible;
 }
 
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -252,22 +252,21 @@ void
 nsDocAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
 {
   NS_ASSERTION(mDocument, "No document during initialization!");
   if (!mDocument)
     return;
 
   mRoleMapEntry = aRoleMapEntry;
 
+  nsIDocument *parentDoc = mDocument->GetParentDocument();
+  if (!parentDoc)
+    return; // No parent document for the root document
+
   // Allow use of ARIA role from outer to override
-  nsIDocument *parentDoc = mDocument->GetParentDocument();
-  NS_ASSERTION(parentDoc, "No parent document during initialization!");
-  if (!parentDoc)
-    return;
-
   nsIContent *ownerContent = parentDoc->FindContentForSubDocument(mDocument);
   nsCOMPtr<nsIDOMNode> ownerNode(do_QueryInterface(ownerContent));
   if (ownerNode) {
     nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(ownerNode);
     if (roleMapEntry)
       mRoleMapEntry = roleMapEntry; // Override
   }
 }
@@ -802,18 +801,36 @@ nsresult nsDocAccessible::AddEventListen
 }
 
 nsresult nsDocAccessible::RemoveEventListeners()
 {
   // Remove listeners associated with content documents
   // Remove scroll position listener
   RemoveScrollListener();
 
-  // Remove document observer
-  mDocument->RemoveObserver(this);
+  NS_ASSERTION(mDocument, "No document during removal of listeners.");
+
+  if (mDocument) {
+    mDocument->RemoveObserver(this);
+
+    nsCOMPtr<nsISupports> container = mDocument->GetContainer();
+    nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
+    NS_ASSERTION(docShellTreeItem, "doc should support nsIDocShellTreeItem.");
+
+    if (docShellTreeItem) {
+      PRInt32 itemType;
+      docShellTreeItem->GetItemType(&itemType);
+      if (itemType == nsIDocShellTreeItem::typeContent) {
+        nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
+        if (commandManager) {
+          commandManager->RemoveCommandObserver(this, "obs_documentCreated");
+        }
+      }
+    }
+  }
 
   if (mScrollWatchTimer) {
     mScrollWatchTimer->Cancel();
     mScrollWatchTimer = nsnull;
     NS_RELEASE_THIS(); // Kung fu death grip
   }
 
   nsRefPtr<nsRootAccessible> rootAccessible(GetRootAccessible());
@@ -821,29 +838,16 @@ nsresult nsDocAccessible::RemoveEventLis
     nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
     if (caretAccessible) {
       // Don't use GetPresShell() which can call Shutdown() if it sees dead pres shell
       nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
       caretAccessible->RemoveDocSelectionListener(presShell);
     }
   }
 
-  nsCOMPtr<nsISupports> container = mDocument->GetContainer();
-  nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
-  NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
-
-  PRInt32 itemType;
-  docShellTreeItem->GetItemType(&itemType);
-  if (itemType == nsIDocShellTreeItem::typeContent) {
-    nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShellTreeItem);
-    if (commandManager) {
-      commandManager->RemoveCommandObserver(this, "obs_documentCreated");
-    }
-  }
-
   return NS_OK;
 }
 
 void
 nsDocAccessible::FireAnchorJumpEvent()
 {
   if (!mIsContentLoaded || !mDocument)
     return;
@@ -1046,16 +1050,27 @@ NS_IMETHODIMP nsDocAccessible::Observe(n
   ///////////////////////////////////////////////////////////////////////
 // nsIDocumentObserver
 
 NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(nsDocAccessible)
 NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsDocAccessible)
 NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(nsDocAccessible)
 
 void
+nsDocAccessible::AttributeWillChange(nsIDocument *aDocument,
+                                     nsIContent* aContent, PRInt32 aNameSpaceID,
+                                     nsIAtom* aAttribute, PRInt32 aModType)
+{
+  // XXX TODO: bugs 381599 467143 472142 472143
+  // Here we will want to cache whatever state we are potentially interested in,
+  // such as the existence of aria-pressed for button (so we know if we need to
+  // newly expose it as a toggle button) etc.
+}
+
+void
 nsDocAccessible::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
                                   PRInt32 aNameSpaceID, nsIAtom* aAttribute,
                                   PRInt32 aModType, PRUint32 aStateMask)
 {
   AttributeChangedImpl(aContent, aNameSpaceID, aAttribute);
 
   // If it was the focused node, cache the new state
   nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(aContent);
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -664,23 +664,26 @@ nsresult nsRootAccessible::HandleEventWi
     return HandlePopupHidingEvent(aTargetNode, accessible);
 
   nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessible));
   if (!acc)
     return NS_OK;
 
 #ifdef MOZ_XUL
   if (isTree) {
-    nsCOMPtr<nsIAccessibleTreeCache> treeAcc(do_QueryInterface(accessible));
+    nsRefPtr<nsXULTreeAccessible> treeAcc =
+      nsAccUtils::QueryAccessibleTree(accessible);
     NS_ASSERTION(treeAcc,
-                 "Accessible for xul:tree doesn't implement nsIAccessibleTreeCache interface.");
+                 "Accessible for xul:tree isn't nsXULTreeAccessible.");
 
     if (treeAcc) {
-      if (eventType.EqualsLiteral("TreeViewChanged"))
-        return treeAcc->TreeViewChanged();
+      if (eventType.EqualsLiteral("TreeViewChanged")) {
+        treeAcc->TreeViewChanged();
+        return NS_OK;
+      }
 
       if (eventType.EqualsLiteral("TreeRowCountChanged"))
         return HandleTreeRowCountChangedEvent(aEvent, treeAcc);
       
       if (eventType.EqualsLiteral("TreeInvalidated"))
         return HandleTreeInvalidatedEvent(aEvent, treeAcc);
     }
   }
@@ -725,26 +728,24 @@ nsresult nsRootAccessible::HandleEventWi
   // If it's a tree element, need the currently selected item
   if (isTree) {
     nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
       do_QueryInterface(aTargetNode);
     if (multiSelect) {
       PRInt32 treeIndex = -1;
       multiSelect->GetCurrentIndex(&treeIndex);
       if (treeIndex >= 0) {
-        nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(accessible));
-        if (!treeCache ||
-            NS_FAILED(treeCache->GetCachedTreeitemAccessible(
-                      treeIndex,
-                      nsnull,
-                      getter_AddRefs(treeItemAccessible))) ||
-                      !treeItemAccessible) {
-          return NS_ERROR_OUT_OF_MEMORY;
+        nsRefPtr<nsXULTreeAccessible> treeCache =
+          nsAccUtils::QueryAccessibleTree(accessible);
+        if (treeCache) {
+          treeCache->GetCachedTreeitemAccessible(treeIndex, nsnull,
+                                                 getter_AddRefs(treeItemAccessible));
+          if (treeItemAccessible)
+            accessible = treeItemAccessible;
         }
-        accessible = treeItemAccessible;
       }
     }
   }
 #endif
 
 #ifdef MOZ_XUL
   if (treeItemAccessible && eventType.EqualsLiteral("OpenStateChange")) {
     PRUint32 state = nsAccUtils::State(accessible); // collapsed/expanded changed
@@ -1176,17 +1177,17 @@ nsRootAccessible::HandlePopupHidingEvent
   }
 
   return NS_OK;
 }
 
 #ifdef MOZ_XUL
 nsresult
 nsRootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
-                                                 nsIAccessibleTreeCache *aAccessible)
+                                                 nsXULTreeAccessible *aAccessible)
 {
   nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
   if (!dataEvent)
     return NS_OK;
 
   nsCOMPtr<nsIVariant> indexVariant;
   dataEvent->GetData(NS_LITERAL_STRING("index"),
                      getter_AddRefs(indexVariant));
@@ -1198,22 +1199,23 @@ nsRootAccessible::HandleTreeRowCountChan
                      getter_AddRefs(countVariant));
   if (!countVariant)
     return NS_OK;
 
   PRInt32 index, count;
   indexVariant->GetAsInt32(&index);
   countVariant->GetAsInt32(&count);
 
-  return aAccessible->InvalidateCache(index, count);
+  aAccessible->InvalidateCache(index, count);
+  return NS_OK;
 }
 
 nsresult
 nsRootAccessible::HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
-                                             nsIAccessibleTreeCache *aAccessible)
+                                             nsXULTreeAccessible *aAccessible)
 {
   nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
   if (!dataEvent)
     return NS_OK;
 
   PRInt32 startRow = 0, endRow = -1, startCol = 0, endCol = -1;
 
   nsCOMPtr<nsIVariant> startRowVariant;
@@ -1235,12 +1237,13 @@ nsRootAccessible::HandleTreeInvalidatedE
     startColVariant->GetAsInt32(&startCol);
 
   nsCOMPtr<nsIVariant> endColVariant;
   dataEvent->GetData(NS_LITERAL_STRING("endcolumn"),
                      getter_AddRefs(endColVariant));
   if (endColVariant)
     endColVariant->GetAsInt32(&endCol);
 
-  return aAccessible->TreeViewInvalidated(startRow, endRow, startCol, endCol);
+  aAccessible->TreeViewInvalidated(startRow, endRow, startCol, endCol);
+  return NS_OK;
 }
 #endif
 
--- a/accessible/src/base/nsRootAccessible.h
+++ b/accessible/src/base/nsRootAccessible.h
@@ -38,25 +38,24 @@
 #ifndef _nsRootAccessible_H_
 #define _nsRootAccessible_H_
 
 #include "nsCaretAccessible.h"
 #include "nsDocAccessibleWrap.h"
 
 #include "nsIAccessibleDocument.h"
 #ifdef MOZ_XUL
-#include "nsIAccessibleTreeCache.h"
+#include "nsXULTreeAccessible.h"
 #endif
 
 #include "nsHashtable.h"
 #include "nsCaretAccessible.h"
 #include "nsIDocument.h"
 #include "nsIDOMFocusListener.h"
 #include "nsIDOMFormListener.h"
-#include "nsIDOMXULListener.h"
 #include "nsITimer.h"
 
 #define NS_ROOTACCESSIBLE_IMPL_CID                      \
 {  /* 7565f0d1-1465-4b71-906c-a623ac279f5d */           \
   0x7565f0d1,                                           \
   0x1465,                                               \
   0x4b71,                                               \
   { 0x90, 0x6c, 0xa6, 0x23, 0xac, 0x27, 0x9f, 0x5d }    \
@@ -135,19 +134,19 @@ public:
      * Used in HandleEventWithTarget().
      */
     nsresult HandlePopupShownEvent(nsIAccessible *aAccessible);
     nsresult HandlePopupHidingEvent(nsIDOMNode *aNode,
                                     nsIAccessible *aAccessible);
 
 #ifdef MOZ_XUL
     nsresult HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
-                                            nsIAccessibleTreeCache *aAccessible);
+                                            nsXULTreeAccessible *aAccessible);
     nsresult HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
-                                        nsIAccessibleTreeCache *aAccessible);
+                                        nsXULTreeAccessible *aAccessible);
 
     PRUint32 GetChromeFlags();
 #endif
     already_AddRefed<nsIDocShellTreeItem>
            GetContentDocShell(nsIDocShellTreeItem *aStart);
     nsRefPtr<nsCaretAccessible> mCaretAccessible;
     nsCOMPtr<nsIDOMNode> mCurrentARIAMenubar;
 };
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -844,17 +844,21 @@ nsHTMLTableAccessible::GetIndexAt(PRInt3
   NS_ENSURE_ARG_POINTER(aIndex);
 
   NS_ENSURE_TRUE(IsValidRow(aRow) && IsValidColumn(aColumn), NS_ERROR_INVALID_ARG);
 
   nsITableLayout *tableLayout = nsnull;
   nsresult rv = GetTableLayout(&tableLayout);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return tableLayout->GetIndexByRowAndColumn(aRow, aColumn, aIndex);
+  rv = tableLayout->GetIndexByRowAndColumn(aRow, aColumn, aIndex);
+  if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
+    return NS_ERROR_INVALID_ARG;
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLTableAccessible::GetColumnAtIndex(PRInt32 aIndex, PRInt32 *aColumn)
 {
   NS_ENSURE_ARG_POINTER(aColumn);
 
   nsITableLayout *tableLayout = nsnull;
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -128,17 +128,19 @@ mAccessNodeCache(nsnull)
   GetTreeBoxObject(aDOMNode, getter_AddRefs(mTree));
   if (mTree)
     mTree->GetView(getter_AddRefs(mTreeView));
   NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
   mAccessNodeCache = new nsAccessNodeHashtable;
   mAccessNodeCache->Init(kDefaultTreeCacheSize);
 }
 
-NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible, nsXULSelectableAccessible, nsIAccessibleTreeCache)
+NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible,
+                             nsXULSelectableAccessible,
+                             nsXULTreeAccessible)
                                                                                                        
 
 
 // Get the nsITreeBoxObject interface from any levels DOMNode under the <tree>
 void nsXULTreeAccessible::GetTreeBoxObject(nsIDOMNode *aDOMNode, nsITreeBoxObject **aBoxObject)
 {
   nsAutoString name;
   nsCOMPtr<nsIDOMNode> parentNode, currentNode;
@@ -215,16 +217,22 @@ NS_IMETHODIMP nsXULTreeAccessible::GetVa
       cols->GetKeyColumn(getter_AddRefs(keyCol));
 
     return mTreeView->GetCellText(currentIndex, keyCol, _retval);
   }
 
   return NS_OK;
 }
 
+PRBool
+nsXULTreeAccessible::IsDefunct()
+{
+  return nsXULSelectableAccessible::IsDefunct() || !mTree || !mTreeView;
+}
+
 nsresult
 nsXULTreeAccessible::Shutdown()
 {
   mTree = nsnull;
   mTreeView = nsnull;
 
   nsXULSelectableAccessible::Shutdown();
 
@@ -257,17 +265,17 @@ NS_IMETHODIMP nsXULTreeAccessible::GetFi
   //   use the first row as tree's first child
   if (*aFirstChild == nsnull) {
     NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
 
     PRInt32 rowCount;
     mTreeView->GetRowCount(&rowCount);
     if (rowCount > 0) {
       nsCOMPtr<nsITreeColumn> column = GetFirstVisibleColumn(mTree);
-      return GetCachedTreeitemAccessible(0, column, aFirstChild);
+      GetCachedTreeitemAccessible(0, column, aFirstChild);
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULTreeAccessible::GetLastChild(nsIAccessible **aLastChild)
@@ -276,23 +284,22 @@ nsXULTreeAccessible::GetLastChild(nsIAcc
   *aLastChild = nsnull;
 
   NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
 
   PRInt32 rowCount = 0;
   mTreeView->GetRowCount(&rowCount);
   if (rowCount > 0) {
     nsCOMPtr<nsITreeColumn> column = GetLastVisibleColumn(mTree);
-    nsresult rv = GetCachedTreeitemAccessible(rowCount - 1, column, aLastChild);
-    NS_ENSURE_SUCCESS(rv, rv);
+    GetCachedTreeitemAccessible(rowCount - 1, column, aLastChild);
+
+    if (*aLastChild)
+      return NS_OK;
   }
 
-  if (*aLastChild)
-    return NS_OK;
-
   // If there is not any rows, use treecols as tree's last child.
   return nsAccessible::GetLastChild(aLastChild);
 }
 
 // tree's children count is row count + treecols count
 NS_IMETHODIMP nsXULTreeAccessible::GetChildCount(PRInt32 *aAccChildCount)
 {
   NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
@@ -311,19 +318,18 @@ NS_IMETHODIMP nsXULTreeAccessible::GetFo
 {
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
     do_QueryInterface(mDOMNode);
   if (multiSelect) {
     PRInt32 row;
     multiSelect->GetCurrentIndex(&row);
     if (row >= 0) {
       GetCachedTreeitemAccessible(row, nsnull, aFocusedChild);
-      if (*aFocusedChild) {
-        return NS_OK;  // Already addref'd by getter
-      }
+      if (*aFocusedChild)
+        return NS_OK;
     }
   }
   NS_ADDREF(*aFocusedChild = this);
   return NS_OK;
 }
 
 // nsAccessible::GetChildAtPoint()
 nsresult
@@ -355,23 +361,17 @@ nsXULTreeAccessible::GetChildAtPoint(PRI
                    childEltUnused);
 
   // If we failed to find tree cell for the given point then it might be
   // tree columns.
   if (row == -1 || !column)
     return nsXULSelectableAccessible::
       GetChildAtPoint(aX, aY, aDeepestChild, aChild);
 
-  nsCOMPtr<nsIAccessible> treeitemAcc;
-  nsresult rv = GetCachedTreeitemAccessible(row, column,
-                                            getter_AddRefs(treeitemAcc));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*aChild = treeitemAcc);
-
+  GetCachedTreeitemAccessible(row, column, aChild);
   return NS_OK;
 }
 
 // Ask treeselection to get all selected children
 NS_IMETHODIMP nsXULTreeAccessible::GetSelectedChildren(nsIArray **_retval)
 {
   *_retval = nsnull;
 
@@ -387,19 +387,20 @@ NS_IMETHODIMP nsXULTreeAccessible::GetSe
 
   PRInt32 rowIndex, rowCount;
   PRBool isSelected;
   mTreeView->GetRowCount(&rowCount);
   for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
     selection->IsSelected(rowIndex, &isSelected);
     if (isSelected) {
       nsCOMPtr<nsIAccessible> tempAccess;
-      if (NS_FAILED(GetCachedTreeitemAccessible(rowIndex, nsnull, getter_AddRefs(tempAccess))) || !tempAccess)
+        GetCachedTreeitemAccessible(rowIndex, nsnull,
+                                    getter_AddRefs(tempAccess));
+      NS_ENSURE_STATE(tempAccess);
 
-        return NS_ERROR_OUT_OF_MEMORY;
       selectedAccessibles->AppendElement(tempAccess, PR_FALSE);
     }
   }
 
   PRUint32 length;
   selectedAccessibles->GetLength(&length);
   if (length != 0) {
     *_retval = selectedAccessibles;
@@ -463,36 +464,39 @@ NS_IMETHODIMP nsXULTreeAccessible::Clear
   nsCOMPtr<nsITreeSelection> selection;
   mTreeView->GetSelection(getter_AddRefs(selection));
   if (selection)
     selection->ClearSelection();
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **_retval)
+NS_IMETHODIMP
+nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **aAccessible)
 {
-  *_retval = nsnull;
+  NS_ENSURE_ARG_POINTER(aAccessible);
+  *aAccessible = nsnull;
 
   NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsITreeSelection> selection;
   mTreeView->GetSelection(getter_AddRefs(selection));
   if (!selection)
     return NS_ERROR_FAILURE;
 
   PRInt32 rowIndex, rowCount;
   PRInt32 selCount = 0;
   PRBool isSelected;
   mTreeView->GetRowCount(&rowCount);
   for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
     selection->IsSelected(rowIndex, &isSelected);
     if (isSelected) {
       if (selCount == aIndex) {
-        return GetCachedTreeitemAccessible(rowIndex, nsnull, _retval);
+        GetCachedTreeitemAccessible(rowIndex, nsnull, aAccessible);
+        return NS_OK;
       }
       selCount++;
     }
   }
 
   return NS_OK;
 }
 
@@ -514,24 +518,23 @@ NS_IMETHODIMP nsXULTreeAccessible::Selec
       if (selection)
         selection->SelectAll();
     }
   }
 
   return NS_OK;
 }
 
-// nsIAccessible nsIAccessibleTreeCache::
-//   GetCachedTreeitemAccessible(in long aRow, nsITreeColumn* aColumn)
-NS_IMETHODIMP
+// nsXULTreeAccessible
+
+void
 nsXULTreeAccessible::GetCachedTreeitemAccessible(PRInt32 aRow,
                                                  nsITreeColumn* aColumn,
                                                  nsIAccessible** aAccessible)
 {
-  NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
   NS_ASSERTION(mAccessNodeCache, "No accessibility cache for tree");
   NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
 
   nsCOMPtr<nsITreeColumn> col;
 #ifdef MOZ_ACCESSIBILITY_ATK
   col = aColumn;
@@ -543,69 +546,71 @@ nsXULTreeAccessible::GetCachedTreeitemAc
     mTree->GetColumns(getter_AddRefs(cols));
     if (cols)
       cols->GetKeyColumn(getter_AddRefs(col));
   }
 
   // Do not create accessible for treeitem if there is no column in the tree
   // because it doesn't render treeitems properly.
   if (!col)
-    return NS_OK;
+    return;
 
   col->GetIndex(&columnIndex);
 
   nsCOMPtr<nsIAccessNode> accessNode;
   GetCacheEntry(*mAccessNodeCache, (void*)(aRow * kMaxTreeColumns + columnIndex), getter_AddRefs(accessNode));
-  if (!accessNode)
-  {
-    nsXULTreeitemAccessibleWrap* treeItemAcc =
+
+  if (!accessNode) {
+    nsRefPtr<nsAccessNode> treeItemAcc =
       new nsXULTreeitemAccessibleWrap(this, mDOMNode, mWeakShell, aRow, col);
-    NS_ENSURE_TRUE(treeItemAcc, NS_ERROR_OUT_OF_MEMORY);
+    if (!treeItemAcc)
+      return;
 
     nsresult rv = treeItemAcc->Init();
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_FAILED(rv))
+      return;
 
     accessNode = treeItemAcc;
     PutCacheEntry(*mAccessNodeCache, (void*)(aRow * kMaxTreeColumns + columnIndex), accessNode);
   }
-  nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
-  NS_IF_ADDREF(*aAccessible = accessible);
-  return NS_OK;
+
+  CallQueryInterface(accessNode, aAccessible);
 }
 
-// void nsIAccessibleTreeCache::
-//   invalidateCache(in PRInt32 aRow, in PRInt32 aCount)
-NS_IMETHODIMP
+void
 nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
 {
+  if (IsDefunct())
+    return;
+
   // Do not invalidate the cache if rows have been inserted.
   if (aCount > 0)
-    return NS_OK;
-
-  NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
+    return;
 
   nsCOMPtr<nsITreeColumns> cols;
-  nsresult rv = mTree->GetColumns(getter_AddRefs(cols));
-  NS_ENSURE_STATE(cols);
+  mTree->GetColumns(getter_AddRefs(cols));
+  if (!cols)
+    return;
 
 #ifdef MOZ_ACCESSIBILITY_ATK
   PRInt32 colsCount = 0;
-  rv = cols->GetCount(&colsCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsresult rv = cols->GetCount(&colsCount);
+  if (NS_FAILED(rv))
+    return;
 #else
   nsCOMPtr<nsITreeColumn> col;
-  rv = cols->GetKeyColumn(getter_AddRefs(col));
-  NS_ENSURE_SUCCESS(rv, rv);
-
+  cols->GetKeyColumn(getter_AddRefs(col));
   if (!col)
-    return NS_OK;
+    return;
 
   PRInt32 colIdx = 0;
-  rv = col->GetIndex(&colIdx);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsresult rv = col->GetIndex(&colIdx);
+  if (NS_FAILED(rv))
+    return;
+
 #endif
 
   for (PRInt32 rowIdx = aRow; rowIdx < aRow - aCount; rowIdx++) {
 #ifdef MOZ_ACCESSIBILITY_ATK
     for (PRInt32 colIdx = 0; colIdx < colsCount; ++colIdx) {
 #else
     {
 #endif
@@ -624,146 +629,138 @@ nsXULTreeAccessible::InvalidateCache(PRI
 
         mAccessNodeCache->Remove(key);
       }
     }
   }
 
   PRInt32 newRowCount = 0;
   rv = mTreeView->GetRowCount(&newRowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_FAILED(rv))
+    return;
 
   PRInt32 oldRowCount = newRowCount - aCount;
 
   for (PRInt32 rowIdx = newRowCount; rowIdx < oldRowCount; ++rowIdx) {
 #ifdef MOZ_ACCESSIBILITY_ATK
     for (PRInt32 colIdx = 0; colIdx < colsCount; ++colIdx) {
 #else
     {
 #endif
       void *key = reinterpret_cast<void*>(rowIdx * kMaxTreeColumns + colIdx);
       mAccessNodeCache->Remove(key);
     }
   }
-
-  return NS_OK;
 }
 
-// void nsIAccessibleTreeCache::
-//   treeViewInvalidated(in long aStartRow, in long aEndRow,
-//                       in long aStartCol, in long aEndCol);
-NS_IMETHODIMP
+void
 nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
                                          PRInt32 aStartCol, PRInt32 aEndCol)
 {
-  NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
+  if (IsDefunct())
+    return;
 
   PRInt32 endRow = aEndRow;
 
   nsresult rv;
   if (endRow == -1) {
     PRInt32 rowCount = 0;
     rv = mTreeView->GetRowCount(&rowCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_FAILED(rv))
+      return;
 
     endRow = rowCount - 1;
   }
 
   nsCOMPtr<nsITreeColumns> treeColumns;
   mTree->GetColumns(getter_AddRefs(treeColumns));
-  NS_ENSURE_STATE(treeColumns);
+  if (!treeColumns)
+    return;
 
 #ifdef MOZ_ACCESSIBILITY_ATK
   PRInt32 endCol = aEndCol;
 
   if (endCol == -1) {
     PRInt32 colCount = 0;
     rv = treeColumns->GetCount(&colCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_FAILED(rv))
+      return;
 
     endCol = colCount - 1;
   }
 #else
   nsCOMPtr<nsITreeColumn> col;
   rv = treeColumns->GetKeyColumn(getter_AddRefs(col));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   if (!col)
-    return NS_OK;
+    return;
 
   PRInt32 colIdx = 0;
   rv = col->GetIndex(&colIdx);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_FAILED(rv))
+    return;
+
 #endif
 
   for (PRInt32 rowIdx = aStartRow; rowIdx <= endRow; ++rowIdx) {
 #ifdef MOZ_ACCESSIBILITY_ATK
     for (PRInt32 colIdx = aStartCol; colIdx <= endCol; ++colIdx)
 #endif
     {
       void *key = reinterpret_cast<void*>(rowIdx * kMaxTreeColumns + colIdx);
 
       nsCOMPtr<nsIAccessNode> accessNode;
       GetCacheEntry(*mAccessNodeCache, key, getter_AddRefs(accessNode));
 
       if (accessNode) {
-        nsCOMPtr<nsIAccessible> acc(do_QueryInterface(accessNode));
-        NS_ENSURE_STATE(acc);
-
-        nsCOMPtr<nsPIAccessibleTreeItem> treeItemAcc(
-          do_QueryInterface(accessNode));
-        NS_ENSURE_STATE(treeItemAcc);
+        nsRefPtr<nsXULTreeitemAccessible> treeitemAcc(
+          nsAccUtils::QueryAccessibleTreeitem(accessNode));
+        NS_ASSERTION(treeitemAcc, "Wrong accessible at the given key!");
 
         nsAutoString name, cachedName;
-        rv = acc->GetName(name);
-        NS_ENSURE_SUCCESS(rv, rv);
+        treeitemAcc->GetName(name);
 
-        rv = treeItemAcc->GetCachedName(cachedName);
-        NS_ENSURE_SUCCESS(rv, rv);
-
+        treeitemAcc->GetCachedName(cachedName);
         if (name != cachedName) {
-          nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, acc);
-          treeItemAcc->SetCachedName(name);
+          nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE,
+                                   treeitemAcc);
+          treeitemAcc->SetCachedName(name);
         }
       }
     }
   }
-
-  return NS_OK;
 }
 
-// void nsIAccessibleTreeCache::treeViewChanged();
-NS_IMETHODIMP
+void
 nsXULTreeAccessible::TreeViewChanged()
 {
-  if (!mTree)
-    return NS_ERROR_FAILURE;
+  if (IsDefunct())
+    return;
 
   // Fire only notification destroy/create events on accessible tree to lie to
   // AT because it should be expensive to fire destroy events for each tree item
   // in cache.
   nsCOMPtr<nsIAccessibleEvent> eventDestroy =
     new nsAccEvent(nsIAccessibleEvent::EVENT_DOM_DESTROY,
                    this, PR_FALSE);
-  NS_ENSURE_TRUE(eventDestroy, NS_ERROR_OUT_OF_MEMORY);
+  if (!eventDestroy)
+    return;
 
-  nsresult rv = FirePlatformEvent(eventDestroy);
+  FirePlatformEvent(eventDestroy);
 
   ClearCache(*mAccessNodeCache);
 
   mTree->GetView(getter_AddRefs(mTreeView));
 
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIAccessibleEvent> eventCreate =
     new nsAccEvent(nsIAccessibleEvent::EVENT_DOM_CREATE,
                    this, PR_FALSE);
-  NS_ENSURE_TRUE(eventCreate, NS_ERROR_OUT_OF_MEMORY);
+  if (!eventCreate)
+    return;
 
-  return FirePlatformEvent(eventCreate);
+  FirePlatformEvent(eventCreate);
 }
 
 nsresult nsXULTreeAccessible::GetColumnCount(nsITreeBoxObject* aBoxObject, PRInt32* aCount)
 {
   NS_ENSURE_TRUE(aBoxObject, NS_ERROR_FAILURE);
   nsCOMPtr<nsITreeColumns> treeColumns;
   aBoxObject->GetColumns(getter_AddRefs(treeColumns));
   NS_ENSURE_TRUE(treeColumns, NS_ERROR_FAILURE);
@@ -790,28 +787,33 @@ nsXULTreeitemAccessible::nsXULTreeitemAc
   if (!mColumn && mTree) {
     nsCOMPtr<nsITreeColumns> cols;
     mTree->GetColumns(getter_AddRefs(cols));
     if (cols)
       cols->GetKeyColumn(getter_AddRefs(mColumn));
   }
 }
 
-NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeitemAccessible, nsLeafAccessible,
-                             nsPIAccessibleTreeItem)
+NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeitemAccessible,
+                             nsLeafAccessible,
+                             nsXULTreeitemAccessible)
 
+// nsAccessNode
+ 
 nsresult
 nsXULTreeitemAccessible::Shutdown()
 {
   mTree = nsnull;
   mTreeView = nsnull;
   mColumn = nsnull;
   return nsLeafAccessible::Shutdown();
 }
 
+// nsIAccessible
+
 NS_IMETHODIMP
 nsXULTreeitemAccessible::GetName(nsAString& aName)
 {
   // XXX: we should take into account ARIA usage for content tree. 
   aName.Truncate();
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
@@ -1097,30 +1099,30 @@ NS_IMETHODIMP nsXULTreeitemAccessible::G
 NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibling)
 {
   NS_ENSURE_ARG_POINTER(aNextSibling);
   *aNextSibling = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
+  nsRefPtr<nsXULTreeAccessible> treeCache =
+    nsAccUtils::QueryAccessibleTree(mParent);
   NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
 
   PRInt32 rowCount;
   mTreeView->GetRowCount(&rowCount);
 
   if (!mColumn) {
     if (mRow < rowCount - 1)
-      return treeCache->GetCachedTreeitemAccessible(mRow + 1, nsnull, aNextSibling);
-    else
-      return NS_OK;
+      treeCache->GetCachedTreeitemAccessible(mRow + 1, nsnull, aNextSibling);
+
+    return NS_OK;
   }
 
-  nsresult rv = NS_OK;
   PRInt32 row = mRow;
   nsCOMPtr<nsITreeColumn> column;
 #ifdef MOZ_ACCESSIBILITY_ATK
   column = nsXULTreeAccessible::GetNextVisibleColumn(mColumn);
 
   if (!column) {
     if (mRow < rowCount -1) {
       row++;
@@ -1131,37 +1133,37 @@ NS_IMETHODIMP nsXULTreeitemAccessible::G
     }
   }
 #else
   if (++row >= rowCount) {
     return NS_ERROR_FAILURE;
   }
 #endif //MOZ_ACCESSIBILITY_ATK
 
-  rv = treeCache->GetCachedTreeitemAccessible(row, column, aNextSibling);
-  
-  return rv;
+  treeCache->GetCachedTreeitemAccessible(row, column, aNextSibling);
+  return NS_OK;
 }
 
 // Return the previous row of tree if mColumn (if any),
 // otherwise return the previous cell.
 NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPreviousSibling)
 {
   NS_ENSURE_ARG_POINTER(aPreviousSibling);
   *aPreviousSibling = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
+  nsRefPtr<nsXULTreeAccessible> treeCache =
+    nsAccUtils::QueryAccessibleTree(mParent);
   NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
 
   if (!mColumn && mRow > 0)
-    return treeCache->GetCachedTreeitemAccessible(mRow - 1, nsnull, aPreviousSibling);
-  
+    treeCache->GetCachedTreeitemAccessible(mRow - 1, nsnull, aPreviousSibling);
+
   nsresult rv = NS_OK;
 
 
   PRInt32 row = mRow;
   nsCOMPtr<nsITreeColumn> column;
 #ifdef MOZ_ACCESSIBILITY_ATK
   rv = mColumn->GetPrevious(getter_AddRefs(column));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1171,19 +1173,18 @@ NS_IMETHODIMP nsXULTreeitemAccessible::G
     column = nsXULTreeAccessible::GetLastVisibleColumn(mTree);
   }
 #else
   if (--row < 0) {
     return NS_ERROR_FAILURE;
   }
 #endif
 
-  rv = treeCache->GetCachedTreeitemAccessible(row, column, aPreviousSibling);
-
-  return rv;
+  treeCache->GetCachedTreeitemAccessible(row, column, aPreviousSibling);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeitemAccessible::DoAction(PRUint8 index)
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   if (index == eAction_Click) {
@@ -1289,48 +1290,44 @@ nsXULTreeitemAccessible::GetRelationByTy
   if (aRelationType == nsIAccessibleRelation::RELATION_NODE_CHILD_OF) {
     PRInt32 columnIndex;
     if (NS_SUCCEEDED(mColumn->GetIndex(&columnIndex)) && columnIndex == 0) {
       PRInt32 parentIndex;
       if (NS_SUCCEEDED(mTreeView->GetParentIndex(mRow, &parentIndex))) {
         if (parentIndex == -1)
           return nsRelUtils::AddTarget(aRelationType, aRelation, mParent);
   
-        nsCOMPtr<nsIAccessibleTreeCache> cache =
-          do_QueryInterface(mParent);
+        nsRefPtr<nsXULTreeAccessible> treeCache =
+          nsAccUtils::QueryAccessibleTree(mParent);
+
         nsCOMPtr<nsIAccessible> accParent;
-        nsresult rv = cache->
-          GetCachedTreeitemAccessible(parentIndex, mColumn,
-                                      getter_AddRefs(accParent));
-        NS_ENSURE_SUCCESS(rv, rv);
+        treeCache->GetCachedTreeitemAccessible(parentIndex, mColumn,
+                                               getter_AddRefs(accParent));
 
         return nsRelUtils::AddTarget(aRelationType, aRelation, accParent);
       }
     }
 
     return NS_OK;
   }
 
   return nsAccessible::GetRelationByType(aRelationType, aRelation);
 }
 
-// attribute AString nsIAccessibleTreeItem::cachedName
-NS_IMETHODIMP
+// nsXULTreeitemAccessible
+void
 nsXULTreeitemAccessible::GetCachedName(nsAString &aName)
 {
   aName = mCachedName;
-  return NS_OK;
 }
 
-// attribute AString nsIAccessibleTreeItem::cachedName
-NS_IMETHODIMP
+void
 nsXULTreeitemAccessible::SetCachedName(const nsAString &aName)
 {
   mCachedName = aName;
-  return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //  nsXULTreeColumnsAccessible
 nsXULTreeColumnsAccessible::
   nsXULTreeColumnsAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
   nsXULColumnsAccessible(aDOMNode, aShell)
 {
@@ -1350,19 +1347,20 @@ nsXULTreeColumnsAccessible::GetNextSibli
     tree->GetView(getter_AddRefs(treeView));
     if (treeView) {
       PRInt32 rowCount;
       treeView->GetRowCount(&rowCount);
       if (rowCount > 0) {
         nsCOMPtr<nsITreeColumn> column =
           nsXULTreeAccessible::GetFirstVisibleColumn(tree);
 
-        nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
+        nsRefPtr<nsXULTreeAccessible> treeCache =
+          nsAccUtils::QueryAccessibleTree(mParent);
         NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
 
-        return treeCache->GetCachedTreeitemAccessible(0, column, aNextSibling);
+        treeCache->GetCachedTreeitemAccessible(0, column, aNextSibling);
       }
     }
   }
 
   return NS_OK;
 }
 
--- a/accessible/src/xul/nsXULTreeAccessible.h
+++ b/accessible/src/xul/nsXULTreeAccessible.h
@@ -37,90 +37,155 @@
  * ***** END LICENSE BLOCK ***** */
 #ifndef __nsXULTreeAccessible_h__
 #define __nsXULTreeAccessible_h__
 
 #include "nsITreeBoxObject.h"
 #include "nsITreeView.h"
 #include "nsITreeColumns.h"
 #include "nsXULSelectAccessible.h"
-#include "nsIAccessibleTreeCache.h"
 
 /*
  * A class the represents the XUL Tree widget.
  */
 const PRUint32 kMaxTreeColumns = 100;
 const PRUint32 kDefaultTreeCacheSize = 256;
 
-class nsXULTreeAccessible : public nsXULSelectableAccessible,
-                            public nsIAccessibleTreeCache
+/**
+ * Accessible class for XUL tree element.
+ */
+
+#define NS_XULTREEACCESSIBLE_IMPL_CID                   \
+{  /* 2692e149-6176-42ee-b8e1-2c44b04185e3 */           \
+  0x2692e149,                                           \
+  0x6176,                                               \
+  0x42ee,                                               \
+  { 0xb8, 0xe1, 0x2c, 0x44, 0xb0, 0x41, 0x85, 0xe3 }    \
+}
+
+class nsXULTreeAccessible : public nsXULSelectableAccessible
 {
 public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIACCESSIBLESELECTABLE
-  NS_DECL_NSIACCESSIBLETREECACHE
-
   nsXULTreeAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
   virtual ~nsXULTreeAccessible() {}
 
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIAccessibleSelectable
+  NS_DECL_NSIACCESSIBLESELECTABLE
+
   // nsIAccessible
   NS_IMETHOD GetValue(nsAString& _retval);
 
   NS_IMETHOD GetFirstChild(nsIAccessible **_retval);
   NS_IMETHOD GetLastChild(nsIAccessible **_retval);
   NS_IMETHOD GetChildCount(PRInt32 *_retval);
   NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
 
   // nsAccessNode
+  virtual PRBool IsDefunct();
   virtual nsresult Shutdown();
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetChildAtPoint(PRInt32 aX, PRInt32 aY,
                                    PRBool aDeepestChild,
                                    nsIAccessible **aChild);
 
   // nsXULTreeAccessible
+
+  NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEACCESSIBLE_IMPL_CID)
+
+  /**
+   * Return tree item accessible at the givem row and column. If accessible
+   * doesn't exist in the cache then create it.
+   *
+   * @param aRow         [in] the given row index
+   * @param aColumn      [in] the given column object. If is is nsnull then
+   *                      primary column is used
+   * @param aAccessible  [out] tree item accessible
+   */
+  void GetCachedTreeitemAccessible(PRInt32 aRow, nsITreeColumn *aColumn,
+                                   nsIAccessible **aAccessible);
+
+  /**
+   * Invalidates the number of cached treeitem accessibles.
+   *
+   * @param aRow    [in] row index the invalidation starts from
+   * @param aCount  [in] the number of treeitem accessibles to invalidate,
+   *                 the number sign specifies whether rows have been
+   *                 inserted (plus) or removed (minus)
+   */
+  void InvalidateCache(PRInt32 aRow, PRInt32 aCount);
+
+  /**
+   * Fires name change events for invalidated area of tree.
+   *
+   * @param aStartRow  [in] row index invalidation starts from
+   * @param aEndRow    [in] row index invalidation ends, -1 means last row index
+   * @param aStartCol  [in] column index invalidation starts from
+   * @param aEndCol    [in] column index invalidation ends, -1 mens last column
+   *                    index
+   */
+  void TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
+                           PRInt32 aStartCol, PRInt32 aEndCol);
+
+  /**
+   * Invalidates children created for previous tree view.
+   */
+  void TreeViewChanged();
+
   static void GetTreeBoxObject(nsIDOMNode* aDOMNode, nsITreeBoxObject** aBoxObject);
   static nsresult GetColumnCount(nsITreeBoxObject* aBoxObject, PRInt32 *aCount);
 
   static PRBool IsColumnHidden(nsITreeColumn *aColumn);
   static already_AddRefed<nsITreeColumn> GetNextVisibleColumn(nsITreeColumn *aColumn);
   static already_AddRefed<nsITreeColumn> GetFirstVisibleColumn(nsITreeBoxObject *aTree);
   static already_AddRefed<nsITreeColumn> GetLastVisibleColumn(nsITreeBoxObject *aTree);
 
 protected:
   nsCOMPtr<nsITreeBoxObject> mTree;
   nsCOMPtr<nsITreeView> mTreeView;
   nsAccessNodeHashtable *mAccessNodeCache;
 
   NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeAccessible,
+                              NS_XULTREEACCESSIBLE_IMPL_CID)
+
 /**
-  * Treeitems -- used in Trees
-  */
-class nsXULTreeitemAccessible : public nsLeafAccessible,
-                                public nsPIAccessibleTreeItem
+ * Accessible class for items for XUL tree.
+ */
+
+#define NS_XULTREEITEMACCESSIBLE_IMPL_CID             \
+{  /* 7b1aa039-7270-4523-aeb3-61063a13ac3f */         \
+  0x7b1aa039,                                         \
+  0x7270,                                             \
+  0x4523,                                             \
+  { 0xae, 0xb3, 0x61, 0x06, 0x3a, 0x13, 0xac, 0x3f }  \
+}
+
+class nsXULTreeitemAccessible : public nsLeafAccessible
 {
 public:
   enum { eAction_Click = 0, eAction_Expand = 1 };
 
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSPIACCESSIBLETREEITEM
-
   nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, nsITreeColumn* aColumn = nsnull);
   virtual ~nsXULTreeitemAccessible() {}
 
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& aName);
   NS_IMETHOD GetNumActions(PRUint8 *_retval);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
-  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 
   NS_IMETHOD GetParent(nsIAccessible **_retval);
   NS_IMETHOD GetNextSibling(nsIAccessible **_retval);
   NS_IMETHOD GetPreviousSibling(nsIAccessible **_retval);
 
   NS_IMETHOD DoAction(PRUint8 index);
   NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
   NS_IMETHOD SetSelected(PRBool aSelect); 
@@ -133,28 +198,44 @@ public:
   NS_IMETHOD GetUniqueID(void **aUniqueID);
 
   // nsAccessNode
   virtual PRBool IsDefunct();
   virtual nsresult Init();
   virtual nsresult Shutdown();
 
   // nsAccessible
+  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
 
+  // nsXULTreeitemAccessible
+  NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEITEMACCESSIBLE_IMPL_CID)
+
+  /**
+   * Get/set cached name.
+   */
+  void GetCachedName(nsAString& aName);
+  void SetCachedName(const nsAString& aName);
+
 protected:
   PRBool IsExpandable();
   nsCOMPtr<nsITreeBoxObject> mTree;
   nsCOMPtr<nsITreeView> mTreeView;
   PRInt32 mRow;
   nsCOMPtr<nsITreeColumn> mColumn;
   nsString mCachedName;
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeitemAccessible,
+                              NS_XULTREEITEMACCESSIBLE_IMPL_CID)
+
+/**
+ * Accessible class for columns element of XUL tree.
+ */
 class nsXULTreeColumnsAccessible : public nsXULColumnsAccessible
 {
 public:
   nsXULTreeColumnsAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
 
   // nsIAccessible
   NS_IMETHOD GetNextSibling(nsIAccessible **aNextSibling);
 };
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -121,17 +121,17 @@ include $(topsrcdir)/config/rules.mk
 		test_states_editablebody.html \
 		test_states_doc.html \
 		test_states_docarticle.html \
 		test_states_frames.html \
 		test_table_1.html \
 		test_table_2.html \
 		test_table_3.html \
 		test_table_4.html \
-  $(warning test_table_indexes.html temporarily disabled) \
+		test_table_indexes.html \
 		test_table_indexes_ariagrid.html \
 		test_table_sels_ariagrid.html \
 		test_textattrs.html \
 		test_textboxes.html \
 		test_textboxes.xul \
 		test_value.xul \
 		testTextboxes.js \
 		treeview.js \
--- a/accessible/tests/mochitest/table.js
+++ b/accessible/tests/mochitest/table.js
@@ -1,76 +1,97 @@
 /**
  * Test table indexes.
  *
  * @param  aIdentifier  [in] table accessible identifier
- * @param  aLen         [in] cells count
- * @param  aRowIdxes    [in] array of row indexes for each cell index
- * @param  aColIdxes    [in] array of column indexes for each cell index
+ * @param  aIdxes       [in] two dimensional array of cell indexes
  */
-function testTableIndexes(aIdentifier, aLen, aRowIdxes, aColIdxes)
+function testTableIndexes(aIdentifier, aIdxes)
 {
   var tableAcc = getAccessible(aIdentifier, [nsIAccessibleTable]);
   if (!tableAcc)
     return;
 
-  var row, column, index;
+  var obtainedRowIdx, obtainedColIdx, obtainedIdx;
   var cellAcc;
 
   var id = prettyName(aIdentifier);
 
-  for (var i = 0; i < aLen; i++) {
-    try {
-      row = tableAcc.getRowAtIndex(i);
-    } catch (e) {
-      ok(false, id + ": can't get row index for cell index " + i + "," + e);
-    }
+  var rowCount = aIdxes.length;
+  for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
+    var colCount = aIdxes[rowIdx].length;
+    for (var colIdx = 0; colIdx < colCount; colIdx++) {
+      var idx = aIdxes[rowIdx][colIdx];
+      if (idx != - 1) {
+        // getRowAtIndex
+        var origRowIdx = rowIdx;
+        while (origRowIdx > 0 &&
+               aIdxes[rowIdx][colIdx] == aIdxes[origRowIdx - 1][colIdx])
+          origRowIdx--;
 
-    try {
-      column = tableAcc.getColumnAtIndex(i);
-    } catch (e) {
-      ok(false, id + ": can't get column index for cell index " + i + "," + e);
-    }
+        try {
+          obtainedRowIdx = tableAcc.getRowAtIndex(idx);
+        } catch (e) {
+          ok(false, id + ": can't get row index for cell index " + idx + "," + e);
+        }
 
-    try {
-      index = tableAcc.getIndexAt(aRowIdxes[i], aColIdxes[i]);
-    } catch (e) {
-      ok(false,
-         id + ": can't get cell index by row index " + aRowIdxes[i] +
-           " and column index: " + aColIdxes[i]  + ", " + e);
-    }
+        is(obtainedRowIdx, origRowIdx,
+           id + ": row  for index " + idx +" is not correct");
+
+        // getColumnAtIndex
+        var origColIdx = colIdx;
+        while (origColIdx > 0 &&
+               aIdxes[rowIdx][colIdx] == aIdxes[rowIdx][origColIdx - 1])
+          origColIdx--;
 
-    is(row, aRowIdxes[i], id + ": row  for index " + i +" is nor correct");
-    is(column, aColIdxes[i],
-       id + ": column  for index " + i +" is not correct");
-    is(index, i,
-       id + ": row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
+        try {
+          obtainedColIdx = tableAcc.getColumnAtIndex(idx);
+        } catch (e) {
+          ok(false, id + ": can't get column index for cell index " + idx + "," + e);
+        }
 
-    try {
-      cellAcc = null;
-      cellAcc = tableAcc.cellRefAt(row, column);
-    } catch (e) { }
+        is(obtainedColIdx, origColIdx,
+           id + ": column  for index " + idx +" is not correct");
+
+        // cellRefAt
+        try {
+          cellAcc = null;
+          cellAcc = tableAcc.cellRefAt(rowIdx, colIdx);
+        } catch (e) { }
 
-    ok(cellAcc,
-       id + ": Can't get cell accessible at row = " + row + ", column = " + column);
+        ok(cellAcc,
+           id + ": Can't get cell accessible at row = " + rowIdx + ", column = " + colIdx);
 
-    if (cellAcc) {
-      var attrs = cellAcc.attributes;
-      var strIdx = "";
-      try {
-        strIdx = attrs.getStringProperty("table-cell-index");
-      } catch (e) {
-        ok(false,
-           id + ": no cell index from object attributes on the cell accessible at index " + index + ".");
+        // 'table-cell-index' attribute
+        if (cellAcc) {
+          var attrs = cellAcc.attributes;
+          var strIdx = "";
+          try {
+            strIdx = attrs.getStringProperty("table-cell-index");
+          } catch (e) {
+            ok(false,
+               id + ": no cell index from object attributes on the cell accessible at index " + idx + ".");
+          }
+
+          if (strIdx) {
+            is (parseInt(strIdx), idx,
+                id + ": cell index from object attributes of cell accessible isn't corrent.");
+          }
+        }
       }
 
-      if (strIdx) {
-        is (parseInt(strIdx), index,
-            id + ": cell index from object attributes of cell accessible isn't corrent.");
+      // getIndexAt
+      try {
+        obtainedIdx = tableAcc.getIndexAt(rowIdx, colIdx);
+      } catch (e) {
+        obtainedIdx = -1;
       }
+
+      is(obtainedIdx, idx,
+         id + ": row " + rowIdx + " /column " + colIdx + " and index " + obtainedIdx + " aren't inconsistent.");
     }
   }
 }
 
 /**
  * Test table getters selection methods.
  *
  * @param  aIdentifier  [in] table accessible identifier
--- a/accessible/tests/mochitest/test_aria_token_attrs.html
+++ b/accessible/tests/mochitest/test_aria_token_attrs.html
@@ -146,17 +146,17 @@ https://bugzilla.mozilla.org/show_bug.cg
       testStates("native_textbox_nativeeditable_ariaundefined", 0, 0, STATE_READONLY);
       testStates("native_textbox_nativeeditable_ariaabsent", 0, 0, STATE_READONLY);
 
       // test (treeitem) selectable and selected states
       testStates("treeitem_selected_true", (STATE_SELECTABLE | STATE_SELECTED));
       testStates("treeitem_selected_false", STATE_SELECTABLE, 0, STATE_SELECTED);
       testStates("treeitem_selected_empty", 0, 0, (STATE_SELECTABLE | STATE_SELECTED));
       testStates("treeitem_selected_undefined", 0, 0, (STATE_SELECTABLE | STATE_SELECTED));
-      testStates("treeitem_selected_absent", 0, 0, (STATE_SELECTABLE | STATE_SELECTED));
+      testStates("treeitem_selected_absent", STATE_SELECTABLE, 0, STATE_SELECTED);
 
       // test (treeitem) haspopup states
       testStates("treeitem_haspopup_true", STATE_HASPOPUP);
       testStates("treeitem_haspopup_false", 0, 0, STATE_HASPOPUP);
       testStates("treeitem_haspopup_empty", 0, 0, STATE_HASPOPUP);
       testStates("treeitem_haspopup_undefined", 0, 0, STATE_HASPOPUP);
       testStates("treeitem_haspopup_absent", 0, 0, STATE_HASPOPUP);
 
--- a/accessible/tests/mochitest/test_table_indexes.html
+++ b/accessible/tests/mochitest/test_table_indexes.html
@@ -18,48 +18,100 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript"
           src="chrome://mochikit/content/a11y/accessible/table.js"></script>
 
   <script type="application/javascript">
     function doTest()
     {
       //////////////////////////////////////////////////////////////////////////
       // table
-      var tRow = new Array(0,0,0,1,1,1,2,2,3,3);
-      var tCol = new Array(0,1,2,0,1,2,0,1,1,2);
-
-      testTableIndexes("table", 10, tRow, tCol);
-
-      //////////////////////////////////////////////////////////////////////////
-      // tableinsane1
-      tRow = [0,0,0,1,1,1,2,2,3,3];
-      tCol = [0,1,2,0,1,2,0,1,1,2];
-
-      testTableIndexes("tableinsane1", 10, tRow, tCol);
+      var idxes = [
+        [0, 1, 2],
+        [3, 4, 5],
+        [6, 7, 7],
+        [6, 8, 9]
+      ];
 
-      //////////////////////////////////////////////////////////////////////////
-      // tableinsane2
-      tRow = [0,0,0,1,1,1,2,2,3,3,4,4,4];
-      tCol = [0,1,2,0,1,2,0,1,1,2,1,3,4];
-
-      testTableIndexes("tableinsane2", 13, tRow, tCol);
-
-      //////////////////////////////////////////////////////////////////////////
-      // tableinsane4
-      tRow = [0,0,0,1,1,1,2,2,3,4];
-      tCol = [0,1,2,0,1,2,0,2,0,0];
-
-      testTableIndexes("tableinsane4", 10, tRow, tCol);
+      testTableIndexes("table", idxes);
 
       //////////////////////////////////////////////////////////////////////////
       // tableborder
-      tRow = [0,0,0,1,1,1,2,2,3,3];
-      tCol = [0,1,2,0,1,2,0,1,1,2];
+      idxes = [
+        [0, 1, 2],
+        [3, 4, 5],
+        [6, 7, 7],
+        [6, 8, 9]
+      ];
+
+      testTableIndexes("tableborder", idxes);
+
+      //////////////////////////////////////////////////////////////////////////
+      // table
+      var idxes = [
+        [ 0,  1,  2,  2,  3,  4,  5,  6],
+        [ 7,  8,  9, 10, 11, 12, 13,  6],
+        [14, 15, 15, 16, 17, 18, 19,  6],
+        [20, 15, 15, 21, 22, 18, 23,  6]
+      ];
+
+      testTableIndexes("table2", idxes);
+
+      //////////////////////////////////////////////////////////////////////////
+      // tableinsane1 (empty row groups)
+      idxes = [
+        [0, 1, 2],
+        [3, 4, 5],
+        [6, 7, 7],
+        [6, 8, 9]
+      ];
+
+      testTableIndexes("tableinsane1", idxes);
 
-      testTableIndexes("tableborder", 10, tRow, tCol);
+      //////////////////////////////////////////////////////////////////////////
+      // tableinsane2 (empry rows)
+      idxes = [
+        [-1, -1, -1],
+        [-1, -1, -1],
+        [ 0,  1,  2]
+      ];
+
+      testTableIndexes("tableinsane2", idxes);
+
+      //////////////////////////////////////////////////////////////////////////
+      // tableinsane3 (cell holes)
+      idxes = [
+        [0, 1, -1],
+        [2, 3,  4]
+      ];
+
+      testTableIndexes("tableinsane3", idxes);
+
+      //////////////////////////////////////////////////////////////////////////
+      // tableinsane4 (empty row groups/rows and cell holes)
+      idxes = [
+        [ 0,  1,  2],
+        [-1, -1, -1],
+        [ 3,  4,  5],
+        [ 6,  6,  7],
+        [ 8, -1,  7],
+        [ 9,  9,  9]
+      ];
+      testTableIndexes("tableinsane4", idxes);
+
+      //////////////////////////////////////////////////////////////////////////
+      // tableinsane4 (just a crazy table)
+      idxes = [
+        [ 0,  1,  2, -1, -1],
+        [-1, -1, -1, -1, -1],
+        [ 3,  4,  5, -1, -1],
+        [ 6,  7,  7,  7,  7],
+        [ 6,  8,  9, -1, -1],
+        [ 6, 10,  9, 11, 12]
+      ];
+      testTableIndexes("tableinsane5", idxes);
 
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addLoadEvent(doTest);
   </script>
 </head>
@@ -122,16 +174,54 @@ https://bugzilla.mozilla.org/show_bug.cg
       </tr>
       <tr>
         <td>6</td>
         <td>7</td>
       </tr>
     </tbody>
   </table>
 
+  <table cellpadding="2" cellspacing="2" border="1" width="50%" id="table2">
+    <caption>column and row spans</caption>
+    <tbody>
+      <tr>
+        <td>0</td>
+        <td>1</td>
+        <td rowspan="1" colspan="2">2</td>
+        <td>3</td>
+        <td>4</td>
+        <td>5</td>
+        <td rowspan="4" colspan="1">6</td>
+      </tr>
+      <tr>
+        <td>7</td>
+        <td>8</td>
+        <td>8</td>
+        <td>10</td>
+        <td>11</td>
+        <td>12</td>
+        <td>13</td>
+      </tr>
+      <tr>
+        <td>14</td>
+        <td rowspan="2" colspan="2">15</td>
+        <td>16</td>
+        <td>17</td>
+        <td rowspan="2" colspan="1">18</td>
+        <td>19</td>
+      </tr>
+      <tr>
+        <td>20</td>
+        <td>21</td>
+        <td>22</td>
+        <td>23</td>
+      </tr>
+    </tbody>
+  </table>
+
   <table border="1" id="tableinsane1">
     <caption>test empty row groups</caption>
     <thead>
       <tr>
         <th>col1</th>
         <th>col2</th>
         <th>col3</th>
       </tr>
@@ -151,18 +241,80 @@ https://bugzilla.mozilla.org/show_bug.cg
       </tr>
       <tr>
         <td>6</td>
         <td>7</td>
       </tr>
     </tbody>
   </table>
 
-  <table border="1" id="tableinsane2" >
-    <caption>empty rowgroup + empty rows</caption>
+  <table border="1" id="tableinsane2">
+    <caption>empty rows</caption>
+    <tbody><tr></tr><tr></tr></tbody>
+    <tbody></tbody>
+    <tbody>
+      <tr>
+        <td>0</td>
+        <td>1</td>
+        <td>2</td>
+      </tr>
+    </tbody>
+  </table>
+
+  <table border="1" id="tableinsane3">
+    <caption>missed cell</caption>
+    <tbody>
+      <tr>
+        <td>0</td>
+        <td>1</td>
+      </tr>
+    </tbody>
+    <tbody>
+      <tr>
+        <td>2</td>
+        <td>3</td>
+        <td>4</td>
+      </tr>
+    </tbody>
+  </table>
+
+  <table border="1" id="tableinsane4">
+    <caption>test empty rows + cellmap holes</caption>
+    <thead>
+      <tr>
+        <th>col1</th>
+        <th>col2</th>
+        <th>col3</th>
+      </tr>
+    </thead>
+    <tbody><tr></tr></tbody>
+    <tbody></tbody>
+    <tbody></tbody>
+    <tbody>
+      <tr>
+        <td>1</td>
+        <td>2</td>
+        <td>3</td>
+      </tr>
+      <tr>
+         <td colspan="2">4</td>
+        <td rowspan="2">5</td>
+        </tr>
+      <tr>
+        <td>6</td>
+      </tr>
+      <tr>
+        <td colspan="3">7</td>       
+      </tr>
+
+    </tbody>
+  </table>
+
+  <table border="1" id="tableinsane5">
+    <caption>just a crazy table</caption>
     <thead>
       <tr>
         <th>col1</th>
         <th>col2</th>
         <th>col3</th>
       </tr>
     </thead>
     <tbody><tr></tr></tbody>
@@ -185,42 +337,10 @@ https://bugzilla.mozilla.org/show_bug.cg
       <tr>
         <td>8</td>
         <td>9</td>
         <td>10</td>
       </tr>
 
     </tbody>
 
-  <table border="1" id="tableinsane4" >
-    <caption>test cellmap holes</caption>
-    <thead>
-      <tr>
-        <th>col1</th>
-        <th>col2</th>
-        <th>col3</th>
-      </tr>
-    </thead>
-    <tbody><tr></tr></tbody>
-    <tbody></tbody>
-    <tbody></tbody>
-    <tbody>
-      <tr>
-        <td>1</td>
-        <td>2</td>
-        <td>3</td>
-      </tr>
-      <tr>
-         <td colspan="2">4</td>
-        <td rowspan="2">5</td>
-        </tr>
-      <tr>
-        <td>6</td>
-      </tr>
-      <tr>
-        <td colspan="3">7</td>       
-      </tr>
-
-    </tbody>
-  </table>
-
 </body>
 </html>
--- a/accessible/tests/mochitest/test_table_indexes_ariagrid.html
+++ b/accessible/tests/mochitest/test_table_indexes_ariagrid.html
@@ -17,20 +17,23 @@
   <script type="application/javascript"
           src="chrome://mochikit/content/a11y/accessible/table.js"></script>
 
   <script type="application/javascript">
     function doTest()
     {
       //////////////////////////////////////////////////////////////////////////
       // ARIA grid
-      var tRow = new Array(0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3);
-      var tCol = new Array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
-
-      testTableIndexes("grid", 12, tRow, tCol);
+      var idxes = [
+        [0, 1, 2],
+        [3, 4, 5],
+        [6, 7, 8],
+        [9, 10, 11]
+      ];
+      testTableIndexes("grid", idxes);
 
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -53,32 +53,42 @@ if [ "$srcdir" = "" ]; then
 fi
 
 #
 # Common makefiles used by everyone
 #
 add_makefiles "
 Makefile
 build/Makefile
+build/pgo/Makefile
+build/pgo/blueprint/Makefile
+build/pgo/js-input/Makefile
 build/unix/Makefile
+build/win32/Makefile
 config/Makefile
 config/autoconf.mk
 config/mkdepend/Makefile
+config/nspr/Makefile
 config/doxygen.cfg
 config/tests/src-simple/Makefile
 probes/Makefile
 extensions/Makefile
-build/wince/tools/Makefile
-build/wince/shunt/Makefile
-build/wince/shunt/include/windows.h
-build/wince/shunt/include/ymath.h
-build/wince/shunt/include/stdlib.h
-build/wince/shunt/include/sys/Makefile
 "
 
+if [ "$WINCE" ]; then
+  add_makefiles "
+    build/wince/tools/Makefile
+    build/wince/shunt/Makefile
+    build/wince/shunt/include/windows.h
+    build/wince/shunt/include/ymath.h
+    build/wince/shunt/include/stdlib.h
+    build/wince/shunt/include/sys/Makefile
+  "
+fi
+
 if [ "$MOZ_MEMORY" ]; then
   add_makefiles "
     memory/jemalloc/Makefile
   "
 fi
 
 #
 # Application-specific makefiles
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -540,17 +540,17 @@
              context="toolbar-context-menu"
              defaultset="personal-bookmarks"
              toolbarname="&personalbarCmd.label;" accesskey="&personalbarCmd.accesskey;"
              customizable="true"/>
   </toolbox>
 
   <hbox flex="1" id="browser">
     <vbox id="sidebar-box" hidden="true" class="chromeclass-extrachrome">
-      <sidebarheader align="center">
+      <sidebarheader id="sidebar-header" align="center">
         <label id="sidebar-title" persist="value" flex="1" crop="end" control="sidebar"/>
         <image id="sidebar-throbber"/>
         <toolbarbutton class="tabs-closebutton" tooltiptext="&sidebarCloseButton.tooltip;" oncommand="toggleSidebar();"/>
       </sidebarheader>
       <browser id="sidebar" flex="1" autoscroll="false" disablehistory="true"
                 style="min-width: 14em; width: 18em; max-width: 36em;"/>
     </vbox>
 
--- a/browser/components/places/content/controller.js
+++ b/browser/components/places/content/controller.js
@@ -541,21 +541,24 @@ PlacesController.prototype = {
    */
   _shouldShowMenuItem: function PC__shouldShowMenuItem(aMenuItem, aMetaData) {
     var selectiontype = aMenuItem.getAttribute("selectiontype");
     if (selectiontype == "multiple" && aMetaData.length == 1)
       return false;
     if (selectiontype == "single" && aMetaData.length != 1)
       return false;
 
-    var forceHideRules = aMenuItem.getAttribute("forcehideselection").split("|");
-    for (var i = 0; i < aMetaData.length; ++i) {
-      for (var j=0; j < forceHideRules.length; ++j) {
-        if (forceHideRules[j] in aMetaData[i])
-          return false;
+    var forceHideAttr = aMenuItem.getAttribute("forcehideselection");
+    if (forceHideAttr) {
+      var forceHideRules = forceHideAttr.split("|");
+      for (var i = 0; i < aMetaData.length; ++i) {
+        for (var j=0; j < forceHideRules.length; ++j) {
+          if (forceHideRules[j] in aMetaData[i])
+            return false;
+        }
       }
     }
 
     var selectionAttr = aMenuItem.getAttribute("selection");
     if (selectionAttr) {
       if (selectionAttr == "any")
         return true;
 
--- a/browser/components/places/content/utils.js
+++ b/browser/components/places/content/utils.js
@@ -1361,17 +1361,17 @@ var PlacesUIUtils = {
 
     if (lmStatus && !aPopup._lmStatusMenuItem) {
       // Create the status menuitem and cache it in the popup object.
       aPopup._lmStatusMenuItem = document.createElement("menuitem");
       aPopup._lmStatusMenuItem.setAttribute("lmStatus", lmStatus);
       aPopup._lmStatusMenuItem.setAttribute("label", this.getString(lmStatus));
       aPopup._lmStatusMenuItem.setAttribute("disabled", true);
       aPopup.insertBefore(aPopup._lmStatusMenuItem,
-                          aPopup.childNodes[aPopup._startMarker + 1]);
+                          aPopup.childNodes.item(aPopup._startMarker + 1));
       aPopup._startMarker++;
     }
     else if (lmStatus &&
              aPopup._lmStatusMenuItem.getAttribute("lmStatus") != lmStatus) {
       // Status has changed, update the cached status menuitem.
       aPopup._lmStatusMenuItem.setAttribute("label",
                                             this.getString(lmStatus));
     }
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -2761,17 +2761,17 @@ SessionStoreService.prototype = {
     let maxWindowsUndo = this._prefBranch.getIntPref("sessionstore.max_windows_undo");
     if (this._closedWindows.length <= maxWindowsUndo)
       return;
     let spliceTo = maxWindowsUndo;
 #ifndef XP_MACOSX
     let normalWindowIndex = 0;
     // try to find a non-popup window in this._closedWindows
     while (normalWindowIndex < this._closedWindows.length &&
-           this._closedWindows[normalWindowIndex].isPopup)
+           !!this._closedWindows[normalWindowIndex].isPopup)
       normalWindowIndex++;
     if (normalWindowIndex >= maxWindowsUndo)
       spliceTo = normalWindowIndex + 1;
 #endif
     this._closedWindows.splice(spliceTo);
   },
 
 /* ........ Storage API .............. */
--- a/browser/components/sessionstore/test/browser/browser_394759.js
+++ b/browser/components/sessionstore/test/browser/browser_394759.js
@@ -108,34 +108,34 @@ function test() {
           }, false);
         });
       }, true);
     }, false);
   }
   
   function test_behavior (callback) {
     // helper function that does the actual testing
-    function openWindowRec(windowsToOpen, expectedResults) {
+    function openWindowRec(windowsToOpen, expectedResults, recCallback) {
       // do actual checking
       if (!windowsToOpen.length) {
         let closedWindowData = JSON.parse(ss.getClosedWindowData());
         let numPopups = closedWindowData.filter(function(el, i, arr) {
           return el.isPopup;
         }).length;
         let numNormal = ss.getClosedWindowCount() - numPopups;
         // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
         let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
                                                        : expectedResults.other;
         is(numPopups, oResults.popup,
            "There were " + oResults.popup + " popup windows to repoen");
         is(numNormal, oResults.normal,
            "There were " + oResults.normal + " normal windows to repoen");
 
         // cleanup & return
-        executeSoon(callback);
+        executeSoon(recCallback);
         return;
       }
       // hack to force window to be considered a popup (toolbar=no didn't work)
       let winData = windowsToOpen.shift();
       let settings = "chrome,dialog=no," +
                      (winData.isPopup ? "all=no" : "all");
       let url = "http://window" + windowsToOpen.length + ".example.com";
       let window = openDialog(location, "_blank", settings, url);
@@ -144,17 +144,17 @@ function test() {
           // the window _should_ have state with a tab of url, but it doesn't
           // always happend before window.close(). addTab ensure we don't treat
           // this window as a stateless window
           window.gBrowser.addTab();
           window.gBrowser.removeEventListener("load", arguments.callee, true);
           executeSoon(function() {
             window.close();
             executeSoon(function() {
-              openWindowRec(windowsToOpen, expectedResults);
+              openWindowRec(windowsToOpen, expectedResults, recCallback);
             });
           });
         }, true);
       }, true);
     }
 
     let windowsToOpen = [{isPopup: false},
                          {isPopup: false},
--- a/browser/installer/removed-files.in
+++ b/browser/installer/removed-files.in
@@ -636,14 +636,12 @@ libjemalloc.so
 #ifdef MOZ_MEMORY
 Microsoft.VC80.CRT.manifest
 msvcm80.dll
 msvcp80.dll
 msvcr80.dll
 #else
 mozcrt19.dll
 #endif
-xpicleanup.exe
-#else
-xpicleanup
 #endif
+xpicleanup@BIN_SUFFIX@
 chrome.manifest
 install.rdf
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -59,18 +59,16 @@ ifdef LOCALE_MERGEDIR
 vpath book%.inc $(LOCALE_MERGEDIR)/browser/profile
 endif
 vpath book%.inc $(LOCALE_SRCDIR)/profile
 ifdef LOCALE_MERGEDIR
 vpath book%.inc @srcdir@/en-US/profile
 endif
 
 
-run_for_effects_too := if ! test -d $(DIST)/branding; then $(NSINSTALL) -D $(DIST)/branding; fi)
-
 ifdef MOZ_BRANDING_DIRECTORY
 SUBMAKEFILES += \
 	$(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/Makefile \
 	$(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales/Makefile \
 	$(NULL)
 endif
 
 # This makefile uses variable overrides from the libs-% target to
@@ -99,16 +97,21 @@ endif
 
 PREF_JS_EXPORTS = $(firstword $(wildcard $(LOCALE_SRCDIR)/firefox-l10n.js) \
                        $(srcdir)/en-US/firefox-l10n.js )
 
 include $(topsrcdir)/config/rules.mk
 
 include $(topsrcdir)/toolkit/locales/l10n.mk
 
+$(STAGEDIST): $(DIST)/branding
+
+$(DIST)/branding:
+	$(NSINSTALL) -D $@
+
 libs::
 	@if test -f "$(LOCALE_SRCDIR)/existing-profile-defaults.js"; then \
 	  $(PERL) $(topsrcdir)/config/preprocessor.pl $(PREF_PPFLAGS) $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) \
 	    $(LOCALE_SRCDIR)/existing-profile-defaults.js > $(FINAL_TARGET)/defaults/existing-profile-defaults.js; \
 	fi
 install::
 	@if test -f "$(LOCALE_SRCDIR)/existing-profile-defaults.js"; then \
 	  $(PERL) $(topsrcdir)/config/preprocessor.pl $(PREF_PPFLAGS) $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) \
--- a/browser/makefiles.sh
+++ b/browser/makefiles.sh
@@ -37,37 +37,79 @@
 
 add_makefiles "
 browser/Makefile
 browser/app/Makefile
 browser/app/profile/extensions/Makefile
 browser/base/Makefile
 browser/components/Makefile
 browser/components/build/Makefile
+browser/components/certerror/Makefile
 browser/components/dirprovider/Makefile
+browser/components/feeds/Makefile
+browser/components/feeds/public/Makefile
+browser/components/feeds/src/Makefile
+browser/components/microsummaries/Makefile
+browser/components/microsummaries/public/Makefile
+browser/components/microsummaries/src/Makefile
 browser/components/migration/Makefile
 browser/components/migration/public/Makefile
 browser/components/migration/src/Makefile
 browser/components/places/Makefile
+browser/components/places/public/Makefile
+browser/components/places/src/Makefile
 browser/components/preferences/Makefile
+browser/components/privatebrowsing/Makefile
+browser/components/privatebrowsing/src/Makefile
+browser/components/safebrowsing/Makefile
+browser/components/safebrowsing/src/Makefile
 browser/components/search/Makefile
+browser/components/sessionstore/Makefile
+browser/components/sessionstore/src/Makefile
 browser/components/sidebar/Makefile
 browser/components/sidebar/src/Makefile
 browser/components/shell/Makefile
 browser/components/shell/public/Makefile
 browser/components/shell/src/Makefile
+browser/fuel/Makefile
+browser/fuel/public/Makefile
+browser/fuel/src/Makefile
 browser/installer/Makefile
 browser/installer/windows/Makefile
 browser/locales/Makefile
 browser/themes/Makefile
 browser/themes/pinstripe/browser/Makefile
+browser/themes/pinstripe/communicator/Makefile
 browser/themes/pinstripe/Makefile
 browser/themes/winstripe/browser/Makefile
+browser/themes/winstripe/communicator/Makefile
 browser/themes/winstripe/Makefile
 "
 
 if test -n "$MOZ_BRANDING_DIRECTORY"; then
   add_makefiles "
     $MOZ_BRANDING_DIRECTORY/Makefile
     $MOZ_BRANDING_DIRECTORY/content/Makefile
     $MOZ_BRANDING_DIRECTORY/locales/Makefile
   "
 fi
+
+if [ "$ENABLE_TESTS" ]; then
+  add_makefiles "
+    browser/base/content/test/Makefile
+    browser/components/certerror/test/Makefile
+    browser/components/preferences/tests/Makefile
+    browser/components/search/test/Makefile
+    browser/components/sessionstore/test/Makefile
+    browser/components/sessionstore/test/browser/Makefile
+    browser/components/shell/test/Makefile
+    browser/components/feeds/test/Makefile
+    browser/components/feeds/test/chrome/Makefile
+    browser/components/places/tests/Makefile
+    browser/components/places/tests/chrome/Makefile
+    browser/components/places/tests/browser/Makefile
+    browser/components/places/tests/perf/Makefile
+    browser/components/privatebrowsing/test/Makefile
+    browser/components/privatebrowsing/test/browser/Makefile
+    browser/components/safebrowsing/content/test/Makefile
+    browser/fuel/test/Makefile
+  "
+fi
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -233,16 +233,17 @@ MOZ_TREE_CAIRO = @MOZ_TREE_CAIRO@
 
 MOZ_UPDATE_XTERM = @MOZ_UPDATE_XTERM@
 MOZ_MATHML = @MOZ_MATHML@
 MOZ_PERMISSIONS = @MOZ_PERMISSIONS@
 MOZ_XTF = @MOZ_XTF@
 MOZ_NO_INSPECTOR_APIS = @MOZ_NO_INSPECTOR_APIS@
 MOZ_SVG = @MOZ_SVG@
 MOZ_ENABLE_CANVAS = @MOZ_ENABLE_CANVAS@
+MOZ_ENABLE_CANVAS3D = @MOZ_ENABLE_CANVAS3D@
 MOZ_CAIRO_CFLAGS = @MOZ_CAIRO_CFLAGS@
 MOZ_SMIL = @MOZ_SMIL@
 MOZ_XSLT_STANDALONE = @MOZ_XSLT_STANDALONE@
 
 MOZ_PREF_EXTENSIONS = @MOZ_PREF_EXTENSIONS@
 
 MOZ_CAIRO_LIBS = @MOZ_CAIRO_LIBS@
 
@@ -542,19 +543,16 @@ GLIB_CFLAGS	= @GLIB_CFLAGS@
 GLIB_LIBS	= @GLIB_LIBS@
 GLIB_GMODULE_LIBS	= @GLIB_GMODULE_LIBS@
 LIBIDL_CFLAGS = @LIBIDL_CFLAGS@
 LIBIDL_LIBS = @LIBIDL_LIBS@
 STATIC_LIBIDL = @STATIC_LIBIDL@
 
 MOZ_NATIVE_MAKEDEPEND	= @SYSTEM_MAKEDEPEND@
 
-# Used for LD_LIBRARY_PATH
-LIBS_PATH       = @LIBS_PATH@
-
 MOZ_AUTO_DEPS	= @MOZ_AUTO_DEPS@
 COMPILER_DEPEND = @COMPILER_DEPEND@
 MDDEPDIR        := @MDDEPDIR@
 
 MOZ_DEMANGLE_SYMBOLS = @MOZ_DEMANGLE_SYMBOLS@
 
 # XXX - these need to be cleaned up and have real checks added -cls
 CM_BLDTYPE=dbg
--- a/config/nspr/Makefile.in
+++ b/config/nspr/Makefile.in
@@ -55,16 +55,17 @@ ifdef MOZ_NATIVE_NSPR
 $(error config/nspr/Makefile.in is not compatible with MOZ_NATIVE_NSPR)
 endif
 
 # Copy NSPR to the SDK
 ABS_DIST = $(call core_abspath,$(DIST))
 
 libs::
 	$(MAKE) -C $(DEPTH)/nsprpub install prefix=$(ABS_DIST)/sdk exec_prefix=$(ABS_DIST)/sdk bindir=$(ABS_DIST)/sdk/dummy includedir=$(ABS_DIST)/include libdir=$(ABS_DIST)/sdk/lib datadir=$(ABS_DIST)/sdk/dummy DESTDIR=
+	$(INSTALL) $(DEPTH)/nsprpub/config/nspr-config $(DIST)/bin
 	$(RM) -rf $(DIST)/sdk/dummy
 ifneq (,$(filter OS2 WINNT,$(OS_ARCH))) # {
 	$(RM) -f $(DIST)/sdk/lib/$(DLL_PREFIX)nspr4$(DLL_SUFFIX) $(DIST)/sdk/lib/$(DLL_PREFIX)plc4$(DLL_SUFFIX) $(DIST)/sdk/lib/$(DLL_PREFIX)plds4$(DLL_SUFFIX)
 	$(RM) -f $(DIST)/sdk/lib/$(LIB_PREFIX)nspr4_s.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plc4_s.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plds4_s.$(LIB_SUFFIX)
 else # } {
 	$(RM) -f $(DIST)/sdk/lib/$(LIB_PREFIX)nspr4.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plc4.$(LIB_SUFFIX) $(DIST)/sdk/lib/$(LIB_PREFIX)plds4.$(LIB_SUFFIX)
 endif # }
 
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -941,22 +941,16 @@ endif # WINNT_
 endif # MOZ_PROFILE_GENERATE || MOZ_PROFILE_USE
 endif # NO_PROFILE_GUIDED_OPTIMIZE
 
 ##############################################
 
 checkout:
 	$(MAKE) -C $(topsrcdir) -f client.mk checkout
 
-run_viewer: $(FINAL_TARGET)/viewer
-	cd $(FINAL_TARGET); \
-	MOZILLA_FIVE_HOME=`pwd` \
-	LD_LIBRARY_PATH=".:$(LIBS_PATH):$$LD_LIBRARY_PATH" \
-	viewer
-
 clean clobber realclean clobber_all:: $(SUBMAKEFILES)
 	-rm -f $(ALL_TRASH)
 	-rm -rf $(ALL_TRASH_DIRS)
 	$(foreach dir,$(PARALLEL_DIRS) $(DIRS) $(STATIC_DIRS) $(TOOL_DIRS),-$(call SUBMAKE,$@,$(dir)))
 
 distclean:: $(SUBMAKEFILES)
 	$(foreach dir,$(PARALLEL_DIRS) $(DIRS) $(STATIC_DIRS) $(TOOL_DIRS),-$(call SUBMAKE,$@,$(dir)))
 	-rm -rf $(ALL_TRASH_DIRS) 
@@ -2101,17 +2095,17 @@ endif
 # hundreds of built-in suffix rules for stuff we don't need.
 #
 .SUFFIXES:
 
 #
 # Fake targets.  Always run these rules, even if a file/directory with that
 # name already exists.
 #
-.PHONY: all alltags boot checkout chrome realchrome clean clobber clobber_all export install libs makefiles realclean run_viewer run_apprunner tools $(DIRS) $(TOOL_DIRS) FORCE
+.PHONY: all alltags boot checkout chrome realchrome clean clobber clobber_all export install libs makefiles realclean run_apprunner tools $(DIRS) $(TOOL_DIRS) FORCE
 
 # Used as a dependency to force targets to rebuild
 FORCE:
 
 # Delete target if error occurs when building target
 .DELETE_ON_ERROR:
 
 # Properly set LIBPATTERNS for the platform
--- a/config/system-headers
+++ b/config/system-headers
@@ -57,16 +57,17 @@ base/PCR_Base.h
 base/session.h
 basetyps.h
 be/app/Application.h
 Beep.h
 be/kernel/image.h
 be/kernel/OS.h
 bfd.h
 Bitmap.h
+blapi.h
 bsd/libc.h
 bsd/syscall.h
 bstring.h
 builtin.h
 Button.h
 byteswap.h
 #if MOZ_ENABLE_LIBXUL!=1
 #define WRAP_CAIRO_HEADERS
@@ -246,16 +247,17 @@ File.h
 filehdr.h
 files.h
 Files.h
 FindDirectory.h
 Finder.h
 FinderRegistry.h
 FixMath.h
 float.h
+fnmatch.h
 Folders.h
 fontconfig/fontconfig.h
 fontconfig/fcfreetype.h
 Font.h
 Fonts.h
 fp.h
 fpieee.h
 frame/log.h
@@ -267,16 +269,17 @@ freetype/ftsynth.h
 freetype/ftoutln.h
 freetype/ttnameid.h
 freetype/tttables.h
 freetype/t1tables.h
 fribidi/fribidi.h
 FSp_fopen.h
 fstream.h
 ft2build.h
+fts.h
 gconf/gconf-client.h
 Gdiplus.h
 gdk/gdk.h
 gdk/gdkkeysyms.h
 gdk/gdkprivate.h
 gdk/gdkx.h
 gdk/gdkdirectfb.h
 gdk-pixbuf/gdk-pixbuf.h
@@ -784,16 +787,17 @@ TextView.h
 th/PCR_Th.h
 thread.h
 ThreadManagerTests.h
 Threads.h
 time.h
 Timer.h
 tlhelp32.h
 ToolUtils.h
+tr1/functional
 trace.h
 Traps.h
 typeinfo
 types.h
 Types.h
 UAppleEventsMgr.h
 UAttachments.h
 ucontext.h
--- a/configure.in
+++ b/configure.in
@@ -4219,29 +4219,29 @@ if test -n "$MOZ_NATIVE_NSPR"; then
     AC_TRY_COMPILE([#include "prlog.h"],
                 [#ifndef PR_STATIC_ASSERT
                  #error PR_STATIC_ASSERT not defined
                  #endif],
                 [MOZ_NATIVE_NSPR=1],
                 AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT]))
     CFLAGS=$_SAVE_CFLAGS
 else
-    NSPR_CFLAGS='`$(DEPTH)/nsprpub/config/nspr-config --prefix='${LIBXUL_DIST}' --includedir='${LIBXUL_DIST}'/include/nspr --cflags`'
     if test "$OS_ARCH" = "WINCE"; then
         NSPR_CFLAGS="-I${LIBXUL_DIST}/include/nspr"
         NSPR_LIBS="${LIBXUL_DIST}/lib/nspr${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plc${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plds${NSPR_VERSION}.lib "
     elif test "$OS_ARCH" = "WINNT"; then
         NSPR_CFLAGS="-I${LIBXUL_DIST}/include/nspr"
         if test -n "$GNU_CC"; then
             NSPR_LIBS="-L${LIBXUL_DIST}/lib -lnspr${NSPR_VERSION} -lplc${NSPR_VERSION} -lplds${NSPR_VERSION}"
         else
             NSPR_LIBS="${LIBXUL_DIST}/lib/nspr${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plc${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plds${NSPR_VERSION}.lib "
         fi
     else
-        NSPR_LIBS='`$(DEPTH)/nsprpub/config/nspr-config --prefix='${LIBXUL_DIST}' --libdir='${LIBXUL_DIST}'/lib --libs`'
+        NSPR_CFLAGS='`$(LIBXUL_DIST)/bin/nspr-config --prefix='${LIBXUL_DIST}' --includedir='${LIBXUL_DIST}'/include/nspr --cflags`'
+        NSPR_LIBS='`$(LIBXUL_DIST)/bin/nspr-config --prefix='${LIBXUL_DIST}' --libdir='${LIBXUL_DIST}'/lib --libs`'
     fi
 fi
 
 dnl ========================================================
 dnl = If NSS was not detected in the system, 
 dnl = use the one in the source tree (mozilla/security/nss)
 dnl ========================================================
 
@@ -4486,16 +4486,17 @@ dnl ====================================
 MOZ_ARG_HEADER(Application)
 
 BUILD_STATIC_LIBS=
 ENABLE_TESTS=1
 MOZ_ACTIVEX_SCRIPTING_SUPPORT=
 MOZ_BRANDING_DIRECTORY=
 MOZ_DBGRINFO_MODULES=
 MOZ_ENABLE_CANVAS=1
+MOZ_ENABLE_CANVAS3D=
 MOZ_FEEDS=1
 MOZ_IMG_DECODERS_DEFAULT="png gif jpeg bmp xbm icon"
 MOZ_IMG_ENCODERS_DEFAULT="png jpeg"
 MOZ_JAVAXPCOM=
 MOZ_JSDEBUGGER=1
 MOZ_JSLOADER=1
 MOZ_MATHML=1
 MOZ_MORK=1
@@ -5925,16 +5926,25 @@ MOZ_ARG_DISABLE_BOOL(canvas,
 [  --disable-canvas          Disable html:canvas feature],
     MOZ_ENABLE_CANVAS=,
     MOZ_ENABLE_CANVAS=1 )
 if test -n "$MOZ_ENABLE_CANVAS"; then
     AC_DEFINE(MOZ_ENABLE_CANVAS)
 fi
 AC_SUBST(MOZ_ENABLE_CANVAS)
 
+MOZ_ARG_ENABLE_BOOL(canvas3d,
+[  --enable-canvas3d        Enable canvas 3D context],
+    MOZ_ENABLE_CANVAS3D=1,
+    MOZ_ENABLE_CANVAS3D= )
+if test -n "$MOZ_ENABLE_CANVAS3D"; then
+    AC_DEFINE(MOZ_ENABLE_CANVAS3D)
+fi
+AC_SUBST(MOZ_ENABLE_CANVAS3D)
+
 dnl ========================================================
 dnl SVG
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(svg,
 [  --disable-svg            Disable SVG support],
     MOZ_SVG=,
     MOZ_SVG=1 )
 if test -n "$MOZ_SVG"; then
@@ -8330,26 +8340,16 @@ if test "$ACCESSIBILITY" -a "$MOZ_ENABLE
     ATK_MAJOR_VERSION=`echo ${ATK_FULL_VERSION} | $AWK -F\. '{ print $1 }'`
     ATK_MINOR_VERSION=`echo ${ATK_FULL_VERSION} | $AWK -F\. '{ print $2 }'`
     ATK_REV_VERSION=`echo ${ATK_FULL_VERSION} | $AWK -F\. '{ print $3 }'`
     AC_DEFINE_UNQUOTED(ATK_MAJOR_VERSION, $ATK_MAJOR_VERSION)
     AC_DEFINE_UNQUOTED(ATK_MINOR_VERSION, $ATK_MINOR_VERSION)
     AC_DEFINE_UNQUOTED(ATK_REV_VERSION, $ATK_REV_VERSION)
 fi
 
-# Used for LD_LIBRARY_PATH of run_viewer target
-LIBS_PATH=
-for lib_arg in $NSPR_LIBS $TK_LIBS; do
-  case $lib_arg in
-    -L* ) LIBS_PATH="${LIBS_PATH:+$LIBS_PATH:}"`expr $lib_arg : "-L\(.*\)"` ;;
-      * ) ;;
-  esac
-done
-AC_SUBST(LIBS_PATH)
-
 dnl ========================================================
 dnl Use cygwin wrapper for win32 builds, except MSYS/MinGW
 dnl ========================================================
 case "$host_os" in
 mingw*)
     WIN_TOP_SRC=`cd $srcdir; pwd -W`
     ;;
 cygwin*|msvc*|mks*)
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -101,16 +101,17 @@ template<class E> class nsCOMArray;
 class nsIPref;
 struct JSRuntime;
 class nsICaseConversion;
 class nsIUGenCategory;
 class nsIWidget;
 class nsIDragSession;
 class nsPIDOMWindow;
 class nsPIDOMEventTarget;
+class nsIPresShell;
 #ifdef MOZ_XTF
 class nsIXTFService;
 #endif
 #ifdef IBMBIDI
 class nsIBidiKeyboard;
 #endif
 class nsIMIMEHeaderParam;
 
@@ -1397,25 +1398,46 @@ public:
   static nsresult GetASCIIOrigin(nsIPrincipal* aPrincipal,
                                  nsCString& aOrigin);
   static nsresult GetASCIIOrigin(nsIURI* aURI, nsCString& aOrigin);
   static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal,
                                nsString& aOrigin);
   static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin);
 
   /**
+   * This method creates and dispatches "command" event, which implements
+   * nsIDOMXULCommandEvent.
+   * If aShell is not null, dispatching goes via
+   * nsIPresShell::HandleDOMEventWithTarget.
+   */
+  static nsresult DispatchXULCommand(nsIContent* aTarget,
+                                     PRBool aTrusted,
+                                     nsIDOMEvent* aSourceEvent = nsnull,
+                                     nsIPresShell* aShell = nsnull,
+                                     PRBool aCtrl = PR_FALSE,
+                                     PRBool aAlt = PR_FALSE,
+                                     PRBool aShift = PR_FALSE,
+                                     PRBool aMeta = PR_FALSE);
+
+  /**
    * Gets the nsIDocument given the script context. Will return nsnull on failure.
    *
    * @param aScriptContext the script context to get the document for; can be null
    *
    * @return the document associated with the script context
    */
   static already_AddRefed<nsIDocument>
   GetDocumentFromScriptContext(nsIScriptContext *aScriptContext);
 
+  /**
+   * The method checks whether the caller can access native anonymous content.
+   * If there is no JS in the stack or privileged JS is running, this
+   * method returns PR_TRUE, otherwise PR_FALSE.
+   */
+  static PRBool CanAccessNativeAnon();
 private:
 
   static PRBool InitializeEventTable();
 
   static nsresult doReparentContentWrapper(nsIContent *aChild,
                                            JSContext *cx,
                                            JSObject *aOldGlobal,
                                            JSObject *aNewGlobal,
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -100,18 +100,18 @@ class nsBindingManager;
 class nsIDOMNodeList;
 class mozAutoSubtreeModified;
 struct JSObject;
 class nsFrameLoader;
 class nsIBoxObject;
 
 // IID for the nsIDocument interface
 #define NS_IDOCUMENT_IID      \
-  { 0x9abf0b96, 0xc9e2, 0x4d49, \
-    { 0x9c, 0x0a, 0x37, 0xc1, 0x22, 0x39, 0x83, 0x50 } }
+  {0x282f1cd0, 0x6dfb, 0x4cff, \
+      {0x83, 0x3e, 0x05, 0x98, 0x52, 0xe6, 0xd8, 0x59 } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 //----------------------------------------------------------------------
 
 // Document interface.  This is implemented by all document objects in
 // Gecko.
@@ -648,23 +648,16 @@ public:
                                 nsIStyleRule* aOldStyleRule,
                                 nsIStyleRule* aNewStyleRule) = 0;
   virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
                               nsIStyleRule* aStyleRule) = 0;
   virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
                                 nsIStyleRule* aStyleRule) = 0;
 
   /**
-   * Notify document of pending attribute change
-   */
-  virtual void AttributeWillChange(nsIContent* aChild,
-                                   PRInt32 aNameSpaceID,
-                                   nsIAtom* aAttribute) = 0;
-
-  /**
    * Flush notifications for this document and its parent documents
    * (since those may affect the layout of this one).
    */
   virtual void FlushPendingNotifications(mozFlushType aType) = 0;
 
   nsBindingManager* BindingManager() const
   {
     return mNodeInfoManager->GetBindingManager();
--- a/content/base/public/nsIMutationObserver.h
+++ b/content/base/public/nsIMutationObserver.h
@@ -40,18 +40,18 @@
 #include "nsISupports.h"
 
 class nsIAtom;
 class nsIContent;
 class nsIDocument;
 class nsINode;
 
 #define NS_IMUTATION_OBSERVER_IID \
-{ 0x32e68316, 0x67d4, 0x44a5, \
- { 0x8d, 0x35, 0xd, 0x39, 0xf, 0xa9, 0xdf, 0x11 } }
+{0x365d600b, 0x868a, 0x452a, \
+  {0x8d, 0xe8, 0xf4, 0x6f, 0xad, 0x8f, 0xee, 0x53 } }
 
 /**
  * Information details about a characterdata change.  Basically, we
  * view all changes as replacements of a length of text at some offset
  * with some other text (of possibly some other length).
  */
 struct CharacterDataChangeInfo
 {
@@ -134,16 +134,33 @@ public:
    * @param aContent  The piece of content that changed. Is never null.
    * @param aInfo     The structure with information details about the change.
    */
   virtual void CharacterDataChanged(nsIDocument *aDocument,
                                     nsIContent* aContent,
                                     CharacterDataChangeInfo* aInfo) = 0;
 
   /**
+   * Notification that an attribute of an element will change.
+   *
+   * @param aDocument    The owner-document of aContent. Can be null.
+   * @param aContent     The element whose attribute will change
+   * @param aNameSpaceID The namespace id of the changing attribute
+   * @param aAttribute   The name of the changing attribute
+   * @param aModType     Whether or not the attribute will be added, changed, or
+   *                     removed. The constants are defined in
+   *                     nsIDOMMutationEvent.h.
+   */
+  virtual void AttributeWillChange(nsIDocument* aDocument,
+                                   nsIContent*  aContent,
+                                   PRInt32      aNameSpaceID,
+                                   nsIAtom*     aAttribute,
+                                   PRInt32      aModType) = 0;
+
+  /**
    * Notification that an attribute of an element has changed.
    *
    * @param aDocument    The owner-document of aContent. Can be null.
    * @param aContent     The element whose attribute changed
    * @param aNameSpaceID The namespace id of the changed attribute
    * @param aAttribute   The name of the changed attribute
    * @param aModType     Whether or not the attribute was added, changed, or
    *                     removed. The constants are defined in
@@ -246,16 +263,23 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutatio
                                          nsIContent* aContent,               \
                                          CharacterDataChangeInfo* aInfo);
 
 #define NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED                     \
     virtual void CharacterDataChanged(nsIDocument* aDocument,                \
                                       nsIContent* aContent,                  \
                                       CharacterDataChangeInfo* aInfo);
 
+#define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE                      \
+    virtual void AttributeWillChange(nsIDocument* aDocument,                 \
+                                     nsIContent* aContent,                   \
+                                     PRInt32 aNameSpaceID,                   \
+                                     nsIAtom* aAttribute,                    \
+                                     PRInt32 aModType);
+
 #define NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED                         \
     virtual void AttributeChanged(nsIDocument* aDocument,                    \
                                   nsIContent* aContent,                      \
                                   PRInt32 aNameSpaceID,                      \
                                   nsIAtom* aAttribute,                       \
                                   PRInt32 aModType,                          \
                                   PRUint32 aStateMask);
 
@@ -280,16 +304,17 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutatio
     virtual void NodeWillBeDestroyed(const nsINode* aNode);
 
 #define NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED                       \
     virtual void ParentChainChanged(nsIContent *aContent);
 
 #define NS_DECL_NSIMUTATIONOBSERVER                                          \
     NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE                      \
     NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED                         \
+    NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE                          \
     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED                             \
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED                              \
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED                              \
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED                               \
     NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED                          \
     NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
 
 #define NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class)                     \
@@ -307,16 +332,24 @@ void                                    
 }                                                                         \
 void                                                                      \
 _class::CharacterDataChanged(nsIDocument* aDocument,                      \
                              nsIContent* aContent,                        \
                              CharacterDataChangeInfo* aInfo)              \
 {                                                                         \
 }                                                                         \
 void                                                                      \
+_class::AttributeWillChange(nsIDocument* aDocument,                       \
+                            nsIContent* aContent,                         \
+                            PRInt32 aNameSpaceID,                         \
+                            nsIAtom* aAttribute,                          \
+                            PRInt32 aModType)                             \
+{                                                                         \
+}                                                                         \
+void                                                                      \
 _class::AttributeChanged(nsIDocument* aDocument,                          \
                          nsIContent* aContent,                            \
                          PRInt32 aNameSpaceID,                            \
                          nsIAtom* aAttribute,                             \
                          PRInt32 aModType,                                \
                          PRUint32 aStateMask)                             \
 {                                                                         \
 }                                                                         \
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -434,20 +434,23 @@ public:
   /**
    * Remove a child from this node.  This method handles calling UnbindFromTree
    * on the child appropriately.
    *
    * @param aIndex the index of the child to remove
    * @param aNotify whether to notify the document (current document for
    *        nsIContent, and |this| for nsIDocument) that the remove has
    *        occurred
+   * @param aMutationEvent whether to fire a mutation event
    *
    * Note: If there is no child at aIndex, this method will simply do nothing.
    */
-  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify) = 0;
+  virtual nsresult RemoveChildAt(PRUint32 aIndex, 
+                                 PRBool aNotify, 
+                                 PRBool aMutationEvent = PR_TRUE) = 0;
 
   /**
    * Get a property associated with this node.
    *
    * @param aPropertyName  name of property to get.
    * @param aStatus        out parameter for storing resulting status.
    *                       Set to NS_PROPTABLE_PROP_NOT_THERE if the property
    *                       is not set.
--- a/content/base/src/Makefile.in
+++ b/content/base/src/Makefile.in
@@ -79,16 +79,17 @@ REQUIRES	= xpcom \
 		  uriloader \
 		  rdf \
 		  xultmpl \
 		  util \
 		  appshell \
 		  shistory \
 		  editor \
 		  windowwatcher \
+		  html5 \
 		  $(NULL)
 
 ifdef ACCESSIBILITY
 REQUIRES	+= accessibility
 endif
 
 EXPORTS		= \
 		nsAtomListUtils.h \
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -789,32 +789,42 @@ nsContentSink::ProcessStyleLink(nsIConte
 
   return NS_OK;
 }
 
 
 nsresult
 nsContentSink::ProcessMETATag(nsIContent* aContent)
 {
-  NS_ASSERTION(aContent, "missing base-element");
+  NS_ASSERTION(aContent, "missing meta-element");
 
   nsresult rv = NS_OK;
 
   // set any HTTP-EQUIV data into document's header data as well as url
   nsAutoString header;
   aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header);
   if (!header.IsEmpty()) {
     nsAutoString result;
     aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::content, result);
     if (!result.IsEmpty()) {
       ToLowerCase(header);
       nsCOMPtr<nsIAtom> fieldAtom(do_GetAtom(header));
       rv = ProcessHeaderData(fieldAtom, result, aContent); 
     }
   }
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  /* Look for the viewport meta tag. If we find it, process it and put the
+   * data into the document header. */
+  if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
+                            nsGkAtoms::viewport, eIgnoreCase)) {
+    nsAutoString value;
+    aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::content, value);
+    rv = nsContentUtils::ProcessViewportInfo(mDocument, value);
+  }
 
   return rv;
 }
 
 
 void
 nsContentSink::PrefetchHref(const nsAString &aHref,
                             nsIContent *aSource,
--- a/content/base/src/nsContentSink.h
+++ b/content/base/src/nsContentSink.h
@@ -141,16 +141,18 @@ class nsContentSink : public nsICSSLoade
   void NotifyAppend(nsIContent* aContent, PRUint32 aStartIndex);
 
   // nsIDocumentObserver
   virtual void BeginUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType);
   virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType);
 
   virtual void UpdateChildCounts() = 0;
 
+  PRBool IsTimeToNotify();
+
 protected:
   nsContentSink();
   virtual ~nsContentSink();
 
   enum CacheSelectionAction {
     // There is no offline cache manifest specified by the document,
     // or the document was loaded from a cache other than the one it
     // specifies via its manifest attribute and IS NOT a top-level
@@ -236,34 +238,35 @@ protected:
   //        was selected.
   // @param aAction
   //        Out parameter, returns the action that should be performed
   //        by the calling function.
   nsresult SelectDocAppCacheNoManifest(nsIApplicationCache *aLoadApplicationCache,
                                        nsIURI **aManifestURI,
                                        CacheSelectionAction *aAction);
 
+public:
   // Searches for the offline cache manifest attribute and calls one
   // of the above defined methods to select the document's application
   // cache, let it be associated with the document and eventually
   // schedule the cache update process.
   void ProcessOfflineManifest(nsIContent *aElement);
 
+protected:
   // Tries to scroll to the URI's named anchor. Once we've successfully
   // done that, further calls to this method will be ignored.
   void ScrollToRef();
   nsresult RefreshIfEnabled(nsIViewManager* vm);
 
   // Start layout.  If aIgnorePendingSheets is true, this will happen even if
   // we still have stylesheet loads pending.  Otherwise, we'll wait until the
   // stylesheets are all done loading.
+public:
   void StartLayout(PRBool aIgnorePendingSheets);
-
-  PRBool IsTimeToNotify();
-
+protected:
   void
   FavorPerformanceHint(PRBool perfOverStarvation, PRUint32 starvationDelay);
 
   inline PRInt32 GetNotificationInterval()
   {
     if (mDynamicLowerValue) {
       return 1000;
     }
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -157,30 +157,34 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
 #include "nsIUGenCategory.h"
 #include "nsIDragService.h"
 #include "nsIChannelEventSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIOfflineCacheUpdate.h"
 #include "nsCPrefetchService.h"
 #include "nsIChromeRegistry.h"
 #include "nsIMIMEHeaderParam.h"
+#include "nsIDOMXULCommandEvent.h"
+#include "nsIDOMAbstractView.h"
 #include "nsIDOMDragEvent.h"
 #include "nsDOMDataTransfer.h"
+#include "nsHtml5Module.h"
 
 #ifdef IBMBIDI
 #include "nsIBidiKeyboard.h"
 #endif
 #include "nsCycleCollectionParticipant.h"
 
 // for ReportToConsole
 #include "nsIStringBundle.h"
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
 
 #include "mozAutoDocUpdate.h"
+#include "jsinterp.h"
 
 const char kLoadAsData[] = "loadAsData";
 
 static const char kJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
 static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
 static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
 
 nsIDOMScriptObjectFactory *nsContentUtils::sDOMScriptObjectFactory = nsnull;
@@ -3573,16 +3577,68 @@ nsContentUtils::CreateContextualFragment
   nsresult rv;
   nsCOMPtr<nsINode> node = do_QueryInterface(aContextNode);
   NS_ENSURE_TRUE(node, NS_ERROR_NOT_AVAILABLE);
 
   // If we don't have a document here, we can't get the right security context
   // for compiling event handlers... so just bail out.
   nsCOMPtr<nsIDocument> document = node->GetOwnerDoc();
   NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
+  
+  PRBool bCaseSensitive = document->IsCaseSensitive();
+
+  nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document));
+  PRBool bHTML = htmlDoc && !bCaseSensitive;
+
+  if (bHTML && nsHtml5Module::Enabled) {
+    // See if the document has a cached fragment parser. nsHTMLDocument is the
+    // only one that should really have one at the moment.
+    nsCOMPtr<nsIParser> parser = document->GetFragmentParser();
+    if (parser) {
+      // Get the parser ready to use.
+      parser->Reset();
+    }
+    else {
+      // Create a new parser for this operation.
+      parser = nsHtml5Module::NewHtml5Parser();
+      if (!parser) {
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+      document->SetFragmentParser(parser);
+    }
+    nsCOMPtr<nsIDOMDocumentFragment> frag;
+    rv = NS_NewDocumentFragment(getter_AddRefs(frag), document->NodeInfoManager());
+    NS_ENSURE_SUCCESS(rv, rv);
+    
+    nsCOMPtr<nsIContent> contextAsContent = do_QueryInterface(aContextNode);
+    if (contextAsContent && !contextAsContent->IsNodeOfType(nsINode::eELEMENT)) {
+      contextAsContent = contextAsContent->GetParent();
+      if (contextAsContent && !contextAsContent->IsNodeOfType(nsINode::eELEMENT)) {
+        // can this even happen?
+        contextAsContent = nsnull;
+      }
+    }
+    
+    if (contextAsContent) {
+      parser->ParseFragment(aFragment, 
+                            frag, 
+                            contextAsContent->Tag(), 
+                            contextAsContent->GetNameSpaceID(), 
+                            (document->GetCompatibilityMode() == eCompatibility_NavQuirks));    
+    } else {
+      parser->ParseFragment(aFragment, 
+                            frag, 
+                            nsGkAtoms::body, 
+                            kNameSpaceID_XHTML, 
+                            (document->GetCompatibilityMode() == eCompatibility_NavQuirks));
+    }
+  
+    NS_ADDREF(*aReturn = frag);
+    return NS_OK;
+  }
 
   nsAutoTArray<nsString, 32> tagStack;
   nsAutoString uriStr, nameStr;
   nsCOMPtr<nsIContent> content = do_QueryInterface(aContextNode);
   // just in case we have a text node
   if (content && !content->IsNodeOfType(nsINode::eELEMENT))
     content = content->GetParent();
 
@@ -3630,24 +3686,19 @@ nsContentUtils::CreateContextualFragment
                        NS_LITERAL_STRING("\""));
       }
     }
 
     content = content->GetParent();
   }
 
   nsCAutoString contentType;
-  PRBool bCaseSensitive = PR_TRUE;
   nsAutoString buf;
   document->GetContentType(buf);
   LossyCopyUTF16toASCII(buf, contentType);
-  bCaseSensitive = document->IsCaseSensitive();
-
-  nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document));
-  PRBool bHTML = htmlDoc && !bCaseSensitive;
 
   // See if the document has a cached fragment parser. nsHTMLDocument is the
   // only one that should really have one at the moment.
   nsCOMPtr<nsIParser> parser = document->GetFragmentParser();
   if (parser) {
     // Get the parser ready to use.
     parser->Reset();
   }
@@ -4938,8 +4989,99 @@ nsContentTypeParser::~nsContentTypeParse
 nsresult
 nsContentTypeParser::GetParameter(const char* aParameterName, nsAString& aResult)
 {
   NS_ENSURE_TRUE(mService, NS_ERROR_FAILURE);
   return mService->GetParameter(mString, aParameterName,
                                 EmptyCString(), PR_FALSE, nsnull,
                                 aResult);
 }
+
+/* static */
+
+// If you change this code, change also AllowedToAct() in
+// XPCSystemOnlyWrapper.cpp!
+PRBool
+nsContentUtils::CanAccessNativeAnon()
+{
+  JSContext* cx = nsnull;
+  sThreadJSContextStack->Peek(&cx);
+  if (!cx) {
+    return PR_TRUE;
+  }
+  JSStackFrame* fp;
+  nsIPrincipal* principal =
+    sSecurityManager->GetCxSubjectPrincipalAndFrame(cx, &fp);
+  NS_ENSURE_TRUE(principal, PR_FALSE);
+
+  if (!fp) {
+    if (!JS_FrameIterator(cx, &fp)) {
+      // No code at all is running. So we must be arriving here as the result
+      // of C++ code asking us to do something. Allow access.
+      return PR_TRUE;
+    }
+
+    // Some code is running, we can't make the assumption, as above, but we
+    // can't use a native frame, so clear fp.
+    fp = nsnull;
+  }
+
+  void *annotation = fp ? JS_GetFrameAnnotation(cx, fp) : nsnull;
+  PRBool privileged;
+  if (NS_SUCCEEDED(principal->IsCapabilityEnabled("UniversalXPConnect",
+                                                  annotation,
+                                                  &privileged)) &&
+      privileged) {
+    // UniversalXPConnect things are allowed to touch us.
+    return PR_TRUE;
+  }
+
+  // XXX HACK EWW! Allow chrome://global/ access to these things, even
+  // if they've been cloned into less privileged contexts.
+  static const char prefix[] = "chrome://global/";
+  const char *filename;
+  if (fp && fp->script &&
+      (filename = fp->script->filename) &&
+      !strncmp(filename, prefix, NS_ARRAY_LENGTH(prefix) - 1)) {
+    return PR_TRUE;
+  }
+
+  return PR_FALSE;
+}
+
+/* static */ nsresult
+nsContentUtils::DispatchXULCommand(nsIContent* aTarget,
+                                   PRBool aTrusted,
+                                   nsIDOMEvent* aSourceEvent,
+                                   nsIPresShell* aShell,
+                                   PRBool aCtrl,
+                                   PRBool aAlt,
+                                   PRBool aShift,
+                                   PRBool aMeta)
+{
+  NS_ENSURE_STATE(aTarget);
+  nsIDocument* doc = aTarget->GetOwnerDoc();
+  nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(doc);
+  NS_ENSURE_STATE(docEvent);
+  nsCOMPtr<nsIDOMEvent> event;
+  docEvent->CreateEvent(NS_LITERAL_STRING("xulcommandevent"),
+                        getter_AddRefs(event));
+  nsCOMPtr<nsIDOMXULCommandEvent> xulCommand = do_QueryInterface(event);
+  nsCOMPtr<nsIPrivateDOMEvent> pEvent = do_QueryInterface(xulCommand);
+  NS_ENSURE_STATE(pEvent);
+  nsCOMPtr<nsIDOMAbstractView> view = do_QueryInterface(doc->GetWindow());
+  nsresult rv = xulCommand->InitCommandEvent(NS_LITERAL_STRING("command"),
+                                             PR_TRUE, PR_TRUE, view,
+                                             0, aCtrl, aAlt, aShift, aMeta,
+                                             aSourceEvent);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (aShell) {
+    nsEventStatus status = nsEventStatus_eIgnore;
+    nsCOMPtr<nsIPresShell> kungFuDeathGrip = aShell;
+    return aShell->HandleDOMEventWithTarget(aTarget, event, &status);
+  }
+
+  nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aTarget);
+  NS_ENSURE_STATE(target);
+  PRBool dummy;
+  return target->DispatchEvent(event, &dummy);
+}
--- a/content/base/src/nsDOMAttribute.cpp
+++ b/content/base/src/nsDOMAttribute.cpp
@@ -694,18 +694,19 @@ nsDOMAttribute::InsertChildAt(nsIContent
 
 nsresult
 nsDOMAttribute::AppendChildTo(nsIContent* aKid, PRBool aNotify)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
-nsDOMAttribute::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
+nsDOMAttribute::RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent)
 {
+  NS_ASSERTION(aMutationEvent, "Someone tried to inhibit mutations on attribute child removal.");
   if (aIndex != 0 || !mChild) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIContent> child = mChild;
   nsMutationGuard::DidMutate();
   mozAutoDocUpdate updateBatch(GetOwnerDoc(), UPDATE_CONTENT_MODEL, aNotify);
   nsMutationGuard guard;
--- a/content/base/src/nsDOMAttribute.h
+++ b/content/base/src/nsDOMAttribute.h
@@ -93,17 +93,17 @@ public:
   virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
   virtual PRUint32 GetChildCount() const;
   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
   virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const;
   virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
                                  PRBool aNotify);
   virtual nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify);
-  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
+  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent = PR_TRUE);
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
   virtual nsresult DispatchDOMEvent(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
                                     nsPresContext* aPresContext,
                                     nsEventStatus* aEventStatus);
   virtual nsIEventListenerManager* GetListenerManager(PRBool aCreateIfNotFound);
   virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener,
                                          const nsIID& aIID);
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -2392,18 +2392,19 @@ nsDocument::ContentRemoved(nsIDocument* 
   NS_ASSERTION(aDocument == this, "unexpected doc");
 
   NS_ABORT_IF_FALSE(aChild, "Null content!");
 
   UnregisterNamedItems(aChild);
 }
 
 void
-nsDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
-                                nsIAtom* aAttribute)
+nsDocument::AttributeWillChange(nsIDocument* aDocument,
+                                nsIContent* aContent, PRInt32 aNameSpaceID,
+                                nsIAtom* aAttribute, PRInt32 aModType)
 {
   NS_ABORT_IF_FALSE(aContent, "Null content!");
   NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
 
   if (aNameSpaceID != kNameSpaceID_None)
     return;
   if (aAttribute == nsGkAtoms::name) {
     RemoveFromNameTable(aContent);
@@ -3216,30 +3217,32 @@ nsDocument::AppendChildTo(nsIContent* aK
   // subclasses wanted to hook into this stuff, they would have
   // overridden AppendChildTo.
   // XXXbz maybe this should just be a non-virtual method on nsINode?
   // Feels that way to me...
   return nsDocument::InsertChildAt(aKid, GetChildCount(), aNotify);
 }
 
 nsresult
-nsDocument::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
-{
+nsDocument::RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent)
+{
+  NS_ASSERTION(aMutationEvent, "Someone tried to inhibit mutations on document child removal.");
   nsCOMPtr<nsIContent> oldKid = GetChildAt(aIndex);
   if (!oldKid) {
     return NS_OK;
   }
 
   if (oldKid->IsNodeOfType(nsINode::eELEMENT)) {
     // Destroy the link map up front before we mess with the child list.
     DestroyLinkMap();
   }
 
   nsresult rv = nsGenericElement::doRemoveChildAt(aIndex, aNotify, oldKid,
-                                                  nsnull, this, mChildren);
+                                                  nsnull, this, mChildren, 
+                                                  aMutationEvent);
   mCachedRootContent = nsnull;
   return rv;
 }
 
 PRInt32
 nsDocument::GetNumberOfStyleSheets() const
 {
   return mStyleSheets.Count();
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -768,20 +768,16 @@ public:
   virtual void EndLoad();
 
   virtual void SetReadyStateInternal(ReadyState rs);
 
   virtual void ContentStatesChanged(nsIContent* aContent1,
                                     nsIContent* aContent2,
                                     PRInt32 aStateMask);
 
-  virtual void AttributeWillChange(nsIContent* aChild,
-                                   PRInt32 aNameSpaceID,
-                                   nsIAtom* aAttribute);
-
   virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
                                 nsIStyleRule* aOldStyleRule,
                                 nsIStyleRule* aNewStyleRule);
   virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
                               nsIStyleRule* aStyleRule);
   virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
                                 nsIStyleRule* aStyleRule);
 
@@ -805,17 +801,17 @@ public:
   virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
   virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const;
   virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
   virtual PRUint32 GetChildCount() const;
   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
                                  PRBool aNotify);
   virtual nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify);
-  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
+  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent = PR_TRUE);
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
   virtual nsresult DispatchDOMEvent(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
                                     nsPresContext* aPresContext,
                                     nsEventStatus* aEventStatus);
   virtual nsIEventListenerManager* GetListenerManager(PRBool aCreateIfNotFound);
   virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener,
                                          const nsIID& aIID);
@@ -909,16 +905,17 @@ public:
   // nsIDOMNodeSelector
   NS_DECL_NSIDOMNODESELECTOR
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
+  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
 
   // nsIScriptObjectPrincipal
   virtual nsIPrincipal* GetPrincipal();
 
   // nsIApplicationCacheContainer
   NS_DECL_NSIAPPLICATIONCACHECONTAINER
 
   virtual nsresult Init();
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -582,19 +582,19 @@ nsGenericDOMDataNode::BindToTree(nsIDocu
                    "Bound to wrong binding parent");
 
   return NS_OK;
 }
 
 void
 nsGenericDOMDataNode::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
 {
-  // Unset FRAMETREE_DEPENDS_ON_CHARS; if we need it again later, it'll get set
-  // again.
-  UnsetFlags(FRAMETREE_DEPENDS_ON_CHARS);
+  // Unset frame flags; if we need them again later, they'll get set again.
+  UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE |
+             NS_REFRAME_IF_WHITESPACE);
   
   nsIDocument *document = GetCurrentDoc();
   if (document) {
     // Notify XBL- & nsIAnonymousContentCreator-generated
     // anonymous content that the document is changing.
     // This is needed to update the insertion point.
     document->BindingManager()->ChangeDocumentFor(this, document, nsnull);
   }
@@ -747,17 +747,17 @@ nsGenericDOMDataNode::IndexOf(nsINode* a
 nsresult
 nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
                                     PRBool aNotify)
 {
   return NS_OK;
 }
 
 nsresult
-nsGenericDOMDataNode::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
+nsGenericDOMDataNode::RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent)
 {
   return NS_OK;
 }
 
 // virtual
 PRBool
 nsGenericDOMDataNode::MayHaveFrame() const
 {
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -38,18 +38,24 @@
 /*
  * Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
  * nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
  */
 
 #ifndef nsGenericDOMDataNode_h___
 #define nsGenericDOMDataNode_h___
 
-// This bit is set if the frame tree depends on whether this node is whitespace
-#define FRAMETREE_DEPENDS_ON_CHARS (1 << NODE_TYPE_SPECIFIC_BITS_OFFSET)
+// This bit is set to indicate that if the text node changes to
+// non-whitespace, we may need to create a frame for it. This bit must
+// not be set on nodes that already have a frame.
+#define NS_CREATE_FRAME_IF_NON_WHITESPACE (1 << NODE_TYPE_SPECIFIC_BITS_OFFSET)
+
+// This bit is set to indicate that if the text node changes to
+// whitespace, we may need to reframe it (or its ancestors).
+#define NS_REFRAME_IF_WHITESPACE (1 << (NODE_TYPE_SPECIFIC_BITS_OFFSET + 1))
 
 #include "nsIDOMCharacterData.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOM3Text.h"
 #include "nsTextFragment.h"
 #include "nsDOMError.h"
 #include "nsIEventListenerManager.h"
 #include "nsGenericElement.h"
@@ -161,17 +167,17 @@ public:
 
   // nsINode methods
   virtual PRUint32 GetChildCount() const;
   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
   virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const;
   virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
                                  PRBool aNotify);
-  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
+  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent = PR_TRUE);
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
   virtual nsresult DispatchDOMEvent(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
                                     nsPresContext* aPresContext,
                                     nsEventStatus* aEventStatus);
   virtual nsIEventListenerManager* GetListenerManager(PRBool aCreateIfNotFound);
   virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener,
                                          const nsIID& aIID);
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -3241,35 +3241,36 @@ nsGenericElement::doInsertChildAt(nsICon
       nsEventDispatcher::Dispatch(aKid, nsnull, &mutation);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
-nsGenericElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
+nsGenericElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent)
 {
   nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
   NS_ASSERTION(oldKid == GetChildAt(aIndex), "Unexpected child in RemoveChildAt");
 
   if (oldKid) {
     return doRemoveChildAt(aIndex, aNotify, oldKid, this, GetCurrentDoc(),
-                           mAttrsAndChildren);
+                           mAttrsAndChildren, aMutationEvent);
   }
 
   return NS_OK;
 }
 
 /* static */
 nsresult
 nsGenericElement::doRemoveChildAt(PRUint32 aIndex, PRBool aNotify,
                                   nsIContent* aKid, nsIContent* aParent,
                                   nsIDocument* aDocument,
-                                  nsAttrAndChildArray& aChildArray)
+                                  nsAttrAndChildArray& aChildArray,
+                                  PRBool aMutationEvent)
 {
   NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
   NS_PRECONDITION(!aParent || aParent->GetCurrentDoc() == aDocument,
                   "Incorrect aDocument");
 
 #ifdef ACCESSIBILITY
   // A11y needs to be notified of content removals first, so accessibility
   // events can be fired before any changes occur
@@ -3295,16 +3296,17 @@ nsGenericElement::doRemoveChildAt(PRUint
                   container->IndexOf(aKid) == (PRInt32)aIndex, "Bogus aKid");
 
   mozAutoDocUpdate updateBatch(aDocument, UPDATE_CONTENT_MODEL, aNotify);
 
   nsMutationGuard guard;
 
   mozAutoSubtreeModified subtree(nsnull, nsnull);
   if (aNotify &&
+      aMutationEvent &&
       nsContentUtils::HasMutationListeners(aKid,
         NS_EVENT_BITS_MUTATION_NODEREMOVED, container)) {
     mozAutoRemovableBlockerRemover blockerRemover;
 
     nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEREMOVED);
     mutation.mRelatedNode = do_QueryInterface(container);
 
     subtree.UpdateTarget(container->GetOwnerDoc(), container);
@@ -4248,19 +4250,17 @@ nsGenericElement::SetAttrAndNotify(PRInt
   mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
 
   // When notifying, make sure to keep track of states whose value
   // depends solely on the value of an attribute.
   PRUint32 stateMask;
   if (aNotify) {
     stateMask = PRUint32(IntrinsicState());
     
-    if (document) {
-      document->AttributeWillChange(this, aNamespaceID, aName);
-    }
+    nsNodeUtils::AttributeWillChange(this, aNamespaceID, aName, modType);
   }
 
   if (aNamespaceID == kNameSpaceID_None) {
     // XXXbz Perhaps we should push up the attribute mapping function
     // stuff to nsGenericElement?
     if (!IsAttributeMapped(aName) ||
         !SetMappedAttribute(document, aName, aParsedValue, &rv)) {
       rv = mAttrsAndChildren.SetAndTakeAttr(aName, aParsedValue);
@@ -4488,25 +4488,26 @@ nsGenericElement::UnsetAttr(PRInt32 aNam
     return NS_OK;
   }
 
   nsresult rv = BeforeSetAttr(aNameSpaceID, aName, nsnull, aNotify);
   NS_ENSURE_SUCCESS(rv, rv);
   
   nsIDocument *document = GetCurrentDoc();    
   mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
-  if (document) {
-    if (kNameSpaceID_XLink == aNameSpaceID && nsGkAtoms::href == aName) {
-      // XLink URI might be changing.
-      document->ForgetLink(this);
-    }
-
-    if (aNotify) {
-      document->AttributeWillChange(this, aNameSpaceID, aName);
-    }
+
+  if (aNotify) {
+    nsNodeUtils::AttributeWillChange(this, aNameSpaceID, aName,
+                                     nsIDOMMutationEvent::REMOVAL);
+  }
+
+  if (document && kNameSpaceID_XLink == aNameSpaceID &&
+      nsGkAtoms::href == aName) {
+    // XLink URI might be changing.
+    document->ForgetLink(this);
   }
 
   // When notifying, make sure to keep track of states whose value
   // depends solely on the value of an attribute.
   PRUint32 stateMask;
   if (aNotify) {
     stateMask = PRUint32(IntrinsicState());
   }    
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -349,17 +349,17 @@ public:
 
   // nsINode interface methods
   virtual PRUint32 GetChildCount() const;
   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
   virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const;
   virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
                                  PRBool aNotify);
-  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
+  virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify, PRBool aMutationEvent = PR_TRUE);
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
   virtual nsresult DispatchDOMEvent(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
                                     nsPresContext* aPresContext,
                                     nsEventStatus* aEventStatus);
   virtual nsIEventListenerManager* GetListenerManager(PRBool aCreateIfNotFound);
   virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener,
                                          const nsIID& aIID);
@@ -649,17 +649,18 @@ public:
    *                  non-null if aParent is null (in which case aKid is being
    *                  removed as its child) and must match
    *                  aParent->GetCurrentDoc() if aParent is not null.
    * @param aChildArray The child array to work with
    */
   static nsresult doRemoveChildAt(PRUint32 aIndex, PRBool aNotify,
                                   nsIContent* aKid, nsIContent* aParent,
                                   nsIDocument* aDocument,
-                                  nsAttrAndChildArray& aChildArray);
+                                  nsAttrAndChildArray& aChildArray,
+                                  PRBool aMutationEvent);
 
   /**
    * Helper methods for implementing querySelector/querySelectorAll
    */
   static nsresult doQuerySelector(nsINode* aRoot, const nsAString& aSelector,
                                   nsIDOMElement **aReturn);
   static nsresult doQuerySelectorAll(nsINode* aRoot,
                                      const nsAString& aSelector,
--- a/content/base/src/nsHTMLContentSerializer.cpp
+++ b/content/base/src/nsHTMLContentSerializer.cpp
@@ -63,16 +63,17 @@
 #include "nsEscape.h"
 #include "nsITextToSubURI.h"
 #include "nsCRT.h"
 #include "nsIParserService.h"
 #include "nsContentUtils.h"
 #include "nsLWBrkCIID.h"
 #include "nsIScriptElement.h"
 #include "nsAttrName.h"
+#include "nsHtml5Module.h"
 
 static const char kMozStr[] = "moz";
 
 static const PRInt32 kLongLineLen = 128;
 
 nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
 {
   nsHTMLContentSerializer* it = new nsHTMLContentSerializer();
@@ -95,37 +96,59 @@ nsHTMLContentSerializer::~nsHTMLContentS
 
 NS_IMETHODIMP
 nsHTMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument,
                                              nsAString& aStr)
 {
   return NS_OK;
 }
 
+#include "nsIHTMLDocument.h"
 void 
 nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
                                              nsIDOMElement *aOriginalElement,
                                              nsAString& aTagPrefix,
                                              const nsAString& aTagNamespaceURI,
                                              nsIAtom* aTagName,
                                              nsAString& aStr)
 {
+  PRInt32 count = aContent->GetAttrCount();
+  if (!count)
+    return;
+
   nsresult rv;
-  PRUint32 index, count;
   nsAutoString nameStr, valueStr;
-
-  count = aContent->GetAttrCount();
-
   NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
 
-  // Loop backward over the attributes, since the order they are stored in is
-  // the opposite of the order they were parsed in (see bug 213347 for reason).
-  // index is unsigned, hence index >= 0 is always true.
-  for (index = count; index > 0; ) {
-    --index;
+  // HTML5 parser stored them in the order they were parsed so we want to
+  // loop forward in that case.
+  nsIDocument* doc = aContent->GetOwnerDocument();
+  PRBool caseSensitive = doc && doc->IsCaseSensitive();
+  PRBool loopForward = PR_FALSE;
+  if (!caseSensitive) {
+    nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
+    if (htmlDoc) {
+      loopForward = nsHtml5Module::Enabled;
+    }
+  }
+  PRInt32 index, limit, step;
+  if (loopForward) {
+    index = 0;
+    limit = count;
+    step = 1;
+  }
+  else {
+    // Loop backward over the attributes, since the order they are stored in is
+    // the opposite of the order they were parsed in (see bug 213347 for reason).
+    index = count - 1;
+    limit = -1;
+    step = -1;
+  }
+  
+  for (; index != limit; index += step) {
     const nsAttrName* name = aContent->GetAttrNameAt(index);
     PRInt32 namespaceID = name->NamespaceID();
     nsIAtom* attrName = name->LocalName();
 
     // Filter out any attribute starting with [-|_]moz
     const char* sharedName;
     attrName->GetUTF8String(&sharedName);
     if ((('_' == *sharedName) || ('-' == *sharedName)) &&
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -93,16 +93,28 @@ nsNodeUtils::CharacterDataChanged(nsICon
                                   CharacterDataChangeInfo* aInfo)
 {
   nsIDocument* doc = aContent->GetOwnerDoc();
   IMPL_MUTATION_NOTIFICATION(CharacterDataChanged, aContent,
                              (doc, aContent, aInfo));
 }
 
 void
+nsNodeUtils::AttributeWillChange(nsIContent* aContent,
+                                 PRInt32 aNameSpaceID,
+                                 nsIAtom* aAttribute,
+                                 PRInt32 aModType)
+{
+  nsIDocument* doc = aContent->GetOwnerDoc();
+  IMPL_MUTATION_NOTIFICATION(AttributeWillChange, aContent,
+                             (doc, aContent, aNameSpaceID, aAttribute,
+                              aModType));
+}
+
+void
 nsNodeUtils::AttributeChanged(nsIContent* aContent,
                               PRInt32 aNameSpaceID,
                               nsIAtom* aAttribute,
                               PRInt32 aModType,
                               PRUint32 aStateMask)
 {
   nsIDocument* doc = aContent->GetOwnerDoc();
   IMPL_MUTATION_NOTIFICATION(AttributeChanged, aContent,
--- a/content/base/src/nsNodeUtils.h
+++ b/content/base/src/nsNodeUtils.h
@@ -69,16 +69,29 @@ public:
    * @param aContent  Node whose data changed
    * @param aInfo     Struct with information details about the change
    * @see nsIMutationObserver::CharacterDataChanged
    */
   static void CharacterDataChanged(nsIContent* aContent,
                                    CharacterDataChangeInfo* aInfo);
 
   /**
+   * Send AttributeWillChange notifications to nsIMutationObservers.
+   * @param aContent      Node whose data will change
+   * @param aNameSpaceID  Namespace of changing attribute
+   * @param aAttribute    Local-name of changing attribute
+   * @param aModType      Type of change (add/change/removal)
+   * @see nsIMutationObserver::AttributeWillChange
+   */
+  static void AttributeWillChange(nsIContent* aContent,
+                                  PRInt32 aNameSpaceID,
+                                  nsIAtom* aAttribute,
+                                  PRInt32 aModType);
+
+  /**
    * Send AttributeChanged notifications to nsIMutationObservers.
    * @param aContent      Node whose data changed
    * @param aNameSpaceID  Namespace of changed attribute
    * @param aAttribute    Local-name of changed attribute
    * @param aModType      Type of change (add/change/removal)
    * @param aStateMask    States which changed
    * @see nsIMutationObserver::AttributeChanged
    */
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -47,16 +47,17 @@
 #include "nsIContent.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsIExternalProtocolHandler.h"
 #include "nsIEventStateManager.h"
 #include "nsIObjectFrame.h"
 #include "nsIPluginDocument.h"
 #include "nsIPluginHost.h"
+#include "nsIPluginInstance.h"
 #include "nsIPresShell.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIStreamConverterService.h"
 #include "nsIURILoader.h"
 #include "nsIURL.h"
 #include "nsIWebNavigation.h"
 #include "nsIWebNavigationInfo.h"
--- a/content/base/src/nsRange.cpp
+++ b/content/base/src/nsRange.cpp
@@ -1140,56 +1140,39 @@ static nsresult
 RemoveNode(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   nsCOMPtr<nsINode> parent = node->GetNodeParent();
   return parent ? parent->RemoveChildAt(parent->IndexOf(node), PR_TRUE) : NS_OK;
 }
 
 /**
- * Split a data node into two or three parts.
+ * Split a data node into two parts.
  *
- * @param aStartNode          The original node we are trying to split,
- *                            and first of three.
- * @param aStartIndex         The index at which to split the first and second
- *                            parts.
- * @param aEndIndex           The index at which to split the second and third
- *                            parts.
- * @param aMiddleNode         The second node of three.
- * @param aEndNode            The third node of three.  May be null to indicate
- *                            aEndIndex doesn't apply.
+ * @param aStartNode          The original node we are trying to split.
+ * @param aStartIndex         The index at which to split.
+ * @param aEndNode            The second node.
  * @param aCloneAfterOriginal Set PR_FALSE if the original node should be the
  *                            latter one after split.
  */
 static nsresult SplitDataNode(nsIDOMCharacterData* aStartNode,
                               PRUint32 aStartIndex,
-                              PRUint32 aEndIndex,
-                              nsIDOMCharacterData** aMiddleNode,
                               nsIDOMCharacterData** aEndNode,
                               PRBool aCloneAfterOriginal = PR_TRUE)
 {
   nsresult rv;
   nsCOMPtr<nsINode> node = do_QueryInterface(aStartNode);
   NS_ENSURE_STATE(node && node->IsNodeOfType(nsINode::eDATA_NODE));
   nsGenericDOMDataNode* dataNode = static_cast<nsGenericDOMDataNode*>(node.get());
-  // Split the main node, starting with the end.
-  if (aEndNode && aEndIndex > aStartIndex) {
-    nsCOMPtr<nsIContent> newData;
-    rv = dataNode->SplitData(aEndIndex, getter_AddRefs(newData),
-                             aCloneAfterOriginal);
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = CallQueryInterface(newData, aEndNode);
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
 
   nsCOMPtr<nsIContent> newData;
   rv = dataNode->SplitData(aStartIndex, getter_AddRefs(newData),
                            aCloneAfterOriginal);
   NS_ENSURE_SUCCESS(rv, rv);
-  return CallQueryInterface(newData, aMiddleNode);
+  return CallQueryInterface(newData, aEndNode);
 }
 
 nsresult PrependChild(nsIDOMNode* aParent, nsIDOMNode* aChild)
 {
   nsCOMPtr<nsIDOMNode> first, tmpNode;
   aParent->GetFirstChild(getter_AddRefs(first));
   return aParent->InsertBefore(aChild, first, getter_AddRefs(tmpNode));
 }
@@ -1289,39 +1272,45 @@ nsresult nsRange::CutContents(nsIDOMDocu
       {
         if (node == endContainer)
         {
           // This range is completely contained within a single text node.
           // Delete or extract the data between startOffset and endOffset.
 
           if (endOffset > startOffset)
           {
-            nsCOMPtr<nsIDOMCharacterData> cutNode;
-            nsCOMPtr<nsIDOMCharacterData> endNode;
-            rv = SplitDataNode(charData, startOffset, endOffset,
-                               getter_AddRefs(cutNode),
-                               getter_AddRefs(endNode));
+            if (retval) {
+              nsAutoString cutValue;
+              rv = charData->SubstringData(startOffset, endOffset - startOffset,
+                                           cutValue);
+              NS_ENSURE_SUCCESS(rv, rv);
+              nsCOMPtr<nsIDOMNode> clone;
+              rv = charData->CloneNode(PR_FALSE, getter_AddRefs(clone));
+              NS_ENSURE_SUCCESS(rv, rv);
+              clone->SetNodeValue(cutValue);
+              nodeToResult = clone;
+            }
+
+            rv = charData->DeleteData(startOffset, endOffset - startOffset);
             NS_ENSURE_SUCCESS(rv, rv);
-            nodeToResult = cutNode;
           }
 
           handled = PR_TRUE;
         }
         else
         {
           // Delete or extract everything after startOffset.
 
           rv = charData->GetLength(&dataLength);
           NS_ENSURE_SUCCESS(rv, rv);
 
           if (dataLength >= (PRUint32)startOffset)
           {
             nsCOMPtr<nsIDOMCharacterData> cutNode;
-            rv = SplitDataNode(charData, startOffset, dataLength,
-                               getter_AddRefs(cutNode), nsnull);
+            rv = SplitDataNode(charData, startOffset, getter_AddRefs(cutNode));
             NS_ENSURE_SUCCESS(rv, rv);
             nodeToResult = cutNode;
           }
 
           handled = PR_TRUE;
         }
       }
       else if (node == endContainer)
@@ -1329,18 +1318,18 @@ nsresult nsRange::CutContents(nsIDOMDocu
         // Delete or extract everything before endOffset.
 
         if (endOffset >= 0)
         {
           nsCOMPtr<nsIDOMCharacterData> cutNode;
           /* The Range spec clearly states clones get cut and original nodes
              remain behind, so use PR_FALSE as the last parameter.
           */
-          rv = SplitDataNode(charData, endOffset, endOffset,
-                             getter_AddRefs(cutNode), nsnull, PR_FALSE);
+          rv = SplitDataNode(charData, endOffset, getter_AddRefs(cutNode),
+                             PR_FALSE);
           NS_ENSURE_SUCCESS(rv, rv);
           nodeToResult = cutNode;
         }
 
         handled = PR_TRUE;
       }       
     }
 
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -312,16 +312,18 @@ include $(topsrcdir)/config/rules.mk
 		test_sync_xhr_timer.xhtml \
 		file_htmlserializer_ipv6.html \
 		file_htmlserializer_ipv6_out.html \
 		test_bug498433.html \
 		test_bug498897.html \
 		file_bug498897.html \
 		file_bug498897.html^headers^ \
 		file_bug498897.css \
+		test_bug493881.js \
+		test_bug493881.html \
 		$(NULL)
 # Disabled; see bug 492181
 #		test_plugin_freezing.html
 
 # Disabled for now. Mochitest isn't reliable enough for these.
 # test_bug444546.html \
 # bug444546.sjs \
 
--- a/content/base/test/test_bug417255.html
+++ b/content/base/test/test_bug417255.html
@@ -10,30 +10,30 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <style>
   .spacer { display:inline-block; height:10px; }
   </style>
 </head>
 <body>
 
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=417255">Mozilla Bug 417255</a>
-<p id="display" style="width:800px"></p>
+<div id="display" style="width:800px"></div>
 
-<p><span id="s1" style="border:2px dotted red;"><span class="spacer" style="width:100px"></span>
+<div><span id="s1" style="border:2px dotted red;"><span class="spacer" style="width:100px"></span>
 <div style="width:500px; height:100px; background:yellow;"></div>
-<span class="spacer" style="width:200px"></span></span>
+<span class="spacer" style="width:200px"></span></span></div>
 
-<p><span id="s2" style="border:2px dotted red;"><span class="spacer" style="width:100px"></span>
+<div><span id="s2" style="border:2px dotted red;"><span class="spacer" style="width:100px"></span>
 <div style="width:150px; height:100px; background:yellow;"></div>
-<span class="spacer" style="width:200px"></span></span>
+<span class="spacer" style="width:200px"></span></span></div>
 
 <!-- test nested spans around the IB split -->
-<p><span id="s3" style="border:2px dotted red;"><span><span class="spacer" style="width:100px"></span>
+<div><span id="s3" style="border:2px dotted red;"><span><span class="spacer" style="width:100px"></span>
 <div style="width:500px; height:100px; background:yellow;"></div>
-<span class="spacer" style="width:200px"></span></span></span>
+<span class="spacer" style="width:200px"></span></span></span></div>
 
 <div id="content" style="display: none">
 
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
--- a/content/base/test/test_bug454325.html
+++ b/content/base/test/test_bug454325.html
@@ -106,19 +106,39 @@ function testDocument2() {
   r.setStart(t1, 1);
   r.setEnd(d2, 2);
   is(r.toString(), "||", "Wrong range");
   var c1 = r.cloneContents();
   var e1 = r.extractContents();
   ok(c1.isEqualNode(e1), "Wrong cloning or extracting!");
 }
 
+function testSurroundContents() {
+  var div = document.createElement('div');
+  document.body.appendChild(div);
+  div.innerHTML = '<div>hello</div>world';
+  var innerDiv = div.firstChild;
+  var hello = innerDiv.firstChild;
+  var range = document.createRange();
+  range.setStart(hello, 0);
+  range.setEnd(hello, 5);
+  range.surroundContents(document.createElement('code'));
+  is(innerDiv.childNodes.length, 3, "Wrong childNodes count");
+  is(innerDiv.childNodes[0].nodeName, "#text", "Wrong node name (1)");
+  is(innerDiv.childNodes[0].textContent, "", "Wrong textContent (1)");
+  is(innerDiv.childNodes[1].nodeName, "CODE", "Wrong node name (2)");
+  is(innerDiv.childNodes[1].textContent, "hello", "Wrong textContent (2)");
+  is(innerDiv.childNodes[2].nodeName, "#text", "Wrong node name (3)");
+  is(innerDiv.childNodes[2].textContent, "", "Wrong textContent (3)");
+}
+
 function runTest() {
   testDocument1();
   testDocument2();
+  testSurroundContents();
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 
 
 </script>
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug493881.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=493881
+-->
+
+<head>
+  <title>Test for Bug 493881</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="test_bug493881.js"></script>     
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <style type="text/css">
+
+  </style>
+</head>
+
+<body>
+
+<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=493881"
+   target="_blank" >Mozilla Bug 493881</a>
+
+<p id="display"></p>
+
+<a id="nonvisitedlink" href="http://www.example.com/">Non-visited link</a>
+<a id="visitedlink" href="">Visited link</a>
+<p id="plaintext">some text</p>
+
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug493881.js
@@ -0,0 +1,72 @@
+/** 
+ * Test for Bug 493881: Changes to legacy HTML color properties before the BODY is loaded
+ * should be ignored. Additionally, after BODY loads, setting any of these properties to undefined 
+ * should cause them to be returned as the string "undefined".
+ */
+
+SimpleTest.waitForExplicitFinish();
+
+var legacyProps = ["fgColor", "bgColor", "linkColor", "vlinkColor", "alinkColor"];
+var testColors = ["blue", "silver", "green", "orange", "red"];
+var rgbTestColors = ["rgb(255, 0, 0)", "rgb(192, 192, 192)", "rgb(0, 128, 0)", "rgb(255, 165, 0)", "rgb(255, 0, 0)"];
+var idPropList = [ {id: "plaintext", prop: "color"},
+                   {id: "plaintext", prop: "background-color"},
+                   {id: "nonvisitedlink", prop: "color"},
+                   {id: "visitedlink", prop: "color"} ];
+var initialValues = [];
+
+function setAndTestProperty(prop, color) {
+  var initial = document[prop];
+  document[prop] = color;
+  is(document[prop], initial, "document[" + prop + "] not ignored before body");
+  return initial;
+}
+
+/**
+ * Attempt to set legacy color properties before BODY exists, and verify that such
+ * attempts are ignored.
+ */
+for (var i = 0; i < legacyProps.length; i++) {
+  initialValues[i] = setAndTestProperty(legacyProps[i], testColors[i]);
+}
+
+/**
+ * After BODY loads, run some more tests.
+ */
+addLoadEvent( function() {
+  // Verify that the legacy color properties still have their original values.
+  for (var i = 0; i < legacyProps.length; i++) {
+    is(document[legacyProps[i]], initialValues[i], "document[" + legacyProps[i] + "] altered after body load");
+  }
+  
+  // Verify that legacy color properties applied before BODY are really ignored when rendering.
+  // Save current computed style colors for later use.
+  for (i = 0; i < idPropList.length; i++) {
+    var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null);
+    var color = style.getPropertyValue(idPropList[i].prop);
+    idPropList[i].initialComputedColor = color;
+    isnot(color, rgbTestColors[i], "element rendered using before-body style");
+  }
+  // XXX: Can't get links to visually activate via script events, so can't verify
+  // that the alinkColor property was not applied.
+  
+  // Verify that setting legacy color props to undefined after BODY loads will cause them
+  // to be read as the string "undefined".
+  for (var i = 0; i < legacyProps.length; i++) {
+    document[legacyProps[i]] = undefined;
+    is(document[legacyProps[i]], "undefined", 
+      "Unexpected value of " + legacyProps[i] + " after setting to undefined");
+  }
+  
+  // Verify that setting legacy color props to undefined did not affect rendering 
+  // (computed styles).
+  for (i = 0; i < idPropList.length; i++) {
+    var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null);
+    var color = style.getPropertyValue(idPropList[i].prop);
+    is(color, idPropList[i].initialComputedColor, 
+      "element's style changed by setting legacy prop to undefined");
+  }
+
+  // Mark the test as finished.
+  setTimeout(SimpleTest.finish, 0);
+});
--- a/content/canvas/public/Makefile.in
+++ b/content/canvas/public/Makefile.in
@@ -44,9 +44,13 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE		= content
 
 EXPORTS		= \
 		nsICanvasRenderingContextInternal.h \
 		nsICanvasElement.h \
 		$(NULL)
 
+XPIDLSRCS	= \
+		nsICanvasGLPrivate.idl \
+		$(NULL)
+
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/content/canvas/public/nsICanvasGLPrivate.idl
@@ -0,0 +1,53 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is canvas 3D.
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Vladimir Vukicevic <vladimir@pobox.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsISupports.idl"
+
+/* These are private interface that's used to identify
+ * specific concrete classes so we know what we can cast.
+ */
+
+[scriptable, uuid(eba2aa03-ae19-46e2-bad7-6b966037e22c)]
+interface nsICanvasGLBuffer : nsISupports
+{
+};
+
+[scriptable, uuid(27310aab-1988-43e8-882e-6293c8c9df60)]
+interface nsICanvasGLTexture : nsISupports
+{
+};
--- a/content/canvas/src/Makefile.in
+++ b/content/canvas/src/Makefile.in
@@ -69,16 +69,46 @@ REQUIRES	= \
 		$(NULL)
 
 
 CPPSRCS	= \
 	CanvasUtils.cpp \
 	nsCanvasRenderingContext2D.cpp \
 	$(NULL)
 
+# Canvas 3D Pieces
+
+ifdef MOZ_ENABLE_CANVAS3D
+
+CPPSRCS += \
+	nsCanvasRenderingContextGL.cpp \
+	nsCanvasRenderingContextGLWeb20.cpp \
+	glwrap.cpp \
+	nsGLPbuffer.cpp \
+	nsGLPbufferOSMesa.cpp \
+	$(NULL)
+
+ifdef MOZ_X11
+EXTRA_DSO_LIBS += X11
+CPPSRCS += nsGLPbufferGLX.cpp
+DEFINES += -DUSE_GLX
+endif
+
+ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
+CPPSRCS += nsGLPbufferWGL.cpp
+DEFINES += -DUSE_WGL
+endif
+
+ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),mac cocoa))
+CPPSRCS += nsGLPbufferCGL.cpp
+DEFINES += -DUSE_CGL
+endif
+
+endif
+
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 CXXFLAGS	+= $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
 
 INCLUDES	+= \
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/NativeJSContext.h
@@ -0,0 +1,390 @@
+#ifndef _NATIVEJSCONTEXT_H_
+#define _NATIVEJSCONTEXT_H_
+
+class JSObjectHelper;
+
+class NativeJSContext {
+public:
+    NativeJSContext() {
+        error = gXPConnect->GetCurrentNativeCallContext(&ncc);
+        if (NS_FAILED(error))
+            return;
+
+        if (!ncc) {
+            error = NS_ERROR_FAILURE;
+            return;
+        }
+
+        ctx = nsnull;
+
+        error = ncc->GetJSContext(&ctx);
+        if (NS_FAILED(error))
+            return;
+
+        JS_BeginRequest(ctx);
+
+        ncc->GetArgc(&argc);
+        ncc->GetArgvPtr(&argv);
+    }
+
+    ~NativeJSContext() {
+        JS_EndRequest(ctx);
+    }
+
+    PRBool CheckArray (JSObject *obj, jsuint *sz) {
+        if (obj &&
+            ::JS_IsArrayObject(ctx, obj) &&
+            ::JS_GetArrayLength(ctx, obj, sz))
+            return PR_TRUE;
+        return PR_FALSE;
+    }
+
+    PRBool CheckArray (jsval val, jsuint *sz) {
+        if (!JSVAL_IS_NULL(val) &&
+            JSVAL_IS_OBJECT(val) &&
+            ::JS_IsArrayObject(ctx, JSVAL_TO_OBJECT(val)) &&
+            ::JS_GetArrayLength(ctx, JSVAL_TO_OBJECT(val), sz))
+            return PR_TRUE;
+        return PR_FALSE;
+    }
+
+    PRBool AddGCRoot (void *aPtr, const char *aName) {
+        return JS_AddNamedRootRT(gScriptRuntime, aPtr, aName);
+    }
+
+    void ReleaseGCRoot (void *aPtr) {
+        JS_RemoveRootRT(gScriptRuntime, aPtr);
+    }
+
+    void SetRetVal (PRInt32 val) {
+        if (INT_FITS_IN_JSVAL(val))
+            SetRetValAsJSVal(INT_TO_JSVAL(val));
+        else
+            SetRetVal((double) val);
+    }
+
+    void SetRetVal (PRUint32 val) {
+        if (INT_FITS_IN_JSVAL(val))
+            SetRetValAsJSVal(INT_TO_JSVAL((int) val));
+        else
+            SetRetVal((double) val);
+    }
+
+    void SetRetVal (double val) {
+        jsval *vp;
+        ncc->GetRetValPtr(&vp);
+        JS_NewDoubleValue(ctx, val, vp);
+    }
+
+    void SetBoolRetVal (PRBool val) {
+        if (val)
+            SetRetValAsJSVal(JSVAL_TRUE);
+        else
+            SetRetValAsJSVal(JSVAL_FALSE);
+    }
+
+    void SetRetVal (PRInt32 *vp, PRUint32 len) {
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+
+        if (!JS_EnterLocalRootScope(ctx))
+            return; // XXX ???
+
+        for (PRUint32 i = 0; i < len; i++) {
+            if (INT_FITS_IN_JSVAL(vp[i])) {
+                jsvector[i] = INT_TO_JSVAL(vp[i]);
+            } else {
+                JS_NewDoubleValue(ctx, vp[i], &jsvector[i]);
+            }
+        }
+
+        JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
+        SetRetVal(jsarr);
+
+        JS_LeaveLocalRootScope(ctx);
+    }
+
+    void SetRetVal (PRUint32 *vp, PRUint32 len) {
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+
+        if (!JS_EnterLocalRootScope(ctx))
+            return; // XXX ???
+
+        for (PRUint32 i = 0; i < len; i++) {
+            JS_NewNumberValue(ctx, vp[i], &jsvector[i]);
+        }
+
+        JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
+        SetRetVal(jsarr);
+
+        JS_LeaveLocalRootScope(ctx);
+    }
+
+    void SetRetVal (double *dp, PRUint32 len) {
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+
+        if (!JS_EnterLocalRootScope(ctx))
+            return; // XXX ???
+
+        for (PRUint32 i = 0; i < len; i++)
+            JS_NewDoubleValue(ctx, (jsdouble) dp[i], &jsvector[i]);
+            
+        JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
+        SetRetVal(jsarr);
+
+        JS_LeaveLocalRootScope(ctx);
+    }
+
+    void SetRetVal (float *fp, PRUint32 len) {
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+
+        if (!JS_EnterLocalRootScope(ctx))
+            return; // XXX ???
+
+        for (PRUint32 i = 0; i < len; i++)
+            JS_NewDoubleValue(ctx, (jsdouble) fp[i], &jsvector[i]);
+        JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
+        SetRetVal(jsarr);
+
+        JS_LeaveLocalRootScope(ctx);
+    }
+
+    void SetRetValAsJSVal (jsval val) {
+        jsval *vp;
+        ncc->GetRetValPtr(&vp);
+        *vp = val;
+        ncc->SetReturnValueWasSet(PR_TRUE);
+    }
+
+    void SetRetVal (JSObject *obj) {
+        SetRetValAsJSVal(OBJECT_TO_JSVAL(obj));
+    }
+
+    void SetRetVal (JSObjectHelper& objh);
+
+    nsAXPCNativeCallContext *ncc;
+    nsresult error;
+    JSContext *ctx;
+    PRUint32 argc;
+    jsval *argv;
+
+public:
+    // static JS helpers
+
+    static inline PRBool JSValToFloatArray (JSContext *ctx, jsval val,
+                                            jsuint cnt, float *array)
+    {
+        JSObject *arrayObj;
+        jsuint arrayLen;
+        jsval jv;
+        jsdouble dv;
+
+        if (!::JS_ValueToObject(ctx, val, &arrayObj) ||
+            arrayObj == NULL ||
+            !::JS_IsArrayObject(ctx, arrayObj) ||
+            !::JS_GetArrayLength(ctx, arrayObj, &arrayLen) ||
+            (arrayLen < cnt))
+            return PR_FALSE;
+
+        for (jsuint i = 0; i < cnt; i++) {
+            ::JS_GetElement(ctx, arrayObj, i, &jv);
+            if (!::JS_ValueToNumber(ctx, jv, &dv))
+                return PR_FALSE;
+            array[i] = (float) dv;
+        }
+
+        return PR_TRUE;
+    }
+
+    static inline PRBool JSValToDoubleArray (JSContext *ctx, jsval val,
+                                             jsuint cnt, double *array)
+    {
+        JSObject *arrayObj;
+        jsuint arrayLen;
+        jsval jv;
+        jsdouble dv;
+
+        if (!::JS_ValueToObject(ctx, val, &arrayObj) ||
+            arrayObj == NULL ||
+            !::JS_IsArrayObject(ctx, arrayObj) ||
+            !::JS_GetArrayLength(ctx, arrayObj, &arrayLen) ||
+            (arrayLen < cnt))
+            return PR_FALSE;
+
+        for (jsuint i = 0; i < cnt; i++) {
+            ::JS_GetElement(ctx, arrayObj, i, &jv);
+            if (!::JS_ValueToNumber(ctx, jv, &dv))
+                return PR_FALSE;
+            array[i] = dv;
+        }
+
+        return PR_TRUE;
+    }
+
+    static inline PRBool JSValToJSArrayAndLength (JSContext *ctx, jsval val,
+                                                  JSObject **outObj, jsuint *outLen)
+    {
+        JSObject *obj = nsnull;
+        jsuint len;
+        if (!::JS_ValueToObject(ctx, val, &obj) ||
+            obj == NULL ||
+            !::JS_IsArrayObject(ctx, obj) ||
+            !::JS_GetArrayLength(ctx, obj, &len))
+        {
+            return PR_FALSE;
+        }
+
+        *outObj = obj;
+        *outLen = len;
+
+        return PR_TRUE;
+    }
+
+    template<class T>
+    static nsresult JSValToSpecificInterface(JSContext *ctx, jsval val, T **out)
+    {
+        if (JSVAL_IS_NULL(val)) {
+            *out = nsnull;
+            return NS_OK;
+        }
+
+        if (!JSVAL_IS_OBJECT(val))
+            return NS_ERROR_DOM_SYNTAX_ERR;
+
+        nsCOMPtr<nsISupports> isup;
+        nsresult rv = gXPConnect->WrapJS(ctx, JSVAL_TO_OBJECT(val),
+                                         NS_GET_IID(nsISupports),
+                                         getter_AddRefs(isup));
+        if (NS_FAILED(rv))
+            return NS_ERROR_DOM_SYNTAX_ERR;
+
+        nsCOMPtr<T> obj = do_QueryInterface(isup);
+        if (!obj)
+            return NS_ERROR_DOM_SYNTAX_ERR;
+
+        NS_ADDREF(*out = obj.get());
+        return NS_OK;
+    }
+
+    static inline JSObject *ArrayToJSArray (JSContext *ctx,
+                                            const PRInt32 *vals,
+                                            const PRUint32 len)
+    {
+        // XXX handle ints that are too big to fit
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+        for (PRUint32 i = 0; i < len; i++)
+            jsvector[i] = INT_TO_JSVAL(vals[i]);
+        return JS_NewArrayObject(ctx, len, jsvector);
+    }
+
+    static inline JSObject *ArrayToJSArray (JSContext *ctx,
+                                            const PRUint32 *vals,
+                                            const PRUint32 len)
+    {
+        // XXX handle ints that are too big to fit
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
+        for (PRUint32 i = 0; i < len; i++)
+            jsvector[i] = INT_TO_JSVAL(vals[i]);
+        return JS_NewArrayObject(ctx, len, jsvector);
+    }
+
+};
+
+class JSObjectHelper {
+    friend class NativeJSContext;
+public:
+    JSObjectHelper(NativeJSContext *jsctx)
+        : mCtx (jsctx)
+    {
+        mObject = JS_NewObject(mCtx->ctx, NULL, NULL, NULL);
+        if (!mObject)
+            return;
+
+        if (!mCtx->AddGCRoot(&mObject, "JSObjectHelperCanvas3D"))
+            mObject = nsnull;
+    }
+
+    ~JSObjectHelper() {
+        if (mObject && mCtx)
+            mCtx->ReleaseGCRoot(&mObject);
+    }
+
+    PRBool DefineProperty(const char *name, PRInt32 val) {
+        // XXX handle too big ints
+        if (!JS_DefineProperty(mCtx->ctx, mObject, name, INT_TO_JSVAL(val), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    PRBool DefineProperty(const char *name, PRUint32 val) {
+        // XXX handle too big ints
+        if (!JS_DefineProperty(mCtx->ctx, mObject, name, INT_TO_JSVAL((int)val), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    PRBool DefineProperty(const char *name, double val) {
+        jsval dv;
+
+        if (!JS_NewDoubleValue(mCtx->ctx, val, &dv))
+            return PR_FALSE;
+
+        if (!JS_DefineProperty(mCtx->ctx, mObject, name, dv, NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    PRBool DefineProperty(const char *name, JSObject *val) {
+        if (!JS_DefineProperty(mCtx->ctx, mObject, name, OBJECT_TO_JSVAL(val), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    // Blah.  We can't name this DefineProperty also because PRBool is the same as PRInt32
+    PRBool DefineBoolProperty(const char *name, PRBool val) {
+        if (!JS_DefineProperty(mCtx->ctx, mObject, name, val ? JS_TRUE : JS_FALSE, NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    // We can't use ns*Substring, because we don't have internal linkage
+#if 0
+    PRBool DefineProperty(const char *name, const nsCSubstring& val) {
+        JSString *jsstr = JS_NewStringCopyN(mCtx->ctx, val.BeginReading(), val.Length());
+        if (!jsstr ||
+            !JS_DefineProperty(mCtx->ctx, mObject, name, STRING_TO_JSVAL(jsstr), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    PRBool DefineProperty(const char *name, const nsSubstring& val) {
+        JSString *jsstr = JS_NewUCStringCopyN(mCtx->ctx, val.BeginReading(), val.Length());
+        if (!jsstr ||
+            !JS_DefineProperty(mCtx->ctx, mObject, name, STRING_TO_JSVAL(jsstr), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+#endif
+
+    PRBool DefineProperty(const char *name, const char *val, PRUint32 len) {
+        JSString *jsstr = JS_NewStringCopyN(mCtx->ctx, val, len);
+        if (!jsstr ||
+            !JS_DefineProperty(mCtx->ctx, mObject, name, STRING_TO_JSVAL(jsstr), NULL, NULL, JSPROP_ENUMERATE))
+            return PR_FALSE;
+        return PR_TRUE;
+    }
+
+    JSObject *Object() {
+        return mObject;
+    }
+
+protected:
+    NativeJSContext *mCtx;
+    JSObject *mObject;
+};
+
+inline void
+NativeJSContext::SetRetVal(JSObjectHelper& objh) {
+    SetRetValAsJSVal(OBJECT_TO_JSVAL(objh.mObject));
+}
+
+#endif
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/glwrap.cpp
@@ -0,0 +1,298 @@
+#ifdef C3D_STANDALONE_BUILD
+#include "c3d-standalone.h"
+#endif
+
+#include <string.h>
+#include <stdio.h>
+
+#include "prlink.h"
+
+#include "glwrap.h"
+
+#define MAX_SYMBOL_LENGTH 128
+#define MAX_SYMBOL_NAMES 5
+
+#ifdef MOZ_X11
+#include <GL/glx.h>
+#endif
+
+bool
+LibrarySymbolLoader::OpenLibrary(const char *library)
+{
+    PRLibSpec lspec;
+    lspec.type = PR_LibSpec_Pathname;
+    lspec.value.pathname = library;
+
+    mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
+    if (!mLibrary)
+        return false;
+
+    return true;
+}
+
+PRFuncPtr
+LibrarySymbolLoader::LookupSymbol(const char *sym, bool tryplatform)
+{
+    PRFuncPtr res = 0;
+
+    // try finding it in the library directly, if we have one
+    if (mLibrary) {
+        res = PR_FindFunctionSymbol(mLibrary, sym);
+    }
+
+    // try finding it in the process
+    if (!res) {
+        PRLibrary *leakedLibRef;
+        res = PR_FindFunctionSymbolAndLibrary(sym, &leakedLibRef);
+    }
+
+    // no? then try looking it up via the lookup symbol
+    if (!res && tryplatform && mLookupFunc) {
+        res = mLookupFunc (sym);
+    }
+
+    return res;
+}
+
+bool
+LibrarySymbolLoader::LoadSymbols(SymLoadStruct *firstStruct, bool tryplatform, const char *prefix)
+{
+    char sbuf[MAX_SYMBOL_LENGTH * 2];
+
+    SymLoadStruct *ss = firstStruct;
+    while (ss->symPointer) {
+        *ss->symPointer = 0;
+
+        for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
+            if (ss->symNames[i] == NULL)
+                break;
+
+            const char *s = ss->symNames[i];
+            if (prefix && *prefix != 0) {
+                strcpy(sbuf, prefix);
+                strcat(sbuf, ss->symNames[i]);
+                s = sbuf;
+            }
+
+            PRFuncPtr p = LookupSymbol(s, tryplatform);
+            if (p) {
+                *ss->symPointer = p;
+                break;
+            }
+        }
+
+        if (*ss->symPointer == 0) {
+            fprintf (stderr, "Can't find symbol '%s'\n", ss->symNames[0]);
+            return false;
+        }
+
+        ss++;
+    }
+
+    return true;
+}
+
+bool
+OSMesaWrap::Init()
+{
+    if (fCreateContextExt)
+        return true;
+
+    SymLoadStruct symbols[] = {
+        { (PRFuncPtr*) &fCreateContextExt, { "OSMesaCreateContextExt", NULL } },
+        { (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
+        { (PRFuncPtr*) &fPixelStore, { "OSMesaPixelStore", NULL } },
+        { (PRFuncPtr*) &fDestroyContext, { "OSMesaDestroyContext", NULL } },
+        { (PRFuncPtr*) &fGetCurrentContext, { "OSMesaGetCurrentContext", NULL } },
+        { (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
+        { (PRFuncPtr*) &fGetProcAddress, { "OSMesaGetProcAddress", NULL } },
+        { NULL, { NULL } }
+    };
+
+    return LoadSymbols(&symbols[0]);
+}
+
+bool
+GLES20Wrap::Init(NativeGLMode mode)
+{
+    if (mode & TRY_NATIVE_GL) {
+        if (InitNative())
+            return true;
+    }
+
+    if (mode & TRY_SOFTWARE_GL) {
+        if (InitSoftware())
+            return true;
+    }
+
+    return false;
+}
+
+bool
+GLES20Wrap::InitNative()
+{
+    return InitWithPrefix("gl", true);
+}
+
+bool
+GLES20Wrap::InitSoftware()
+{
+    return InitWithPrefix("mgl", true);
+}
+
+/*
+ * XXX - we should really know the ARB/EXT variants of these
+ * instead of only handling the symbol if it's exposed directly.
+ */
+
+bool
+GLES20Wrap::InitWithPrefix(const char *prefix, bool trygl)
+{
+    if (ok)
+        return true;
+
+    SymLoadStruct symbols[] = {
+        { (PRFuncPtr*) &fActiveTexture, { "ActiveTexture", "ActiveTextureARB", NULL } },
+        { (PRFuncPtr*) &fAttachShader, { "AttachShader", "AttachShaderARB", NULL } },
+        { (PRFuncPtr*) &fBindAttribLocation, { "BindAttribLocation", "BindAttribLocationARB", NULL } },
+        { (PRFuncPtr*) &fBindBuffer, { "BindBuffer", "BindBufferARB", NULL } },
+        { (PRFuncPtr*) &fBindTexture, { "BindTexture", "BindTextureARB", NULL } },
+        { (PRFuncPtr*) &fBlendColor, { "BlendColor", NULL } },
+        { (PRFuncPtr*) &fBlendEquation, { "BlendEquation", NULL } },
+        { (PRFuncPtr*) &fBlendEquationSeparate, { "BlendEquationSeparate", "BlendEquationSeparateEXT", NULL } },
+        { (PRFuncPtr*) &fBlendFunc, { "BlendFunc", NULL } },
+        { (PRFuncPtr*) &fBlendFuncSeparate, { "BlendFuncSeparate", "BlendFuncSeparateEXT", NULL } },
+        { (PRFuncPtr*) &fBufferData, { "BufferData", NULL } },
+        { (PRFuncPtr*) &fBufferSubData, { "BufferSubData", NULL } },
+        { (PRFuncPtr*) &fClear, { "Clear", NULL } },
+        { (PRFuncPtr*) &fClearColor, { "ClearColor", NULL } },
+        { (PRFuncPtr*) &fClearDepth, { "ClearDepth", NULL } },
+        { (PRFuncPtr*) &fClearStencil, { "ClearStencil", NULL } },
+        { (PRFuncPtr*) &fColorMask, { "ColorMask", NULL } },
+        { (PRFuncPtr*) &fCreateProgram, { "CreateProgram", "CreateProgramARB", NULL } },
+        { (PRFuncPtr*) &fCreateShader, { "CreateShader", "CreateShaderARB", NULL } },
+        { (PRFuncPtr*) &fCullFace, { "CullFace", NULL } },
+        { (PRFuncPtr*) &fDeleteBuffers, { "DeleteBuffers", "DeleteBuffersARB", NULL } },
+        { (PRFuncPtr*) &fDeleteTextures, { "DeleteTextures", "DeleteTexturesARB", NULL } },
+        { (PRFuncPtr*) &fDeleteProgram, { "DeleteProgram", "DeleteProgramARB", NULL } },
+        { (PRFuncPtr*) &fDeleteShader, { "DeleteShader", "DeleteShaderARB", NULL } },
+        { (PRFuncPtr*) &fDetachShader, { "DetachShader", "DetachShaderARB", NULL } },
+        { (PRFuncPtr*) &fDepthFunc, { "DepthFunc", NULL } },
+        { (PRFuncPtr*) &fDepthMask, { "DepthMask", NULL } },
+        { (PRFuncPtr*) &fDepthRange, { "DepthRange", NULL } },
+        { (PRFuncPtr*) &fDisable, { "Disable", NULL } },
+        { (PRFuncPtr*) &fDisableVertexAttribArray, { "DisableVertexAttribArray", "DisableVertexAttribArrayARB", NULL } },
+        { (PRFuncPtr*) &fDrawArrays, { "DrawArrays", NULL } },
+        { (PRFuncPtr*) &fDrawElements, { "DrawElements", NULL } },
+        { (PRFuncPtr*) &fEnable, { "Enable", NULL } },
+        { (PRFuncPtr*) &fEnableVertexAttribArray, { "EnableVertexAttribArray", "EnableVertexAttribArrayARB", NULL } },
+        { (PRFuncPtr*) &fFinish, { "Finish", NULL } },
+        { (PRFuncPtr*) &fFlush, { "Flush", NULL } },
+        { (PRFuncPtr*) &fFrontFace, { "FrontFace", NULL } },
+        { (PRFuncPtr*) &fGetActiveAttrib, { "GetActiveAttrib", "GetActiveAttribARB", NULL } },
+        { (PRFuncPtr*) &fGetActiveUniform, { "GetActiveUniform", "GetActiveUniformARB", NULL } },
+        { (PRFuncPtr*) &fGetAttachedShaders, { "GetAttachedShaders", "GetAttachedShadersARB", NULL } },
+        { (PRFuncPtr*) &fGetAttribLocation, { "GetAttribLocation", "GetAttribLocationARB", NULL } },
+        { (PRFuncPtr*) &fGetIntegerv, { "GetIntegerv", NULL } },
+        { (PRFuncPtr*) &fGetDoublev, { "GetDoublev", NULL } },
+        { (PRFuncPtr*) &fGetFloatv, { "GetFloatv", NULL } },
+        { (PRFuncPtr*) &fGetBooleanv, { "GetBooleanv", NULL } },
+        { (PRFuncPtr*) &fGetBufferParameteriv, { "GetBufferParameteriv", "GetBufferParameterivARB", NULL } },
+        { (PRFuncPtr*) &fGenBuffers, { "GenBuffers", "GenBuffersARB", NULL } },
+        { (PRFuncPtr*) &fGenTextures, { "GenTextures", NULL } },
+        { (PRFuncPtr*) &fGetError, { "GetError", NULL } },
+        { (PRFuncPtr*) &fGetProgramiv, { "GetProgramiv", "GetProgramivARB", NULL } },
+        { (PRFuncPtr*) &fGetProgramInfoLog, { "GetProgramInfoLog", "GetProgramInfoLogARB", NULL } },
+        { (PRFuncPtr*) &fTexParameteri, { "TexParameteri", NULL } },
+        { (PRFuncPtr*) &fTexParameterf, { "TexParameterf", NULL } },
+        { (PRFuncPtr*) &fGetTexParameteriv, { "GetTexParameteriv", NULL } },
+        { (PRFuncPtr*) &fGetUniformfv, { "GetUniformfv", "GetUniformfvARB", NULL } },
+        { (PRFuncPtr*) &fGetUniformiv, { "GetUniformiv", "GetUniformivARB", NULL } },
+        { (PRFuncPtr*) &fGetUniformLocation, { "GetUniformLocation", "GetUniformLocationARB", NULL } },
+        { (PRFuncPtr*) &fGetVertexAttribdv, { "GetVertexAttribdv", "GetVertexAttribdvARB", NULL } },
+        { (PRFuncPtr*) &fGetVertexAttribfv, { "GetVertexAttribfv", "GetVertexAttribfvARB", NULL } },
+        { (PRFuncPtr*) &fGetVertexAttribiv, { "GetVertexAttribiv", "GetVertexAttribivARB", NULL } },
+        { (PRFuncPtr*) &fHint, { "Hint", NULL } },
+        { (PRFuncPtr*) &fIsBuffer, { "IsBuffer", "IsBufferARB", NULL } },
+        { (PRFuncPtr*) &fIsEnabled, { "IsEnabled", NULL } },
+        { (PRFuncPtr*) &fIsProgram, { "IsProgram", "IsProgramARB", NULL } },
+        { (PRFuncPtr*) &fIsShader, { "IsShader", "IsShaderARB", NULL } },
+        { (PRFuncPtr*) &fIsTexture, { "IsTexture", "IsTextureARB", NULL } },
+        { (PRFuncPtr*) &fLineWidth, { "LineWidth", NULL } },
+        { (PRFuncPtr*) &fLinkProgram, { "LinkProgram", "LinkProgramARB", NULL } },
+        { (PRFuncPtr*) &fPixelStorei, { "PixelStorei", NULL } },
+        { (PRFuncPtr*) &fPolygonOffset, { "PolygonOffset", NULL } },
+        { (PRFuncPtr*) &fReadPixels, { "ReadPixels", NULL } },
+        { (PRFuncPtr*) &fSampleCoverage, { "SampleCoverage", NULL } },
+        { (PRFuncPtr*) &fScissor, { "Scissor", NULL } },
+        { (PRFuncPtr*) &fStencilFunc, { "StencilFunc", NULL } },
+        { (PRFuncPtr*) &fStencilFuncSeparate, { "StencilFuncSeparate", "StencilFuncSeparateEXT", NULL } },
+        { (PRFuncPtr*) &fStencilMask, { "StencilMask", NULL } },
+        { (PRFuncPtr*) &fStencilMaskSeparate, { "StencilMaskSeparate", "StencilMaskSeparateEXT", NULL } },
+        { (PRFuncPtr*) &fStencilOp, { "StencilOp", NULL } },
+        { (PRFuncPtr*) &fStencilOpSeparate, { "StencilOpSeparate", "StencilOpSeparateEXT", NULL } },
+        { (PRFuncPtr*) &fTexImage2D, { "TexImage2D", NULL } },
+        { (PRFuncPtr*) &fTexSubImage2D, { "TexSubImage2D", NULL } },
+        { (PRFuncPtr*) &fUniform1f, { "Uniform1f", NULL } },
+        { (PRFuncPtr*) &fUniform1fv, { "Uniform1fv", NULL } },
+        { (PRFuncPtr*) &fUniform1i, { "Uniform1i", NULL } },
+        { (PRFuncPtr*) &fUniform1iv, { "Uniform1iv", NULL } },
+        { (PRFuncPtr*) &fUniform2f, { "Uniform2f", NULL } },
+        { (PRFuncPtr*) &fUniform2fv, { "Uniform2fv", NULL } },
+        { (PRFuncPtr*) &fUniform2i, { "Uniform2i", NULL } },
+        { (PRFuncPtr*) &fUniform2iv, { "Uniform2iv", NULL } },
+        { (PRFuncPtr*) &fUniform3f, { "Uniform3f", NULL } },
+        { (PRFuncPtr*) &fUniform3fv, { "Uniform3fv", NULL } },
+        { (PRFuncPtr*) &fUniform3i, { "Uniform3i", NULL } },
+        { (PRFuncPtr*) &fUniform3iv, { "Uniform3iv", NULL } },
+        { (PRFuncPtr*) &fUniform4f, { "Uniform4f", NULL } },
+        { (PRFuncPtr*) &fUniform4fv, { "Uniform4fv", NULL } },
+        { (PRFuncPtr*) &fUniform4i, { "Uniform4i", NULL } },
+        { (PRFuncPtr*) &fUniform4iv, { "Uniform4iv", NULL } },
+        { (PRFuncPtr*) &fUniformMatrix2fv, { "UniformMatrix2fv", NULL } },
+        { (PRFuncPtr*) &fUniformMatrix3fv, { "UniformMatrix3fv", NULL } },
+        { (PRFuncPtr*) &fUniformMatrix4fv, { "UniformMatrix4fv", NULL } },
+        { (PRFuncPtr*) &fUseProgram, { "UseProgram", NULL } },
+        { (PRFuncPtr*) &fValidateProgram, { "ValidateProgram", NULL } },
+        { (PRFuncPtr*) &fVertexAttribPointer, { "VertexAttribPointer", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib1f, { "VertexAttrib1f", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib2f, { "VertexAttrib2f", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib3f, { "VertexAttrib3f", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib4f, { "VertexAttrib4f", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib1fv, { "VertexAttrib1fv", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib2fv, { "VertexAttrib2fv", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib3fv, { "VertexAttrib3fv", NULL } },
+        { (PRFuncPtr*) &fVertexAttrib4fv, { "VertexAttrib4fv", NULL } },
+        { (PRFuncPtr*) &fViewport, { "Viewport", NULL } },
+        { (PRFuncPtr*) &fCompileShader, { "CompileShader", NULL } },
+        { (PRFuncPtr*) &fCopyTexImage2D, { "CopyTexImage2D", NULL } },
+        { (PRFuncPtr*) &fCopyTexSubImage2D, { "CopyTexSubImage2D", NULL } },
+        { (PRFuncPtr*) &fGetShaderiv, { "GetShaderiv", NULL } },
+        { (PRFuncPtr*) &fGetShaderInfoLog, { "GetShaderInfoLog", NULL } },
+        { (PRFuncPtr*) &fGetShaderSource, { "GetShaderSource", NULL } },
+        { (PRFuncPtr*) &fShaderSource, { "ShaderSource", NULL } },
+        { (PRFuncPtr*) &fVertexAttribPointer, { "VertexAttribPointer", NULL } },
+        { (PRFuncPtr*) &fBindFramebuffer, { "BindFramebuffer", "BindFramebufferEXT", NULL } },
+        { (PRFuncPtr*) &fBindRenderbuffer, { "BindRenderbuffer", "BindRenderbufferEXT", NULL } },
+        { (PRFuncPtr*) &fCheckFramebufferStatus, { "CheckFramebufferStatus", "CheckFramebufferStatusEXT", NULL } },
+        { (PRFuncPtr*) &fDeleteFramebuffers, { "DeleteFramebuffers", "DeleteFramebuffersEXT", NULL } },
+        { (PRFuncPtr*) &fDeleteRenderbuffers, { "DeleteRenderbuffers", "DeleteRenderbuffersEXT", NULL } },
+        { (PRFuncPtr*) &fFramebufferRenderbuffer, { "FramebufferRenderbuffer", "FramebufferRenderbufferEXT", NULL } },
+        { (PRFuncPtr*) &fFramebufferTexture2D, { "FramebufferTexture2D", "FramebufferTexture2DEXT", NULL } },
+        { (PRFuncPtr*) &fGenerateMipmap, { "GenerateMipmap", "GenerateMipmapEXT", NULL } },
+        { (PRFuncPtr*) &fGenFramebuffers, { "GenFramebuffers", "GenFramebuffersEXT", NULL } },
+        { (PRFuncPtr*) &fGenRenderbuffers, { "GenRenderbuffers", "GenRenderbuffersEXT", NULL } },
+        { (PRFuncPtr*) &fGetFramebufferAttachmentParameteriv, { "GetFramebufferAttachmentParameteriv", "GetFramebufferAttachmentParameterivEXT", NULL } },
+        { (PRFuncPtr*) &fGetRenderbufferParameteriv, { "GetRenderbufferParameteriv", "GetRenderbufferParameterivEXT", NULL } },
+        { (PRFuncPtr*) &fIsFramebuffer, { "IsFramebuffer", "IsFramebufferEXT", NULL } },
+        { (PRFuncPtr*) &fIsRenderbuffer, { "IsRenderbuffer", "IsRenderbufferEXT", NULL } },
+        { (PRFuncPtr*) &fRenderbufferStorage, { "RenderbufferStorage", "RenderbufferStorageEXT", NULL } },
+
+        { NULL, { NULL } },
+
+    };
+
+    ok = LoadSymbols(&symbols[0], trygl, prefix);
+
+    return ok;
+}
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/glwrap.h
@@ -0,0 +1,388 @@
+
+#ifndef GLWRAP_H_
+#define GLWRAP_H_
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include "localgl.h"
+
+#include "prlink.h"
+
+#ifndef GLAPIENTRY
+#ifdef XP_WIN
+#define GLAPIENTRY __stdcall
+#else
+#define GLAPIENTRY
+#endif
+#define GLAPI
+#endif
+
+class LibrarySymbolLoader
+{
+public:
+    bool OpenLibrary(const char *library);
+
+    typedef PRFuncPtr (GLAPIENTRY * PlatformLookupFunction) (const char *);
+    void SetLookupFunc(PlatformLookupFunction plf) {
+        mLookupFunc = plf;
+    }
+
+    enum {
+        MAX_SYMBOL_NAMES = 5,
+        MAX_SYMBOL_LENGTH = 128
+    };
+
+    typedef struct {
+        PRFuncPtr *symPointer;
+        const char *symNames[MAX_SYMBOL_NAMES];
+    } SymLoadStruct;
+
+    PRFuncPtr LookupSymbol(const char *symname, bool tryplatform = false);
+    bool LoadSymbols(SymLoadStruct *firstStruct, bool tryplatform = false, const char *prefix = NULL);
+
+protected:
+    LibrarySymbolLoader() {
+        mLibrary = NULL;
+        mLookupFunc = NULL;
+    }
+
+    PRLibrary *mLibrary;
+    PlatformLookupFunction mLookupFunc;
+};
+
+typedef void *PrivateOSMesaContext;
+
+class OSMesaWrap
+    : public LibrarySymbolLoader
+{
+public:
+    OSMesaWrap() : fCreateContextExt(0) { }
+
+    bool Init();
+
+protected:
+
+    //
+    // the wrapped functions
+    //
+public:
+    typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESACREATECONTEXTEXT) (GLenum, GLint, GLint, GLint, PrivateOSMesaContext);
+    typedef void (GLAPIENTRY * PFNOSMESADESTROYCONTEXT) (PrivateOSMesaContext);
+    typedef GLboolean (GLAPIENTRY * PFNOSMESAMAKECURRENT) (PrivateOSMesaContext, void *, GLenum, GLsizei, GLsizei);
+    typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESAGETCURRENTCONTEXT) (void);
+    typedef void (GLAPIENTRY * PFNOSMESAPIXELSTORE) (GLint, GLint);
+    typedef PRFuncPtr (GLAPIENTRY * PFNOSMESAGETPROCADDRESS) (const char*);
+
+    PFNOSMESACREATECONTEXTEXT fCreateContextExt;
+    PFNOSMESADESTROYCONTEXT fDestroyContext;
+    PFNOSMESAMAKECURRENT fMakeCurrent;
+    PFNOSMESAGETCURRENTCONTEXT fGetCurrentContext;
+    PFNOSMESAPIXELSTORE fPixelStore;
+    PFNOSMESAGETPROCADDRESS fGetProcAddress;
+};
+
+class GLES20Wrap
+    : public LibrarySymbolLoader
+{
+public:
+    enum NativeGLMode {
+        TRY_NATIVE_GL = 1 << 0,
+        TRY_SOFTWARE_GL = 1 << 1
+    };
+
+    GLES20Wrap() : ok(false) { }
+
+    bool Init(NativeGLMode mode);
+
+protected:
+
+    bool ok;
+
+    bool InitNative();
+    bool InitSoftware();
+
+    bool InitWithPrefix(const char *prefix, bool trygl );
+
+    //
+    // the wrapped functions
+    //
+public:
+    /* One would think that this would live in some nice perl-or-python-or-js script somewhere and would be autogenerated;
+     * one would be wrong.
+     */
+    typedef void (GLAPIENTRY * PFNGLACTIVETEXTUREPROC) (GLenum texture);
+    PFNGLACTIVETEXTUREPROC fActiveTexture;
+    typedef void (GLAPIENTRY * PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
+    PFNGLATTACHSHADERPROC fAttachShader;
+    typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);
+    PFNGLBINDATTRIBLOCATIONPROC fBindAttribLocation;
+    typedef void (GLAPIENTRY * PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
+    PFNGLBINDBUFFERPROC fBindBuffer;
+    typedef void (GLAPIENTRY * PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
+    PFNGLBINDTEXTUREPROC fBindTexture;
+    typedef void (GLAPIENTRY * PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+    PFNGLBLENDCOLORPROC fBlendColor;
+    typedef void (GLAPIENTRY * PFNGLBLENDEQUATIONPROC) (GLenum mode);
+    PFNGLBLENDEQUATIONPROC fBlendEquation;
+    typedef void (GLAPIENTRY * PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum, GLenum);
+    PFNGLBLENDEQUATIONSEPARATEPROC fBlendEquationSeparate;
+    typedef void (GLAPIENTRY * PFNGLBLENDFUNCPROC) (GLenum, GLenum);
+    PFNGLBLENDFUNCPROC fBlendFunc;
+    typedef void (GLAPIENTRY * PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+    PFNGLBLENDFUNCSEPARATEPROC fBlendFuncSeparate;
+    typedef void (GLAPIENTRY * PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
+    PFNGLBUFFERDATAPROC fBufferData;
+    typedef void (GLAPIENTRY * PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
+    PFNGLBUFFERSUBDATAPROC fBufferSubData;
+    typedef void (GLAPIENTRY * PFNGLCLEARPROC) (GLbitfield);
+    PFNGLCLEARPROC fClear;
+    typedef void (GLAPIENTRY * PFNGLCLEARCOLORPROC) (GLclampf, GLclampf, GLclampf, GLclampf);
+    PFNGLCLEARCOLORPROC fClearColor;
+    typedef void (GLAPIENTRY * PFNGLCLEARDEPTHPROC) (GLclampd);
+    PFNGLCLEARDEPTHPROC fClearDepth;
+    typedef void (GLAPIENTRY * PFNGLCLEARSTENCILPROC) (GLint);
+    PFNGLCLEARSTENCILPROC fClearStencil;
+    typedef void (GLAPIENTRY * PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+    PFNGLCOLORMASKPROC fColorMask;
+    typedef GLuint (GLAPIENTRY * PFNGLCREATEPROGRAMPROC) (void);
+    PFNGLCREATEPROGRAMPROC fCreateProgram;
+    typedef GLuint (GLAPIENTRY * PFNGLCREATESHADERPROC) (GLenum type);
+    PFNGLCREATESHADERPROC fCreateShader;
+    typedef void (GLAPIENTRY * PFNGLCULLFACEPROC) (GLenum mode);
+    PFNGLCULLFACEPROC fCullFace;
+    typedef void (GLAPIENTRY * PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint* buffers);
+    PFNGLDELETEBUFFERSPROC fDeleteBuffers;
+    typedef void (GLAPIENTRY * PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint* textures);
+    PFNGLDELETETEXTURESPROC fDeleteTextures;
+    typedef void (GLAPIENTRY * PFNGLDELETEPROGRAMPROC) (GLuint program);
+    PFNGLDELETEPROGRAMPROC fDeleteProgram;
+    typedef void (GLAPIENTRY * PFNGLDELETESHADERPROC) (GLuint shader);
+    PFNGLDELETESHADERPROC fDeleteShader;
+    typedef void (GLAPIENTRY * PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
+    PFNGLDETACHSHADERPROC fDetachShader;
+    typedef void (GLAPIENTRY * PFNGLDEPTHFUNCPROC) (GLenum);
+    PFNGLDEPTHFUNCPROC fDepthFunc;
+    typedef void (GLAPIENTRY * PFNGLDEPTHMASKPROC) (GLboolean);
+    PFNGLDEPTHMASKPROC fDepthMask;
+    typedef void (GLAPIENTRY * PFNGLDEPTHRANGEPROC) (GLclampd, GLclampd);
+    PFNGLDEPTHRANGEPROC fDepthRange;
+    typedef void (GLAPIENTRY * PFNGLDISABLEPROC) (GLenum);
+    PFNGLDISABLEPROC fDisable;
+    typedef void (GLAPIENTRY * PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint);
+    PFNGLDISABLEVERTEXATTRIBARRAYPROC fDisableVertexAttribArray;
+    typedef void (GLAPIENTRY * PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
+    PFNGLDRAWARRAYSPROC fDrawArrays;
+    typedef void (GLAPIENTRY * PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
+    PFNGLDRAWELEMENTSPROC fDrawElements;
+    typedef void (GLAPIENTRY * PFNGLENABLEPROC) (GLenum);
+    PFNGLENABLEPROC fEnable;
+    typedef void (GLAPIENTRY * PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint);
+    PFNGLENABLEVERTEXATTRIBARRAYPROC fEnableVertexAttribArray;
+    typedef void (GLAPIENTRY * PFNGLFINISHPROC) (void);
+    PFNGLFINISHPROC fFinish;
+    typedef void (GLAPIENTRY * PFNGLFLUSHPROC) (void);
+    PFNGLFLUSHPROC fFlush;
+    typedef void (GLAPIENTRY * PFNGLFRONTFACEPROC) (GLenum);
+    PFNGLFRONTFACEPROC fFrontFace;
+    typedef void (GLAPIENTRY * PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+    PFNGLGETACTIVEATTRIBPROC fGetActiveAttrib;
+    typedef void (GLAPIENTRY * PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+    PFNGLGETACTIVEUNIFORMPROC fGetActiveUniform;
+    typedef void (GLAPIENTRY * PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders);
+    PFNGLGETATTACHEDSHADERSPROC fGetAttachedShaders;
+    typedef GLint (GLAPIENTRY * PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar* name);
+    PFNGLGETATTRIBLOCATIONPROC fGetAttribLocation;
+    typedef void (GLAPIENTRY * PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
+    PFNGLGETINTEGERVPROC fGetIntegerv;
+    typedef void (GLAPIENTRY * PFNGLGETDOUBLEVPROC) (GLenum pname, GLdouble *params);
+    PFNGLGETDOUBLEVPROC fGetDoublev;
+    typedef void (GLAPIENTRY * PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params);
+    PFNGLGETFLOATVPROC fGetFloatv;
+    typedef void (GLAPIENTRY * PFNGLGETBOOLEANBPROC) (GLenum pname, GLboolean *params);
+    PFNGLGETBOOLEANBPROC fGetBooleanv;
+    typedef void (GLAPIENTRY * PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint* params);
+    PFNGLGETBUFFERPARAMETERIVPROC fGetBufferParameteriv;
+    typedef void (GLAPIENTRY * PFNGLGENBUFFERSPROC) (GLsizei n, GLuint* buffers);
+    PFNGLGENBUFFERSPROC fGenBuffers;
+    typedef void (GLAPIENTRY * PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
+    PFNGLGENTEXTURESPROC fGenTextures;
+    typedef void (GLAPIENTRY * PFNGLGENERATEMIPMAPPROC) (GLenum target);
+    PFNGLGENERATEMIPMAPPROC fGenerateMipmap;
+    typedef GLenum (GLAPIENTRY * PFNGLGETERRORPROC) (void);
+    PFNGLGETERRORPROC fGetError;
+    typedef void (GLAPIENTRY * PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint* param);
+    PFNGLGETPROGRAMIVPROC fGetProgramiv;
+    typedef void (GLAPIENTRY * PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
+    PFNGLGETPROGRAMINFOLOGPROC fGetProgramInfoLog;
+    typedef void (GLAPIENTRY * PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
+    PFNGLTEXPARAMETERIPROC fTexParameteri;
+    typedef void (GLAPIENTRY * PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
+    PFNGLTEXPARAMETERFPROC fTexParameterf;
+    typedef void (GLAPIENTRY * PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+    PFNGLTEXPARAMETERIVPROC fGetTexParameteriv;
+    typedef void (GLAPIENTRY * PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat* params);
+    PFNGLGETUNIFORMFVPROC fGetUniformfv;
+    typedef void (GLAPIENTRY * PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint* params);
+    PFNGLGETUNIFORMIVPROC fGetUniformiv;
+    typedef GLint (GLAPIENTRY * PFNGLGETUNIFORMLOCATIONPROC) (GLint programObj, const GLchar* name);
+    PFNGLGETUNIFORMLOCATIONPROC fGetUniformLocation;
+    typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBDVPROC) (GLuint, GLenum, GLdouble*);
+    PFNGLGETVERTEXATTRIBDVPROC fGetVertexAttribdv;
+    typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBFVPROC) (GLuint, GLenum, GLfloat*);
+    PFNGLGETVERTEXATTRIBFVPROC fGetVertexAttribfv;
+    typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBIVPROC) (GLuint, GLenum, GLint*);
+    PFNGLGETVERTEXATTRIBIVPROC fGetVertexAttribiv;
+    typedef void (GLAPIENTRY * PFNGLHINTPROC) (GLenum target, GLenum mode);
+    PFNGLHINTPROC fHint;
+    typedef GLboolean (GLAPIENTRY * PFNGLISBUFFERPROC) (GLuint buffer);
+    PFNGLISBUFFERPROC fIsBuffer;
+    typedef GLboolean (GLAPIENTRY * PFNGLISENABLEDPROC) (GLenum cap);
+    PFNGLISENABLEDPROC fIsEnabled;
+    typedef GLboolean (GLAPIENTRY * PFNGLISPROGRAMPROC) (GLuint program);
+    PFNGLISPROGRAMPROC fIsProgram;
+    typedef GLboolean (GLAPIENTRY * PFNGLISSHADERPROC) (GLuint shader);
+    PFNGLISSHADERPROC fIsShader;
+    typedef GLboolean (GLAPIENTRY * PFNGLISTEXTUREPROC) (GLuint texture);
+    PFNGLISTEXTUREPROC fIsTexture;
+    typedef void (GLAPIENTRY * PFNGLLINEWIDTHPROC) (GLfloat width);
+    PFNGLLINEWIDTHPROC fLineWidth;
+    typedef void (GLAPIENTRY * PFNGLLINKPROGRAMPROC) (GLuint program);
+    PFNGLLINKPROGRAMPROC fLinkProgram;
+    typedef void (GLAPIENTRY * PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
+    PFNGLPIXELSTOREIPROC fPixelStorei;
+    typedef void (GLAPIENTRY * PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat bias);
+    PFNGLPOLYGONOFFSETPROC fPolygonOffset;
+    typedef void (GLAPIENTRY * PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
+    PFNGLREADPIXELSPROC fReadPixels;
+    typedef void (GLAPIENTRY * PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert);
+    PFNGLSAMPLECOVERAGEPROC fSampleCoverage;
+    typedef void (GLAPIENTRY * PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
+    PFNGLSCISSORPROC fScissor;
+    typedef void (GLAPIENTRY * PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask);
+    PFNGLSTENCILFUNCPROC fStencilFunc;
+    typedef void (GLAPIENTRY * PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+    PFNGLSTENCILFUNCSEPARATEPROC fStencilFuncSeparate;
+    typedef void (GLAPIENTRY * PFNGLSTENCILMASKPROC) (GLuint mask);
+    PFNGLSTENCILMASKPROC fStencilMask;
+    typedef void (GLAPIENTRY * PFNGLSTENCILMASKSEPARATEPROC) (GLenum, GLuint);
+    PFNGLSTENCILMASKSEPARATEPROC fStencilMaskSeparate;
+    typedef void (GLAPIENTRY * PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
+    PFNGLSTENCILOPPROC fStencilOp;
+    typedef void (GLAPIENTRY * PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+    PFNGLSTENCILOPSEPARATEPROC fStencilOpSeparate;
+    typedef void (GLAPIENTRY * PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+    PFNGLTEXIMAGE2DPROC fTexImage2D;
+    typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels);
+    PFNGLTEXSUBIMAGE2DPROC fTexSubImage2D;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
+    PFNGLUNIFORM1FPROC fUniform1f;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+    PFNGLUNIFORM1FVPROC fUniform1fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
+    PFNGLUNIFORM1IPROC fUniform1i;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint* value);
+    PFNGLUNIFORM1IVPROC fUniform1iv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
+    PFNGLUNIFORM2FPROC fUniform2f;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+    PFNGLUNIFORM2FVPROC fUniform2fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
+    PFNGLUNIFORM2IPROC fUniform2i;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint* value);
+    PFNGLUNIFORM2IVPROC fUniform2iv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+    PFNGLUNIFORM3FPROC fUniform3f;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+    PFNGLUNIFORM3FVPROC fUniform3fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+    PFNGLUNIFORM3IPROC fUniform3i;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint* value);
+    PFNGLUNIFORM3IVPROC fUniform3iv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+    PFNGLUNIFORM4FPROC fUniform4f;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+    PFNGLUNIFORM4FVPROC fUniform4fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+    PFNGLUNIFORM4IPROC fUniform4i;
+    typedef void (GLAPIENTRY * PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint* value);
+    PFNGLUNIFORM4IVPROC fUniform4iv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+    PFNGLUNIFORMMATRIX2FVPROC fUniformMatrix2fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+    PFNGLUNIFORMMATRIX3FVPROC fUniformMatrix3fv;
+    typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+    PFNGLUNIFORMMATRIX4FVPROC fUniformMatrix4fv;
+    typedef void (GLAPIENTRY * PFNGLUSEPROGRAMPROC) (GLuint program);
+    PFNGLUSEPROGRAMPROC fUseProgram;
+    typedef void (GLAPIENTRY * PFNGLVALIDATEPROGRAMPROC) (GLuint program);
+    PFNGLVALIDATEPROGRAMPROC fValidateProgram;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
+    PFNGLVERTEXATTRIBPOINTERPROC fVertexAttribPointer;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
+    PFNGLVERTEXATTRIB1FPROC fVertexAttrib1f;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
+    PFNGLVERTEXATTRIB2FPROC fVertexAttrib2f;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+    PFNGLVERTEXATTRIB3FPROC fVertexAttrib3f;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+    PFNGLVERTEXATTRIB4FPROC fVertexAttrib4f;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat* v);
+    PFNGLVERTEXATTRIB1FVPROC fVertexAttrib1fv;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat* v);
+    PFNGLVERTEXATTRIB2FVPROC fVertexAttrib2fv;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat* v);
+    PFNGLVERTEXATTRIB3FVPROC fVertexAttrib3fv;
+    typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat* v);
+    PFNGLVERTEXATTRIB4FVPROC fVertexAttrib4fv;
+    typedef void (GLAPIENTRY * PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
+    PFNGLVIEWPORTPROC fViewport;
+    typedef void (GLAPIENTRY * PFNGLCOMPILESHADERPROC) (GLuint shader);
+    PFNGLCOMPILESHADERPROC fCompileShader;
+    typedef void (GLAPIENTRY * PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+    PFNGLCOPYTEXIMAGE2DPROC fCopyTexImage2D;
+    typedef void (GLAPIENTRY * PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+    PFNGLCOPYTEXSUBIMAGE2DPROC fCopyTexSubImage2D;
+    typedef void (GLAPIENTRY * PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint* param);
+    PFNGLGETSHADERIVPROC fGetShaderiv;
+    typedef void (GLAPIENTRY * PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
+    PFNGLGETSHADERINFOLOGPROC fGetShaderInfoLog;
+    typedef void (GLAPIENTRY * PFNGLGETSHADERSOURCEPROC) (GLint obj, GLsizei maxLength, GLsizei* length, GLchar* source);
+    PFNGLGETSHADERSOURCEPROC fGetShaderSource;
+    typedef void (GLAPIENTRY * PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar** strings, const GLint* lengths);
+    PFNGLSHADERSOURCEPROC fShaderSource;
+
+    typedef void (GLAPIENTRY * PFNGLBINDFRAMEBUFFER) (GLenum target, GLuint framebuffer);
+    PFNGLBINDFRAMEBUFFER fBindFramebuffer;
+    typedef void (GLAPIENTRY * PFNGLBINDRENDERBUFFER) (GLenum target, GLuint renderbuffer);
+    PFNGLBINDRENDERBUFFER fBindRenderbuffer;
+    typedef GLenum (GLAPIENTRY * PFNGLCHECKFRAMEBUFFERSTATUS) (GLenum target);
+    PFNGLCHECKFRAMEBUFFERSTATUS fCheckFramebufferStatus;
+    typedef void (GLAPIENTRY * PFNGLDELETEFRAMEBUFFERS) (GLsizei n, const GLuint* ids);
+    PFNGLDELETEFRAMEBUFFERS fDeleteFramebuffers;
+    typedef void (GLAPIENTRY * PFNGLDELETERENDERBUFFERS) (GLsizei n, const GLuint* ids);
+    PFNGLDELETERENDERBUFFERS fDeleteRenderbuffers;
+    typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERRENDERBUFFER) (GLenum target, GLenum attachmentPoint, GLenum renderbufferTarget, GLuint renderbuffer);
+    PFNGLFRAMEBUFFERRENDERBUFFER fFramebufferRenderbuffer;
+    typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE2D) (GLenum target, GLenum attachmentPoint, GLenum textureTarget, GLuint texture, GLint level);
+    PFNGLFRAMEBUFFERTEXTURE2D fFramebufferTexture2D;
+    typedef void (GLAPIENTRY * PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIV) (GLenum target, GLenum attachment, GLenum pname, GLint* value);
+    PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIV fGetFramebufferAttachmentParameteriv;
+    typedef void (GLAPIENTRY * PFNGLGETRENDERBUFFERPARAMETERIV) (GLenum target, GLenum pname, GLint* value);
+    PFNGLGETRENDERBUFFERPARAMETERIV fGetRenderbufferParameteriv;
+    typedef void (GLAPIENTRY * PFNGLGENFRAMEBUFFERS) (GLsizei n, GLuint* ids);
+    PFNGLGENFRAMEBUFFERS fGenFramebuffers;
+    typedef void (GLAPIENTRY * PFNGLGENRENDERBUFFERS) (GLsizei n, GLuint* ids);
+    PFNGLGENRENDERBUFFERS fGenRenderbuffers;
+    typedef GLboolean (GLAPIENTRY * PFNGLISFRAMEBUFFER) (GLuint framebuffer);
+    PFNGLISFRAMEBUFFER fIsFramebuffer;
+    typedef GLboolean (GLAPIENTRY * PFNGLISRENDERBUFFER) (GLuint renderbuffer);
+    PFNGLISRENDERBUFFER fIsRenderbuffer;
+    typedef void (GLAPIENTRY * PFNGLRENDERBUFFERSTORAGE) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height);
+    PFNGLRENDERBUFFERSTORAGE fRenderbufferStorage;
+
+};
+
+
+#endif
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/localgl.h
@@ -0,0 +1,3051 @@
+
+#if !defined(LOCALGL_H_) && !defined(__gl_h_)
+
+#define LOCALGL_H_
+#define __gl_h_
+
+#if defined(__APPLE__)
+typedef unsigned long GLenum;
+typedef unsigned long GLbitfield;
+typedef unsigned long GLuint;
+typedef long GLint;
+typedef long GLsizei;
+#else
+typedef unsigned int GLenum;
+typedef unsigned int GLbitfield;
+typedef unsigned int GLuint;
+typedef int GLint;
+typedef int GLsizei;
+#endif
+typedef unsigned char GLboolean;
+typedef signed char GLbyte;
+typedef short GLshort;
+typedef unsigned char GLubyte;
+typedef unsigned short GLushort;
+typedef float GLfloat;
+typedef float GLclampf;
+typedef double GLdouble;
+typedef double GLclampd;
+typedef void GLvoid;
+
+typedef char GLchar;
+typedef ptrdiff_t GLsizeiptr;
+typedef ptrdiff_t GLintptr;
+
+#ifndef GLAPIENTRY
+# ifdef WIN32
+#  define GLAPIENTRY APIENTRY
+#  define GLAPI
+# else
+#  define GLAPIENTRY
+#  define GLAPI
+# endif
+#endif
+
+#define GL_VERSION_1_1 1
+#define GL_ACCUM 0x0100
+#define GL_LOAD 0x0101
+#define GL_RETURN 0x0102
+#define GL_MULT 0x0103
+#define GL_ADD 0x0104
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+#define GL_CURRENT_BIT 0x00000001
+#define GL_POINT_BIT 0x00000002
+#define GL_LINE_BIT 0x00000004
+#define GL_POLYGON_BIT 0x00000008
+#define GL_POLYGON_STIPPLE_BIT 0x00000010
+#define GL_PIXEL_MODE_BIT 0x00000020
+#define GL_LIGHTING_BIT 0x00000040
+#define GL_FOG_BIT 0x00000080
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_ACCUM_BUFFER_BIT 0x00000200
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_VIEWPORT_BIT 0x00000800
+#define GL_TRANSFORM_BIT 0x00001000
+#define GL_ENABLE_BIT 0x00002000
+#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_HINT_BIT 0x00008000
+#define GL_EVAL_BIT 0x00010000
+#define GL_LIST_BIT 0x00020000
+#define GL_TEXTURE_BIT 0x00040000
+#define GL_SCISSOR_BIT 0x00080000
+#define GL_ALL_ATTRIB_BITS 0x000fffff
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+#define GL_QUADS 0x0007
+#define GL_QUAD_STRIP 0x0008
+#define GL_POLYGON 0x0009
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+#define GL_TRUE 1
+#define GL_FALSE 0
+#define GL_CLIP_PLANE0 0x3000
+#define GL_CLIP_PLANE1 0x3001
+#define GL_CLIP_PLANE2 0x3002
+#define GL_CLIP_PLANE3 0x3003
+#define GL_CLIP_PLANE4 0x3004
+#define GL_CLIP_PLANE5 0x3005
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_2_BYTES 0x1407
+#define GL_3_BYTES 0x1408
+#define GL_4_BYTES 0x1409
+#define GL_DOUBLE 0x140A
+#define GL_NONE 0
+#define GL_FRONT_LEFT 0x0400
+#define GL_FRONT_RIGHT 0x0401
+#define GL_BACK_LEFT 0x0402
+#define GL_BACK_RIGHT 0x0403
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_LEFT 0x0406
+#define GL_RIGHT 0x0407
+#define GL_FRONT_AND_BACK 0x0408
+#define GL_AUX0 0x0409
+#define GL_AUX1 0x040A
+#define GL_AUX2 0x040B
+#define GL_AUX3 0x040C
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_STACK_OVERFLOW 0x0503
+#define GL_STACK_UNDERFLOW 0x0504
+#define GL_OUT_OF_MEMORY 0x0505
+#define GL_2D 0x0600
+#define GL_3D 0x0601
+#define GL_3D_COLOR 0x0602
+#define GL_3D_COLOR_TEXTURE 0x0603
+#define GL_4D_COLOR_TEXTURE 0x0604
+#define GL_PASS_THROUGH_TOKEN 0x0700
+#define GL_POINT_TOKEN 0x0701
+#define GL_LINE_TOKEN 0x0702
+#define GL_POLYGON_TOKEN 0x0703
+#define GL_BITMAP_TOKEN 0x0704
+#define GL_DRAW_PIXEL_TOKEN 0x0705
+#define GL_COPY_PIXEL_TOKEN 0x0706
+#define GL_LINE_RESET_TOKEN 0x0707
+#define GL_EXP 0x0800
+#define GL_EXP2 0x0801
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+#define GL_COEFF 0x0A00
+#define GL_ORDER 0x0A01
+#define GL_DOMAIN 0x0A02
+#define GL_CURRENT_COLOR 0x0B00
+#define GL_CURRENT_INDEX 0x0B01
+#define GL_CURRENT_NORMAL 0x0B02
+#define GL_CURRENT_TEXTURE_COORDS 0x0B03
+#define GL_CURRENT_RASTER_COLOR 0x0B04
+#define GL_CURRENT_RASTER_INDEX 0x0B05
+#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06
+#define GL_CURRENT_RASTER_POSITION 0x0B07
+#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08
+#define GL_CURRENT_RASTER_DISTANCE 0x0B09
+#define GL_POINT_SMOOTH 0x0B10
+#define GL_POINT_SIZE 0x0B11
+#define GL_POINT_SIZE_RANGE 0x0B12
+#define GL_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_LINE_SMOOTH 0x0B20
+#define GL_LINE_WIDTH 0x0B21
+#define GL_LINE_WIDTH_RANGE 0x0B22
+#define GL_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_LINE_STIPPLE 0x0B24
+#define GL_LINE_STIPPLE_PATTERN 0x0B25
+#define GL_LINE_STIPPLE_REPEAT 0x0B26
+#define GL_LIST_MODE 0x0B30
+#define GL_MAX_LIST_NESTING 0x0B31
+#define GL_LIST_BASE 0x0B32
+#define GL_LIST_INDEX 0x0B33
+#define GL_POLYGON_MODE 0x0B40
+#define GL_POLYGON_SMOOTH 0x0B41
+#define GL_POLYGON_STIPPLE 0x0B42
+#define GL_EDGE_FLAG 0x0B43
+#define GL_CULL_FACE 0x0B44
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_LIGHTING 0x0B50
+#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
+#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
+#define GL_LIGHT_MODEL_AMBIENT 0x0B53
+#define GL_SHADE_MODEL 0x0B54
+#define GL_COLOR_MATERIAL_FACE 0x0B55
+#define GL_COLOR_MATERIAL_PARAMETER 0x0B56
+#define GL_COLOR_MATERIAL 0x0B57
+#define GL_FOG 0x0B60
+#define GL_FOG_INDEX 0x0B61
+#define GL_FOG_DENSITY 0x0B62
+#define GL_FOG_START 0x0B63
+#define GL_FOG_END 0x0B64
+#define GL_FOG_MODE 0x0B65
+#define GL_FOG_COLOR 0x0B66
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_TEST 0x0B71
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_ACCUM_CLEAR_VALUE 0x0B80
+#define GL_STENCIL_TEST 0x0B90
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_MATRIX_MODE 0x0BA0
+#define GL_NORMALIZE 0x0BA1
+#define GL_VIEWPORT 0x0BA2
+#define GL_MODELVIEW_STACK_DEPTH 0x0BA3
+#define GL_PROJECTION_STACK_DEPTH 0x0BA4
+#define GL_TEXTURE_STACK_DEPTH 0x0BA5
+#define GL_MODELVIEW_MATRIX 0x0BA6
+#define GL_PROJECTION_MATRIX 0x0BA7
+#define GL_TEXTURE_MATRIX 0x0BA8
+#define GL_ATTRIB_STACK_DEPTH 0x0BB0
+#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1
+#define GL_ALPHA_TEST 0x0BC0
+#define GL_ALPHA_TEST_FUNC 0x0BC1
+#define GL_ALPHA_TEST_REF 0x0BC2
+#define GL_DITHER 0x0BD0
+#define GL_BLEND_DST 0x0BE0
+#define GL_BLEND_SRC 0x0BE1
+#define GL_BLEND 0x0BE2
+#define GL_LOGIC_OP_MODE 0x0BF0
+#define GL_INDEX_LOGIC_OP 0x0BF1
+#define GL_COLOR_LOGIC_OP 0x0BF2
+#define GL_AUX_BUFFERS 0x0C00
+#define GL_DRAW_BUFFER 0x0C01
+#define GL_READ_BUFFER 0x0C02
+#define GL_SCISSOR_BOX 0x0C10
+#define GL_SCISSOR_TEST 0x0C11
+#define GL_INDEX_CLEAR_VALUE 0x0C20
+#define GL_INDEX_WRITEMASK 0x0C21
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_INDEX_MODE 0x0C30
+#define GL_RGBA_MODE 0x0C31
+#define GL_DOUBLEBUFFER 0x0C32
+#define GL_STEREO 0x0C33
+#define GL_RENDER_MODE 0x0C40
+#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
+#define GL_POINT_SMOOTH_HINT 0x0C51
+#define GL_LINE_SMOOTH_HINT 0x0C52
+#define GL_POLYGON_SMOOTH_HINT 0x0C53
+#define GL_FOG_HINT 0x0C54
+#define GL_TEXTURE_GEN_S 0x0C60
+#define GL_TEXTURE_GEN_T 0x0C61
+#define GL_TEXTURE_GEN_R 0x0C62
+#define GL_TEXTURE_GEN_Q 0x0C63
+#define GL_PIXEL_MAP_I_TO_I 0x0C70
+#define GL_PIXEL_MAP_S_TO_S 0x0C71
+#define GL_PIXEL_MAP_I_TO_R 0x0C72
+#define GL_PIXEL_MAP_I_TO_G 0x0C73
+#define GL_PIXEL_MAP_I_TO_B 0x0C74
+#define GL_PIXEL_MAP_I_TO_A 0x0C75
+#define GL_PIXEL_MAP_R_TO_R 0x0C76
+#define GL_PIXEL_MAP_G_TO_G 0x0C77
+#define GL_PIXEL_MAP_B_TO_B 0x0C78
+#define GL_PIXEL_MAP_A_TO_A 0x0C79
+#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0
+#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1
+#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2
+#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3
+#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4
+#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5
+#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6
+#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7
+#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8
+#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9
+#define GL_UNPACK_SWAP_BYTES 0x0CF0
+#define GL_UNPACK_LSB_FIRST 0x0CF1
+#define GL_UNPACK_ROW_LENGTH 0x0CF2
+#define GL_UNPACK_SKIP_ROWS 0x0CF3
+#define GL_UNPACK_SKIP_PIXELS 0x0CF4
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_PACK_SWAP_BYTES 0x0D00
+#define GL_PACK_LSB_FIRST 0x0D01
+#define GL_PACK_ROW_LENGTH 0x0D02
+#define GL_PACK_SKIP_ROWS 0x0D03
+#define GL_PACK_SKIP_PIXELS 0x0D04
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_MAP_COLOR 0x0D10
+#define GL_MAP_STENCIL 0x0D11
+#define GL_INDEX_SHIFT 0x0D12
+#define GL_INDEX_OFFSET 0x0D13
+#define GL_RED_SCALE 0x0D14
+#define GL_RED_BIAS 0x0D15
+#define GL_ZOOM_X 0x0D16
+#define GL_ZOOM_Y 0x0D17
+#define GL_GREEN_SCALE 0x0D18
+#define GL_GREEN_BIAS 0x0D19
+#define GL_BLUE_SCALE 0x0D1A
+#define GL_BLUE_BIAS 0x0D1B
+#define GL_ALPHA_SCALE 0x0D1C
+#define GL_ALPHA_BIAS 0x0D1D
+#define GL_DEPTH_SCALE 0x0D1E
+#define GL_DEPTH_BIAS 0x0D1F
+#define GL_MAX_EVAL_ORDER 0x0D30
+#define GL_MAX_LIGHTS 0x0D31
+#define GL_MAX_CLIP_PLANES 0x0D32
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_PIXEL_MAP_TABLE 0x0D34
+#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35
+#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
+#define GL_MAX_NAME_STACK_DEPTH 0x0D37
+#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
+#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_INDEX_BITS 0x0D51
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_ALPHA_BITS 0x0D55
+#define GL_DEPTH_BITS 0x0D56
+#define GL_STENCIL_BITS 0x0D57
+#define GL_ACCUM_RED_BITS 0x0D58
+#define GL_ACCUM_GREEN_BITS 0x0D59
+#define GL_ACCUM_BLUE_BITS 0x0D5A
+#define GL_ACCUM_ALPHA_BITS 0x0D5B
+#define GL_NAME_STACK_DEPTH 0x0D70
+#define GL_AUTO_NORMAL 0x0D80
+#define GL_MAP1_COLOR_4 0x0D90
+#define GL_MAP1_INDEX 0x0D91
+#define GL_MAP1_NORMAL 0x0D92
+#define GL_MAP1_TEXTURE_COORD_1 0x0D93
+#define GL_MAP1_TEXTURE_COORD_2 0x0D94
+#define GL_MAP1_TEXTURE_COORD_3 0x0D95
+#define GL_MAP1_TEXTURE_COORD_4 0x0D96
+#define GL_MAP1_VERTEX_3 0x0D97
+#define GL_MAP1_VERTEX_4 0x0D98
+#define GL_MAP2_COLOR_4 0x0DB0
+#define GL_MAP2_INDEX 0x0DB1
+#define GL_MAP2_NORMAL 0x0DB2
+#define GL_MAP2_TEXTURE_COORD_1 0x0DB3
+#define GL_MAP2_TEXTURE_COORD_2 0x0DB4
+#define GL_MAP2_TEXTURE_COORD_3 0x0DB5
+#define GL_MAP2_TEXTURE_COORD_4 0x0DB6
+#define GL_MAP2_VERTEX_3 0x0DB7
+#define GL_MAP2_VERTEX_4 0x0DB8
+#define GL_MAP1_GRID_DOMAIN 0x0DD0
+#define GL_MAP1_GRID_SEGMENTS 0x0DD1
+#define GL_MAP2_GRID_DOMAIN 0x0DD2
+#define GL_MAP2_GRID_SEGMENTS 0x0DD3
+#define GL_TEXTURE_1D 0x0DE0
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0
+#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1
+#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2
+#define GL_SELECTION_BUFFER_POINTER 0x0DF3
+#define GL_SELECTION_BUFFER_SIZE 0x0DF4
+#define GL_TEXTURE_WIDTH 0x1000
+#define GL_TEXTURE_HEIGHT 0x1001
+#define GL_TEXTURE_INTERNAL_FORMAT 0x1003
+#define GL_TEXTURE_BORDER_COLOR 0x1004
+#define GL_TEXTURE_BORDER 0x1005
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+#define GL_LIGHT0 0x4000
+#define GL_LIGHT1 0x4001
+#define GL_LIGHT2 0x4002
+#define GL_LIGHT3 0x4003
+#define GL_LIGHT4 0x4004
+#define GL_LIGHT5 0x4005
+#define GL_LIGHT6 0x4006
+#define GL_LIGHT7 0x4007
+#define GL_AMBIENT 0x1200
+#define GL_DIFFUSE 0x1201
+#define GL_SPECULAR 0x1202
+#define GL_POSITION 0x1203
+#define GL_SPOT_DIRECTION 0x1204
+#define GL_SPOT_EXPONENT 0x1205
+#define GL_SPOT_CUTOFF 0x1206
+#define GL_CONSTANT_ATTENUATION 0x1207
+#define GL_LINEAR_ATTENUATION 0x1208
+#define GL_QUADRATIC_ATTENUATION 0x1209
+#define GL_COMPILE 0x1300
+#define GL_COMPILE_AND_EXECUTE 0x1301
+#define GL_CLEAR 0x1500
+#define GL_AND 0x1501
+#define GL_AND_REVERSE 0x1502
+#define GL_COPY 0x1503
+#define GL_AND_INVERTED 0x1504
+#define GL_NOOP 0x1505
+#define GL_XOR 0x1506
+#define GL_OR 0x1507
+#define GL_NOR 0x1508
+#define GL_EQUIV 0x1509
+#define GL_INVERT 0x150A
+#define GL_OR_REVERSE 0x150B
+#define GL_COPY_INVERTED 0x150C
+#define GL_OR_INVERTED 0x150D
+#define GL_NAND 0x150E
+#define GL_SET 0x150F
+#define GL_EMISSION 0x1600
+#define GL_SHININESS 0x1601
+#define GL_AMBIENT_AND_DIFFUSE 0x1602
+#define GL_COLOR_INDEXES 0x1603
+#define GL_MODELVIEW 0x1700
+#define GL_PROJECTION 0x1701
+#define GL_TEXTURE 0x1702
+#define GL_COLOR 0x1800
+#define GL_DEPTH 0x1801
+#define GL_STENCIL 0x1802
+#define GL_COLOR_INDEX 0x1900
+#define GL_STENCIL_INDEX 0x1901
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_RED 0x1903
+#define GL_GREEN 0x1904
+#define GL_BLUE 0x1905
+#define GL_ALPHA 0x1906
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+#define GL_BITMAP 0x1A00
+#define GL_POINT 0x1B00
+#define GL_LINE 0x1B01
+#define GL_FILL 0x1B02
+#define GL_RENDER 0x1C00
+#define GL_FEEDBACK 0x1C01
+#define GL_SELECT 0x1C02
+#define GL_FLAT 0x1D00
+#define GL_SMOOTH 0x1D01
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+#define GL_S 0x2000
+#define GL_T 0x2001
+#define GL_R 0x2002
+#define GL_Q 0x2003
+#define GL_MODULATE 0x2100
+#define GL_DECAL 0x2101
+#define GL_TEXTURE_ENV_MODE 0x2200
+#define GL_TEXTURE_ENV_COLOR 0x2201
+#define GL_TEXTURE_ENV 0x2300
+#define GL_EYE_LINEAR 0x2400
+#define GL_OBJECT_LINEAR 0x2401
+#define GL_SPHERE_MAP 0x2402
+#define GL_TEXTURE_GEN_MODE 0x2500
+#define GL_OBJECT_PLANE 0x2501
+#define GL_EYE_PLANE 0x2502
+#define GL_NEAREST 0x2600
+#define GL_LINEAR 0x2601
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+#define GL_CLAMP 0x2900
+#define GL_REPEAT 0x2901
+#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001
+#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002
+#define GL_CLIENT_ALL_ATTRIB_BITS 0xffffffff
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+#define GL_POLYGON_OFFSET_POINT 0x2A01
+#define GL_POLYGON_OFFSET_LINE 0x2A02
+#define GL_POLYGON_OFFSET_FILL 0x8037
+#define GL_ALPHA4 0x803B
+#define GL_ALPHA8 0x803C
+#define GL_ALPHA12 0x803D
+#define GL_ALPHA16 0x803E
+#define GL_LUMINANCE4 0x803F
+#define GL_LUMINANCE8 0x8040
+#define GL_LUMINANCE12 0x8041
+#define GL_LUMINANCE16 0x8042
+#define GL_LUMINANCE4_ALPHA4 0x8043
+#define GL_LUMINANCE6_ALPHA2 0x8044
+#define GL_LUMINANCE8_ALPHA8 0x8045
+#define GL_LUMINANCE12_ALPHA4 0x8046
+#define GL_LUMINANCE12_ALPHA12 0x8047
+#define GL_LUMINANCE16_ALPHA16 0x8048
+#define GL_INTENSITY 0x8049
+#define GL_INTENSITY4 0x804A
+#define GL_INTENSITY8 0x804B
+#define GL_INTENSITY12 0x804C
+#define GL_INTENSITY16 0x804D
+#define GL_R3_G3_B2 0x2A10
+#define GL_RGB4 0x804F
+#define GL_RGB5 0x8050
+#define GL_RGB8 0x8051
+#define GL_RGB10 0x8052
+#define GL_RGB12 0x8053
+#define GL_RGB16 0x8054
+#define GL_RGBA2 0x8055
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGBA8 0x8058
+#define GL_RGB10_A2 0x8059
+#define GL_RGBA12 0x805A
+#define GL_RGBA16 0x805B
+#define GL_TEXTURE_RED_SIZE 0x805C
+#define GL_TEXTURE_GREEN_SIZE 0x805D
+#define GL_TEXTURE_BLUE_SIZE 0x805E
+#define GL_TEXTURE_ALPHA_SIZE 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE 0x8061
+#define GL_PROXY_TEXTURE_1D 0x8063
+#define GL_PROXY_TEXTURE_2D 0x8064
+#define GL_TEXTURE_PRIORITY 0x8066
+#define GL_TEXTURE_RESIDENT 0x8067
+#define GL_TEXTURE_BINDING_1D 0x8068
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_VERTEX_ARRAY 0x8074
+#define GL_NORMAL_ARRAY 0x8075
+#define GL_COLOR_ARRAY 0x8076
+#define GL_INDEX_ARRAY 0x8077
+#define GL_TEXTURE_COORD_ARRAY 0x8078
+#define GL_EDGE_FLAG_ARRAY 0x8079
+#define GL_VERTEX_ARRAY_SIZE 0x807A
+#define GL_VERTEX_ARRAY_TYPE 0x807B
+#define GL_VERTEX_ARRAY_STRIDE 0x807C
+#define GL_NORMAL_ARRAY_TYPE 0x807E
+#define GL_NORMAL_ARRAY_STRIDE 0x807F
+#define GL_COLOR_ARRAY_SIZE 0x8081
+#define GL_COLOR_ARRAY_TYPE 0x8082
+#define GL_COLOR_ARRAY_STRIDE 0x8083
+#define GL_INDEX_ARRAY_TYPE 0x8085
+#define GL_INDEX_ARRAY_STRIDE 0x8086
+#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
+#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
+#define GL_VERTEX_ARRAY_POINTER 0x808E
+#define GL_NORMAL_ARRAY_POINTER 0x808F
+#define GL_COLOR_ARRAY_POINTER 0x8090
+#define GL_INDEX_ARRAY_POINTER 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093
+#define GL_V2F 0x2A20
+#define GL_V3F 0x2A21
+#define GL_C4UB_V2F 0x2A22
+#define GL_C4UB_V3F 0x2A23
+#define GL_C3F_V3F 0x2A24
+#define GL_N3F_V3F 0x2A25
+#define GL_C4F_N3F_V3F 0x2A26
+#define GL_T2F_V3F 0x2A27
+#define GL_T4F_V4F 0x2A28
+#define GL_T2F_C4UB_V3F 0x2A29
+#define GL_T2F_C3F_V3F 0x2A2A
+#define GL_T2F_N3F_V3F 0x2A2B
+#define GL_T2F_C4F_N3F_V3F 0x2A2C
+#define GL_T4F_C4F_N3F_V4F 0x2A2D
+#define GL_LOGIC_OP GL_INDEX_LOGIC_OP
+#define GL_TEXTURE_COMPONENTS GL_TEXTURE_INTERNAL_FORMAT
+#define GL_COLOR_INDEX1_EXT 0x80E2
+#define GL_COLOR_INDEX2_EXT 0x80E3
+#define GL_COLOR_INDEX4_EXT 0x80E4
+#define GL_COLOR_INDEX8_EXT 0x80E5
+#define GL_COLOR_INDEX12_EXT 0x80E6
+#define GL_COLOR_INDEX16_EXT 0x80E7
+#define GL_VERSION_1_2 1
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_TEXTURE_BINDING_3D 0x806A
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_VERSION_1_3 1
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_CLAMP_TO_BORDER 0x812D
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+#define GL_SUBTRACT 0x84E7
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+#define GL_MULTISAMPLE_BIT 0x20000000
+#define GL_VERSION_1_4 1
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_POINT_SIZE_MIN 0x8126
+#define GL_POINT_SIZE_MAX 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128
+#define GL_POINT_DISTANCE_ATTENUATION 0x8129
+#define GL_GENERATE_MIPMAP 0x8191
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT24 0x81A6
+#define GL_DEPTH_COMPONENT32 0x81A7
+#define GL_MIRRORED_REPEAT 0x8370
+#define GL_FOG_COORDINATE_SOURCE 0x8450
+#define GL_FOG_COORDINATE 0x8451
+#define GL_FRAGMENT_DEPTH 0x8452
+#define GL_CURRENT_FOG_COORDINATE 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456
+#define GL_FOG_COORDINATE_ARRAY 0x8457
+#define GL_COLOR_SUM 0x8458
+#define GL_CURRENT_SECONDARY_COLOR 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D
+#define GL_SECONDARY_COLOR_ARRAY 0x845E
+#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD
+#define GL_TEXTURE_FILTER_CONTROL 0x8500
+#define GL_TEXTURE_LOD_BIAS 0x8501
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#define GL_TEXTURE_DEPTH_SIZE 0x884A
+#define GL_DEPTH_TEXTURE_MODE 0x884B
+#define GL_TEXTURE_COMPARE_MODE 0x884C
+#define GL_TEXTURE_COMPARE_FUNC 0x884D
+#define GL_COMPARE_R_TO_TEXTURE 0x884E
+#define GL_VERSION_1_5 1
+#define GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE
+#define GL_FOG_COORD GL_FOG_COORDINATE
+#define GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY
+#define GL_SRC0_RGB GL_SOURCE0_RGB
+#define GL_FOG_COORD_ARRAY_POINTER GL_FOG_COORDINATE_ARRAY_POINTER
+#define GL_FOG_COORD_ARRAY_TYPE GL_FOG_COORDINATE_ARRAY_TYPE
+#define GL_SRC1_ALPHA GL_SOURCE1_ALPHA
+#define GL_CURRENT_FOG_COORD GL_CURRENT_FOG_COORDINATE
+#define GL_FOG_COORD_ARRAY_STRIDE GL_FOG_COORDINATE_ARRAY_STRIDE
+#define GL_SRC0_ALPHA GL_SOURCE0_ALPHA
+#define GL_SRC1_RGB GL_SOURCE1_RGB
+#define GL_FOG_COORD_ARRAY_BUFFER_BINDING GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING
+#define GL_SRC2_ALPHA GL_SOURCE2_ALPHA
+#define GL_SRC2_RGB GL_SOURCE2_RGB
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+#define GL_QUERY_COUNTER_BITS 0x8864
+#define GL_CURRENT_QUERY 0x8865
+#define GL_QUERY_RESULT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE 0x8867
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GL_READ_ONLY 0x88B8
+#define GL_WRITE_ONLY 0x88B9
+#define GL_READ_WRITE 0x88BA
+#define GL_BUFFER_ACCESS 0x88BB
+#define GL_BUFFER_MAPPED 0x88BC
+#define GL_BUFFER_MAP_POINTER 0x88BD
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STREAM_READ 0x88E1
+#define GL_STREAM_COPY 0x88E2
+#define GL_STATIC_DRAW 0x88E4
+#define GL_STATIC_READ 0x88E5
+#define GL_STATIC_COPY 0x88E6
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_DYNAMIC_READ 0x88E9
+#define GL_DYNAMIC_COPY 0x88EA
+#define GL_SAMPLES_PASSED 0x8914
+#define GL_VERSION_2_0 1
+#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_MAX_DRAW_BUFFERS 0x8824
+#define GL_DRAW_BUFFER0 0x8825
+#define GL_DRAW_BUFFER1 0x8826
+#define GL_DRAW_BUFFER2 0x8827
+#define GL_DRAW_BUFFER3 0x8828
+#define GL_DRAW_BUFFER4 0x8829
+#define GL_DRAW_BUFFER5 0x882A
+#define GL_DRAW_BUFFER6 0x882B
+#define GL_DRAW_BUFFER7 0x882C
+#define GL_DRAW_BUFFER8 0x882D
+#define GL_DRAW_BUFFER9 0x882E
+#define GL_DRAW_BUFFER10 0x882F
+#define GL_DRAW_BUFFER11 0x8830
+#define GL_DRAW_BUFFER12 0x8831
+#define GL_DRAW_BUFFER13 0x8832
+#define GL_DRAW_BUFFER14 0x8833
+#define GL_DRAW_BUFFER15 0x8834
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_POINT_SPRITE 0x8861
+#define GL_COORD_REPLACE 0x8862
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_MAX_TEXTURE_COORDS 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+#define GL_MAX_VARYING_FLOATS 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SAMPLER_1D_SHADOW 0x8B61
+#define GL_SAMPLER_2D_SHADOW 0x8B62
+#define GL_DELETE_STATUS 0x8B80
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0
+#define GL_LOWER_LEFT 0x8CA1
+#define GL_UPPER_LEFT 0x8CA2
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_3DFX_multisample 1
+#define GL_MULTISAMPLE_3DFX 0x86B2
+#define GL_SAMPLE_BUFFERS_3DFX 0x86B3
+#define GL_SAMPLES_3DFX 0x86B4
+#define GL_MULTISAMPLE_BIT_3DFX 0x20000000
+#define GL_3DFX_tbuffer 1
+#define GL_3DFX_texture_compression_FXT1 1
+#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0
+#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1
+#define GL_APPLE_client_storage 1
+#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
+#define GL_APPLE_element_array 1
+#define GL_ELEMENT_ARRAY_APPLE 0x8768
+#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8769
+#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x876A
+#define GL_APPLE_fence 1
+#define GL_DRAW_PIXELS_APPLE 0x8A0A
+#define GL_FENCE_APPLE 0x8A0B
+#define GL_APPLE_float_pixels 1
+#define GL_HALF_APPLE 0x140B
+#define GL_RGBA_FLOAT32_APPLE 0x8814
+#define GL_RGB_FLOAT32_APPLE 0x8815
+#define GL_ALPHA_FLOAT32_APPLE 0x8816
+#define GL_INTENSITY_FLOAT32_APPLE 0x8817
+#define GL_LUMINANCE_FLOAT32_APPLE 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819
+#define GL_RGBA_FLOAT16_APPLE 0x881A
+#define GL_RGB_FLOAT16_APPLE 0x881B
+#define GL_ALPHA_FLOAT16_APPLE 0x881C
+#define GL_INTENSITY_FLOAT16_APPLE 0x881D
+#define GL_LUMINANCE_FLOAT16_APPLE 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F
+#define GL_COLOR_FLOAT_APPLE 0x8A0F
+#define GL_APPLE_pixel_buffer 1
+#define GL_MIN_PBUFFER_VIEWPORT_DIMS_APPLE 0x8A10
+#define GL_APPLE_specular_vector 1
+#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0
+#define GL_APPLE_texture_range 1
+#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7
+#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8
+#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
+#define GL_STORAGE_PRIVATE_APPLE 0x85BD
+#define GL_STORAGE_CACHED_APPLE 0x85BE
+#define GL_STORAGE_SHARED_APPLE 0x85BF
+#define GL_APPLE_transform_hint 1
+#define GL_TRANSFORM_HINT_APPLE 0x85B1
+#define GL_APPLE_vertex_array_object 1
+#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5
+#define GL_APPLE_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E
+#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F
+#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_APPLE 0x8520
+#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521
+#define GL_STORAGE_CACHED_APPLE 0x85BE
+#define GL_STORAGE_SHARED_APPLE 0x85BF
+#define GL_APPLE_ycbcr_422 1
+#define GL_YCBCR_422_APPLE 0x85B9
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#define GL_ARB_color_buffer_float 1
+#define GL_RGBA_FLOAT_MODE_ARB 0x8820
+#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A
+#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B
+#define GL_CLAMP_READ_COLOR_ARB 0x891C
+#define GL_FIXED_ONLY_ARB 0x891D
+#define GL_ARB_depth_texture 1
+#define GL_DEPTH_COMPONENT16_ARB 0x81A5
+#define GL_DEPTH_COMPONENT24_ARB 0x81A6
+#define GL_DEPTH_COMPONENT32_ARB 0x81A7
+#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A
+#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
+#define GL_ARB_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ARB 0x8824
+#define GL_DRAW_BUFFER0_ARB 0x8825
+#define GL_DRAW_BUFFER1_ARB 0x8826
+#define GL_DRAW_BUFFER2_ARB 0x8827
+#define GL_DRAW_BUFFER3_ARB 0x8828
+#define GL_DRAW_BUFFER4_ARB 0x8829
+#define GL_DRAW_BUFFER5_ARB 0x882A
+#define GL_DRAW_BUFFER6_ARB 0x882B
+#define GL_DRAW_BUFFER7_ARB 0x882C
+#define GL_DRAW_BUFFER8_ARB 0x882D
+#define GL_DRAW_BUFFER9_ARB 0x882E
+#define GL_DRAW_BUFFER10_ARB 0x882F
+#define GL_DRAW_BUFFER11_ARB 0x8830
+#define GL_DRAW_BUFFER12_ARB 0x8831
+#define GL_DRAW_BUFFER13_ARB 0x8832
+#define GL_DRAW_BUFFER14_ARB 0x8833
+#define GL_DRAW_BUFFER15_ARB 0x8834
+#define GL_ARB_fragment_program 1
+#define GL_FRAGMENT_PROGRAM_ARB 0x8804
+#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805
+#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806
+#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807
+#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808
+#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809
+#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A
+#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B
+#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C
+#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D
+#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E
+#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F
+#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810
+#define GL_MAX_TEXTURE_COORDS_ARB 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
+#define GL_ARB_fragment_program_shadow 1
+#define GL_ARB_fragment_shader 1
+#define GL_FRAGMENT_SHADER_ARB 0x8B30
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B
+#define GL_ARB_half_float_pixel 1
+#define GL_HALF_FLOAT_ARB 0x140B
+#define GL_ARB_imaging 1
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_BLEND_COLOR 0x8005
+#define GL_FUNC_ADD 0x8006
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_BLEND_EQUATION 0x8009
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_CONVOLUTION_1D 0x8010
+#define GL_CONVOLUTION_2D 0x8011
+#define GL_SEPARABLE_2D 0x8012
+#define GL_CONVOLUTION_BORDER_MODE 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS 0x8015
+#define GL_REDUCE 0x8016
+#define GL_CONVOLUTION_FORMAT 0x8017
+#define GL_CONVOLUTION_WIDTH 0x8018
+#define GL_CONVOLUTION_HEIGHT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023
+#define GL_HISTOGRAM 0x8024
+#define GL_PROXY_HISTOGRAM 0x8025
+#define GL_HISTOGRAM_WIDTH 0x8026
+#define GL_HISTOGRAM_FORMAT 0x8027
+#define GL_HISTOGRAM_RED_SIZE 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C
+#define GL_HISTOGRAM_SINK 0x802D
+#define GL_MINMAX 0x802E
+#define GL_MINMAX_FORMAT 0x802F
+#define GL_MINMAX_SINK 0x8030
+#define GL_TABLE_TOO_LARGE 0x8031
+#define GL_COLOR_MATRIX 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB
+#define GL_COLOR_TABLE 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2
+#define GL_PROXY_COLOR_TABLE 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5
+#define GL_COLOR_TABLE_SCALE 0x80D6
+#define GL_COLOR_TABLE_BIAS 0x80D7
+#define GL_COLOR_TABLE_FORMAT 0x80D8
+#define GL_COLOR_TABLE_WIDTH 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF
+#define GL_IGNORE_BORDER 0x8150
+#define GL_CONSTANT_BORDER 0x8151
+#define GL_WRAP_BORDER 0x8152
+#define GL_REPLICATE_BORDER 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR 0x8154
+#define GL_ARB_matrix_palette 1
+#define GL_MATRIX_PALETTE_ARB 0x8840
+#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841
+#define GL_MAX_PALETTE_MATRICES_ARB 0x8842
+#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843
+#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844
+#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845
+#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846
+#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847
+#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848
+#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849
+#define GL_ARB_multisample 1
+#define GL_MULTISAMPLE_ARB 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F
+#define GL_SAMPLE_COVERAGE_ARB 0x80A0
+#define GL_SAMPLE_BUFFERS_ARB 0x80A8
+#define GL_SAMPLES_ARB 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB
+#define GL_MULTISAMPLE_BIT_ARB 0x20000000
+#define GL_ARB_multitexture 1
+#define GL_TEXTURE0_ARB 0x84C0
+#define GL_TEXTURE1_ARB 0x84C1
+#define GL_TEXTURE2_ARB 0x84C2
+#define GL_TEXTURE3_ARB 0x84C3
+#define GL_TEXTURE4_ARB 0x84C4
+#define GL_TEXTURE5_ARB 0x84C5
+#define GL_TEXTURE6_ARB 0x84C6
+#define GL_TEXTURE7_ARB 0x84C7
+#define GL_TEXTURE8_ARB 0x84C8
+#define GL_TEXTURE9_ARB 0x84C9
+#define GL_TEXTURE10_ARB 0x84CA
+#define GL_TEXTURE11_ARB 0x84CB
+#define GL_TEXTURE12_ARB 0x84CC
+#define GL_TEXTURE13_ARB 0x84CD
+#define GL_TEXTURE14_ARB 0x84CE
+#define GL_TEXTURE15_ARB 0x84CF
+#define GL_TEXTURE16_ARB 0x84D0
+#define GL_TEXTURE17_ARB 0x84D1
+#define GL_TEXTURE18_ARB 0x84D2
+#define GL_TEXTURE19_ARB 0x84D3
+#define GL_TEXTURE20_ARB 0x84D4
+#define GL_TEXTURE21_ARB 0x84D5
+#define GL_TEXTURE22_ARB 0x84D6
+#define GL_TEXTURE23_ARB 0x84D7
+#define GL_TEXTURE24_ARB 0x84D8
+#define GL_TEXTURE25_ARB 0x84D9
+#define GL_TEXTURE26_ARB 0x84DA
+#define GL_TEXTURE27_ARB 0x84DB
+#define GL_TEXTURE28_ARB 0x84DC
+#define GL_TEXTURE29_ARB 0x84DD
+#define GL_TEXTURE30_ARB 0x84DE
+#define GL_TEXTURE31_ARB 0x84DF
+#define GL_ACTIVE_TEXTURE_ARB 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
+#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
+#define GL_ARB_occlusion_query 1
+#define GL_QUERY_COUNTER_BITS_ARB 0x8864
+#define GL_CURRENT_QUERY_ARB 0x8865
+#define GL_QUERY_RESULT_ARB 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867
+#define GL_SAMPLES_PASSED_ARB 0x8914
+#define GL_ARB_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
+#define GL_ARB_point_parameters 1
+#define GL_POINT_SIZE_MIN_ARB 0x8126
+#define GL_POINT_SIZE_MAX_ARB 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128
+#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129
+#define GL_ARB_point_sprite 1
+#define GL_POINT_SPRITE_ARB 0x8861
+#define GL_COORD_REPLACE_ARB 0x8862
+#define GL_ARB_shader_objects 1
+#define GL_PROGRAM_OBJECT_ARB 0x8B40
+#define GL_SHADER_OBJECT_ARB 0x8B48
+#define GL_OBJECT_TYPE_ARB 0x8B4E
+#define GL_OBJECT_SUBTYPE_ARB 0x8B4F
+#define GL_FLOAT_VEC2_ARB 0x8B50
+#define GL_FLOAT_VEC3_ARB 0x8B51
+#define GL_FLOAT_VEC4_ARB 0x8B52
+#define GL_INT_VEC2_ARB 0x8B53
+#define GL_INT_VEC3_ARB 0x8B54
+#define GL_INT_VEC4_ARB 0x8B55
+#define GL_BOOL_ARB 0x8B56
+#define GL_BOOL_VEC2_ARB 0x8B57
+#define GL_BOOL_VEC3_ARB 0x8B58
+#define GL_BOOL_VEC4_ARB 0x8B59
+#define GL_FLOAT_MAT2_ARB 0x8B5A
+#define GL_FLOAT_MAT3_ARB 0x8B5B
+#define GL_FLOAT_MAT4_ARB 0x8B5C
+#define GL_SAMPLER_1D_ARB 0x8B5D
+#define GL_SAMPLER_2D_ARB 0x8B5E
+#define GL_SAMPLER_3D_ARB 0x8B5F
+#define GL_SAMPLER_CUBE_ARB 0x8B60
+#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61
+#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62
+#define GL_SAMPLER_2D_RECT_ARB 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64
+#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80
+#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
+#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
+#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83
+#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
+#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85
+#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86
+#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87
+#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88
+#define GL_ARB_shading_language_100 1
+#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C
+#define GL_ARB_shadow 1
+#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
+#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
+#define GL_ARB_shadow_ambient 1
+#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF
+#define GL_ARB_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_ARB 0x812D
+#define GL_ARB_texture_compression 1
+#define GL_COMPRESSED_ALPHA_ARB 0x84E9
+#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
+#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
+#define GL_COMPRESSED_RGB_ARB 0x84ED
+#define GL_COMPRESSED_RGBA_ARB 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0
+#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
+#define GL_ARB_texture_cube_map 1
+#define GL_NORMAL_MAP_ARB 0x8511
+#define GL_REFLECTION_MAP_ARB 0x8512
+#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C
+#define GL_ARB_texture_env_add 1
+#define GL_ARB_texture_env_combine 1
+#define GL_SUBTRACT_ARB 0x84E7
+#define GL_COMBINE_ARB 0x8570
+#define GL_COMBINE_RGB_ARB 0x8571
+#define GL_COMBINE_ALPHA_ARB 0x8572
+#define GL_RGB_SCALE_ARB 0x8573
+#define GL_ADD_SIGNED_ARB 0x8574
+#define GL_INTERPOLATE_ARB 0x8575
+#define GL_CONSTANT_ARB 0x8576
+#define GL_PRIMARY_COLOR_ARB 0x8577
+#define GL_PREVIOUS_ARB 0x8578
+#define GL_SOURCE0_RGB_ARB 0x8580
+#define GL_SOURCE1_RGB_ARB 0x8581
+#define GL_SOURCE2_RGB_ARB 0x8582
+#define GL_SOURCE0_ALPHA_ARB 0x8588
+#define GL_SOURCE1_ALPHA_ARB 0x8589
+#define GL_SOURCE2_ALPHA_ARB 0x858A
+#define GL_OPERAND0_RGB_ARB 0x8590
+#define GL_OPERAND1_RGB_ARB 0x8591
+#define GL_OPERAND2_RGB_ARB 0x8592
+#define GL_OPERAND0_ALPHA_ARB 0x8598
+#define GL_OPERAND1_ALPHA_ARB 0x8599
+#define GL_OPERAND2_ALPHA_ARB 0x859A
+#define GL_ARB_texture_env_crossbar 1
+#define GL_ARB_texture_env_dot3 1
+#define GL_DOT3_RGB_ARB 0x86AE
+#define GL_DOT3_RGBA_ARB 0x86AF
+#define GL_ARB_texture_float 1
+#define GL_RGBA32F_ARB 0x8814
+#define GL_RGB32F_ARB 0x8815
+#define GL_ALPHA32F_ARB 0x8816
+#define GL_INTENSITY32F_ARB 0x8817
+#define GL_LUMINANCE32F_ARB 0x8818
+#define GL_LUMINANCE_ALPHA32F_ARB 0x8819
+#define GL_RGBA16F_ARB 0x881A
+#define GL_RGB16F_ARB 0x881B
+#define GL_ALPHA16F_ARB 0x881C
+#define GL_INTENSITY16F_ARB 0x881D
+#define GL_LUMINANCE16F_ARB 0x881E
+#define GL_LUMINANCE_ALPHA16F_ARB 0x881F
+#define GL_TEXTURE_RED_TYPE_ARB 0x8C10
+#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11
+#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12
+#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13
+#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14
+#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15
+#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16
+#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17
+#define GL_ARB_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_ARB 0x8370
+#define GL_ARB_texture_non_power_of_two 1
+#define GL_ARB_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+#define GL_SAMPLER_2D_RECT_ARB 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64
+#define GL_ARB_transpose_matrix 1
+#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6
+#define GL_ARB_vertex_blend 1
+#define GL_MODELVIEW0_ARB 0x1700
+#define GL_MODELVIEW1_ARB 0x850A
+#define GL_MAX_VERTEX_UNITS_ARB 0x86A4
+#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5
+#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6
+#define GL_VERTEX_BLEND_ARB 0x86A7
+#define GL_CURRENT_WEIGHT_ARB 0x86A8
+#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9
+#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA
+#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB
+#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC
+#define GL_WEIGHT_ARRAY_ARB 0x86AD
+#define GL_MODELVIEW2_ARB 0x8722
+#define GL_MODELVIEW3_ARB 0x8723
+#define GL_MODELVIEW4_ARB 0x8724
+#define GL_MODELVIEW5_ARB 0x8725
+#define GL_MODELVIEW6_ARB 0x8726
+#define GL_MODELVIEW7_ARB 0x8727
+#define GL_MODELVIEW8_ARB 0x8728
+#define GL_MODELVIEW9_ARB 0x8729
+#define GL_MODELVIEW10_ARB 0x872A
+#define GL_MODELVIEW11_ARB 0x872B
+#define GL_MODELVIEW12_ARB 0x872C
+#define GL_MODELVIEW13_ARB 0x872D
+#define GL_MODELVIEW14_ARB 0x872E
+#define GL_MODELVIEW15_ARB 0x872F
+#define GL_MODELVIEW16_ARB 0x8730
+#define GL_MODELVIEW17_ARB 0x8731
+#define GL_MODELVIEW18_ARB 0x8732
+#define GL_MODELVIEW19_ARB 0x8733
+#define GL_MODELVIEW20_ARB 0x8734
+#define GL_MODELVIEW21_ARB 0x8735
+#define GL_MODELVIEW22_ARB 0x8736
+#define GL_MODELVIEW23_ARB 0x8737
+#define GL_MODELVIEW24_ARB 0x8738
+#define GL_MODELVIEW25_ARB 0x8739
+#define GL_MODELVIEW26_ARB 0x873A
+#define GL_MODELVIEW27_ARB 0x873B
+#define GL_MODELVIEW28_ARB 0x873C
+#define GL_MODELVIEW29_ARB 0x873D
+#define GL_MODELVIEW30_ARB 0x873E
+#define GL_MODELVIEW31_ARB 0x873F
+#define GL_ARB_vertex_buffer_object 1
+#define GL_BUFFER_SIZE_ARB 0x8764
+#define GL_BUFFER_USAGE_ARB 0x8765
+#define GL_ARRAY_BUFFER_ARB 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
+#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895
+#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F
+#define GL_READ_ONLY_ARB 0x88B8
+#define GL_WRITE_ONLY_ARB 0x88B9
+#define GL_READ_WRITE_ARB 0x88BA
+#define GL_BUFFER_ACCESS_ARB 0x88BB
+#define GL_BUFFER_MAPPED_ARB 0x88BC
+#define GL_BUFFER_MAP_POINTER_ARB 0x88BD
+#define GL_STREAM_DRAW_ARB 0x88E0
+#define GL_STREAM_READ_ARB 0x88E1
+#define GL_STREAM_COPY_ARB 0x88E2
+#define GL_STATIC_DRAW_ARB 0x88E4
+#define GL_STATIC_READ_ARB 0x88E5
+#define GL_STATIC_COPY_ARB 0x88E6
+#define GL_DYNAMIC_DRAW_ARB 0x88E8
+#define GL_DYNAMIC_READ_ARB 0x88E9
+#define GL_DYNAMIC_COPY_ARB 0x88EA
+#define GL_ARB_vertex_program 1
+#define GL_COLOR_SUM_ARB 0x8458
+#define GL_VERTEX_PROGRAM_ARB 0x8620
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626
+#define GL_PROGRAM_LENGTH_ARB 0x8627
+#define GL_PROGRAM_STRING_ARB 0x8628
+#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E
+#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F
+#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640
+#define GL_CURRENT_MATRIX_ARB 0x8641
+#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645
+#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B
+#define GL_PROGRAM_BINDING_ARB 0x8677
+#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A
+#define GL_PROGRAM_ERROR_STRING_ARB 0x8874
+#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
+#define GL_PROGRAM_FORMAT_ARB 0x8876
+#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0
+#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1
+#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2
+#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3
+#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4
+#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5
+#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6
+#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7
+#define GL_PROGRAM_PARAMETERS_ARB 0x88A8
+#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9
+#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA
+#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB
+#define GL_PROGRAM_ATTRIBS_ARB 0x88AC
+#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD
+#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE
+#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF
+#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0
+#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1
+#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2
+#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3
+#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4
+#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5
+#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6
+#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7
+#define GL_MATRIX0_ARB 0x88C0
+#define GL_MATRIX1_ARB 0x88C1
+#define GL_MATRIX2_ARB 0x88C2
+#define GL_MATRIX3_ARB 0x88C3
+#define GL_MATRIX4_ARB 0x88C4
+#define GL_MATRIX5_ARB 0x88C5
+#define GL_MATRIX6_ARB 0x88C6
+#define GL_MATRIX7_ARB 0x88C7
+#define GL_MATRIX8_ARB 0x88C8
+#define GL_MATRIX9_ARB 0x88C9
+#define GL_MATRIX10_ARB 0x88CA
+#define GL_MATRIX11_ARB 0x88CB
+#define GL_MATRIX12_ARB 0x88CC
+#define GL_MATRIX13_ARB 0x88CD
+#define GL_MATRIX14_ARB 0x88CE
+#define GL_MATRIX15_ARB 0x88CF
+#define GL_MATRIX16_ARB 0x88D0
+#define GL_MATRIX17_ARB 0x88D1
+#define GL_MATRIX18_ARB 0x88D2
+#define GL_MATRIX19_ARB 0x88D3
+#define GL_MATRIX20_ARB 0x88D4
+#define GL_MATRIX21_ARB 0x88D5
+#define GL_MATRIX22_ARB 0x88D6
+#define GL_MATRIX23_ARB 0x88D7
+#define GL_MATRIX24_ARB 0x88D8
+#define GL_MATRIX25_ARB 0x88D9
+#define GL_MATRIX26_ARB 0x88DA
+#define GL_MATRIX27_ARB 0x88DB
+#define GL_MATRIX28_ARB 0x88DC
+#define GL_MATRIX29_ARB 0x88DD
+#define GL_MATRIX30_ARB 0x88DE
+#define GL_MATRIX31_ARB 0x88DF
+#define GL_ARB_vertex_shader 1
+#define GL_VERTEX_SHADER_ARB 0x8B31
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A
+#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D
+#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89
+#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A
+#define GL_ARB_window_pos 1
+#define GL_ATIX_point_sprites 1
+#define GL_ATIX_texture_env_combine3 1
+#define GL_MODULATE_ADD_ATIX 0x8744
+#define GL_MODULATE_SIGNED_ADD_ATIX 0x8745
+#define GL_MODULATE_SUBTRACT_ATIX 0x8746
+#define GL_ATIX_texture_env_route 1
+#define GL_SECONDARY_COLOR_ATIX 0x8747
+#define GL_TEXTURE_OUTPUT_RGB_ATIX 0x8748
+#define GL_TEXTURE_OUTPUT_ALPHA_ATIX 0x8749
+#define GL_ATIX_vertex_shader_output_point_size 1
+#define GL_OUTPUT_POINT_SIZE_ATIX 0x610E
+#define GL_ATI_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ATI 0x8824
+#define GL_DRAW_BUFFER0_ATI 0x8825
+#define GL_DRAW_BUFFER1_ATI 0x8826
+#define GL_DRAW_BUFFER2_ATI 0x8827
+#define GL_DRAW_BUFFER3_ATI 0x8828
+#define GL_DRAW_BUFFER4_ATI 0x8829
+#define GL_DRAW_BUFFER5_ATI 0x882A
+#define GL_DRAW_BUFFER6_ATI 0x882B
+#define GL_DRAW_BUFFER7_ATI 0x882C
+#define GL_DRAW_BUFFER8_ATI 0x882D
+#define GL_DRAW_BUFFER9_ATI 0x882E
+#define GL_DRAW_BUFFER10_ATI 0x882F
+#define GL_DRAW_BUFFER11_ATI 0x8830
+#define GL_DRAW_BUFFER12_ATI 0x8831
+#define GL_DRAW_BUFFER13_ATI 0x8832
+#define GL_DRAW_BUFFER14_ATI 0x8833
+#define GL_DRAW_BUFFER15_ATI 0x8834
+#define GL_ATI_element_array 1
+#define GL_ELEMENT_ARRAY_ATI 0x8768
+#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769
+#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A
+#define GL_ATI_envmap_bumpmap 1
+#define GL_BUMP_ROT_MATRIX_ATI 0x8775
+#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776
+#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777
+#define GL_BUMP_TEX_UNITS_ATI 0x8778
+#define GL_DUDV_ATI 0x8779
+#define GL_DU8DV8_ATI 0x877A
+#define GL_BUMP_ENVMAP_ATI 0x877B
+#define GL_BUMP_TARGET_ATI 0x877C
+#define GL_ATI_fragment_shader 1
+#define GL_RED_BIT_ATI 0x00000001
+#define GL_2X_BIT_ATI 0x00000001
+#define GL_4X_BIT_ATI 0x00000002
+#define GL_GREEN_BIT_ATI 0x00000002
+#define GL_COMP_BIT_ATI 0x00000002
+#define GL_BLUE_BIT_ATI 0x00000004
+#define GL_8X_BIT_ATI 0x00000004
+#define GL_NEGATE_BIT_ATI 0x00000004
+#define GL_BIAS_BIT_ATI 0x00000008
+#define GL_HALF_BIT_ATI 0x00000008
+#define GL_QUARTER_BIT_ATI 0x00000010
+#define GL_EIGHTH_BIT_ATI 0x00000020
+#define GL_SATURATE_BIT_ATI 0x00000040
+#define GL_FRAGMENT_SHADER_ATI 0x8920
+#define GL_REG_0_ATI 0x8921
+#define GL_REG_1_ATI 0x8922
+#define GL_REG_2_ATI 0x8923
+#define GL_REG_3_ATI 0x8924
+#define GL_REG_4_ATI 0x8925
+#define GL_REG_5_ATI 0x8926
+#define GL_CON_0_ATI 0x8941
+#define GL_CON_1_ATI 0x8942
+#define GL_CON_2_ATI 0x8943
+#define GL_CON_3_ATI 0x8944
+#define GL_CON_4_ATI 0x8945
+#define GL_CON_5_ATI 0x8946
+#define GL_CON_6_ATI 0x8947
+#define GL_CON_7_ATI 0x8948
+#define GL_MOV_ATI 0x8961
+#define GL_ADD_ATI 0x8963
+#define GL_MUL_ATI 0x8964
+#define GL_SUB_ATI 0x8965
+#define GL_DOT3_ATI 0x8966
+#define GL_DOT4_ATI 0x8967
+#define GL_MAD_ATI 0x8968
+#define GL_LERP_ATI 0x8969
+#define GL_CND_ATI 0x896A
+#define GL_CND0_ATI 0x896B
+#define GL_DOT2_ADD_ATI 0x896C
+#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D
+#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
+#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F
+#define GL_NUM_PASSES_ATI 0x8970
+#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971
+#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972
+#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973
+#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974
+#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975
+#define GL_SWIZZLE_STR_ATI 0x8976
+#define GL_SWIZZLE_STQ_ATI 0x8977
+#define GL_SWIZZLE_STR_DR_ATI 0x8978
+#define GL_SWIZZLE_STQ_DQ_ATI 0x8979
+#define GL_SWIZZLE_STRQ_ATI 0x897A
+#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B
+#define GL_ATI_map_object_buffer 1
+#define GL_ATI_pn_triangles 1
+#define GL_PN_TRIANGLES_ATI 0x87F0
+#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1
+#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2
+#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3
+#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4
+#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5
+#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6
+#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7
+#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8
+#define GL_ATI_separate_stencil 1
+#define GL_STENCIL_BACK_FUNC_ATI 0x8800
+#define GL_STENCIL_BACK_FAIL_ATI 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803
+#define GL_ATI_text_fragment_shader 1
+#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
+#define GL_ATI_texture_compression_3dc 1
+#define GL_COMPRESSED_RGB_3DC_ATI 0x8837
+#define GL_ATI_texture_env_combine3 1
+#define GL_MODULATE_ADD_ATI 0x8744
+#define GL_MODULATE_SIGNED_ADD_ATI 0x8745
+#define GL_MODULATE_SUBTRACT_ATI 0x8746
+#define GL_ATI_texture_float 1
+#define GL_RGBA_FLOAT32_ATI 0x8814
+#define GL_RGB_FLOAT32_ATI 0x8815
+#define GL_ALPHA_FLOAT32_ATI 0x8816
+#define GL_INTENSITY_FLOAT32_ATI 0x8817
+#define GL_LUMINANCE_FLOAT32_ATI 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819
+#define GL_RGBA_FLOAT16_ATI 0x881A
+#define GL_RGB_FLOAT16_ATI 0x881B
+#define GL_ALPHA_FLOAT16_ATI 0x881C
+#define GL_INTENSITY_FLOAT16_ATI 0x881D
+#define GL_LUMINANCE_FLOAT16_ATI 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F
+#define GL_ATI_texture_mirror_once 1
+#define GL_MIRROR_CLAMP_ATI 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743
+#define GL_ATI_vertex_array_object 1
+#define GL_STATIC_ATI 0x8760
+#define GL_DYNAMIC_ATI 0x8761
+#define GL_PRESERVE_ATI 0x8762
+#define GL_DISCARD_ATI 0x8763
+#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764
+#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765
+#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766
+#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767
+#define GL_ATI_vertex_attrib_array_object 1
+#define GL_ATI_vertex_streams 1
+#define GL_MAX_VERTEX_STREAMS_ATI 0x876B
+#define GL_VERTEX_SOURCE_ATI 0x876C
+#define GL_VERTEX_STREAM0_ATI 0x876D
+#define GL_VERTEX_STREAM1_ATI 0x876E
+#define GL_VERTEX_STREAM2_ATI 0x876F
+#define GL_VERTEX_STREAM3_ATI 0x8770
+#define GL_VERTEX_STREAM4_ATI 0x8771
+#define GL_VERTEX_STREAM5_ATI 0x8772
+#define GL_VERTEX_STREAM6_ATI 0x8773
+#define GL_VERTEX_STREAM7_ATI 0x8774
+#define GL_EXT_422_pixels 1
+#define GL_422_EXT 0x80CC
+#define GL_422_REV_EXT 0x80CD
+#define GL_422_AVERAGE_EXT 0x80CE
+#define GL_422_REV_AVERAGE_EXT 0x80CF
+#define GL_EXT_Cg_shader 1
+#define GL_CG_VERTEX_SHADER_EXT 0x890E
+#define GL_CG_FRAGMENT_SHADER_EXT 0x890F
+#define GL_EXT_abgr 1
+#define GL_ABGR_EXT 0x8000
+#define GL_EXT_bgra 1
+#define GL_BGR_EXT 0x80E0
+#define GL_BGRA_EXT 0x80E1
+#define GL_EXT_blend_color 1
+#define GL_CONSTANT_COLOR_EXT 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002
+#define GL_CONSTANT_ALPHA_EXT 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004
+#define GL_BLEND_COLOR_EXT 0x8005
+#define GL_EXT_blend_equation_separate 1
+#define GL_BLEND_EQUATION_RGB_EXT 0x8009
+#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D
+#define GL_EXT_blend_func_separate 1
+#define GL_BLEND_DST_RGB_EXT 0x80C8
+#define GL_BLEND_SRC_RGB_EXT 0x80C9
+#define GL_BLEND_DST_ALPHA_EXT 0x80CA
+#define GL_BLEND_SRC_ALPHA_EXT 0x80CB
+#define GL_EXT_blend_logic_op 1
+#define GL_EXT_blend_minmax 1
+#define GL_FUNC_ADD_EXT 0x8006
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#define GL_BLEND_EQUATION_EXT 0x8009
+#define GL_EXT_blend_subtract 1
+#define GL_FUNC_SUBTRACT_EXT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B
+#define GL_EXT_clip_volume_hint 1
+#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0
+#define GL_EXT_cmyka 1
+#define GL_CMYK_EXT 0x800C
+#define GL_CMYKA_EXT 0x800D
+#define GL_PACK_CMYK_HINT_EXT 0x800E
+#define GL_UNPACK_CMYK_HINT_EXT 0x800F
+#define GL_EXT_color_subtable 1
+#define GL_EXT_compiled_vertex_array 1
+#define GL_EXT_convolution 1
+#define GL_CONVOLUTION_1D_EXT 0x8010
+#define GL_CONVOLUTION_2D_EXT 0x8011
+#define GL_SEPARABLE_2D_EXT 0x8012
+#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015
+#define GL_REDUCE_EXT 0x8016
+#define GL_CONVOLUTION_FORMAT_EXT 0x8017
+#define GL_CONVOLUTION_WIDTH_EXT 0x8018
+#define GL_CONVOLUTION_HEIGHT_EXT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023
+#define GL_EXT_coordinate_frame 1
+#define GL_TANGENT_ARRAY_EXT 0x8439
+#define GL_BINORMAL_ARRAY_EXT 0x843A
+#define GL_CURRENT_TANGENT_EXT 0x843B
+#define GL_CURRENT_BINORMAL_EXT 0x843C
+#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E
+#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F
+#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440
+#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441
+#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442
+#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443
+#define GL_MAP1_TANGENT_EXT 0x8444
+#define GL_MAP2_TANGENT_EXT 0x8445
+#define GL_MAP1_BINORMAL_EXT 0x8446
+#define GL_MAP2_BINORMAL_EXT 0x8447
+#define GL_EXT_copy_texture 1
+#define GL_EXT_cull_vertex 1
+#define GL_EXT_depth_bounds_test 1
+#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890
+#define GL_DEPTH_BOUNDS_EXT 0x8891
+#define GL_EXT_draw_range_elements 1
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_EXT_fog_coord 1
+#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450
+#define GL_FOG_COORDINATE_EXT 0x8451
+#define GL_FRAGMENT_DEPTH_EXT 0x8452
+#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456
+#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457
+#define GL_EXT_fragment_lighting 1
+#define GL_FRAGMENT_LIGHTING_EXT 0x8400
+#define GL_FRAGMENT_COLOR_MATERIAL_EXT 0x8401
+#define GL_FRAGMENT_COLOR_MATERIAL_FACE_EXT 0x8402
+#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_EXT 0x8403
+#define GL_MAX_FRAGMENT_LIGHTS_EXT 0x8404
+#define GL_MAX_ACTIVE_LIGHTS_EXT 0x8405
+#define GL_CURRENT_RASTER_NORMAL_EXT 0x8406
+#define GL_LIGHT_ENV_MODE_EXT 0x8407
+#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_EXT 0x8408
+#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_EXT 0x8409
+#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_EXT 0x840A
+#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_EXT 0x840B
+#define GL_FRAGMENT_LIGHT0_EXT 0x840C
+#define GL_FRAGMENT_LIGHT7_EXT 0x8413
+#define GL_EXT_framebuffer_blit 1
+#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
+#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
+#define GL_EXT_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_EXT_framebuffer_object 1
+#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
+#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
+#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
+#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
+#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#define GL_RENDERBUFFER_EXT 0x8D41
+#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
+#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
+#define GL_STENCIL_INDEX1_EXT 0x8D46
+#define GL_STENCIL_INDEX4_EXT 0x8D47
+#define GL_STENCIL_INDEX8_EXT 0x8D48
+#define GL_STENCIL_INDEX16_EXT 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
+#define GL_EXT_histogram 1
+#define GL_HISTOGRAM_EXT 0x8024
+#define GL_PROXY_HISTOGRAM_EXT 0x8025
+#define GL_HISTOGRAM_WIDTH_EXT 0x8026
+#define GL_HISTOGRAM_FORMAT_EXT 0x8027
+#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C
+#define GL_HISTOGRAM_SINK_EXT 0x802D
+#define GL_MINMAX_EXT 0x802E
+#define GL_MINMAX_FORMAT_EXT 0x802F
+#define GL_MINMAX_SINK_EXT 0x8030
+#define GL_EXT_index_array_formats 1
+#define GL_EXT_index_func 1
+#define GL_EXT_index_material 1
+#define GL_EXT_index_texture 1
+#define GL_EXT_light_texture 1
+#define GL_FRAGMENT_MATERIAL_EXT 0x8349
+#define GL_FRAGMENT_NORMAL_EXT 0x834A
+#define GL_FRAGMENT_COLOR_EXT 0x834C
+#define GL_ATTENUATION_EXT 0x834D
+#define GL_SHADOW_ATTENUATION_EXT 0x834E
+#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F
+#define GL_TEXTURE_LIGHT_EXT 0x8350
+#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351
+#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352
+#define GL_FRAGMENT_DEPTH_EXT 0x8452
+#define GL_EXT_misc_attribute 1
+#define GL_EXT_multi_draw_arrays 1
+#define GL_EXT_multisample 1
+#define GL_MULTISAMPLE_EXT 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F
+#define GL_SAMPLE_MASK_EXT 0x80A0
+#define GL_1PASS_EXT 0x80A1
+#define GL_2PASS_0_EXT 0x80A2
+#define GL_2PASS_1_EXT 0x80A3
+#define GL_4PASS_0_EXT 0x80A4
+#define GL_4PASS_1_EXT 0x80A5
+#define GL_4PASS_2_EXT 0x80A6
+#define GL_4PASS_3_EXT 0x80A7
+#define GL_SAMPLE_BUFFERS_EXT 0x80A8
+#define GL_SAMPLES_EXT 0x80A9
+#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA
+#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB
+#define GL_SAMPLE_PATTERN_EXT 0x80AC
+#define GL_MULTISAMPLE_BIT_EXT 0x20000000
+#define GL_EXT_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_EXT 0x84F9
+#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
+#define GL_DEPTH24_STENCIL8_EXT 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
+#define GL_EXT_packed_pixels 1
+#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036
+#define GL_EXT_paletted_texture 1
+#define GL_TEXTURE_1D 0x0DE0
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_PROXY_TEXTURE_1D 0x8063
+#define GL_PROXY_TEXTURE_2D 0x8064
+#define GL_TEXTURE_3D_EXT 0x806F
+#define GL_PROXY_TEXTURE_3D_EXT 0x8070
+#define GL_COLOR_TABLE_FORMAT_EXT 0x80D8
+#define GL_COLOR_TABLE_WIDTH_EXT 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE_EXT 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE_EXT 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE_EXT 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE_EXT 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE_EXT 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE_EXT 0x80DF
+#define GL_COLOR_INDEX1_EXT 0x80E2
+#define GL_COLOR_INDEX2_EXT 0x80E3
+#define GL_COLOR_INDEX4_EXT 0x80E4
+#define GL_COLOR_INDEX8_EXT 0x80E5
+#define GL_COLOR_INDEX12_EXT 0x80E6
+#define GL_COLOR_INDEX16_EXT 0x80E7
+#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
+#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B
+#define GL_EXT_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF
+#define GL_EXT_pixel_transform 1
+#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330
+#define GL_PIXEL_MAG_FILTER_EXT 0x8331
+#define GL_PIXEL_MIN_FILTER_EXT 0x8332
+#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333
+#define GL_CUBIC_EXT 0x8334
+#define GL_AVERAGE_EXT 0x8335
+#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336
+#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337
+#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338
+#define GL_EXT_pixel_transform_color_table 1
+#define GL_EXT_point_parameters 1
+#define GL_POINT_SIZE_MIN_EXT 0x8126
+#define GL_POINT_SIZE_MAX_EXT 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
+#define GL_DISTANCE_ATTENUATION_EXT 0x8129
+#define GL_EXT_polygon_offset 1
+#define GL_POLYGON_OFFSET_EXT 0x8037
+#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038
+#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039
+#define GL_EXT_rescale_normal 1
+#define GL_EXT_scene_marker 1
+#define GL_EXT_secondary_color 1
+#define GL_COLOR_SUM_EXT 0x8458
+#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D
+#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E
+#define GL_EXT_separate_specular_color 1
+#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8
+#define GL_SINGLE_COLOR_EXT 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA
+#define GL_EXT_shadow_funcs 1
+#define GL_EXT_shared_texture_palette 1
+#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
+#define GL_EXT_stencil_clear_tag 1
+#define GL_STENCIL_TAG_BITS_EXT 0x88F2
+#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3
+#define GL_EXT_stencil_two_side 1
+#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910
+#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911
+#define GL_EXT_stencil_wrap 1
+#define GL_INCR_WRAP_EXT 0x8507
+#define GL_DECR_WRAP_EXT 0x8508
+#define GL_EXT_subtexture 1
+#define GL_EXT_texture 1
+#define GL_ALPHA4_EXT 0x803B
+#define GL_ALPHA8_EXT 0x803C
+#define GL_ALPHA12_EXT 0x803D
+#define GL_ALPHA16_EXT 0x803E
+#define GL_LUMINANCE4_EXT 0x803F
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE12_EXT 0x8041
+#define GL_LUMINANCE16_EXT 0x8042
+#define GL_LUMINANCE4_ALPHA4_EXT 0x8043
+#define GL_LUMINANCE6_ALPHA2_EXT 0x8044
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_LUMINANCE12_ALPHA4_EXT 0x8046
+#define GL_LUMINANCE12_ALPHA12_EXT 0x8047
+#define GL_LUMINANCE16_ALPHA16_EXT 0x8048
+#define GL_INTENSITY_EXT 0x8049
+#define GL_INTENSITY4_EXT 0x804A
+#define GL_INTENSITY8_EXT 0x804B
+#define GL_INTENSITY12_EXT 0x804C
+#define GL_INTENSITY16_EXT 0x804D
+#define GL_RGB2_EXT 0x804E
+#define GL_RGB4_EXT 0x804F
+#define GL_RGB5_EXT 0x8050
+#define GL_RGB8_EXT 0x8051
+#define GL_RGB10_EXT 0x8052
+#define GL_RGB12_EXT 0x8053
+#define GL_RGB16_EXT 0x8054
+#define GL_RGBA2_EXT 0x8055
+#define GL_RGBA4_EXT 0x8056
+#define GL_RGB5_A1_EXT 0x8057
+#define GL_RGBA8_EXT 0x8058
+#define GL_RGB10_A2_EXT 0x8059
+#define GL_RGBA12_EXT 0x805A
+#define GL_RGBA16_EXT 0x805B
+#define GL_TEXTURE_RED_SIZE_EXT 0x805C
+#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D
+#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E
+#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061
+#define GL_REPLACE_EXT 0x8062
+#define GL_PROXY_TEXTURE_1D_EXT 0x8063
+#define GL_PROXY_TEXTURE_2D_EXT 0x8064
+#define GL_EXT_texture3D 1
+#define GL_PACK_SKIP_IMAGES_EXT 0x806B
+#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C
+#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E
+#define GL_TEXTURE_3D_EXT 0x806F
+#define GL_PROXY_TEXTURE_3D_EXT 0x8070
+#define GL_TEXTURE_DEPTH_EXT 0x8071
+#define GL_TEXTURE_WRAP_R_EXT 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073
+#define GL_EXT_texture_compression_dxt1 1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#define GL_EXT_texture_compression_s3tc 1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#define GL_EXT_texture_cube_map 1
+#define GL_NORMAL_MAP_EXT 0x8511
+#define GL_REFLECTION_MAP_EXT 0x8512
+#define GL_TEXTURE_CUBE_MAP_EXT 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C
+#define GL_EXT_texture_edge_clamp 1
+#define GL_CLAMP_TO_EDGE_EXT 0x812F
+#define GL_EXT_texture_env 1
+#define GL_TEXTURE_ENV0_EXT 0
+#define GL_ENV_BLEND_EXT 0
+#define GL_TEXTURE_ENV_SHIFT_EXT 0
+#define GL_ENV_REPLACE_EXT 0
+#define GL_ENV_ADD_EXT 0
+#define GL_ENV_SUBTRACT_EXT 0
+#define GL_TEXTURE_ENV_MODE_ALPHA_EXT 0
+#define GL_ENV_REVERSE_SUBTRACT_EXT 0
+#define GL_ENV_REVERSE_BLEND_EXT 0
+#define GL_ENV_COPY_EXT 0
+#define GL_ENV_MODULATE_EXT 0
+#define GL_EXT_texture_env_add 1
+#define GL_EXT_texture_env_combine 1
+#define GL_COMBINE_EXT 0x8570
+#define GL_COMBINE_RGB_EXT 0x8571
+#define GL_COMBINE_ALPHA_EXT 0x8572
+#define GL_RGB_SCALE_EXT 0x8573
+#define GL_ADD_SIGNED_EXT 0x8574
+#define GL_INTERPOLATE_EXT 0x8575
+#define GL_CONSTANT_EXT 0x8576
+#define GL_PRIMARY_COLOR_EXT 0x8577
+#define GL_PREVIOUS_EXT 0x8578
+#define GL_SOURCE0_RGB_EXT 0x8580
+#define GL_SOURCE1_RGB_EXT 0x8581
+#define GL_SOURCE2_RGB_EXT 0x8582
+#define GL_SOURCE0_ALPHA_EXT 0x8588
+#define GL_SOURCE1_ALPHA_EXT 0x8589
+#define GL_SOURCE2_ALPHA_EXT 0x858A
+#define GL_OPERAND0_RGB_EXT 0x8590
+#define GL_OPERAND1_RGB_EXT 0x8591
+#define GL_OPERAND2_RGB_EXT 0x8592
+#define GL_OPERAND0_ALPHA_EXT 0x8598
+#define GL_OPERAND1_ALPHA_EXT 0x8599
+#define GL_OPERAND2_ALPHA_EXT 0x859A
+#define GL_EXT_texture_env_dot3 1
+#define GL_DOT3_RGB_EXT 0x8740
+#define GL_DOT3_RGBA_EXT 0x8741
+#define GL_EXT_texture_filter_anisotropic 1
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#define GL_EXT_texture_lod_bias 1
+#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD
+#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500
+#define GL_TEXTURE_LOD_BIAS_EXT 0x8501
+#define GL_EXT_texture_mirror_clamp 1
+#define GL_MIRROR_CLAMP_EXT 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743
+#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912
+#define GL_EXT_texture_object 1
+#define GL_TEXTURE_PRIORITY_EXT 0x8066
+#define GL_TEXTURE_RESIDENT_EXT 0x8067
+#define GL_TEXTURE_1D_BINDING_EXT 0x8068
+#define GL_TEXTURE_2D_BINDING_EXT 0x8069
+#define GL_TEXTURE_3D_BINDING_EXT 0x806A
+#define GL_EXT_texture_perturb_normal 1
+#define GL_PERTURB_EXT 0x85AE
+#define GL_TEXTURE_NORMAL_EXT 0x85AF
+#define GL_EXT_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_EXT 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_EXT 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_EXT 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT 0x84F8
+#define GL_EXT_texture_sRGB 1
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB8_EXT 0x8C41
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_SLUMINANCE_ALPHA_EXT 0x8C44
+#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45
+#define GL_SLUMINANCE_EXT 0x8C46
+#define GL_SLUMINANCE8_EXT 0x8C47
+#define GL_COMPRESSED_SRGB_EXT 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49
+#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
+#define GL_EXT_vertex_array 1
+#define GL_DOUBLE_EXT 0x140A
+#define GL_VERTEX_ARRAY_EXT 0x8074
+#define GL_NORMAL_ARRAY_EXT 0x8075
+#define GL_COLOR_ARRAY_EXT 0x8076
+#define GL_INDEX_ARRAY_EXT 0x8077
+#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078
+#define GL_EDGE_FLAG_ARRAY_EXT 0x8079
+#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A
+#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B
+#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C
+#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
+#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E
+#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F
+#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
+#define GL_COLOR_ARRAY_SIZE_EXT 0x8081
+#define GL_COLOR_ARRAY_TYPE_EXT 0x8082
+#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083
+#define GL_COLOR_ARRAY_COUNT_EXT 0x8084
+#define GL_INDEX_ARRAY_TYPE_EXT 0x8085
+#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086
+#define GL_INDEX_ARRAY_COUNT_EXT 0x8087
+#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A
+#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
+#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C
+#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
+#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E
+#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F
+#define GL_COLOR_ARRAY_POINTER_EXT 0x8090
+#define GL_INDEX_ARRAY_POINTER_EXT 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093
+#define GL_EXT_vertex_shader 1
+#define GL_VERTEX_SHADER_EXT 0x8780
+#define GL_VERTEX_SHADER_BINDING_EXT 0x8781
+#define GL_OP_INDEX_EXT 0x8782
+#define GL_OP_NEGATE_EXT 0x8783
+#define GL_OP_DOT3_EXT 0x8784
+#define GL_OP_DOT4_EXT 0x8785
+#define GL_OP_MUL_EXT 0x8786
+#define GL_OP_ADD_EXT 0x8787
+#define GL_OP_MADD_EXT 0x8788
+#define GL_OP_FRAC_EXT 0x8789
+#define GL_OP_MAX_EXT 0x878A
+#define GL_OP_MIN_EXT 0x878B
+#define GL_OP_SET_GE_EXT 0x878C
+#define GL_OP_SET_LT_EXT 0x878D
+#define GL_OP_CLAMP_EXT 0x878E
+#define GL_OP_FLOOR_EXT 0x878F
+#define GL_OP_ROUND_EXT 0x8790
+#define GL_OP_EXP_BASE_2_EXT 0x8791
+#define GL_OP_LOG_BASE_2_EXT 0x8792
+#define GL_OP_POWER_EXT 0x8793
+#define GL_OP_RECIP_EXT 0x8794
+#define GL_OP_RECIP_SQRT_EXT 0x8795
+#define GL_OP_SUB_EXT 0x8796
+#define GL_OP_CROSS_PRODUCT_EXT 0x8797
+#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798
+#define GL_OP_MOV_EXT 0x8799
+#define GL_OUTPUT_VERTEX_EXT 0x879A
+#define GL_OUTPUT_COLOR0_EXT 0x879B
+#define GL_OUTPUT_COLOR1_EXT 0x879C
+#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D
+#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E
+#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F
+#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0
+#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1
+#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2
+#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3
+#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4
+#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5
+#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6
+#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7
+#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8
+#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9
+#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA
+#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB
+#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC
+#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD
+#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE
+#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF
+#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0
+#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1
+#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2
+#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3
+#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4
+#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5
+#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6
+#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7
+#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8
+#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9
+#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA
+#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB
+#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC
+#define GL_OUTPUT_FOG_EXT 0x87BD
+#define GL_SCALAR_EXT 0x87BE
+#define GL_VECTOR_EXT 0x87BF
+#define GL_MATRIX_EXT 0x87C0
+#define GL_VARIANT_EXT 0x87C1
+#define GL_INVARIANT_EXT 0x87C2
+#define GL_LOCAL_CONSTANT_EXT 0x87C3
+#define GL_LOCAL_EXT 0x87C4
+#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5
+#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6
+#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7
+#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8
+#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CC
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CD
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE
+#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF
+#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0
+#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1
+#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2
+#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3
+#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4
+#define GL_X_EXT 0x87D5
+#define GL_Y_EXT 0x87D6
+#define GL_Z_EXT 0x87D7
+#define GL_W_EXT 0x87D8
+#define GL_NEGATIVE_X_EXT 0x87D9
+#define GL_NEGATIVE_Y_EXT 0x87DA
+#define GL_NEGATIVE_Z_EXT 0x87DB
+#define GL_NEGATIVE_W_EXT 0x87DC
+#define GL_ZERO_EXT 0x87DD
+#define GL_ONE_EXT 0x87DE
+#define GL_NEGATIVE_ONE_EXT 0x87DF
+#define GL_NORMALIZED_RANGE_EXT 0x87E0
+#define GL_FULL_RANGE_EXT 0x87E1
+#define GL_CURRENT_VERTEX_EXT 0x87E2
+#define GL_MVP_MATRIX_EXT 0x87E3
+#define GL_VARIANT_VALUE_EXT 0x87E4
+#define GL_VARIANT_DATATYPE_EXT 0x87E5
+#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6
+#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7
+#define GL_VARIANT_ARRAY_EXT 0x87E8
+#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9
+#define GL_INVARIANT_VALUE_EXT 0x87EA
+#define GL_INVARIANT_DATATYPE_EXT 0x87EB
+#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC
+#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED
+#define GL_EXT_vertex_weighting 1
+#define GL_MODELVIEW0_STACK_DEPTH_EXT 0x0BA3
+#define GL_MODELVIEW0_MATRIX_EXT 0x0BA6
+#define GL_MODELVIEW0_EXT 0x1700
+#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502
+#define GL_MODELVIEW1_MATRIX_EXT 0x8506
+#define GL_VERTEX_WEIGHTING_EXT 0x8509
+#define GL_MODELVIEW1_EXT 0x850A
+#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B
+#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C
+#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D
+#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E
+#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F
+#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510
+#define GL_GREMEDY_string_marker 1
+#define GL_HP_convolution_border_modes 1
+#define GL_HP_image_transform 1
+#define GL_HP_occlusion_test 1
+#define GL_OCCLUSION_TEST_HP 0x8165
+#define GL_OCCLUSION_TEST_RESULT_HP 0x8166
+#define GL_HP_texture_lighting 1
+#define GL_IBM_cull_vertex 1
+#define GL_CULL_VERTEX_IBM 103050
+#define GL_IBM_multimode_draw_arrays 1
+#define GL_IBM_rasterpos_clip 1
+#define GL_RASTER_POSITION_UNCLIPPED_IBM 103010
+#define GL_IBM_static_data 1
+#define GL_ALL_STATIC_DATA_IBM 103060
+#define GL_STATIC_VERTEX_ARRAY_IBM 103061
+#define GL_IBM_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_IBM 0x8370
+#define GL_IBM_vertex_array_lists 1
+#define GL_VERTEX_ARRAY_LIST_IBM 103070
+#define GL_NORMAL_ARRAY_LIST_IBM 103071
+#define GL_COLOR_ARRAY_LIST_IBM 103072
+#define GL_INDEX_ARRAY_LIST_IBM 103073
+#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074
+#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075
+#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076
+#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077
+#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080
+#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081
+#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082
+#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083
+#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084
+#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085
+#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086
+#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087
+#define GL_INGR_color_clamp 1
+#define GL_RED_MIN_CLAMP_INGR 0x8560
+#define GL_GREEN_MIN_CLAMP_INGR 0x8561
+#define GL_BLUE_MIN_CLAMP_INGR 0x8562
+#define GL_ALPHA_MIN_CLAMP_INGR 0x8563
+#define GL_RED_MAX_CLAMP_INGR 0x8564
+#define GL_GREEN_MAX_CLAMP_INGR 0x8565
+#define GL_BLUE_MAX_CLAMP_INGR 0x8566
+#define GL_ALPHA_MAX_CLAMP_INGR 0x8567
+#define GL_INGR_interlace_read 1
+#define GL_INTERLACE_READ_INGR 0x8568
+#define GL_INTEL_parallel_arrays 1
+#define GL_PARALLEL_ARRAYS_INTEL 0x83F4
+#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5
+#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6
+#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7
+#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8
+#define GL_INTEL_texture_scissor 1
+#define GL_KTX_buffer_region 1
+#define GL_KTX_FRONT_REGION 0x0
+#define GL_KTX_BACK_REGION 0x1
+#define GL_KTX_Z_REGION 0x2
+#define GL_KTX_STENCIL_REGION 0x3
+#define GL_MESAX_texture_stack 1
+#define GL_TEXTURE_1D_STACK_MESAX 0x8759
+#define GL_TEXTURE_2D_STACK_MESAX 0x875A
+#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B
+#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C
+#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D
+#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E
+#define GL_MESA_pack_invert 1
+#define GL_PACK_INVERT_MESA 0x8758
+#define GL_MESA_resize_buffers 1
+#define GL_MESA_window_pos 1
+#define GL_MESA_ycbcr_texture 1
+#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB
+#define GL_YCBCR_MESA 0x8757
+#define GL_NV_blend_square 1
+#define GL_NV_copy_depth_to_color 1
+#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E
+#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F
+#define GL_NV_depth_clamp 1
+#define GL_DEPTH_CLAMP_NV 0x864F
+#define GL_NV_evaluators 1
+#define GL_EVAL_2D_NV 0x86C0
+#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1
+#define GL_MAP_TESSELLATION_NV 0x86C2
+#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3
+#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4
+#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5
+#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6
+#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7
+#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8
+#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9
+#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA
+#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB
+#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC
+#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD
+#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE
+#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF
+#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0
+#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1
+#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2
+#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3
+#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4
+#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5
+#define GL_MAX_MAP_TESSELLATION_NV 0x86D6
+#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7
+#define GL_NV_fence 1
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+#define GL_NV_float_buffer 1
+#define GL_FLOAT_R_NV 0x8880
+#define GL_FLOAT_RG_NV 0x8881
+#define GL_FLOAT_RGB_NV 0x8882
+#define GL_FLOAT_RGBA_NV 0x8883
+#define GL_FLOAT_R16_NV 0x8884
+#define GL_FLOAT_R32_NV 0x8885
+#define GL_FLOAT_RG16_NV 0x8886
+#define GL_FLOAT_RG32_NV 0x8887
+#define GL_FLOAT_RGB16_NV 0x8888
+#define GL_FLOAT_RGB32_NV 0x8889
+#define GL_FLOAT_RGBA16_NV 0x888A
+#define GL_FLOAT_RGBA32_NV 0x888B
+#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
+#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
+#define GL_FLOAT_RGBA_MODE_NV 0x888E
+#define GL_NV_fog_distance 1
+#define GL_FOG_DISTANCE_MODE_NV 0x855A
+#define GL_EYE_RADIAL_NV 0x855B
+#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
+#define GL_NV_fragment_program 1
+#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868
+#define GL_FRAGMENT_PROGRAM_NV 0x8870
+#define GL_MAX_TEXTURE_COORDS_NV 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872
+#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873
+#define GL_PROGRAM_ERROR_STRING_NV 0x8874
+#define GL_NV_fragment_program2 1
+#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4
+#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5
+#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6
+#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7
+#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8
+#define GL_NV_fragment_program_option 1
+#define GL_NV_half_float 1
+#define GL_HALF_FLOAT_NV 0x140B
+#define GL_NV_light_max_exponent 1
+#define GL_MAX_SHININESS_NV 0x8504
+#define GL_MAX_SPOT_EXPONENT_NV 0x8505
+#define GL_NV_multisample_filter_hint 1
+#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
+#define GL_NV_occlusion_query 1
+#define GL_PIXEL_COUNTER_BITS_NV 0x8864
+#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865
+#define GL_PIXEL_COUNT_NV 0x8866
+#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867
+#define GL_NV_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_NV 0x84F9
+#define GL_UNSIGNED_INT_24_8_NV 0x84FA
+#define GL_NV_pixel_data_range 1
+#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878
+#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879
+#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A
+#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B
+#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C
+#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D
+#define GL_NV_point_sprite 1
+#define GL_POINT_SPRITE_NV 0x8861
+#define GL_COORD_REPLACE_NV 0x8862
+#define GL_POINT_SPRITE_R_MODE_NV 0x8863
+#define GL_NV_primitive_restart 1
+#define GL_PRIMITIVE_RESTART_NV 0x8558
+#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559
+#define GL_NV_register_combiners 1
+#define GL_REGISTER_COMBINERS_NV 0x8522
+#define GL_VARIABLE_A_NV 0x8523
+#define GL_VARIABLE_B_NV 0x8524
+#define GL_VARIABLE_C_NV 0x8525
+#define GL_VARIABLE_D_NV 0x8526
+#define GL_VARIABLE_E_NV 0x8527
+#define GL_VARIABLE_F_NV 0x8528
+#define GL_VARIABLE_G_NV 0x8529
+#define GL_CONSTANT_COLOR0_NV 0x852A
+#define GL_CONSTANT_COLOR1_NV 0x852B
+#define GL_PRIMARY_COLOR_NV 0x852C
+#define GL_SECONDARY_COLOR_NV 0x852D
+#define GL_SPARE0_NV 0x852E
+#define GL_SPARE1_NV 0x852F
+#define GL_DISCARD_NV 0x8530
+#define GL_E_TIMES_F_NV 0x8531
+#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532
+#define GL_UNSIGNED_IDENTITY_NV 0x8536
+#define GL_UNSIGNED_INVERT_NV 0x8537
+#define GL_EXPAND_NORMAL_NV 0x8538
+#define GL_EXPAND_NEGATE_NV 0x8539
+#define GL_HALF_BIAS_NORMAL_NV 0x853A
+#define GL_HALF_BIAS_NEGATE_NV 0x853B
+#define GL_SIGNED_IDENTITY_NV 0x853C
+#define GL_SIGNED_NEGATE_NV 0x853D
+#define GL_SCALE_BY_TWO_NV 0x853E
+#define GL_SCALE_BY_FOUR_NV 0x853F
+#define GL_SCALE_BY_ONE_HALF_NV 0x8540
+#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541
+#define GL_COMBINER_INPUT_NV 0x8542
+#define GL_COMBINER_MAPPING_NV 0x8543
+#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544
+#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545
+#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546
+#define GL_COMBINER_MUX_SUM_NV 0x8547
+#define GL_COMBINER_SCALE_NV 0x8548
+#define GL_COMBINER_BIAS_NV 0x8549
+#define GL_COMBINER_AB_OUTPUT_NV 0x854A
+#define GL_COMBINER_CD_OUTPUT_NV 0x854B
+#define GL_COMBINER_SUM_OUTPUT_NV 0x854C
+#define GL_MAX_GENERAL_COMBINERS_NV 0x854D
+#define GL_NUM_GENERAL_COMBINERS_NV 0x854E
+#define GL_COLOR_SUM_CLAMP_NV 0x854F
+#define GL_COMBINER0_NV 0x8550
+#define GL_COMBINER1_NV 0x8551
+#define GL_COMBINER2_NV 0x8552
+#define GL_COMBINER3_NV 0x8553
+#define GL_COMBINER4_NV 0x8554
+#define GL_COMBINER5_NV 0x8555
+#define GL_COMBINER6_NV 0x8556
+#define GL_COMBINER7_NV 0x8557
+#define GL_NV_register_combiners2 1
+#define GL_PER_STAGE_CONSTANTS_NV 0x8535
+#define GL_NV_texgen_emboss 1
+#define GL_EMBOSS_LIGHT_NV 0x855D
+#define GL_EMBOSS_CONSTANT_NV 0x855E
+#define GL_EMBOSS_MAP_NV 0x855F
+#define GL_NV_texgen_reflection 1
+#define GL_NORMAL_MAP_NV 0x8511
+#define GL_REFLECTION_MAP_NV 0x8512
+#define GL_NV_texture_compression_vtc 1
+#define GL_NV_texture_env_combine4 1
+#define GL_COMBINE4_NV 0x8503
+#define GL_SOURCE3_RGB_NV 0x8583
+#define GL_SOURCE3_ALPHA_NV 0x858B
+#define GL_OPERAND3_RGB_NV 0x8593
+#define GL_OPERAND3_ALPHA_NV 0x859B
+#define GL_NV_texture_expand_normal 1
+#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F
+#define GL_NV_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_NV 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8
+#define GL_NV_texture_shader 1
+#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C
+#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D
+#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E
+#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9
+#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA
+#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB
+#define GL_DSDT_MAG_INTENSITY_NV 0x86DC
+#define GL_SHADER_CONSISTENT_NV 0x86DD
+#define GL_TEXTURE_SHADER_NV 0x86DE
+#define GL_SHADER_OPERATION_NV 0x86DF
+#define GL_CULL_MODES_NV 0x86E0
+#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1
+#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2
+#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3
+#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4
+#define GL_CONST_EYE_NV 0x86E5
+#define GL_PASS_THROUGH_NV 0x86E6
+#define GL_CULL_FRAGMENT_NV 0x86E7
+#define GL_OFFSET_TEXTURE_2D_NV 0x86E8
+#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9
+#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA
+#define GL_DOT_PRODUCT_NV 0x86EC
+#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED
+#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE
+#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0
+#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1
+#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2
+#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3
+#define GL_HILO_NV 0x86F4
+#define GL_DSDT_NV 0x86F5
+#define GL_DSDT_MAG_NV 0x86F6
+#define GL_DSDT_MAG_VIB_NV 0x86F7
+#define GL_HILO16_NV 0x86F8
+#define GL_SIGNED_HILO_NV 0x86F9
+#define GL_SIGNED_HILO16_NV 0x86FA
+#define GL_SIGNED_RGBA_NV 0x86FB
+#define GL_SIGNED_RGBA8_NV 0x86FC
+#define GL_SIGNED_RGB_NV 0x86FE
+#define GL_SIGNED_RGB8_NV 0x86FF
+#define GL_SIGNED_LUMINANCE_NV 0x8701
+#define GL_SIGNED_LUMINANCE8_NV 0x8702
+#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
+#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
+#define GL_SIGNED_ALPHA_NV 0x8705
+#define GL_SIGNED_ALPHA8_NV 0x8706
+#define GL_SIGNED_INTENSITY_NV 0x8707
+#define GL_SIGNED_INTENSITY8_NV 0x8708
+#define GL_DSDT8_NV 0x8709
+#define GL_DSDT8_MAG8_NV 0x870A
+#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
+#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
+#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
+#define GL_HI_SCALE_NV 0x870E
+#define GL_LO_SCALE_NV 0x870F
+#define GL_DS_SCALE_NV 0x8710
+#define GL_DT_SCALE_NV 0x8711
+#define GL_MAGNITUDE_SCALE_NV 0x8712
+#define GL_VIBRANCE_SCALE_NV 0x8713
+#define GL_HI_BIAS_NV 0x8714
+#define GL_LO_BIAS_NV 0x8715
+#define GL_DS_BIAS_NV 0x8716
+#define GL_DT_BIAS_NV 0x8717
+#define GL_MAGNITUDE_BIAS_NV 0x8718
+#define GL_VIBRANCE_BIAS_NV 0x8719
+#define GL_TEXTURE_BORDER_VALUES_NV 0x871A
+#define GL_TEXTURE_HI_SIZE_NV 0x871B
+#define GL_TEXTURE_LO_SIZE_NV 0x871C
+#define GL_TEXTURE_DS_SIZE_NV 0x871D
+#define GL_TEXTURE_DT_SIZE_NV 0x871E
+#define GL_TEXTURE_MAG_SIZE_NV 0x871F
+#define GL_NV_texture_shader2 1
+#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA
+#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB
+#define GL_DSDT_MAG_INTENSITY_NV 0x86DC
+#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF
+#define GL_HILO_NV 0x86F4
+#define GL_DSDT_NV 0x86F5
+#define GL_DSDT_MAG_NV 0x86F6
+#define GL_DSDT_MAG_VIB_NV 0x86F7
+#define GL_HILO16_NV 0x86F8
+#define GL_SIGNED_HILO_NV 0x86F9
+#define GL_SIGNED_HILO16_NV 0x86FA
+#define GL_SIGNED_RGBA_NV 0x86FB
+#define GL_SIGNED_RGBA8_NV 0x86FC
+#define GL_SIGNED_RGB_NV 0x86FE
+#define GL_SIGNED_RGB8_NV 0x86FF
+#define GL_SIGNED_LUMINANCE_NV 0x8701
+#define GL_SIGNED_LUMINANCE8_NV 0x8702
+#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
+#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
+#define GL_SIGNED_ALPHA_NV 0x8705
+#define GL_SIGNED_ALPHA8_NV 0x8706
+#define GL_SIGNED_INTENSITY_NV 0x8707
+#define GL_SIGNED_INTENSITY8_NV 0x8708
+#define GL_DSDT8_NV 0x8709
+#define GL_DSDT8_MAG8_NV 0x870A
+#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
+#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
+#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
+#define GL_NV_texture_shader3 1
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853
+#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854
+#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857
+#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858
+#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859
+#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A
+#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B
+#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C
+#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D
+#define GL_HILO8_NV 0x885E
+#define GL_SIGNED_HILO8_NV 0x885F
+#define GL_FORCE_BLUE_TO_ONE_NV 0x8860
+#define GL_NV_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_NV 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E
+#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F
+#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520
+#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521
+#define GL_NV_vertex_array_range2 1
+#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533
+#define GL_NV_vertex_program 1
+#define GL_VERTEX_PROGRAM_NV 0x8620
+#define GL_VERTEX_STATE_PROGRAM_NV 0x8621
+#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623
+#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624
+#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625
+#define GL_CURRENT_ATTRIB_NV 0x8626
+#define GL_PROGRAM_LENGTH_NV 0x8627
+#define GL_PROGRAM_STRING_NV 0x8628
+#define GL_MODELVIEW_PROJECTION_NV 0x8629
+#define GL_IDENTITY_NV 0x862A
+#define GL_INVERSE_NV 0x862B
+#define GL_TRANSPOSE_NV 0x862C
+#define GL_INVERSE_TRANSPOSE_NV 0x862D
+#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E
+#define GL_MAX_TRACK_MATRICES_NV 0x862F
+#define GL_MATRIX0_NV 0x8630
+#define GL_MATRIX1_NV 0x8631
+#define GL_MATRIX2_NV 0x8632
+#define GL_MATRIX3_NV 0x8633
+#define GL_MATRIX4_NV 0x8634
+#define GL_MATRIX5_NV 0x8635
+#define GL_MATRIX6_NV 0x8636
+#define GL_MATRIX7_NV 0x8637
+#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640
+#define GL_CURRENT_MATRIX_NV 0x8641
+#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643
+#define GL_PROGRAM_PARAMETER_NV 0x8644
+#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645
+#define GL_PROGRAM_TARGET_NV 0x8646
+#define GL_PROGRAM_RESIDENT_NV 0x8647
+#define GL_TRACK_MATRIX_NV 0x8648
+#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649
+#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A
+#define GL_PROGRAM_ERROR_POSITION_NV 0x864B
+#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650
+#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651
+#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652
+#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653
+#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654
+#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655
+#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656
+#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657
+#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658
+#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659
+#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A
+#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B
+#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C
+#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D
+#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E
+#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F
+#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660
+#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661
+#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662
+#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663
+#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664
+#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665
+#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666
+#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667
+#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668
+#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669
+#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A
+#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B
+#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C
+#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D
+#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E
+#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F
+#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670
+#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671
+#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672
+#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673
+#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674
+#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675
+#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676
+#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677
+#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678
+#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679
+#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A
+#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B
+#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C
+#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D
+#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E
+#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F
+#define GL_NV_vertex_program1_1 1
+#define GL_NV_vertex_program2 1
+#define GL_NV_vertex_program2_option 1
+#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4
+#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5
+#define GL_NV_vertex_program3 1
+#define GL_OML_interlace 1
+#define GL_INTERLACE_OML 0x8980
+#define GL_INTERLACE_READ_OML 0x8981
+#define GL_OML_resample 1
+#define GL_PACK_RESAMPLE_OML 0x8984
+#define GL_UNPACK_RESAMPLE_OML 0x8985
+#define GL_RESAMPLE_REPLICATE_OML 0x8986
+#define GL_RESAMPLE_ZERO_FILL_OML 0x8987
+#define GL_RESAMPLE_AVERAGE_OML 0x8988
+#define GL_RESAMPLE_DECIMATE_OML 0x8989
+#define GL_OML_subsample 1
+#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982
+#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983
+#define GL_PGI_misc_hints 1
+#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 107000
+#define GL_CONSERVE_MEMORY_HINT_PGI 107005
+#define GL_RECLAIM_MEMORY_HINT_PGI 107006
+#define GL_NATIVE_GRAPHICS_HANDLE_PGI 107010
+#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 107011
+#define GL_NATIVE_GRAPHICS_END_HINT_PGI 107012
+#define GL_ALWAYS_FAST_HINT_PGI 107020
+#define GL_ALWAYS_SOFT_HINT_PGI 107021
+#define GL_ALLOW_DRAW_OBJ_HINT_PGI 107022
+#define GL_ALLOW_DRAW_WIN_HINT_PGI 107023
+#define GL_ALLOW_DRAW_FRG_HINT_PGI 107024
+#define GL_ALLOW_DRAW_MEM_HINT_PGI 107025
+#define GL_STRICT_DEPTHFUNC_HINT_PGI 107030
+#define GL_STRICT_LIGHTING_HINT_PGI 107031
+#define GL_STRICT_SCISSOR_HINT_PGI 107032
+#define GL_FULL_STIPPLE_HINT_PGI 107033
+#define GL_CLIP_NEAR_HINT_PGI 107040
+#define GL_CLIP_FAR_HINT_PGI 107041
+#define GL_WIDE_LINE_HINT_PGI 107042
+#define GL_BACK_NORMALS_HINT_PGI 107043
+#define GL_PGI_vertex_hints 1
+#define GL_VERTEX23_BIT_PGI 0x00000004
+#define GL_VERTEX4_BIT_PGI 0x00000008
+#define GL_COLOR3_BIT_PGI 0x00010000
+#define GL_COLOR4_BIT_PGI 0x00020000
+#define GL_EDGEFLAG_BIT_PGI 0x00040000
+#define GL_INDEX_BIT_PGI 0x00080000
+#define GL_MAT_AMBIENT_BIT_PGI 0x00100000
+#define GL_VERTEX_DATA_HINT_PGI 107050
+#define GL_VERTEX_CONSISTENT_HINT_PGI 107051
+#define GL_MATERIAL_SIDE_HINT_PGI 107052
+#define GL_MAX_VERTEX_HINT_PGI 107053
+#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000
+#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000
+#define GL_MAT_EMISSION_BIT_PGI 0x00800000
+#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000
+#define GL_MAT_SHININESS_BIT_PGI 0x02000000
+#define GL_MAT_SPECULAR_BIT_PGI 0x04000000
+#define GL_NORMAL_BIT_PGI 0x08000000
+#define GL_TEXCOORD1_BIT_PGI 0x10000000
+#define GL_TEXCOORD2_BIT_PGI 0x20000000
+#define GL_TEXCOORD3_BIT_PGI 0x40000000
+#define GL_TEXCOORD4_BIT_PGI 0x80000000
+#define GL_REND_screen_coordinates 1
+#define GL_SCREEN_COORDINATES_REND 0x8490
+#define GL_INVERTED_SCREEN_W_REND 0x8491
+#define GL_S3_s3tc 1
+#define GL_RGB_S3TC 0x83A0
+#define GL_RGB4_S3TC 0x83A1
+#define GL_RGBA_S3TC 0x83A2
+#define GL_RGBA4_S3TC 0x83A3
+#define GL_RGBA_DXT5_S3TC 0x83A4
+#define GL_RGBA4_DXT5_S3TC 0x83A5
+#define GL_SGIS_color_range 1
+#define GL_EXTENDED_RANGE_SGIS 0x85A5
+#define GL_MIN_RED_SGIS 0x85A6
+#define GL_MAX_RED_SGIS 0x85A7
+#define GL_MIN_GREEN_SGIS 0x85A8
+#define GL_MAX_GREEN_SGIS 0x85A9
+#define GL_MIN_BLUE_SGIS 0x85AA
+#define GL_MAX_BLUE_SGIS 0x85AB
+#define GL_MIN_ALPHA_SGIS 0x85AC
+#define GL_MAX_ALPHA_SGIS 0x85AD
+#define GL_SGIS_detail_texture 1
+#define GL_SGIS_fog_function 1
+#define GL_SGIS_generate_mipmap 1
+#define GL_GENERATE_MIPMAP_SGIS 0x8191
+#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
+#define GL_SGIS_multisample 1
+#define GL_MULTISAMPLE_SGIS 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F
+#define GL_SAMPLE_MASK_SGIS 0x80A0
+#define GL_1PASS_SGIS 0x80A1
+#define GL_2PASS_0_SGIS 0x80A2
+#define GL_2PASS_1_SGIS 0x80A3
+#define GL_4PASS_0_SGIS 0x80A4
+#define GL_4PASS_1_SGIS 0x80A5
+#define GL_4PASS_2_SGIS 0x80A6
+#define GL_4PASS_3_SGIS 0x80A7
+#define GL_SAMPLE_BUFFERS_SGIS 0x80A8
+#define GL_SAMPLES_SGIS 0x80A9
+#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA
+#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB
+#define GL_SAMPLE_PATTERN_SGIS 0x80AC
+#define GL_MULTISAMPLE_BIT_EXT 0x20000000
+#define GL_SGIS_pixel_texture 1
+#define GL_SGIS_sharpen_texture 1
+#define GL_SGIS_texture4D 1
+#define GL_SGIS_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_SGIS 0x812D
+#define GL_SGIS_texture_edge_clamp 1
+#define GL_CLAMP_TO_EDGE_SGIS 0x812F
+#define GL_SGIS_texture_filter4 1
+#define GL_SGIS_texture_lod 1
+#define GL_TEXTURE_MIN_LOD_SGIS 0x813A
+#define GL_TEXTURE_MAX_LOD_SGIS 0x813B
+#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C
+#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D
+#define GL_SGIS_texture_select 1
+#define GL_SGIX_async 1
+#define GL_ASYNC_MARKER_SGIX 0x8329
+#define GL_SGIX_async_histogram 1
+#define GL_ASYNC_HISTOGRAM_SGIX 0x832C
+#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D
+#define GL_SGIX_async_pixel 1
+#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C
+#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D
+#define GL_ASYNC_READ_PIXELS_SGIX 0x835E
+#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F
+#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360
+#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361
+#define GL_SGIX_blend_alpha_minmax 1
+#define GL_ALPHA_MIN_SGIX 0x8320
+#define GL_ALPHA_MAX_SGIX 0x8321
+#define GL_SGIX_clipmap 1
+#define GL_SGIX_depth_texture 1
+#define GL_DEPTH_COMPONENT16_SGIX 0x81A5
+#define GL_DEPTH_COMPONENT24_SGIX 0x81A6
+#define GL_DEPTH_COMPONENT32_SGIX 0x81A7
+#define GL_SGIX_flush_raster 1
+#define GL_SGIX_fog_offset 1
+#define GL_FOG_OFFSET_SGIX 0x8198
+#define GL_FOG_OFFSET_VALUE_SGIX 0x8199
+#define GL_SGIX_fog_texture 1
+#define GL_TEXTURE_FOG_SGIX 0
+#define GL_FOG_PATCHY_FACTOR_SGIX 0
+#define GL_FRAGMENT_FOG_SGIX 0
+#define GL_SGIX_fragment_specular_lighting 1
+#define GL_SGIX_framezoom 1
+#define GL_SGIX_interlace 1
+#define GL_INTERLACE_SGIX 0x8094
+#define GL_SGIX_ir_instrument1 1
+#define GL_SGIX_list_priority 1
+#define GL_SGIX_pixel_texture 1
+#define GL_SGIX_pixel_texture_bits 1
+#define GL_SGIX_reference_plane 1
+#define GL_SGIX_resample 1
+#define GL_PACK_RESAMPLE_SGIX 0x842E
+#define GL_UNPACK_RESAMPLE_SGIX 0x842F
+#define GL_RESAMPLE_DECIMATE_SGIX 0x8430
+#define GL_RESAMPLE_REPLICATE_SGIX 0x8433
+#define GL_RESAMPLE_ZERO_FILL_SGIX 0x8434
+#define GL_SGIX_shadow 1
+#define GL_TEXTURE_COMPARE_SGIX 0x819A
+#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B
+#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C
+#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D
+#define GL_SGIX_shadow_ambient 1
+#define GL_SHADOW_AMBIENT_SGIX 0x80BF
+#define GL_SGIX_sprite 1
+#define GL_SGIX_tag_sample_buffer 1
+#define GL_SGIX_texture_add_env 1
+#define GL_SGIX_texture_coordinate_clamp 1
+#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369
+#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A
+#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B
+#define GL_SGIX_texture_lod_bias 1
+#define GL_SGIX_texture_multi_buffer 1
+#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E
+#define GL_SGIX_texture_range 1
+#define GL_RGB_SIGNED_SGIX 0x85E0
+#define GL_RGBA_SIGNED_SGIX 0x85E1
+#define GL_ALPHA_SIGNED_SGIX 0x85E2
+#define GL_LUMINANCE_SIGNED_SGIX 0x85E3
+#define GL_INTENSITY_SIGNED_SGIX 0x85E4
+#define GL_LUMINANCE_ALPHA_SIGNED_SGIX 0x85E5
+#define GL_RGB16_SIGNED_SGIX 0x85E6
+#define GL_RGBA16_SIGNED_SGIX 0x85E7
+#define GL_ALPHA16_SIGNED_SGIX 0x85E8
+#define GL_LUMINANCE16_SIGNED_SGIX 0x85E9
+#define GL_INTENSITY16_SIGNED_SGIX 0x85EA
+#define GL_LUMINANCE16_ALPHA16_SIGNED_SGIX 0x85EB
+#define GL_RGB_EXTENDED_RANGE_SGIX 0x85EC
+#define GL_RGBA_EXTENDED_RANGE_SGIX 0x85ED
+#define GL_ALPHA_EXTENDED_RANGE_SGIX 0x85EE
+#define GL_LUMINANCE_EXTENDED_RANGE_SGIX 0x85EF
+#define GL_INTENSITY_EXTENDED_RANGE_SGIX 0x85F0
+#define GL_LUMINANCE_ALPHA_EXTENDED_RANGE_SGIX 0x85F1
+#define GL_RGB16_EXTENDED_RANGE_SGIX 0x85F2
+#define GL_RGBA16_EXTENDED_RANGE_SGIX 0x85F3
+#define GL_ALPHA16_EXTENDED_RANGE_SGIX 0x85F4
+#define GL_LUMINANCE16_EXTENDED_RANGE_SGIX 0x85F5
+#define GL_INTENSITY16_EXTENDED_RANGE_SGIX 0x85F6
+#define GL_LUMINANCE16_ALPHA16_EXTENDED_RANGE_SGIX 0x85F7
+#define GL_MIN_LUMINANCE_SGIS 0x85F8
+#define GL_MAX_LUMINANCE_SGIS 0x85F9
+#define GL_MIN_INTENSITY_SGIS 0x85FA
+#define GL_MAX_INTENSITY_SGIS 0x85FB
+#define GL_SGIX_texture_scale_bias 1
+#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179
+#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A
+#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B
+#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C
+#define GL_SGIX_vertex_preclip 1
+#define GL_VERTEX_PRECLIP_SGIX 0x83EE
+#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF
+#define GL_SGIX_vertex_preclip_hint 1
+#define GL_VERTEX_PRECLIP_SGIX 0x83EE
+#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF
+#define GL_SGIX_ycrcb 1
+#define GL_SGI_color_matrix 1
+#define GL_COLOR_MATRIX_SGI 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB
+#define GL_SGI_color_table 1
+#define GL_COLOR_TABLE_SGI 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2
+#define GL_PROXY_COLOR_TABLE_SGI 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5
+#define GL_COLOR_TABLE_SCALE_SGI 0x80D6
+#define GL_COLOR_TABLE_BIAS_SGI 0x80D7
+#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8
+#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF
+#define GL_SGI_texture_color_table 1
+#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC
+#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD
+#define GL_SUNX_constant_data 1
+#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5
+#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6
+#define GL_SUN_convolution_border_modes 1
+#define GL_WRAP_BORDER_SUN 0x81D4
+#define GL_SUN_global_alpha 1
+#define GL_GLOBAL_ALPHA_SUN 0x81D9
+#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA
+#define GL_SUN_mesh_array 1
+#define GL_QUAD_MESH_SUN 0x8614
+#define GL_TRIANGLE_MESH_SUN 0x8615
+#define GL_SUN_read_video_pixels 1
+#define GL_SUN_slice_accum 1
+#define GL_SLICE_ACCUM_SUN 0x85CC
+#define GL_SUN_triangle_list 1
+#define GL_RESTART_SUN 0x01
+#define GL_REPLACE_MIDDLE_SUN 0x02
+#define GL_REPLACE_OLDEST_SUN 0x03
+#define GL_TRIANGLE_LIST_SUN 0x81D7
+#define GL_REPLACEMENT_CODE_SUN 0x81D8
+#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0
+#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1
+#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2
+#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3
+#define GL_R1UI_V3F_SUN 0x85C4
+#define GL_R1UI_C4UB_V3F_SUN 0x85C5
+#define GL_R1UI_C3F_V3F_SUN 0x85C6
+#define GL_R1UI_N3F_V3F_SUN 0x85C7
+#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8
+#define GL_R1UI_T2F_V3F_SUN 0x85C9
+#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA
+#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB
+#define GL_SUN_vertex 1
+#define GL_WIN_phong_shading 1
+#define GL_PHONG_WIN 0x80EA
+#define GL_PHONG_HINT_WIN 0x80EB
+#define GL_WIN_specular_fog 1
+#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC
+#define GL_WIN_swap_hint 1
+
+#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
+#define WGL_DRAW_TO_WINDOW_ARB 0x2001
+#define WGL_DRAW_TO_BITMAP_ARB 0x2002
+#define WGL_ACCELERATION_ARB 0x2003
+#define WGL_NEED_PALETTE_ARB 0x2004
+#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
+#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
+#define WGL_SWAP_METHOD_ARB 0x2007
+#define WGL_NUMBER_OVERLAYS_ARB 0x2008
+#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
+#define WGL_TRANSPARENT_ARB 0x200A
+#define WGL_SHARE_DEPTH_ARB 0x200C
+#define WGL_SHARE_STENCIL_ARB 0x200D
+#define WGL_SHARE_ACCUM_ARB 0x200E
+#define WGL_SUPPORT_GDI_ARB 0x200F
+#define WGL_SUPPORT_OPENGL_ARB 0x2010
+#define WGL_DOUBLE_BUFFER_ARB 0x2011
+#define WGL_STEREO_ARB 0x2012
+#define WGL_PIXEL_TYPE_ARB 0x2013
+#define WGL_COLOR_BITS_ARB 0x2014
+#define WGL_RED_BITS_ARB 0x2015
+#define WGL_RED_SHIFT_ARB 0x2016
+#define WGL_GREEN_BITS_ARB 0x2017
+#define WGL_GREEN_SHIFT_ARB 0x2018
+#define WGL_BLUE_BITS_ARB 0x2019
+#define WGL_BLUE_SHIFT_ARB 0x201A
+#define WGL_ALPHA_BITS_ARB 0x201B
+#define WGL_ALPHA_SHIFT_ARB 0x201C
+#define WGL_ACCUM_BITS_ARB 0x201D
+#define WGL_ACCUM_RED_BITS_ARB 0x201E
+#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
+#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
+#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
+#define WGL_DEPTH_BITS_ARB 0x2022
+#define WGL_STENCIL_BITS_ARB 0x2023
+#define WGL_AUX_BUFFERS_ARB 0x2024
+#define WGL_NO_ACCELERATION_ARB 0x2025
+#define WGL_GENERIC_ACCELERATION_ARB 0x2026
+#define WGL_FULL_ACCELERATION_ARB 0x2027
+#define WGL_SWAP_EXCHANGE_ARB 0x2028
+#define WGL_SWAP_COPY_ARB 0x2029
+#define WGL_SWAP_UNDEFINED_ARB 0x202A
+#define WGL_TYPE_RGBA_ARB 0x202B
+#define WGL_TYPE_COLORINDEX_ARB 0x202C
+#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
+#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
+#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
+#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
+#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
+
+#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
+#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
+#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
+#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
+#define WGL_PBUFFER_LARGEST_ARB 0x2033
+#define WGL_PBUFFER_WIDTH_ARB 0x2034
+#define WGL_PBUFFER_HEIGHT_ARB 0x2035
+#define WGL_PBUFFER_LOST_ARB 0x2036
+
+#define WGL_SAMPLE_BUFFERS_ARB 0x2041
+#define WGL_SAMPLES_ARB 0x2042
+
+#endif
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -2933,19 +2933,17 @@ nsCanvasRenderingContext2D::DrawImage()
     if (!ConvertJSValToXPCObject(getter_AddRefs(imgElt),
                                  NS_GET_IID(nsIDOMElement),
                                  ctx, argv[0]))
         return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
 
     gfxMatrix matrix;
     nsRefPtr<gfxPattern> pattern;
     nsRefPtr<gfxPath> path;
-#ifdef WINCE
-    nsRefPtr<gfxASurface> currentSurface;
-#endif
+
     nsLayoutUtils::SurfaceFromElementResult res =
         nsLayoutUtils::SurfaceFromElement(imgElt);
     if (!res.mSurface)
         return NS_ERROR_NOT_AVAILABLE;
 
 #ifndef WINCE
     // On non-CE, force a copy if we're using drawImage with our destination
     // as a source to work around some Cairo self-copy semantics issues.
@@ -3021,39 +3019,40 @@ nsCanvasRenderingContext2D::DrawImage()
         // XXX ERRMSG we need to report an error to developers here! (bug 329026)
         rv = NS_ERROR_DOM_INDEX_SIZE_ERR;
         goto FINISH;
     }
     
     matrix.Translate(gfxPoint(sx, sy));
     matrix.Scale(sw/dw, sh/dh);
 #ifdef WINCE
-    currentSurface = getter_AddRefs(mThebes->CurrentSurface());
-
     /* cairo doesn't have consistent semantics for drawing a surface onto
      * itself. Specifically, pixman will not preserve the contents when doing
      * the copy. So to get the desired semantics a temporary copy would be needed.
      * Instead we optimize opaque self copies here */
-    if (currentSurface == imgsurf) {
-        if (imgsurf->GetType() == gfxASurface::SurfaceTypeImage) {
-            gfxImageSurface *surf = static_cast<gfxImageSurface*>(imgsurf.get());
-            gfxContext::GraphicsOperator op = mThebes->CurrentOperator();
-            PRBool opaque, unscaled;
-
-            opaque  = surf->Format() == gfxASurface::ImageFormatARGB32 &&
-                (op == gfxContext::OPERATOR_SOURCE);
-            opaque |= surf->Format() == gfxASurface::ImageFormatRGB24  &&
-                (op == gfxContext::OPERATOR_SOURCE || op == gfxContext::OPERATOR_OVER);
-
-            unscaled = sw == dw && sh == dh;
-
-            if (opaque && unscaled) {
-                bitblt(surf, sx, sy, sw, sh, dx, dy);
-                rv = NS_OK;
-                goto FINISH;
+    {
+        nsRefPtr<gfxASurface> csurf = mThebes->CurrentSurface();
+        if (csurf == imgsurf) {
+            if (imgsurf->GetType() == gfxASurface::SurfaceTypeImage) {
+                gfxImageSurface *surf = static_cast<gfxImageSurface*>(imgsurf.get());
+                gfxContext::GraphicsOperator op = mThebes->CurrentOperator();
+                PRBool opaque, unscaled;
+
+                opaque  = surf->Format() == gfxASurface::ImageFormatARGB32 &&
+                    (op == gfxContext::OPERATOR_SOURCE);
+                opaque |= surf->Format() == gfxASurface::ImageFormatRGB24  &&
+                    (op == gfxContext::OPERATOR_SOURCE || op == gfxContext::OPERATOR_OVER);
+
+                unscaled = sw == dw && sh == dh;
+
+                if (opaque && unscaled) {
+                    bitblt(surf, sx, sy, sw, sh, dx, dy);
+                    rv = NS_OK;
+                    goto FINISH;
+                }
             }
         }
     }
 #endif
 
     pattern = new gfxPattern(imgsurf);
     pattern->SetMatrix(matrix);
 
@@ -3242,32 +3241,16 @@ nsCanvasRenderingContext2D::ConvertJSVal
       WrapJS(aContext, JSVAL_TO_OBJECT(aValue), aIID, (void**)aSupports);
 
     return NS_SUCCEEDED(rv);
   }
 
   return JS_FALSE;
 }
 
-/* Check that the rect [x,y,w,h] is a valid subrect of [0,0,realWidth,realHeight]
- * without overflowing any integers and the like.
- */
-PRBool
-CheckSaneSubrectSize (PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h, PRInt32 realWidth, PRInt32 realHeight)
-{
-    if (w <= 0 || h <= 0 || x < 0 || y < 0)
-        return PR_FALSE;
-
-    if (x >= realWidth  || w > (realWidth - x) ||
-        y >= realHeight || h > (realHeight - y))
-        return PR_FALSE;
-
-    return PR_TRUE;
-}
-
 static void
 FlushLayoutForTree(nsIDOMWindow* aWindow)
 {
     nsCOMPtr<nsPIDOMWindow> piWin = do_QueryInterface(aWindow);
     if (!piWin)
         return;
 
     // Note that because FlushPendingNotifications flushes parents, this
@@ -3760,23 +3743,26 @@ nsCanvasRenderingContext2D::CreateImageD
     PRUint32 argc;
     jsval *argv = nsnull;
 
     ncc->GetArgc(&argc);
     ncc->GetArgvPtr(&argv);
 
     JSAutoRequest ar(ctx);
 
-    int32 w, h;
-    if (!JS_ConvertArguments (ctx, argc, argv, "jj", &w, &h))
+    int32 width, height;
+    if (!JS_ConvertArguments (ctx, argc, argv, "jj", &width, &height))
         return NS_ERROR_DOM_SYNTAX_ERR;
 
-    if (w <= 0 || h <= 0)
+    if (width <= 0 || height <= 0)
         return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
+    PRUint32 w = (PRUint32) width;
+    PRUint32 h = (PRUint32) height;
+
     // check for overflow when calculating len
     PRUint32 len0 = w * h;
     if (len0 / w != (PRUint32) h)
         return NS_ERROR_DOM_INDEX_SIZE_ERR;
     PRUint32 len = len0 * 4;
     if (len / 4 != len0)
         return NS_ERROR_DOM_INDEX_SIZE_ERR;
 
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/nsCanvasRenderingContextGL.cpp
@@ -0,0 +1,1071 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Vladimir Vukicevic <vladimir@pobox.com> (original author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "prmem.h"
+#include "prlog.h"
+
+#include "nsCanvasRenderingContextGL.h"
+
+#include "nsICanvasRenderingContextGL.h"
+
+#include "nsIRenderingContext.h"
+
+#include "nsICanvasRenderingContextInternal.h"
+#include "nsIDOMHTMLCanvasElement.h"
+#include "nsIView.h"
+#include "nsIViewManager.h"
+
+#include "nsIDocument.h"
+
+#include "nsTransform2D.h"
+
+#include "nsIScriptSecurityManager.h"
+#include "nsISecurityCheckedComponent.h"
+
+#include "imgIRequest.h"
+#include "imgIContainer.h"
+#include "gfxIImageFrame.h"
+#include "nsIDOMHTMLCanvasElement.h"
+#include "nsICanvasElement.h"
+#include "nsIDOMHTMLImageElement.h"
+#include "nsIImageLoadingContent.h"
+#include "nsIInterfaceRequestorUtils.h"
+#include "nsIImage.h"
+#include "nsDOMError.h"
+#include "nsIJSRuntimeService.h"
+
+#include "imgIEncoder.h"
+
+#include "nsIPrefService.h"
+
+#include "nsIClassInfoImpl.h"
+
+#include "nsComponentManagerUtils.h"
+#include "nsServiceManagerUtils.h"
+
+#include "nsDOMError.h"
+
+#include "nsIXPConnect.h"
+#include "jsapi.h"
+#include "jsarray.h"
+
+#include "nsIDOMDocument.h"
+#include "nsIDOMDocumentEvent.h"
+#include "nsIDOMEvent.h"
+#include "nsIDOMEventTarget.h"
+#include "nsIPrivateDOMEvent.h"
+#include "nsIDOMDataContainerEvent.h"
+
+#include "nsLayoutUtils.h"
+
+#ifdef ARGH_NEED_SEPARATE_SERVICE
+#include "nsIContentURIGrouper.h"
+#include "nsIContentPrefService.h"
+#endif
+
+// we're hoping that something is setting us up the remap
+
+#include "gfxContext.h"
+#include "gfxASurface.h"
+
+#ifdef XP_WIN
+#include "gfxWindowsSurface.h"
+#endif
+
+#ifdef XP_MACOSX
+#include "gfxQuartzImageSurface.h"
+#endif
+
+#ifdef MOZ_X11
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include "cairo-xlib.h"
+#endif
+
+// can't do this due to linkage
+#undef MOZ_MEDIA
+
+#ifndef GL_FRAMEBUFFER
+#define GL_FRAMEBUFFER 0x8D40
+#endif
+
+nsIXPConnect *gXPConnect = nsnull;
+JSRuntime *gScriptRuntime = nsnull;
+nsIJSRuntimeService *gJSRuntimeService = nsnull;
+
+// CanvasGLBuffer
+NS_DECL_CLASSINFO(CanvasGLBuffer)
+NS_IMPL_ADDREF(CanvasGLBuffer)
+NS_IMPL_RELEASE(CanvasGLBuffer)
+
+NS_IMPL_CI_INTERFACE_GETTER1(CanvasGLBuffer, nsICanvasRenderingContextGLBuffer)
+
+NS_INTERFACE_MAP_BEGIN(CanvasGLBuffer)
+  NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextGLBuffer)
+  NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
+  NS_INTERFACE_MAP_ENTRY(nsICanvasGLBuffer)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICanvasRenderingContextGLBuffer)
+  NS_IMPL_QUERY_CLASSINFO(CanvasGLBuffer)
+NS_INTERFACE_MAP_END
+
+// CanvasGLTexture
+NS_DECL_CLASSINFO(CanvasGLTexture)
+NS_IMPL_ADDREF(CanvasGLTexture)
+NS_IMPL_RELEASE(CanvasGLTexture)
+
+NS_IMPL_CI_INTERFACE_GETTER1(CanvasGLTexture, nsICanvasRenderingContextGLTexture)
+
+NS_INTERFACE_MAP_BEGIN(CanvasGLTexture)
+  NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextGLTexture)
+  NS_INTERFACE_MAP_ENTRY(nsICanvasGLTexture)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICanvasRenderingContextGLTexture)
+  NS_IMPL_QUERY_CLASSINFO(CanvasGLTexture)
+NS_INTERFACE_MAP_END
+
+/**
+ ** CanvasGLBuffer
+ **/
+
+static int bufferCount = 0;
+
+CanvasGLBuffer::CanvasGLBuffer(nsCanvasRenderingContextGLPrivate *owner)
+    : mDisposed(PR_TRUE),
+      mLength(0), mSize(0), mType(0), mUsage(GL_STATIC_DRAW),
+      mBufferID(0), mMaxUShort(0), mMaxUShortComputed(false)
+{
+    owner->GetWeakReference(getter_AddRefs(mOwnerContext));
+
+    gl = owner->gl;
+
+    bufferCount++;
+    //fprintf (stderr, "VVVV Created; Buffers now: %d\n", bufferCount); fflush(stderr);
+}
+
+CanvasGLBuffer::~CanvasGLBuffer()
+{
+    Dispose();
+
+    --bufferCount;
+    //fprintf (stderr, "VVVV Released; Buffers now: %d\n", bufferCount); fflush(stderr);
+}
+
+/* nsISecurityCheckedComponent bits */
+
+static char* cloneAllAccess()
+{
+    static const char allAccess[] = "allAccess";
+    return (char*)nsMemory::Clone(allAccess, sizeof(allAccess));
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::CanCreateWrapper(const nsIID* iid, char **_retval) {
+    *_retval = cloneAllAccess();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::CanCallMethod(const nsIID *iid, const PRUnichar *methodName, char **_retval) {
+    *_retval = cloneAllAccess();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::CanGetProperty(const nsIID *iid, const PRUnichar *propertyName, char **_retval) {
+    *_retval = cloneAllAccess();
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::CanSetProperty(const nsIID *iid, const PRUnichar *propertyName, char **_retval) {
+    *_retval = cloneAllAccess();
+    return NS_OK;
+}
+
+nsresult
+CanvasGLBuffer::Init(PRUint32 usage,
+                     PRUint32 size,
+                     PRUint32 type,
+                     JSContext *ctx,
+                     JSObject *arrayObj,
+                     jsuint arrayLen)
+{
+    nsresult rv;
+
+    //fprintf (stderr, "VVVV CanvasGLBuffer::Init\n");
+
+    if (!mDisposed)
+        Dispose();
+
+    if (usage != GL_STATIC_DRAW &&
+        usage != GL_STREAM_DRAW &&
+        usage != GL_DYNAMIC_DRAW)
+        return NS_ERROR_INVALID_ARG;
+
+    rv = mSimpleBuffer.InitFromJSArray(type, size, ctx, arrayObj, arrayLen);
+    if (NS_FAILED(rv))
+        return rv;
+
+    mUsage = usage;
+    mSize = size;
+    mType = type;
+    mLength = arrayLen;
+
+    mMaxUShortComputed = false;
+    
+    mBufferID = 0;
+
+    mDisposed = PR_FALSE;
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::Dispose()
+{
+    if (mDisposed)
+        return NS_OK;
+
+    if (mBufferID) {
+        nsCOMPtr<nsICanvasRenderingContextInternal> ctx = do_QueryReferent(mOwnerContext);
+        if (ctx) {
+            nsCanvasRenderingContextGLPrivate *priv = (nsCanvasRenderingContextGLPrivate*) ctx.get();
+            priv->MakeContextCurrent();
+
+            gl->fDeleteBuffers(1, &mBufferID);
+            mBufferID = 0;
+        }
+    }
+
+    mSimpleBuffer.Release();
+
+    mDisposed = PR_TRUE;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::GetOwnerContext(nsICanvasRenderingContextGL **retval)
+{
+    nsCOMPtr<nsICanvasRenderingContextInternal> ctx = do_QueryReferent(mOwnerContext);
+    if (ctx) {
+        nsCanvasRenderingContextGLPrivate *priv = (nsCanvasRenderingContextGLPrivate*) ctx.get();
+        *retval = priv->GetSelf();
+    } else {
+        *retval = nsnull;
+    }
+
+    NS_IF_ADDREF(*retval);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::GetDisposed(PRBool *retval)
+{
+    *retval = mDisposed;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::GetUsage(PRUint32 *usage)
+{
+    if (mDisposed)
+        return NS_ERROR_FAILURE;
+
+    *usage = mUsage;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::GetLength(PRUint32 *retval)
+{
+    if (mDisposed)
+        return NS_ERROR_FAILURE;
+
+    *retval = mLength;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLBuffer::GetType(PRUint32 *retval)
+{
+    if (mDisposed)
+        return NS_ERROR_FAILURE;
+
+    *retval = mType;
+    return NS_OK;
+}
+
+/**
+ ** CanvasGLTexture
+ **/
+
+CanvasGLTexture::CanvasGLTexture(nsCanvasRenderingContextGLPrivate *owner)
+    : mDisposed(PR_FALSE),
+      //mGlitzTextureSurface(nsnull), mGlitzTextureObject(nsnull),
+      mWidth(0), mHeight(0)
+{
+    owner->GetWeakReference(getter_AddRefs(mOwnerContext));
+
+    gl = owner->gl;
+}
+
+CanvasGLTexture::~CanvasGLTexture()
+{
+    Dispose();
+}
+
+nsresult
+CanvasGLTexture::Init()
+{
+    return NS_OK;
+}
+
+nsresult
+CanvasGLTexture::Dispose()
+{
+    if (mDisposed)
+        return NS_OK;
+
+    mDisposed = PR_TRUE;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::GetDisposed(PRBool *retval)
+{
+    *retval = mDisposed;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::GetOwnerContext(nsICanvasRenderingContextGL **retval)
+{
+    nsCOMPtr<nsICanvasRenderingContextInternal> ctx = do_QueryReferent(mOwnerContext);
+    if (ctx) {
+        nsCanvasRenderingContextGLPrivate *priv = (nsCanvasRenderingContextGLPrivate*) ctx.get();
+        *retval = priv->GetSelf();
+    } else {
+        *retval = nsnull;
+    }
+
+    NS_IF_ADDREF(*retval);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::GetTarget(PRUint32 *aResult)
+{
+    //*aResult = glitz_texture_object_get_target (mGlitzTextureObject);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::GetWidth(PRUint32 *aWidth)
+{
+    *aWidth = mWidth;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::GetHeight(PRUint32 *aHeight)
+{
+    *aHeight = mHeight;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::SetFilter(PRUint32 filterType, PRUint32 filterMode)
+{
+    if (filterType < 0 || filterType > 1 ||
+        filterMode < 0 || filterMode > 1)
+    {
+        return NS_ERROR_DOM_SYNTAX_ERR;
+    }
+
+    //glitz_texture_object_set_filter (mGlitzTextureObject, (glitz_texture_filter_type_t)filterType, (glitz_texture_filter_t)filterMode);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+CanvasGLTexture::SetWrap(PRUint32 wrapType, PRUint32 wrapMode)
+{
+    if (wrapType != GL_TEXTURE_WRAP_S &&
+        wrapType != GL_TEXTURE_WRAP_T)
+        return NS_ERROR_DOM_SYNTAX_ERR;
+
+    if (wrapMode != GL_CLAMP_TO_EDGE &&
+        wrapMode != GL_REPEAT &&
+        wrapMode != GL_MIRRORED_REPEAT)
+        return NS_ERROR_DOM_SYNTAX_ERR;
+
+    //glitz_texture_object_set_wrap (mGlitzTextureObject, (glitz_texture_wrap_type_t)wrapType, (glitz_texture_wrap_t)wrapMode);
+    return NS_OK;
+}
+
+/*
+ * these got removed accidentally in bug 495499.  We make them just return false here and
+ * take the slow path until we get that fixed up.
+ */
+
+#define FOO(_x,_y) JSBool _x (JSContext *cx, JSObject *obj, jsuint offset, jsuint count, _y *dest) { return 0; }
+
+FOO(js_ArrayToJSUint8Buffer, JSUint8);
+FOO(js_ArrayToJSUint16Buffer, JSUint16);
+FOO(js_ArrayToJSUint32Buffer, JSUint32);
+FOO(js_ArrayToJSInt8Buffer, JSInt8);
+FOO(js_ArrayToJSInt16Buffer, JSInt16);
+FOO(js_ArrayToJSInt32Buffer, JSInt32);
+FOO(js_ArrayToJSDoubleBuffer, jsdouble);
+
+
+PRBool
+SimpleBuffer::InitFromJSArray(PRUint32 typeParam,
+                              PRUint32 sizeParam,
+                              JSContext *ctx,
+                              JSObject *arrayObj,
+                              jsuint arrayLen)
+{
+    if (typeParam == GL_SHORT) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        short *ptr = (short*) data;
+
+        if (!js_ArrayToJSInt16Buffer(ctx, arrayObj, 0, arrayLen, ptr)) {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                int32 iv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToECMAInt32(ctx, jv, &iv);
+                *ptr++ = (short) iv;
+            }
+        }
+    } else if (typeParam == GL_FLOAT) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        float *ptr = (float*) data;
+        double *tmpd = new double[arrayLen];
+        if (js_ArrayToJSDoubleBuffer(ctx, arrayObj, 0, arrayLen, tmpd)) {
+            for (PRUint32 i = 0; i < arrayLen; i++)
+                ptr[i] = (float) tmpd[i];
+        } else {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                jsdouble dv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToNumber(ctx, jv, &dv);
+                *ptr++ = (float) dv;
+            }
+        }
+        delete [] tmpd;
+    } else if (typeParam == GL_UNSIGNED_BYTE) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        unsigned char *ptr = (unsigned char*) data;
+        if (!js_ArrayToJSUint8Buffer(ctx, arrayObj, 0, arrayLen, ptr)) {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                uint32 iv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToECMAUint32(ctx, jv, &iv);
+                *ptr++ = (unsigned char) iv;
+            }
+        }
+    } else if (typeParam == GL_UNSIGNED_SHORT) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        PRUint16 *ptr = (PRUint16*) data;
+        if (!js_ArrayToJSUint16Buffer(ctx, arrayObj, 0, arrayLen, ptr)) {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                uint32 iv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToECMAUint32(ctx, jv, &iv);
+                *ptr++ = (unsigned short) iv;
+            }
+        }
+    } else if (typeParam == GL_UNSIGNED_INT) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        PRUint32 *ptr = (PRUint32*) data;
+        if (!js_ArrayToJSUint32Buffer(ctx, arrayObj, 0, arrayLen, ptr)) {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                uint32 iv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToECMAUint32(ctx, jv, &iv);
+                *ptr++ = iv;
+            }
+        }
+    } else if (typeParam == GL_INT) {
+        Prepare(typeParam, sizeParam, arrayLen);
+        PRInt32 *ptr = (PRInt32*) data;
+        if (!js_ArrayToJSInt32Buffer(ctx, arrayObj, 0, arrayLen, ptr)) {
+            for (PRUint32 i = 0; i < arrayLen; i++) {
+                jsval jv;
+                int32 iv;
+                ::JS_GetElement(ctx, arrayObj, i, &jv);
+                ::JS_ValueToECMAInt32(ctx, jv, &iv);
+                *ptr++ = iv;
+            }
+        }
+    } else {
+        return PR_FALSE;
+    }
+
+    return PR_TRUE;
+}
+
+void
+nsCanvasRenderingContextGLPrivate::MakeContextCurrent()
+{
+    mGLPbuffer->MakeContextCurrent();
+}
+
+void
+nsCanvasRenderingContextGLPrivate::LostCurrentContext(void *closure)
+{
+    //nsCanvasRenderingContextGLPrivate* self = (nsCanvasRenderingContextGLPrivate*) closure;
+}
+
+//
+// nsICanvasRenderingContextInternal
+//
+
+NS_IMETHODIMP
+nsCanvasRenderingContextGLPrivate::SetCanvasElement(nsICanvasElement* aParentCanvas)
+{
+    nsresult rv;
+
+    if (aParentCanvas == nsnull) {
+        // we get this on shutdown; we should do some more cleanup here,
+        // but instead we just let our destructor do it.
+        return NS_OK;
+    }
+
+    if (!SafeToCreateCanvas3DContext(aParentCanvas))
+        return NS_ERROR_FAILURE;
+
+    // Let's find our prefs
+    nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mPrefWireframe = PR_FALSE;
+    PRBool forceSoftware = PR_FALSE;
+
+    nsCOMPtr<nsIPrefBranch> prefBranch;
+    rv = prefService->GetBranch("extensions.canvas3d.", getter_AddRefs(prefBranch));
+    if (NS_SUCCEEDED(rv)) {
+        PRBool val;
+        rv = prefBranch->GetBoolPref("wireframe", &val);
+        if (NS_SUCCEEDED(rv))
+            mPrefWireframe = val;
+
+        rv = prefBranch->GetBoolPref("software_render", &val);
+        if (NS_SUCCEEDED(rv))
+            forceSoftware = val;
+    }
+
+    fprintf (stderr, "Wireframe: %d\n", mPrefWireframe);
+
+
+    LogMessage(NS_LITERAL_CSTRING("Canvas 3D: creating PBuffer..."));
+
+    if (!forceSoftware) {
+#ifdef XP_WIN
+        mGLPbuffer = new nsGLPbufferWGL();
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+        mGLPbuffer = new nsGLPbufferGLX();
+#elif defined(XP_MACOSX)
+        mGLPbuffer = new nsGLPbufferCGL();
+#else
+        mGLPbuffer = nsnull;
+#endif
+
+        if (mGLPbuffer && !mGLPbuffer->Init(this))
+            mGLPbuffer = nsnull;
+    }
+
+    if (!mGLPbuffer) {
+        mGLPbuffer = new nsGLPbufferOSMESA();
+        if (!mGLPbuffer->Init(this))
+            mGLPbuffer = nsnull;
+    }
+
+    if (!mGLPbuffer)
+        return NS_ERROR_FAILURE;
+
+    gl = mGLPbuffer->GL();
+
+    if (!ValidateGL()) {
+        // XXX over here we need to destroy mGLPbuffer and create a mesa buffer
+
+        LogMessage(NS_LITERAL_CSTRING("Canvas 3D: Couldn't validate OpenGL implementation; is everything needed present?"));
+        return NS_ERROR_FAILURE;
+    }
+
+    mCanvasElement = aParentCanvas;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCanvasRenderingContextGLPrivate::SetDimensions(PRInt32 width, PRInt32 height)
+{
+    if (mWidth == width && mHeight == height)
+        return NS_OK;
+
+    if (!mGLPbuffer->Resize(width, height)) {
+        LogMessage(NS_LITERAL_CSTRING("mGLPbuffer->Resize failed"));
+        return NS_ERROR_FAILURE;
+    }
+
+    LogMessage(NS_LITERAL_CSTRING("Canvas 3D: ready"));
+
+    mWidth = width;
+    mHeight = height;
+
+    // Make sure that we clear this out, otherwise
+    // we'll end up displaying random memory
+    MakeContextCurrent();
+    gl->fViewport(0, 0, mWidth, mHeight);
+    gl->fClearColor(0, 0, 0, 0);
+    gl->fClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsCanvasRenderingContextGLPrivate::Render(gfxContext *ctx, gfxPattern::GraphicsFilter f)
+{
+    nsresult rv = NS_OK;
+
+    if (!mGLPbuffer)
+        return NS_OK;
+
+    // use GL Drawing if we can get a target GL context; otherwise
+    // go through the fallback path.
+#ifdef HAVE_GL_DRAWING
+    if (mCanvasElement->GLWidgetBeginDrawing()) {
+        glClearColor(0.0, 0.0, 0.0, 0.0);
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        int bwidth = mGLPbuffer->Width();
+        int bheight = mGLPbuffer->Height();
+
+        GLuint tex = 0;
+        glGenTextures(1, &tex);
+        glBindTexture(GL_TEXTURE_RECTANGLE_EXT, tex);
+
+        CGLError err =
+            CGLTexImagePBuffer(CGLGetCurrentContext(),
+                               ((nsGLPbufferCGL*)mGLPbuffer)->GetCGLPbuffer(),
+                               GL_BACK);
+        if (err) {
+            fprintf (stderr, "CGLTexImagePBuffer failed: %d\n", err);
+            glDeleteTextures(1, &tex);
+            return NS_OK;
+        }
+
+        glEnable(GL_TEXTURE_RECTANGLE_EXT);
+
+        glMatrixMode(GL_PROJECTION);
+        glLoadIdentity();
+        //glFrustum(-halfWidth, halfWidth, halfHeight, -halfHeight, 1.0, 100000.0);
+        glOrtho(0, bwidth, bheight, 0, -0.5, 10.0);
+
+        glMatrixMode(GL_MODELVIEW);
+        glLoadIdentity();
+
+        glBegin(GL_QUADS);
+
+        /* Note that the texture needs a y-flip */
+        glTexCoord2f(0.0, bheight);
+        glVertex3f(0.0, 0.0, 0.0);
+
+        glTexCoord2f(bwidth, bheight);
+        glVertex3f(bwidth, 0.0, 0.0);
+
+        glTexCoord2f(bwidth, 0);
+        glVertex3f(bwidth, bheight, 0.0);
+
+        glTexCoord2f(0.0, 0);
+        glVertex3f(0.0, bheight, 0.0);
+
+        glEnd();
+
+        glDisable(GL_TEXTURE_RECTANGLE_EXT);
+        glDeleteTextures(1, &tex);
+
+        mCanvasElement->GLWidgetSwapBuffers();
+        mCanvasElement->GLWidgetEndDrawing();
+    } else
+#endif
+    {
+        nsRefPtr<gfxASurface> surf = mGLPbuffer->ThebesSurface();
+        if (!surf)
+            return NS_OK;
+
+        nsRefPtr<gfxPattern> pat = CanvasGLThebes::CreatePattern(surf);
+        gfxMatrix m;
+        m.Translate(gfxPoint(0.0, mGLPbuffer->Height()));
+        m.Scale(1.0, -1.0);
+        pat->SetMatrix(m);
+
+        // XXX I don't want to use PixelSnapped here, but layout doesn't guarantee
+        // pixel alignment for this stuff!
+        ctx->NewPath();
+        ctx->PixelSnappedRectangleAndSetPattern(gfxRect(0, 0, mWidth, mHeight), pat);
+        ctx->Fill();
+    }
+    return rv;
+}
+
+NS_IMETHODIMP
+nsCanvasRenderingContextGLPrivate::GetInputStream(const char* aMimeType,
+                                                  const PRUnichar* aEncoderOptions,
+                                                  nsIInputStream **aStream)
+{
+    // XXX disabled for now due to the win32 nsRefPtr situation -- we need
+    // to manage allocations and deletions very carefully, and can't allocate
+    // an object in our dll and have xul.dll call delete on it (which
+    // Release() will do).
+    return NS_ERROR_FAILURE;
+
+#if 0
+    if (!mGLPbuffer ||
+        !mGLPbuffer->ThebesSurface())
+        return NS_ERROR_FAILURE;
+
+    nsresult rv;
+    const char encoderPrefix[] = "@mozilla.org/image/encoder;2?type=";
+    nsAutoArrayPtr<char> conid(new (std::nothrow) char[strlen(encoderPrefix) + strlen(aMimeType) + 1]);
+
+    if (!conid)
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    strcpy(conid, encoderPrefix);
+    strcat(conid, aMimeType);
+
+    nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(conid);
+    if (!encoder)
+        return NS_ERROR_FAILURE;
+
+    nsAutoArrayPtr<PRUint8> imageBuffer(new (std::nothrow) PRUint8[mWidth * mHeight * 4]);
+    if (!imageBuffer)
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    nsRefPtr<gfxImageSurface> imgsurf = new gfxImageSurface(imageBuffer.get(),
+                                                            gfxIntSize(mWidth, mHeight),
+                                                            mWidth * 4,
+                                                            gfxASurface::ImageFormatARGB32);
+
+    if (!imgsurf || imgsurf->CairoStatus())
+        return NS_ERROR_FAILURE;
+
+    nsRefPtr<gfxContext> ctx = new gfxContext(imgsurf);
+
+    if (!ctx || ctx->HasError())
+        return NS_ERROR_FAILURE;
+
+    nsRefPtr<gfxASurface> surf = mGLPbuffer->ThebesSurface();
+    nsRefPtr<gfxPattern> pat = CanvasGLThebes::CreatePattern(surf);
+    gfxMatrix m;
+    m.Translate(gfxPoint(0.0, mGLPbuffer->Height()));
+    m.Scale(1.0, -1.0);
+    pat->SetMatrix(m);
+
+    // XXX I don't want to use PixelSnapped here, but layout doesn't guarantee
+    // pixel alignment for this stuff!
+    ctx->NewPath();
+    ctx->PixelSnappedRectangleAndSetPattern(gfxRect(0, 0, mWidth, mHeight), pat);
+    ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
+    ctx->Fill();
+
+    rv = encoder->InitFromData(imageBuffer.get(),
+                               mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4,
+                               imgIEncoder::INPUT_FORMAT_HOSTARGB,
+                               nsDependentString(aEncoderOptions));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    return CallQueryInterface(encoder, aStream);
+#endif
+}
+
+NS_IMETHODIMP
+nsCanvasRenderingContextGLPrivate::GetThebesSurface(gfxASurface **surface)
+{
+    if (!mGLPbuffer) {
+        *surface = nsnull;
+        return NS_ERROR_NOT_AVAILABLE;
+    }
+
+    *surface = mGLPbuffer->ThebesSurface();
+    NS_IF_ADDREF(*surface);
+    return NS_OK;
+}
+
+nsCanvasRenderingContextGLPrivate::nsCanvasRenderingContextGLPrivate()
+    : mGLPbuffer(nsnull), mWidth(0), mHeight(0), mCanvasElement(nsnull)
+{
+    // grab the xpconnect service
+    if (!gXPConnect) {
+        nsresult rv = CallGetService(nsIXPConnect::GetCID(), &gXPConnect);
+        if (NS_FAILED(rv)) {
+            NS_ERROR("Failed to get XPConnect!");
+            return;
+        }
+    } else {
+        NS_ADDREF(gXPConnect);
+    }
+
+    if (!gJSRuntimeService) {
+        nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1",
+                                     &gJSRuntimeService);
+        if (NS_FAILED(rv)) {
+            // uh..
+            NS_ERROR("Failed to get JS RuntimeService!");
+            return;
+        }
+
+        gJSRuntimeService->GetRuntime(&gScriptRuntime);
+        if (!gScriptRuntime) {
+            NS_RELEASE(gJSRuntimeService);
+            gJSRuntimeService = nsnull;
+            NS_ERROR("Unable to get JS runtime from JS runtime service");
+        }
+    } else {
+        NS_ADDREF(gJSRuntimeService);
+    }
+}
+
+nsCanvasRenderingContextGLPrivate::~nsCanvasRenderingContextGLPrivate()
+{
+    delete mGLPbuffer;
+    mGLPbuffer = nsnull;
+    
+    // get rid of the context
+    if (gXPConnect && gXPConnect->Release() == 0)
+        gXPConnect = nsnull;
+    if (gJSRuntimeService && gJSRuntimeService->Release() == 0) {
+        gJSRuntimeService = nsnull;
+        gScriptRuntime = nsnull;
+    }
+}
+
+nsresult
+nsCanvasRenderingContextGLPrivate::DoSwapBuffers()
+{
+    mGLPbuffer->SwapBuffers();
+
+    // then invalidate the region and do a redraw
+    if (!mCanvasElement)
+        return NS_OK;
+
+    mCanvasElement->InvalidateFrame();
+    return NS_OK;
+}
+
+PRBool
+nsCanvasRenderingContextGLPrivate::SafeToCreateCanvas3DContext(nsICanvasElement *canvasElement)
+{
+    nsresult rv;
+
+    // first see if we're a chrome context
+    PRBool is_caller_chrome = PR_FALSE;
+    nsCOMPtr<nsIScriptSecurityManager> ssm =
+        do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    rv = ssm->SubjectPrincipalIsSystem(&is_caller_chrome);
+    if (NS_SUCCEEDED(rv) && is_caller_chrome)
+        return PR_TRUE;
+
+    // not chrome? check pref.
+
+    // first check our global pref
+    nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    PRBool allSites = PR_FALSE;
+    rv = prefService->GetBoolPref("extensions.canvas3d.enabled_for_all_sites", &allSites);
+    if (NS_SUCCEEDED(rv) && allSites) {
+        // the all-sites pref was set, we're good to go
+        return PR_TRUE;
+    }
+
+    // otherwise we'll check content prefs
+
+#ifdef ARGH_NEED_SEPARATE_SERVICE
+    // the content pref service IID changed after 3.1b3, so this will fail for nightly builds.
+    nsCOMPtr<nsIContentPrefService> cpsvc = do_GetService("@mozilla.org/content-pref/service;1", &rv);
+    if (NS_FAILED(rv)) {
+        LogMessage(NS_LITERAL_CSTRING("Canvas 3D: Failed to get Content Pref service.  If you are running Firefox 3.1b3, as a temporary fix until 3.5b4 is released, open the Canvas 3D Addon preferences and check the \"Enabled for all sites\" checkbox."));
+        return PR_FALSE;
+    }
+
+    // grab our content URI
+    nsCOMPtr<nsIURI> contentURI;
+
+    nsCOMPtr<nsIPrincipal> principal;
+    rv = ssm->GetSubjectPrincipal(getter_AddRefs(principal));
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    if (!principal) {
+        // seriously? no script executing, but not the system principal?
+        return PR_FALSE;
+    }
+    rv = principal->GetURI(getter_AddRefs(contentURI));
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    // our pref is 'canvas3d.enabled'
+    nsCOMPtr<nsIVariant> val;
+    rv = cpsvc->GetPref(contentURI, NS_LITERAL_STRING("canvas3d.enabled"), getter_AddRefs(val));
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    PRInt32 iv;
+    rv = val->GetAsInt32(&iv);
+    if (NS_SUCCEEDED(rv)) {
+        // 1 means "yes, allowed"
+        if (iv == 1)
+            return PR_TRUE;
+
+        // -1 means "no, don't ask me again"
+        if (iv == -1)
+            return PR_FALSE;
+
+        // otherwise, we'll throw an event and maybe ask the user
+    }
+
+    // grab the document that we can use to create the event
+    nsCOMPtr<nsIDOMNode> node = do_QueryInterface(canvasElement);
+    nsCOMPtr<nsIDOMDocument> domDoc;
+    rv = node->GetOwnerDocument(getter_AddRefs(domDoc));
+
+    /*
+    // figure out where to throw the event.  we just go for the outermost
+    // document.  ideally, I want to throw the event to the <browser> if one exists,
+    // otherwise the topmost document, but that's more work than I want to deal with.
+    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
+    while (doc->GetParentDocument())
+        doc = doc->GetParentDocument();
+    */
+
+    // set up the event
+    nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(domDoc);
+    NS_ENSURE_TRUE(docEvent, PR_FALSE);
+
+    nsCOMPtr<nsIDOMEvent> eventBase;
+    rv = docEvent->CreateEvent(NS_LITERAL_STRING("DataContainerEvent"), getter_AddRefs(eventBase));
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    rv = eventBase->InitEvent(NS_LITERAL_STRING("Canvas3DContextRequest"), PR_TRUE, PR_TRUE);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    nsCOMPtr<nsIDOMDataContainerEvent> event = do_QueryInterface(eventBase);
+    nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(eventBase);
+    NS_ENSURE_TRUE(event && privateEvent, PR_FALSE);
+
+    // mark it as trusted, so that it'll bubble upwards into chrome
+    privateEvent->SetTrusted(PR_TRUE);
+
+    // set some extra data on the event
+    nsCOMPtr<nsIContentURIGrouper> grouper = do_GetService("@mozilla.org/content-pref/hostname-grouper;1", &rv);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    nsAutoString group;
+    rv = grouper->Group(contentURI, group);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    nsCOMPtr<nsIWritableVariant> groupVariant = do_CreateInstance(NS_VARIANT_CONTRACTID);
+    nsCOMPtr<nsIWritableVariant> uriVariant = do_CreateInstance(NS_VARIANT_CONTRACTID);
+
+    groupVariant->SetAsAString(group);
+    uriVariant->SetAsISupports(contentURI);
+
+    rv = event->SetData(NS_LITERAL_STRING("group"), groupVariant);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    rv = event->SetData(NS_LITERAL_STRING("uri"), uriVariant);
+    NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+    // our target...
+    nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(canvasElement);
+
+    // and go.
+    PRBool defaultActionEnabled;
+    targ->DispatchEvent(event, &defaultActionEnabled);
+#endif
+
+    return PR_FALSE;
+}
+
+gfxImageSurface *
+CanvasGLThebes::CreateImageSurface (const gfxIntSize &isize,
+                                    gfxASurface::gfxImageFormat fmt)
+{
+    /*void *p = NS_Alloc(sizeof(gfxImageSurface));*/
+    return new /*(p)*/ gfxImageSurface (isize, fmt);
+}
+
+gfxContext *
+CanvasGLThebes::CreateContext (gfxASurface *surf)
+{
+    void *p = NS_Alloc(sizeof(gfxContext));
+    return new (p) gfxContext (surf);
+}
+
+gfxPattern *
+CanvasGLThebes::CreatePattern (gfxASurface *surf)
+{
+    /*void *p = NS_Alloc(sizeof(gfxPattern));*/
+    return new /*(p)*/ gfxPattern(surf);
+}
+
+/*
+ * We need this here, because nsAString has a different type name based on whether it's
+ * used internally or externally.  BeginPrinting isn't ever called, but gfxImageSurface
+ * wants to inherit the default definition, and it can't find it.  So instead, we just
+ * stick a stub here to shut the compiler up, because we never call this method.
+ */
+
+#ifdef XP_WIN
+nsresult
+gfxWindowsSurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName)
+{
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+nsresult
+gfxASurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName)
+{
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+#endif
+
new file mode 100644
--- /dev/null
+++ b/content/canvas/src/nsCanvasRenderingContextGL.h
@@ -0,0 +1,425 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Vladimir Vukicevic <vladimir@pobox.com> (original author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef _NSCANVASRENDERINGCONTEXTGL_H_
+#define _NSCANVASRENDERINGCONTEXTGL_H_
+
+#ifdef C3D_STANDALONE_BUILD
+#include "c3d-standalone.h"
+#endif
+
+#include "nsICanvasRenderingContextGL.h"
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "prmem.h"
+
+#include "nsStringGlue.h"
+
+#include "nsICanvasRenderingContextGLBuffer.h"
+#include "nsICanvasRenderingContextInternal.h"
+#include "nsIDOMHTMLCanvasElement.h"
+
+#include "nsICanvasGLPrivate.h"
+
+#include "nsIScriptSecurityManager.h"
+#include "nsISecurityCheckedComponent.h"
+
+#include "nsWeakReference.h"
+
+#include "imgIRequest.h"
+#include "imgIContainer.h"
+#include "gfxIImageFrame.h"
+#include "nsIDOMHTMLCanvasElement.h"
+#include "nsICanvasElement.h"
+#include "nsIDOMHTMLImageElement.h"
+#include "nsIImageLoadingContent.h"
+#include "nsIInterfaceRequestorUtils.h"
+#include "nsIImage.h"
+#include "nsDOMError.h"
+#include "nsIJSRuntimeService.h"
+
+#include "nsIServiceManager.h"
+#include "nsIConsoleService.h"
+
+#include "nsDOMError.h"
+
+#include "nsServiceManagerUtils.h"
+
+#include "nsIXPConnect.h"
+#include "jsapi.h"
+
+#include "gfxContext.h"
+
+#include "nsGLPbuffer.h"
+
+extern nsIXPConnect *gXPConnect;
+extern JSRuntime *gScriptRuntime;
+extern nsIJSRuntimeService *gJSRuntimeService;
+
+class nsICanvasRenderingContextGL;
+
+class nsCanvasRenderingContextGLES11;
+class nsCanvasRenderingContextGLWeb20;
+
+class CanvasGLBuffer;
+class CanvasGLTexture;
+
+class nsCanvasRenderingContextGLPrivate :
+    public nsICanvasRenderingContextInternal,
+    public nsSupportsWeakReference
+{
+    friend class nsGLPbuffer;
+    friend class CanvasGLBuffer;
+    friend class CanvasGLTexture;
+
+public:
+    nsCanvasRenderingContextGLPrivate();
+    virtual ~nsCanvasRenderingContextGLPrivate();
+
+    virtual nsICanvasRenderingContextGL *GetSelf() = 0;
+
+    virtual PRBool ValidateGL() { return PR_TRUE; }
+
+    void MakeContextCurrent();
+    static void LostCurrentContext(void *closure);
+
+    // nsICanvasRenderingContextInternal
+    NS_IMETHOD SetCanvasElement(nsICanvasElement* aParentCanvas);
+    NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
+    NS_IMETHOD Render(gfxContext *ctx, gfxPattern::GraphicsFilter f);
+    NS_IMETHOD GetInputStream(const char* aMimeType,
+                              const PRUnichar* aEncoderOptions,
+                              nsIInputStream **aStream);
+    NS_IMETHOD GetThebesSurface(gfxASurface **surface);
+    NS_IMETHOD SetIsOpaque(PRBool b) { return NS_OK; };
+
+protected:
+    PRBool SafeToCreateCanvas3DContext(nsICanvasElement *canvasElement);
+    nsresult DoSwapBuffers();
+
+    // thebes helpers
+    nsresult ImageSurfaceFromElement(nsIDOMElement *imgElt,
+                                     gfxImageSurface **aSurface,
+                                     nsIPrincipal **prinOut,
+                                     PRBool *forceWriteOnlyOut,
+                                     PRBool *surfaceNeedsReleaseInsteadOfDelete);
+
+    void DoDrawImageSecurityCheck(nsIPrincipal* element_uri, PRBool forceWriteOnly);
+
+    GLES20Wrap *gl;
+
+    nsGLPbuffer *mGLPbuffer;
+    PRInt32 mWidth, mHeight;
+    nsICanvasElement* mCanvasElement;
+
+    PRPackedBool mPrefWireframe;
+
+    void LogMessage (const nsCString& errorString) {
+        nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
+        if (!console)
+            return;
+
+        console->LogStringMessage(NS_ConvertUTF8toUTF16(errorString).get());
+        fprintf(stderr, "%s\n", errorString.get());
+    }
+
+    void LogMessagef (const char *fmt, ...) {
+        va_list ap;
+        va_start(ap, fmt);
+        char buf[256];
+
+        nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));