1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef GLUploadHelpers_h_ 7 #define GLUploadHelpers_h_ 8 9 #include "GLDefs.h" 10 #include "mozilla/gfx/Types.h" 11 #include "nsPoint.h" 12 #include "nsRegionFwd.h" 13 14 namespace mozilla { 15 16 namespace gfx { 17 class DataSourceSurface; 18 } // namespace gfx 19 20 namespace gl { 21 22 class GLContext; 23 24 /** 25 * Uploads image data to an OpenGL texture, initializing the texture 26 * first if necessary. 27 * 28 * \param gl The GL Context to use. 29 * \param aData Start of image data of surface to upload. 30 * Corresponds to the first pixel of the texture. 31 * \param aDataSize The image data's size. 32 * \param aStride The image data's stride. 33 * \param aFormat The image data's format. 34 * \param aDstRegion Region of the texture to upload. 35 * \param aTexture The OpenGL texture to use. Must refer to a valid texture. 36 * \param aSize The full size of the texture. 37 * \param aOutUploadSize If set, the number of bytes the texture requires will 38 * be returned here. 39 * \param aNeedInit Indicates whether a new texture must be allocated. 40 * \param aTextureUnit The texture unit used temporarily to upload the surface. 41 * This may be overridden, so clients should not rely on 42 * the aTexture being bound to aTextureUnit after this call, 43 * or even on aTextureUnit being active. 44 * \param aTextureTarget The texture target to use. 45 * \return Surface format of this texture. 46 */ 47 gfx::SurfaceFormat 48 UploadImageDataToTexture(GLContext* gl, 49 unsigned char* aData, 50 const gfx::IntSize& aDataSize, 51 int32_t aStride, 52 gfx::SurfaceFormat aFormat, 53 const nsIntRegion& aDstRegion, 54 GLuint aTexture, 55 const gfx::IntSize& aSize, 56 size_t* aOutUploadSize = nullptr, 57 bool aNeedInit = false, 58 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, 59 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); 60 61 /** 62 * Convenience wrapper around UploadImageDataToTexture for 63 * gfx::DataSourceSurface's. 64 * 65 * \param aSurface The surface from which to upload image data. 66 * \param aSrcPoint Offset into aSurface where this texture's data begins. 67 */ 68 gfx::SurfaceFormat 69 UploadSurfaceToTexture(GLContext* gl, 70 gfx::DataSourceSurface* aSurface, 71 const nsIntRegion& aDstRegion, 72 GLuint aTexture, 73 const gfx::IntSize& aSize, 74 size_t* aOutUploadSize = nullptr, 75 bool aNeedInit = false, 76 const gfx::IntPoint& aSrcPoint = gfx::IntPoint(0, 0), 77 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, 78 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); 79 80 bool CanUploadSubTextures(GLContext* gl); 81 bool CanUploadNonPowerOfTwo(GLContext* gl); 82 83 } // namespace gl 84 } // namespace mozilla 85 86 #endif 87