[WebGL2] Teach WebGLRenderingContextBase about new texture internal formats
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext3D.h
index 1856eb7..4106617 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 #ifndef GraphicsContext3D_h
 #define GraphicsContext3D_h
 
+#include "ANGLEWebKitBridge.h"
 #include "GraphicsTypes3D.h"
 #include "Image.h"
 #include "IntRect.h"
 #include "PlatformLayer.h"
+#include <memory>
 #include <wtf/HashMap.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/OwnArrayPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
 
 #endif
 
 // FIXME: Find a better way to avoid the name confliction for NO_ERROR.
-#if PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS))
+#if PLATFORM(WIN)
 #undef NO_ERROR
 #elif PLATFORM(GTK)
 // This define is from the X11 headers, but it's used below, so we must undefine it.
 #undef VERSION
 #endif
 
-#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY) || PLATFORM(WIN) || PLATFORM(NIX)
-#include "ANGLEWebKitBridge.h"
-#endif
-
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
+#if PLATFORM(IOS)
+#include <OpenGLES/ES2/gl.h>
+#ifdef __OBJC__
+#import <OpenGLES/EAGL.h>
+#endif // __OBJC__
+#endif // PLATFORM(IOS)
 #include <wtf/RetainPtr.h>
 OBJC_CLASS CALayer;
 OBJC_CLASS WebGLLayer;
-#elif PLATFORM(QT)
-QT_BEGIN_NAMESPACE
-class QPainter;
-class QRect;
-class QOpenGLContext;
-class QSurface;
-QT_END_NAMESPACE
-#elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(NIX)
+#elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN_CAIRO)
 typedef unsigned int GLuint;
 #endif
 
-#if PLATFORM(MAC)
+#if PLATFORM(IOS)
+#ifdef __OBJC__
+typedef EAGLContext* PlatformGraphicsContext3D;
+#else
+typedef void* PlatformGraphicsContext3D;
+#endif // __OBJC__
+#elif PLATFORM(MAC)
 typedef struct _CGLContextObject *CGLContextObj;
 
 typedef CGLContextObj PlatformGraphicsContext3D;
-#elif PLATFORM(QT)
-typedef QOpenGLContext* PlatformGraphicsContext3D;
-typedef QSurface* PlatformGraphicsSurface3D;
 #else
 typedef void* PlatformGraphicsContext3D;
 typedef void* PlatformGraphicsSurface3D;
