added new clang format and fixed window creation endless loops + implemented missing functions

dev
keldu.magnus 2020-10-27 05:04:44 +01:00
parent 04d4e2a02f
commit c43377a5a1
14 changed files with 536 additions and 371 deletions

121
.clang-format Normal file
View File

@ -0,0 +1,121 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 4
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: ForContinuationAndIndentation
...

View File

@ -8,11 +8,8 @@ namespace gin {
XcbDevice::XcbDevice(::Display *display, int screen,
xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen,
Own<InputStream> &&an)
: display{display},
screen{screen},
xcb_connection{xcb_connection},
xcb_screen{xcb_screen},
async_notifier{std::move(an)},
: display{display}, screen{screen}, xcb_connection{xcb_connection},
xcb_screen{xcb_screen}, async_notifier{std::move(an)},
async_conveyor{async_notifier->readReady()
.then([this]() { handleEvents(); })
.buffer(1)} {}
@ -28,6 +25,8 @@ void XcbDevice::windowDestroyed(xcb_window_t window_id) {
windows.erase(window_id);
}
void XcbDevice::handleEvents() {}
Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode &video_mode,
std::string_view title_view,
int visual_id) {
@ -45,9 +44,9 @@ Own<XcbWindow> XcbDevice::createXcbWindow(const VideoMode& video_mode,
uint32_t valuemask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
xcb_create_window(xcb_connection, XCB_COPY_FROM_PARENT, xcb_window,
xcb_screen->root, 0, 0, video_mode.width, video_mode.height,
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visual_id, valuemask,
valuelist);
xcb_screen->root, 0, 0, video_mode.width,
video_mode.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
visual_id, valuemask, valuelist);
xcb_change_property(xcb_connection, XCB_PROP_MODE_REPLACE, xcb_window,
XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, title_view.size(),

View File

@ -7,7 +7,8 @@
#include <string_view>
#include <vector>
#include "device_xcb.h"
#include "../device_xcb.h"
#include "gl_window_xcb.h"
namespace gin {
namespace {
@ -15,23 +16,24 @@ GlxLibraryExtensions glxLibraryExtensions(const char* extension_string) {
std::string_view extensions_view{extension_string};
std::set<std::string_view> extensions;
while (1) {
size_t n = extensions_view.find_first_not_of(' ');
size_t n = extensions_view.find_first_of(' ');
if (n != extensions_view.npos && n < extensions_view.size()) {
std::string_view sub_glx_ext = extensions_view.substr(0, n);
extensions.insert(sub_glx_ext);
extensions_view.remove_prefix(n + 1);
} else {
break;
}
}
auto find = extensions.find("glXCreateContextAttribsARB");
auto find = extensions.find("GLX_ARB_create_context");
GLXContext (*glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext,
Bool, const int *) = nullptr;
if (find != extensions.end()) {
glXCreateContextAttribsARB = reinterpret_cast<GLXContext (*)(
Display *, GLXFBConfig, GLXContext, Bool, const int *)>(
glXGetProcAddress(
reinterpret_cast<const GLubyte*>("glXCreateContextAttribsARB")));
glXGetProcAddress(reinterpret_cast<const GLubyte *>(
"glXCreateContextAttribsARB")));
}
return {extensions_view, glXCreateContextAttribsARB};
}
@ -64,11 +66,8 @@ int translateDrawableTypeSetting(GlSettings::DrawableType cmp) {
XcbGlContext::XcbGlContext(const GlxLibraryExtensions &ext_lib,
Own<XcbDevice> &&dev, int visual_id,
GLXContext context, GLXFBConfig fb_config)
: ext_lib{ext_lib},
device{std::move(dev)},
visual_id{visual_id},
context{context},
fb_config{fb_config} {}
: ext_lib{ext_lib}, device{std::move(dev)}, visual_id{visual_id},
context{context}, fb_config{fb_config} {}
XcbGlContext::~XcbGlContext() {
assert(device);
@ -84,10 +83,28 @@ void XcbGlContext::bind() {}
Own<GlWindow> XcbGlContext::createWindow(const VideoMode &video_mode,
std::string_view title_view) {
assert(device);
if (!device) {
return nullptr;
}
gin::Own<XcbWindow> window =
device->createXcbWindow(video_mode, title_view, visual_id);
if (!window) {
return nullptr;
}
void XcbGlContext::flush() {}
::GLXWindow glx_window = glXCreateWindow(device->display, fb_config,
window->xcb_window, nullptr);
return gin::heap<XcbGlWindow>(std::move(window), *this, glx_window);
}
void XcbGlContext::flush() {
assert(device);
if (device) {
device->flush();
}
}
Own<GlContext> createGlContext(AsyncIoProvider &provider,
const GlSettings &settings) {
@ -142,8 +159,8 @@ Own<GlContext> createGlContext(AsyncIoProvider& provider,
GlxLibraryExtensions lib_ext = glxLibraryExtensions(
glXQueryExtensionsString(device->display, device->screen));
GLXFBConfig* fb_configs = glXChooseFBConfig(device->display, device->screen,
&attributes[0], &num_fb_configs);
GLXFBConfig *fb_configs = glXChooseFBConfig(
device->display, device->screen, &attributes[0], &num_fb_configs);
if (!fb_configs || num_fb_configs == 0) {
/// @todo log errors
return nullptr;
@ -167,8 +184,8 @@ Own<GlContext> createGlContext(AsyncIoProvider& provider,
: GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
glx_attribs.push_back(None);
context = lib_ext.glXCreateContextAttribsARB(device->display, fb_config,
NULL, True, &glx_attribs[0]);
context = lib_ext.glXCreateContextAttribsARB(
device->display, fb_config, NULL, True, &glx_attribs[0]);
if (!context) {
return nullptr;
}

View File

@ -18,7 +18,7 @@ struct GlxLibraryExtensions {
class XcbDevice;
class XcbGlContext final : public GlContext {
private:
public:
GlxLibraryExtensions ext_lib;
Own<XcbDevice> device;
int visual_id;
@ -26,8 +26,8 @@ class XcbGlContext final : public GlContext {
GLXFBConfig fb_config;
public:
XcbGlContext(const GlxLibraryExtensions&, Own<XcbDevice>&&, int, GLXContext,
GLXFBConfig);
XcbGlContext(const GlxLibraryExtensions &, Own<XcbDevice> &&, int,
GLXContext, GLXFBConfig);
~XcbGlContext();
void bind() override;

View File

@ -1,5 +1,32 @@
#include "gl_window_xcb.h"
#include "window_xcb.h"
#include "gl_context_xcb.h"
namespace gin {}
#include "../device_xcb.h"
#include "../window_xcb.h"
#include <cassert>
namespace gin {
XcbGlWindow::XcbGlWindow(Own<XcbWindow> &&win, XcbGlContext &ctx,
::GLXWindow glx_win)
: window{std::move(win)}, context{ctx}, glx_window{glx_win} {}
XcbGlWindow::~XcbGlWindow() {
assert(context.device);
if (context.device) {
glXDestroyWindow(context.device->display, glx_window);
}
}
void XcbGlWindow::bind() {}
void XcbGlWindow::show() {
assert(window);
if (window) {
window->show();
}
}
void XcbGlWindow::swap() {}
} // namespace gin

View File

@ -18,5 +18,9 @@ class XcbGlWindow final : public GlWindow {
public:
XcbGlWindow(Own<XcbWindow> &&, XcbGlContext &, ::GLXWindow);
~XcbGlWindow();
void bind() override;
void swap() override;
void show() override;
};
} // namespace gin

View File

@ -8,11 +8,8 @@ namespace gin {
XcbWindow::XcbWindow(XcbDevice &device, xcb_window_t xcb_window,
xcb_colormap_t xcb_colormap, const VideoMode &video_mode,
std::string_view title_view)
: device{device},
xcb_window{xcb_window},
xcb_colormap{xcb_colormap},
video_mode{video_mode},
window_title{title_view} {}
: device{device}, xcb_window{xcb_window}, xcb_colormap{xcb_colormap},
video_mode{video_mode}, window_title{title_view} {}
XcbWindow::~XcbWindow() {
device.windowDestroyed(xcb_window);

View File

@ -1,6 +1,6 @@
#pragma once
#include "video_mode.h"
#include "../video_mode.h"
namespace gin {
class GlWindow {