summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/main.c b/main.c
index 5cc4299..f29f9aa 100644
--- a/main.c
+++ b/main.c
@@ -15,16 +15,16 @@
* along with Pui. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <stdlib.h>
-#include <string.h>
-
#include <err.h>
#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wayland-client.h>
+#include "font.h"
#include "pui.h"
#include "xdg-shell.h"
@@ -113,38 +113,39 @@ static const void* CreatePui(const char* filename) {
return result;
}
-static int CreateShm(int size) {
+static int CreateShm(size_t size) {
static const char kShmName[] = "/wl_shm-pui";
int fd = shm_open(kShmName, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd == -1) err(1, "Failed to create shm");
shm_unlink(kShmName);
- if (ftruncate(fd, size)) err(1, "Failed to truncate shm");
+ if (ftruncate(fd, (off_t)size)) err(1, "Failed to truncate shm");
return fd;
}
static void RenderPui(const void* pui, int fd) {
- int width = PuiGetWidth(pui);
- int height = PuiGetHeight(pui);
- size_t size = (size_t)width * (size_t)height * 4;
+ size_t width = PuiGetWidth(pui);
+ size_t height = PuiGetHeight(pui);
+ size_t size = width * height * 4;
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buffer == MAP_FAILED) err(1, "Failed to map shm");
PuiRender(pui, buffer, width, 0);
- for (int i = 0; i < width * height; i++) {
+ for (size_t i = 0; i < width * height; i++) {
uint32_t* ptr = (uint32_t*)buffer + i;
*ptr = (*ptr << 16 & 0xff0000) | (*ptr >> 16 & 0xff) | (*ptr & 0xff00);
}
+ PuiStringRender("This is just a test string", buffer, width, 0);
munmap(buffer, size);
}
static struct wl_buffer* PrepareBuffer(struct Context* ctx) {
- int width = PuiGetWidth(ctx->pui);
- int height = PuiGetHeight(ctx->pui);
- int stride = width * 4;
- int size = stride * height;
+ size_t width = PuiGetWidth(ctx->pui);
+ size_t height = PuiGetHeight(ctx->pui);
+ size_t stride = width * 4;
+ size_t size = stride * height;
int fd = CreateShm(size);
- struct wl_shm_pool* pool = wl_shm_create_pool(ctx->shm, fd, size);
+ struct wl_shm_pool* pool = wl_shm_create_pool(ctx->shm, fd, (int)size);
struct wl_buffer* buffer = wl_shm_pool_create_buffer(
- pool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888);
+ pool, 0, (int)width, (int)height, (int)stride, WL_SHM_FORMAT_XRGB8888);
wl_shm_pool_destroy(pool);
RenderPui(ctx->pui, fd);
close(fd);