⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268756 in webkit


Ignore:
Timestamp:
Oct 20, 2020, 1:11:16 PM (6 years ago)
Author:
Alan Coon
Message:

Revert r268386. rdar://problem/70497386

Location:
branches/safari-611.1.4-branch/Source
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-611.1.4-branch/Source/WebCore/ChangeLog

    r268755 r268756  
     12020-10-20  Alan Coon  <alancoon@apple.com>
     2
     3        Revert r268386. rdar://problem/70497386
     4
    152020-10-20  Alan Coon  <alancoon@apple.com>
    26
  • branches/safari-611.1.4-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r268755 r268756  
    22192219                7AF9B20D18CFB5F400C64BEF /* JSVTTRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20918CFB5F200C64BEF /* JSVTTRegion.h */; };
    22202220                7AF9B20F18CFB5F400C64BEF /* JSVTTRegionList.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */; };
    2221                 7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A132534579100029D08 /* WebGLLayerClient.h */; };
    2222                 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */; };
    22232221                7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
    22242222                7C029C6E2493C8F800268204 /* ColorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C029C6D2493C8F800268204 /* ColorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1007410072                7AF9B20A18CFB5F300C64BEF /* JSVTTRegionList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSVTTRegionList.cpp; sourceTree = "<group>"; };
    1007510073                7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVTTRegionList.h; sourceTree = "<group>"; };
    10076                 7BB34A132534579100029D08 /* WebGLLayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLLayerClient.h; sourceTree = "<group>"; };
    10077                 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLANGLEUtilities.h; sourceTree = "<group>"; };
    1007810074                7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; };
    1007910075                7C011F3E24FAD360005BEF10 /* InternalSettingsGenerated.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = InternalSettingsGenerated.cpp.erb; sourceTree = "<group>"; };
     
    2189521891                                6E27F244229C9F8D00F1F632 /* ExtensionsGLANGLE.h */,
    2189621892                                6E27F2422298CE4B00F1F632 /* GraphicsContextGLANGLE.cpp */,
    21897                                 7BB34A1625345CB200029D08 /* GraphicsContextGLANGLEUtilities.h */,
    2189821893                                6E290861229DB950000986E2 /* TemporaryANGLESetting.cpp */,
    2189921894                                6E290863229DB970000986E2 /* TemporaryANGLESetting.h */,
     
    2644726442                                49FFBF3D11C93EE3006A7118 /* WebGLLayer.h */,
    2644826443                                49FFBF3E11C93EE3006A7118 /* WebGLLayer.mm */,
    26449                                 7BB34A132534579100029D08 /* WebGLLayerClient.h */,
    2645026444                                318436DB21B9DAA000ED383E /* WebGPULayer.h */,
    2645126445                                318436DD21B9DAA000ED383E /* WebGPULayer.mm */,
     
    3164131635                                934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */,
    3164231636                                313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */,
    31643                                 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */,
    3164431637                                7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */,
    3164531638                                49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */,
     
    3464434637                                49C7B9CF1042D32F0009D447 /* WebGLFramebuffer.h in Headers */,
    3464534638                                49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */,
    34646                                 7BB34A152534579100029D08 /* WebGLLayerClient.h in Headers */,
    3464734639                                93F1D5BB12D532C400832BEC /* WebGLLoseContext.h in Headers */,
    3464834640                                49C7B9D51042D32F0009D447 /* WebGLObject.h in Headers */,
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp

    r268755 r268756  
    210210
    211211#if PLATFORM(COCOA)
    212     if (!reshapeDisplayBufferBacking()) {
     212    if (!allocateIOSurfaceBackingStore(size)) {
    213213        RELEASE_LOG(WebGL, "Fatal: Unable to allocate backing store of size %d x %d", width, height);
    214214        forceContextLost();
    215215        return true;
    216216    }
     217    updateFramebufferTextureBackingStoreFromLayer();
    217218    if (m_preserveDrawingBufferTexture) {
    218219        // The context requires the use of an intermediate texture in order to implement
     
    520521
    521522    makeContextCurrent();
    522     prepareTextureImpl();
    523 }
    524 
    525 void GraphicsContextGLOpenGL::prepareTextureImpl()
    526 {
    527     ASSERT(!m_layerComposited);
    528523
    529524    if (contextAttributes().antialias)
     
    561556            gl::BindFramebuffer(GL_FRAMEBUFFER, m_state.boundDrawFBO);
    562557    }
     558    gl::Flush();
    563559#endif
    564560}
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm

    r268753 r268756  
    3030
    3131#import "ExtensionsGLANGLE.h"
    32 #import "GraphicsContextGLANGLEUtilities.h"
    3332#import "GraphicsContextGLOpenGLManager.h"
    3433#import "HostWindow.h"
     
    4140#import <wtf/BlockObjCExceptions.h>
    4241#import <wtf/text/CString.h>
     42
     43#define EGL_EGL_PROTOTYPES 0
     44// Skip the inclusion of ANGLE's explicit context entry points for now.
     45#define GL_ANGLE_explicit_context
     46#define GL_ANGLE_explicit_context_gles1
     47typedef void* GLeglContext;
     48#import <ANGLE/egl.h>
     49#import <ANGLE/eglext.h>
     50#import <ANGLE/eglext_angle.h>
     51#import <ANGLE/entry_points_egl.h>
     52#import <ANGLE/entry_points_egl_ext.h>
     53#import <ANGLE/entry_points_gles_2_0_autogen.h>
     54#import <ANGLE/entry_points_gles_ext_autogen.h>
     55#import <ANGLE/gl2ext.h>
     56#import <ANGLE/gl2ext_angle.h>
    4357
    4458#if PLATFORM(MAC)
     
    335349    // Create the WebGLLayer
    336350    BEGIN_BLOCK_OBJC_EXCEPTIONS
    337         m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithClient:this devicePixelRatio:attrs.devicePixelRatio]);
     351        m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithGraphicsContextGL:this]);
    338352#ifndef NDEBUG
    339353        [m_webGLLayer setName:@"WebGL Layer"];
    340354#endif
     355        [m_webGLLayer setEGLDisplay:m_displayObj config:m_configObj];
    341356    END_BLOCK_OBJC_EXCEPTIONS
    342357
     
    410425            gl::DeleteFramebuffers(1, &m_preserveDrawingBufferFBO);
    411426
    412         if (m_displayBufferPbuffer) {
    413             EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
    414             EGL_DestroySurface(m_displayObj, m_displayBufferPbuffer);
    415         }
    416         auto recycledBuffer = [m_webGLLayer recycleBuffer];
    417         if (recycledBuffer.handle)
    418             EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
    419         auto contentsHandle = [m_webGLLayer detachClient];
    420         if (contentsHandle)
    421             EGL_DestroySurface(m_displayObj, contentsHandle);
    422 
     427        [m_webGLLayer releaseGLResources];
    423428        EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    424429        EGL_DestroyContext(m_displayObj, m_contextObj);
     430        [m_webGLLayer setContext:nullptr];
    425431    }
    426432
     
    471477    if (!m_contextObj)
    472478        return false;
    473     // If there is no drawing buffer, we failed to allocate one during preparing for display.
    474     // The exception is the case when the context is used before reshaping.
    475     if (!m_displayBufferBacking && !getInternalFramebufferSize().isEmpty())
    476         return false;
    477479    // ANGLE has an early out for case where nothing changes. Calling MakeCurrent
    478480    // is important to set volatile platform context. See InitializeEGLDisplay().
     
    570572#endif
    571573
    572 bool GraphicsContextGLOpenGL::reshapeDisplayBufferBacking()
    573 {
    574     ASSERT(!getInternalFramebufferSize().isEmpty());
    575     // Reset the current backbuffer now before allocating a new one in order to slightly reduce memory pressure.
    576     if (m_displayBufferBacking) {
    577         m_displayBufferBacking.reset();
    578         EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
    579         EGL_DestroySurface(m_displayObj, m_displayBufferPbuffer);
    580         m_displayBufferPbuffer = EGL_NO_SURFACE;
    581     }
    582     // Reset the future recycled buffer now, because it most likely will not be reusable at the time it will be reused.
    583     auto recycledBuffer = [m_webGLLayer recycleBuffer];
    584     if (recycledBuffer.handle)
    585         EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
    586     recycledBuffer.surface.reset();
    587 
    588     auto backing = WebCore::IOSurface::create(getInternalFramebufferSize(), WebCore::sRGBColorSpaceRef());
    589     if (!backing)
    590         return false;
    591 
    592     backing->migrateColorSpaceToProperties();
    593 
    594     const bool usingAlpha = contextAttributes().alpha;
    595     const auto size = getInternalFramebufferSize();
    596     const EGLint surfaceAttributes[] = {
    597         EGL_WIDTH, size.width(),
    598         EGL_HEIGHT, size.height(),
    599         EGL_IOSURFACE_PLANE_ANGLE, 0,
    600         EGL_TEXTURE_TARGET, WebCore::GraphicsContextGLOpenGL::EGLIOSurfaceTextureTarget(),
    601         EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, usingAlpha ? GL_BGRA_EXT : GL_RGB,
    602         EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
    603         EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
    604         // Only has an effect on the iOS Simulator.
    605         EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_WRITE_HINT_ANGLE,
    606         EGL_NONE, EGL_NONE
    607     };
    608     EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(m_displayObj, EGL_IOSURFACE_ANGLE, backing->surface(), m_configObj, surfaceAttributes);
    609     if (!pbuffer)
    610         return false;
    611     return bindDisplayBufferBacking(WTFMove(backing), pbuffer);
    612 }
    613 
    614 bool GraphicsContextGLOpenGL::bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer)
    615 {
    616     GCGLenum textureTarget = IOSurfaceTextureTarget();
    617     ScopedRestoreTextureBinding restoreBinding(IOSurfaceTextureTargetQuery(), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
    618     gl::BindTexture(textureTarget, m_texture);
    619     if (!EGL_BindTexImage(m_displayObj, pbuffer, EGL_BACK_BUFFER)) {
    620         EGL_DestroySurface(m_displayObj, pbuffer);
    621         return false;
    622     }
    623     m_displayBufferPbuffer = pbuffer;
    624     m_displayBufferBacking = WTFMove(backing);
    625     return true;
     574bool GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore(IntSize size)
     575{
     576    LOG(WebGL, "GraphicsContextGLOpenGL::allocateIOSurfaceBackingStore at %d x %d. (%p)", size.width(), size.height(), this);
     577    return [m_webGLLayer allocateIOSurfaceBackingStoreWithSize:size usingAlpha:contextAttributes().alpha];
     578}
     579
     580void GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer()
     581{
     582    LOG(WebGL, "GraphicsContextGLOpenGL::updateFramebufferTextureBackingStoreFromLayer(). (%p)", this);
     583    [m_webGLLayer bindFramebufferToNextAvailableSurface];
    626584}
    627585
     
    680638void GraphicsContextGLOpenGL::prepareForDisplay()
    681639{
    682     if (m_layerComposited)
    683         return;
    684     if (!makeContextCurrent())
    685         return;
    686     prepareTextureImpl();
    687 
    688     // The IOSurface will be used from other graphics subsystem, so flush GL commands.
    689     gl::Flush();
    690 
    691     auto recycledBuffer = [m_webGLLayer recycleBuffer];
    692 
    693     EGL_ReleaseTexImage(m_displayObj, m_displayBufferPbuffer, EGL_BACK_BUFFER);
    694     [m_webGLLayer prepareForDisplayWithContents: {WTFMove(m_displayBufferBacking), m_displayBufferPbuffer}];
    695     m_displayBufferPbuffer = EGL_NO_SURFACE;
    696 
    697     if (recycledBuffer.surface && recycledBuffer.surface->size() == getInternalFramebufferSize()) {
    698         if (bindDisplayBufferBacking(WTFMove(recycledBuffer.surface), recycledBuffer.handle))
    699             return;
    700     }
    701     recycledBuffer.surface.reset();
    702     if (recycledBuffer.handle)
    703         EGL_DestroySurface(m_displayObj, recycledBuffer.handle);
    704     // Error will be handled by next call to makeContextCurrent() which will notice lack of display buffer.
    705     reshapeDisplayBufferBacking();
    706 }
    707 
    708 void GraphicsContextGLOpenGL::didDisplay()
    709 {
    710     markLayerComposited();
     640    [m_webGLLayer prepareForDisplay];
    711641}
    712642
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.h

    r268753 r268756  
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    2424 */
    2525
    2626#import "IOSurface.h"
     27#import "IntSize.h"
    2728#import <QuartzCore/QuartzCore.h>
    2829#import <wtf/NakedPtr.h>
    2930
    3031namespace WebCore {
    31 class WebGLLayerClient;
    32 struct WebGLLayerBuffer {
    33     std::unique_ptr<WebCore::IOSurface> surface; // The actual contents.
    34     void* handle { nullptr }; // Client specific metadata handle (such as EGLSurface).
    35 };
     32class GraphicsLayer;
     33class GraphicsContextGLOpenGL;
    3634}
    3735
    3836ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    3937
    40 // A layer class implementing front buffer management of a 3-buffering swap
    41 // chain of IOSurfaces.
    42 // The layer will own the IOSurfaces it uses for display.
    43 // The client may attach metadata to each IOSurface and will receive the metadata
    44 // back once the IOSurface has been displayed. However, the client may not neccessarily
    45 // be able to obtain the IOSurface itself for reuse.
    46 // Example use of the metadata is to use EGLSurface binding as the metadata. This way
    47 // when the WebGLLayer is done with the IOSurface display, the client can continue using
    48 // the existing binding obtained through the buffer recycle logic.
    4938@interface WebGLLayer : CALayer
    5039
    51 - (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio;
     40@property (nonatomic) NakedPtr<WebCore::GraphicsContextGLOpenGL> context;
     41
     42- (id)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context;
    5243
    5344- (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace;
    5445
    55 // Returns the metadata handle of last unused contents buffer.
    56 // Client may recieve back also the ownership of the contents surface, in case it is available at the
    57 // time of the call.
    58 // Returns either:
    59 // - Empty buffer if no buffer has been submitted.
    60 // - Buffer with empty surface and non-empty metadata handle if the recycled buffer was available
    61 //   but the surface is still in use.
    62 // - Surface and handle.
    63 - (WebCore::WebGLLayerBuffer)recycleBuffer;
     46- (void)prepareForDisplay;
    6447
    65 // Prepares the layer for display with a contents buffer.
    66 // Client transfers the ownership of the IOSurface surface in the `buffer`.
    67 - (void)prepareForDisplayWithContents:(WebCore::WebGLLayerBuffer)buffer;
    68 
    69 // Detaches the client and returns the current contents buffer metadata handle.
    70 // The if multiple buffers have been submitted, recycleBuffer must have been called before calling
    71 // this.
    72 // The client will not receive `WebGLLayerClient` notifications after calling this.
    73 - (void*)detachClient;
     48- (bool)allocateIOSurfaceBackingStoreWithSize:(WebCore::IntSize)size usingAlpha:(BOOL)usingAlpha;
     49- (void)bindFramebufferToNextAvailableSurface;
     50- (void)setEGLDisplay:(void*)eglDisplay config:(void*)eglConfig;
     51- (void)releaseGLResources;
    7452
    7553@end
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm

    r268753 r268756  
    2929#import "WebGLLayer.h"
    3030
     31#import "GraphicsContextCG.h"
     32#import "GraphicsContextGLOpenGL.h"
    3133#import "GraphicsLayer.h"
    3234#import "GraphicsLayerCA.h"
     35#import "ImageBufferUtilitiesCG.h"
     36#import "NotImplemented.h"
    3337#import "PlatformCALayer.h"
    34 #import "WebGLLayerClient.h"
    3538#import <pal/spi/cocoa/QuartzCoreSPI.h>
     39#import <wtf/FastMalloc.h>
    3640#import <wtf/RetainPtr.h>
    3741
     42#define EGL_EGL_PROTOTYPES 0
     43#import <ANGLE/egl.h>
     44#import <ANGLE/eglext.h>
     45#import <ANGLE/eglext_angle.h>
     46#import <ANGLE/entry_points_egl.h>
     47#import <ANGLE/entry_points_gles_2_0_autogen.h>
     48// Skip the inclusion of ANGLE's explicit context entry points for now.
     49#define GL_ANGLE_explicit_context
     50#import <ANGLE/gl2ext.h>
     51#import <ANGLE/gl2ext_angle.h>
     52
     53namespace {
     54    class ScopedRestoreTextureBinding {
     55        WTF_MAKE_NONCOPYABLE(ScopedRestoreTextureBinding);
     56    public:
     57        ScopedRestoreTextureBinding(GLenum bindingPointQuery, GLenum bindingPoint)
     58            : m_bindingPoint(bindingPoint)
     59        {
     60            gl::GetIntegerv(bindingPointQuery, &m_bindingValue);
     61        }
     62
     63        ~ScopedRestoreTextureBinding()
     64        {
     65            gl::BindTexture(m_bindingPoint, m_bindingValue);
     66        }
     67
     68    private:
     69        GLint m_bindingPoint { 0 };
     70        GLint m_bindingValue { 0 };
     71    };
     72}
     73
    3874@implementation WebGLLayer {
    39     NakedPtr<WebCore::WebGLLayerClient> _client;
    40     WebCore::WebGLLayerBuffer _contentsBuffer;
    41     WebCore::WebGLLayerBuffer _spareBuffer;
    42 
     75    float _devicePixelRatio;
     76    std::unique_ptr<WebCore::IOSurface> _contentsBuffer;
     77    std::unique_ptr<WebCore::IOSurface> _drawingBuffer;
     78    std::unique_ptr<WebCore::IOSurface> _spareBuffer;
     79    WebCore::IntSize _bufferSize;
     80    BOOL _usingAlpha;
     81    void* _eglDisplay;
     82    void* _eglConfig;
     83    void* _contentsPbuffer;
     84    void* _drawingPbuffer;
     85    void* _sparePbuffer;
     86    void* _latchedPbuffer;
    4387    BOOL _preparedForDisplay;
    4488}
    4589
    46 - (id)initWithClient:(NakedPtr<WebCore::WebGLLayerClient>)client devicePixelRatio:(float)devicePixelRatio
    47 {
    48     _client = client;
     90- (id)initWithGraphicsContextGL:(NakedPtr<WebCore::GraphicsContextGLOpenGL>)context
     91{
     92    _context = context;
    4993    self = [super init];
     94    auto attributes = context->contextAttributes();
     95    _devicePixelRatio = attributes.devicePixelRatio;
     96    self.contentsOpaque = !attributes.alpha;
    5097    self.transform = CATransform3DIdentity;
    51     self.contentsScale = devicePixelRatio;
     98    self.contentsScale = _devicePixelRatio;
    5299    return self;
    53100}
     
    71118- (CGImageRef)copyImageSnapshotWithColorSpace:(CGColorSpaceRef)colorSpace
    72119{
     120    if (!_context)
     121        return nullptr;
    73122    // FIXME: implement. https://bugs.webkit.org/show_bug.cgi?id=217377
    74     // When implementing, remember to use self.contentsScale.
    75123    UNUSED_PARAM(colorSpace);
    76124    return nullptr;
    77125}
    78126
    79 - (WebCore::WebGLLayerBuffer) recycleBuffer
    80 {
    81     if (_spareBuffer.surface) {
    82         if (_spareBuffer.surface->isInUse())
    83             _spareBuffer.surface.reset();
    84         return WTFMove(_spareBuffer);
    85     }
    86     return { };
    87 }
    88 
    89 - (void)prepareForDisplayWithContents:(WebCore::WebGLLayerBuffer) buffer
    90 {
    91     ASSERT(!_spareBuffer.surface);
    92     _spareBuffer = WTFMove(_contentsBuffer);
    93     _contentsBuffer = WTFMove(buffer);
     127- (void)prepareForDisplay
     128{
     129    if (!_context)
     130        return;
     131
     132    // To avoid running any OpenGL code in `display`, this method should be called
     133    // at the end of the rendering task. We will flush all painting commands
     134    // leaving the buffers ready to composite.
     135
     136    if (!_context->makeContextCurrent()) {
     137        // Context is likely being torn down.
     138        return;
     139    }
     140    _context->prepareTexture();
     141    if (_drawingBuffer) {
     142        if (_latchedPbuffer) {
     143            WTF::Optional<ScopedRestoreTextureBinding> restoreBinding;
     144            GCGLenum textureTarget = WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTarget();
     145            // We don't need to restore GL_TEXTURE_RECTANGLE because it's not accessible from user code.
     146            if (textureTarget != WebCore::GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
     147                restoreBinding.emplace(WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTargetQuery(), textureTarget);
     148            GCGLenum texture = _context->platformTexture();
     149            gl::BindTexture(textureTarget, texture);
     150            if (!EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER)) {
     151                // FIXME: report error.
     152                notImplemented();
     153            }
     154            _latchedPbuffer = nullptr;
     155        }
     156
     157        std::swap(_contentsBuffer, _drawingBuffer);
     158        std::swap(_contentsPbuffer, _drawingPbuffer);
     159        [self bindFramebufferToNextAvailableSurface];
     160    }
    94161    [self setNeedsDisplay];
    95162    _preparedForDisplay = YES;
     
    98165- (void)display
    99166{
    100     if (_contentsBuffer.surface && _preparedForDisplay) {
    101         self.contents = _contentsBuffer.surface->asLayerContents();
     167    if (!_context)
     168        return;
     169
     170    // At this point we've painted into the _drawingBuffer and swapped it with the old _contentsBuffer,
     171    // so all we need to do here is tickle the CALayer to let it know it has new contents.
     172    // This avoids running any OpenGL code in this method.
     173
     174    if (_contentsBuffer && _preparedForDisplay) {
     175        self.contents = _contentsBuffer->asLayerContents();
    102176        [self reloadValueForKeyPath:@"contents"];
    103177    }
    104     if (_client)
    105         _client->didDisplay();
     178
     179    _context->markLayerComposited();
    106180    auto layer = WebCore::PlatformCALayer::platformCALayerForLayer((__bridge void*)self);
    107181    if (layer && layer->owner())
     
    111185}
    112186
    113 - (void*) detachClient
    114 {
    115     ASSERT(!_spareBuffer.surface);
    116     _client = nil;
    117     void* result = _contentsBuffer.handle;
    118     _contentsBuffer.handle = nullptr;
    119     return result;
    120 }
     187- (void)setEGLDisplay:(void*)display config:(void*)config
     188{
     189    _eglDisplay = display;
     190    _eglConfig = config;
     191}
     192
     193- (void)releaseGLResources
     194{
     195    if (!_context)
     196        return;
     197
     198    if (_context->makeContextCurrent() && _latchedPbuffer) {
     199        EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER);
     200        _latchedPbuffer = nullptr;
     201    }
     202
     203    EGL_DestroySurface(_eglDisplay, _contentsPbuffer);
     204    EGL_DestroySurface(_eglDisplay, _drawingPbuffer);
     205    EGL_DestroySurface(_eglDisplay, _sparePbuffer);
     206}
     207
     208- (bool)allocateIOSurfaceBackingStoreWithSize:(WebCore::IntSize)size usingAlpha:(BOOL)usingAlpha
     209{
     210    _bufferSize = size;
     211    _usingAlpha = usingAlpha;
     212    _contentsBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
     213    _drawingBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
     214    _spareBuffer = WebCore::IOSurface::create(size, WebCore::sRGBColorSpaceRef());
     215
     216    if (!_contentsBuffer || !_drawingBuffer || !_spareBuffer)
     217        return false;
     218
     219    _contentsBuffer->migrateColorSpaceToProperties();
     220    _drawingBuffer->migrateColorSpaceToProperties();
     221    _spareBuffer->migrateColorSpaceToProperties();
     222    const EGLint surfaceAttributes[] = {
     223        EGL_WIDTH, size.width(),
     224        EGL_HEIGHT, size.height(),
     225        EGL_IOSURFACE_PLANE_ANGLE, 0,
     226        EGL_TEXTURE_TARGET, WebCore::GraphicsContextGLOpenGL::EGLIOSurfaceTextureTarget(),
     227        EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, usingAlpha ? GL_BGRA_EXT : GL_RGB,
     228        EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
     229        EGL_TEXTURE_TYPE_ANGLE, GL_UNSIGNED_BYTE,
     230        // Only has an effect on the iOS Simulator.
     231        EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_WRITE_HINT_ANGLE,
     232        EGL_NONE, EGL_NONE
     233    };
     234
     235    _contentsPbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _contentsBuffer->surface(), _eglConfig, surfaceAttributes);
     236    _drawingPbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _drawingBuffer->surface(), _eglConfig, surfaceAttributes);
     237    _sparePbuffer = EGL_CreatePbufferFromClientBuffer(_eglDisplay, EGL_IOSURFACE_ANGLE, _spareBuffer->surface(), _eglConfig, surfaceAttributes);
     238
     239    if (!_contentsPbuffer || !_drawingPbuffer || !_sparePbuffer)
     240        return false;
     241
     242    return true;
     243}
     244
     245- (void)bindFramebufferToNextAvailableSurface
     246{
     247    WTF::Optional<ScopedRestoreTextureBinding> restoreBinding;
     248    GCGLenum textureTarget = WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTarget();
     249    // We don't need to restore GL_TEXTURE_RECTANGLE because it's not accessible from user code.
     250    if (textureTarget != WebCore::GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
     251        restoreBinding.emplace(WebCore::GraphicsContextGLOpenGL::IOSurfaceTextureTargetQuery(), textureTarget);
     252
     253    GCGLenum texture = _context->platformTexture();
     254    gl::BindTexture(textureTarget, texture);
     255
     256    if (_latchedPbuffer) {
     257        if (!EGL_ReleaseTexImage(_eglDisplay, _latchedPbuffer, EGL_BACK_BUFFER)) {
     258            // FIXME: report error.
     259            notImplemented();
     260        }
     261        _latchedPbuffer = nullptr;
     262    }
     263
     264    if (_drawingBuffer && _drawingBuffer->isInUse()) {
     265        std::swap(_drawingBuffer, _spareBuffer);
     266        std::swap(_drawingPbuffer, _sparePbuffer);
     267    }
     268
     269    // Link the IOSurface to the texture via the previously-created pbuffer.
     270    if (!EGL_BindTexImage(_eglDisplay, _drawingPbuffer, EGL_BACK_BUFFER)) {
     271        // FIXME: report error.
     272        notImplemented();
     273    }
     274    _latchedPbuffer = _drawingPbuffer;
     275}
     276
    121277@end
    122278
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h

    r268755 r268756  
    3636#include <wtf/UniqueArray.h>
    3737
    38 #if PLATFORM(COCOA)
    39 #include "IOSurface.h"
    40 #include "WebGLLayerClient.h"
    41 #endif
    42 
    4338#if USE(CA)
    4439#include "PlatformCALayer.h"
     
    6055OBJC_CLASS CALayer;
    6156OBJC_CLASS WebGLLayer;
     57typedef struct __IOSurface* IOSurfaceRef;
    6258#endif // PLATFORM(COCOA)
    6359
     
    8884class GraphicsContextGLOpenGLPrivate;
    8985
    90 class GraphicsContextGLOpenGL : public GraphicsContextGL
    91 #if PLATFORM(COCOA)
    92     , private WebGLLayerClient
    93 #endif
    94 {
     86class GraphicsContextGLOpenGL : public GraphicsContextGL {
    9587public:
    9688    class Client {
     
    552544
    553545#if PLATFORM(COCOA)
    554     bool reshapeDisplayBufferBacking();
    555     bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer);
     546    bool allocateIOSurfaceBackingStore(IntSize);
     547    void updateFramebufferTextureBackingStoreFromLayer();
    556548#if PLATFORM(MAC)
    557549    void updateCGLContext();
     
    690682
    691683    bool reshapeFBOs(const IntSize&);
    692     void prepareTextureImpl();
    693684    void resolveMultisamplingIfNecessary(const IntRect& = IntRect());
    694685    void attachDepthAndStencilBufferIfNeeded(GCGLuint internalDepthStencilFormat, int width, int height);
     
    696687#if PLATFORM(COCOA)
    697688    bool allowOfflineRenderers() const;
    698     // WebGLLayerClient overrides.
    699     void didDisplay() override;
    700689#endif
    701690
     
    902891
    903892#if PLATFORM(COCOA)
    904     // Backing store for the the buffer which is eventually used for display.
    905     // When preserveDrawingBuffer == false, this is the drawing buffer backing store.
    906     // When preserveDrawingBuffer == true, this is blitted to during display prepare.
    907     std::unique_ptr<IOSurface> m_displayBufferBacking;
    908     void* m_displayBufferPbuffer { nullptr };
    909 
    910893    bool m_hasSwitchedToHighPerformanceGPU { false };
    911894#endif
  • branches/safari-611.1.4-branch/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGLBase.cpp

    r268386 r268756  
    165165        return true;
    166166    }
     167    updateFramebufferTextureBackingStoreFromLayer();
    167168    ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_texture, 0);
    168169#endif // !USE(OPENGL_ES))
  • branches/safari-611.1.4-branch/Source/WebKit/ChangeLog

    r268649 r268756  
     12020-10-20  Alan Coon  <alancoon@apple.com>
     2
     3        Revert r268386. rdar://problem/70497386
     4
    152020-10-17  David Kilzer  <ddkilzer@apple.com>
    26
  • branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r268499 r268756  
    176176#include <WebCore/FrameView.h>
    177177#include <WebCore/FullscreenManager.h>
     178#include <WebCore/GraphicsContextGLOpenGL.h>
    178179#include <WebCore/HTMLAttachmentElement.h>
    179180#include <WebCore/HTMLFormElement.h>
  • branches/safari-611.1.4-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r268386 r268756  
    7272#import <WebCore/FrameView.h>
    7373#import <WebCore/GraphicsContext.h>
     74#import <WebCore/GraphicsContextGLOpenGL.h>
    7475#import <WebCore/HTMLConverter.h>
    7576#import <WebCore/HTMLPlugInImageElement.h>
Note: See TracChangeset for help on using the changeset viewer.