@@ -85,16 +84,12 @@ const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0;
 const Platform3DObject NullPlatform3DObject = 0;
 
 namespace WebCore {
-class DrawingBuffer;
 class Extensions3D;
 #if USE(OPENGL_ES_2)
 class Extensions3DOpenGLES;
 #else
 class Extensions3DOpenGL;
 #endif
-#if PLATFORM(QT)
-class Extensions3DQt;
-#endif
 class HostWindow;
 class Image;
 class ImageBuffer;
@@ -102,12 +97,13 @@ class ImageSource;
 class ImageData;
 class IntRect;
 class IntSize;
+class WebGLRenderingContextBase;
 #if USE(CAIRO)
 class PlatformContextCairo;
-#elif PLATFORM(BLACKBERRY)
-class GraphicsContext;
 #endif
 
+typedef WTF::HashMap<CString, uint64_t> ShaderNameHash;
+
 struct ActiveInfo {
     String name;
     GC3Denum type;
@@ -119,6 +115,7 @@ class GraphicsContext3DPrivate;
 class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
 public:
     enum {
+        // WebGL 1 constants
         DEPTH_BUFFER_BIT = 0x00000100,
         STENCIL_BUFFER_BIT = 0x00000400,
         COLOR_BUFFER_BIT = 0x00004000,
@@ -373,6 +370,8 @@ public:
         VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A,
         VERTEX_ATTRIB_ARRAY_POINTER = 0x8645,
         VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F,
+        IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A,
+        IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B,
         COMPILE_STATUS = 0x8B81,
         INFO_LOG_LENGTH = 0x8B84,
         SHADER_SOURCE_LENGTH = 0x8B88,
@@ -393,9 +392,6 @@ public:
         DEPTH_COMPONENT16 = 0x81A5,
         STENCIL_INDEX = 0x1901,
         STENCIL_INDEX8 = 0x8D48,
-        DEPTH_STENCIL = 0x84F9,
-        UNSIGNED_INT_24_8 = 0x84FA,
-        DEPTH24_STENCIL8 = 0x88F0,
         RENDERBUFFER_WIDTH = 0x8D42,
         RENDERBUFFER_HEIGHT = 0x8D43,
         RENDERBUFFER_INTERNAL_FORMAT = 0x8D44,
@@ -412,7 +408,6 @@ public:
         COLOR_ATTACHMENT0 = 0x8CE0,
         DEPTH_ATTACHMENT = 0x8D00,
         STENCIL_ATTACHMENT = 0x8D20,
-        DEPTH_STENCIL_ATTACHMENT = 0x821A,
         NONE = 0,
         FRAMEBUFFER_COMPLETE = 0x8CD5,
         FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6,
@@ -429,33 +424,315 @@ public:
         UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241,
         CONTEXT_LOST_WEBGL = 0x9242,
         UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
-        BROWSER_DEFAULT_WEBGL = 0x9244
+        BROWSER_DEFAULT_WEBGL = 0x9244,
+        VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE,
+        
+        // WebGL2 constants
+        READ_BUFFER = 0x0C02,
+        UNPACK_ROW_LENGTH = 0x0CF2,
+        UNPACK_SKIP_ROWS = 0x0CF3,
+        UNPACK_SKIP_PIXELS = 0x0CF4,
+        PACK_ROW_LENGTH = 0x0D02,
+        PACK_SKIP_ROWS = 0x0D03,
+        PACK_SKIP_PIXELS = 0x0D04,
+        COLOR = 0x1800,
+        DEPTH = 0x1801,
+        STENCIL = 0x1802,
+        RED = 0x1903,
+        RGB8 = 0x8051,
+        RGBA8 = 0x8058,
+        RGB10_A2 = 0x8059,
+        TEXTURE_BINDING_3D = 0x806A,
+        UNPACK_SKIP_IMAGES = 0x806D,
+        UNPACK_IMAGE_HEIGHT = 0x806E,
+        TEXTURE_3D = 0x806F,
+        TEXTURE_WRAP_R = 0x8072,
+        MAX_3D_TEXTURE_SIZE = 0x8073,
+        UNSIGNED_INT_2_10_10_10_REV = 0x8368,
+        MAX_ELEMENTS_VERTICES = 0x80E8,
+        MAX_ELEMENTS_INDICES = 0x80E9,
+        TEXTURE_MIN_LOD = 0x813A,
+        TEXTURE_MAX_LOD = 0x813B,
+        TEXTURE_BASE_LEVEL = 0x813C,
+        TEXTURE_MAX_LEVEL = 0x813D,
+        MIN = 0x8007,
+        MAX = 0x8008,
+        DEPTH_COMPONENT24 = 0x81A6,
+        MAX_TEXTURE_LOD_BIAS = 0x84FD,
+        TEXTURE_COMPARE_MODE = 0x884C,
+        TEXTURE_COMPARE_FUNC = 0x884D,
+        CURRENT_QUERY = 0x8865,
+        QUERY_RESULT = 0x8866,
+        QUERY_RESULT_AVAILABLE = 0x8867,
+        STREAM_READ = 0x88E1,
+        STREAM_COPY = 0x88E2,
+        STATIC_READ = 0x88E5,
+        STATIC_COPY = 0x88E6,
+        DYNAMIC_READ = 0x88E9,
+        DYNAMIC_COPY = 0x88EA,
+        MAX_DRAW_BUFFERS = 0x8824,
+        DRAW_BUFFER0 = 0x8825,
+        DRAW_BUFFER1 = 0x8826,
+        DRAW_BUFFER2 = 0x8827,
+        DRAW_BUFFER3 = 0x8828,
+        DRAW_BUFFER4 = 0x8829,
+        DRAW_BUFFER5 = 0x882A,
+        DRAW_BUFFER6 = 0x882B,
+        DRAW_BUFFER7 = 0x882C,
+        DRAW_BUFFER8 = 0x882D,
+        DRAW_BUFFER9 = 0x882E,
+        DRAW_BUFFER10 = 0x882F,
+        DRAW_BUFFER11 = 0x8830,
+        DRAW_BUFFER12 = 0x8831,
+        DRAW_BUFFER13 = 0x8832,
+        DRAW_BUFFER14 = 0x8833,
+        DRAW_BUFFER15 = 0x8834,
+        MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49,
+        MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A,
+        SAMPLER_3D = 0x8B5F,
+        SAMPLER_2D_SHADOW = 0x8B62,
+        FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B,
+        PIXEL_PACK_BUFFER = 0x88EB,
+        PIXEL_UNPACK_BUFFER = 0x88EC,
+        PIXEL_PACK_BUFFER_BINDING = 0x88ED,
+        PIXEL_UNPACK_BUFFER_BINDING = 0x88EF,
+        FLOAT_MAT2x3 = 0x8B65,
+        FLOAT_MAT2x4 = 0x8B66,
+        FLOAT_MAT3x2 = 0x8B67,
+        FLOAT_MAT3x4 = 0x8B68,
+        FLOAT_MAT4x2 = 0x8B69,
+        FLOAT_MAT4x3 = 0x8B6A,
+        SRGB = 0x8C40,
+        SRGB8 = 0x8C41,
+        SRGB_ALPHA = 0x8C42,
+        SRGB8_ALPHA8 = 0x8C43,
+        COMPARE_REF_TO_TEXTURE = 0x884E,
+        RGBA32F = 0x8814,
+        RGB32F = 0x8815,
+        RGBA16F = 0x881A,
+        RGB16F = 0x881B,
+        VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD,
+        MAX_ARRAY_TEXTURE_LAYERS = 0x88FF,
+        MIN_PROGRAM_TEXEL_OFFSET = 0x8904,
+        MAX_PROGRAM_TEXEL_OFFSET = 0x8905,
+        MAX_VARYING_COMPONENTS = 0x8B4B,
+        TEXTURE_2D_ARRAY = 0x8C1A,
+        TEXTURE_BINDING_2D_ARRAY = 0x8C1D,
+        R11F_G11F_B10F = 0x8C3A,
+        UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B,
+        RGB9_E5 = 0x8C3D,
+        UNSIGNED_INT_5_9_9_9_REV = 0x8C3E,
+        TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F,
+        MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80,
+        TRANSFORM_FEEDBACK_VARYINGS = 0x8C83,
+        TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84,
+        TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85,
+        TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88,
+        RASTERIZER_DISCARD = 0x8C89,
+        MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A,
+        MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B,
+        INTERLEAVED_ATTRIBS = 0x8C8C,
+        SEPARATE_ATTRIBS = 0x8C8D,
+        TRANSFORM_FEEDBACK_BUFFER = 0x8C8E,
+        TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F,
+        RGBA32UI = 0x8D70,
+        RGB32UI = 0x8D71,
+        RGBA16UI = 0x8D76,
+        RGB16UI = 0x8D77,
+        RGBA8UI = 0x8D7C,
+        RGB8UI = 0x8D7D,
+        RGBA32I = 0x8D82,
+        RGB32I = 0x8D83,
+        RGBA16I = 0x8D88,
+        RGB16I = 0x8D89,
+        RGBA8I = 0x8D8E,
+        RGB8I = 0x8D8F,
+        RED_INTEGER = 0x8D94,
+        RGB_INTEGER = 0x8D98,
+        RGBA_INTEGER = 0x8D99,
+        SAMPLER_2D_ARRAY = 0x8DC1,
+        SAMPLER_2D_ARRAY_SHADOW = 0x8DC4,
+        SAMPLER_CUBE_SHADOW = 0x8DC5,
+        UNSIGNED_INT_VEC2 = 0x8DC6,
+        UNSIGNED_INT_VEC3 = 0x8DC7,
+        UNSIGNED_INT_VEC4 = 0x8DC8,
+        INT_SAMPLER_2D = 0x8DCA,
+        INT_SAMPLER_3D = 0x8DCB,
+        INT_SAMPLER_CUBE = 0x8DCC,
+        INT_SAMPLER_2D_ARRAY = 0x8DCF,
+        UNSIGNED_INT_SAMPLER_2D = 0x8DD2,
+        UNSIGNED_INT_SAMPLER_3D = 0x8DD3,
+        UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4,
+        UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7,
+        DEPTH_COMPONENT32F = 0x8CAC,
+        DEPTH32F_STENCIL8 = 0x8CAD,
+        FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD,
+        FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210,
+        FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211,
+        FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212,
+        FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213,
+        FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214,
+        FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215,
+        FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216,
+        FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217,
+        FRAMEBUFFER_DEFAULT = 0x8218,
+        DEPTH_STENCIL_ATTACHMENT = 0x821A,
+        DEPTH_STENCIL = 0x84F9,
+        UNSIGNED_INT_24_8 = 0x84FA,
+        DEPTH24_STENCIL8 = 0x88F0,
+        UNSIGNED_NORMALIZED = 0x8C17,
+        DRAW_FRAMEBUFFER_BINDING = 0x8CA6, /* Same as FRAMEBUFFER_BINDING */
+        READ_FRAMEBUFFER = 0x8CA8,
+        DRAW_FRAMEBUFFER = 0x8CA9,
+        READ_FRAMEBUFFER_BINDING = 0x8CAA,
+        RENDERBUFFER_SAMPLES = 0x8CAB,
+        FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4,
+        MAX_COLOR_ATTACHMENTS = 0x8CDF,
+        COLOR_ATTACHMENT1 = 0x8CE1,
+        COLOR_ATTACHMENT2 = 0x8CE2,
+        COLOR_ATTACHMENT3 = 0x8CE3,
+        COLOR_ATTACHMENT4 = 0x8CE4,
+        COLOR_ATTACHMENT5 = 0x8CE5,
+        COLOR_ATTACHMENT6 = 0x8CE6,
+        COLOR_ATTACHMENT7 = 0x8CE7,
+        COLOR_ATTACHMENT8 = 0x8CE8,
+        COLOR_ATTACHMENT9 = 0x8CE9,
+        COLOR_ATTACHMENT10 = 0x8CEA,
+        COLOR_ATTACHMENT11 = 0x8CEB,
+        COLOR_ATTACHMENT12 = 0x8CEC,
+        COLOR_ATTACHMENT13 = 0x8CED,
+        COLOR_ATTACHMENT14 = 0x8CEE,
+        COLOR_ATTACHMENT15 = 0x8CEF,
+        FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
+        MAX_SAMPLES = 0x8D57,
+        HALF_FLOAT = 0x140B,
+        RG = 0x8227,
+        RG_INTEGER = 0x8228,
+        R8 = 0x8229,
+        RG8 = 0x822B,
+        R16F = 0x822D,
+        R32F = 0x822E,
+        RG16F = 0x822F,
+        RG32F = 0x8230,
+        R8I = 0x8231,
+        R8UI = 0x8232,
+        R16I = 0x8233,
+        R16UI = 0x8234,
+        R32I = 0x8235,
+        R32UI = 0x8236,
+        RG8I = 0x8237,
+        RG8UI = 0x8238,
+        RG16I = 0x8239,
+        RG16UI = 0x823A,
+        RG32I = 0x823B,
+        RG32UI = 0x823C,
+        VERTEX_ARRAY_BINDING = 0x85B5,
+        R8_SNORM = 0x8F94,
+        RG8_SNORM = 0x8F95,
+        RGB8_SNORM = 0x8F96,
+        RGBA8_SNORM = 0x8F97,
+        SIGNED_NORMALIZED = 0x8F9C,
+        COPY_READ_BUFFER = 0x8F36,
+        COPY_WRITE_BUFFER = 0x8F37,
+        COPY_READ_BUFFER_BINDING = 0x8F36, /* Same as COPY_READ_BUFFER */
+        COPY_WRITE_BUFFER_BINDING = 0x8F37, /* Same as COPY_WRITE_BUFFER */
+        UNIFORM_BUFFER = 0x8A11,
+        UNIFORM_BUFFER_BINDING = 0x8A28,
+        UNIFORM_BUFFER_START = 0x8A29,
+        UNIFORM_BUFFER_SIZE = 0x8A2A,
+        MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B,
+        MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D,
+        MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E,
+        MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F,
+        MAX_UNIFORM_BLOCK_SIZE = 0x8A30,
+        MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31,
+        MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33,
+        UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34,
+        ACTIVE_UNIFORM_BLOCKS = 0x8A36,
+        UNIFORM_TYPE = 0x8A37,
+        UNIFORM_SIZE = 0x8A38,
+        UNIFORM_BLOCK_INDEX = 0x8A3A,
+        UNIFORM_OFFSET = 0x8A3B,
+        UNIFORM_ARRAY_STRIDE = 0x8A3C,
+        UNIFORM_MATRIX_STRIDE = 0x8A3D,
+        UNIFORM_IS_ROW_MAJOR = 0x8A3E,
+        UNIFORM_BLOCK_BINDING = 0x8A3F,
+        UNIFORM_BLOCK_DATA_SIZE = 0x8A40,
+        UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42,
+        UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43,
+        UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44,
+        UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46,
+        INVALID_INDEX = 0xFFFFFFFF,
+        MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122,
+        MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125,
+        MAX_SERVER_WAIT_TIMEOUT = 0x9111,
+        OBJECT_TYPE = 0x9112,
+        SYNC_CONDITION = 0x9113,
+        SYNC_STATUS = 0x9114,
+        SYNC_FLAGS = 0x9115,
+        SYNC_FENCE = 0x9116,
+        SYNC_GPU_COMMANDS_COMPLETE = 0x9117,
+        UNSIGNALED = 0x9118,
+        SIGNALED = 0x9119,
+        ALREADY_SIGNALED = 0x911A,
+        TIMEOUT_EXPIRED = 0x911B,
+        CONDITION_SATISFIED = 0x911C,
+#if PLATFORM(WIN)
+        WAIT_FAILED_WIN = 0x911D,
+#else
+        WAIT_FAILED = 0x911D,
+#endif
+        SYNC_FLUSH_COMMANDS_BIT = 0x00000001,
+        VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE,
+        ANY_SAMPLES_PASSED = 0x8C2F,
+        ANY_SAMPLES_PASSED_CONSERVATIVE = 0x8D6A,
+        SAMPLER_BINDING = 0x8919,
+        RGB10_A2UI = 0x906F,
+        TEXTURE_SWIZZLE_R = 0x8E42,
+        TEXTURE_SWIZZLE_G = 0x8E43,
+        TEXTURE_SWIZZLE_B = 0x8E44,
+        TEXTURE_SWIZZLE_A = 0x8E45,
+        GREEN = 0x1904,
+        BLUE = 0x1905,
+        INT_2_10_10_10_REV = 0x8D9F,
+        TRANSFORM_FEEDBACK = 0x8E22,
+        TRANSFORM_FEEDBACK_PAUSED = 0x8E23,
+        TRANSFORM_FEEDBACK_ACTIVE = 0x8E24,
+        TRANSFORM_FEEDBACK_BINDING = 0x8E25,
+        COMPRESSED_R11_EAC = 0x9270,
+        COMPRESSED_SIGNED_R11_EAC = 0x9271,
+        COMPRESSED_RG11_EAC = 0x9272,
+        COMPRESSED_SIGNED_RG11_EAC = 0x9273,
+        COMPRESSED_RGB8_ETC2 = 0x9274,
+        COMPRESSED_SRGB8_ETC2 = 0x9275,
+        COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
+        COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
+        COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
+        COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
+        TEXTURE_IMMUTABLE_FORMAT = 0x912F,
+        MAX_ELEMENT_INDEX = 0x8D6B,
+        NUM_SAMPLE_COUNTS = 0x9380,
+        TEXTURE_IMMUTABLE_LEVELS = 0x82DF, 
+
+        // OpenGL ES 3 constants
+        MAP_READ_BIT = 0x0001
     };
 
     // Context creation attributes.
     struct Attributes {
-        Attributes()
-            : alpha(true)
-            , depth(true)
-            , stencil(false)
-            , antialias(true)
-            , premultipliedAlpha(true)
-            , preserveDrawingBuffer(false)
-            , noExtensions(false)
-            , shareResources(true)
-            , preferDiscreteGPU(false)
-        {
-        }
-
-        bool alpha;
-        bool depth;
-        bool stencil;
-        bool antialias;
-        bool premultipliedAlpha;
-        bool preserveDrawingBuffer;
-        bool noExtensions;
-        bool shareResources;
-        bool preferDiscreteGPU;
+        bool alpha { true };
+        bool depth { true };
+        bool stencil { false };
+        bool antialias { true };
+        bool premultipliedAlpha { true };
+        bool preserveDrawingBuffer { false };
+        bool noExtensions { false };
+        bool shareResources { true };
+        bool preferLowPowerToHighPerformance { false };
+        bool forceSoftwareRenderer { false };
+        bool failIfMajorPerformanceCaveat { false };
+        bool useGLES3 { false };
+        float devicePixelRatio { 1 };
     };
 
     enum RenderStyle {
@@ -476,31 +753,28 @@ public:
         virtual ~ErrorMessageCallback() { }
     };
 
-    void setContextLostCallback(PassOwnPtr<ContextLostCallback>);
-    void setErrorMessageCallback(PassOwnPtr<ErrorMessageCallback>);
+    void setContextLostCallback(std::unique_ptr<ContextLostCallback>);
+    void setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>);
 
-    static PassRefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
+    static RefPtr<GraphicsContext3D> create(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
     static PassRefPtr<GraphicsContext3D> createForCurrentGLContext();
     ~GraphicsContext3D();
 
-#if PLATFORM(MAC)
+#if PLATFORM(COCOA)
     PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; }
     Platform3DObject platformTexture() const { return m_compositorTexture; }
     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); }
 #else
     PlatformGraphicsContext3D platformGraphicsContext3D();
     Platform3DObject platformTexture() const;
