c1fa3249f506d68ba03162cb104662595ac3f554
[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 copySubTexture(const gl::Context *context,
76                                  TextureGL *source,
77                                  size_t sourceLevel,
78                                  GLenum sourceComponentType,
79                                  GLuint destID,
80                                  gl::TextureTarget destTarget,
81                                  size_t destLevel,
82                                  GLenum destComponentType,
83                                  const gl::Extents &sourceSize,
84                                  const gl::Rectangle &sourceArea,
85                                  const gl::Offset &destOffset,
86                                  bool needsLumaWorkaround,
87                                  GLenum lumaFormat,
88                                  bool unpackFlipY,
89                                  bool unpackPremultiplyAlpha,
90                                  bool unpackUnmultiplyAlpha,
91                                  bool *copySucceededOut);
92
93     angle::Result copySubTextureCPUReadback(const gl::Context *context,
94                                             TextureGL *source,
95                                             size_t sourceLevel,
96                                             GLenum sourceSizedInternalFormat,
97                                             TextureGL *dest,
98                                             gl::TextureTarget destTarget,
99                                             size_t destLevel,
100                                             GLenum destFormat,
101                                             GLenum destType,
102                                             const gl::Extents &sourceSize,
103                                             const gl::Rectangle &sourceArea,
104                                             const gl::Offset &destOffset,
105                                             bool needsLumaWorkaround,
106                                             GLenum lumaFormat,
107                                             bool unpackFlipY,
108                                             bool unpackPremultiplyAlpha,
109                                             bool unpackUnmultiplyAlpha);
110
111     angle::Result copyTexSubImage(const gl::Context *context,
112                                   TextureGL *source,
113                                   size_t sourceLevel,
114                                   TextureGL *dest,
115                                   gl::TextureTarget destTarget,
116                                   size_t destLevel,
117                                   const gl::Rectangle &sourceArea,
118                                   const gl::Offset &destOffset,
119                                   bool *copySucceededOut);
120
121     angle::Result clearRenderableTexture(const gl::Context *context,
122                                          TextureGL *source,
123                                          GLenum sizedInternalFormat,
124                                          int numTextureLayers,
125                                          const gl::ImageIndex &imageIndex,
126                                          bool *clearSucceededOut);
127
128     angle::Result clearRenderbuffer(const gl::Context *context,
129                                     RenderbufferGL *source,
130                                     GLenum sizedInternalFormat);
131
132     angle::Result clearFramebuffer(const gl::Context *context, FramebufferGL *source);
133
134     angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context,
135                                                    GLuint texture,
136                                                    gl::TextureTarget target,
137                                                    size_t level);
138
139     angle::Result initializeResources(const gl::Context *context);
140
141   private:
142     angle::Result orphanScratchTextures(const gl::Context *context);
143     angle::Result setScratchTextureParameter(const gl::Context *context,
144                                              GLenum param,
145                                              GLenum value);
146
147     const FunctionsGL *mFunctions;
148     const angle::FeaturesGL &mFeatures;
149     StateManagerGL *mStateManager;
150
151     struct BlitProgram
152     {
153         GLuint program                = 0;
154         GLint sourceTextureLocation   = -1;
155         GLint scaleLocation           = -1;
156         GLint offsetLocation          = -1;
157         GLint multiplyAlphaLocation   = -1;
158         GLint unMultiplyAlphaLocation = -1;
159     };
160
161     angle::Result getBlitProgram(const gl::Context *context,
162                                  gl::TextureType sourceTextureType,
163                                  GLenum sourceComponentType,
164                                  GLenum destComponentType,
165                                  BlitProgram **program);
166
167     // SourceType, SourceComponentType, DestComponentType
168     using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
169     std::map<BlitProgramType, BlitProgram> mBlitPrograms;
170
171     GLuint mScratchTextures[2];
172     GLuint mScratchFBO;
173
174     GLuint mVAO;
175     GLuint mVertexBuffer;
176 };
177 }  // namespace rx
178
179 #endif  // LIBANGLE_RENDERER_GL_BLITGL_H_