Changes in / [5713e5f:a4666a9] in mainline
- Files:
-
- 6 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r5713e5f ra4666a9 28 28 uspace/app/dnsres/dnsres 29 29 uspace/app/edit/edit 30 uspace/app/fontviewer/fontviewer31 30 uspace/app/getterm/getterm 32 31 uspace/app/inet/inet … … 80 79 uspace/dist/app/dnsres 81 80 uspace/dist/app/edit 82 uspace/dist/app/fontviewer83 81 uspace/dist/app/getterm 84 82 uspace/dist/app/inet -
boot/Makefile.common
r5713e5f ra4666a9 218 218 $(USPACE_PATH)/app/vdemo/vdemo \ 219 219 $(USPACE_PATH)/app/viewer/viewer \ 220 $(USPACE_PATH)/app/df/df \ 221 $(USPACE_PATH)/app/fontviewer/fontviewer 220 $(USPACE_PATH)/app/df/df 222 221 223 222 COMPONENTS = \ -
uspace/Makefile
r5713e5f ra4666a9 44 44 app/download \ 45 45 app/edit \ 46 app/fontviewer \47 46 app/getterm \ 48 47 app/hdisk \ -
uspace/lib/c/generic/io/asprintf.c
r5713e5f ra4666a9 76 76 * the newly allocated string. 77 77 * @fmt Format string. 78 * @args Variable argument list79 *80 * @return Number of characters printed or a negative error code.81 *82 */83 int vasprintf(char **strp, const char *fmt, va_list args)84 {85 va_list args2;86 va_copy(args2, args);87 int ret = vprintf_size(fmt, args2);88 va_end(args2);89 90 if (ret > 0) {91 *strp = malloc(STR_BOUNDS(ret) + 1);92 if (*strp == NULL)93 return -1;94 95 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);96 }97 98 return ret;99 }100 101 /** Allocate and print to string.102 *103 * @param strp Address of the pointer where to store the address of104 * the newly allocated string.105 * @fmt Format string.106 78 * 107 79 * @return Number of characters printed or a negative error code. … … 112 84 va_list args; 113 85 va_start(args, fmt); 114 int ret = v asprintf(strp,fmt, args);86 int ret = vprintf_size(fmt, args); 115 87 va_end(args); 88 89 if (ret > 0) { 90 *strp = malloc(STR_BOUNDS(ret) + 1); 91 if (*strp == NULL) 92 return -1; 93 94 va_start(args, fmt); 95 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args); 96 va_end(args); 97 } 116 98 117 99 return ret; -
uspace/lib/c/include/io/pixelmap.h
r5713e5f ra4666a9 1 1 /* 2 2 * Copyright (c) 2011 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 41 40 #include <unistd.h> 42 41 #include <io/pixel.h> 43 44 /* Defines how a pixel outside of pixmap rectangle shall be treated */45 typedef enum {46 /* Pixels outside of a pixmap are PIXEL(0, 0, 0, 0) */47 PIXELMAP_EXTEND_TRANSPARENT_BLACK = 0,48 49 /* The pixmap is repeated infinetely */50 PIXELMAP_EXTEND_TILE,51 52 /* If outside of a pixmap, return closest pixel from the edge */53 PIXELMAP_EXTEND_SIDES,54 55 /* If outside of a pixmap, return closest pixel from the edge,56 * with alpha = 057 */58 PIXELMAP_EXTEND_TRANSPARENT_SIDES59 } pixelmap_extend_t;60 42 61 43 typedef struct { … … 104 86 } 105 87 106 static inline pixel_t pixelmap_get_extended_pixel(pixelmap_t *pixmap,107 native_t x, native_t y, pixelmap_extend_t extend)108 {109 bool transparent = false;110 if (extend == PIXELMAP_EXTEND_TILE) {111 x %= pixmap->width;112 y %= pixmap->height;113 }114 else if (extend == PIXELMAP_EXTEND_SIDES ||115 extend == PIXELMAP_EXTEND_TRANSPARENT_SIDES) {116 bool transparent_outside =117 (extend == PIXELMAP_EXTEND_TRANSPARENT_SIDES);118 if (x < 0) {119 x = 0;120 transparent = transparent_outside;121 }122 else if (((sysarg_t) x) >= pixmap->width) {123 x = pixmap->width - 1;124 transparent = transparent_outside;125 }126 127 if (y < 0) {128 y = 0;129 transparent = transparent_outside;130 }131 else if (((sysarg_t) y) >= pixmap->height) {132 y = pixmap->height - 1;133 transparent = transparent_outside;134 }135 }136 137 if (x < 0 || ((sysarg_t) x) >= pixmap->width ||138 y < 0 || ((sysarg_t) y) >= pixmap->height)139 return PIXEL(0, 0, 0, 0);140 141 pixel_t pixel = pixelmap_get_pixel(pixmap, x, y);142 143 if (transparent)144 pixel = PIXEL(0, RED(pixel), GREEN(pixel), BLUE(pixel));145 146 return pixel;147 }148 149 150 88 #endif 151 89 -
uspace/lib/c/include/stdio.h
r5713e5f ra4666a9 120 120 extern int snprintf(char *, size_t , const char *, ...) 121 121 PRINTF_ATTRIBUTE(3, 4); 122 extern int vasprintf(char **, const char *, va_list);123 122 extern int asprintf(char **, const char *, ...) 124 123 PRINTF_ATTRIBUTE(2, 3); -
uspace/lib/draw/Makefile
r5713e5f ra4666a9 37 37 cursor/embedded.c \ 38 38 font/embedded.c \ 39 font/bitmap_backend.c \40 font/pcf.c \41 39 gfx/font-8x16.c \ 42 40 gfx/cursor-11x18.c \ -
uspace/lib/draw/font.c
r5713e5f ra4666a9 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 35 34 */ 36 35 36 #include <assert.h> 37 37 #include <malloc.h> 38 #include <errno.h>39 #include <str.h>40 38 41 39 #include "font.h" … … 43 41 #include "drawctx.h" 44 42 45 font_t *font_create(font_backend_t *backend, void *backend_data)43 void font_init(font_t *font, font_decoder_type_t decoder, char *path, uint16_t points) 46 44 { 47 font_t *font = malloc(sizeof(font_t)); 48 if (font == NULL) 49 return NULL; 50 51 font->backend = backend; 52 font->backend_data = backend_data; 53 54 return font; 45 font->points = points; 46 47 switch (decoder) { 48 case FONT_DECODER_EMBEDDED: 49 font->decoder = &fd_embedded; 50 break; 51 default: 52 font->decoder = NULL; 53 break; 54 } 55 56 if (font->decoder) { 57 font->decoder->init(path, &font->glyph_count, &font->decoder_data); 58 59 if (font->glyph_count > 0) { 60 font->glyphs = (surface_t **) malloc(sizeof(surface_t *) * font->glyph_count); 61 } else { 62 font->glyphs = NULL; 63 } 64 65 if (font->glyphs) { 66 for (size_t i = 0; i < font->glyph_count; ++i) { 67 font->glyphs[i] = NULL; 68 } 69 } else { 70 font->glyph_count = 0; 71 } 72 } else { 73 font->glyph_count = 0; 74 font->glyphs = NULL; 75 font->decoder_data = NULL; 76 } 55 77 } 56 78 57 79 void font_release(font_t *font) 58 80 { 59 font->backend->release(font->backend_data); 81 if (font->glyphs) { 82 for (size_t i = 0; i < font->glyph_count; ++i) { 83 if (font->glyphs[i]) { 84 surface_destroy(font->glyphs[i]); 85 } 86 } 87 free(font->glyphs); 88 } 89 90 if (font->decoder) { 91 font->decoder->release(font->decoder_data); 92 } 60 93 } 61 94 62 int font_get_metrics(font_t *font, font_metrics_t *metrics) { 63 return font->backend->get_font_metrics(font->backend_data, metrics); 95 void font_get_box(font_t *font, char *text, sysarg_t *width, sysarg_t *height) 96 { 97 assert(width); 98 assert(height); 99 100 (*width) = 0; 101 (*height) = 0; 102 103 if (!text) { 104 return; 105 } 106 107 while (*text) { 108 uint16_t glyph_idx = font->decoder->resolve(*text, font->decoder_data); 109 if (glyph_idx < font->glyph_count) { 110 if (!font->glyphs[glyph_idx]) { 111 font->glyphs[glyph_idx] = 112 font->decoder->render(glyph_idx, font->points); 113 } 114 115 surface_t *glyph = font->glyphs[glyph_idx]; 116 if (glyph) { 117 sysarg_t w; 118 sysarg_t h; 119 surface_get_resolution(glyph, &w, &h); 120 (*width) += w; 121 (*height) = (*height) < h ? h : (*height); 122 } 123 } 124 ++text; 125 } 64 126 } 65 127 66 int font_resolve_glyph(font_t *font, wchar_t c, glyph_id_t *glyph_id) { 67 return font->backend->resolve_glyph(font->backend_data, c, glyph_id); 68 } 128 void font_draw_text(font_t *font, drawctx_t *context, source_t *source, 129 const char *text, sysarg_t x, sysarg_t y) 130 { 131 assert(context); 132 assert(source); 69 133 70 int font_get_glyph_metrics(font_t *font, glyph_id_t glyph_id,71 glyph_metrics_t *glyph_metrics)72 {73 return font->backend->get_glyph_metrics(font->backend_data,74 glyph_id, glyph_metrics);75 }76 77 int font_render_glyph(font_t *font, drawctx_t *context, source_t *source,78 sysarg_t x, sysarg_t y, glyph_id_t glyph_id)79 {80 return font->backend->render_glyph(font->backend_data, context, source,81 x, y, glyph_id);82 }83 84 /* TODO this is bad interface */85 int font_get_box(font_t *font, char *text, sysarg_t *width, sysarg_t *height)86 {87 font_metrics_t fm;88 int rc = font_get_metrics(font, &fm);89 if (rc != EOK)90 return rc;91 92 native_t x = 0;93 94 size_t off = 0;95 while (true) {96 wchar_t c = str_decode(text, &off, STR_NO_LIMIT);97 if (c == 0)98 break;99 100 glyph_id_t glyph_id;101 rc = font_resolve_glyph(font, c, &glyph_id);102 if (rc != EOK) {103 int rc2 = font_resolve_glyph(font, U_SPECIAL, &glyph_id);104 if (rc2 != EOK) {105 return rc;106 }107 }108 109 glyph_metrics_t glyph_metrics;110 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics);111 if (rc != EOK)112 return rc;113 114 x += glyph_metrics_get_advancement(&glyph_metrics);115 }116 117 *width = x;118 *height = fm.ascender + fm.descender;119 return EOK;120 }121 122 /* TODO this is bad interface */123 int font_draw_text(font_t *font, drawctx_t *context, source_t *source,124 const char *text, sysarg_t sx, sysarg_t sy)125 {126 134 drawctx_save(context); 127 135 drawctx_set_compose(context, compose_over); 128 136 129 font_metrics_t fm; 130 int rc = font_get_metrics(font, &fm); 131 if (rc != EOK) 132 return rc; 137 while (*text) { 138 uint16_t glyph_idx = font->decoder->resolve(*text, font->decoder_data); 139 if (glyph_idx < font->glyph_count) { 140 if (!font->glyphs[glyph_idx]) { 141 font->glyphs[glyph_idx] = 142 font->decoder->render(glyph_idx, font->points); 143 } 133 144 134 native_t baseline = sy + fm.ascender; 135 native_t x = sx; 145 surface_t *glyph = font->glyphs[glyph_idx]; 146 if (glyph) { 147 sysarg_t w; 148 sysarg_t h; 149 surface_get_resolution(glyph, &w, &h); 136 150 137 size_t off = 0; 138 while (true) { 139 wchar_t c = str_decode(text, &off, STR_NO_LIMIT); 140 if (c == 0) 141 break; 142 143 glyph_id_t glyph_id; 144 rc = font_resolve_glyph(font, c, &glyph_id); 145 if (rc != EOK) { 146 int rc2 = font_resolve_glyph(font, U_SPECIAL, &glyph_id); 147 if (rc2 != EOK) { 148 return rc; 151 transform_t transform; 152 transform_identity(&transform); 153 transform_translate(&transform, x, y); 154 source_set_transform(source, transform); 155 source_set_mask(source, glyph, false); 156 drawctx_transfer(context, x, y, w, h); 157 158 x += w; 149 159 } 150 160 } 151 152 glyph_metrics_t glyph_metrics; 153 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics); 154 if (rc != EOK) 155 return rc; 156 157 rc = font_render_glyph(font, context, source, x, baseline, 158 glyph_id); 159 if (rc != EOK) 160 return rc; 161 162 x += glyph_metrics_get_advancement(&glyph_metrics); 163 161 ++text; 164 162 } 165 163 166 164 drawctx_restore(context); 167 165 source_set_mask(source, NULL, false); 168 169 return EOK;170 166 } 171 167 -
uspace/lib/draw/font.h
r5713e5f ra4666a9 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 46 45 typedef struct drawctx drawctx_t; 47 46 48 typedef int metric_t; 47 typedef enum { 48 FONT_DECODER_EMBEDDED 49 } font_decoder_type_t; 49 50 50 51 typedef struct { 51 /* Horizontal distance between origin and left side of the glyph */ 52 metric_t left_side_bearing; 53 54 /* Width of the actual glyph drawn */ 55 metric_t width; 56 57 /* Horizontal distance between right side of the glyph and origin 58 of the next glyph */ 59 metric_t right_side_bearing; 60 61 /* Vertical distance between baseline and top of the glyph 62 (positive to top) */ 63 metric_t ascender; 64 65 /* Height of the actual glyph drawn */ 66 metric_t height; 67 } glyph_metrics_t; 52 void (*init)(char *, uint16_t *, void **); 53 uint16_t (*resolve)(const wchar_t, void *); 54 surface_t *(*render)(uint16_t, uint16_t); 55 void (*release)(void *); 56 } font_decoder_t; 68 57 69 static inline metric_t glyph_metrics_get_descender(glyph_metrics_t *gm) 70 { 71 return gm->height - gm->ascender; 72 } 73 74 static inline metric_t glyph_metrics_get_advancement(glyph_metrics_t *gm) 75 { 76 return gm->left_side_bearing + gm->width + gm->right_side_bearing; 77 } 78 79 typedef struct { 80 /* Distance between top of the line and baseline */ 81 metric_t ascender; 82 83 /* Distance between baseline and bottom of the line */ 84 metric_t descender; 85 86 /* Distance between bottom of the line and top of the next line */ 87 metric_t leading; 88 } font_metrics_t; 89 90 typedef uint32_t glyph_id_t; 91 92 typedef struct { 93 int (*get_font_metrics)(void *, font_metrics_t *); 94 int (*resolve_glyph)(void *, wchar_t, glyph_id_t *); 95 int (*get_glyph_metrics)(void *, glyph_id_t, glyph_metrics_t *); 96 int (*render_glyph)(void *, drawctx_t *, source_t *, sysarg_t, 97 sysarg_t, glyph_id_t); 98 void (*release)(void *); 99 } font_backend_t; 100 101 typedef struct { 102 font_backend_t *backend; 103 void *backend_data; 58 typedef struct font { 59 uint16_t points; 60 uint16_t glyph_count; 61 surface_t **glyphs; 62 font_decoder_t *decoder; 63 void *decoder_data; 104 64 } font_t; 105 65 106 extern font_t *font_create(font_backend_t *, void *); 107 extern int font_get_metrics(font_t *, font_metrics_t *); 108 extern int font_resolve_glyph(font_t *, wchar_t, glyph_id_t *); 109 extern int font_get_glyph_metrics(font_t *, glyph_id_t, glyph_metrics_t *); 110 extern int font_render_glyph(font_t *, drawctx_t *, source_t *, 111 sysarg_t, sysarg_t, glyph_id_t); 66 extern void font_init(font_t *, font_decoder_type_t, char *, uint16_t); 112 67 extern void font_release(font_t *); 113 68 114 extern intfont_get_box(font_t *, char *, sysarg_t *, sysarg_t *);115 extern intfont_draw_text(font_t *, drawctx_t *, source_t *, const char *,69 extern void font_get_box(font_t *, char *, sysarg_t *, sysarg_t *); 70 extern void font_draw_text(font_t *, drawctx_t *, source_t *, const char *, 116 71 sysarg_t, sysarg_t); 117 72 -
uspace/lib/draw/font/embedded.c
r5713e5f ra4666a9 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 35 34 */ 36 35 36 #include <assert.h> 37 37 #include <sys/types.h> 38 38 #include <malloc.h> 39 #include <errno.h>40 39 41 40 #include "../gfx/font-8x16.h" 42 41 #include "embedded.h" 43 42 #include "../drawctx.h" 44 #include "bitmap_backend.h"45 43 46 static int fde_resolve_glyph(void *unused, const wchar_t chr, 47 glyph_id_t *glyph_id) 44 static void fde_init(char *path, uint16_t *glyph_count, void **data) 48 45 { 49 bool found = false; 50 uint16_t glyph = fb_font_glyph(chr, &found); 51 if (!found) 52 return ENOENT; 53 54 *glyph_id = glyph; 55 return EOK; 46 assert(glyph_count); 47 assert(data); 48 49 (*glyph_count) = FONT_GLYPHS; 50 (*data) = NULL; 56 51 } 57 52 58 static int fde_load_glyph_surface(void *unused, glyph_id_t glyph_id, 59 surface_t **out_surface) 53 static uint16_t fde_resolve(const wchar_t chr, void *data) 60 54 { 61 surface_t *surface = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0); 62 if (!surface) 63 return ENOMEM; 64 55 return fb_font_glyph(chr); 56 } 57 58 static surface_t *fde_render(uint16_t glyph, uint16_t points) 59 { 60 surface_t *template = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0); 61 if (!template) { 62 return NULL; 63 } 65 64 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) { 66 65 for (unsigned int x = 0; x < FONT_WIDTH; ++x) { 67 pixel_t p = (fb_font[glyph _id][y] & (1 << (7 - x))) ?66 pixel_t p = (fb_font[glyph][y] & (1 << (7 - x))) ? 68 67 PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0); 69 surface_put_pixel( surface, x, y, p);68 surface_put_pixel(template, x, y, p); 70 69 } 71 70 } 72 73 *out_surface = surface;74 return EOK;75 }76 71 77 static int fde_load_glyph_metrics(void *unused, glyph_id_t glyph_id, 78 glyph_metrics_t *gm) 79 { 80 /* This is simple monospaced font, so fill this data statically */ 81 gm->left_side_bearing = 0; 82 gm->width = FONT_WIDTH; 83 gm->right_side_bearing = 0; 84 gm->ascender = FONT_ASCENDER; 85 gm->height = FONT_SCANLINES; 86 87 return EOK; 72 source_t source; 73 source_init(&source); 74 source_set_texture(&source, template, false); 75 76 transform_t transform; 77 transform_identity(&transform); 78 if (points != FONT_SCANLINES) { 79 double ratio = ((double) points) / ((double) FONT_SCANLINES); 80 transform_scale(&transform, ratio, ratio); 81 source_set_transform(&source, transform); 82 } 83 84 double width = FONT_WIDTH; 85 double height = FONT_SCANLINES; 86 transform_apply_linear(&transform, &width, &height); 87 surface_t *result = 88 surface_create((sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5), NULL, 0); 89 if (!result) { 90 surface_destroy(template); 91 return NULL; 92 } 93 94 drawctx_t context; 95 drawctx_init(&context, result); 96 drawctx_set_source(&context, &source); 97 drawctx_transfer(&context, 0, 0, 98 (sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5)); 99 100 surface_destroy(template); 101 102 return result; 88 103 } 89 104 … … 93 108 } 94 109 95 bitmap_font_decoder_t fd_embedded = {96 . resolve_glyph = fde_resolve_glyph,97 . load_glyph_surface = fde_load_glyph_surface,98 . load_glyph_metrics = fde_load_glyph_metrics,110 font_decoder_t fd_embedded = { 111 .init = fde_init, 112 .resolve = fde_resolve, 113 .render = fde_render, 99 114 .release = fde_release 100 115 }; 101 116 102 font_metrics_t font_metrics = {103 .ascender = FONT_ASCENDER,104 .descender = (FONT_SCANLINES - FONT_ASCENDER),105 .leading = 0106 };107 108 int embedded_font_create(font_t **font, uint16_t points)109 {110 return bitmap_font_create(&fd_embedded, NULL, FONT_GLYPHS, font_metrics,111 points, font);112 }113 114 117 /** @} 115 118 */ -
uspace/lib/draw/font/embedded.h
r5713e5f ra4666a9 39 39 #include "../font.h" 40 40 41 extern int embedded_font_create(font_t **, uint16_t points);41 extern font_decoder_t fd_embedded; 42 42 43 43 #endif -
uspace/lib/draw/gfx/font-8x16.c
r5713e5f ra4666a9 44 44 * mark glyph if no specific glyph exists. 45 45 * 46 * If found is not null, indicate whether the glyph was found or not.47 *48 46 */ 49 uint16_t fb_font_glyph(const wchar_t ch , bool *found)47 uint16_t fb_font_glyph(const wchar_t ch) 50 48 { 51 if (found)52 *found = true;53 54 49 if (ch == 0x0000) 55 50 return 0; … … 366 361 if (ch == 0xfeff) 367 362 return 2896; 368 369 if (found)370 *found = false;371 363 372 364 return 2898; -
uspace/lib/draw/gfx/font-8x16.h
r5713e5f ra4666a9 37 37 38 38 #include <sys/types.h> 39 #include <stdbool.h>40 39 41 40 #define FONT_GLYPHS 2899 42 41 #define FONT_WIDTH 8 43 42 #define FONT_SCANLINES 16 44 #define FONT_ASCENDER 1245 43 46 extern uint16_t fb_font_glyph(const wchar_t , bool *);44 extern uint16_t fb_font_glyph(const wchar_t); 47 45 extern uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES]; 48 46 -
uspace/lib/draw/source.c
r5713e5f ra4666a9 45 45 source->color = PIXEL(0, 0, 0, 0); 46 46 source->texture = NULL; 47 source->texture_ extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;47 source->texture_tile = false; 48 48 49 49 source->alpha = PIXEL(255, 0, 0, 0); 50 50 source->mask = NULL; 51 source->mask_ extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;51 source->mask_tile = false; 52 52 } 53 53 … … 73 73 } 74 74 75 void source_set_texture(source_t *source, surface_t *texture, 76 pixelmap_extend_t extend) 75 void source_set_texture(source_t *source, surface_t *texture, bool tile) 77 76 { 78 77 source->texture = texture; 79 source->texture_ extend = extend;78 source->texture_tile = tile; 80 79 } 81 80 … … 85 84 } 86 85 87 void source_set_mask(source_t *source, surface_t *mask, 88 pixelmap_extend_t extend) 86 void source_set_mask(source_t *source, surface_t *mask, bool tile) 89 87 { 90 88 source->mask = mask; 91 source->mask_ extend = extend;89 source->mask_tile = tile; 92 90 } 93 91 … … 97 95 (source->alpha == (pixel_t) PIXEL(255, 0, 0, 0)) && 98 96 (source->texture != NULL) && 99 (source->texture_ extend == PIXELMAP_EXTEND_TRANSPARENT_BLACK) &&97 (source->texture_tile == false) && 100 98 (transform_is_fast(&source->transform))); 101 99 } … … 122 120 mask_pix = source->filter( 123 121 surface_pixmap_access(source->mask), 124 x, y, source->mask_ extend);122 x, y, source->mask_tile); 125 123 } else { 126 124 mask_pix = source->alpha; … … 135 133 texture_pix = source->filter( 136 134 surface_pixmap_access(source->texture), 137 x, y, source->texture_ extend);135 x, y, source->texture_tile); 138 136 } else { 139 137 texture_pix = source->color; -
uspace/lib/draw/source.h
r5713e5f ra4666a9 42 42 #include <transform.h> 43 43 #include <filter.h> 44 #include <io/pixelmap.h>45 44 46 45 #include "surface.h" … … 52 51 pixel_t color; 53 52 surface_t *texture; 54 pixelmap_extend_t texture_extend;53 bool texture_tile; 55 54 56 55 pixel_t alpha; 57 56 surface_t *mask; 58 pixelmap_extend_t mask_extend;57 bool mask_tile; 59 58 } source_t; 60 59 … … 67 66 68 67 extern void source_set_color(source_t *, pixel_t); 69 extern void source_set_texture(source_t *, surface_t *, pixelmap_extend_t);68 extern void source_set_texture(source_t *, surface_t *, bool); 70 69 71 70 extern void source_set_alpha(source_t *, pixel_t); 72 extern void source_set_mask(source_t *, surface_t *, pixelmap_extend_t);71 extern void source_set_mask(source_t *, surface_t *, bool); 73 72 74 73 extern bool source_is_fast(source_t *); -
uspace/lib/gui/button.c
r5713e5f ra4666a9 38 38 #include <drawctx.h> 39 39 #include <surface.h> 40 #include <font/embedded.h>41 #include <errno.h>42 40 #include "common.h" 43 41 #include "window.h" … … 78 76 sysarg_t cpt_width; 79 77 sysarg_t cpt_height; 80 font_get_box( btn->font, btn->caption, &cpt_width, &cpt_height);78 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 81 79 82 80 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { … … 85 83 86 84 drawctx_set_source(&drawctx, &btn->text); 87 drawctx_set_font(&drawctx, btn->font);85 drawctx_set_font(&drawctx, &btn->font); 88 86 89 87 if (btn->caption) … … 98 96 widget_deinit(&btn->widget); 99 97 free(btn->caption); 100 font_release( btn->font);98 font_release(&btn->font); 101 99 } 102 100 … … 173 171 btn->caption = str_dup(caption); 174 172 175 int rc = embedded_font_create(&btn->font, points); 176 if (rc != EOK) { 177 free(btn->caption); 178 btn->caption = NULL; 179 return false; 180 } 173 font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points); 181 174 182 175 sysarg_t cpt_width; 183 176 sysarg_t cpt_height; 184 font_get_box( btn->font, btn->caption, &cpt_width, &cpt_height);177 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 185 178 btn->widget.width_min = cpt_width + 10; 186 179 btn->widget.height_min = cpt_height + 10; -
uspace/lib/gui/button.h
r5713e5f ra4666a9 52 52 source_t text; 53 53 char *caption; 54 font_t *font;54 font_t font; 55 55 signal_t clicked; 56 56 } button_t; -
uspace/lib/gui/canvas.c
r5713e5f ra4666a9 58 58 source_init(&source); 59 59 source_set_transform(&source, transform); 60 source_set_texture(&source, canvas->surface, 61 PIXELMAP_EXTEND_TRANSPARENT_BLACK); 60 source_set_texture(&source, canvas->surface, false); 62 61 63 62 drawctx_t drawctx; -
uspace/lib/gui/label.c
r5713e5f ra4666a9 38 38 #include <drawctx.h> 39 39 #include <surface.h> 40 #include <font/embedded.h>41 #include <errno.h>42 40 #include "window.h" 43 41 #include "label.h" … … 60 58 sysarg_t cpt_width; 61 59 sysarg_t cpt_height; 62 font_get_box( lbl->font, lbl->caption, &cpt_width, &cpt_height);60 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 63 61 64 62 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { … … 67 65 68 66 drawctx_set_source(&drawctx, &lbl->text); 69 drawctx_set_font(&drawctx, lbl->font);67 drawctx_set_font(&drawctx, &lbl->font); 70 68 71 69 if (lbl->caption) … … 86 84 sysarg_t cpt_width; 87 85 sysarg_t cpt_height; 88 font_get_box( lbl->font, lbl->caption, &cpt_width, &cpt_height);86 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 89 87 90 88 lbl->widget.width_min = cpt_width + 4; … … 101 99 widget_deinit(&lbl->widget); 102 100 free(lbl->caption); 103 font_release( lbl->font);101 font_release(&lbl->font); 104 102 } 105 103 … … 163 161 lbl->caption = str_dup(caption); 164 162 165 int rc = embedded_font_create(&lbl->font, points); 166 if (rc != EOK) { 167 free(lbl->caption); 168 lbl->caption = NULL; 169 return false; 170 } 163 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 171 164 172 165 sysarg_t cpt_width; 173 166 sysarg_t cpt_height; 174 font_get_box( lbl->font, lbl->caption, &cpt_width, &cpt_height);167 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 175 168 176 169 lbl->widget.width_min = cpt_width + 4; -
uspace/lib/gui/label.h
r5713e5f ra4666a9 51 51 source_t text; 52 52 char *caption; 53 font_t *font;53 font_t font; 54 54 slot_t rewrite; 55 55 } label_t; -
uspace/lib/gui/terminal.c
r5713e5f ra4666a9 186 186 // for full UTF-32 coverage. 187 187 188 uint16_t glyph = fb_font_glyph(field->ch , NULL);188 uint16_t glyph = fb_font_glyph(field->ch); 189 189 190 190 for (unsigned int y = 0; y < FONT_SCANLINES; y++) { -
uspace/lib/gui/window.c
r5713e5f ra4666a9 55 55 #include <drawctx.h> 56 56 #include <surface.h> 57 #include <font/embedded.h>58 57 59 58 #include "common.h" … … 161 160 /* Window caption */ 162 161 163 font_t *font; 164 int rc = embedded_font_create(&font, 16); 165 if (rc != EOK) { 166 window_yield(widget->window); 167 return; 168 } 169 170 drawctx_set_font(&drawctx, font); 162 font_t font; 163 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16); 164 165 drawctx_set_font(&drawctx, &font); 171 166 source_set_color(&source, widget->window->is_focused ? 172 167 color_caption_focus : color_caption_unfocus); … … 174 169 sysarg_t cpt_width; 175 170 sysarg_t cpt_height; 176 font_get_box( font, widget->window->caption, &cpt_width, &cpt_height);171 font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height); 177 172 178 173 bool draw_title = … … 188 183 } 189 184 190 font_release( font);185 font_release(&font); 191 186 window_yield(widget->window); 192 187 } -
uspace/lib/posix/include/posix/stdio.h
r5713e5f ra4666a9 107 107 extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4); 108 108 #ifdef _GNU_SOURCE 109 extern int vasprintf(char **, const char *, va_list);110 109 extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3); 111 110 #endif -
uspace/lib/softrend/filter.c
r5713e5f ra4666a9 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 36 35 37 36 #include "filter.h" 38 #include <io/pixel.h>39 37 38 pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y, bool tile) 39 { 40 long _x = x > 0 ? (long) (x + 0.5) : (long) (x - 0.5); 41 long _y = y > 0 ? (long) (y + 0.5) : (long) (y - 0.5); 40 42 41 static long round(double val) 42 { 43 return val > 0 ? (long) (val + 0.5) : (long) (val - 0.5); 43 if (tile) { 44 _x %= pixmap->width; 45 _y %= pixmap->height; 46 } 47 48 return pixelmap_get_pixel(pixmap, (sysarg_t) _x, (sysarg_t) _y); 44 49 } 45 50 46 static long floor(double val)51 pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y, bool tile) 47 52 { 48 long lval = (long) val; 49 if (val < 0 && lval != val) 50 return lval - 1; 51 return lval; 53 // TODO 54 return 0; 52 55 } 53 56 54 static long ceil(double val) 55 { 56 long lval = (long) val; 57 if (val > 0 && lval != val) 58 return lval + 1; 59 return lval; 60 } 61 62 63 static inline pixel_t blend_pixels(size_t count, float *weights, 64 pixel_t *pixels) 65 { 66 float alpha = 0, red = 0, green = 0, blue = 0; 67 for (size_t index = 0; index < count; index++) { 68 alpha += weights[index] * ALPHA(pixels[index]); 69 red += weights[index] * RED(pixels[index]); 70 green += weights[index] * GREEN(pixels[index]); 71 blue += weights[index] * BLUE(pixels[index]); 72 } 73 74 return PIXEL((uint8_t) alpha, (uint8_t) red, (uint8_t) green, 75 (uint8_t) blue); 76 } 77 78 pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y, 79 pixelmap_extend_t extend) 80 { 81 return pixelmap_get_extended_pixel(pixmap, round(x), round(y), extend); 82 } 83 84 pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y, 85 pixelmap_extend_t extend) 86 { 87 long x1 = floor(x); 88 long x2 = ceil(x); 89 long y1 = floor(y); 90 long y2 = ceil(y); 91 92 if (y1 == y2 && x1 == x2) { 93 return pixelmap_get_extended_pixel(pixmap, 94 (sysarg_t) x1, (sysarg_t) y1, extend); 95 } 96 97 double x_delta = x - x1; 98 double y_delta = y - y1; 99 100 pixel_t pixels[4]; 101 pixels[0] = pixelmap_get_extended_pixel(pixmap, x1, y1, extend); 102 pixels[1] = pixelmap_get_extended_pixel(pixmap, x2, y1, extend); 103 pixels[2] = pixelmap_get_extended_pixel(pixmap, x1, y2, extend); 104 pixels[3] = pixelmap_get_extended_pixel(pixmap, x2, y2, extend); 105 106 float weights[4]; 107 weights[0] = (1 - x_delta) * (1 - y_delta); 108 weights[1] = ( x_delta) * (1 - y_delta); 109 weights[2] = (1 - x_delta) * ( y_delta); 110 weights[3] = ( x_delta) * ( y_delta); 111 112 return blend_pixels(4, weights, pixels); 113 } 114 115 pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y, 116 pixelmap_extend_t extend) 57 pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y, bool tile) 117 58 { 118 59 // TODO -
uspace/lib/softrend/filter.h
r5713e5f ra4666a9 40 40 #include <io/pixelmap.h> 41 41 42 typedef pixel_t (*filter_t)(pixelmap_t *, double, double, pixelmap_extend_t);42 typedef pixel_t (*filter_t)(pixelmap_t *, double, double, bool); 43 43 44 extern pixel_t filter_nearest(pixelmap_t *, double, double, pixelmap_extend_t);45 extern pixel_t filter_bilinear(pixelmap_t *, double, double, pixelmap_extend_t);46 extern pixel_t filter_bicubic(pixelmap_t *, double, double, pixelmap_extend_t);44 extern pixel_t filter_nearest(pixelmap_t *, double, double, bool); 45 extern pixel_t filter_bilinear(pixelmap_t *, double, double, bool); 46 extern pixel_t filter_bicubic(pixelmap_t *, double, double, bool); 47 47 48 48 #endif -
uspace/srv/hid/compositor/compositor.c
r5713e5f ra4666a9 84 84 static sysarg_t coord_origin; 85 85 static pixel_t bg_color; 86 static filter_t filter = filter_bilinear;87 static unsigned int filter_index = 1;88 86 89 87 typedef struct { … … 410 408 411 409 source_init(&source); 412 source_set_filter(&source, filter );410 source_set_filter(&source, filter_nearest); 413 411 drawctx_init(&context, vp->surface); 414 412 drawctx_set_compose(&context, compose_over); … … 444 442 445 443 source_set_transform(&source, transform); 446 source_set_texture(&source, win->surface, 447 PIXELMAP_EXTEND_TRANSPARENT_SIDES); 444 source_set_texture(&source, win->surface, false); 448 445 source_set_alpha(&source, PIXEL(win->opacity, 0, 0, 0)); 449 446 … … 1821 1818 key == KC_O || key == KC_P); 1822 1819 bool kconsole_switch = (mods & KM_ALT) && (key == KC_M); 1823 bool filter_switch = (mods & KM_ALT) && (key == KC_Y); 1824 1825 bool key_filter = (type == KEY_RELEASE) && (win_transform || win_resize || 1820 1821 bool filter = (type == KEY_RELEASE) && (win_transform || win_resize || 1826 1822 win_opacity || win_close || win_switch || viewport_move || 1827 viewport_change || kconsole_switch || filter_switch);1828 1829 if ( key_filter) {1823 viewport_change || kconsole_switch); 1824 1825 if (filter) { 1830 1826 /* no-op */ 1831 1827 } else if (win_transform) { … … 2095 2091 if (console_kcon()) 2096 2092 active = false; 2097 } else if (filter_switch) {2098 filter_index++;2099 if (filter_index > 1)2100 filter_index = 0;2101 if (filter_index == 0) {2102 filter = filter_nearest;2103 }2104 else {2105 filter = filter_bilinear;2106 }2107 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);2108 2093 } else { 2109 2094 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
Note:
See TracChangeset
for help on using the changeset viewer.