-#if USE(ACCELERATED_COMPOSITING) 
     PlatformLayer* platformLayer() const;
 #endif
-#endif
 
     bool makeContextCurrent();
+    void setWebGLContext(WebGLRenderingContextBase* base) { m_webglContext = base; }
 
-#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY) || PLATFORM(WIN) || PLATFORM(NIX)
     // With multisampling on, blit from multisampleFBO to regular FBO.
     void prepareTexture();
-#endif
 
     // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
     void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels);
@@ -537,6 +811,8 @@ public:
                                      unsigned int* imageSizeInBytes,
                                      unsigned int* paddingInBytes);
 
+    static bool possibleFormatAndTypeForInternalFormat(GC3Denum internalFormat, GC3Denum& format, GC3Denum& type);
+
     // Extracts the contents of the given ImageData into the passed Vector,
     // packing the pixel data according to the given format and type,
     // and obeying the flipY and premultiplyAlpha flags. Returns true
@@ -569,10 +845,12 @@ public:
         DataFormatRGBA8 = 0,
         DataFormatRGBA16Little,
         DataFormatRGBA16Big,
+        DataFormatRGBA16F,
         DataFormatRGBA32F,
         DataFormatRGB8,
         DataFormatRGB16Little,
         DataFormatRGB16Big,
