Title: [268756] branches/safari-611.1.4-branch/Source

Diff

Modified: branches/safari-611.1.4-branch/Source/WebCore/ChangeLog (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/ChangeLog	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/ChangeLog	2020-10-20 20:11:16 UTC (rev 268756)
@@ -1,5 +1,9 @@
 2020-10-20  Alan Coon  <alanc...@apple.com>
 
+        Revert r268386. rdar://problem/70497386
+
+2020-10-20  Alan Coon  <alanc...@apple.com>
+
         Revert r268578. rdar://problem/70497386
 
 2020-10-20  Alan Coon  <alanc...@apple.com>

Modified: branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-10-20 20:11:16 UTC (rev 268756)
@@ -2218,8 +2218,6 @@
 		7AF9B20618CFB2DF00C64BEF /* VTTRegionList.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20018CFB2DF00C64BEF /* VTTRegionList.h */; };
 		7AF9B20D18CFB5F400C64BEF /* JSVTTRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20918CFB5F200C64BEF /* JSVTTRegion.h */; };
 		7AF9B20F18CFB5F400C64BEF /* JSVTTRegionList.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */; };
-		7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A132534579100029D08 /* WebGLLayerClient.h */; };
-		7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; };
 		7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
 		7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C1843FE1C8B7283002EB973 /* Autofill.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C1843FC1C8B7283002EB973 /* Autofill.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -10073,8 +10071,6 @@
 		7AF9B20918CFB5F200C64BEF /* JSVTTRegion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVTTRegion.h; sourceTree = "<group>"; };
 		7AF9B20A18CFB5F300C64BEF /* JSVTTRegionList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSVTTRegionList.cpp; sourceTree = "<group>"; };
 		7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVTTRegionList.h; sourceTree = "<group>"; };
-		7BB34A132534579100029D08 /* WebGLLayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLLayerClient.h; sourceTree = "<group>"; };
-		7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; };
 		7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; };
 		7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; };
 		7C011F3F24FAD360005BEF10 /* InternalSettingsGenerated.idl.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.idl.erb; sourceTree = "<group>"; };
@@ -21894,7 +21890,6 @@
 				6E27F243229C9F8400F1F632 /* ExtensionsGLANGLE.cpp */,
 				6E27F244229C9F8D00F1F632 /* ExtensionsGLANGLE.h */,
 				6E27F2422298CE4B00F1F632 /* GraphicsContextGLANGLE.cpp */,
-				7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */,
 				6E290861229DB950000986E2 /* TemporaryANGLESetting.cpp */,
 				6E290863229DB970000986E2 /* TemporaryANGLESetting.h */,
 			);
@@ -26446,7 +26441,6 @@
 				CD5D27751E8318E000D80A3D /* WebCoreDecompressionSession.mm */,
 				49FFBF3D11C93EE3006A7118 /* WebGLLayer.h */,
 				49FFBF3E11C93EE3006A7118 /* WebGLLayer.mm */,
-				7BB34A132534579100029D08 /* WebGLLayerClient.h */,
 				318436DB21B9DAA000ED383E /* WebGPULayer.h */,
 				318436DD21B9DAA000ED383E /* WebGPULayer.mm */,
 			);
@@ -31640,7 +31634,6 @@
 				B2A015A90AF6CD53006BCE0E /* GraphicsContext.h in Headers */,
 				934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
 				313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */,
-				7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */,
 				7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */,
 				49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */,
 				319A728823C267FE0085353C /* GraphicsContextGLOpenGLManager.h in Headers */,
@@ -34643,7 +34636,6 @@
 				6EBF0E5512A8929800DB1709 /* WebGLExtension.h in Headers */,
 				49C7B9CF1042D32F0009D447 /* WebGLFramebuffer.h in Headers */,
 				49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */,
-				7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */,
 				93F1D5BB12D532C400832BEC /* WebGLLoseContext.h in Headers */,
 				49C7B9D51042D32F0009D447 /* WebGLObject.h in Headers */,
 				49C7B9D71042D32F0009D447 /* WebGLProgram.h in Headers */,

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2020-10-20 20:11:16 UTC (rev 268756)
@@ -209,11 +209,12 @@
     ASSERT(m_texture);
 
 #if PLATFORM(COCOA)
