Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display bottom rendering2 #788

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions obs-studio-client/source/nodeobs_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@ Napi::Value display::OBS_content_createDisplay(const Napi::CallbackInfo& info)
std::string key = info[1].ToString().Utf8Value();
int32_t mode = info[2].ToNumber().Int32Value();

bool renderAtBottom = false;

if (info.Length() > 3)
renderAtBottom = info[3].ToBoolean().Value();

auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

conn->call("Display", "OBS_content_createDisplay", {ipc::value((uint64_t)windowHandle), ipc::value(key), ipc::value(mode)});
conn->call("Display", "OBS_content_createDisplay",
{
ipc::value((uint64_t)windowHandle),
ipc::value(key),
ipc::value(mode),
ipc::value(renderAtBottom)
});
return info.Env().Undefined();
}

Expand Down Expand Up @@ -139,12 +150,22 @@ Napi::Value display::OBS_content_createSourcePreviewDisplay(const Napi::Callback
std::string sourceName = info[1].ToString().Utf8Value();
std::string key = info[2].ToString().Utf8Value();

bool renderAtBottom = false;

if (info.Length() > 3)
renderAtBottom = info[3].ToBoolean().Value();

auto conn = GetConnection(info);
if (!conn)
return info.Env().Undefined();

conn->call("Display", "OBS_content_createSourcePreviewDisplay",
{ipc::value((uint64_t)windowHandle), ipc::value(sourceName), ipc::value(key)});
{
ipc::value((uint64_t)windowHandle),
ipc::value(sourceName),
ipc::value(key),
ipc::value(renderAtBottom)
});

return info.Env().Undefined();
}
Expand Down
13 changes: 8 additions & 5 deletions obs-studio-server/source/nodeobs_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void OBS_content::Register(ipc::server& srv)

cls->register_function(std::make_shared<ipc::function>(
"OBS_content_createDisplay",
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::Int32},
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::Int32, ipc::type::Int32},
OBS_content_createDisplay));

cls->register_function(std::make_shared<ipc::function>(
Expand All @@ -172,7 +172,7 @@ void OBS_content::Register(ipc::server& srv)

cls->register_function(std::make_shared<ipc::function>(
"OBS_content_createSourcePreviewDisplay",
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::String},
std::vector<ipc::type>{ipc::type::UInt64, ipc::type::String, ipc::type::String, ipc::type::Int32},
OBS_content_createSourcePreviewDisplay));

cls->register_function(std::make_shared<ipc::function>(
Expand Down Expand Up @@ -274,7 +274,7 @@ void OBS_content::OBS_content_createDisplay(
}

#ifdef WIN32
displays.insert_or_assign(args[1].value_str, new OBS::Display(windowHandle, mode));
displays.insert_or_assign(args[1].value_str, new OBS::Display(windowHandle, mode, args[3].value_union.i32));
if (!IsWindows8OrGreater()) {
BOOL enabled = FALSE;
DwmIsCompositionEnabled(&enabled);
Expand All @@ -283,7 +283,7 @@ void OBS_content::OBS_content_createDisplay(
}
}
#else
OBS::Display *display = new OBS::Display(windowHandle, mode);
OBS::Display *display = new OBS::Display(windowHandle, mode, args[3].value_union.i32);
displays.insert_or_assign(args[1].value_str, display);
#endif

Expand Down Expand Up @@ -350,7 +350,10 @@ void OBS_content::OBS_content_createSourcePreviewDisplay(
return;
}

OBS::Display *display = new OBS::Display(windowHandle, OBS_MAIN_VIDEO_RENDERING, args[1].value_str);
OBS::Display *display = new OBS::Display(
windowHandle,
OBS_MAIN_VIDEO_RENDERING,
args[1].value_str, args[3].value_union.i32);
displays.insert_or_assign(
args[2].value_str, display);

Expand Down
33 changes: 17 additions & 16 deletions obs-studio-server/source/nodeobs_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,26 @@ void OBS::Display::SystemWorker()

BOOL enabled = FALSE;
DwmIsCompositionEnabled(&enabled);
DWORD windowStyle;
DWORD windowStyle = WS_VISIBLE;
DWORD windowEXStyle = 0;

if (IsWindows8OrGreater() || !enabled) {
windowStyle = WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST;
} else {
windowStyle = WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_COMPOSITED;
windowEXStyle = WS_EX_LAYERED;
}

windowStyle |= this->m_renderAtBottom ? WS_CHILD : WS_POPUP;
windowEXStyle |= WS_EX_TRANSPARENT;

HWND newWindow = CreateWindowEx(
windowStyle,
windowEXStyle,
TEXT("Win32DisplayClass"),
TEXT("SlobsChildWindowPreview"),
WS_VISIBLE | WS_POPUP | WS_CHILD,
windowStyle,
0,
0,
question->width,
question->height,
NULL,
question->parentWindow,
NULL,
NULL,
this);
Expand All @@ -186,11 +188,9 @@ void OBS::Display::SystemWorker()
answer->success = false;
HandleWin32ErrorMessage(GetLastError());
} else {
if (IsWindows8OrGreater() || !enabled) {
SetLayeredWindowAttributes(newWindow, 0, 255, LWA_ALPHA);
}

SetParent(newWindow, question->parentWindow);
SetLayeredWindowAttributes(newWindow, 0, 255, LWA_ALPHA);
if (!this->m_renderAtBottom)
SetParent(newWindow, question->parentWindow);
answer->windowHandle = newWindow;
answer->success = true;
}
Expand Down Expand Up @@ -322,7 +322,7 @@ OBS::Display::Display()
m_drawGuideLines = true;
}

OBS::Display::Display(uint64_t windowHandle, enum obs_video_rendering_mode mode) : Display()
OBS::Display::Display(uint64_t windowHandle, enum obs_video_rendering_mode mode, bool renderAtBottom) : Display()
{
#ifdef _WIN32
CreateWindowMessageQuestion question;
Expand Down Expand Up @@ -362,12 +362,13 @@ OBS::Display::Display(uint64_t windowHandle, enum obs_video_rendering_mode mode)
}

m_renderingMode = mode;
m_renderAtBottom = renderAtBottom;

obs_display_add_draw_callback(m_display, DisplayCallback, this);
}

