├── screenshot.png ├── src ├── reclutch_skia │ └── error.rs ├── reclutch_skia.rs └── main.rs ├── Cargo.toml ├── README.md └── LICENSE /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ctrlcctrlv/imgui-skia-example/HEAD/screenshot.png -------------------------------------------------------------------------------- /src/reclutch_skia/error.rs: -------------------------------------------------------------------------------- 1 | use thiserror::Error; 2 | 3 | /// An error within Skia and its interactions with OpenGL. 4 | #[derive(Error, Debug)] 5 | pub enum SkiaError { 6 | #[error("the OpenGL target {0} is invalid")] 7 | InvalidTarget(String), 8 | #[error("invalid OpenGL context")] 9 | InvalidContext, 10 | #[error("unknown skia error")] 11 | UnknownError, 12 | } 13 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "imgui-skia-example" 3 | version = "0.0.0" 4 | authors = ["Fredrick Brennan "] 5 | edition = "2018" 6 | license = "MIT / Apache-2.0" 7 | description = "An example of combining Skia and IMGui in Rust" 8 | 9 | [dependencies] 10 | skia-safe = { version = "0.32.1", features = ["gl"] } 11 | imgui-glium-renderer = "0.4.0" 12 | imgui-winit-support = "0.4.0" 13 | imgui = "0.4.0" 14 | glium = "0.27.0" 15 | gl = "0.14.0" 16 | thiserror = "1.0.20" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dear ImGui, Skia, and Rust, all playing nice together 2 | 3 | ![](https://raw.githubusercontent.com/ctrlcctrlv/imgui-skia-example/master/screenshot.png) 4 | 5 | **Turns out it's probably better to use Skulpin. Cf. [aclysma/skulpin#62](https://github.com/aclysma/skulpin/issues/62), [mfeq/Qglif#2](https://github.com/mfeq/Qglif/issues/2) and [jazzfool/reclutch#26](https://github.com/jazzfool/reclutch/issues/26). This repo will remain intact, but archived, if you're too stubborn to use Vulkan. :-)** 6 | 7 | Much of the code here comes from the Reclutch project: 8 | 9 | https://github.com/jazzfool/reclutch/blob/master/reclutch/examples/opengl/main.rs 10 | 11 | Reclutch is however _not a dependency_, and Skia is _directly accessible_ via `skia-safe`! 12 | 13 | (c) jazzfool - Dual Apache 2 / MIT licensed. 14 | 15 | I replaced the OpenGL cube example with Skia! :-) 16 | -------------------------------------------------------------------------------- /src/reclutch_skia.rs: -------------------------------------------------------------------------------- 1 | //! Robust implementation of `GraphicsDisplay` using Google's Skia. 2 | //! From https://github.com/jazzfool/reclutch/ 3 | //! MIT licensed 4 | 5 | extern crate gl; 6 | use { 7 | skia_safe as sk, 8 | std::collections::HashMap, 9 | }; 10 | 11 | mod error; 12 | 13 | /// Contains information about an existing OpenGL framebuffer. 14 | #[derive(Debug, Clone, Copy)] 15 | pub struct SkiaOpenGlFramebuffer { 16 | pub size: (i32, i32), 17 | pub framebuffer_id: u32, 18 | } 19 | 20 | /// Contains information about an existing OpenGL texture. 21 | #[derive(Debug, Clone, Copy)] 22 | pub struct SkiaOpenGlTexture { 23 | pub size: (i32, i32), 24 | pub mip_mapped: bool, 25 | pub texture_id: u32, 26 | } 27 | 28 | pub enum SurfaceType { 29 | OpenGlFramebuffer(SkiaOpenGlFramebuffer), 30 | OpenGlTexture(SkiaOpenGlTexture), 31 | } 32 | 33 | enum Resource { 34 | Image(sk::Image), 35 | Font(sk::Typeface), 36 | } 37 | 38 | /// Converts [`DisplayCommand`](crate::display::DisplayCommand) to immediate-mode Skia commands. 39 | pub struct SkiaGraphicsDisplay { 40 | pub surface: sk::Surface, 41 | pub surface_type: SurfaceType, 42 | pub context: sk::gpu::Context, 43 | next_command_group_id: u64, 44 | resources: HashMap, 45 | next_resource_id: u64, 46 | } 47 | 48 | impl SkiaGraphicsDisplay { 49 | /// Creates a new [`SkiaGraphicsDisplay`](SkiaGraphicsDisplay) with the Skia OpenGL backend, drawing into an existing framebuffer. 50 | /// This assumes that an OpenGL context has already been set up. 51 | /// This also assumes that the color format is RGBA with 8-bit components. 52 | pub fn new_gl_framebuffer(target: &SkiaOpenGlFramebuffer) -> Result { 53 | let (surface, context) = Self::new_gl_framebuffer_surface(target)?; 54 | Ok(Self { 55 | surface, 56 | surface_type: SurfaceType::OpenGlFramebuffer(*target), 57 | context, 58 | next_command_group_id: 0, 59 | resources: HashMap::new(), 60 | next_resource_id: 0, 61 | }) 62 | } 63 | 64 | /// Creates a new [`SkiaGraphicsDisplay`](SkiaGraphicsDisplay) with the Skia OpenGL backend, drawing into an existing texture. 65 | /// This assumes that an OpenGL context has already been set up. 66 | /// This also assumes that the color format is RGBA with 8-bit components 67 | pub fn new_gl_texture(target: &SkiaOpenGlTexture) -> Result { 68 | let (surface, context) = Self::new_gl_texture_surface(target)?; 69 | Ok(Self { 70 | surface, 71 | surface_type: SurfaceType::OpenGlTexture(*target), 72 | context, 73 | next_command_group_id: 0, 74 | resources: HashMap::new(), 75 | next_resource_id: 0, 76 | }) 77 | } 78 | 79 | /// Returns the size of the underlying surface. 80 | pub fn size(&self) -> (i32, i32) { 81 | match self.surface_type { 82 | SurfaceType::OpenGlFramebuffer(SkiaOpenGlFramebuffer { size, .. }) 83 | | SurfaceType::OpenGlTexture(SkiaOpenGlTexture { size, .. }) => size, 84 | } 85 | } 86 | 87 | fn new_gl_framebuffer_surface( 88 | target: &SkiaOpenGlFramebuffer, 89 | ) -> Result<(sk::Surface, sk::gpu::Context), error::SkiaError> { 90 | let mut context = Self::new_gl_context()?; 91 | 92 | Ok((SkiaGraphicsDisplay::new_gl_framebuffer_from_context(target, &mut context)?, context)) 93 | } 94 | 95 | fn new_gl_framebuffer_from_context( 96 | target: &SkiaOpenGlFramebuffer, 97 | context: &mut sk::gpu::Context, 98 | ) -> Result { 99 | let info = sk::gpu::BackendRenderTarget::new_gl( 100 | target.size, 101 | None, 102 | 8, 103 | sk::gpu::gl::FramebufferInfo { fboid: target.framebuffer_id, format: gl::RGBA8 }, 104 | ); 105 | 106 | Ok(sk::Surface::from_backend_render_target( 107 | context, 108 | &info, 109 | sk::gpu::SurfaceOrigin::BottomLeft, 110 | sk::ColorType::RGBA8888, 111 | sk::ColorSpace::new_srgb(), 112 | None, 113 | ) 114 | .ok_or_else(|| error::SkiaError::InvalidTarget(String::from("framebuffer")))?) 115 | } 116 | 117 | fn new_gl_texture_surface( 118 | target: &SkiaOpenGlTexture, 119 | ) -> Result<(sk::Surface, sk::gpu::Context), error::SkiaError> { 120 | let mut context = Self::new_gl_context()?; 121 | 122 | Ok((SkiaGraphicsDisplay::new_gl_texture_from_context(target, &mut context)?, context)) 123 | } 124 | 125 | fn new_gl_texture_from_context( 126 | target: &SkiaOpenGlTexture, 127 | context: &mut sk::gpu::Context, 128 | ) -> Result { 129 | let info = unsafe { 130 | sk::gpu::BackendTexture::new_gl( 131 | target.size, 132 | if target.mip_mapped { sk::gpu::MipMapped::Yes } else { sk::gpu::MipMapped::No }, 133 | sk::gpu::gl::TextureInfo { 134 | format: gl::RGBA8, 135 | target: gl::TEXTURE_2D, 136 | id: target.texture_id, 137 | }, 138 | ) 139 | }; 140 | 141 | Ok(sk::Surface::from_backend_texture( 142 | context, 143 | &info, 144 | sk::gpu::SurfaceOrigin::BottomLeft, 145 | None, 146 | sk::ColorType::RGBA8888, 147 | sk::ColorSpace::new_srgb(), 148 | None, 149 | ) 150 | .ok_or_else(|| error::SkiaError::InvalidTarget(String::from("texture")))?) 151 | } 152 | 153 | fn new_gl_context() -> Result { 154 | sk::gpu::Context::new_gl(sk::gpu::gl::Interface::new_native()) 155 | .ok_or(error::SkiaError::InvalidContext) 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Much of the code here comes from the Reclutch project: 3 | * 4 | * https://github.com/jazzfool/reclutch/blob/master/reclutch/examples/opengl/main.rs 5 | * 6 | * (c) jazzfool - MIT licensed. 7 | * 8 | * I replaced the OpenGL cube example with Skia! :-) 9 | * 10 | */ 11 | 12 | extern crate thiserror; 13 | #[macro_use] extern crate glium; 14 | extern crate skia_safe as skia; 15 | 16 | use glium::glutin; 17 | use glutin::event::{Event, WindowEvent, KeyboardInput, VirtualKeyCode}; 18 | use glutin::event_loop::{ControlFlow, EventLoop}; 19 | use glium::{GlObject, Surface}; 20 | 21 | use std::time::Instant; 22 | 23 | #[macro_use] extern crate imgui; // for the macros, can't use one in imgui_glium_renderer 24 | #[macro_use] extern crate imgui_glium_renderer; 25 | extern crate imgui_winit_support; 26 | use imgui_winit_support::WinitPlatform; 27 | use imgui_glium_renderer::Renderer as ImguiRenderer; 28 | use imgui::{Context as ImguiContext}; 29 | 30 | mod reclutch_skia; 31 | 32 | #[derive(Copy, Clone)] 33 | struct TextureVertex { 34 | position: [f32; 3], 35 | tex_coord: [f32; 2], 36 | } 37 | 38 | implement_vertex!(TextureVertex, position, tex_coord); 39 | 40 | const fn texture_vertex(pos: [i8; 2], tex: [i8; 2]) -> TextureVertex { 41 | TextureVertex { 42 | position: [pos[0] as _, pos[1] as _, 0.0], 43 | tex_coord: [tex[0] as _, tex[1] as _], 44 | } 45 | } 46 | 47 | const QUAD_VERTICES: [TextureVertex; 4] = [ 48 | texture_vertex([-1, -1], [0, 0]), 49 | texture_vertex([-1, 1], [0, 1]), 50 | texture_vertex([1, 1], [1, 1]), 51 | texture_vertex([1, -1], [1, 0]), 52 | ]; 53 | 54 | const QUAD_INDICES: [u32; 6] = [0, 1, 2, 0, 2, 3]; 55 | 56 | fn run_ui(ui: &mut imgui::Ui) { 57 | imgui::Window::new(im_str!("Hello world")) 58 | .size([300.0, 100.0], imgui::Condition::FirstUseEver) 59 | .build(ui, || { 60 | ui.text(im_str!("Hello world!")); 61 | ui.text(im_str!("This...is...imgui-rs!")); 62 | ui.separator(); 63 | let mouse_pos = ui.io().mouse_pos; 64 | ui.text(format!( 65 | "Mouse Position: ({:.1},{:.1})", 66 | mouse_pos[0], mouse_pos[1] 67 | )); 68 | }); 69 | } 70 | 71 | const HEIGHT: u32 = 500; 72 | const WIDTH: u32 = HEIGHT; 73 | 74 | fn main() { 75 | let window_size = (WIDTH, HEIGHT); 76 | 77 | let event_loop = EventLoop::new(); 78 | 79 | let wb = glutin::window::WindowBuilder::new() 80 | .with_title("OpenGL 3D with Reclutch") 81 | .with_inner_size(glutin::dpi::PhysicalSize::new(window_size.0 as f64, window_size.1 as f64)) 82 | .with_resizable(false); 83 | 84 | let cb = glutin::ContextBuilder::new().with_vsync(true).with_srgb(true); 85 | 86 | let gl_display = glium::Display::new(wb, cb, &event_loop).unwrap(); 87 | 88 | let quad_vertex_buffer = glium::VertexBuffer::new(&gl_display, &QUAD_VERTICES).unwrap(); 89 | let quad_indices = glium::IndexBuffer::new( 90 | &gl_display, 91 | glium::index::PrimitiveType::TrianglesList, 92 | &QUAD_INDICES, 93 | ) 94 | .unwrap(); 95 | 96 | let quad_vertex_shader_src = r#" 97 | #version 140 98 | 99 | in vec3 position; 100 | in vec2 tex_coord; 101 | 102 | out vec2 frag_tex_coord; 103 | 104 | void main() { 105 | frag_tex_coord = tex_coord; 106 | gl_Position = vec4(position, 1.0); 107 | } 108 | "#; 109 | 110 | let quad_fragment_shader_src = r#" 111 | #version 150 112 | 113 | in vec2 frag_tex_coord; 114 | out vec4 color; 115 | 116 | uniform sampler2D tex; 117 | 118 | void main() { 119 | color = texture(tex, frag_tex_coord); 120 | } 121 | "#; 122 | 123 | let quad_program = glium::Program::from_source( 124 | &gl_display, 125 | quad_vertex_shader_src, 126 | quad_fragment_shader_src, 127 | None, 128 | ) 129 | .unwrap(); 130 | 131 | let out_texture = glium::texture::SrgbTexture2d::empty_with_format( 132 | &gl_display, 133 | glium::texture::SrgbFormat::U8U8U8U8, 134 | glium::texture::MipmapsOption::NoMipmap, 135 | window_size.0, 136 | window_size.1, 137 | ) 138 | .unwrap(); 139 | let out_texture_depth = 140 | glium::texture::DepthTexture2d::empty(&gl_display, window_size.0, window_size.1).unwrap(); 141 | 142 | let mut skia_context = Some(unsafe { 143 | glutin::ContextBuilder::new() 144 | .with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 3))) 145 | .with_shared_lists(&gl_display.gl_window()) 146 | .with_srgb(true) 147 | .build_headless( 148 | &event_loop, 149 | glutin::dpi::PhysicalSize::new(window_size.0 as _, window_size.1 as _), 150 | ) 151 | .unwrap() 152 | .make_current() 153 | .unwrap() 154 | }); 155 | 156 | 157 | let mut display = 158 | reclutch_skia::SkiaGraphicsDisplay::new_gl_texture(&reclutch_skia::SkiaOpenGlTexture { 159 | size: (window_size.0 as _, window_size.1 as _), 160 | texture_id: out_texture.get_id(), 161 | mip_mapped: false, 162 | }) 163 | .unwrap(); 164 | 165 | let mut last_frame = Instant::now(); 166 | 167 | let mut imgui = ImguiContext::create(); 168 | let mut platform = WinitPlatform::init(&mut imgui); 169 | imgui.set_ini_filename(None); 170 | imgui.io_mut().display_size = [window_size.0 as f32, window_size.1 as f32]; 171 | let mut renderer = ImguiRenderer::init(&mut imgui, &gl_display).expect("Failed to initialize renderer"); 172 | 173 | event_loop.run(move |event, _, control_flow| { 174 | *control_flow = ControlFlow::WaitUntil( 175 | std::time::Instant::now() + std::time::Duration::from_nanos(16_666_667), 176 | ); 177 | 178 | platform.handle_event(imgui.io_mut(), &gl_display.gl_window().window(), &event); 179 | 180 | match event { 181 | Event::RedrawRequested { .. } => { 182 | let mut out_texture_fb = glium::framebuffer::SimpleFrameBuffer::with_depth_buffer( 183 | &gl_display, 184 | &out_texture, 185 | &out_texture_depth, 186 | ) 187 | .unwrap(); 188 | 189 | let mut frame_target = gl_display.draw(); 190 | let target = &mut out_texture_fb; 191 | 192 | target.clear_color_and_depth((1.0, 1.0, 1.0, 1.0), 1.0); 193 | 194 | skia_context = 195 | Some(unsafe { skia_context.take().unwrap().make_current().unwrap() }); 196 | 197 | render_skia(&mut display); 198 | render_imgui_frame(target, &mut imgui, &mut last_frame, &mut renderer); 199 | frame_target 200 | .draw( 201 | &quad_vertex_buffer, 202 | &quad_indices, 203 | &quad_program, 204 | &uniform! { tex: &out_texture }, 205 | &Default::default(), 206 | ) 207 | .unwrap(); 208 | frame_target.finish().unwrap(); 209 | }, 210 | Event::MainEventsCleared => { 211 | gl_display.gl_window().window().request_redraw(); 212 | }, 213 | Event::WindowEvent { event: WindowEvent::KeyboardInput { input: KeyboardInput { virtual_keycode: Some(VirtualKeyCode::Escape), .. }, .. }, ..} | Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { 214 | *control_flow = ControlFlow::Exit; 215 | }, 216 | _ => return, 217 | } 218 | }); 219 | } 220 | 221 | fn render_imgui_frame(target: &mut glium::framebuffer::SimpleFrameBuffer, imgui: &mut imgui::Context, last_frame: &mut Instant, renderer: &mut ImguiRenderer) { 222 | let io = imgui.io_mut(); 223 | 224 | *last_frame = io.update_delta_time(*last_frame); 225 | let mut ui = imgui.frame(); 226 | run_ui(&mut ui); 227 | 228 | let draw_data = ui.render(); 229 | renderer.render(target, draw_data).expect("Rendering failed"); 230 | } 231 | 232 | fn render_skia(display: &mut reclutch_skia::SkiaGraphicsDisplay) { 233 | let mut surface = &mut display.surface; 234 | let canvas = surface.canvas(); 235 | let center = (HEIGHT as f32 / 4., WIDTH as f32 / 4.); 236 | 237 | let mut path = skia::Path::new(); 238 | let mut paint = skia::Paint::default(); 239 | paint.set_anti_alias(true); 240 | paint.set_style(skia::PaintStyle::StrokeAndFill); 241 | // Face 242 | paint.set_color(0x55_ffff00); 243 | path.add_circle(center, center.0, None); 244 | canvas.draw_path(&path, &paint); 245 | path = skia::Path::new(); 246 | // Eyes 247 | paint.set_color(0x55_000000); 248 | let left_eye = (center.0 - (center.0 / 2.), center.1 - (center.1 / 3.)); 249 | path.add_circle(left_eye, center.0 / 10., None); 250 | let right_eye = (center.0 + (center.0 / 2.), center.1 - (center.1 / 3.)); 251 | path.add_circle(right_eye, center.0 / 10., None); 252 | canvas.draw_path(&path, &paint); 253 | 254 | let blur = skia::image_filters::blur( 255 | (4., 4.), 256 | skia::TileMode::Clamp, 257 | None, 258 | None 259 | ).unwrap(); 260 | let count = canvas.save(); 261 | canvas.save_layer(&skia::canvas::SaveLayerRec::default().backdrop(&blur)); 262 | 263 | path = skia::Path::new(); 264 | path.move_to((0. + (center.0 / 10.), center.1)); 265 | path.cubic_to((0. + (center.0 / 10.), center.1 + (center.1 / 2.)), (WIDTH as f32 / 2. - (center.0 / 10.), center.1 + (center.1 / 2.)), (WIDTH as f32 / 2. - (center.0 / 10.), center.1)); 266 | paint.set_color(0xff_000000); 267 | paint.set_style(skia::PaintStyle::Stroke); 268 | canvas.draw_path(&path, &paint); 269 | 270 | canvas.restore_to_count(count); 271 | 272 | display.surface.flush_and_submit(); 273 | } 274 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | --------------------------------------------------------------------------------