From d370c3c94f7a7875c3887a5270b53289e1f96a94 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sat, 9 Aug 2014 10:42:56 +0000 Subject: [PATCH] sdk: 1)update 2)freetype sample git-svn-id: svn://kolibrios.org@5024 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/samples/Mesa/gl-render/main.c | 509 ++---------------- contrib/sdk/samples/freetype/txview/Makefile | 29 + contrib/sdk/samples/freetype/txview/fontlib.c | 275 ++++++++++ contrib/sdk/samples/freetype/txview/main.c | 142 +++++ contrib/sdk/sources/Intel-2D/Makefile | 4 +- .../sources/newlib/libc/include/kos32sys.h | 1 - contrib/sdk/sources/render/render.c | 4 +- 7 files changed, 492 insertions(+), 472 deletions(-) create mode 100644 contrib/sdk/samples/freetype/txview/Makefile create mode 100644 contrib/sdk/samples/freetype/txview/fontlib.c create mode 100644 contrib/sdk/samples/freetype/txview/main.c diff --git a/contrib/sdk/samples/Mesa/gl-render/main.c b/contrib/sdk/samples/Mesa/gl-render/main.c index c17f0fab46..41a8aa8e83 100644 --- a/contrib/sdk/samples/Mesa/gl-render/main.c +++ b/contrib/sdk/samples/Mesa/gl-render/main.c @@ -3,45 +3,10 @@ #include #include -#define EGL_EGLEXT_PROTOTYPES -#define GL_GLEXT_PROTOTYPES - -#include "EGL/egl.h" -#include "EGL/eglext.h" -#include "GL/gl.h" +#include #include "gbm.h" -#include #include -#include -enum px_buffer -{ - PX_FRONT = 0, - PX_BACK = 1 -}; - -struct render -{ - EGLDisplay dpy; - EGLContext context; - GLuint framebuffer; - EGLImageKHR front, back, screen; - GLuint tx_buffers[2]; - GLuint tx_screen; - int back_buffer; - GLuint blit_prog; - GLint sampler; - float vertices[8], texcoords[8]; -}; - - -EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, - int width, int height, int stride, int name); -GLuint create_framebuffer(int width, int height, GLuint *tex); -GLint create_shader(GLenum type, const char *source); -struct render* create_render(EGLDisplay dpy, EGLSurface surface); -void blit_texture(struct render *render, GLuint tex, int x, int y, int w, int h); -void render_swap_buffers(struct render *render, int x, int y, int w, int h); int main() { @@ -59,6 +24,10 @@ int main() EGLint config_attribs[32]; EGLint num_configs, i; + int width = 400; + int height = 300; + int skinh; + int run =1; int fd; @@ -69,8 +38,6 @@ int main() return 1; }; - init_pixlib(HW_BIT_BLIT); - dpy = eglGetDisplay((EGLNativeDisplayType)gbm); if (!eglInitialize(dpy, &major, &minor)) @@ -106,10 +73,13 @@ int main() if (!context) printf("failed to create context"); - gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); + gs = gbm_surface_create(gbm, width, height, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); + + skinh = get_skin_height(); BeginDraw(); - DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74); + DrawWindow(20, 20, width+TYPE_3_BORDER_WIDTH*2, + height+TYPE_3_BORDER_WIDTH+skinh, "gl-render", 0x000000, 0x74); EndDraw(); surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL); @@ -120,14 +90,13 @@ int main() printf("failed to make window current"); - glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glViewport(0, 0, 400, 300); + glViewport(0, 0, width, height); glClearColor( 0, 0, 0, 1); @@ -147,16 +116,39 @@ int main() glFlush(); - asm volatile ("int3"); + // asm volatile ("int3"); - render = create_render(dpy, surface); - glViewport(0, 0, 1024, 768); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + render = create_render(dpy, surface, TYPE_3_BORDER_WIDTH, skinh); + render_blit(render, PX_BACK); + + while (run) + { + oskey_t key; + int ev; + + ev = get_os_event(); + switch(ev) + { + case 1: + BeginDraw(); + DrawWindow(0,0,0,0,NULL,0,0x74); + EndDraw(); + render_blit(render, PX_BACK); + break; + + case 2: + key = get_key(); + if (key.code == 27) + run = 0; + break; + + case 3: + if(get_os_button()==1) + run = 0; + break; + }; + } - render_swap_buffers(render, 20, 20, 400, 300); glFinish(); eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); @@ -165,426 +157,9 @@ int main() eglDestroyContext(dpy, context); eglTerminate(dpy); - while(1) - { - delay(1); - } - return 0; } -int drmIoctl(int fd, unsigned long request, void *arg) -{ - ioctl_t io; - - io.handle = fd; - io.io_code = request; - io.input = arg; - io.inp_size = 64; - io.output = NULL; - io.out_size = 0; - - return call_service(&io); -} - -EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, - int width, int height, int stride, int name) -{ - EGLImageKHR image; - EGLint attribs[] = { - EGL_WIDTH, 0, - EGL_HEIGHT, 0, - EGL_DRM_BUFFER_STRIDE_MESA, 0, - EGL_DRM_BUFFER_FORMAT_MESA, - EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, - EGL_DRM_BUFFER_USE_MESA, - EGL_DRM_BUFFER_USE_SHARE_MESA | - EGL_DRM_BUFFER_USE_SCANOUT_MESA, - EGL_NONE - }; - attribs[1] = width; - attribs[3] = height; - attribs[5] = stride/4; - - printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__, - width, height, stride, name); - - image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, - (void *) (uintptr_t)name, attribs); - - return image; -} - -GLint create_shader(GLenum type, const char *source) -{ - GLint ok; - GLint shader; - - shader = glCreateShader(type); - if(shader == 0) - goto err; - - glShaderSource(shader, 1, (const GLchar **) &source, NULL); - glCompileShader(shader); - glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); - if (!ok) { - GLchar *info; - GLint size; - - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); - - glGetShaderInfoLog(shader, size, NULL, info); - printf("Failed to compile %s: %s\n", - type == GL_FRAGMENT_SHADER ? "FS" : "VS",info); - printf("Program source:\n%s", source); - printf("GLSL compile failure\n"); - free(info); - glDeleteProgram(shader); - shader = 0; - } -err: - return shader; -} - - -struct render* create_render(EGLDisplay dpy, EGLSurface surface) -{ - const char *vs_src = - "attribute vec4 v_position;\n" - "attribute vec4 v_texcoord0;\n" - "varying vec2 source_texture;\n" - "void main()\n" - "{\n" - " gl_Position = v_position;\n" - " source_texture = v_texcoord0.xy;\n" - "}\n"; - - const char *fs_src = -// "precision mediump float;\n" - "varying vec2 source_texture;\n" - "uniform sampler2D sampler;\n" - "void main()\n" - "{\n" - " vec3 cg = texture2D(sampler, source_texture).rgb;\n" - " gl_FragColor = vec4(cg.r,cg.g,cg.b,1.0);\n" - "}\n"; - EGLint config_attribs[14]; - EGLConfig config; - EGLint num_configs; - - EGLContext context; - - struct drm_i915_fb_info fb; - GLint vs_shader, fs_shader; - GLenum status; - GLint ret; - int fd; - struct render *render; - - - - fd = get_service("DISPLAY"); - - memset(&fb, 0, sizeof(fb)); - ret = drmIoctl(fd, SRV_FBINFO, &fb); - if( ret != 0 ) - { printf("failed to get framebuffer info\n"); - goto err; - }; - - render = (struct render*)malloc(sizeof(struct render)); - if(render == NULL) - goto err; - - render->dpy = dpy; - - render->front = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_FRONT); - if(render->front == EGL_NO_IMAGE_KHR) - goto err1; - - render->back = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_BACK); - if( render->back == EGL_NO_IMAGE_KHR) - goto err2; - - glGenTextures(2, render->tx_buffers); - if(glGetError() != GL_NO_ERROR) - goto err3; - - glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_FRONT]); - if(glGetError() != GL_NO_ERROR) - goto err4; - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->front); - if(glGetError() != GL_NO_ERROR) - goto err4; - - glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_BACK]); - if(glGetError() != GL_NO_ERROR) - goto err4; - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->back); - if(glGetError() != GL_NO_ERROR) - goto err4; - - glBindTexture(GL_TEXTURE_2D, 0); - - render->back_buffer = EGL_DRM_BUFFER_BACK; - - context = eglGetCurrentContext(); - - config_attribs[0] = EGL_RED_SIZE; - config_attribs[1] = 1; - config_attribs[2] = EGL_GREEN_SIZE; - config_attribs[3] = 1; - config_attribs[4] = EGL_BLUE_SIZE; - config_attribs[5] = 1; - config_attribs[6] = EGL_DEPTH_SIZE; - config_attribs[7] = 1; - - config_attribs[8] = EGL_SURFACE_TYPE; - config_attribs[9] = EGL_WINDOW_BIT; - - config_attribs[10] = EGL_RENDERABLE_TYPE; - config_attribs[11] = EGL_OPENGL_BIT; - config_attribs[12] = EGL_NONE; - - if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs) - { - printf("failed to choose a config"); - goto err4; - } - - render->context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); - if (!context) - { - printf("failed to create context"); - goto err4; - }; - - if (!eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) - { - printf("failed to make window current"); - goto err5; - }; - - render->screen = px_create_image(dpy,context,fb.width,fb.height, - fb.pitch,fb.name); - if(render->screen == EGL_NO_IMAGE_KHR) - goto err6; - - glGenTextures(1, &render->tx_screen); - if(glGetError() != GL_NO_ERROR) - goto err6; - - glBindTexture(GL_TEXTURE_2D, render->tx_screen); - if(glGetError() != GL_NO_ERROR) - goto err7; - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->screen); - if(glGetError() != GL_NO_ERROR) - goto err7; - - glBindTexture(GL_TEXTURE_2D, 0); - - glGenFramebuffers(1, &render->framebuffer); - if(glGetError() != GL_NO_ERROR) - goto err8; - - glBindFramebuffer(GL_FRAMEBUFFER, render->framebuffer); - if(glGetError() != GL_NO_ERROR) - goto err9; - - glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, render->tx_screen,0); - - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) - { - const char *str; - switch (status) - { - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - str = "incomplete attachment"; - break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - str = "incomplete/missing attachment"; - break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: - str = "incomplete draw buffer"; - break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: - str = "incomplete read buffer"; - break; - case GL_FRAMEBUFFER_UNSUPPORTED: - str = "unsupported"; - break; - case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: - str = "incomplete multiple"; - break; - default: - str = "unknown error"; - break; - } - printf("destination is framebuffer incomplete: %s [%#x]\n", str, status); - goto err9; - } - - render->blit_prog = glCreateProgram(); - if(render->blit_prog == 0) - goto err9; - - vs_shader = create_shader(GL_VERTEX_SHADER,vs_src); - if(vs_shader == 0) - goto err10; - - fs_shader = create_shader(GL_FRAGMENT_SHADER, fs_src); - if(fs_shader == 0) - goto err11; - - glAttachShader(render->blit_prog, vs_shader); - glAttachShader(render->blit_prog, fs_shader); - glBindAttribLocation(render->blit_prog, 0, "v_position"); - glBindAttribLocation(render->blit_prog, 1, "v_texcoord0"); - glLinkProgram(render->blit_prog); - - glGetProgramiv(render->blit_prog, GL_LINK_STATUS, &ret); - if (!ret) - { - GLchar *info; - GLint size; - - glGetProgramiv(render->blit_prog, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); - - glGetProgramInfoLog(render->blit_prog, size, NULL, info); - printf("Failed to link: %s\n", info); - printf("GLSL link failure\n"); - free(info); - } - - render->sampler = glGetUniformLocation(render->blit_prog,"sampler"); - - eglMakeCurrent(dpy, surface, surface, context); - - return render; - -err11: - glDeleteShader(vs_shader); -err10: - glDeleteProgram(render->blit_prog); -err9: - glDeleteFramebuffers(1, &render->framebuffer); -err8: - eglDestroyImageKHR(dpy, render->screen); -err7: - glDeleteTextures(1, &render->tx_screen); -err6: - eglMakeCurrent(dpy, surface, surface, context); -err5: - eglDestroyContext(dpy, render->context); -err4: - glDeleteTextures(2, render->tx_buffers); -err3: - eglDestroyImageKHR(dpy, render->back); -err2: - eglDestroyImageKHR(dpy, render->front); -err1: - free(render); -err: - return NULL; -}; - -void render_swap_buffers(struct render *render, int x, int y, int w, int h) -{ - EGLContext context; - EGLSurface draw, read; - - float dst_xscale, dst_yscale; - float *vertices = render->vertices; - float *texcoords = render->texcoords; - int r, b; - - if(render == NULL) - return; - - context = eglGetCurrentContext(); - draw = eglGetCurrentSurface(EGL_DRAW); - read = eglGetCurrentSurface(EGL_READ); - - eglSwapBuffers(render->dpy,draw); - - if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) - { - printf("failed to make window current"); - goto err1; - }; - - glUseProgram(render->blit_prog); - glUniform1i(render->sampler, 0); - - glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); - glEnableVertexAttribArray(0); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]); - glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MIN_FILTER, - GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, - GL_TEXTURE_MAG_FILTER, - GL_NEAREST); - - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); - glEnableVertexAttribArray(1); - - dst_xscale = 1.0/1024; - dst_yscale = 1.0/768; - - r = x+w-1; - b = y+h-1; - - float t0, t1, t2, t5; - - vertices[0] = t0 = 2*x*dst_xscale - 1.0; - vertices[1 * 2] = t2 = 2*r*dst_xscale - 1.0; - - vertices[2 * 2] = t2; - vertices[3 * 2] = t0; - - vertices[1] = t1 = 2*y*dst_yscale - 1.0; - vertices[2*2+1] = t5 = 2*b*dst_yscale - 1.0; - vertices[1*2+1] = t1; - vertices[3*2+1] = t5; - - texcoords[0] = 0.0; - texcoords[1] = 0.0; - texcoords[1*2] = 1.0; - texcoords[1*2+1]= 0.0; - texcoords[2*2] = 1.0; - texcoords[2*2+1]= 1.0; - texcoords[3*2] = 0.0; - texcoords[3*2+1]= 1.0; - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - glDisable(GL_TEXTURE_2D); - glUseProgram(0); - - render->back_buffer++; - render->back_buffer&=1; - -err1: - eglMakeCurrent(render->dpy, draw, read, context); -} #if 0 GLuint create_framebuffer(int width, int height, GLuint *tex) diff --git a/contrib/sdk/samples/freetype/txview/Makefile b/contrib/sdk/samples/freetype/txview/Makefile new file mode 100644 index 0000000000..22f474f6b9 --- /dev/null +++ b/contrib/sdk/samples/freetype/txview/Makefile @@ -0,0 +1,29 @@ +CC = kos32-gcc +LD = kos32-ld + +SDK_DIR:= $(abspath ../../..) + +LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds -Map txview.map --image-base 0 + +CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 + +INCLUDES= -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/freetype/include +LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib + +SOURCES = main.c \ + fontlib.c \ + tview.c + + +OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) + + +default: txview + +txview: $(OBJECTS) Makefile + $(LD) $(LDFLAGS) $(LIBPATH) -o txview $(OBJECTS) -lfreetype.dll -lpixlib.dll -lgcc -lc.dll -lapp + objcopy txview -O binary + + +%.o : %.c Makefile $(SOURCES) + $(CC) $(CFLAGS) $(INCLUDES) -o $@ $< diff --git a/contrib/sdk/samples/freetype/txview/fontlib.c b/contrib/sdk/samples/freetype/txview/fontlib.c new file mode 100644 index 0000000000..dfe8cf2418 --- /dev/null +++ b/contrib/sdk/samples/freetype/txview/fontlib.c @@ -0,0 +1,275 @@ + +#include +#include +#include +#include +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H +#include + +typedef struct +{ + int l; + int t; + int r; + int b; +}rect_t; + +typedef struct +{ + FT_Face face; + int height; + int base; + + FT_Glyph glyph[256]; + +}font_t; + +static FT_Face def_face; + +typedef unsigned int color_t; + +unsigned int ansi2utf32(unsigned char ch); + +font_t *create_font(FT_Face face, int size); + +void my_draw_bitmap(bitmap_t *win, FT_Bitmap *bitmap, int dstx, int dsty, int col) +{ + uint8_t *dst; + uint8_t *src, *tmpsrc; + + uint32_t *tmpdst; + int i, j; + + dst = win->data + dsty * win->pitch + dstx*4; + src = bitmap->buffer; + +// printf("buffer %x width %d rows %d\n", +// bitmap->buffer, bitmap->width, bitmap->rows); + + + for( i = 0; i < bitmap->rows; i++ ) + { + tmpdst = (uint32_t*)dst; + tmpsrc = src; + + dst+= win->pitch; + src+= bitmap->pitch; + + for( j = 0; j < bitmap->width; j++) + { + int a = *tmpsrc++; + int sr, sg, sb; + int dr, dg, db; + + if( a != 0) a++; + + db = *tmpdst & 0xFF; + dg = (*tmpdst >> 8) & 0xFF; + dr = (*tmpdst >> 16) & 0xFF; + + sb = col & 0xFF; + sg = (col >> 8) & 0xFF; + sr = (col >> 16) &0xFF; + + db = (a*sb + db*(256-a))/256; + dg = (a*sg + dg*(256-a))/256; + dr = (a*sr + dr*(256-a))/256; + + *tmpdst++ = 0xFF000000|(dr<<16)|(dg<<8)|db; + }; + } +}; + + +int draw_text_ext(bitmap_t *winbitmap, font_t *font, char *text, int len, rect_t *rc, int color) +{ + FT_UInt glyph_index; + FT_Bool use_kerning = 0; + FT_BitmapGlyph glyph; + FT_UInt previous; + + int x, y, w; + int col, ncol; + unsigned char ch; + int err = 0; + + use_kerning = FT_HAS_KERNING( font->face ); + previous = 0; + col = 0; + + x = rc->l << 6; + y = rc->b; + + w = (rc->r - rc->l) << 6; + + while( len-- ) + { + ch = *text++; + + if(ch == '\n' || ch == '\r') + continue; + + if(ch == '\t') + { + ncol = (col+4) & ~3; + if( col < ncol) + { + glyph_index = FT_Get_Char_Index( font->face, ansi2utf32(' ') ); + + while( col < ncol) + { + if ( use_kerning && previous && glyph_index ) + { + FT_Vector delta; + FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); + x += delta.x ; + } + + if( x + (font->glyph[ch]->advance.x >> 10) > w) + break; + + x += font->glyph[ch]->advance.x >> 10; + previous = glyph_index; + col ++; + }; + }; + continue; + }; + + glyph_index = FT_Get_Char_Index( font->face, ansi2utf32(ch) ); + + if ( use_kerning && previous && glyph_index ) + { + FT_Vector delta; + FT_Get_Kerning( font->face, previous, glyph_index, FT_KERNING_DEFAULT, &delta ); + x += delta.x ; + } + + if( x + (font->glyph[ch]->advance.x >> 10) > w) + break; + + glyph = (FT_BitmapGlyph)font->glyph[ch]; + + my_draw_bitmap(winbitmap, &glyph->bitmap, (x >> 6) + glyph->left, + y - glyph->top, color); + + x += font->glyph[ch]->advance.x >> 10; + previous = glyph_index; + }; + + return err; +}; + + +int init_fontlib() +{ + static FT_Library library; + FT_Face face = NULL; + int err; + + err = FT_Init_FreeType( &library ); + if ( err ) + { + printf("an error occurred during FreeType initialization\n"); + goto done; + } + + err = FT_New_Face( library, "/kolibrios/Fonts/IstokWeb.ttf", 0, &face ); +// err = FT_New_Face( library, "/kolibrios/Fonts/lucon.ttf", 0, &face ); + if ( err == FT_Err_Unknown_File_Format ) + { + printf("font format is unsupported\n"); + goto done; + + } + else if ( err ) + { + printf("font file could not be read or broken\n"); + goto done; + + } + + def_face = face; + +done: + + return err; +}; + + +unsigned int ansi2utf32(unsigned char ch) +{ + if(ch < 0x80) + return ch; + + if(ch < 0xB0) + return 0x410-0x80 + ch; + + if(ch < 0xE0) + return 0; + + if(ch < 0xF0) + return 0x440-0xE0 + ch; + + if(ch == 0xF0) + return 0x401; + else if(ch==0xF1) + return 0x451; + else return 0; +} + + +font_t *create_font(FT_Face xface, int size) +{ + font_t *font; + int i, err; + + font = malloc(sizeof(*font)); + if(font == NULL) + return font; + + memset(font, 0, sizeof(*font)); + + font->face = (xface == NULL) ? def_face : xface; + font->height = size; + + err = FT_Set_Pixel_Sizes( font->face, 0, size ); + + for(i = 0; i < 256; i++) + { + FT_UInt glyph_index; + FT_BitmapGlyph glyph_bitmap; + + glyph_index = FT_Get_Char_Index( font->face, ansi2utf32(i) ); + + err = FT_Load_Glyph( font->face, glyph_index, FT_LOAD_DEFAULT ); + if ( err ) + { + font->glyph[i] = font->glyph[0] ; + continue; + }; + + err = FT_Get_Glyph( font->face->glyph, &font->glyph[i] ); + if (err) + { + font->glyph[i] = font->glyph[0] ; + continue; + }; + + if ( font->glyph[i]->format != FT_GLYPH_FORMAT_BITMAP ) + { + err = FT_Glyph_To_Bitmap( &font->glyph[i], FT_RENDER_MODE_NORMAL, 0, 1 ); + if ( err ) + continue; + + glyph_bitmap = (FT_BitmapGlyph)font->glyph[i]; + + if(glyph_bitmap->top > font->base) + font->base = glyph_bitmap->top; + } + } + + return font; +} diff --git a/contrib/sdk/samples/freetype/txview/main.c b/contrib/sdk/samples/freetype/txview/main.c new file mode 100644 index 0000000000..e91a340fbf --- /dev/null +++ b/contrib/sdk/samples/freetype/txview/main.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H +#include +#include + +typedef struct +{ + int l; + int t; + int r; + int b; +}rect_t; + +typedef struct +{ + FT_Face face; + int height; + int base; + + FT_Glyph glyph[256]; + +}font_t; + +typedef struct +{ + bitmap_t bitmap; + font_t *font; + + char *text; + char **line; + int lines; + int txlines; + int startline; + int endline; + int w; + int h; +}tview_t; + +int init_tview(tview_t *txv, int width, int height, char *text, int size); +int txv_scroll_up(tview_t *txv); +int txv_scroll_down(tview_t *txv); + +void* init_fontlib(); +int draw_text_ext(bitmap_t *winbitmap, FT_Face face, char *text, int len, rect_t *rc, int color); + +void draw_window(void) +{ + BeginDraw(); + DrawWindow(0,0,0,0,NULL,0,0x74); + EndDraw(); +} + +tview_t txv; + +int main(int argc, char *argv[]) +{ + ufile_t uf; + oskey_t key; + + __asm__ __volatile__( + "int $0x40" + ::"a"(40), "b"(0xc0000027)); + + if(argc < 2) + uf = load_file("/RD/1/EXAMPLE.ASM"); + else uf = load_file(argv[1]); + + if(uf.data == NULL || + uf.size == 0) + return 0; + + init_pixlib(0); + init_fontlib(); + + init_tview(&txv, 480, 600, uf.data, uf.size); + + BeginDraw(); + DrawWindow(10, 40, txv.w+TYPE_3_BORDER_WIDTH*2, + txv.h+TYPE_3_BORDER_WIDTH+get_skin_height(), "Text example", 0x000000, 0x74); + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + + EndDraw(); + + for (;;) + { + uint32_t wheels; + int buttons; + pos_t pos; + + switch (get_os_event()) + { + case 1: + draw_window(); + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; + case 2: + key = get_key(); + switch(key.code) + { + case 27: + return; + + case 177: + if( txv_scroll_up(&txv) ) + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; + + case 178: + if( txv_scroll_down(&txv) ) + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + break; + } + break; + + case 3: + // button pressed; we have only one button, close + return; + + case 6: +// pos = get_mouse_pos(); +// buttons = get_mouse_buttons(); + wheels = get_mouse_wheels(); + + if( wheels & 0xFFFF) + { + int r; + + if((short)wheels > 0) + r = txv_scroll_up(&txv); + else + r = txv_scroll_down(&txv); + + if( r ) + blit_bitmap(&txv.bitmap, TYPE_3_BORDER_WIDTH, get_skin_height(), txv.w, txv.h, 0, 0); + } + } + } + return 0; +} diff --git a/contrib/sdk/sources/Intel-2D/Makefile b/contrib/sdk/sources/Intel-2D/Makefile index 4bbc0bb6cb..28bc9c921c 100644 --- a/contrib/sdk/sources/Intel-2D/Makefile +++ b/contrib/sdk/sources/Intel-2D/Makefile @@ -8,7 +8,7 @@ STRIP = kos32-strip CFLAGS = -U_Win32 -U_WIN32 -U__MINGW32__ -c -O2 -fno-ident -fomit-frame-pointer LDFLAGS:= -shared -s -nostdlib -T ../newlib/dll.lds --entry _DllStartup --image-base=0 -PXFLAGS:= --version-script pixlib.ver --out-implib $(LIBRARY).dll.a +PXFLAGS:= --version-script pixlib.ver --out-implib lib$(LIBRARY).dll.a SNAFLAGS:= --version-script sna.ver --output-def sna.def UXAFLAGS:= --version-script uxa.ver --output-def uxa.def @@ -78,7 +78,7 @@ ebox:$(LIBRARY).dll $(LIBRARY).dll: $(OBJ_PIXLIB) Makefile $(LD) $(LDFLAGS) $(PXFLAGS) $(LIBPATH) -o $@ $(OBJ_PIXLIB) $(LIBS) mv -f $@ ../../bin - mv -f $(LIBRARY).dll.a ../../lib + mv -f lib$(LIBRARY).dll.a ../../lib intel-sna.drv: $(OBJ_SNA) Makefile $(LD) $(LDFLAGS) $(SNAFLAGS) $(LIBPATH) -o $@ $(OBJ_SNA) $(LIBS) diff --git a/contrib/sdk/sources/newlib/libc/include/kos32sys.h b/contrib/sdk/sources/newlib/libc/include/kos32sys.h index 6670c2b7e9..7c79d91765 100644 --- a/contrib/sdk/sources/newlib/libc/include/kos32sys.h +++ b/contrib/sdk/sources/newlib/libc/include/kos32sys.h @@ -146,7 +146,6 @@ uint32_t get_mouse_wheels(void) __asm__ __volatile__( "int $0x40 \n\t" - "rol $16, %%eax" :"=a"(val) :"a"(37),"b"(7)); return val; diff --git a/contrib/sdk/sources/render/render.c b/contrib/sdk/sources/render/render.c index d3a6842293..46cb033afe 100644 --- a/contrib/sdk/sources/render/render.c +++ b/contrib/sdk/sources/render/render.c @@ -453,7 +453,7 @@ void create_mask(struct render *render) (void *) (uintptr_t)mask_name, attribs); printf("create mask image %p\n", mask_image); if(mask_image == NULL) - goto err2 + goto err2; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); @@ -486,7 +486,7 @@ err3: eglDestroyImageKHR(render->dpy, mask_image); err2: close.handle = mask_handle; - (void)drm_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); + (void)drm_ioctl(render->fd, DRM_IOCTL_GEM_CLOSE, &close); glBindTexture(GL_TEXTURE_2D, 0); err1: glDeleteTextures(1, &render->tx_mask);