1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */ 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 UploadImageDataToTexture( 48 GLContext* gl, unsigned char* aData, const gfx::IntSize& aDataSize, 49 const gfx::IntPoint& aDstOffset, 50 int32_t aStride, gfx::SurfaceFormat aFormat, const nsIntRegion& aDstRegion, 51 GLuint aTexture, const gfx::IntSize& aSize, 52 size_t* aOutUploadSize = nullptr, bool aNeedInit = false, 53 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, 54 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); 55 56 /** 57 * Convenience wrapper around UploadImageDataToTexture for 58 * gfx::DataSourceSurface's. 59 * 60 * \param aSurface The surface from which to upload image data. 61 * \param aSrcPoint Offset into aSurface where this texture's data begins. 62 */ 63 gfx::SurfaceFormat UploadSurfaceToTexture( 64 GLContext* gl, gfx::DataSourceSurface* aSurface, 65 const nsIntRegion& aDstRegion, GLuint aTexture, const gfx::IntSize& aSize, 66 size_t* aOutUploadSize = nullptr, bool aNeedInit = false, 67 const gfx::IntPoint& aSrcOffset = gfx::IntPoint(0, 0), 68 const gfx::IntPoint& aDstOffset = gfx::IntPoint(0, 0), 69 GLenum aTextureUnit = LOCAL_GL_TEXTURE0, 70 GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D); 71 72 bool ShouldUploadSubTextures(GLContext* gl); 73 bool CanUploadNonPowerOfTwo(GLContext* gl); 74 75 } // namespace gl 76 } // namespace mozilla 77 78 #endif 79