Prep for image support in windows.

This commit is contained in:
James Grogan 2022-11-11 15:51:37 +00:00
parent 53c98a227d
commit e7683cd94e
13 changed files with 172 additions and 135 deletions

View file

@ -1,22 +1,80 @@
#include "XcbWindow.h"
XcbWindow::XcbWindow(int hwnd)
: mHandle(hwnd)
#include "Window.h"
#include "XcbLayerInterface.h"
#include "XcbScreen.h"
#include "XcbImage.h"
#include "Screen.h"
#include <xcb/xcb.h>
XcbWindow::XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection)
: mHandle(hwnd),
mWindow(window),
mBackingImage(std::make_unique<XcbImage>()),
mConnection(connection)
{
}
std::unique_ptr<XcbWindow> XcbWindow::Create(int hwnd)
void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask)
{
return std::make_unique<XcbWindow>(hwnd);
if (!screen)
{
return;
}
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
const auto hwnd = xcb_generate_id(connection);
const uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
const uint32_t values[2] = {xcb_screen->GetNativeScreen()->white_pixel, eventMask};
xcb_create_window (connection, /* connection */
XCB_COPY_FROM_PARENT, /* depth */
hwnd, /* window Id */
xcb_screen->GetNativeScreen()->root, /* parent window */
0, 0, /* x, y */
window->GetWidth(), window->GetHeight(), /* width, height */
10, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
xcb_screen->GetNativeScreen()->root_visual, /* visual */
mask, values ); /* masks */
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection);
window->SetPlatformWindow(std::move(xcb_window));
}
int XcbWindow::GetHandle() const
int XcbWindow::getHandle() const
{
return mHandle;
}
unsigned XcbWindow::GetGraphicsContext() const
unsigned XcbWindow::getGraphicsContext() const
{
return mGraphicsContext;
}
void XcbWindow::show() const
{
map();
}
void XcbWindow::paint(mt::Screen* screen) const
{
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
for(const auto& layer : mWindow->GetLayers())
{
XcbLayerInterface::AddLayer(mConnection, xcb_screen->GetNativeScreen(), mHandle, xcb_screen->GetGraphicsContext(), layer);
}
}
void XcbWindow::clear() const
{
xcb_clear_area(mConnection, 1, mHandle, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
xcb_flush(mConnection);
}
void XcbWindow::map() const
{
xcb_map_window(mConnection, mHandle);
xcb_flush(mConnection);
}