From 4756c30d3f91eff6b5e31e59b2ed4bb2da2f2775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Mon, 30 Jan 2017 05:43:19 +0100 Subject: [PATCH] ui.pixel-formats,ui.backend.*: new word pixel-format-attributes>int-array This word replaces usages of the PIXEL-FORMAT-ATTRIBUTE-TABLE: syntax --- basis/ui/backend/gtk/gtk.factor | 45 +++++++++---------- basis/ui/backend/x11/x11.factor | 11 ++--- .../pixel-formats/pixel-formats-tests.factor | 14 ++++++ basis/ui/pixel-formats/pixel-formats.factor | 11 +++-- 4 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 basis/ui/pixel-formats/pixel-formats-tests.factor diff --git a/basis/ui/backend/gtk/gtk.factor b/basis/ui/backend/gtk/gtk.factor index 819d7afe4c..6af7d43aa3 100644 --- a/basis/ui/backend/gtk/gtk.factor +++ b/basis/ui/backend/gtk/gtk.factor @@ -362,33 +362,30 @@ CONSTANT: window-controls>func-flags ] 2tri ; ! OpenGL and Pixel formats +CONSTANT: perm-attribs ${ GDK_GL_USE_GL GDK_GL_RGBA } -PIXEL-FORMAT-ATTRIBUTE-TABLE: gl-config-attribs - ${ GDK_GL_USE_GL GDK_GL_RGBA } - H{ - { double-buffered ${ GDK_GL_DOUBLEBUFFER } } - { stereo ${ GDK_GL_STEREO } } - ! { offscreen ${ GDK_GL_DRAWABLE_TYPE 2 } } - ! { fullscreen ${ GDK_GL_DRAWABLE_TYPE 1 } } - ! { windowed ${ GDK_GL_DRAWABLE_TYPE 1 } } - { color-bits ${ GDK_GL_BUFFER_SIZE } } - { red-bits ${ GDK_GL_RED_SIZE } } - { green-bits ${ GDK_GL_GREEN_SIZE } } - { blue-bits ${ GDK_GL_BLUE_SIZE } } - { alpha-bits ${ GDK_GL_ALPHA_SIZE } } - { accum-red-bits ${ GDK_GL_ACCUM_RED_SIZE } } - { accum-green-bits ${ GDK_GL_ACCUM_GREEN_SIZE } } - { accum-blue-bits ${ GDK_GL_ACCUM_BLUE_SIZE } } - { accum-alpha-bits ${ GDK_GL_ACCUM_ALPHA_SIZE } } - { depth-bits ${ GDK_GL_DEPTH_SIZE } } - { stencil-bits ${ GDK_GL_STENCIL_SIZE } } - { aux-buffers ${ GDK_GL_AUX_BUFFERS } } - { sample-buffers ${ GDK_GL_SAMPLE_BUFFERS } } - { samples ${ GDK_GL_SAMPLES } } - } +CONSTANT: attrib-table H{ + { double-buffered ${ GDK_GL_DOUBLEBUFFER } } + { stereo ${ GDK_GL_STEREO } } + { color-bits ${ GDK_GL_BUFFER_SIZE } } + { red-bits ${ GDK_GL_RED_SIZE } } + { green-bits ${ GDK_GL_GREEN_SIZE } } + { blue-bits ${ GDK_GL_BLUE_SIZE } } + { alpha-bits ${ GDK_GL_ALPHA_SIZE } } + { accum-red-bits ${ GDK_GL_ACCUM_RED_SIZE } } + { accum-green-bits ${ GDK_GL_ACCUM_GREEN_SIZE } } + { accum-blue-bits ${ GDK_GL_ACCUM_BLUE_SIZE } } + { accum-alpha-bits ${ GDK_GL_ACCUM_ALPHA_SIZE } } + { depth-bits ${ GDK_GL_DEPTH_SIZE } } + { stencil-bits ${ GDK_GL_STENCIL_SIZE } } + { aux-buffers ${ GDK_GL_AUX_BUFFERS } } + { sample-buffers ${ GDK_GL_SAMPLE_BUFFERS } } + { samples ${ GDK_GL_SAMPLES } } +} M: gtk-ui-backend (make-pixel-format) - nip >gl-config-attribs-int-array gdk_gl_config_new ; + nip perm-attribs attrib-table + pixel-format-attributes>int-array gdk_gl_config_new ; M: gtk-ui-backend (free-pixel-format) handle>> g_object_unref ; diff --git a/basis/ui/backend/x11/x11.factor b/basis/ui/backend/x11/x11.factor index 2b97e36d35..4a85b42a42 100644 --- a/basis/ui/backend/x11/x11.factor +++ b/basis/ui/backend/x11/x11.factor @@ -6,8 +6,8 @@ environment io.encodings.ascii io.encodings.string io.encodings.utf8 kernel literals locals math namespaces sequences specialized-arrays strings ui ui.backend ui.backend.x11.keys ui.clipboards ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures -ui.pixel-formats ui.pixel-formats.private ui.private x11 x11.X -x11.clipboard x11.events x11.glx x11.io x11.windows x11.xim x11.xlib ; +ui.pixel-formats ui.private x11 x11.X x11.clipboard x11.events x11.glx +x11.io x11.windows x11.xim x11.xlib ; FROM: libc => system ; SPECIALIZED-ARRAYS: uchar ulong ; IN: ui.backend.x11 @@ -68,7 +68,8 @@ M: world configure-event ! In case dimensions didn't change relayout-1 ; -PIXEL-FORMAT-ATTRIBUTE-TABLE: glx-visual { $ GLX_RGBA } H{ +CONSTANT: perm-attribs { $ GLX_RGBA } +CONSTANT: attrib-table H{ { double-buffered { $ GLX_DOUBLEBUFFER } } { stereo { $ GLX_STEREO } } { color-bits { $ GLX_BUFFER_SIZE } } @@ -88,8 +89,8 @@ PIXEL-FORMAT-ATTRIBUTE-TABLE: glx-visual { $ GLX_RGBA } H{ } M: x11-ui-backend (make-pixel-format) - [ drop dpy get scr get ] dip - >glx-visual-int-array glXChooseVisual ; + [ drop dpy get scr get ] dip perm-attribs attrib-table + pixel-format-attributes>int-array glXChooseVisual ; M: x11-ui-backend (free-pixel-format) handle>> XFree ; diff --git a/basis/ui/pixel-formats/pixel-formats-tests.factor b/basis/ui/pixel-formats/pixel-formats-tests.factor new file mode 100644 index 0000000000..67690e4ab1 --- /dev/null +++ b/basis/ui/pixel-formats/pixel-formats-tests.factor @@ -0,0 +1,14 @@ +USING: specialized-arrays.instances.alien.c-types.int tools.test +ui.pixel-formats ; +IN: ui.pixel-formats.tests + +CONSTANT: attrib-table { + { windowed { 99 } } + { double-buffered { 7 } } +} + +! pixel-format-attributes>int-array +{ int-array{ 9 2 99 7 0 } } [ + { windowed double-buffered } { 9 2 } attrib-table + pixel-format-attributes>int-array +] unit-test diff --git a/basis/ui/pixel-formats/pixel-formats.factor b/basis/ui/pixel-formats/pixel-formats.factor index 97f8dc6a3f..dc97d4bf8d 100644 --- a/basis/ui/pixel-formats/pixel-formats.factor +++ b/basis/ui/pixel-formats/pixel-formats.factor @@ -1,6 +1,6 @@ -USING: alien.c-types alien.data accessors assocs classes -destructors functors kernel lexer math parser sequences -specialized-arrays ui.backend words ; +USING: accessors alien.c-types alien.data assocs classes destructors +fry functors kernel lexer math parser sequences specialized-arrays +ui.backend words ; SPECIALIZED-ARRAY: int IN: ui.pixel-formats @@ -57,6 +57,11 @@ TUPLE: pixel-format < disposable world handle ; M: pixel-format dispose* [ (free-pixel-format) ] [ f >>handle drop ] bi ; +: pixel-format-attributes>int-array ( attrs perm table -- arr ) + swapd '[ _ at ] map sift concat append + ! 0 happens to work as a sentinel value for all ui backends. + 0 suffix int >c-array ; +