Merge pull request #10999 from akallabeth/uwac-implicit-fix

Uwac implicit fix
This commit is contained in:
akallabeth
2025-01-01 11:21:41 +01:00
committed by GitHub
7 changed files with 119 additions and 111 deletions

View File

@@ -19,6 +19,9 @@
#ifndef RDTK_H
#define RDTK_H
#include <winpr/assert.h>
#include <winpr/winpr.h>
#include <stdint.h>
#include <rdtk/api.h>
@@ -38,9 +41,11 @@ extern "C"
/* Engine */
RDTK_EXPORT rdtkEngine* rdtk_engine_new(void);
RDTK_EXPORT void rdtk_engine_free(rdtkEngine* engine);
WINPR_ATTR_MALLOC(rdtk_engine_free, 1)
RDTK_EXPORT rdtkEngine* rdtk_engine_new(void);
/* Surface */
RDTK_EXPORT int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width,

View File

@@ -17,6 +17,7 @@
*/
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <rdtk/config.h>
@@ -27,12 +28,8 @@
int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
uint16_t nHeight, rdtkButton* button, const char* text)
{
uint16_t offsetX = 0;
uint16_t offsetY = 0;
uint16_t textWidth = 0;
uint16_t textHeight = 0;
uint16_t fillWidth = 0;
uint16_t fillHeight = 0;
WINPR_ASSERT(surface);
WINPR_ASSERT(button);
@@ -48,21 +45,35 @@ int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint1
if ((textWidth > 0) && (textHeight > 0))
{
fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
const int wd = (ninePatch->width - ninePatch->fillWidth);
const int hd = (ninePatch->height - ninePatch->fillHeight);
offsetX = ninePatch->fillLeft;
offsetY = ninePatch->fillTop;
const uint16_t fillWidth = nWidth - WINPR_ASSERTING_INT_CAST(uint16_t, wd);
const uint16_t fillHeight = nHeight - WINPR_ASSERTING_INT_CAST(uint16_t, hd);
uint16_t offsetX = WINPR_ASSERTING_INT_CAST(UINT16, ninePatch->fillLeft);
uint16_t offsetY = WINPR_ASSERTING_INT_CAST(UINT16, ninePatch->fillTop);
if (textWidth < fillWidth)
offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
{
const int twd = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
}
else if (textWidth < ninePatch->width)
offsetX = ((ninePatch->width - textWidth) / 2);
{
const int twd = ((ninePatch->width - textWidth) / 2);
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
}
if (textHeight < fillHeight)
offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
{
const int twd = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
}
else if (textHeight < ninePatch->height)
offsetY = ((ninePatch->height - textHeight) / 2);
{
const int twd = ((ninePatch->height - textHeight) / 2);
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, twd);
}
rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
}

View File

