[Chromium] GL_EXT_occlusion_query_boolean and GL_CHROMIUM_command_buffer_query support.
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / Extensions3DChromium.h
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef Extensions3DChromium_h
27 #define Extensions3DChromium_h
28
29 #include "Extensions3D.h"
30
31 namespace WebCore {
32
33 class GraphicsContext3DPrivate;
34 class ImageBuffer;
35
36 class Extensions3DChromium : public Extensions3D {
37 public:
38     virtual ~Extensions3DChromium();
39
40     // Supported extensions:
41     //   GL_CHROMIUM_resource_safe  : indicating that textures/renderbuffers are always initialized before read/write.
42     //   GL_CHROMIUM_strict_attribs : indicating a GL error is generated for out-of-bounds buffer accesses.
43     //   GL_CHROMIUM_post_sub_buffer
44     //   GL_CHROMIUM_map_sub
45     //   GL_CHROMIUM_swapbuffers_complete_callback
46     //   GL_CHROMIUM_rate_limit_offscreen_context
47     //   GL_CHROMIUM_paint_framebuffer_canvas
48     //   GL_CHROMIUM_iosurface (Mac OS X specific)
49     //   GL_CHROMIUM_command_buffer_query
50     //   GL_ANGLE_texture_usage
51     //   GL_EXT_texture_storage
52     //   GL_EXT_occlusion_query_boolean
53
54     // Extensions3D methods.
55     virtual bool supports(const String&);
56     virtual void ensureEnabled(const String&);
57     virtual bool isEnabled(const String&);
58     virtual int getGraphicsResetStatusARB();
59     virtual void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
60     virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
61     virtual Platform3DObject createVertexArrayOES();
62     virtual void deleteVertexArrayOES(Platform3DObject);
63     virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
64     virtual void bindVertexArrayOES(Platform3DObject);
65     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
66
67     enum {
68         // GL_OES_EGL_image_external
69         GL_TEXTURE_EXTERNAL_OES = 0x8D65,
70
71         // GL_CHROMIUM_map_sub (enums inherited from GL_ARB_vertex_buffer_object)
72         READ_ONLY = 0x88B8,
73         WRITE_ONLY = 0x88B9,
74
75         // GL_ANGLE_texture_usage
76         GL_TEXTURE_USAGE_ANGLE = 0x93A2,
77         GL_FRAMEBUFFER_ATTACHMENT_ANGLE = 0x93A3,
78
79         // GL_EXT_texture_storage
80         BGRA8_EXT = 0x93A1,
81
82         // GL_EXT_occlusion_query_boolean
83         ANY_SAMPLES_PASSED_EXT = 0x8C2F,
84         ANY_SAMPLES_PASSED_CONSERVATIVE_EXT = 0x8D6A,
85         CURRENT_QUERY_EXT = 0x8865,
86         QUERY_RESULT_EXT = 0x8866,
87         QUERY_RESULT_AVAILABLE_EXT = 0x8867,
88
89         // GL_CHROMIUM_command_buffer_query
90         COMMANDS_ISSUED_CHROMIUM = 0x84F2
91     };
92
93     // GL_CHROMIUM_post_sub_buffer
94     void postSubBufferCHROMIUM(int x, int y, int width, int height);
95
96     // GL_CHROMIUM_map_sub
97     void* mapBufferSubDataCHROMIUM(unsigned target, int offset, int size, unsigned access);
98     void unmapBufferSubDataCHROMIUM(const void*);
99     void* mapTexSubImage2DCHROMIUM(unsigned target, int level, int xoffset, int yoffset, int width, int height, unsigned format, unsigned type, unsigned access);
100     void unmapTexSubImage2DCHROMIUM(const void*);
101
102     // GL_CHROMIUM_set_visibility
103     void setVisibilityCHROMIUM(bool);
104
105     // GL_EXT_discard_framebuffer
106     virtual void discardFramebufferEXT(GC3Denum target, GC3Dsizei numAttachments, const GC3Denum* attachments);
107     virtual void ensureFramebufferCHROMIUM();
108
109     // GL_CHROMIUM_gpu_memory_manager
110     struct GpuMemoryAllocationCHROMIUM {
111         size_t gpuResourceSizeInBytes;
112         bool suggestHaveBackbuffer;
113
114         GpuMemoryAllocationCHROMIUM(size_t gpuResourceSizeInBytes, bool suggestHaveBackbuffer)
115             : gpuResourceSizeInBytes(gpuResourceSizeInBytes)
116             , suggestHaveBackbuffer(suggestHaveBackbuffer)
117         {
118         }
119     };
120     class GpuMemoryAllocationChangedCallbackCHROMIUM {
121     public:
122
123         virtual void onGpuMemoryAllocationChanged(GpuMemoryAllocationCHROMIUM) = 0;
124         virtual ~GpuMemoryAllocationChangedCallbackCHROMIUM() { }
125     };
126     void setGpuMemoryAllocationChangedCallbackCHROMIUM(PassOwnPtr<GpuMemoryAllocationChangedCallbackCHROMIUM>);
127
128     // GL_CHROMIUM_swapbuffers_complete_callback
129     class SwapBuffersCompleteCallbackCHROMIUM {
130     public:
131         virtual void onSwapBuffersComplete() = 0;
132         virtual ~SwapBuffersCompleteCallbackCHROMIUM() { }
133     };
134     void setSwapBuffersCompleteCallbackCHROMIUM(PassOwnPtr<SwapBuffersCompleteCallbackCHROMIUM>);
135
136     // GL_CHROMIUM_rate_limit_offscreen_context
137     void rateLimitOffscreenContextCHROMIUM();
138
139     // GL_CHROMIUM_paint_framebuffer_canvas
140     void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*);
141
142     // GL_CHROMIUM_iosurface
143     // To avoid needing to expose extraneous enums, assumes internal format
144     // RGBA, format BGRA, and type UNSIGNED_INT_8_8_8_8_REV.
145     void texImageIOSurface2DCHROMIUM(unsigned target, int width, int height, uint32_t ioSurfaceId, unsigned plane);
146
147     // GL_EXT_texture_storage
148     void texStorage2DEXT(unsigned target, int levels, unsigned internalformat, int width, int height);
149
150     // GL_EXT_occlusion_query
151     Platform3DObject createQueryEXT();
152     void deleteQueryEXT(Platform3DObject);
153     GC3Dboolean isQueryEXT(Platform3DObject);
154     void beginQueryEXT(GC3Denum, Platform3DObject);
155     void endQueryEXT(GC3Denum);
156     void getQueryivEXT(GC3Denum, GC3Denum, GC3Dint*);
157     void getQueryObjectuivEXT(Platform3DObject, GC3Denum, GC3Duint*);
158
159 private:
160     // Instances of this class are strictly owned by the GraphicsContext3D implementation and do not
161     // need to be instantiated by any other code.
162     friend class GraphicsContext3DPrivate;
163     explicit Extensions3DChromium(GraphicsContext3DPrivate*);
164
165     // Weak pointer back to GraphicsContext3DPrivate
166     GraphicsContext3DPrivate* m_private;
167 };
168
169 } // namespace WebCore
170
171 #endif // Extensions3DChromium_h