+        DataFormatRGB16F,
         DataFormatRGB32F,
         DataFormatBGR8,
         DataFormatBGRA8,
@@ -588,10 +866,12 @@ public:
         DataFormatR8,
         DataFormatR16Little,
         DataFormatR16Big,
+        DataFormatR16F,
         DataFormatR32F,
         DataFormatRA8,
         DataFormatRA16Little,
         DataFormatRA16Big,
+        DataFormatRA16F,
         DataFormatRA32F,
         DataFormatAR8,
         DataFormatAR16Little,
@@ -599,10 +879,64 @@ public:
         DataFormatA8,
         DataFormatA16Little,
         DataFormatA16Big,
+        DataFormatA16F,
         DataFormatA32F,
         DataFormatNumFormats
     };
 
+    ALWAYS_INLINE static bool hasAlpha(DataFormat format)
+    {
+        switch (format) {
+        case GraphicsContext3D::DataFormatA8:
+        case GraphicsContext3D::DataFormatA16F:
+        case GraphicsContext3D::DataFormatA32F:
+        case GraphicsContext3D::DataFormatRA8:
+        case GraphicsContext3D::DataFormatAR8:
+        case GraphicsContext3D::DataFormatRA16F:
+        case GraphicsContext3D::DataFormatRA32F:
+        case GraphicsContext3D::DataFormatRGBA8:
+        case GraphicsContext3D::DataFormatBGRA8:
+        case GraphicsContext3D::DataFormatARGB8:
+        case GraphicsContext3D::DataFormatABGR8:
+        case GraphicsContext3D::DataFormatRGBA16F:
+        case GraphicsContext3D::DataFormatRGBA32F:
+        case GraphicsContext3D::DataFormatRGBA4444:
+        case GraphicsContext3D::DataFormatRGBA5551:
+            return true;
+        default:
+            return false;
+        }
+    }
+
+    ALWAYS_INLINE static bool hasColor(DataFormat format)
+    {
+        switch (format) {
+        case GraphicsContext3D::DataFormatRGBA8:
+        case GraphicsContext3D::DataFormatRGBA16F:
+        case GraphicsContext3D::DataFormatRGBA32F:
+        case GraphicsContext3D::DataFormatRGB8:
+        case GraphicsContext3D::DataFormatRGB16F:
+        case GraphicsContext3D::DataFormatRGB32F:
+        case GraphicsContext3D::DataFormatBGR8:
+        case GraphicsContext3D::DataFormatBGRA8:
+        case GraphicsContext3D::DataFormatARGB8:
+        case GraphicsContext3D::DataFormatABGR8:
+        case GraphicsContext3D::DataFormatRGBA5551:
+        case GraphicsContext3D::DataFormatRGBA4444:
+        case GraphicsContext3D::DataFormatRGB565:
+        case GraphicsContext3D::DataFormatR8:
+        case GraphicsContext3D::DataFormatR16F:
+        case GraphicsContext3D::DataFormatR32F:
+        case GraphicsContext3D::DataFormatRA8:
+        case GraphicsContext3D::DataFormatRA16F:
+        case GraphicsContext3D::DataFormatRA32F:
+        case GraphicsContext3D::DataFormatAR8:
+            return true;
+        default:
+            return false;
+        }
+    }
+
     // Check if the format is one of the formats from the ImageData or DOM elements.
     // The formats from ImageData is always RGBA8.
     // The formats from DOM elements vary with Graphics ports. It can only be RGBA8 or BGRA8 for non-CG port while a little more for CG port.
