tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

EGLSync.cpp (3170B)


      1 //
      2 // Copyright 2002 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // EGLSync.cpp: Implements the egl::Sync class.
      8 
      9 #include "libANGLE/EGLSync.h"
     10 
     11 #include "angle_gl.h"
     12 
     13 #include "common/utilities.h"
     14 #include "libANGLE/renderer/EGLImplFactory.h"
     15 #include "libANGLE/renderer/EGLReusableSync.h"
     16 #include "libANGLE/renderer/EGLSyncImpl.h"
     17 
     18 namespace egl
     19 {
     20 
     21 Sync::Sync(rx::EGLImplFactory *factory, EGLenum type, const AttributeMap &attribs)
     22    : mLabel(nullptr),
     23      mType(type),
     24      mCondition(EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR),
     25      mNativeFenceFD(
     26          attribs.getAsInt(EGL_SYNC_NATIVE_FENCE_FD_ANDROID, EGL_NO_NATIVE_FENCE_FD_ANDROID))
     27 {
     28    switch (type)
     29    {
     30        case EGL_SYNC_FENCE:
     31        case EGL_SYNC_NATIVE_FENCE_ANDROID:
     32        case EGL_SYNC_METAL_SHARED_EVENT_ANGLE:
     33            mFence = std::unique_ptr<rx::EGLSyncImpl>(factory->createSync(attribs));
     34            break;
     35 
     36        case EGL_SYNC_REUSABLE_KHR:
     37            mFence = std::unique_ptr<rx::EGLSyncImpl>(new rx::ReusableSync(attribs));
     38            break;
     39 
     40        default:
     41            UNREACHABLE();
     42    }
     43 
     44    // Per extension spec: Signaling Condition.
     45    // "If the EGL_SYNC_NATIVE_FENCE_FD_ANDROID attribute is not
     46    // EGL_NO_NATIVE_FENCE_FD_ANDROID then the EGL_SYNC_CONDITION_KHR attribute
     47    // is set to EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID and the EGL_SYNC_STATUS_KHR
     48    // attribute is set to reflect the signal status of the native fence object.
     49    if ((mType == EGL_SYNC_NATIVE_FENCE_ANDROID) &&
     50        (mNativeFenceFD != EGL_NO_NATIVE_FENCE_FD_ANDROID))
     51    {
     52        mCondition = EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID;
     53    }
     54 }
     55 
     56 void Sync::onDestroy(const Display *display)
     57 {
     58    ASSERT(mFence);
     59    mFence->onDestroy(display);
     60    mFence.reset();
     61 }
     62 
     63 Sync::~Sync() {}
     64 
     65 Error Sync::initialize(const Display *display, const gl::Context *context)
     66 {
     67    return mFence->initialize(display, context, mType);
     68 }
     69 
     70 void Sync::setLabel(EGLLabelKHR label)
     71 {
     72    mLabel = label;
     73 }
     74 
     75 EGLLabelKHR Sync::getLabel() const
     76 {
     77    return mLabel;
     78 }
     79 
     80 Error Sync::clientWait(const Display *display,
     81                       const gl::Context *context,
     82                       EGLint flags,
     83                       EGLTime timeout,
     84                       EGLint *outResult)
     85 {
     86    return mFence->clientWait(display, context, flags, timeout, outResult);
     87 }
     88 
     89 Error Sync::serverWait(const Display *display, const gl::Context *context, EGLint flags)
     90 {
     91    return mFence->serverWait(display, context, flags);
     92 }
     93 
     94 Error Sync::signal(const Display *display, const gl::Context *context, EGLint mode)
     95 {
     96    return mFence->signal(display, context, mode);
     97 }
     98 
     99 Error Sync::getStatus(const Display *display, EGLint *outStatus) const
    100 {
    101    return mFence->getStatus(display, outStatus);
    102 }
    103 
    104 Error Sync::copyMetalSharedEventANGLE(const Display *display, void **result) const
    105 {
    106    return mFence->copyMetalSharedEventANGLE(display, result);
    107 }
    108 
    109 Error Sync::dupNativeFenceFD(const Display *display, EGLint *result) const
    110 {
    111    return mFence->dupNativeFenceFD(display, result);
    112 }
    113 
    114 }  // namespace egl