xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/BlitGL.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 #include "libANGLE/renderer/gl/formatutilsgl.h"
17 
18 #include <map>
19 
20 namespace angle
21 {
22 struct FeaturesGL;
23 }  // namespace angle
24 
25 namespace gl
26 {
27 class Framebuffer;
28 class ImageIndex;
29 }  // namespace gl
30 
31 namespace rx
32 {
33 
34 class FramebufferGL;
35 class FunctionsGL;
36 class RenderbufferGL;
37 class StateManagerGL;
38 class TextureGL;
39 struct VertexArrayStateGL;
40 
41 class BlitGL : angle::NonCopyable
42 {
43   public:
44     BlitGL(const FunctionsGL *functions,
45            const angle::FeaturesGL &features,
46            StateManagerGL *stateManager);
47     ~BlitGL();
48 
49     angle::Result copyImageToLUMAWorkaroundTexture(const gl::Context *context,
50                                                    GLuint texture,
51                                                    gl::TextureType textureType,
52                                                    gl::TextureTarget target,
53                                                    GLenum lumaFormat,
54                                                    size_t level,
55                                                    const gl::Rectangle &sourceArea,
56                                                    GLenum internalFormat,
57                                                    gl::Framebuffer *source);
58 
59     angle::Result copySubImageToLUMAWorkaroundTexture(const gl::Context *context,
60                                                       GLuint texture,
61                                                       gl::TextureType textureType,
62                                                       gl::TextureTarget target,
63                                                       GLenum lumaFormat,
64                                                       size_t level,
65                                                       const gl::Offset &destOffset,
66                                                       const gl::Rectangle &sourceArea,
67                                                       gl::Framebuffer *source);
68 
69     angle::Result blitColorBufferWithShader(const gl::Context *context,
70                                             const gl::Framebuffer *source,
71                                             const gl::Framebuffer *dest,
72                                             const gl::Rectangle &sourceArea,
73                                             const gl::Rectangle &destArea,
74                                             GLenum filter,
75                                             bool writeAlpha);
76 
77     angle::Result blitColorBufferWithShader(const gl::Context *context,
78                                             const gl::Framebuffer *source,
79                                             const GLuint destFramebuffer,
80                                             const gl::Rectangle &sourceArea,
81                                             const gl::Rectangle &destArea,
82                                             GLenum filter,
83                                             bool writeAlpha);
84 
85     angle::Result blitColorBufferWithShader(const gl::Context *context,
86                                             const gl::Framebuffer *source,
87                                             const GLuint destTexture,
88                                             const gl::TextureTarget destTarget,
89                                             const size_t destLevel,
90                                             const gl::Rectangle &sourceArea,
91                                             const gl::Rectangle &destArea,
92                                             GLenum filter,
93                                             bool writeAlpha);
94 
95     angle::Result copySubTexture(const gl::Context *context,
96                                  TextureGL *source,
97                                  size_t sourceLevel,
98                                  GLenum sourceComponentType,
99                                  GLuint destID,
100                                  gl::TextureTarget destTarget,
101                                  size_t destLevel,
102                                  GLenum destComponentType,
103                                  const gl::Extents &sourceSize,
104                                  const gl::Rectangle &sourceArea,
105                                  const gl::Offset &destOffset,
106                                  bool needsLumaWorkaround,
107                                  GLenum lumaFormat,
108                                  bool unpackFlipY,
109                                  bool unpackPremultiplyAlpha,
110                                  bool unpackUnmultiplyAlpha,
111                                  bool transformLinearToSrgb,
112                                  bool *copySucceededOut);
113 
114     angle::Result copySubTextureCPUReadback(const gl::Context *context,
115                                             TextureGL *source,
116                                             size_t sourceLevel,
117                                             GLenum sourceSizedInternalFormat,
118                                             TextureGL *dest,
119                                             gl::TextureTarget destTarget,
120                                             size_t destLevel,
121                                             GLenum destFormat,
122                                             GLenum destType,
123                                             const gl::Extents &sourceSize,
124                                             const gl::Rectangle &sourceArea,
125                                             const gl::Offset &destOffset,
126                                             bool needsLumaWorkaround,
127                                             GLenum lumaFormat,
128                                             bool unpackFlipY,
129                                             bool unpackPremultiplyAlpha,
130                                             bool unpackUnmultiplyAlpha);
131 
132     angle::Result copyTexSubImage(const gl::Context *context,
133                                   TextureGL *source,
134                                   size_t sourceLevel,
135                                   TextureGL *dest,
136                                   gl::TextureTarget destTarget,
137                                   size_t destLevel,
138                                   const gl::Rectangle &sourceArea,
139                                   const gl::Offset &destOffset,
140                                   bool *copySucceededOut);
141 
142     angle::Result clearRenderableTexture(const gl::Context *context,
143                                          TextureGL *source,
144                                          GLenum sizedInternalFormat,
145                                          int numTextureLayers,
146                                          const gl::ImageIndex &imageIndex,
147                                          bool *clearSucceededOut);
148 
149     angle::Result clearRenderbuffer(const gl::Context *context,
150                                     RenderbufferGL *source,
151                                     GLenum sizedInternalFormat);
152 
153     angle::Result clearFramebuffer(const gl::Context *context,
154                                    const gl::DrawBufferMask &colorAttachments,
155                                    bool depthClear,
156                                    bool stencilClear,
157                                    FramebufferGL *source);
158 
159     angle::Result clearRenderableTextureAlphaToOne(const gl::Context *context,
160                                                    GLuint texture,
161                                                    gl::TextureTarget target,
162                                                    size_t level);
163 
164     angle::Result generateMipmap(const gl::Context *context,
165                                  TextureGL *source,
166                                  GLuint baseLevel,
167                                  GLuint levelCount,
168                                  const gl::Extents &sourceBaseLevelSize,
169                                  const nativegl::TexImageFormat &format);
170     angle::Result generateSRGBMipmap(const gl::Context *context,
171                                      TextureGL *source,
172                                      GLuint baseLevel,
173                                      GLuint levelCount,
174                                      const gl::Extents &sourceBaseLevelSize);
175 
176     angle::Result initializeResources(const gl::Context *context);
177 
178   private:
179     angle::Result orphanScratchTextures(const gl::Context *context);
180     angle::Result setScratchTextureParameter(const gl::Context *context,
181                                              GLenum param,
182                                              GLenum value);
183     angle::Result setVAOState(const gl::Context *context);
184     angle::Result initializeVAOState(const gl::Context *context);
185 
186     const FunctionsGL *mFunctions;
187     const angle::FeaturesGL &mFeatures;
188     StateManagerGL *mStateManager;
189 
190     struct BlitProgram
191     {
192         GLuint program                      = 0;
193         GLint sourceTextureLocation         = -1;
194         GLint scaleLocation                 = -1;
195         GLint offsetLocation                = -1;
196         GLint multiplyAlphaLocation         = -1;
197         GLint unMultiplyAlphaLocation       = -1;
198         GLint transformLinearToSrgbLocation = -1;
199     };
200 
201     angle::Result getBlitProgram(const gl::Context *context,
202                                  gl::TextureType sourceTextureType,
203                                  GLenum sourceComponentType,
204                                  GLenum destComponentType,
205                                  BlitProgram **program);
206 
207     bool mResourcesInitialized = false;
208 
209     // SourceType, SourceComponentType, DestComponentType
210     using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
211     std::map<BlitProgramType, BlitProgram> mBlitPrograms;
212 
213     GLuint mScratchTextures[2] = {0};
214     GLuint mScratchFBO         = 0;
215 
216     GLuint mVAO                   = 0;
217     VertexArrayStateGL *mVAOState = nullptr;
218     bool mOwnsVAOState            = false;
219 
220     const GLuint mTexcoordAttribLocation = 0;
221     GLuint mVertexBuffer                 = 0;
222 
223     nativegl::TexImageFormat mSRGBMipmapGenerationFormat;
224 };
225 }  // namespace rx
226 
227 #endif  // LIBANGLE_RENDERER_GL_BLITGL_H_
228