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/Platform.h>
10 
11 #include <cstring>
12 
13 #include "common/debug.h"
14 
15 namespace
16 {
17 // TODO(jmadill): Make methods owned by egl::Display.
PlatformMethods()18 angle::PlatformMethods &PlatformMethods()
19 {
20     static angle::PlatformMethods platformMethods;
21     return platformMethods;
22 }
23 }  // anonymous namespace
24 
ANGLEPlatformCurrent()25 angle::PlatformMethods *ANGLEPlatformCurrent()
26 {
27     return &PlatformMethods();
28 }
29 
ANGLEGetDisplayPlatform(angle::EGLDisplayType display,const char * const methodNames[],unsigned int methodNameCount,void * context,void * platformMethods)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         if (strcmp(expectedName, actualName) != 0)
52         {
53             ERR() << "Invalid platform method name: " << actualName << ", expected " << expectedName
54                   << ".";
55             return false;
56         }
57     }
58 
59     // TODO(jmadill): Store platform methods in display.
60     PlatformMethods().context = context;
61     *platformMethodsOut       = &PlatformMethods();
62     return true;
63 }
64 
ANGLEResetDisplayPlatform(angle::EGLDisplayType display)65 void ANGLE_APIENTRY ANGLEResetDisplayPlatform(angle::EGLDisplayType display)
66 {
67     // TODO(jmadill): Store platform methods in display.
68     PlatformMethods() = angle::PlatformMethods();
69 }
70