@@ -24,6 +24,7 @@
#include <winpr/wtypes.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <winpr/path.h>
#include <winpr/file.h>
#include <winpr/print.h>
@@ -40,8 +41,8 @@
#define FILE_EXT "bmp"
#endif
static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font,
rdtkGlyph* glyph)
static int rdtk_font_draw_glyph(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
rdtkFont* font, rdtkGlyph* glyph)
{
WINPR_ASSERT(surface);
WINPR_ASSERT(font);
@@ -49,21 +50,21 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
nXDst += glyph->offsetX;
nYDst += glyph->offsetY;
const int nXSrc = glyph->rectX;
const int nYSrc = glyph->rectY;
const int nWidth = glyph->rectWidth;
const int nHeight = glyph->rectHeight;
const size_t nXSrc = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectX);
const size_t nYSrc = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectY);
const size_t nWidth = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectWidth);
const size_t nHeight = WINPR_ASSERTING_INT_CAST(size_t, glyph->rectHeight);
const uint32_t nSrcStep = font->image->scanline;
const uint8_t* pSrcData = font->image->data;
uint8_t* pDstData = surface->data;
const uint32_t nDstStep = surface->scanline;
for (int y = 0; y < nHeight; y++)
for (size_t y = 0; y < nHeight; y++)
{
const uint8_t* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)];
uint8_t* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)];
const uint8_t* pSrcPixel = &pSrcData[((1ULL * nYSrc + y) * nSrcStep) + (4ULL * nXSrc)];
uint8_t* pDstPixel = &pDstData[((1ULL * nYDst + y) * nDstStep) + (4ULL * nXDst)];
for (int x = 0; x < nWidth; x++)
for (size_t x = 0; x < nWidth; x++)
{
uint8_t B = pSrcPixel[0];
uint8_t G = pSrcPixel[1];
@@ -133,7 +134,7 @@ int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height,
const size_t length = strlen(text);
for (size_t index = 0; index < length; index++)
{
const size_t glyphIndex = text[index] - 32;
const size_t glyphIndex = WINPR_ASSERTING_INT_CAST(size_t, text[index] - 32);
if (glyphIndex < font->glyphCount)
{
@@ -216,7 +217,7 @@ static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, uint8_t* u
{
if ((str[0] > 31) && (str[0] < 127))
{
utf8[0] = str[0];
utf8[0] = WINPR_ASSERTING_INT_CAST(uint8_t, str[0] & 0xFF);
}
}
else
@@ -330,12 +331,12 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, char* buffer, size_
*q = '\0';
errno = 0;
{
long val = strtol(p, NULL, 0);
const unsigned long val = strtoul(p, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
if ((errno != 0) || (val > UINT16_MAX))
goto fail;
font->height = val;
font->height = (uint16_t)val;
}
*q = '"';

View File

@@ -17,6 +17,7 @@
*/
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <rdtk/config.h>
@@ -27,24 +28,17 @@
int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
uint16_t nHeight, rdtkTextField* textField, const char* text)
{
uint16_t offsetX = 0;
uint16_t offsetY = 0;
uint16_t textWidth = 0;
uint16_t textHeight = 0;
uint16_t fillWidth = 0;
uint16_t fillHeight = 0;
rdtkFont* font = NULL;
rdtkEngine* engine = NULL;
rdtkNinePatch* ninePatch = NULL;
WINPR_ASSERT(surface);
WINPR_ASSERT(textField);
WINPR_ASSERT(text);
engine = surface->engine;
font = engine->font;
rdtkEngine* engine = surface->engine;
rdtkFont* font = engine->font;
textField = surface->engine->textField;
ninePatch = textField->ninePatch;
rdtkNinePatch* ninePatch = textField->ninePatch;
rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
@@ -52,21 +46,35 @@ int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, u
if ((textWidth > 0) && (textHeight > 0))
{
fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
const int fwd = (ninePatch->width - ninePatch->fillWidth);
const int fhd = (ninePatch->height - ninePatch->fillHeight);
offsetX = ninePatch->fillLeft;
offsetY = ninePatch->fillTop;
uint16_t fillWidth = nWidth - WINPR_ASSERTING_INT_CAST(uint16_t, fwd);
uint16_t fillHeight = nHeight - WINPR_ASSERTING_INT_CAST(uint16_t, fhd);
uint16_t offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, ninePatch->fillLeft);
uint16_t offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, ninePatch->fillTop);
if (textWidth < fillWidth)
offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
{
const int wd = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
}
else if (textWidth < ninePatch->width)
offsetX = ((ninePatch->width - textWidth) / 2);
{
const int wd = ((ninePatch->width - textWidth) / 2);
offsetX = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
}
if (textHeight < fillHeight)
offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
{
const int wd = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
}
else if (textHeight < ninePatch->height)
offsetY = ((ninePatch->height - textHeight) / 2);
{
const int wd = ((ninePatch->height - textHeight) / 2);
offsetY = WINPR_ASSERTING_INT_CAST(uint16_t, wd);
}
rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
}

View File

@@ -21,6 +21,8 @@
#include <stdint.h>
#include <winpr/wlog.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <rdtk/rdtk.h>
#include <X11/Xlib.h>
@@ -31,36 +33,17 @@
int main(int argc, char** argv)
{
int rc = 1;
GC gc = NULL;
int depth = 0;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
uint8_t* buffer = NULL;
int scanline = 0;
int pf_count = 0;
XEvent event;
XImage* image = NULL;
Pixmap pixmap = 0;
Screen* screen = NULL;
Visual* visual = NULL;
int scanline_pad = 0;
int screen_number = 0;
Display* display = NULL;
Window window = 0;
Window root_window = 0;
rdtkEngine* engine = NULL;
rdtkSurface* surface = NULL;
unsigned long border = 0;
unsigned long background = 0;
XPixmapFormatValues* pf = NULL;
XPixmapFormatValues* pfs = NULL;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
display = XOpenDisplay(NULL);
Display* display = XOpenDisplay(NULL);
if (!display)
{
@@ -68,27 +51,27 @@ int main(int argc, char** argv)
return 1;
}
x = 10;
y = 10;
width = 640;
height = 480;
const INT32 x = 10;
const INT32 y = 10;
const UINT32 width = 640;
const UINT32 height = 480;
screen_number = DefaultScreen(display);
screen = ScreenOfDisplay(display, screen_number);
visual = DefaultVisual(display, screen_number);
gc = DefaultGC(display, screen_number);
depth = DefaultDepthOfScreen(screen);
root_window = RootWindow(display, screen_number);
border = BlackPixel(display, screen_number);
background = WhitePixel(display, screen_number);
const int screen_number = DefaultScreen(display);
const Screen* screen = ScreenOfDisplay(display, screen_number);
Visual* visual = DefaultVisual(display, screen_number);
const GC gc = DefaultGC(display, screen_number);
const int depth = DefaultDepthOfScreen(screen);
const Window root_window = RootWindow(display, screen_number);
const unsigned long border = BlackPixel(display, screen_number);
const unsigned long background = WhitePixel(display, screen_number);
scanline_pad = 0;
int scanline_pad = 0;
pfs = XListPixmapFormats(display, &pf_count);
XPixmapFormatValues* pfs = XListPixmapFormats(display, &pf_count);
for (int index = 0; index < pf_count; index++)
{
pf = &pfs[index];
XPixmapFormatValues* pf = &pfs[index];
if (pf->depth == depth)
{
@@ -99,13 +82,10 @@ int main(int argc, char** argv)
XFree(pfs);
engine = rdtk_engine_new();
if (!engine)
goto fail;
scanline = width * 4;
buffer = (uint8_t*)calloc(height, scanline);
if (!buffer)
rdtkEngine* engine = rdtk_engine_new();
const size_t scanline = width * 4ULL;
uint8_t* buffer = (uint8_t*)calloc(height, scanline);
if (!engine || !buffer || (depth < 0))
goto fail;
surface = rdtk_surface_new(engine, buffer, width, height, scanline);
@@ -123,9 +103,9 @@ int main(int argc, char** argv)
XSetFunction(display, gc, GXcopy);
XSetFillStyle(display, gc, FillSolid);
pixmap = XCreatePixmap(display, window, width, height, depth);
pixmap = XCreatePixmap(display, window, width, height, (unsigned)depth);
image = XCreateImage(display, visual, depth, ZPixmap, 0, (char*)buffer, width, height,
image = XCreateImage(display, visual, (unsigned)depth, ZPixmap, 0, (char*)buffer, width, height,
scanline_pad, 0);
while (1)

View File

@@ -42,18 +42,16 @@
static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, size_t size)
{
struct wl_buffer* buffer = NULL;
int fd = 0;
void* data = NULL;
struct wl_shm_pool* pool = NULL;
assert(seat);
fd = uwac_create_anonymous_file(size);
const int fd = uwac_create_anonymous_file(WINPR_ASSERTING_INT_CAST(off_t, size));
if (fd < 0)
return buffer;
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
void* data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED)
{
@@ -69,9 +67,10 @@ static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src,
goto error_mmap;
}
buffer =
wl_shm_pool_create_buffer(pool, 0, seat->pointer_image->width, seat->pointer_image->height,
seat->pointer_image->width * 4, WL_SHM_FORMAT_ARGB8888);
buffer = wl_shm_pool_create_buffer(
pool, 0, WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->width),
WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->height),
WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->width * 4), WL_SHM_FORMAT_ARGB8888);
wl_shm_pool_destroy(pool);
if (munmap(data, size) < 0)
@@ -121,8 +120,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
return UWAC_ERROR_INTERNAL;
surface = seat->pointer_surface;
x = image->hotspot_x / scale;
y = image->hotspot_y / scale;
x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x / scale);
y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y / scale);
break;
case 1: /* NULL pointer */
break;
@@ -133,8 +132,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
image = cursor->images[0];
if (!image)
return UWAC_ERROR_INTERNAL;
x = image->hotspot_x;
y = image->hotspot_y;
x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x);
y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y);
buffer = wl_cursor_image_get_buffer(image);
if (!buffer)
return UWAC_ERROR_INTERNAL;
@@ -146,7 +145,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
{
wl_surface_set_buffer_scale(surface, scale);
wl_surface_attach(surface, buffer, 0, 0);
wl_surface_damage(surface, 0, 0, image->width, image->height);
wl_surface_damage(surface, 0, 0, WINPR_ASSERTING_INT_CAST(int32_t, image->width),
WINPR_ASSERTING_INT_CAST(int32_t, image->height));
wl_surface_commit(surface);
}