@@ -646,6 +980,10 @@ public:
     void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage);
     void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data);
 
+    void* mapBufferRange(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr length, GC3Dbitfield access);
+    GC3Dboolean unmapBuffer(GC3Denum target);
+    void copyBufferSubData(GC3Denum readTarget, GC3Denum writeTarget, GC3Dintptr readOffset, GC3Dintptr writeOffset, GC3Dsizeiptr);
+
     GC3Denum checkFramebufferStatus(GC3Denum target);
     void clear(GC3Dbitfield mask);
     void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha);
@@ -678,7 +1016,9 @@ public:
     void generateMipmap(GC3Denum target);
 
     bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&);
+    bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
     bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&);
+    bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&);
     void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders);
     GC3Dint getAttribLocation(Platform3DObject, const String& name);
     void getBooleanv(GC3Denum pname, GC3Dboolean* value);
@@ -688,8 +1028,11 @@ public:
     void getFloatv(GC3Denum pname, GC3Dfloat* value);
     void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value);
     void getIntegerv(GC3Denum pname, GC3Dint* value);
+    void getInteger64v(GC3Denum pname, GC3Dint64* value);
     void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value);
+    void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value);
     String getProgramInfoLog(Platform3DObject);
+    String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&);
     void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value);
     void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value);
     String getShaderInfoLog(Platform3DObject);