-    if (!reshapeDisplayBufferBacking()) {
+    if (!allocateIOSurfaceBackingStore(size)) {
         RELEASE_LOG(WebGL, "Fatal: Unable to allocate backing store of size %d x %d", width, height);
         forceContextLost();
         return true;
     }
+    updateFramebufferTextureBackingStoreFromLayer();
     if (m_preserveDrawingBufferTexture) {
         // The context requires the use of an intermediate texture in order to implement
         // preserveDrawingBuffer:true without antialiasing.
@@ -519,13 +520,7 @@
         return;
 
     makeContextCurrent();
-    prepareTextureImpl();
-}
 
-void GraphicsContextGLOpenGL::prepareTextureImpl()
-{
-    ASSERT(!m_layerComposited);
-
     if (contextAttributes().antialias)
         resolveMultisamplingIfNecessary();
 
@@ -560,6 +555,7 @@
         } else
             gl::BindFramebuffer(GL_FRAMEBUFFER, m_state.boundDrawFBO);
     }
+    gl::Flush();
 #endif
 }
 

Deleted: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h	2020-10-20 20:11:16 UTC (rev 268756)
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(GRAPHICS_CONTEXT_GL) && USE(ANGLE)
-
-#include "GraphicsTypesGL.h"
-#include <wtf/Noncopyable.h>
-
-#define EGL_EGL_PROTOTYPES 0
-// Skip the inclusion of ANGLE's explicit context entry points for now.
-#define GL_ANGLE_explicit_context
-#define GL_ANGLE_explicit_context_gles1
-typedef void* GLeglContext;
-#import <ANGLE/egl.h>  // NOLINT
-#import <ANGLE/eglext.h>
-#import <ANGLE/eglext_angle.h>
-#import <ANGLE/entry_points_egl.h>
-#import <ANGLE/entry_points_egl_ext.h>
-#import <ANGLE/entry_points_gles_2_0_autogen.h>
-#import <ANGLE/entry_points_gles_ext_autogen.h>
-#import <ANGLE/gl2ext.h>
-#import <ANGLE/gl2ext_angle.h>
-
-namespace WebCore {
-
-class ScopedRestoreTextureBinding {
-    WTF_MAKE_NONCOPYABLE(ScopedRestoreTextureBinding);
-public:
-    ScopedRestoreTextureBinding(GCGLenum bindingPointQuery, GCGLenum bindingPoint, bool condition = true)
-    {
-        ASSERT(bindingPoint != static_cast<GCGLenum>(0u));
-        if (condition) {
-            m_bindingPoint = bindingPoint;
-            gl::GetIntegerv(bindingPointQuery, reinterpret_cast<GLint*>(&m_bindingValue));
-        }
-    }
-
-    ~ScopedRestoreTextureBinding()
-    {
-        if (m_bindingPoint)
-            gl::BindTexture(m_bindingPoint, m_bindingValue);
-    }
-
-private:
-    GLenum m_bindingPoint { 0 };
-    GLuint m_bindingValue { 0u };
-};
-
-}
-
-#endif

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2020-10-20 20:11:16 UTC (rev 268756)
@@ -29,7 +29,6 @@
 #import "GraphicsContextGLOpenGL.h"
 
 #import "ExtensionsGLANGLE.h"
-#import "GraphicsContextGLANGLEUtilities.h"
 #import "GraphicsContextGLOpenGLManager.h"
 #import "HostWindow.h"
 #import "Logging.h"
@@ -41,6 +40,21 @@
 #import <wtf/BlockObjCExceptions.h>
 #import <wtf/text/CString.h>
 
