Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm (252740 => 252741)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm 2019-11-21 17:52:24 UTC (rev 252740)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm 2019-11-21 18:53:59 UTC (rev 252741)
@@ -290,7 +290,6 @@
#elif USE(ANGLE)
UNUSED_PARAM(hostWindow);
- UNUSED_PARAM(sharedContext);
m_displayObj = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
if (m_displayObj == EGL_NO_DISPLAY)
@@ -304,7 +303,6 @@
const char *displayExtensions = EGL_QueryString(m_displayObj, EGL_EXTENSIONS);
LOG(WebGL, "Extensions: %s", displayExtensions);
- EGLConfig config;
EGLint configAttributes[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
@@ -314,7 +312,7 @@
EGL_NONE
};
EGLint numberConfigsReturned = 0;
- EGL_ChooseConfig(m_displayObj, configAttributes, &config, 1, &numberConfigsReturned);
+ EGL_ChooseConfig(m_displayObj, configAttributes, &m_configObj, 1, &numberConfigsReturned);
if (numberConfigsReturned != 1) {
LOG(WebGL, "EGLConfig Initialization failed.");
return;
@@ -349,7 +347,7 @@
}
contextAttributes.push_back(EGL_NONE);
- m_contextObj = EGL_CreateContext(m_displayObj, config, EGL_NO_CONTEXT, contextAttributes.data());
+ m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharedContext ? static_cast<EGLContext>(sharedContext->m_contextObj) : EGL_NO_CONTEXT, contextAttributes.data());
if (m_contextObj == EGL_NO_CONTEXT) {
LOG(WebGL, "EGLContext Initialization failed.");
return;
@@ -387,7 +385,7 @@
[m_webGLLayer setName:@"WebGL Layer"];
#endif
#if USE(ANGLE)
- [m_webGLLayer setEGLDisplay:m_displayObj config:config];
+ [m_webGLLayer setEGLDisplay:m_displayObj config:m_configObj];
#endif
END_BLOCK_OBJC_EXCEPTIONS
Modified: trunk/Source/WebCore/platform/graphics/cv/VideoTextureCopierCV.cpp (252740 => 252741)
--- trunk/Source/WebCore/platform/graphics/cv/VideoTextureCopierCV.cpp 2019-11-21 17:52:24 UTC (rev 252740)
+++ trunk/Source/WebCore/platform/graphics/cv/VideoTextureCopierCV.cpp 2019-11-21 18:53:59 UTC (rev 252741)
@@ -40,6 +40,19 @@
#include <OpenGLES/ES3/glext.h>
#endif
+#if USE(ANGLE)
+#define EGL_EGL_PROTOTYPES 0
+#include <ANGLE/egl.h>
+#include <ANGLE/eglext.h>
+#include <ANGLE/eglext_angle.h>
+#include <ANGLE/entry_points_egl.h>
+#include <ANGLE/entry_points_gles_2_0_autogen.h>
+// Skip the inclusion of ANGLE's explicit context entry points for now.
+#define GL_ANGLE_explicit_context
+#include <ANGLE/gl2ext.h>
+#include <ANGLE/gl2ext_angle.h>
+#endif
+
#include "CoreVideoSoftLink.h"
namespace WebCore {
@@ -515,14 +528,13 @@
StringBuilder fragmentShaderSource;
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || USE(ANGLE)
fragmentShaderSource.appendLiteral("precision mediump float;\n");
+#endif
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
fragmentShaderSource.appendLiteral("uniform sampler2D u_texture;\n");
-#elif USE(OPENGL)
+#elif USE(OPENGL) || (USE(ANGLE) && !PLATFORM(IOS_FAMILY))
fragmentShaderSource.appendLiteral("uniform sampler2DRect u_texture;\n");
-#elif USE(ANGLE)
- // FIXME: determine how to access rectangular textures via ANGLE.
- ASSERT_NOT_REACHED();
#else
#error Unsupported configuration
#endif
@@ -532,13 +544,10 @@
fragmentShaderSource.appendLiteral("uniform int u_swapColorChannels;\n");
fragmentShaderSource.appendLiteral("void main() {\n");
fragmentShaderSource.appendLiteral(" vec2 texPos = vec2(v_texturePosition.x * u_textureDimensions.x, v_texturePosition.y * u_textureDimensions.y);\n");
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
fragmentShaderSource.appendLiteral(" vec4 color = texture2D(u_texture, texPos);\n");
-#elif USE(OPENGL)
+#elif USE(OPENGL) || (USE(ANGLE) && !PLATFORM(IOS_FAMILY))
fragmentShaderSource.appendLiteral(" vec4 color = texture2DRect(u_texture, texPos);\n");
-#elif USE(ANGLE)
- // FIXME: determine how to access rectangular textures via ANGLE.
- ASSERT_NOT_REACHED();
#else
#error Unsupported configuration
#endif
@@ -618,14 +627,12 @@
" if (u_flipY == 1) {\n"
" normalizedPosition.y = 1.0 - normalizedPosition.y;\n"
" }\n"
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
" v_yTextureCoordinate = normalizedPosition;\n"
" v_uvTextureCoordinate = normalizedPosition;\n"
-#elif USE(OPENGL)
+#elif USE(OPENGL) || (USE(ANGLE) && !PLATFORM(IOS_FAMILY))
" v_yTextureCoordinate = normalizedPosition * u_yTextureSize;\n"
" v_uvTextureCoordinate = normalizedPosition * u_uvTextureSize;\n"
-#elif USE(ANGLE)
- // FIXME: determine how to access rectangular textures via ANGLE.
#else
#error Unsupported configuration
#endif
@@ -645,15 +652,15 @@
}
String fragmentShaderSource {
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || USE(ANGLE)
"precision mediump float;\n"
+#endif
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
"#define SAMPLERTYPE sampler2D\n"
"#define TEXTUREFUNC texture2D\n"
-#elif USE(OPENGL)
+#elif USE(OPENGL) || (USE(ANGLE) && !PLATFORM(IOS_FAMILY))
"#define SAMPLERTYPE sampler2DRect\n"
"#define TEXTUREFUNC texture2DRect\n"
-#elif USE(ANGLE)
- // FIXME: determine how to access rectangular textures via ANGLE.
#else
#error Unsupported configuration
#endif
@@ -722,8 +729,57 @@
return true;
}
+#if USE(ANGLE)
+void* VideoTextureCopierCV::attachIOSurfaceToTexture(GC3Denum target, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height, GC3Denum type, IOSurfaceRef surface, GC3Duint plane)
+{
+ auto display = m_context->platformDisplay();
+ EGLint eglTextureTarget = 0;
+
+ if (target == GraphicsContext3D::TEXTURE_RECTANGLE_ARB)
+ eglTextureTarget = EGL_TEXTURE_RECTANGLE_ANGLE;
+ else if (target == GraphicsContext3D::TEXTURE_2D)
+ eglTextureTarget = EGL_TEXTURE_2D;
+ else {
+ LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target));
+ return nullptr;
+ }
+
+ const EGLint surfaceAttributes[] = {
+ EGL_WIDTH, width,
+ EGL_HEIGHT, height,
+ EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane),
+ EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget),
+ EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat),
+ EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
+ EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type),
+ EGL_NONE, EGL_NONE
+ };
+ EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, m_context->platformConfig(), surfaceAttributes);
+ if (!pbuffer)
+ return nullptr;
+ if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) {
+ EGL_DestroySurface(display, pbuffer);
+ return nullptr;
+ }
+ return pbuffer;
+}
+
+void VideoTextureCopierCV::detachIOSurfaceFromTexture(void* handle)
+{
+ auto display = m_context->platformDisplay();
+ EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER);
+ EGL_DestroySurface(display, handle);
+}
+#endif
+
bool VideoTextureCopierCV::copyImageToPlatformTexture(CVPixelBufferRef image, size_t width, size_t height, Platform3DObject outputTexture, GC3Denum outputTarget, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY)
{
+ // CVOpenGLTextureCache seems to be disabled since the deprecation of
+ // OpenGL. To avoid porting unused code to the ANGLE code paths, remove it.
+#if USE(ANGLE)
+ UNUSED_PARAM(outputTarget);
+ UNUSED_PARAM(premultiplyAlpha);
+#else
if (!m_textureCache) {
m_textureCache = TextureCacheCV::create(m_context);
if (!m_textureCache)
@@ -738,6 +794,7 @@
#endif
return copyVideoTextureToPlatformTexture(texture.get(), width, height, outputTexture, outputTarget, level, internalFormat, format, type, premultiplyAlpha, flipY, swapColorChannels);
}
+#endif // USE(ANGLE)
#if HAVE(IOSURFACE)
// FIXME: This currently only supports '420v' and '420f' pixel formats. Investigate supporting more pixel formats.
@@ -794,13 +851,10 @@
auto uvPlaneWidth = IOSurfaceGetWidthOfPlane(surface, 1);
auto uvPlaneHeight = IOSurfaceGetHeightOfPlane(surface, 1);
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
GC3Denum videoTextureTarget = GraphicsContext3D::TEXTURE_2D;
-#elif USE(OPENGL)
- GC3Denum videoTextureTarget = GL_TEXTURE_RECTANGLE_ARB;
-#elif USE(ANGLE)
- // FIXME: determine how to access rectangular textures via ANGLE.
- GC3Denum videoTextureTarget = GraphicsContext3D::TEXTURE_2D;
+#elif USE(OPENGL) || (USE(ANGLE) && !PLATFORM(IOS_FAMILY))
+ GC3Denum videoTextureTarget = GraphicsContext3D::TEXTURE_RECTANGLE_ARB;
#else
#error Unsupported configuration
#endif
@@ -811,10 +865,18 @@
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
+#if USE(ANGLE)
+ auto uvHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContext3D::RG, uvPlaneWidth, uvPlaneHeight, GraphicsContext3D::UNSIGNED_BYTE, surface, 1);
+ if (!uvHandle) {
+ m_context->deleteTexture(uvTexture);
+ return false;
+ }
+#else
if (!m_context->texImageIOSurface2D(videoTextureTarget, GraphicsContext3D::RG, uvPlaneWidth, uvPlaneHeight, GraphicsContext3D::RG, GraphicsContext3D::UNSIGNED_BYTE, surface, 1)) {
m_context->deleteTexture(uvTexture);
return false;
}
+#endif // USE(ANGLE)
auto yTexture = m_context->createTexture();
m_context->activeTexture(GraphicsContext3D::TEXTURE0);
@@ -823,11 +885,20 @@
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
m_context->texParameteri(videoTextureTarget, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
+#if USE(ANGLE)
+ auto yHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContext3D::RED, yPlaneWidth, yPlaneHeight, GraphicsContext3D::UNSIGNED_BYTE, surface, 0);
+ if (!yHandle) {
+ m_context->deleteTexture(yTexture);
+ m_context->deleteTexture(uvTexture);
+ return false;
+ }
+#else
if (!m_context->texImageIOSurface2D(videoTextureTarget, GraphicsContext3D::LUMINANCE, yPlaneWidth, yPlaneHeight, GraphicsContext3D::LUMINANCE, GraphicsContext3D::UNSIGNED_BYTE, surface, 0)) {
m_context->deleteTexture(yTexture);
m_context->deleteTexture(uvTexture);
return false;
}
+#endif // USE(ANGLE)
// Configure the drawing parameters.
m_context->uniform1i(m_yTextureUniformLocation, 0);
@@ -844,7 +915,7 @@
// Do the actual drawing.
m_context->drawArrays(GraphicsContext3D::TRIANGLES, 0, 6);
-#if USE(OPENGL_ES)
+#if USE(OPENGL_ES) || (USE(ANGLE) && PLATFORM(IOS_FAMILY))
// flush() must be called here in order to re-synchronize the output texture's contents across the
// two EAGL contexts.
m_context->flush();
@@ -853,6 +924,10 @@
// Clean-up.
m_context->deleteTexture(yTexture);
m_context->deleteTexture(uvTexture);
+#if USE(ANGLE)
+ detachIOSurfaceFromTexture(yHandle);
+ detachIOSurfaceFromTexture(uvHandle);
+#endif
m_lastSurface = surface;
m_lastSurfaceSeed = newSurfaceSeed;
@@ -886,6 +961,10 @@
videoTextureTarget = CVOpenGLTextureGetTarget(inputVideoTexture);
CVOpenGLTextureGetCleanTexCoords(inputVideoTexture, lowerLeft, lowerRight, upperRight, upperLeft);
#elif USE(ANGLE)
+ // CVOpenGLTextureCacheCreateTextureFromImage seems to always return
+ // kCVReturnPixelBufferNotOpenGLCompatible on desktop macOS now, so this
+ // entire code path seems to be unused. Assume the IOSurface path will be
+ // taken when using ANGLE.
UNUSED_PARAM(lowerLeft);
UNUSED_PARAM(lowerRight);
UNUSED_PARAM(upperLeft);