Bug 1797755 - Part 5: Use a single initial mark stack size regardless of whether...
[gecko.git] / gfx / gl / GLReadTexImageHelper.h
blob3f5ad6bd1ec64dbada1144063d63134d8e5f7950
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GLREADTEXIMAGEHELPER_H_
8 #define GLREADTEXIMAGEHELPER_H_
10 #include "GLContextTypes.h"
11 #include "mozilla/Attributes.h"
12 #include "nsSize.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/gfx/Types.h"
16 namespace mozilla {
18 namespace gfx {
19 class DataSourceSurface;
20 } // namespace gfx
22 namespace gl {
24 // Returns true if the `dest{Format,Type}` are the same as the
25 // `read{Format,Type}`.
26 bool GetActualReadFormats(GLContext* gl, GLenum destFormat, GLenum destType,
27 GLenum* out_readFormat, GLenum* out_readType);
29 void ReadPixelsIntoDataSurface(GLContext* aGL,
30 gfx::DataSourceSurface* aSurface);
32 already_AddRefed<gfx::DataSourceSurface> ReadBackSurface(
33 GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat);
35 already_AddRefed<gfx::DataSourceSurface> YInvertImageSurface(
36 gfx::DataSourceSurface* aSurf, uint32_t aStride);
38 void SwapRAndBComponents(gfx::DataSourceSurface* surf);
40 class GLReadTexImageHelper final {
41 // The GLContext is the sole owner of the GLBlitHelper.
42 GLContext* mGL;
44 GLuint mPrograms[4];
46 GLuint TextureImageProgramFor(GLenum aTextureTarget, int aShader);
48 bool DidGLErrorOccur(const char* str);
50 public:
51 explicit GLReadTexImageHelper(GLContext* gl);
52 ~GLReadTexImageHelper();
54 /**
55 * Read the image data contained in aTexture, and return it as an
56 * ImageSurface. If GL_RGBA is given as the format, a
57 * SurfaceFormat::A8R8G8B8_UINT32 surface is returned. Not implemented yet: If
58 * GL_RGB is given as the format, a SurfaceFormat::X8R8G8B8_UINT32 surface is
59 * returned. If GL_LUMINANCE is given as the format, a SurfaceFormat::A8
60 * surface is returned.
62 * THIS IS EXPENSIVE. It is ridiculously expensive. Only do this
63 * if you absolutely positively must, and never in any performance
64 * critical path.
66 * NOTE: aShaderProgram is really mozilla::layers::ShaderProgramType. It is
67 * passed as int to eliminate including LayerManagerOGLProgram.h here.
69 already_AddRefed<gfx::DataSourceSurface> ReadTexImage(
70 GLuint aTextureId, GLenum aTextureTarget, const gfx::IntSize& aSize,
71 /* ShaderProgramType */ int aShaderProgram, bool aYInvert = false);
73 bool ReadTexImage(gfx::DataSourceSurface* aDest, GLuint aTextureId,
74 GLenum aTextureTarget, const gfx::IntSize& aSize,
75 int aShaderProgram, bool aYInvert = false);
78 } // namespace gl
79 } // namespace mozilla
81 #endif