Skip to content

Commit 22ffabe

Browse files
null77dhritzkiv
authored andcommitted
Format all c++ files with clang-format.
1 parent ee42968 commit 22ffabe

File tree

6 files changed

+774
-984
lines changed

6 files changed

+774
-984
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ColumnLimit: 100

src/native/SharedLibrary.cc

+37-46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <string>
21
#include <array>
2+
#include <string>
33

44
#ifdef _WIN32
55
#include <windows.h>
@@ -8,62 +8,53 @@
88
#endif
99

1010
#ifdef _WIN32
11-
std::string Narrow(const std::wstring_view &utf16)
12-
{
13-
if (utf16.empty())
14-
{
15-
return {};
16-
}
17-
int requiredSize = WideCharToMultiByte(CP_UTF8, 0, utf16.data(), static_cast<int>(utf16.size()),
18-
nullptr, 0, nullptr, nullptr);
19-
std::string utf8(requiredSize, '\0');
20-
WideCharToMultiByte(CP_UTF8, 0, utf16.data(), static_cast<int>(utf16.size()), &utf8[0],
21-
requiredSize, nullptr, nullptr);
22-
return utf8;
11+
std::string Narrow(const std::wstring_view &utf16) {
12+
if (utf16.empty()) {
13+
return {};
14+
}
15+
int requiredSize = WideCharToMultiByte(CP_UTF8, 0, utf16.data(), static_cast<int>(utf16.size()),
16+
nullptr, 0, nullptr, nullptr);
17+
std::string utf8(requiredSize, '\0');
18+
WideCharToMultiByte(CP_UTF8, 0, utf16.data(), static_cast<int>(utf16.size()), &utf8[0],
19+
requiredSize, nullptr, nullptr);
20+
return utf8;
2321
}
2422

25-
std::string GetPath(HMODULE module)
26-
{
27-
std::array<wchar_t, MAX_PATH> executableFileBuf;
28-
DWORD executablePathLen = GetModuleFileNameW(module, executableFileBuf.data(),
29-
static_cast<DWORD>(executableFileBuf.size()));
30-
return Narrow(executablePathLen > 0 ? executableFileBuf.data() : L"");
23+
std::string GetPath(HMODULE module) {
24+
std::array<wchar_t, MAX_PATH> executableFileBuf;
25+
DWORD executablePathLen = GetModuleFileNameW(module, executableFileBuf.data(),
26+
static_cast<DWORD>(executableFileBuf.size()));
27+
return Narrow(executablePathLen > 0 ? executableFileBuf.data() : L"");
3128
}
3229

33-
std::string GetModulePath(void *moduleOrSymbol)
34-
{
35-
HMODULE module = nullptr;
36-
if (GetModuleHandleExW(
37-
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
38-
reinterpret_cast<LPCWSTR>(moduleOrSymbol), &module))
39-
{
40-
return GetPath(module);
41-
}
30+
std::string GetModulePath(void *moduleOrSymbol) {
31+
HMODULE module = nullptr;
32+
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
33+
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
34+
reinterpret_cast<LPCWSTR>(moduleOrSymbol), &module)) {
35+
return GetPath(module);
36+
}
4237

43-
return "";
38+
return "";
4439
}
4540
#else
46-
std::string GetModulePath(void *moduleOrSymbol)
47-
{
48-
Dl_info dlInfo;
49-
if (dladdr(moduleOrSymbol, &dlInfo) == 0)
50-
{
51-
return "";
52-
}
41+
std::string GetModulePath(void *moduleOrSymbol) {
42+
Dl_info dlInfo;
43+
if (dladdr(moduleOrSymbol, &dlInfo) == 0) {
44+
return "";
45+
}
5346

54-
return dlInfo.dli_fname;
47+
return dlInfo.dli_fname;
5548
}
5649
#endif
5750

58-
std::string StripFilenameFromPath(const std::string &path)
59-
{
60-
size_t lastPathSepLoc = path.find_last_of("\\/");
61-
return (lastPathSepLoc != std::string::npos) ? path.substr(0, lastPathSepLoc) : "";
51+
std::string StripFilenameFromPath(const std::string &path) {
52+
size_t lastPathSepLoc = path.find_last_of("\\/");
53+
return (lastPathSepLoc != std::string::npos) ? path.substr(0, lastPathSepLoc) : "";
6254
}
6355

64-
std::string GetModuleDirectory()
65-
{
66-
static int placeholderSymbol = 0;
67-
std::string moduleName = GetModulePath(&placeholderSymbol);
68-
return StripFilenameFromPath(moduleName);
56+
std::string GetModuleDirectory() {
57+
static int placeholderSymbol = 0;
58+
std::string moduleName = GetModulePath(&placeholderSymbol);
59+
return StripFilenameFromPath(moduleName);
6960
}

src/native/SharedLibrary.h

+23-22
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
inline std::string GetSharedLibraryExtension() {
1414
#ifdef _WIN32
15-
return ".dll"; // Windows
15+
return ".dll"; // Windows
1616
#elif __APPLE__
17-
return ".dylib"; // OSX
17+
return ".dylib"; // OSX
1818
#elif __linux__
19-
return ".so"; // Linux
19+
return ".so"; // Linux
2020
#else
2121
#error Unsupported platform
2222
#endif
@@ -26,38 +26,39 @@ std::string GetModuleDirectory();
2626

2727
class SharedLibrary {
2828
public:
29-
SharedLibrary() {}
29+
SharedLibrary() {}
3030

31-
bool open(const std::string& libraryPath) {
32-
const std::string libraryPathWithExt = GetModuleDirectory() + "/" + libraryPath + GetSharedLibraryExtension();
31+
bool open(const std::string &libraryPath) {
32+
const std::string libraryPathWithExt =
33+
GetModuleDirectory() + "/" + libraryPath + GetSharedLibraryExtension();
3334
#ifdef _WIN32
34-
handle = LoadLibraryA(libraryPathWithExt.c_str());
35+
handle = LoadLibraryA(libraryPathWithExt.c_str());
3536
#else
36-
handle = dlopen(libraryPathWithExt.c_str(), RTLD_LAZY);
37+
handle = dlopen(libraryPathWithExt.c_str(), RTLD_LAZY);
3738
#endif
38-
return handle != nullptr;
39-
}
39+
return handle != nullptr;
40+
}
4041

41-
~SharedLibrary() {
42-
if (handle) {
42+
~SharedLibrary() {
43+
if (handle) {
4344
#ifdef _WIN32
44-
FreeLibrary(static_cast<HMODULE>(handle));
45+
FreeLibrary(static_cast<HMODULE>(handle));
4546
#else
46-
dlclose(handle);
47+
dlclose(handle);
4748
#endif
48-
}
4949
}
50+
}
5051

51-
template <typename Func>
52-
Func getFunction(const std::string& functionName) {
52+
template <typename Func> Func getFunction(const std::string &functionName) {
5353
#ifdef _WIN32
54-
auto func = reinterpret_cast<Func>(GetProcAddress(static_cast<HMODULE>(handle), functionName.c_str()));
54+
auto func =
55+
reinterpret_cast<Func>(GetProcAddress(static_cast<HMODULE>(handle), functionName.c_str()));
5556
#else
56-
auto func = reinterpret_cast<Func>(dlsym(handle, functionName.c_str()));
57+
auto func = reinterpret_cast<Func>(dlsym(handle, functionName.c_str()));
5758
#endif
58-
return func;
59-
}
59+
return func;
60+
}
6061

6162
private:
62-
void* handle = nullptr;
63+
void *handle = nullptr;
6364
};

src/native/bindings.cc

+17-34
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,25 @@
55
* Author: ngk437
66
*/
77

8-
#include <cstdlib>
98
#include "webgl.h"
9+
#include <cstdlib>
1010

1111
Nan::Persistent<v8::FunctionTemplate> WEBGL_TEMPLATE;
1212

13-
#define JS_GL_METHOD(webgl_name, method_name) \
14-
Nan::SetPrototypeTemplate(\
15-
webgl_template \
16-
, webgl_name\
17-
, Nan::New<v8::FunctionTemplate>(\
18-
WebGLRenderingContext:: method_name))
13+
#define JS_GL_METHOD(webgl_name, method_name) \
14+
Nan::SetPrototypeTemplate(webgl_template, webgl_name, \
15+
Nan::New<v8::FunctionTemplate>(WebGLRenderingContext::method_name))
1916

20-
#define JS_CONSTANT(x, v) \
21-
Nan::SetPrototypeTemplate( \
22-
webgl_template \
23-
, #x \
24-
, Nan::New<v8::Integer>(v))
17+
#define JS_CONSTANT(x, v) Nan::SetPrototypeTemplate(webgl_template, #x, Nan::New<v8::Integer>(v))
2518

26-
#define JS_GL_CONSTANT(name) JS_CONSTANT(name, GL_ ## name)
19+
#define JS_GL_CONSTANT(name) JS_CONSTANT(name, GL_##name)
2720

2821
NAN_MODULE_INIT(Init) {
2922
v8::Local<v8::FunctionTemplate> webgl_template =
30-
Nan::New<v8::FunctionTemplate>(WebGLRenderingContext::New);
23+
Nan::New<v8::FunctionTemplate>(WebGLRenderingContext::New);
3124

3225
webgl_template->InstanceTemplate()->SetInternalFieldCount(1);
33-
webgl_template->SetClassName(
34-
Nan::New<v8::String>("WebGLRenderingContext").ToLocalChecked());
26+
webgl_template->SetClassName(Nan::New<v8::String>("WebGLRenderingContext").ToLocalChecked());
3527

3628
/* WebGL methods */
3729
JS_GL_METHOD("_drawArraysInstancedANGLE", DrawArraysInstancedANGLE);
@@ -167,25 +159,18 @@ NAN_MODULE_INIT(Init) {
167159
JS_GL_METHOD("bindVertexArrayOES", BindVertexArrayOES);
168160

169161
// Windows defines a macro called NO_ERROR which messes this up
170-
Nan::SetPrototypeTemplate(
171-
webgl_template,
172-
"NO_ERROR",
173-
Nan::New<v8::Integer>(GL_NO_ERROR));
162+
Nan::SetPrototypeTemplate(webgl_template, "NO_ERROR", Nan::New<v8::Integer>(GL_NO_ERROR));
174163
JS_GL_CONSTANT(INVALID_ENUM);
175164
JS_GL_CONSTANT(INVALID_VALUE);
176165
JS_GL_CONSTANT(INVALID_OPERATION);
177166
JS_GL_CONSTANT(OUT_OF_MEMORY);
178167

179168
// OpenGL ES 2.1 constants
180-
Nan::SetPrototypeTemplate(
181-
webgl_template
182-
, "DEPTH_STENCIL"
183-
, Nan::New<v8::Integer>(GL_DEPTH_STENCIL_OES));
169+
Nan::SetPrototypeTemplate(webgl_template, "DEPTH_STENCIL",
170+
Nan::New<v8::Integer>(GL_DEPTH_STENCIL_OES));
184171

185-
Nan::SetPrototypeTemplate(
186-
webgl_template
187-
, "DEPTH_STENCIL_ATTACHMENT"
188-
, Nan::New<v8::Integer>(0x821A));
172+
Nan::SetPrototypeTemplate(webgl_template, "DEPTH_STENCIL_ATTACHMENT",
173+
Nan::New<v8::Integer>(0x821A));
189174

190175
JS_GL_CONSTANT(MAX_VERTEX_UNIFORM_VECTORS);
191176
JS_GL_CONSTANT(MAX_VARYING_VECTORS);
@@ -480,14 +465,12 @@ NAN_MODULE_INIT(Init) {
480465
JS_CONSTANT(IMPLEMENTATION_COLOR_READ_TYPE, 0x8B9A);
481466
JS_CONSTANT(IMPLEMENTATION_COLOR_READ_FORMAT, 0x8B9B);
482467

483-
//Export template
468+
// Export template
484469
WEBGL_TEMPLATE.Reset(webgl_template);
485-
Nan::Set(
486-
target
487-
, Nan::New<v8::String>("WebGLRenderingContext").ToLocalChecked()
488-
, Nan::GetFunction(webgl_template).ToLocalChecked());
470+
Nan::Set(target, Nan::New<v8::String>("WebGLRenderingContext").ToLocalChecked(),
471+
Nan::GetFunction(webgl_template).ToLocalChecked());
489472

490-
//Export helper methods for clean up and error handling
473+
// Export helper methods for clean up and error handling
491474
Nan::Export(target, "cleanup", WebGLRenderingContext::DisposeAll);
492475
Nan::Export(target, "setError", WebGLRenderingContext::SetError);
493476
}

0 commit comments

Comments
 (0)