1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef sw_SwiftConfig_hpp 16 #define sw_SwiftConfig_hpp 17 18 #include "Reactor/Nucleus.hpp" 19 20 #include "Common/Thread.hpp" 21 #include "Common/MutexLock.hpp" 22 #include "Common/Socket.hpp" 23 24 #include <string> 25 26 namespace sw 27 { 28 class SwiftConfig 29 { 30 public: 31 struct Configuration 32 { 33 int pixelShaderVersion; 34 int vertexShaderVersion; 35 int textureMemory; 36 int identifier; 37 int vertexRoutineCacheSize; 38 int pixelRoutineCacheSize; 39 int setupRoutineCacheSize; 40 int vertexCacheSize; 41 int textureSampleQuality; 42 int mipmapQuality; 43 bool perspectiveCorrection; 44 int transcendentalPrecision; 45 int threadCount; 46 bool enableSSE; 47 bool enableSSE2; 48 bool enableSSE3; 49 bool enableSSSE3; 50 bool enableSSE4_1; 51 Optimization optimization[10]; 52 bool disableServer; 53 bool keepSystemCursor; 54 bool forceWindowed; 55 bool complementaryDepthBuffer; 56 bool postBlendSRGB; 57 bool exactColorRounding; 58 bool disableAlphaMode; 59 bool disable10BitMode; 60 int transparencyAntialiasing; 61 int frameBufferAPI; 62 bool precache; 63 int shadowMapping; 64 bool forceClearRegisters; 65 #ifndef NDEBUG 66 unsigned int minPrimitives; 67 unsigned int maxPrimitives; 68 #endif 69 }; 70 71 SwiftConfig(bool disableServerOverride); 72 73 ~SwiftConfig(); 74 75 bool hasNewConfiguration(bool reset = true); 76 void getConfiguration(Configuration &configuration); 77 78 private: 79 enum Status 80 { 81 OK = 200, 82 NotFound = 404 83 }; 84 85 void createServer(); 86 void destroyServer(); 87 88 static void serverRoutine(void *parameters); 89 90 void serverLoop(); 91 void respond(Socket *clientSocket, const char *request); 92 std::string page(); 93 std::string profile(); 94 void send(Socket *clientSocket, Status code, std::string body = ""); 95 void parsePost(const char *post); 96 97 void readConfiguration(bool disableServerOverride = false); 98 void writeConfiguration(); 99 100 Configuration config; 101 102 Thread *serverThread; 103 volatile bool terminate; 104 MutexLock criticalSection; // Protects reading and writing the configuration settings 105 106 bool newConfig; 107 108 Socket *listenSocket; 109 110 int bufferLength; 111 char *receiveBuffer; 112 }; 113 } 114 115 #endif // sw_SwiftConfig_hpp 116