Skip to content

Commit

Permalink
incorporate functionality from loki-chat#11
Browse files Browse the repository at this point in the history
  • Loading branch information
limikael committed May 4, 2023
1 parent 39e2f80 commit 9d50df7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
31 changes: 1 addition & 30 deletions examples/skia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,8 @@ impl EventHandler for Stage {

impl Stage {
pub fn new()->Self {
//println!("addr: {:?}",window::get_gl_proc_addr("glDrawArrays"));

let skia_ctx = {
// Skia initialization on OpenGL
use skia_safe::gpu::{gl::FramebufferInfo, DirectContext};
use std::convert::TryInto;

let interface = skia_safe::gpu::gl::Interface::new_load_with(window::get_gl_proc_addr)
.expect("Failed to create Skia <-> OpenGL interface");

let dctx = DirectContext::new_gl(Some(interface), None)
.expect("Failed to create Skia's direct context");

let fb_info = {
let mut fboid: gl::GLint = 0;
unsafe { gl::glGetIntegerv(gl::GL_FRAMEBUFFER_BINDING, &mut fboid) };

FramebufferInfo {
fboid: fboid.try_into().unwrap(),
format: gl::GL_RGBA8,
}
};

// TODO! expose a way to get the window size
let (w,h)=(800,600);

SkiaContext::new(dctx, fb_info, w, h)
};

Self {
skia_ctx,
skia_ctx: SkiaContext::from_gl_loader(),
pointers: [
// pointers for fingers
Pointer::colored(0xff3737),
Expand Down
28 changes: 28 additions & 0 deletions src/skia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use skia_safe::{
Surface,
};

use crate::{gl, window};

pub struct SkiaContext {
pub(crate) fb_info: FramebufferInfo,
pub surface: Surface,
Expand All @@ -21,6 +23,32 @@ impl SkiaContext {
}
}

pub fn from_gl_loader()->Self {
use std::convert::TryInto;

let interface = skia_safe::gpu::gl::Interface::new_load_with(window::get_gl_proc_addr)
.expect("Failed to create Skia <-> OpenGL interface");

let dctx = DirectContext::new_gl(Some(interface), None)
.expect("Failed to create Skia's direct context");

let fb_info = {
let mut fboid: gl::GLint = 0;
unsafe { gl::glGetIntegerv(gl::GL_FRAMEBUFFER_BINDING, &mut fboid) };

FramebufferInfo {
fboid: fboid.try_into().unwrap(),
format: gl::GL_RGBA8,
}
};

// TODO! This shouldn't be screen size, it should be window size,
// but there is currently no way to get it.
let (w,h)=window::screen_size();

SkiaContext::new(dctx, fb_info, w as i32, h as i32)
}

pub fn recreate_surface(&mut self, width: i32, height: i32) {
self.surface = Self::create_surface(&mut self.dctx, self.fb_info, width, height);
}
Expand Down

0 comments on commit 9d50df7

Please sign in to comment.