View File

@@ -34,6 +34,8 @@
#include <uwac/config.h>
#include <winpr/cast.h>
#define UWAC_INITIAL_BUFFERS 3ull
static int bppFromShmFormat(enum wl_shm_format format)
@@ -354,7 +356,7 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, uint64_t nbuffers, uint64_t allocSi
if (allocbuffersize > INT32_MAX)
return UWAC_ERROR_NOMEMORY;
fd = uwac_create_anonymous_file((off_t)allocbuffersize);
fd = uwac_create_anonymous_file(WINPR_ASSERTING_INT_CAST(off_t, allocbuffersize));
if (fd < 0)
{
@@ -424,7 +426,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index)
{
w->buffers[i].used = true;
if (index)
*index = i;
*index = WINPR_ASSERTING_INT_CAST(ssize_t, i);
return &w->buffers[i];
}
}
@@ -440,7 +442,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index)
w->buffers[i].used = true;
if (index)
*index = i;
*index = WINPR_ASSERTING_INT_CAST(ssize_t, i);
return &w->buffers[i];
}
@@ -482,7 +484,6 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h
enum wl_shm_format format)
{
UwacWindow* w = NULL;
int allocSize = 0;
int ret = 0;
if (!display)
@@ -500,10 +501,10 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h
w->display = display;
w->format = format;
w->width = width;
w->height = height;
w->stride = width * bppFromShmFormat(format);
allocSize = w->stride * height;
w->width = WINPR_ASSERTING_INT_CAST(int32_t, width);
w->height = WINPR_ASSERTING_INT_CAST(int32_t, height);
w->stride = WINPR_ASSERTING_INT_CAST(int32_t, width* bppFromShmFormat(format));
const size_t allocSize = 1ULL * w->stride * height;
ret = UwacWindowShmAllocBuffers(w, UWAC_INITIAL_BUFFERS, allocSize, width, height, format);
if (ret != UWAC_SUCCESS)
@@ -662,7 +663,9 @@ UwacReturnCode UwacWindowSetOpaqueRegion(UwacWindow* window, uint32_t x, uint32_
if (!window->opaque_region)
return UWAC_ERROR_NOMEMORY;
wl_region_add(window->opaque_region, x, y, width, height);
wl_region_add(window->opaque_region, WINPR_ASSERTING_INT_CAST(int32_t, x),
WINPR_ASSERTING_INT_CAST(int32_t, y), WINPR_ASSERTING_INT_CAST(int32_t, width),
WINPR_ASSERTING_INT_CAST(int32_t, height));
wl_surface_set_opaque_region(window->surface, window->opaque_region);
return UWAC_SUCCESS;
}