+#define EGL_EGL_PROTOTYPES 0
+// Skip the inclusion of ANGLE's explicit context entry points for now.
+#define GL_ANGLE_explicit_context
+#define GL_ANGLE_explicit_context_gles1
+typedef void* GLeglContext;
+#import <ANGLE/egl.h>
+#import <ANGLE/eglext.h>
+#import <ANGLE/eglext_angle.h>
+#import <ANGLE/entry_points_egl.h>
+#import <ANGLE/entry_points_egl_ext.h>
+#import <ANGLE/entry_points_gles_2_0_autogen.h>
+#import <ANGLE/entry_points_gles_ext_autogen.h>
+#import <ANGLE/gl2ext.h>
+#import <ANGLE/gl2ext_angle.h>
+
 #if PLATFORM(MAC)
 #import "ScreenProperties.h"
 #import <OpenGL/CGLRenderers.h>
@@ -334,10 +348,11 @@
 
     // Create the WebGLLayer
     BEGIN_BLOCK_OBJC_EXCEPTIONS
-        m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithClient:this devicePixelRatio:attrs.devicePixelRatio]);
+        m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithGraphicsContextGL:this]);
 #ifndef NDEBUG
         [m_webGLLayer setName:@"WebGL Layer"];
 #endif
+        [m_webGLLayer setEGLDisplay:m_displayObj config:m_configObj];
     END_BLOCK_OBJC_EXCEPTIONS
 
     // Create the texture that will be used for the framebuffer.
@@ -409,19 +424,10 @@
         if (m_preserveDrawingBufferFBO)
             gl::DeleteFramebuffers(1, &m_preserveDrawingBufferFBO);
 
-        if (m_displayBufferPbuffer) {
-            EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
-            EGL_DestroySurface(m_displayObj, m_displayBufferPbuffer);
-        }
-        auto recycledBuffer = [m_webGLLayer recycleBuffer];
-        if (recycledBuffer.handle)
-            EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
-        auto contentsHandle = [m_webGLLayer detachClient];
-        if (contentsHandle)
-            EGL_DestroySurface(m_displayObj, contentsHandle);
-
+        [m_webGLLayer releaseGLResources];
         EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
         EGL_DestroyContext(m_displayObj, m_contextObj);
+        [m_webGLLayer setContext:nullptr];
     }
 
     LOG(WebGL, "Destroyed a GraphicsContextGLOpenGL (%p).", this);
@@ -470,10 +476,6 @@
 {
     if (!m_contextObj)
         return false;
-    // If there is no drawing buffer, we failed to allocate one during preparing for display.
-    // The exception is the case when the context is used before reshaping.
-    if (!m_displayBufferBacking && !getInternalFramebufferSize().isEmpty())
-        return false;
     // ANGLE has an early out for case where nothing changes. Calling MakeCurrent
     // is important to set volatile platform context. See InitializeEGLDisplay().
     if (!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj))
@@ -569,60 +571,16 @@
 }
 #endif
 
-bool GraphicsContextGLOpenGL::reshapeDisplayBufferBacking()
+bool GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore(IntSize size)
 {
-    ASSERT(!getInternalFramebufferSize().isEmpty());
-    // Reset the current backbuffer now before allocating a new one in order to slightly reduce memory pressure.
-    if (m_displayBufferBacking) {
-        m_displayBufferBacking.reset();
-        EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
-        EGL_DestroySurface(m_displayObj, m_displayBufferPbuffer);
-        m_displayBufferPbuffer = EGL_NO_SURFACE;
-    }
-    // Reset the future recycled buffer now, because it most likely will not be reusable at the time it will be reused.
-    auto recycledBuffer = [m_webGLLayer recycleBuffer];
-    if (recycledBuffer.handle)
-        EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
-    recycledBuffer.surface.reset();
-
-    auto backing = WebCore::IOSurface::create(getInternalFramebufferSize(), WebCore::sRGBColorSpaceRef());
-    if (!backing)
-        return false;
-
-    backing->migrateColorSpaceToProperties();
-
-    const bool usingAlpha = contextAttributes().alpha;
-    const auto size = getInternalFramebufferSize();
-    const EGLint surfaceAttributes[] = {
-        EGL_WIDTH, size.width(),
-        EGL_HEIGHT, size.height(),
-        EGL_IOSURFACE_PLANE_ANGLE, 0,
-        EGL_TEXTURE_TARGET, WebCore::GraphicsContextGLOpenGL::EGLIOSurfaceTextureTarget(),
-        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, usingAlpha ? GL_BGRA_EXT : GL_RGB,
-        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
-        EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
-        // Only has an effect on the iOS Simulator.
-        EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_WRITE_HINT_ANGLE,
-        EGL_NONE, EGL_NONE
-    };
-    EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(m_displayObj, EGL_IOSURFACE_ANGLE, backing->surface(), m_configObj, surfaceAttributes);
-    if (!pbuffer)
-        return false;
-    return bindDisplayBufferBacking(WTFMove(backing), pbuffer);
+    LOG(WebGL, "GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore at %d x %d. (%p)", size.width(), size.height(), this);
+    return [m_webGLLayer allocateIOSurfaceBackingStoreWithSize:size usingAlpha:contextAttributes().alpha];
 }
 
