66200c1633f430d353c7bf227f886c38f098da0a
[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_ANGLE_texture_usage
50     //   GL_EXT_texture_storage
51
52     // Extensions3D methods.
53     virtual bool supports(const String&);
54     virtual void ensureEnabled(const String&);
55     virtual bool isEnabled(const String&);
56     virtual int getGraphicsResetStatusARB();
57     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);
58     virtual void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
59     virtual Platform3DObject createVertexArrayOES();
60     virtual void deleteVertexArrayOES(Platform3DObject);
61     virtual GC3Dboolean isVertexArrayOES(Platform3DObject);
62     virtual void bindVertexArrayOES(Platform3DObject);
63     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
64
65     enum {
66         // GL_OES_EGL_image_external
67         GL_TEXTURE_EXTERNAL_OES = 0x8D65,
68
69         // GL_CHROMIUM_map_sub (enums inherited from GL_ARB_vertex_buffer_object)
70         READ_ONLY = 0x88B8,
71         WRITE_ONLY = 0x88B9,
72
73         // GL_ANGLE_texture_usage
74         GL_TEXTURE_USAGE_ANGLE = 0x93A2,
75         GL_FRAMEBUFFER_ATTACHMENT_ANGLE = 0x93A3,
76
77         // GL_EXT_texture_storage
78         BGRA8_EXT = 0x93A1
79     };
80
81     // GL_CHROMIUM_post_sub_buffer
82     void postSubBufferCHROMIUM(int x, int y, int width, int height);
83
84     // GL_CHROMIUM_map_sub
85     void* mapBufferSubDataCHROMIUM(unsigned target, int offset, int size, unsigned access);
86     void unmapBufferSubDataCHROMIUM(const void*);
87     void* mapTexSubImage2DCHROMIUM(unsigned target, int level, int xoffset, int yoffset, int width, int height, unsigned format, unsigned type, unsigned access);
88     void unmapTexSubImage2DCHROMIUM(const void*);
89
90     // GL_CHROMIUM_set_visibility
91     void setVisibilityCHROMIUM(bool);
92
93     // GL_EXT_discard_framebuffer
94     virtual void discardFramebufferEXT(GC3Denum target, GC3Dsizei numAttachments, const GC3Denum* attachments);
95     virtual void ensureFramebufferCHROMIUM();
96
97     // GL_CHROMIUM_gpu_memory_manager
98     struct GpuMemoryAllocationCHROMIUM {
99         size_t gpuResourceSizeInBytes;
100         bool suggestHaveBackbuffer;
101
102         GpuMemoryAllocationCHROMIUM(size_t gpuResourceSizeInBytes, bool suggestHaveBackbuffer)
103             : gpuResourceSizeInBytes(gpuResourceSizeInBytes)
104             , suggestHaveBackbuffer(suggestHaveBackbuffer)
105         {
106         }
107     };
108     class GpuMemoryAllocationChangedCallbackCHROMIUM {
109     public:
110
111         virtual void onGpuMemoryAllocationChanged(GpuMemoryAllocationCHROMIUM) = 0;
112         virtual ~GpuMemoryAllocationChangedCallbackCHROMIUM() { }
113     };
114     void setGpuMemoryAllocationChangedCallbackCHROMIUM(PassOwnPtr<GpuMemoryAllocationChangedCallbackCHROMIUM>);
115
116     // GL_CHROMIUM_swapbuffers_complete_callback
117     class SwapBuffersCompleteCallbackCHROMIUM {
118     public:
119         virtual void onSwapBuffersComplete() = 0;
120         virtual ~SwapBuffersCompleteCallbackCHROMIUM() { }
121     };
122     void setSwapBuffersCompleteCallbackCHROMIUM(PassOwnPtr<SwapBuffersCompleteCallbackCHROMIUM>);
123
124     // GL_CHROMIUM_rate_limit_offscreen_context
125     void rateLimitOffscreenContextCHROMIUM();
126
127     // GL_CHROMIUM_paint_framebuffer_canvas
128     void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*);
129
130     // GL_CHROMIUM_iosurface
131     // To avoid needing to expose extraneous enums, assumes internal format
132     // RGBA, format BGRA, and type UNSIGNED_INT_8_8_8_8_REV.
133     void texImageIOSurface2DCHROMIUM(unsigned target, int width, int height, uint32_t ioSurfaceId, unsigned plane);
134
135     // GL_EXT_texture_storage
136     void texStorage2DEXT(unsigned target, int levels, unsigned internalformat, int width, int height);
137
138 private:
139     // Instances of this class are strictly owned by the GraphicsContext3D implementation and do not
140     // need to be instantiated by any other code.
141     friend class GraphicsContext3DPrivate;
142     explicit Extensions3DChromium(GraphicsContext3DPrivate*);
143
144     // Weak pointer back to GraphicsContext3DPrivate
145     GraphicsContext3DPrivate* m_private;
146 };
147
148 } // namespace WebCore
149
150 #endif // Extensions3DChromium_h