@@ -760,6 +1103,8 @@ public:
 
     void useProgram(Platform3DObject);
     void validateProgram(Platform3DObject);
+    bool checkVaryingsPacking(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
+    bool precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const;
 
     void vertexAttrib1f(GC3Duint index, GC3Dfloat x);
     void vertexAttrib1fv(GC3Duint index, GC3Dfloat* values);
@@ -776,27 +1121,35 @@ public:
 
     void reshape(int width, int height);
 
+    void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
+    void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
+    void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
+
+    // VertexArrayOject calls
+    Platform3DObject createVertexArray();
+    void deleteVertexArray(Platform3DObject);
+    GC3Dboolean isVertexArray(Platform3DObject);
+    void bindVertexArray(Platform3DObject);
+
 #if PLATFORM(GTK) || PLATFORM(EFL) || USE(CAIRO)
     void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
                        int canvasWidth, int canvasHeight, PlatformContextCairo* context);
-#elif PLATFORM(QT)
-    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
-                       int canvasWidth, int canvasHeight, QPainter* context);
-#elif PLATFORM(BLACKBERRY) || USE(CG)
-    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
-                       int canvasWidth, int canvasHeight, GraphicsContext*);
+#elif USE(CG)
+    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, GraphicsContext&);
 #endif
 
     void markContextChanged();
     void markLayerComposited();
     bool layerComposited() const;
