xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/TextureImpl.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2014 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 // TextureImpl.h: Defines the abstract rx::TextureImpl classes.
8 
9 #ifndef LIBANGLE_RENDERER_TEXTUREIMPL_H_
10 #define LIBANGLE_RENDERER_TEXTUREIMPL_H_
11 
12 #include <stdint.h>
13 
14 #include "angle_gl.h"
15 #include "common/angleutils.h"
16 #include "libANGLE/Error.h"
17 #include "libANGLE/ImageIndex.h"
18 #include "libANGLE/Stream.h"
19 #include "libANGLE/Texture.h"
20 #include "libANGLE/angletypes.h"
21 #include "libANGLE/renderer/FramebufferAttachmentObjectImpl.h"
22 
23 namespace egl
24 {
25 class Surface;
26 class Image;
27 }  // namespace egl
28 
29 namespace gl
30 {
31 class Framebuffer;
32 class MemoryObject;
33 struct PixelUnpackState;
34 class TextureState;
35 }  // namespace gl
36 
37 namespace rx
38 {
39 class ContextImpl;
40 
41 class TextureImpl : public FramebufferAttachmentObjectImpl
42 {
43   public:
44     TextureImpl(const gl::TextureState &state);
45     ~TextureImpl() override;
46 
47     virtual void onDestroy(const gl::Context *context);
48 
49     virtual angle::Result setImage(const gl::Context *context,
50                                    const gl::ImageIndex &index,
51                                    GLenum internalFormat,
52                                    const gl::Extents &size,
53                                    GLenum format,
54                                    GLenum type,
55                                    const gl::PixelUnpackState &unpack,
56                                    gl::Buffer *unpackBuffer,
57                                    const uint8_t *pixels)    = 0;
58     virtual angle::Result setSubImage(const gl::Context *context,
59                                       const gl::ImageIndex &index,
60                                       const gl::Box &area,
61                                       GLenum format,
62                                       GLenum type,
63                                       const gl::PixelUnpackState &unpack,
64                                       gl::Buffer *unpackBuffer,
65                                       const uint8_t *pixels) = 0;
66 
67     virtual angle::Result setCompressedImage(const gl::Context *context,
68                                              const gl::ImageIndex &index,
69                                              GLenum internalFormat,
70                                              const gl::Extents &size,
71                                              const gl::PixelUnpackState &unpack,
72                                              size_t imageSize,
73                                              const uint8_t *pixels)    = 0;
74     virtual angle::Result setCompressedSubImage(const gl::Context *context,
75                                                 const gl::ImageIndex &index,
76                                                 const gl::Box &area,
77                                                 GLenum format,
78                                                 const gl::PixelUnpackState &unpack,
79                                                 size_t imageSize,
80                                                 const uint8_t *pixels) = 0;
81 
82     virtual angle::Result copyImage(const gl::Context *context,
83                                     const gl::ImageIndex &index,
84                                     const gl::Rectangle &sourceArea,
85                                     GLenum internalFormat,
86                                     gl::Framebuffer *source)    = 0;
87     virtual angle::Result copySubImage(const gl::Context *context,
88                                        const gl::ImageIndex &index,
89                                        const gl::Offset &destOffset,
90                                        const gl::Rectangle &sourceArea,
91                                        gl::Framebuffer *source) = 0;
92 
93     virtual angle::Result copyTexture(const gl::Context *context,
94                                       const gl::ImageIndex &index,
95                                       GLenum internalFormat,
96                                       GLenum type,
97                                       GLint sourceLevel,
98                                       bool unpackFlipY,
99                                       bool unpackPremultiplyAlpha,
100                                       bool unpackUnmultiplyAlpha,
101                                       const gl::Texture *source);
102     virtual angle::Result copySubTexture(const gl::Context *context,
103                                          const gl::ImageIndex &index,
104                                          const gl::Offset &destOffset,
105                                          GLint sourceLevel,
106                                          const gl::Box &sourceBox,
107                                          bool unpackFlipY,
108                                          bool unpackPremultiplyAlpha,
109                                          bool unpackUnmultiplyAlpha,
110                                          const gl::Texture *source);
111 
112     virtual angle::Result copyRenderbufferSubData(const gl::Context *context,
113                                                   const gl::Renderbuffer *srcBuffer,
114                                                   GLint srcLevel,
115                                                   GLint srcX,
116                                                   GLint srcY,
117                                                   GLint srcZ,
118                                                   GLint dstLevel,
119                                                   GLint dstX,
120                                                   GLint dstY,
121                                                   GLint dstZ,
122                                                   GLsizei srcWidth,
123                                                   GLsizei srcHeight,
124                                                   GLsizei srcDepth);
125 
126     virtual angle::Result copyTextureSubData(const gl::Context *context,
127                                              const gl::Texture *srcTexture,
128                                              GLint srcLevel,
129                                              GLint srcX,
130                                              GLint srcY,
131                                              GLint srcZ,
132                                              GLint dstLevel,
133                                              GLint dstX,
134                                              GLint dstY,
135                                              GLint dstZ,
136                                              GLsizei srcWidth,
137                                              GLsizei srcHeight,
138                                              GLsizei srcDepth);
139 
140     virtual angle::Result copyCompressedTexture(const gl::Context *context,
141                                                 const gl::Texture *source);
142 
143     virtual angle::Result copy3DTexture(const gl::Context *context,
144                                         gl::TextureTarget target,
145                                         GLenum internalFormat,
146                                         GLenum type,
147                                         GLint sourceLevel,
148                                         GLint destLevel,
149                                         bool unpackFlipY,
150                                         bool unpackPremultiplyAlpha,
151                                         bool unpackUnmultiplyAlpha,
152                                         const gl::Texture *source);
153     virtual angle::Result copy3DSubTexture(const gl::Context *context,
154                                            const gl::TextureTarget target,
155                                            const gl::Offset &destOffset,
156                                            GLint sourceLevel,
157                                            GLint destLevel,
158                                            const gl::Box &srcBox,
159                                            bool unpackFlipY,
160                                            bool unpackPremultiplyAlpha,
161                                            bool unpackUnmultiplyAlpha,
162                                            const gl::Texture *source);
163 
164     virtual angle::Result setStorage(const gl::Context *context,
165                                      gl::TextureType type,
166                                      size_t levels,
167                                      GLenum internalFormat,
168                                      const gl::Extents &size) = 0;
169 
170     virtual angle::Result setStorageMultisample(const gl::Context *context,
171                                                 gl::TextureType type,
172                                                 GLsizei samples,
173                                                 GLint internalformat,
174                                                 const gl::Extents &size,
175                                                 bool fixedSampleLocations) = 0;
176 
177     virtual angle::Result setStorageAttribs(const gl::Context *context,
178                                             gl::TextureType type,
179                                             size_t levels,
180                                             GLint internalformat,
181                                             const gl::Extents &size,
182                                             const GLint *attribList);
183 
184     virtual angle::Result setStorageExternalMemory(const gl::Context *context,
185                                                    gl::TextureType type,
186                                                    size_t levels,
187                                                    GLenum internalFormat,
188                                                    const gl::Extents &size,
189                                                    gl::MemoryObject *memoryObject,
190                                                    GLuint64 offset,
191                                                    GLbitfield createFlags,
192                                                    GLbitfield usageFlags,
193                                                    const void *imageCreateInfoPNext) = 0;
194 
195     virtual angle::Result setImageExternal(const gl::Context *context,
196                                            const gl::ImageIndex &index,
197                                            GLenum internalFormat,
198                                            const gl::Extents &size,
199                                            GLenum format,
200                                            GLenum type);
201 
202     virtual angle::Result setEGLImageTarget(const gl::Context *context,
203                                             gl::TextureType type,
204                                             egl::Image *image) = 0;
205 
206     virtual angle::Result setImageExternal(const gl::Context *context,
207                                            gl::TextureType type,
208                                            egl::Stream *stream,
209                                            const egl::Stream::GLTextureDescription &desc) = 0;
210 
211     virtual angle::Result setBuffer(const gl::Context *context, GLenum internalFormat);
212 
213     virtual angle::Result generateMipmap(const gl::Context *context) = 0;
214 
215     virtual angle::Result clearImage(const gl::Context *context,
216                                      GLint level,
217                                      GLenum format,
218                                      GLenum type,
219                                      const uint8_t *data);
220     virtual angle::Result clearSubImage(const gl::Context *context,
221                                         GLint level,
222                                         const gl::Box &area,
223                                         GLenum format,
224                                         GLenum type,
225                                         const uint8_t *data);
226 
227     virtual angle::Result setBaseLevel(const gl::Context *context, GLuint baseLevel) = 0;
228 
229     virtual angle::Result bindTexImage(const gl::Context *context, egl::Surface *surface) = 0;
230     virtual angle::Result releaseTexImage(const gl::Context *context)                     = 0;
231 
232     virtual angle::Result onLabelUpdate(const gl::Context *context);
233 
234     // Override if accurate native memory size information is available
235     virtual GLint getMemorySize() const;
236     virtual GLint getLevelMemorySize(gl::TextureTarget target, GLint level);
237 
238     virtual GLint getNativeID() const;
239 
240     virtual GLint getImageCompressionRate(const gl::Context *context);
241     virtual GLint getFormatSupportedCompressionRates(const gl::Context *context,
242                                                      GLenum internalformat,
243                                                      GLsizei bufSize,
244                                                      GLint *rates);
245 
246     virtual angle::Result syncState(const gl::Context *context,
247                                     const gl::Texture::DirtyBits &dirtyBits,
248                                     gl::Command source) = 0;
249 
250     virtual GLenum getColorReadFormat(const gl::Context *context);
251     virtual GLenum getColorReadType(const gl::Context *context);
252 
253     virtual angle::Result getTexImage(const gl::Context *context,
254                                       const gl::PixelPackState &packState,
255                                       gl::Buffer *packBuffer,
256                                       gl::TextureTarget target,
257                                       GLint level,
258                                       GLenum format,
259                                       GLenum type,
260                                       void *pixels);
261 
262     virtual angle::Result getCompressedTexImage(const gl::Context *context,
263                                                 const gl::PixelPackState &packState,
264                                                 gl::Buffer *packBuffer,
265                                                 gl::TextureTarget target,
266                                                 GLint level,
267                                                 void *pixels);
268 
269     virtual GLint getRequiredExternalTextureImageUnits(const gl::Context *context);
270 
getState()271     const gl::TextureState &getState() const { return mState; }
272 
setContentsObservers(gl::TextureBufferContentsObservers * observers)273     void setContentsObservers(gl::TextureBufferContentsObservers *observers)
274     {
275         mBufferContentsObservers = observers;
276     }
277 
278   protected:
279     const gl::TextureState &mState;
280     gl::TextureBufferContentsObservers *mBufferContentsObservers = nullptr;
281 };
282 
283 }  // namespace rx
284 
285 #endif  // LIBANGLE_RENDERER_TEXTUREIMPL_H_
286