Clean image types

This commit is contained in:
James Grogan 2022-11-11 16:32:55 +00:00
parent e7683cd94e
commit c6d03f16d0
18 changed files with 169 additions and 107 deletions

View file

@ -1,9 +1,10 @@
#include "WaylandSurface.h"
#include "WaylandEglWindowInterface.h"
#include "ImagePrimitives.h"
WaylandSurface::WaylandSurface(mt::Window* window)
: mWindow(window)
: IPlatformWindow(window)
{
}
@ -36,17 +37,22 @@ void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_b
mXdgTopLevel = xdg_surface_get_toplevel(mXdgSurface);
xdg_toplevel_set_title(mXdgTopLevel, "Example client");
wl_surface_commit(mSurface);
auto region = wl_compositor_create_region(compositor);
wl_region_add(region, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
wl_surface_set_opaque_region(mSurface, region);
wl_surface_commit(mSurface);
}
void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
{
xdg_surface_ack_configure(xdg_surface, serial);
paint(nullptr);
}
void WaylandSurface::paint(mt::Screen* screen)
{
if (mEglWindowInterface)
{
mEglWindowInterface->initialize(mSurface, mWindow->GetWidth(), mWindow->GetHeight());
@ -77,29 +83,11 @@ wl_buffer* WaylandSurface::drawFrame()
mBuffer->setUpPool(shm_pool_size, width, height, stride);
int offset = 0;
drawCheckerboard(width, height, offset);
ImagePrimitives::drawCheckerboard(mBuffer->getPoolData(), width, height, offset);
mBuffer->tearDownPool(shm_pool_size);
return mBuffer->getWorkingBuffer();
}
void WaylandSurface::drawCheckerboard(int width, int height, int offset)
{
uint32_t *pixels = (uint32_t *)&(mBuffer->getPoolData())[offset];
for (int y = 100; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if ((x + y / 8 * 8) % 16 < 8)
{
pixels[y * width + x] = 0xFF666666;
}
else
{
pixels[y * width + x] = 0xFFEEEEEE;
}
}
}
}

View file

@ -7,6 +7,8 @@
#include "SharedMemory.h"
#include "WaylandBuffer.h"
#include "IPlatformWindow.h"
struct wl_surface;
struct xdg_surface;
struct xdg_toplevel;
@ -14,7 +16,7 @@ struct xdg_toplevel;
class WaylandEglInterface;
class WaylandEglWindowInterface;
class WaylandSurface
class WaylandSurface : public IPlatformWindow
{
public:
@ -28,9 +30,24 @@ public:
wl_buffer* drawFrame();
void drawCheckerboard(int width, int height, int offset);
void show() const
{
map();
}
void map() const
{
}
void clear() const
{
}
private:
void paint(mt::Screen* screen) override;
mt::Window* mWindow{nullptr};
wl_surface* mSurface{nullptr};

View file

@ -9,8 +9,8 @@
#include <xcb/xcb.h>
XcbWindow::XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection)
: mHandle(hwnd),
mWindow(window),
: IPlatformWindow(window),
mHandle(hwnd),
mBackingImage(std::make_unique<XcbImage>()),
mConnection(connection)
{
@ -58,7 +58,7 @@ void XcbWindow::show() const
map();
}
void XcbWindow::paint(mt::Screen* screen) const
void XcbWindow::paint(mt::Screen* screen)
{
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
for(const auto& layer : mWindow->GetLayers())

View file

@ -23,17 +23,15 @@ public:
void show() const override;
void paint(mt::Screen* screen) const override;
void paint(mt::Screen* screen) override;
void clear() const override;
void map() const override;
private:
int mHandle{-1};
unsigned mGraphicsContext {0};
mt::Window* mWindow{nullptr};
xcb_connection_t* mConnection{nullptr};
std::unique_ptr<XcbImage> mBackingImage;
};