diff options
author | Brian Smith <brian@dbsoft.org> | 2022-04-26 10:58:05 -0500 |
---|---|---|
committer | Brian Smith <brian@dbsoft.org> | 2022-04-26 10:59:55 -0500 |
commit | b73c17b7c6977a1c53c13ab49d290bd6faf21cde (patch) | |
tree | 8fbbd6113db3c3852b33eb72e66b001d44c90edd /gfx/gl | |
parent | 1a31160dde95477993fb7d3aa1327b2a45f8fca8 (diff) | |
download | uxp-b73c17b7c6977a1c53c13ab49d290bd6faf21cde.tar.gz |
Issue #1829 - Revert "Issue #1751 -- Remove XP_MACOSX conditionals and support files from /gfx"
This reverts commit 616b39413d570fd98a9a300483a3b657a00fa43b.
Diffstat (limited to 'gfx/gl')
-rw-r--r-- | gfx/gl/GLBlitHelper.cpp | 111 | ||||
-rw-r--r-- | gfx/gl/GLBlitHelper.h | 3 | ||||
-rw-r--r-- | gfx/gl/GLContext.cpp | 78 | ||||
-rw-r--r-- | gfx/gl/GLContextProvider.h | 7 | ||||
-rwxr-xr-x | gfx/gl/GLScreenBuffer.cpp | 8 |
5 files changed, 206 insertions, 1 deletions
diff --git a/gfx/gl/GLBlitHelper.cpp b/gfx/gl/GLBlitHelper.cpp index 12e30c8804..da7f5b462d 100644 --- a/gfx/gl/GLBlitHelper.cpp +++ b/gfx/gl/GLBlitHelper.cpp @@ -14,6 +14,11 @@ #include "mozilla/gfx/Matrix.h" #include "mozilla/UniquePtr.h" +#ifdef XP_MACOSX +#include "MacIOSurfaceImage.h" +#include "GLContextCGL.h" +#endif + using mozilla::layers::PlanarYCbCrImage; using mozilla::layers::PlanarYCbCrData; @@ -181,6 +186,34 @@ GLBlitHelper::InitTexQuadProgram(BlitType target) } \n\ "; +#ifdef XP_MACOSX + const char kTexNV12PlanarBlit_FragShaderSource[] = "\ + #version 100 \n\ + #extension GL_ARB_texture_rectangle : require \n\ + #ifdef GL_ES \n\ + precision mediump float \n\ + #endif \n\ + varying vec2 vTexCoord; \n\ + uniform sampler2DRect uYTexture; \n\ + uniform sampler2DRect uCbCrTexture; \n\ + uniform vec2 uYTexScale; \n\ + uniform vec2 uCbCrTexScale; \n\ + void main() \n\ + { \n\ + float y = texture2DRect(uYTexture, vTexCoord * uYTexScale).r; \n\ + float cb = texture2DRect(uCbCrTexture, vTexCoord * uCbCrTexScale).r; \n\ + float cr = texture2DRect(uCbCrTexture, vTexCoord * uCbCrTexScale).a; \n\ + y = (y - 0.06275) * 1.16438; \n\ + cb = cb - 0.50196; \n\ + cr = cr - 0.50196; \n\ + gl_FragColor.r = y + cr * 1.59603; \n\ + gl_FragColor.g = y - 0.81297 * cr - 0.39176 * cb; \n\ + gl_FragColor.b = y + cb * 2.01723; \n\ + gl_FragColor.a = 1.0; \n\ + } \n\ + "; +#endif + bool success = false; GLuint* programPtr; @@ -203,6 +236,13 @@ GLBlitHelper::InitTexQuadProgram(BlitType target) fragShaderPtr = &mTexYUVPlanarBlit_FragShader; fragShaderSource = kTexYUVPlanarBlit_FragShaderSource; break; +#ifdef XP_MACOSX + case ConvertMacIOSurfaceImage: + programPtr = &mTexNV12PlanarBlit_Program; + fragShaderPtr = &mTexNV12PlanarBlit_FragShader; + fragShaderSource = kTexNV12PlanarBlit_FragShaderSource; + break; +#endif default: return false; } @@ -353,6 +393,24 @@ GLBlitHelper::InitTexQuadProgram(BlitType target) mGL->fUniform1i(texCr, Channel_Cr); break; } + case ConvertMacIOSurfaceImage: { +#ifdef XP_MACOSX + GLint texY = mGL->fGetUniformLocation(program, "uYTexture"); + GLint texCbCr = mGL->fGetUniformLocation(program, "uCbCrTexture"); + mYTexScaleLoc = mGL->fGetUniformLocation(program, "uYTexScale"); + mCbCrTexScaleLoc= mGL->fGetUniformLocation(program, "uCbCrTexScale"); + + DebugOnly<bool> hasUniformLocations = texY != -1 && + texCbCr != -1 && + mYTexScaleLoc != -1 && + mCbCrTexScaleLoc != -1; + MOZ_ASSERT(hasUniformLocations, "uniforms not found"); + + mGL->fUniform1i(texY, Channel_Y); + mGL->fUniform1i(texCbCr, Channel_Cb); +#endif + break; + } default: return false; } @@ -620,6 +678,47 @@ GLBlitHelper::BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage) return true; } +#ifdef XP_MACOSX +bool +GLBlitHelper::BlitMacIOSurfaceImage(layers::MacIOSurfaceImage* ioImage) +{ + ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0); + MacIOSurface* surf = ioImage->GetSurface(); + + GLint oldTex[2]; + for (int i = 0; i < 2; i++) { + mGL->fActiveTexture(LOCAL_GL_TEXTURE0 + i); + mGL->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_2D, &oldTex[i]); + } + + GLuint textures[2]; + mGL->fGenTextures(2, textures); + + mGL->fActiveTexture(LOCAL_GL_TEXTURE0); + mGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, textures[0]); + mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); + mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); + surf->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(mGL)->GetCGLContext(), 0); + mGL->fUniform2f(mYTexScaleLoc, surf->GetWidth(0), surf->GetHeight(0)); + + mGL->fActiveTexture(LOCAL_GL_TEXTURE1); + mGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, textures[1]); + mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); + mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); + surf->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(mGL)->GetCGLContext(), 1); + mGL->fUniform2f(mCbCrTexScaleLoc, surf->GetWidth(1), surf->GetHeight(1)); + + mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4); + for (int i = 0; i < 2; i++) { + mGL->fActiveTexture(LOCAL_GL_TEXTURE0 + i); + mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, oldTex[i]); + } + + mGL->fDeleteTextures(2, textures); + return true; +} +#endif + bool GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage, const gfx::IntSize& destSize, @@ -637,6 +736,13 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage, srcOrigin = OriginPos::BottomLeft; break; +#ifdef XP_MACOSX + case ImageFormat::MAC_IOSURFACE: + type = ConvertMacIOSurfaceImage; + srcOrigin = OriginPos::TopLeft; + break; +#endif + default: return false; } @@ -662,6 +768,11 @@ GLBlitHelper::BlitImageToFramebuffer(layers::Image* srcImage, return ret; } +#ifdef XP_MACOSX + case ConvertMacIOSurfaceImage: + return BlitMacIOSurfaceImage(srcImage->AsMacIOSurfaceImage()); +#endif + default: return false; } diff --git a/gfx/gl/GLBlitHelper.h b/gfx/gl/GLBlitHelper.h index 9dd8cd8870..c2858f5913 100644 --- a/gfx/gl/GLBlitHelper.h +++ b/gfx/gl/GLBlitHelper.h @@ -107,6 +107,9 @@ class GLBlitHelper final void BindAndUploadEGLImage(EGLImage image, GLuint target); bool BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage); +#ifdef XP_MACOSX + bool BlitMacIOSurfaceImage(layers::MacIOSurfaceImage* ioImage); +#endif explicit GLBlitHelper(GLContext* gl); diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index 0106f4fd09..72a7bea58b 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -36,6 +36,10 @@ #include "mozilla/DebugOnly.h" +#ifdef XP_MACOSX +#include <CoreServices/CoreServices.h> +#endif + #if defined(MOZ_WIDGET_COCOA) #include "nsCocoaFeatures.h" #endif @@ -873,6 +877,18 @@ GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) // multisampling hardcodes blending with the default blendfunc, which breaks WebGL. MarkUnsupported(GLFeature::framebuffer_multisample); } + +#ifdef XP_MACOSX + // The Mac Nvidia driver, for versions up to and including 10.8, + // don't seem to properly support this. See 814839 + // this has been fixed in Mac OS X 10.9. See 907946 + // and it also works in 10.8.3 and higher. See 1094338. + if (Vendor() == gl::GLVendor::NVIDIA && + !nsCocoaFeatures::IsAtLeastVersion(10,8,3)) + { + MarkUnsupported(GLFeature::depth_texture); + } +#endif } if (IsExtensionSupported(GLContext::ARB_pixel_buffer_object)) { @@ -993,6 +1009,25 @@ GLContext::InitWithPrefixImpl(const char* prefix, bool trygl) raw_fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mMaxRenderbufferSize); raw_fGetIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); +#ifdef XP_MACOSX + if (mWorkAroundDriverBugs) { + if (mVendor == GLVendor::Intel) { + // see bug 737182 for 2D textures, bug 684882 for cube map textures. + mMaxTextureSize = std::min(mMaxTextureSize, 4096); + mMaxCubeMapTextureSize = std::min(mMaxCubeMapTextureSize, 512); + // for good measure, we align renderbuffers on what we do for 2D textures + mMaxRenderbufferSize = std::min(mMaxRenderbufferSize, 4096); + mNeedsTextureSizeChecks = true; + } else if (mVendor == GLVendor::NVIDIA) { + // See bug 879656. 8192 fails, 8191 works. + mMaxTextureSize = std::min(mMaxTextureSize, 8191); + mMaxRenderbufferSize = std::min(mMaxRenderbufferSize, 8191); + + // Part of the bug 879656, but it also doesn't hurt the 877949 + mNeedsTextureSizeChecks = true; + } + } +#endif #ifdef MOZ_X11 if (mWorkAroundDriverBugs) { if (mVendor == GLVendor::Nouveau) { @@ -1765,6 +1800,20 @@ GLContext::InitExtensions() MarkExtensionUnsupported(ANGLE_texture_compression_dxt3); MarkExtensionUnsupported(ANGLE_texture_compression_dxt5); } + +#ifdef XP_MACOSX + // Bug 1009642: On OSX Mavericks (10.9), the driver for Intel HD + // 3000 appears to be buggy WRT updating sub-images of S3TC + // textures with glCompressedTexSubImage2D. Works on Intel HD 4000 + // and Intel HD 5000/Iris that I tested. + // Bug 1124996: Appears to be the same on OSX Yosemite (10.10) + if (nsCocoaFeatures::macOSVersionMajor() == 10 && + nsCocoaFeatures::macOSVersionMinor() >= 9 && + Renderer() == GLRenderer::IntelHD3000) + { + MarkExtensionUnsupported(EXT_texture_compression_s3tc); + } +#endif } if (shouldDumpExts) { @@ -2779,6 +2828,35 @@ GLContext::fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum f } AfterGLReadCall(); + + // Check if GL is giving back 1.0 alpha for + // RGBA reads to RGBA images from no-alpha buffers. +#ifdef XP_MACOSX + if (WorkAroundDriverBugs() && + Vendor() == gl::GLVendor::NVIDIA && + format == LOCAL_GL_RGBA && + type == LOCAL_GL_UNSIGNED_BYTE && + !IsCoreProfile() && + width && height) + { + GLint alphaBits = 0; + fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits); + if (!alphaBits) { + const uint32_t alphaMask = 0xff000000; + + uint32_t* itr = (uint32_t*)pixels; + uint32_t testPixel = *itr; + if ((testPixel & alphaMask) != alphaMask) { + // We need to set the alpha channel to 1.0 manually. + uint32_t* itrEnd = itr + width*height; // Stride is guaranteed to be width*4. + + for (; itr != itrEnd; itr++) { + *itr |= alphaMask; + } + } + } + } +#endif } void diff --git a/gfx/gl/GLContextProvider.h b/gfx/gl/GLContextProvider.h index d9b3f04196..6e096c1f7e 100644 --- a/gfx/gl/GLContextProvider.h +++ b/gfx/gl/GLContextProvider.h @@ -34,6 +34,13 @@ namespace gl { #define DEFAULT_IMPL WGL #endif +#ifdef XP_MACOSX + #define GL_CONTEXT_PROVIDER_NAME GLContextProviderCGL + #include "GLContextProviderImpl.h" + #undef GL_CONTEXT_PROVIDER_NAME + #define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderCGL +#endif + #if defined(MOZ_X11) #define GL_CONTEXT_PROVIDER_NAME GLContextProviderGLX #include "GLContextProviderImpl.h" diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp index 0ac0322be4..5d95eb9285 100755 --- a/gfx/gl/GLScreenBuffer.cpp +++ b/gfx/gl/GLScreenBuffer.cpp @@ -24,6 +24,10 @@ #include "mozilla/gfx/DeviceManagerDx.h" #endif +#ifdef XP_MACOSX +#include "SharedSurfaceIO.h" +#endif + #ifdef GL_PROVIDER_GLX #include "GLXLibrary.h" #include "SharedSurfaceGLX.h" @@ -80,7 +84,9 @@ GLScreenBuffer::CreateFactory(GLContext* gl, if (!gfxPrefs::WebGLForceLayersReadback()) { switch (backend) { case mozilla::layers::LayersBackend::LAYERS_OPENGL: { -#if defined(GL_PROVIDER_GLX) +#if defined(XP_MACOSX) + factory = SurfaceFactory_IOSurface::Create(gl, caps, ipcChannel, flags); +#elif defined(GL_PROVIDER_GLX) if (sGLXLibrary.UseTextureFromPixmap()) factory = SurfaceFactory_GLXDrawable::Create(gl, caps, ipcChannel, flags); #elif defined(MOZ_WIDGET_UIKIT) |