-bool GraphicsContextGLOpenGL::bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer)
+void GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer()
 {
-    GCGLenum textureTarget = IOSurfaceTextureTarget();
-    ScopedRestoreTextureBinding restoreBinding(IOSurfaceTextureTargetQuery(), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
-    gl::BindTexture(textureTarget, m_texture);
-    if (!EGL_BindTexImage(m_displayObj, pbuffer, EGL_BACK_BUFFER)) {
-        EGL_DestroySurface(m_displayObj, pbuffer);
-        return false;
-    }
-    m_displayBufferPbuffer = pbuffer;
-    m_displayBufferBacking = WTFMove(backing);
-    return true;
+    LOG(WebGL, "GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer(). (%p)", this);
+    [m_webGLLayer bindFramebufferToNextAvailableSurface];
 }
 
 bool GraphicsContextGLOpenGL::isGLES2Compliant() const
@@ -679,37 +637,9 @@
 
 void GraphicsContextGLOpenGL::prepareForDisplay()
 {
-    if (m_layerComposited)
-        return;
-    if (!makeContextCurrent())
-        return;
-    prepareTextureImpl();
-
-    // The IOSurface will be used from other graphics subsystem, so flush GL commands.
-    gl::Flush();
-
-    auto recycledBuffer = [m_webGLLayer recycleBuffer];
-
-    EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
-    [m_webGLLayer prepareForDisplayWithContents: {WTFMove(m_displayBufferBacking), m_displayBufferPbuffer}];
-    m_displayBufferPbuffer = EGL_NO_SURFACE;
-
-    if (recycledBuffer.surface && recycledBuffer.surface->size() == getInternalFramebufferSize()) {
-        if (bindDisplayBufferBacking(WTFMove(recycledBuffer.surface), recycledBuffer.handle))
-            return;
-    }
-    recycledBuffer.surface.reset();
-    if (recycledBuffer.handle)
-        EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
-    // Error will be handled by next call to makeContextCurrent() which will notice lack of display buffer.
-    reshapeDisplayBufferBacking();
+    [m_webGLLayer prepareForDisplay];
 }
 
-void GraphicsContextGLOpenGL::didDisplay()
-{
-    markLayerComposited();
 }
 
-}
-
 #endif // ENABLE(GRAPHICS_CONTEXT_GL)

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h	2020-10-20 20:11:16 UTC (rev 268756)
@@ -20,58 +20,36 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
 #import "IOSurface.h"
+#import "IntSize.h"
 #import <QuartzCore/QuartzCore.h>
 #import <wtf/NakedPtr.h>
 
 namespace WebCore {
-class WebGLLayerClient;
-struct WebGLLayerBuffer {
-    std::unique_ptr<WebCore::IOSurface> surface; // The actual contents.
-    void* handle { nullptr }; // Client specific metadata handle (such as EGLSurface).
-};
+class GraphicsLayer;
+class GraphicsContextGLOpenGL;
 }
 
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
 
-// A layer class implementing front buffer management of a 3-buffering swap
-// chain of IOSurfaces.
-// The layer will own the IOSurfaces it uses for display.
-// The client may attach metadata to each IOSurface and will receive the metadata
-// back once the IOSurface has been displayed. However, the client may not neccessarily
-// be able to obtain the IOSurface itself for reuse.
-// Example use of the metadata is to use EGLSurface binding as the metadata. This way
-// when the WebGLLayer is done with the IOSurface display, the client can continue using
-// the existing binding obtained through the buffer recycle logic.
 @interface WebGLLayer : CALayer
 