+    void forceContextLost();
+    void recycleContext();
 
-    void paintRenderingResultsToCanvas(ImageBuffer*, DrawingBuffer*);
-    PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*);
+    void paintRenderingResultsToCanvas(ImageBuffer*);
+    PassRefPtr<ImageData> paintRenderingResultsToImageData();
     bool paintCompositedResultsToCanvas(ImageBuffer*);
 
-#if PLATFORM(BLACKBERRY)
-    bool paintsIntoCanvasBuffer() const;
+#if PLATFORM(IOS)
+    void endPaint();
 #endif
 
     // Support for buffer creation and deletion
@@ -824,6 +1177,10 @@ public:
     // getError in the order they were added.
     void synthesizeGLError(GC3Denum error);
 
+    // Read real OpenGL errors, and move them to the synthetic
+    // error list. Return true if at least one error is moved.
+    bool moveErrorsToSyntheticErrorList();
+
     // Support for extensions. Returns a non-null object, though not
     // all methods it contains may necessarily be supported on the
     // current hardware. Must call Extensions3D::supports() to
@@ -895,14 +1252,10 @@ public:
         ImageSource* m_decoder;
         RefPtr<cairo_surface_t> m_imageSurface;
 #elif USE(CG)
-        CGImageRef m_cgImage;
+        RetainPtr<CGImageRef> m_cgImage;
         RetainPtr<CGImageRef> m_decodedImage;
         RetainPtr<CFDataRef> m_pixelData;
-        OwnArrayPtr<uint8_t> m_formalizedRGBA8Data;
-#elif PLATFORM(QT)
-        QImage m_qtImage;
-#elif PLATFORM(BLACKBERRY)
-        Vector<unsigned> m_imageData;
+        std::unique_ptr<uint8_t[]> m_formalizedRGBA8Data;
 #endif
         Image* m_image;
         ImageHtmlDomSource m_imageHtmlDomSource;
@@ -917,6 +1270,7 @@ public:
 
 private:
     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
+    static int GPUCheckCounter;
 
     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
     // data into the specified OpenGL destination format and type.
@@ -925,72 +1279,45 @@ private:
     // Destination data will have no gaps between rows.
     static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY);
 
-#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY) || PLATFORM(WIN) || PLATFORM(NIX)
     // Take into account the user's requested context creation attributes,
     // in particular stencil and antialias, and determine which could or
     // could not be honored based on the capabilities of the OpenGL
     // implementation.
     void validateDepthStencil(const char* packedDepthStencilExtension);
     void validateAttributes();
+    
+    // Call to make during draw calls to check on the GPU's status.
+    void checkGPUStatusIfNecessary();
 
     // Read rendering results into a pixel array with the same format as the
     // backbuffer.
     void readRenderingResults(unsigned char* pixels, int pixelsSize);
     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
-#endif
 
-#if PLATFORM(BLACKBERRY)
-    void logFrameBufferStatus(int line);
-    void readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data);
+#if PLATFORM(IOS)
+    void setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
 #endif
 
     bool reshapeFBOs(const IntSize&);
     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
-#if (PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(NIX)) && USE(GRAPHICS_SURFACE)
+    void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height);
+#if PLATFORM(EFL) && USE(GRAPHICS_SURFACE)
     void createGraphicsSurfaces(const IntSize&);
 #endif
 
     int m_currentWidth, m_currentHeight;
     bool isResourceSafe();
 
-#if PLATFORM(MAC)
-    CGLContextObj m_contextObj;
+#if PLATFORM(COCOA)
     RetainPtr<WebGLLayer> m_webGLLayer;
-#elif PLATFORM(WIN) && USE(CA)
-    RefPtr<PlatformCALayer> m_webGLLayer;
-#elif PLATFORM(BLACKBERRY)
-#if USE(ACCELERATED_COMPOSITING)
-    RefPtr<PlatformLayer> m_compositingLayer;
-#endif
-    void* m_context;
+    PlatformGraphicsContext3D m_contextObj;
 #endif
 