OBS::Display::Display(uint64_t windowHandle, enum obs_video_rendering_mode mode, std::string sourceName)
: Display(windowHandle, mode)
OBS::Display::Display(uint64_t windowHandle, enum obs_video_rendering_mode mode, std::string sourceName, bool renderAtBottom)
: Display(windowHandle, mode, renderAtBottom)
{
m_source = obs_get_source_by_name(sourceName.c_str());
obs_source_inc_showing(m_source);
Expand Down Expand Up @@ -465,7 +466,7 @@ void OBS::Display::SetPosition(uint32_t x, uint32_t y)

uint32_t offset_y = rect_intermediate.top - rect_parent.top;

SetWindowPos( m_ourWindow, NULL, m_position.first, m_position.second + offset_y, m_gsInitData.cx, m_gsInitData.cy, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
SetWindowPos( m_ourWindow, this->m_renderAtBottom ? HWND_BOTTOM : NULL, m_position.first, m_position.second + offset_y, m_gsInitData.cx, m_gsInitData.cy, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
#endif
}

Expand Down
7 changes: 5 additions & 2 deletions obs-studio-server/source/nodeobs_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ namespace OBS

public:
Display(uint64_t windowHandle,
enum obs_video_rendering_mode mode); // Create a Main Preview one
enum obs_video_rendering_mode mode, // Create a Main Preview one
bool renderAtBottom);
Display(uint64_t windowHandle,
enum obs_video_rendering_mode mode,
std::string sourceName); // Create a Source-Specific one
std::string sourceName, // Create a Source-Specific one
bool renderAtBottom);
~Display();

void SetPosition(uint32_t x, uint32_t y);
Expand Down Expand Up @@ -129,6 +131,7 @@ namespace OBS
uint32_t m_resizeOuterColor = 0xFF7E7E7E;
uint32_t m_resizeInnerColor = 0xFFFFFFFF;
bool m_shouldDrawUI = true;
bool m_renderAtBottom = false;

enum obs_video_rendering_mode m_renderingMode = OBS_MAIN_VIDEO_RENDERING;

Expand Down