Changeset 5713e5f in mainline
- Timestamp:
- 2014-09-01T19:17:55Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 21365c0
- Parents:
- a4666a9 (diff), 00ddb40 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 6 added
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
ra4666a9 r5713e5f 28 28 uspace/app/dnsres/dnsres 29 29 uspace/app/edit/edit 30 uspace/app/fontviewer/fontviewer 30 31 uspace/app/getterm/getterm 31 32 uspace/app/inet/inet … … 79 80 uspace/dist/app/dnsres 80 81 uspace/dist/app/edit 82 uspace/dist/app/fontviewer 81 83 uspace/dist/app/getterm 82 84 uspace/dist/app/inet -
boot/Makefile.common
ra4666a9 r5713e5f 218 218 $(USPACE_PATH)/app/vdemo/vdemo \ 219 219 $(USPACE_PATH)/app/viewer/viewer \ 220 $(USPACE_PATH)/app/df/df 220 $(USPACE_PATH)/app/df/df \ 221 $(USPACE_PATH)/app/fontviewer/fontviewer 221 222 222 223 COMPONENTS = \ -
uspace/Makefile
ra4666a9 r5713e5f 44 44 app/download \ 45 45 app/edit \ 46 app/fontviewer \ 46 47 app/getterm \ 47 48 app/hdisk \ -
uspace/lib/c/generic/io/asprintf.c
ra4666a9 r5713e5f 76 76 * the newly allocated string. 77 77 * @fmt Format string. 78 * @args Variable argument list 79 * 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 of 104 * the newly allocated string. 105 * @fmt Format string. 78 106 * 79 107 * @return Number of characters printed or a negative error code. … … 84 112 va_list args; 85 113 va_start(args, fmt); 86 int ret = v printf_size(fmt, args);114 int ret = vasprintf(strp, fmt, args); 87 115 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 }98 116 99 117 return ret; -
uspace/lib/c/include/io/pixelmap.h
ra4666a9 r5713e5f 1 1 /* 2 2 * Copyright (c) 2011 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 40 41 #include <unistd.h> 41 42 #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 = 0 57 */ 58 PIXELMAP_EXTEND_TRANSPARENT_SIDES 59 } pixelmap_extend_t; 42 60 43 61 typedef struct { … … 86 104 } 87 105 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 88 150 #endif 89 151 -
uspace/lib/c/include/stdio.h
ra4666a9 r5713e5f 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); 122 123 extern int asprintf(char **, const char *, ...) 123 124 PRINTF_ATTRIBUTE(2, 3); -
uspace/lib/draw/Makefile
ra4666a9 r5713e5f 37 37 cursor/embedded.c \ 38 38 font/embedded.c \ 39 font/bitmap_backend.c \ 40 font/pcf.c \ 39 41 gfx/font-8x16.c \ 40 42 gfx/cursor-11x18.c \ -
uspace/lib/draw/font.c
ra4666a9 r5713e5f 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 34 35 */ 35 36 36 #include <assert.h>37 37 #include <malloc.h> 38 #include <errno.h> 39 #include <str.h> 38 40 39 41 #include "font.h" … … 41 43 #include "drawctx.h" 42 44 43 void font_init(font_t *font, font_decoder_type_t decoder, char *path, uint16_t points)45 font_t *font_create(font_backend_t *backend, void *backend_data) 44 46 { 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 } 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; 77 55 } 78 56 79 57 void font_release(font_t *font) 80 58 { 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]); 59 font->backend->release(font->backend_data); 60 } 61 62 int font_get_metrics(font_t *font, font_metrics_t *metrics) { 63 return font->backend->get_font_metrics(font->backend_data, metrics); 64 } 65 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 } 69 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; 85 106 } 86 107 } 87 free(font->glyphs); 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); 88 115 } 89 90 if (font->decoder) {91 font->decoder->release(font->decoder_data);92 }116 117 *width = x; 118 *height = fm.ascender + fm.descender; 119 return EOK; 93 120 } 94 121 95 void font_get_box(font_t *font, char *text, sysarg_t *width, sysarg_t *height) 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) 96 125 { 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 }126 }127 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);133 134 126 drawctx_save(context); 135 127 drawctx_set_compose(context, compose_over); 136 128 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 } 129 font_metrics_t fm; 130 int rc = font_get_metrics(font, &fm); 131 if (rc != EOK) 132 return rc; 144 133 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); 134 native_t baseline = sy + fm.ascender; 135 native_t x = sx; 150 136 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; 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; 159 149 } 160 150 } 161 ++text; 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 162 164 } 163 165 164 166 drawctx_restore(context); 165 167 source_set_mask(source, NULL, false); 168 169 return EOK; 166 170 } 167 171 -
uspace/lib/draw/font.h
ra4666a9 r5713e5f 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 45 46 typedef struct drawctx drawctx_t; 46 47 47 typedef enum { 48 FONT_DECODER_EMBEDDED 49 } font_decoder_type_t; 48 typedef int metric_t; 50 49 51 50 typedef struct { 52 void (*init)(char *, uint16_t *, void **); 53 uint16_t (*resolve)(const wchar_t, void *); 54 surface_t *(*render)(uint16_t, uint16_t); 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; 68 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); 55 98 void (*release)(void *); 56 } font_ decoder_t;99 } font_backend_t; 57 100 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; 101 typedef struct { 102 font_backend_t *backend; 103 void *backend_data; 64 104 } font_t; 65 105 66 extern void font_init(font_t *, font_decoder_type_t, char *, uint16_t); 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); 67 112 extern void font_release(font_t *); 68 113 69 extern voidfont_get_box(font_t *, char *, sysarg_t *, sysarg_t *);70 extern voidfont_draw_text(font_t *, drawctx_t *, source_t *, const char *,114 extern int font_get_box(font_t *, char *, sysarg_t *, sysarg_t *); 115 extern int font_draw_text(font_t *, drawctx_t *, source_t *, const char *, 71 116 sysarg_t, sysarg_t); 72 117 -
uspace/lib/draw/font/embedded.c
ra4666a9 r5713e5f 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 34 35 */ 35 36 36 #include <assert.h>37 37 #include <sys/types.h> 38 38 #include <malloc.h> 39 #include <errno.h> 39 40 40 41 #include "../gfx/font-8x16.h" 41 42 #include "embedded.h" 42 43 #include "../drawctx.h" 44 #include "bitmap_backend.h" 43 45 44 static void fde_init(char *path, uint16_t *glyph_count, void **data) 46 static int fde_resolve_glyph(void *unused, const wchar_t chr, 47 glyph_id_t *glyph_id) 45 48 { 46 assert(glyph_count); 47 assert(data); 48 49 (*glyph_count) = FONT_GLYPHS; 50 (*data) = NULL; 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; 51 56 } 52 57 53 static uint16_t fde_resolve(const wchar_t chr, void *data) 58 static int fde_load_glyph_surface(void *unused, glyph_id_t glyph_id, 59 surface_t **out_surface) 54 60 { 55 return fb_font_glyph(chr); 61 surface_t *surface = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0); 62 if (!surface) 63 return ENOMEM; 64 65 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) { 66 for (unsigned int x = 0; x < FONT_WIDTH; ++x) { 67 pixel_t p = (fb_font[glyph_id][y] & (1 << (7 - x))) ? 68 PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0); 69 surface_put_pixel(surface, x, y, p); 70 } 71 } 72 73 *out_surface = surface; 74 return EOK; 56 75 } 57 76 58 static surface_t *fde_render(uint16_t glyph, uint16_t points) 77 static int fde_load_glyph_metrics(void *unused, glyph_id_t glyph_id, 78 glyph_metrics_t *gm) 59 79 { 60 surface_t *template = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0); 61 if (!template) { 62 return NULL; 63 } 64 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) { 65 for (unsigned int x = 0; x < FONT_WIDTH; ++x) { 66 pixel_t p = (fb_font[glyph][y] & (1 << (7 - x))) ? 67 PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0); 68 surface_put_pixel(template, x, y, p); 69 } 70 } 71 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; 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; 103 88 } 104 89 … … 108 93 } 109 94 110 font_decoder_t fd_embedded = {111 . init = fde_init,112 . resolve = fde_resolve,113 . render = fde_render,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, 114 99 .release = fde_release 115 100 }; 116 101 102 font_metrics_t font_metrics = { 103 .ascender = FONT_ASCENDER, 104 .descender = (FONT_SCANLINES - FONT_ASCENDER), 105 .leading = 0 106 }; 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 117 114 /** @} 118 115 */ -
uspace/lib/draw/font/embedded.h
ra4666a9 r5713e5f 39 39 #include "../font.h" 40 40 41 extern font_decoder_t fd_embedded;41 extern int embedded_font_create(font_t **, uint16_t points); 42 42 43 43 #endif -
uspace/lib/draw/gfx/font-8x16.c
ra4666a9 r5713e5f 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 * 46 48 */ 47 uint16_t fb_font_glyph(const wchar_t ch )49 uint16_t fb_font_glyph(const wchar_t ch, bool *found) 48 50 { 51 if (found) 52 *found = true; 53 49 54 if (ch == 0x0000) 50 55 return 0; … … 361 366 if (ch == 0xfeff) 362 367 return 2896; 368 369 if (found) 370 *found = false; 363 371 364 372 return 2898; -
uspace/lib/draw/gfx/font-8x16.h
ra4666a9 r5713e5f 37 37 38 38 #include <sys/types.h> 39 #include <stdbool.h> 39 40 40 41 #define FONT_GLYPHS 2899 41 42 #define FONT_WIDTH 8 42 43 #define FONT_SCANLINES 16 44 #define FONT_ASCENDER 12 43 45 44 extern uint16_t fb_font_glyph(const wchar_t );46 extern uint16_t fb_font_glyph(const wchar_t, bool *); 45 47 extern uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES]; 46 48 -
uspace/lib/draw/source.c
ra4666a9 r5713e5f 45 45 source->color = PIXEL(0, 0, 0, 0); 46 46 source->texture = NULL; 47 source->texture_ tile = false;47 source->texture_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK; 48 48 49 49 source->alpha = PIXEL(255, 0, 0, 0); 50 50 source->mask = NULL; 51 source->mask_ tile = false;51 source->mask_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK; 52 52 } 53 53 … … 73 73 } 74 74 75 void source_set_texture(source_t *source, surface_t *texture, bool tile) 75 void source_set_texture(source_t *source, surface_t *texture, 76 pixelmap_extend_t extend) 76 77 { 77 78 source->texture = texture; 78 source->texture_ tile = tile;79 source->texture_extend = extend; 79 80 } 80 81 … … 84 85 } 85 86 86 void source_set_mask(source_t *source, surface_t *mask, bool tile) 87 void source_set_mask(source_t *source, surface_t *mask, 88 pixelmap_extend_t extend) 87 89 { 88 90 source->mask = mask; 89 source->mask_ tile = tile;91 source->mask_extend = extend; 90 92 } 91 93 … … 95 97 (source->alpha == (pixel_t) PIXEL(255, 0, 0, 0)) && 96 98 (source->texture != NULL) && 97 (source->texture_ tile == false) &&99 (source->texture_extend == PIXELMAP_EXTEND_TRANSPARENT_BLACK) && 98 100 (transform_is_fast(&source->transform))); 99 101 } … … 120 122 mask_pix = source->filter( 121 123 surface_pixmap_access(source->mask), 122 x, y, source->mask_ tile);124 x, y, source->mask_extend); 123 125 } else { 124 126 mask_pix = source->alpha; … … 133 135 texture_pix = source->filter( 134 136 surface_pixmap_access(source->texture), 135 x, y, source->texture_ tile);137 x, y, source->texture_extend); 136 138 } else { 137 139 texture_pix = source->color; -
uspace/lib/draw/source.h
ra4666a9 r5713e5f 42 42 #include <transform.h> 43 43 #include <filter.h> 44 #include <io/pixelmap.h> 44 45 45 46 #include "surface.h" … … 51 52 pixel_t color; 52 53 surface_t *texture; 53 bool texture_tile;54 pixelmap_extend_t texture_extend; 54 55 55 56 pixel_t alpha; 56 57 surface_t *mask; 57 bool mask_tile;58 pixelmap_extend_t mask_extend; 58 59 } source_t; 59 60 … … 66 67 67 68 extern void source_set_color(source_t *, pixel_t); 68 extern void source_set_texture(source_t *, surface_t *, bool);69 extern void source_set_texture(source_t *, surface_t *, pixelmap_extend_t); 69 70 70 71 extern void source_set_alpha(source_t *, pixel_t); 71 extern void source_set_mask(source_t *, surface_t *, bool);72 extern void source_set_mask(source_t *, surface_t *, pixelmap_extend_t); 72 73 73 74 extern bool source_is_fast(source_t *); -
uspace/lib/gui/button.c
ra4666a9 r5713e5f 38 38 #include <drawctx.h> 39 39 #include <surface.h> 40 #include <font/embedded.h> 41 #include <errno.h> 40 42 #include "common.h" 41 43 #include "window.h" … … 76 78 sysarg_t cpt_width; 77 79 sysarg_t cpt_height; 78 font_get_box( &btn->font, btn->caption, &cpt_width, &cpt_height);80 font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height); 79 81 80 82 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { … … 83 85 84 86 drawctx_set_source(&drawctx, &btn->text); 85 drawctx_set_font(&drawctx, &btn->font);87 drawctx_set_font(&drawctx, btn->font); 86 88 87 89 if (btn->caption) … … 96 98 widget_deinit(&btn->widget); 97 99 free(btn->caption); 98 font_release( &btn->font);100 font_release(btn->font); 99 101 } 100 102 … … 171 173 btn->caption = str_dup(caption); 172 174 173 font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points); 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 } 174 181 175 182 sysarg_t cpt_width; 176 183 sysarg_t cpt_height; 177 font_get_box( &btn->font, btn->caption, &cpt_width, &cpt_height);184 font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height); 178 185 btn->widget.width_min = cpt_width + 10; 179 186 btn->widget.height_min = cpt_height + 10; -
uspace/lib/gui/button.h
ra4666a9 r5713e5f 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
ra4666a9 r5713e5f 58 58 source_init(&source); 59 59 source_set_transform(&source, transform); 60 source_set_texture(&source, canvas->surface, false); 60 source_set_texture(&source, canvas->surface, 61 PIXELMAP_EXTEND_TRANSPARENT_BLACK); 61 62 62 63 drawctx_t drawctx; -
uspace/lib/gui/label.c
ra4666a9 r5713e5f 38 38 #include <drawctx.h> 39 39 #include <surface.h> 40 #include <font/embedded.h> 41 #include <errno.h> 40 42 #include "window.h" 41 43 #include "label.h" … … 58 60 sysarg_t cpt_width; 59 61 sysarg_t cpt_height; 60 font_get_box( &lbl->font, lbl->caption, &cpt_width, &cpt_height);62 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 61 63 62 64 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { … … 65 67 66 68 drawctx_set_source(&drawctx, &lbl->text); 67 drawctx_set_font(&drawctx, &lbl->font);69 drawctx_set_font(&drawctx, lbl->font); 68 70 69 71 if (lbl->caption) … … 84 86 sysarg_t cpt_width; 85 87 sysarg_t cpt_height; 86 font_get_box( &lbl->font, lbl->caption, &cpt_width, &cpt_height);88 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 87 89 88 90 lbl->widget.width_min = cpt_width + 4; … … 99 101 widget_deinit(&lbl->widget); 100 102 free(lbl->caption); 101 font_release( &lbl->font);103 font_release(lbl->font); 102 104 } 103 105 … … 161 163 lbl->caption = str_dup(caption); 162 164 163 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 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 } 164 171 165 172 sysarg_t cpt_width; 166 173 sysarg_t cpt_height; 167 font_get_box( &lbl->font, lbl->caption, &cpt_width, &cpt_height);174 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 168 175 169 176 lbl->widget.width_min = cpt_width + 4; -
uspace/lib/gui/label.h
ra4666a9 r5713e5f 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
ra4666a9 r5713e5f 186 186 // for full UTF-32 coverage. 187 187 188 uint16_t glyph = fb_font_glyph(field->ch );188 uint16_t glyph = fb_font_glyph(field->ch, NULL); 189 189 190 190 for (unsigned int y = 0; y < FONT_SCANLINES; y++) { -
uspace/lib/gui/window.c
ra4666a9 r5713e5f 55 55 #include <drawctx.h> 56 56 #include <surface.h> 57 #include <font/embedded.h> 57 58 58 59 #include "common.h" … … 160 161 /* Window caption */ 161 162 162 font_t font; 163 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16); 164 165 drawctx_set_font(&drawctx, &font); 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); 166 171 source_set_color(&source, widget->window->is_focused ? 167 172 color_caption_focus : color_caption_unfocus); … … 169 174 sysarg_t cpt_width; 170 175 sysarg_t cpt_height; 171 font_get_box( &font, widget->window->caption, &cpt_width, &cpt_height);176 font_get_box(font, widget->window->caption, &cpt_width, &cpt_height); 172 177 173 178 bool draw_title = … … 183 188 } 184 189 185 font_release( &font);190 font_release(font); 186 191 window_yield(widget->window); 187 192 } -
uspace/lib/posix/include/posix/stdio.h
ra4666a9 r5713e5f 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); 109 110 extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3); 110 111 #endif -
uspace/lib/softrend/filter.c
ra4666a9 r5713e5f 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 35 36 36 37 #include "filter.h" 38 #include <io/pixel.h> 37 39 38 pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y, bool tile) 40 41 static long round(double val) 39 42 { 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); 42 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); 43 return val > 0 ? (long) (val + 0.5) : (long) (val - 0.5); 49 44 } 50 45 51 pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y, bool tile)46 static long floor(double val) 52 47 { 53 // TODO 54 return 0; 48 long lval = (long) val; 49 if (val < 0 && lval != val) 50 return lval - 1; 51 return lval; 55 52 } 56 53 57 pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y, bool tile) 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) 58 117 { 59 118 // TODO -
uspace/lib/softrend/filter.h
ra4666a9 r5713e5f 40 40 #include <io/pixelmap.h> 41 41 42 typedef pixel_t (*filter_t)(pixelmap_t *, double, double, bool);42 typedef pixel_t (*filter_t)(pixelmap_t *, double, double, pixelmap_extend_t); 43 43 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);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); 47 47 48 48 #endif -
uspace/srv/hid/compositor/compositor.c
ra4666a9 r5713e5f 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; 86 88 87 89 typedef struct { … … 408 410 409 411 source_init(&source); 410 source_set_filter(&source, filter _nearest);412 source_set_filter(&source, filter); 411 413 drawctx_init(&context, vp->surface); 412 414 drawctx_set_compose(&context, compose_over); … … 442 444 443 445 source_set_transform(&source, transform); 444 source_set_texture(&source, win->surface, false); 446 source_set_texture(&source, win->surface, 447 PIXELMAP_EXTEND_TRANSPARENT_SIDES); 445 448 source_set_alpha(&source, PIXEL(win->opacity, 0, 0, 0)); 446 449 … … 1818 1821 key == KC_O || key == KC_P); 1819 1822 bool kconsole_switch = (mods & KM_ALT) && (key == KC_M); 1820 1821 bool filter = (type == KEY_RELEASE) && (win_transform || win_resize || 1823 bool filter_switch = (mods & KM_ALT) && (key == KC_Y); 1824 1825 bool key_filter = (type == KEY_RELEASE) && (win_transform || win_resize || 1822 1826 win_opacity || win_close || win_switch || viewport_move || 1823 viewport_change || kconsole_switch );1824 1825 if ( filter) {1827 viewport_change || kconsole_switch || filter_switch); 1828 1829 if (key_filter) { 1826 1830 /* no-op */ 1827 1831 } else if (win_transform) { … … 2091 2095 if (console_kcon()) 2092 2096 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); 2093 2108 } else { 2094 2109 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
Note:
See TracChangeset
for help on using the changeset viewer.