1     type Skia =
2         var width : u32
3         var height : u32
4     
5         let interface = sk/make_native_interface
6         let context = DirectContexts.make_gl interface |> release
7     
8         let framebuffer_info = FramebufferInfo
9             fbo_id = 0
10            format = Gl.rgba8
11    
12        let color_type = ColorType/RGBA_8888
13        let props = SurfaceProps 0 PixelGeometry/RgbHorizontal
14    
15        let mut backend_render_target : mem BackendRenderTarget @late
16        let mut surface : MutPtr<mem Surface> @late
17    
18        let create () =
19            backend_render_target = BackendRenderTargets.make_gl
20                width.as<int> height.as<int> 0 0 framebuffer_info@ref
21    
22            surface = Surfaces.wrap_backend_render_target
23                context
24                backend_render_target
25                SurfaceOrigin/BottomLeft
26                color_type null props@ptr
27                null null
28            |> release
29            assert surface <> null
30    
31        create
32    
33        def get_canvas =
34            surface@to_ref.get_canvas
35    
36        def flush =
37            context@to_ref.flush
38    
39        def resize (w : u32) (h : u32) =
40            width = w
41            height = h
42            create
43    
44    def create_color (r : u32
45                      g : u32
46                      b : u32) =
47        let a : u32 @param = 255
48    
49        (a << 24) | (r << 16) | (g << 8) | (b << 0)
50    
51    val white = create_color 255 255 255
52    let blue = create_color 0 0 255
53    val black = create_color 0 0 0
54    
55    let main () =
56        Glfw.init |> ignore
57        Glfw.window_hint Glfw.context_version_major 3
58             window_hint Glfw.context_version_minor 2
59             window_hint Glfw.opengl_forward_compat Glfw.true
60             window_hint Glfw.opengl_profile Glfw.opengl_core_profile
61             window_hint Glfw.stencil_bits 0
62             window_hint Glfw.depth_bits 0
63             swap_interval 1
64    
65        let width = 960
66        let height = 640
67        let window = GlfwWindow.create width height "Skia test"
68                                       is_resizable = true
69        Glfw.make_context_current window
70    
71        let skia = Skia width height
72        let canvas = skia.get_canvas
73        let paint = Paint.new
74    
75        let font_manager = sk/make_font_manager null sk/make_freetype_font_scanner
76        let font_path = "/home/denis/develop/data/fonts/JetBrainsMono/JetBrainsMono-Medium.ttf"
77        let typeface = font_manager.make_from_file font_path
78        let font = Font typeface@copy
79        font.set_subpixel true
80             set_edging FontEdging/SubpixelAntiAlias
81             set_size 18
82    
83        while Glfw.window_should_close window == 0 do
84            Glfw.wait_events
85            paint.set_color white
86            canvas.draw_paint paint
87            paint.set_color blue
88            let rect = Rect 100 200 300 500
89            canvas.draw_rect rect@ref paint
90            paint.set_color black
91            canvas.draw_string "test" 10 20 font paint
92            skia.flush
93            Glfw.swap_buffers window
94            sys/thread/sleep 33
95    
96        Glfw.destroy_window window
97        Glfw.terminate
98    
99    # main
100