Permalink
Browse files

ui.pixel-formats: apply @jonenst's patch for #1859.

  • Loading branch information...
mrjbq7 committed Oct 9, 2017
1 parent 9cdb209 commit dc001f9a34dba13a109310ac9b82903448e5007f
Showing with 27 additions and 6 deletions.
  1. +13 −3 basis/ui/pixel-formats/pixel-formats-tests.factor
  2. +14 −3 basis/ui/pixel-formats/pixel-formats.factor
@@ -1,14 +1,24 @@
USING: specialized-arrays.instances.alien.c-types.int tools.test
USING: alien.c-types literals specialized-arrays tools.test
ui.pixel-formats ;
SPECIALIZED-ARRAY: int
IN: ui.pixel-formats.tests
CONSTANT: attrib-table {
{ windowed { 99 } }
{ double-buffered { 7 } }
{ samples { 100001 } }
}
SYMBOL: garbageword
CONSTANT: garbageint 234
! pixel-format-attributes>int-array
{ int-array{ 9 2 99 7 0 } } [
{ windowed double-buffered } { 9 2 } attrib-table
! it should ignore garbage, even the color-bits because it's not
! in the table
{ int-array{ 9 2 99 7 100001 2 0 } } [
{
windowed "garbage" $ garbageint double-buffered
garbageword T{ samples f 2 } T{ color-bits f 24 }
} { 9 2 } attrib-table
pixel-format-attributes>int-array
] unit-test
@@ -1,5 +1,6 @@
USING: accessors alien.c-types alien.data assocs destructors fry
kernel math sequences specialized-arrays ui.backend ;
USING: accessors alien.c-types alien.data assocs classes
combinators destructors fry kernel math sequences
specialized-arrays ui.backend words ;
SPECIALIZED-ARRAY: int
IN: ui.pixel-formats
@@ -57,8 +58,18 @@ TUPLE: pixel-format < disposable world handle ;
M: pixel-format dispose*
[ (free-pixel-format) ] [ f >>handle drop ] bi ;
: (pixel-format-attribute) ( attribute table -- arr/f )
[ dup class-of ] dip at [ swap value>> suffix ] [ drop f ] if* ;
: pixel-format-attribute>array ( obj table -- arr/f )
{
{ [ over pixel-format-attribute? ] [ (pixel-format-attribute) ] }
{ [ over word? ] [ at ] }
[ 2drop f ]
} cond ;
: pixel-format-attributes>int-array ( attrs perm table -- arr )
swapd '[ _ at ] map sift concat append
swapd '[ _ pixel-format-attribute>array ] map sift concat append
! 0 happens to work as a sentinel value for all ui backends.
0 suffix int >c-array ;

0 comments on commit dc001f9

Please sign in to comment.