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