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 <array>
25#include <string>
26
27namespace sw
28{
29 class SwiftConfig
30 {
31 public:
32 struct Configuration
33 {
34 int pixelShaderVersion;
35 int vertexShaderVersion;
36 int textureMemory;
37 int identifier;
38 int vertexRoutineCacheSize;
39 int pixelRoutineCacheSize;
40 int setupRoutineCacheSize;
41 int vertexCacheSize;
42 int textureSampleQuality;
43 int mipmapQuality;
44 bool perspectiveCorrection;
45 int transcendentalPrecision;
46 int threadCount;
47 bool enableSSE;
48 bool enableSSE2;
49 bool enableSSE3;
50 bool enableSSSE3;
51 bool enableSSE4_1;
52 std::array<rr::Optimization::Pass, 10> optimization;
53 bool disableServer;
54 bool keepSystemCursor;
55 bool forceWindowed;
56 bool complementaryDepthBuffer;
57 bool postBlendSRGB;
58 bool exactColorRounding;
59 bool disableAlphaMode;
60 bool disable10BitMode;
61 int transparencyAntialiasing;
62 int frameBufferAPI;
63 bool precache;
64 int shadowMapping;
65 bool forceClearRegisters;
66 #ifndef NDEBUG
67 unsigned int minPrimitives;
68 unsigned int maxPrimitives;
69 #endif
70 };
71
72 SwiftConfig(bool disableServerOverride);
73
74 ~SwiftConfig();
75
76 bool hasNewConfiguration(bool reset = true);
77 void getConfiguration(Configuration &configuration);
78
79 private:
80 enum Status
81 {
82 OK = 200,
83 NotFound = 404
84 };
85
86 void createServer();
87 void destroyServer();
88
89 static void serverRoutine(void *parameters);
90
91 void serverLoop();
92 void respond(Socket *clientSocket, const char *request);
93 std::string page();
94 std::string profile();
95 void send(Socket *clientSocket, Status code, std::string body = "");
96 void parsePost(const char *post);
97
98 void readConfiguration(bool disableServerOverride = false);
99 void writeConfiguration();
100
101 Configuration config;
102
103 Thread *serverThread;
104 volatile bool terminate;
105 MutexLock criticalSection; // Protects reading and writing the configuration settings
106
107 bool newConfig;
108
109 Socket *listenSocket;
110
111 int bufferLength;
112 char *receiveBuffer;
113 };
114}
115
116#endif // sw_SwiftConfig_hpp
117