-#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL) || PLATFORM(BLACKBERRY) || PLATFORM(WIN) || PLATFORM(NIX)
-    struct SymbolInfo {
-        SymbolInfo()
-            : type(0)
-            , size(0)
-        {
-        }
-
-        SymbolInfo(GC3Denum type, int size, const String& mappedName)
-            : type(type)
-            , size(size)
-            , mappedName(mappedName)
-        {
-        }
-
-        bool operator==(SymbolInfo& other) const
-        {
-            return type == other.type && size == other.size && mappedName == other.mappedName;
-        }
-
-        GC3Denum type;
-        int size;
-        String mappedName;
-    };
+#if PLATFORM(WIN) && USE(CA)
+    RefPtr<PlatformCALayer> m_webGLLayer;
+#endif
 
-    typedef HashMap<String, SymbolInfo> ShaderSymbolMap;
+    typedef HashMap<String, sh::ShaderVariable> ShaderSymbolMap;
 
     struct ShaderSourceEntry {
         GC3Denum type;
@@ -1000,6 +1327,7 @@ private:
         bool isValid;
         ShaderSymbolMap attributeMap;
         ShaderSymbolMap uniformMap;
+        ShaderSymbolMap varyingMap;
         ShaderSourceEntry()
             : type(VERTEX_SHADER)
             , isValid(false)
@@ -1008,9 +1336,11 @@ private:
         
         ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType)
         {
-            ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM);
+            ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING);
             if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE)
                 return attributeMap;
+            if (symbolType == SHADER_SYMBOL_TYPE_VARYING)
+                return varyingMap;
             return uniformMap;
         }
     };
@@ -1018,35 +1348,59 @@ private:
     typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap;
     ShaderSourceMap m_shaderSourceMap;
 
+    struct ActiveShaderSymbolCounts {
+        Vector<GC3Dint> filteredToActualAttributeIndexMap;
+        Vector<GC3Dint> filteredToActualUniformIndexMap;
+
+        ActiveShaderSymbolCounts()
+        {
+        }
+
+        GC3Dint countForType(GC3Denum activeType)
+        {
+            ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS);
+            if (activeType == ACTIVE_ATTRIBUTES)
+                return filteredToActualAttributeIndexMap.size();
+
+            return filteredToActualUniformIndexMap.size();
+        }
+    };
+    typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap;
+    ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
+
+    typedef HashMap<String, String> HashedSymbolMap;
+    HashedSymbolMap m_possiblyUnusedAttributeMap;
+
     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
+    String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name);
     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name);
 
     ANGLEWebKitBridge m_compiler;
-#endif
 
-#if PLATFORM(BLACKBERRY) || (PLATFORM(QT) && defined(QT_OPENGL_ES_2)) || ((PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN)) && USE(OPENGL_ES_2))
+    std::unique_ptr<ShaderNameHash> nameHashMapForShaders;
+
+#if ((PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN)) && USE(OPENGL_ES_2))
     friend class Extensions3DOpenGLES;
-    OwnPtr<Extensions3DOpenGLES> m_extensions;
+    std::unique_ptr<Extensions3DOpenGLES> m_extensions;
 #else
     friend class Extensions3DOpenGL;
-    OwnPtr<Extensions3DOpenGL> m_extensions;
+    std::unique_ptr<Extensions3DOpenGL> m_extensions;
 #endif
     friend class Extensions3DOpenGLCommon;
 
     Attributes m_attrs;
     RenderStyle m_renderStyle;
-    Vector<Vector<float> > m_vertexArray;
+    Vector<Vector<float>> m_vertexArray;
 
     GC3Duint m_texture;
-#if !PLATFORM(BLACKBERRY)
     GC3Duint m_compositorTexture;
-#endif
     GC3Duint m_fbo;
+#if USE(COORDINATED_GRAPHICS_THREADED)
+    GC3Duint m_intermediateTexture;
+#endif
 
-#if !PLATFORM(BLACKBERRY)
     GC3Duint m_depthBuffer;
     GC3Duint m_stencilBuffer;
-#endif
     GC3Duint m_depthStencilBuffer;
 
     bool m_layerComposited;
@@ -1074,14 +1428,12 @@ private:
     // Errors raised by synthesizeGLError().
     ListHashSet<GC3Denum> m_syntheticErrors;
 
-#if PLATFORM(BLACKBERRY)
-    bool m_isImaginationHardware;
-#endif
-
-#if !PLATFORM(BLACKBERRY)
     friend class GraphicsContext3DPrivate;
-    OwnPtr<GraphicsContext3DPrivate> m_private;
-#endif
+    std::unique_ptr<GraphicsContext3DPrivate> m_private;
+    
+    WebGLRenderingContextBase* m_webglContext;
+
+    bool m_isForWebGL2 { false };
 };
 
 } // namespace WebCore