tor-browser

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

Platform.cpp (2499B)


      1 //
      2 // Copyright 2015 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 // Platform.cpp: Implementation methods for angle::Platform.
      8 
      9 #include <platform/PlatformMethods.h>
     10 
     11 #include <cstring>
     12 
     13 #include "common/debug.h"
     14 
     15 namespace
     16 {
     17 // TODO(jmadill): Make methods owned by egl::Display.
     18 angle::PlatformMethods &PlatformMethods()
     19 {
     20    static angle::PlatformMethods platformMethods;
     21    return platformMethods;
     22 }
     23 }  // anonymous namespace
     24 
     25 angle::PlatformMethods *ANGLEPlatformCurrent()
     26 {
     27    return &PlatformMethods();
     28 }
     29 
     30 bool ANGLE_APIENTRY ANGLEGetDisplayPlatform(angle::EGLDisplayType display,
     31                                            const char *const methodNames[],
     32                                            unsigned int methodNameCount,
     33                                            void *context,
     34                                            void *platformMethods)
     35 {
     36    angle::PlatformMethods **platformMethodsOut =
     37        reinterpret_cast<angle::PlatformMethods **>(platformMethods);
     38 
     39    // We allow for a lower input count of impl platform methods if the subset is correct.
     40    if (methodNameCount > angle::g_NumPlatformMethods)
     41    {
     42        ERR() << "Invalid platform method count: " << methodNameCount << ", expected "
     43              << angle::g_NumPlatformMethods << ".";
     44        return false;
     45    }
     46 
     47    for (unsigned int nameIndex = 0; nameIndex < methodNameCount; ++nameIndex)
     48    {
     49        const char *expectedName = angle::g_PlatformMethodNames[nameIndex];
     50        const char *actualName   = methodNames[nameIndex];
     51 
     52        // Skip deprecated methods.  The names of these methods start with |placeholder|.
     53        constexpr char kPlaceholder[] = "placeholder";
     54        if (strncmp(expectedName, kPlaceholder, sizeof(kPlaceholder) - 1) == 0)
     55        {
     56            continue;
     57        }
     58        if (strcmp(expectedName, actualName) != 0)
     59        {
     60            ERR() << "Invalid platform method name: " << actualName << ", expected " << expectedName
     61                  << ".";
     62            return false;
     63        }
     64    }
     65 
     66    // TODO(jmadill): Store platform methods in display.
     67    PlatformMethods().context = context;
     68    *platformMethodsOut       = &PlatformMethods();
     69    return true;
     70 }
     71 
     72 void ANGLE_APIENTRY ANGLEResetDisplayPlatform(angle::EGLDisplayType display)
     73 {
     74    // TODO(jmadill): Store platform methods in display.
     75    PlatformMethods() = angle::PlatformMethods();
     76 }