-- (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio;
+@property (nonatomic) NakedPtr<WebCore::GraphicsContextGLOpenGL> context;
 
+- (id)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context;
+
 - (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace;
 
-// Returns the metadata handle of last unused contents buffer.
-// Client may recieve back also the ownership of the contents surface, in case it is available at the
-// time of the call.
-// Returns either:
-// - Empty buffer if no buffer has been submitted.
-// - Buffer with empty surface and non-empty metadata handle if the recycled buffer was available
-//   but the surface is still in use.
-// - Surface and handle.
-- (WebCore::WebGLLayerBuffer)recycleBuffer;
+- (void)prepareForDisplay;
 
-// Prepares the layer for display with a contents buffer.
-// Client transfers the ownership of the IOSurface surface in the `buffer`.
-- (void)prepareForDisplayWithContents:(WebCore::WebGLLayerBuffer)buffer;
+- (bool)allocateIOSurfaceBackingStoreWithSize:(WebCore::IntSize)size usingAlpha:(BOOL)usingAlpha;
+- (void)bindFramebufferToNextAvailableSurface;
+- (void)setEGLDisplay:(void*)eglDisplay config:(void*)eglConfig;
+- (void)releaseGLResources;
 
-// Detaches the client and returns the current contents buffer metadata handle.
-// The if multiple buffers have been submitted, recycleBuffer must have been called before calling
-// this.
-// The client will not receive `WebGLLayerClient` notifications after calling this.
-- (void*)detachClient;
-
 @end
 
 ALLOW_DEPRECATED_DECLARATIONS_END

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm	2020-10-20 20:11:16 UTC (rev 268756)
@@ -28,27 +28,74 @@
 #if ENABLE(WEBGL)
 #import "WebGLLayer.h"
 
+#import "GraphicsContextCG.h"
+#import "GraphicsContextGLOpenGL.h"
 #import "GraphicsLayer.h"
 #import "GraphicsLayerCA.h"
+#import "ImageBufferUtilitiesCG.h"
+#import "NotImplemented.h"
 #import "PlatformCALayer.h"
-#import "WebGLLayerClient.h"
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
+#import <wtf/FastMalloc.h>
 #import <wtf/RetainPtr.h>
 
+#define EGL_EGL_PROTOTYPES 0
+#import <ANGLE/egl.h>
+#import <ANGLE/eglext.h>
+#import <ANGLE/eglext_angle.h>
+#import <ANGLE/entry_points_egl.h>
+#import <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
+#import <ANGLE/gl2ext.h>
+#import <ANGLE/gl2ext_angle.h>
+
+namespace {
+    class ScopedRestoreTextureBinding {
+        WTF_MAKE_NONCOPYABLE(ScopedRestoreTextureBinding);
+    public:
+        ScopedRestoreTextureBinding(GLenum bindingPointQuery, GLenum bindingPoint)
+            : m_bindingPoint(bindingPoint)
+        {
+            gl::GetIntegerv(bindingPointQuery, &m_bindingValue);
+        }
+
+        ~ScopedRestoreTextureBinding()
+        {
+            gl::BindTexture(m_bindingPoint, m_bindingValue);
+        }
+
+    private:
+        GLint m_bindingPoint { 0 };
+        GLint m_bindingValue { 0 };
+    };
+}
+
 @implementation WebGLLayer {
-    NakedPtr<WebCore::WebGLLayerClient> _client;
-    WebCore::WebGLLayerBuffer _contentsBuffer;
-    WebCore::WebGLLayerBuffer _spareBuffer;
-
+    float _devicePixelRatio;
+    std::unique_ptr<WebCore::IOSurface> _contentsBuffer;
+    std::unique_ptr<WebCore::IOSurface> _drawingBuffer;
+    std::unique_ptr<WebCore::IOSurface> _spareBuffer;
+    WebCore::IntSize _bufferSize;
+    BOOL _usingAlpha;
+    void* _eglDisplay;
+    void* _eglConfig;
+    void* _contentsPbuffer;
+    void* _drawingPbuffer;
+    void* _sparePbuffer;
+    void* _latchedPbuffer;
     BOOL _preparedForDisplay;
 }
 
-- (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio
+- (id)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context
 {
-    _client = client;
+    _context = context;
     self = [super init];
+    auto attributes = context->contextAttributes();
+    _devicePixelRatio = attributes.devicePixelRatio;
+    self.contentsOpaque = !attributes.alpha;
     self.transform = CATransform3DIdentity;
-    self.contentsScale = devicePixelRatio;
+    self.contentsScale = _devicePixelRatio;
     return self;
 }
 
@@ -70,27 +117,47 @@
 
 - (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace
 {
+    if (!_context)
+        return nullptr;
     // FIXME: implement. https://bugs.webkit.org/show_bug.cgi?id=217377
-    // When implementing, remember to use self.contentsScale.
     UNUSED_PARAM(colorSpace);
     return nullptr;
 }
 
-- (WebCore::WebGLLayerBuffer) recycleBuffer
+- (void)prepareForDisplay
 {
-    if (_spareBuffer.surface) {
-        if (_spareBuffer.surface->isInUse())
-            _spareBuffer.surface.reset();
-        return WTFMove(_spareBuffer);
+    if (!_context)
+        return;
+
+    // To avoid running any OpenGL code in `display`, this method should be called
+    // at the end of the rendering task. We will flush all painting commands
+    // leaving the buffers ready to composite.
+
+    if (!_context->makeContextCurrent()) {
+        // Context is likely being torn down.
+        return;
     }
-    return { };
-}
+    _context->prepareTexture();
+    if (_drawingBuffer) {
+        if (_latchedPbuffer) {
+            WTF::Optional<ScopedRestoreTextureBinding> restoreBinding;
+            GCGLenum textureTarget = WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTarget();
+            // We don't need to restore GL_TEXTURE_RECTANGLE because it's not accessible from user code.
+            if (textureTarget != WebCore::GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
+                restoreBinding.emplace(WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTargetQuery(), textureTarget);
+            GCGLenum texture = _context->platformTexture();
+            gl::BindTexture(textureTarget, texture);
+            if (!EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER)) {
+                // FIXME: report error.
+                notImplemented();
+            }
+            _latchedPbuffer = nullptr;
+        }
 
-- (void)prepareForDisplayWithContents:(WebCore::WebGLLayerBuffer) buffer
-{
-    ASSERT(!_spareBuffer.surface);
-    _spareBuffer = WTFMove(_contentsBuffer);
-    _contentsBuffer = WTFMove(buffer);
+        std::swap(_contentsBuffer, _drawingBuffer);
+        std::swap(_contentsPbuffer, _drawingPbuffer);
+        [self bindFramebufferToNextAvailableSurface];
+    }
     [self setNeedsDisplay];
     _preparedForDisplay = YES;
 }
@@ -97,12 +164,19 @@
 
 - (void)display
 {
-    if (_contentsBuffer.surface && _preparedForDisplay) {
-        self.contents = _contentsBuffer.surface->asLayerContents();
+    if (!_context)
+        return;
+
+    // At this point we've painted into the _drawingBuffer and swapped it with the old _contentsBuffer,
+    // so all we need to do here is tickle the CALayer to let it know it has new contents.
+    // This avoids running any OpenGL code in this method.
+
+    if (_contentsBuffer && _preparedForDisplay) {
+        self.contents = _contentsBuffer->asLayerContents();
         [self reloadValueForKeyPath:@"contents"];
     }
-    if (_client)
-        _client->didDisplay();
+
+    _context->markLayerComposited();
     auto layer = WebCore::PlatformCALayer::platformCALayerForLayer((__bridge void*)self);
     if (layer && layer->owner())
         layer->owner()->platformCALayerLayerDidDisplay(layer.get());
@@ -110,14 +184,96 @@
     _preparedForDisplay = NO;
 }
 
-- (void*) detachClient
+- (void)setEGLDisplay:(void*)display config:(void*)config
 {
-    ASSERT(!_spareBuffer.surface);
-    _client = nil;
-    void* result = _contentsBuffer.handle;
-    _contentsBuffer.handle = nullptr;
-    return result;
+    _eglDisplay = display;
+    _eglConfig = config;
 }
+
+- (void)releaseGLResources
+{
+    if (!_context)
+        return;
+
+    if (_context->makeContextCurrent() && _latchedPbuffer) {
+        EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER);
+        _latchedPbuffer = nullptr;
+    }
+
+    EGL_DestroySurface(_eglDisplay, _contentsPbuffer);
+    EGL_DestroySurface(_eglDisplay, _drawingPbuffer);
+    EGL_DestroySurface(_eglDisplay, _sparePbuffer);
+}
+
+- (bool)allocateIOSurfaceBackingStoreWithSize:(WebCore::IntSize)size usingAlpha:(BOOL)usingAlpha
+{
+    _bufferSize = size;
+    _usingAlpha = usingAlpha;
+    _contentsBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
+    _drawingBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
+    _spareBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
+
+    if (!_contentsBuffer || !_drawingBuffer || !_spareBuffer)
+        return false;
+
+    _contentsBuffer->migrateColorSpaceToProperties();
+    _drawingBuffer->migrateColorSpaceToProperties();
+    _spareBuffer->migrateColorSpaceToProperties();
+    const EGLint surfaceAttributes[] = {
+        EGL_WIDTH, size.width(),
+        EGL_HEIGHT, size.height(),
+        EGL_IOSURFACE_PLANE_ANGLE, 0,
+        EGL_TEXTURE_TARGET, WebCore::GraphicsContextGLOpenGL::EGLIOSurfaceTextureTarget(),
+        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, usingAlpha ? GL_BGRA_EXT : GL_RGB,
+        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
+        EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
+        // Only has an effect on the iOS Simulator.
+        EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_WRITE_HINT_ANGLE,
+        EGL_NONE, EGL_NONE
+    };
+
+    _contentsPbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _contentsBuffer->surface(), _eglConfig, surfaceAttributes);
+    _drawingPbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _drawingBuffer->surface(), _eglConfig, surfaceAttributes);
+    _sparePbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _spareBuffer->surface(), _eglConfig, surfaceAttributes);
+
+    if (!_contentsPbuffer || !_drawingPbuffer || !_sparePbuffer)
+        return false;
+
+    return true;
+}
+
+- (void)bindFramebufferToNextAvailableSurface
+{
+    WTF::Optional<ScopedRestoreTextureBinding> restoreBinding;
+    GCGLenum textureTarget = WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTarget();
+    // We don't need to restore GL_TEXTURE_RECTANGLE because it's not accessible from user code.
+    if (textureTarget != WebCore::GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
+        restoreBinding.emplace(WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTargetQuery(), textureTarget);
+
+    GCGLenum texture = _context->platformTexture();
+    gl::BindTexture(textureTarget, texture);
+
+    if (_latchedPbuffer) {
+        if (!EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER)) {
+            // FIXME: report error.
+            notImplemented();
+        }
+        _latchedPbuffer = nullptr;
+    }
+
+    if (_drawingBuffer && _drawingBuffer->isInUse()) {
+        std::swap(_drawingBuffer, _spareBuffer);
+        std::swap(_drawingPbuffer, _sparePbuffer);
+    }
+
+    // Link the IOSurface to the texture via the previously-created pbuffer.
+    if (!EGL_BindTexImage(_eglDisplay, _drawingPbuffer, EGL_BACK_BUFFER)) {
+        // FIXME: report error.
+        notImplemented();
+    }
+    _latchedPbuffer = _drawingPbuffer;
+}
+
 @end
 
 #endif // ENABLE(WEBGL)

Deleted: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h	2020-10-20 20:11:16 UTC (rev 268756)
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-namespace WebCore {
-
-class WebGLLayerClient {
-public:
-    virtual ~WebGLLayerClient() { }
-    virtual void didDisplay() = 0;
-};
-
-}

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2020-10-20 20:11:16 UTC (rev 268756)
@@ -35,11 +35,6 @@
 #include <wtf/RetainPtr.h>
 #include <wtf/UniqueArray.h>
 
-#if PLATFORM(COCOA)
-#include "IOSurface.h"
-#include "WebGLLayerClient.h"
-#endif
-
 #if USE(CA)
 #include "PlatformCALayer.h"
 #endif
@@ -59,6 +54,7 @@
 #if PLATFORM(COCOA)
 OBJC_CLASS CALayer;
 OBJC_CLASS WebGLLayer;
+typedef struct __IOSurface* IOSurfaceRef;
 #endif // PLATFORM(COCOA)
 
 #if USE(NICOSIA)
@@ -87,11 +83,7 @@
 
 class GraphicsContextGLOpenGLPrivate;
 
-class GraphicsContextGLOpenGL : public GraphicsContextGL
-#if PLATFORM(COCOA)
-    , private WebGLLayerClient
-#endif
-{
+class GraphicsContextGLOpenGL : public GraphicsContextGL {
 public:
     class Client {
     public:
@@ -551,8 +543,8 @@
 #endif
 
 #if PLATFORM(COCOA)
-    bool reshapeDisplayBufferBacking();
-    bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
+    bool allocateIOSurfaceBackingStore(IntSize);
+    void updateFramebufferTextureBackingStoreFromLayer();
 #if PLATFORM(MAC)
     void updateCGLContext();
 #endif
@@ -689,14 +681,11 @@
 #endif
 
     bool reshapeFBOs(const IntSize&);
-    void prepareTextureImpl();
     void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
     void attachDepthAndStencilBufferIfNeeded(GCGLuint internalDepthStencilFormat, int width, int height);
 
 #if PLATFORM(COCOA)
     bool allowOfflineRenderers() const;
-    // WebGLLayerClient overrides.
-    void didDisplay() override;
 #endif
 
     int m_currentWidth { 0 };
@@ -901,12 +890,6 @@
 #endif
 
 #if PLATFORM(COCOA)
-    // Backing store for the the buffer which is eventually used for display.
-    // When preserveDrawingBuffer == false, this is the drawing buffer backing store.
-    // When preserveDrawingBuffer == true, this is blitted to during display prepare.
-    std::unique_ptr<IOSurface> m_displayBufferBacking;
-    void* m_displayBufferPbuffer { nullptr };
-
     bool m_hasSwitchedToHighPerformanceGPU { false };
 #endif
 };

Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp	2020-10-20 20:11:16 UTC (rev 268756)
@@ -164,6 +164,7 @@
         forceContextLost();
         return true;
     }
+    updateFramebufferTextureBackingStoreFromLayer();
     ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_texture, 0);
 #endif // !USE(OPENGL_ES))
 #else

Modified: branches/safari-611.1.4-branch/Source/WebKit/ChangeLog (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebKit/ChangeLog	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebKit/ChangeLog	2020-10-20 20:11:16 UTC (rev 268756)
@@ -1,3 +1,7 @@
+2020-10-20  Alan Coon  <alanc...@apple.com>
+
+        Revert r268386. rdar://problem/70497386
+
 2020-10-17  David Kilzer  <ddkil...@apple.com>
 
         REGRESSION (r191637): Fix -Wmisleading-indentation warnings in open source clang

Modified: branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-10-20 20:11:16 UTC (rev 268756)
@@ -175,6 +175,7 @@
 #include <WebCore/FrameLoaderTypes.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/FullscreenManager.h>
+#include <WebCore/GraphicsContextGLOpenGL.h>
 #include <WebCore/HTMLAttachmentElement.h>
 #include <WebCore/HTMLFormElement.h>
 #include <WebCore/HTMLImageElement.h>

Modified: branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (268755 => 268756)


--- branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2020-10-20 20:10:22 UTC (rev 268755)
+++ branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2020-10-20 20:11:16 UTC (rev 268756)
@@ -71,6 +71,7 @@
 #import <WebCore/FrameLoaderTypes.h>
 #import <WebCore/FrameView.h>
 #import <WebCore/GraphicsContext.h>
+#import <WebCore/GraphicsContextGLOpenGL.h>
 #import <WebCore/HTMLConverter.h>
 #import <WebCore/HTMLPlugInImageElement.h>
 #import <WebCore/HitTestResult.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to