[ANGLE - iOS] fast/canvas/webgl/uninitialized-test.html is still failing
[WebKit-https.git] / Source / ThirdParty / ANGLE / src / libANGLE / renderer / gl / BlitGL.h
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // BlitGL.h: Defines the BlitGL class, a helper for blitting textures
8
9 #ifndef LIBANGLE_RENDERER_GL_BLITGL_H_
10 #define LIBANGLE_RENDERER_GL_BLITGL_H_
11
12 #include "angle_gl.h"
13 #include "common/angleutils.h"
14 #include "libANGLE/Error.h"
15 #include "libANGLE/angletypes.h"
16
17 #include <map>
18
19 namespace angle
20 {
21 struct FeaturesGL;
22 }  // namespace angle
23
24 namespace gl
25 {
26 class Framebuffer;
27 class ImageIndex;
28 }  // namespace gl
29
30 namespace rx
31 {
32
33 class FramebufferGL;
34 class FunctionsGL;
35 class RenderbufferGL;
36 class StateManagerGL;
37 class TextureGL;
38
39 class BlitGL : angle::NonCopyable
40 {
41   public:
42     BlitGL(const FunctionsGL *functions,
43            const angle::FeaturesGL &features,
44            StateManagerGL *stateManager);
45     ~BlitGL();
46
47     angle::Result copyImageToLUMAWorkaroundTexture(const gl::Context *context,
48                                                    GLuint texture,
49                                                    gl::TextureType textureType,
50                                                    gl::TextureTarget target,
51                                                    GLenum lumaFormat,
52                                                    size_t level,
53                                                    const gl::Rectangle &sourceArea,
54                                                    GLenum internalFormat,
55                                                    gl::Framebuffer *source);
56
57     angle::Result copySubImageToLUMAWorkaroundTexture(const gl::Context *context,
58                                                       GLuint texture,
59                                                       gl::TextureType textureType,
60                                                       gl::TextureTarget target,
61                                                       GLenum lumaFormat,
62                                                       size_t level,
63                                                       const gl::Offset &destOffset,
64                                                       const gl::Rectangle &sourceArea,
65                                                       gl::Framebuffer *source);
66
67     angle::Result blitColorBufferWithShader(const gl::Context *context,
68                                             const gl::Framebuffer *source,
69                                             const gl::Framebuffer *dest,
70                                             const gl::Rectangle &sourceArea,
71                                             const gl::Rectangle &destArea,
72                                             GLenum filter,
73                                             bool writeAlpha);
74
75     angle::Result blitColorBufferWithShader(const gl::Context *context,
76                                             const gl::Framebuffer *source,
77                                             const GLuint destFramebuffer,
78                                             const gl::Rectangle &sourceArea,
79                                             const gl::Rectangle &destArea,
80                                             GLenum filter,
81                                             bool writeAlpha);
82
83     angle::Result blitColorBufferWithShader(const gl::Context *context,
84                                             const gl::Framebuffer *source,
85                                             const GLuint destTexture,
86                                             const gl::TextureTarget destTarget,
87                                             const size_t destLevel,
88                                             const gl::Rectangle &sourceArea,
89                                             const gl::Rectangle &destArea,
90                                             GLenum filter,
91                                             bool writeAlpha);
92
93     angle::Result copySubTexture(const gl::Context *context,
94                                  TextureGL *source,
95                                  size_t sourceLevel,
96                                  GLenum sourceComponentType,
97                                  GLuint destID,
98                                  gl::TextureTarget destTarget,
99                                  size_t destLevel,
100                                  GLenum destComponentType,
101                                  const gl::Extents &sourceSize,
102                                  const gl::Rectangle &sourceArea,
103                                  const gl::Offset &destOffset,
104                                  bool needsLumaWorkaround,
105                                  GLenum lumaFormat,
106                                  bool unpackFlipY,
107                                  bool unpackPremultiplyAlpha,
108                                  bool unpackUnmultiplyAlpha,
109                                  bool *copySucceededOut);
110
111     angle::Result copySubTextureCPUReadback(const gl::Context *context,
112                                             TextureGL *source,
113                                             size_t sourceLevel,
114                                             GLenum sourceSizedInternalFormat,
115                                             TextureGL *dest,
116                                             gl::TextureTarget destTarget,
117                                             size_t destLevel,
118                                             GLenum destFormat,
119                                             GLenum destType,
120                                             const gl::Extents &sourceSize,
121                                             const gl::Rectangle &sourceArea,
122                                             const gl::Offset &destOffset,
123                                             bool needsLumaWorkaround,
124                                             GLenum lumaFormat,
125                                             bool unpackFlipY,
126                                             bool unpackPremultiplyAlpha,
127                                             bool unpackUnmultiplyAlpha);
128
129     angle::Result copyTexSubImage(const gl::Context *context,
130                                   TextureGL *source,
131                                   size_t sourceLevel,
132                                   TextureGL *dest,
133                                   gl::TextureTarget destTarget,
134                                   size_t destLevel,
135                                   const gl::Rectangle &sourceArea,
136                                   const gl::Offset &destOffset,
137                                   bool *copySucceededOut);
138
139     angle::Result clearRenderableTexture(const gl::Context *context,
140                                          TextureGL *source,
141                                          GLenum sizedInternalFormat,
142                                          int numTextureLayers,
143                                          const gl::ImageIndex &imageIndex,
144                                          bool *clearSucceededOut);
145
146     angle::Result clearRenderbuffer(const gl::Context *context,
147                                     RenderbufferGL *source,
148                                     GLenum sizedInternalFormat);
149
150     angle::Result clearFramebuffer(const gl::Context *context, FramebufferGL *source);
151
152     angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context,
153                                                    GLuint texture,
154                                                    gl::TextureTarget target,
155                                                    size_t level);
156
157     angle::Result initializeResources(const gl::Context *context);
158
159   private:
160     angle::Result orphanScratchTextures(const gl::Context *context);
161     angle::Result setScratchTextureParameter(const gl::Context *context,
162                                              GLenum param,
163                                              GLenum value);
164
165     const FunctionsGL *mFunctions;
166     const angle::FeaturesGL &mFeatures;
167     StateManagerGL *mStateManager;
168
169     struct BlitProgram
170     {
171         GLuint program                = 0;
172         GLint sourceTextureLocation   = -1;
173         GLint scaleLocation           = -1;
174         GLint offsetLocation          = -1;
175         GLint multiplyAlphaLocation   = -1;
176         GLint unMultiplyAlphaLocation = -1;
177     };
178
179     angle::Result getBlitProgram(const gl::Context *context,
180                                  gl::TextureType sourceTextureType,
181                                  GLenum sourceComponentType,
182                                  GLenum destComponentType,
183                                  BlitProgram **program);
184
185     // SourceType, SourceComponentType, DestComponentType
186     using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
187     std::map<BlitProgramType, BlitProgram> mBlitPrograms;
188
189     GLuint mScratchTextures[2];
190     GLuint mScratchFBO;
191
192     GLuint mVAO;
193     GLuint mVertexBuffer;
194 };
195 }  // namespace rx
196
197 #endif  // LIBANGLE_RENDERER_GL_BLITGL_H_