Diff
Modified: branches/safari-611.1.4-branch/Source/WebCore/ChangeLog (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/ChangeLog 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/ChangeLog 2020-10-30 17:42:17 UTC (rev 269191)
@@ -1,3 +1,146 @@
+2020-10-29 Alan Coon <[email protected]>
+
+ Cherry-pick r268386. rdar://problem/70831174
+
+ Cocoa: Make WebGLLayer not dependent on GraphicsContextGLOpenGL
+ https://bugs.webkit.org/show_bug.cgi?id=217212
+ <rdar://problem/69876022>
+
+ Patch by Kimmo Kinnunen <[email protected]> on 2020-10-13
+ Reviewed by Dean Jackson.
+
+ Source/WebCore:
+
+ WebGLLayer was needlessly using GraphicsContextGLOpenGL.
+ This is problematic because WebGLLayer should work with
+ upcoming remote GraphicsContextGL implementation.
+
+ The prepare callgraph was:
+ GCGLOpenGL -> WebGLLayer -> GCGLOpenGL
+ Refactor it to be:
+ GCGLOpenGL -> WebGLLayer
+
+ Move the back buffer ownership to the GraphicsContextGLOpenGL.
+ Make the front buffer ownership explicit in WebGLLayer.
+ Move the EGL bindings ownerships of all buffers to
+ GraphicsContextGLOpenGL.
+
+ Make the WebGLLayer not use EGL or OpenGL, it does not
+ need and cannot use it as not all of its clients use OpenGL
+ (i.e. the above mentioned remote use-case).
+
+ Improves the memory usage by not allocating front buffers
+ unless needed. In case the canvas does not present, will
+ not allocate front buffers at all.
+
+ Improves error handling of the allocations and EGL bindings.
+
+ No new tests, a refactor.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+ (WebCore::GraphicsContextGLOpenGL::prepareTexture):
+ (WebCore::GraphicsContextGLOpenGL::prepareTextureImpl):
+ * platform/graphics/angle/GraphicsContextGLANGLEUtilities.h: Added.
+ (WebCore::ScopedRestoreTextureBinding::ScopedRestoreTextureBinding):
+ (WebCore::ScopedRestoreTextureBinding::~ScopedRestoreTextureBinding):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::makeContextCurrent):
+ (WebCore::GraphicsContextGLOpenGL::reshapeDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::bindDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::prepareForDisplay):
+ (WebCore::GraphicsContextGLOpenGL::didDisplay):
+ * platform/graphics/cocoa/WebGLLayer.h:
+ * platform/graphics/cocoa/WebGLLayer.mm:
+ (-[WebGLLayer initWithClient:devicePixelRatio:]):
+ (-[WebGLLayer copyImageSnapshotWithColorSpace:]):
+ (-[WebGLLayer recycleBuffer]):
+ (-[WebGLLayer prepareForDisplayWithContents:]):
+ (-[WebGLLayer display]):
+ (-[WebGLLayer detachClient]):
+ * platform/graphics/cocoa/WebGLLayerClient.h: Copied from Source/WebCore/platform/graphics/cocoa/WebGLLayer.h.
+ (WebCore::WebGLLayerClient::~WebGLLayerClient):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+ * platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+
+ Source/WebKit:
+
+ Removed unneeded inclusions of GraphicsContextGLOpenGL.h. The
+ file is now using non-public headers.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@268386 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-10-13 Kimmo Kinnunen <[email protected]>
+
+ Cocoa: Make WebGLLayer not dependent on GraphicsContextGLOpenGL
+ https://bugs.webkit.org/show_bug.cgi?id=217212
+ <rdar://problem/69876022>
+
+ Reviewed by Dean Jackson.
+
+ WebGLLayer was needlessly using GraphicsContextGLOpenGL.
+ This is problematic because WebGLLayer should work with
+ upcoming remote GraphicsContextGL implementation.
+
+ The prepare callgraph was:
+ GCGLOpenGL -> WebGLLayer -> GCGLOpenGL
+ Refactor it to be:
+ GCGLOpenGL -> WebGLLayer
+
+ Move the back buffer ownership to the GraphicsContextGLOpenGL.
+ Make the front buffer ownership explicit in WebGLLayer.
+ Move the EGL bindings ownerships of all buffers to
+ GraphicsContextGLOpenGL.
+
+ Make the WebGLLayer not use EGL or OpenGL, it does not
+ need and cannot use it as not all of its clients use OpenGL
+ (i.e. the above mentioned remote use-case).
+
+ Improves the memory usage by not allocating front buffers
+ unless needed. In case the canvas does not present, will
+ not allocate front buffers at all.
+
+ Improves error handling of the allocations and EGL bindings.
+
+ No new tests, a refactor.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+ (WebCore::GraphicsContextGLOpenGL::prepareTexture):
+ (WebCore::GraphicsContextGLOpenGL::prepareTextureImpl):
+ * platform/graphics/angle/GraphicsContextGLANGLEUtilities.h: Added.
+ (WebCore::ScopedRestoreTextureBinding::ScopedRestoreTextureBinding):
+ (WebCore::ScopedRestoreTextureBinding::~ScopedRestoreTextureBinding):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::makeContextCurrent):
+ (WebCore::GraphicsContextGLOpenGL::reshapeDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::bindDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::prepareForDisplay):
+ (WebCore::GraphicsContextGLOpenGL::didDisplay):
+ * platform/graphics/cocoa/WebGLLayer.h:
+ * platform/graphics/cocoa/WebGLLayer.mm:
+ (-[WebGLLayer initWithClient:devicePixelRatio:]):
+ (-[WebGLLayer copyImageSnapshotWithColorSpace:]):
+ (-[WebGLLayer recycleBuffer]):
+ (-[WebGLLayer prepareForDisplayWithContents:]):
+ (-[WebGLLayer display]):
+ (-[WebGLLayer detachClient]):
+ * platform/graphics/cocoa/WebGLLayerClient.h: Copied from Source/WebCore/platform/graphics/cocoa/WebGLLayer.h.
+ (WebCore::WebGLLayerClient::~WebGLLayerClient):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+ * platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+
2020-10-26 Alan Coon <[email protected]>
Cherry-pick r268382. rdar://problem/70702384
Modified: branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-10-30 17:42:17 UTC (rev 269191)
@@ -2218,6 +2218,8 @@
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, ); }; };
@@ -10071,6 +10073,8 @@
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>"; };
@@ -21890,6 +21894,7 @@
6E27F243229C9F8400F1F632 /* ExtensionsGLANGLE.cpp */,
6E27F244229C9F8D00F1F632 /* ExtensionsGLANGLE.h */,
6E27F2422298CE4B00F1F632 /* GraphicsContextGLANGLE.cpp */,
+ 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */,
6E290861229DB950000986E2 /* TemporaryANGLESetting.cpp */,
6E290863229DB970000986E2 /* TemporaryANGLESetting.h */,
);
@@ -26441,6 +26446,7 @@
CD5D27751E8318E000D80A3D /* WebCoreDecompressionSession.mm */,
49FFBF3D11C93EE3006A7118 /* WebGLLayer.h */,
49FFBF3E11C93EE3006A7118 /* WebGLLayer.mm */,
+ 7BB34A132534579100029D08 /* WebGLLayerClient.h */,
318436DB21B9DAA000ED383E /* WebGPULayer.h */,
318436DD21B9DAA000ED383E /* WebGPULayer.mm */,
);
@@ -31634,6 +31640,7 @@
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 */,
@@ -34636,6 +34643,7 @@
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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2020-10-30 17:42:17 UTC (rev 269191)
@@ -209,12 +209,11 @@
ASSERT(m_texture);
#if PLATFORM(COCOA)
- if (!allocateIOSurfaceBackingStore(size)) {
+ if (!reshapeDisplayBufferBacking()) {
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.
@@ -520,7 +519,13 @@
return;
makeContextCurrent();
+ prepareTextureImpl();
+}
+void GraphicsContextGLOpenGL::prepareTextureImpl()
+{
+ ASSERT(!m_layerComposited);
+
if (contextAttributes().antialias)
resolveMultisamplingIfNecessary();
@@ -555,7 +560,6 @@
} else
gl::BindFramebuffer(GL_FRAMEBUFFER, m_state.boundDrawFBO);
}
- gl::Flush();
#endif
}
Added: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h (0 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h (rev 0)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLEUtilities.h 2020-10-30 17:42:17 UTC (rev 269191)
@@ -0,0 +1,75 @@
+/*
+ * 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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2020-10-30 17:42:17 UTC (rev 269191)
@@ -29,6 +29,7 @@
#import "GraphicsContextGLOpenGL.h"
#import "ExtensionsGLANGLE.h"
+#import "GraphicsContextGLANGLEUtilities.h"
#import "GraphicsContextGLOpenGLManager.h"
#import "HostWindow.h"
#import "Logging.h"
@@ -40,21 +41,6 @@
#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>
@@ -348,11 +334,10 @@
// Create the WebGLLayer
BEGIN_BLOCK_OBJC_EXCEPTIONS
- m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithGraphicsContextGL:this]);
+ m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithClient:this devicePixelRatio:attrs.devicePixelRatio]);
#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.
@@ -424,10 +409,19 @@
if (m_preserveDrawingBufferFBO)
gl::DeleteFramebuffers(1, &m_preserveDrawingBufferFBO);
- [m_webGLLayer releaseGLResources];
+ 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);
+
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);
@@ -476,6 +470,10 @@
{
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))
@@ -571,16 +569,60 @@
}
#endif
-bool GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore(IntSize size)
+bool GraphicsContextGLOpenGL::reshapeDisplayBufferBacking()
{
- LOG(WebGL, "GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore at %d x %d. (%p)", size.width(), size.height(), this);
- return [m_webGLLayer allocateIOSurfaceBackingStoreWithSize:size usingAlpha:contextAttributes().alpha];
+ 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);
}
-void GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer()
+bool GraphicsContextGLOpenGL::bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer)
{
- LOG(WebGL, "GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer(). (%p)", this);
- [m_webGLLayer bindFramebufferToNextAvailableSurface];
+ 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;
}
bool GraphicsContextGLOpenGL::isGLES2Compliant() const
@@ -637,9 +679,37 @@
void GraphicsContextGLOpenGL::prepareForDisplay()
{
- [m_webGLLayer 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();
}
+void GraphicsContextGLOpenGL::didDisplay()
+{
+ markLayerComposited();
}
+}
+
#endif // ENABLE(GRAPHICS_CONTEXT_GL)
Modified: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h 2020-10-30 17:42:17 UTC (rev 269191)
@@ -20,36 +20,58 @@
* 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 GraphicsLayer;
-class GraphicsContextGLOpenGL;
+class WebGLLayerClient;
+struct WebGLLayerBuffer {
+ std::unique_ptr<WebCore::IOSurface> surface; // The actual contents.
+ void* handle { nullptr }; // Client specific metadata handle (such as EGLSurface).
+};
}
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
-@property (nonatomic) NakedPtr<WebCore::GraphicsContextGLOpenGL> context;
+- (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio;
-- (id)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context;
-
- (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace;
-- (void)prepareForDisplay;
+// 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;
-- (bool)allocateIOSurfaceBackingStoreWithSize:(WebCore::IntSize)size usingAlpha:(BOOL)usingAlpha;
-- (void)bindFramebufferToNextAvailableSurface;
-- (void)setEGLDisplay:(void*)eglDisplay config:(void*)eglConfig;
-- (void)releaseGLResources;
+// 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;
+// 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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm 2020-10-30 17:42:17 UTC (rev 269191)
@@ -28,74 +28,27 @@
#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>
+@implementation WebGLLayer {
+ NakedPtr<WebCore::WebGLLayerClient> _client;
+ WebCore::WebGLLayerBuffer _contentsBuffer;
+ WebCore::WebGLLayerBuffer _spareBuffer;
-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 {
- 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)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context
+- (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio
{
- _context = context;
+ _client = client;
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;
}
@@ -117,47 +70,27 @@
- (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;
}
-- (void)prepareForDisplay
+- (WebCore::WebGLLayerBuffer) recycleBuffer
{
- 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;
+ if (_spareBuffer.surface) {
+ if (_spareBuffer.surface->isInUse())
+ _spareBuffer.surface.reset();
+ return WTFMove(_spareBuffer);
}
- _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;
- }
+ return { };
+}
- std::swap(_contentsBuffer, _drawingBuffer);
- std::swap(_contentsPbuffer, _drawingPbuffer);
- [self bindFramebufferToNextAvailableSurface];
- }
+- (void)prepareForDisplayWithContents:(WebCore::WebGLLayerBuffer) buffer
+{
+ ASSERT(!_spareBuffer.surface);
+ _spareBuffer = WTFMove(_contentsBuffer);
+ _contentsBuffer = WTFMove(buffer);
[self setNeedsDisplay];
_preparedForDisplay = YES;
}
@@ -164,19 +97,12 @@
- (void)display
{
- 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();
+ if (_contentsBuffer.surface && _preparedForDisplay) {
+ self.contents = _contentsBuffer.surface->asLayerContents();
[self reloadValueForKeyPath:@"contents"];
}
-
- _context->markLayerComposited();
+ if (_client)
+ _client->didDisplay();
auto layer = WebCore::PlatformCALayer::platformCALayerForLayer((__bridge void*)self);
if (layer && layer->owner())
layer->owner()->platformCALayerLayerDidDisplay(layer.get());
@@ -184,96 +110,14 @@
_preparedForDisplay = NO;
}
-- (void)setEGLDisplay:(void*)display config:(void*)config
+- (void*) detachClient
{
- _eglDisplay = display;
- _eglConfig = config;
+ ASSERT(!_spareBuffer.surface);
+ _client = nil;
+ void* result = _contentsBuffer.handle;
+ _contentsBuffer.handle = nullptr;
+ return result;
}
-
-- (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)
Copied: branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h (from rev 269015, branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h) (0 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h (rev 0)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayerClient.h 2020-10-30 17:42:17 UTC (rev 269191)
@@ -0,0 +1,36 @@
+/*
+ * 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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2020-10-30 17:42:17 UTC (rev 269191)
@@ -35,6 +35,11 @@
#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
@@ -54,7 +59,6 @@
#if PLATFORM(COCOA)
OBJC_CLASS CALayer;
OBJC_CLASS WebGLLayer;
-typedef struct __IOSurface* IOSurfaceRef;
#endif // PLATFORM(COCOA)
#if USE(NICOSIA)
@@ -83,7 +87,11 @@
class GraphicsContextGLOpenGLPrivate;
-class GraphicsContextGLOpenGL : public GraphicsContextGL {
+class GraphicsContextGLOpenGL : public GraphicsContextGL
+#if PLATFORM(COCOA)
+ , private WebGLLayerClient
+#endif
+{
public:
class Client {
public:
@@ -543,8 +551,8 @@
#endif
#if PLATFORM(COCOA)
- bool allocateIOSurfaceBackingStore(IntSize);
- void updateFramebufferTextureBackingStoreFromLayer();
+ bool reshapeDisplayBufferBacking();
+ bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
#if PLATFORM(MAC)
void updateCGLContext();
#endif
@@ -681,11 +689,14 @@
#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 };
@@ -890,6 +901,12 @@
#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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp 2020-10-30 17:42:17 UTC (rev 269191)
@@ -164,7 +164,6 @@
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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebKit/ChangeLog 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebKit/ChangeLog 2020-10-30 17:42:17 UTC (rev 269191)
@@ -1,3 +1,96 @@
+2020-10-29 Alan Coon <[email protected]>
+
+ Cherry-pick r268386. rdar://problem/70831174
+
+ Cocoa: Make WebGLLayer not dependent on GraphicsContextGLOpenGL
+ https://bugs.webkit.org/show_bug.cgi?id=217212
+ <rdar://problem/69876022>
+
+ Patch by Kimmo Kinnunen <[email protected]> on 2020-10-13
+ Reviewed by Dean Jackson.
+
+ Source/WebCore:
+
+ WebGLLayer was needlessly using GraphicsContextGLOpenGL.
+ This is problematic because WebGLLayer should work with
+ upcoming remote GraphicsContextGL implementation.
+
+ The prepare callgraph was:
+ GCGLOpenGL -> WebGLLayer -> GCGLOpenGL
+ Refactor it to be:
+ GCGLOpenGL -> WebGLLayer
+
+ Move the back buffer ownership to the GraphicsContextGLOpenGL.
+ Make the front buffer ownership explicit in WebGLLayer.
+ Move the EGL bindings ownerships of all buffers to
+ GraphicsContextGLOpenGL.
+
+ Make the WebGLLayer not use EGL or OpenGL, it does not
+ need and cannot use it as not all of its clients use OpenGL
+ (i.e. the above mentioned remote use-case).
+
+ Improves the memory usage by not allocating front buffers
+ unless needed. In case the canvas does not present, will
+ not allocate front buffers at all.
+
+ Improves error handling of the allocations and EGL bindings.
+
+ No new tests, a refactor.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+ (WebCore::GraphicsContextGLOpenGL::prepareTexture):
+ (WebCore::GraphicsContextGLOpenGL::prepareTextureImpl):
+ * platform/graphics/angle/GraphicsContextGLANGLEUtilities.h: Added.
+ (WebCore::ScopedRestoreTextureBinding::ScopedRestoreTextureBinding):
+ (WebCore::ScopedRestoreTextureBinding::~ScopedRestoreTextureBinding):
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL):
+ (WebCore::GraphicsContextGLOpenGL::makeContextCurrent):
+ (WebCore::GraphicsContextGLOpenGL::reshapeDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::bindDisplayBufferBacking):
+ (WebCore::GraphicsContextGLOpenGL::prepareForDisplay):
+ (WebCore::GraphicsContextGLOpenGL::didDisplay):
+ * platform/graphics/cocoa/WebGLLayer.h:
+ * platform/graphics/cocoa/WebGLLayer.mm:
+ (-[WebGLLayer initWithClient:devicePixelRatio:]):
+ (-[WebGLLayer copyImageSnapshotWithColorSpace:]):
+ (-[WebGLLayer recycleBuffer]):
+ (-[WebGLLayer prepareForDisplayWithContents:]):
+ (-[WebGLLayer display]):
+ (-[WebGLLayer detachClient]):
+ * platform/graphics/cocoa/WebGLLayerClient.h: Copied from Source/WebCore/platform/graphics/cocoa/WebGLLayer.h.
+ (WebCore::WebGLLayerClient::~WebGLLayerClient):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+ * platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp:
+ (WebCore::GraphicsContextGLOpenGL::reshapeFBOs):
+
+ Source/WebKit:
+
+ Removed unneeded inclusions of GraphicsContextGLOpenGL.h. The
+ file is now using non-public headers.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@268386 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-10-13 Kimmo Kinnunen <[email protected]>
+
+ Cocoa: Make WebGLLayer not dependent on GraphicsContextGLOpenGL
+ https://bugs.webkit.org/show_bug.cgi?id=217212
+ <rdar://problem/69876022>
+
+ Reviewed by Dean Jackson.
+
+ Removed unneeded inclusions of GraphicsContextGLOpenGL.h. The
+ file is now using non-public headers.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+
2020-10-26 Alan Coon <[email protected]>
Cherry-pick r268796. rdar://problem/70702309
Modified: branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2020-10-30 17:42:17 UTC (rev 269191)
@@ -175,7 +175,6 @@
#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 (269190 => 269191)
--- branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-10-30 17:02:47 UTC (rev 269190)
+++ branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-10-30 17:42:17 UTC (rev 269191)
@@ -71,7 +71,6 @@
#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>