mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Format component compositing #21373
This commit is contained in:
parent
1ee3deea27
commit
e4cd04399e
5 changed files with 363 additions and 255 deletions
|
@ -2,12 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
use gleam::gl;
|
||||
use image::RgbImage;
|
||||
use servo_geometry::DeviceUintLength;
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RenderTargetInfo {
|
||||
framebuffer_ids: Vec<gl::GLuint>,
|
||||
|
@ -16,7 +14,9 @@ pub struct RenderTargetInfo {
|
|||
}
|
||||
|
||||
pub fn initialize_png(
|
||||
gl: &gl::Gl, width: DeviceUintLength, height: DeviceUintLength
|
||||
gl: &gl::Gl,
|
||||
width: DeviceUintLength,
|
||||
height: DeviceUintLength,
|
||||
) -> RenderTargetInfo {
|
||||
let framebuffer_ids = gl.gen_framebuffers(1);
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);
|
||||
|
@ -24,27 +24,53 @@ pub fn initialize_png(
|
|||
let texture_ids = gl.gen_textures(1);
|
||||
gl.bind_texture(gl::TEXTURE_2D, texture_ids[0]);
|
||||
|
||||
gl.tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as gl::GLint, width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei, 0, gl::RGB, gl::UNSIGNED_BYTE, None);
|
||||
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as gl::GLint);
|
||||
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as gl::GLint);
|
||||
gl.tex_image_2d(
|
||||
gl::TEXTURE_2D,
|
||||
0,
|
||||
gl::RGB as gl::GLint,
|
||||
width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei,
|
||||
0,
|
||||
gl::RGB,
|
||||
gl::UNSIGNED_BYTE,
|
||||
None,
|
||||
);
|
||||
gl.tex_parameter_i(
|
||||
gl::TEXTURE_2D,
|
||||
gl::TEXTURE_MAG_FILTER,
|
||||
gl::NEAREST as gl::GLint,
|
||||
);
|
||||
gl.tex_parameter_i(
|
||||
gl::TEXTURE_2D,
|
||||
gl::TEXTURE_MIN_FILTER,
|
||||
gl::NEAREST as gl::GLint,
|
||||
);
|
||||
|
||||
gl.framebuffer_texture_2d(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D,
|
||||
texture_ids[0], 0);
|
||||
gl.framebuffer_texture_2d(
|
||||
gl::FRAMEBUFFER,
|
||||
gl::COLOR_ATTACHMENT0,
|
||||
gl::TEXTURE_2D,
|
||||
texture_ids[0],
|
||||
0,
|
||||
);
|
||||
|
||||
gl.bind_texture(gl::TEXTURE_2D, 0);
|
||||
|
||||
let renderbuffer_ids = gl.gen_renderbuffers(1);
|
||||
let depth_rb = renderbuffer_ids[0];
|
||||
gl.bind_renderbuffer(gl::RENDERBUFFER, depth_rb);
|
||||
gl.renderbuffer_storage(gl::RENDERBUFFER,
|
||||
gl::DEPTH_COMPONENT24,
|
||||
width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei);
|
||||
gl.framebuffer_renderbuffer(gl::FRAMEBUFFER,
|
||||
gl::DEPTH_ATTACHMENT,
|
||||
gl::RENDERBUFFER,
|
||||
depth_rb);
|
||||
gl.renderbuffer_storage(
|
||||
gl::RENDERBUFFER,
|
||||
gl::DEPTH_COMPONENT24,
|
||||
width.get() as gl::GLsizei,
|
||||
height.get() as gl::GLsizei,
|
||||
);
|
||||
gl.framebuffer_renderbuffer(
|
||||
gl::FRAMEBUFFER,
|
||||
gl::DEPTH_ATTACHMENT,
|
||||
gl::RENDERBUFFER,
|
||||
depth_rb,
|
||||
);
|
||||
|
||||
RenderTargetInfo {
|
||||
framebuffer_ids,
|
||||
|
@ -70,10 +96,12 @@ pub fn draw_img(
|
|||
gl.bind_vertex_array(0);
|
||||
|
||||
let mut pixels = gl.read_pixels(
|
||||
0, 0,
|
||||
0,
|
||||
0,
|
||||
width as gl::GLsizei,
|
||||
height as gl::GLsizei,
|
||||
gl::RGB, gl::UNSIGNED_BYTE,
|
||||
gl::RGB,
|
||||
gl::UNSIGNED_BYTE,
|
||||
);
|
||||
|
||||
gl.bind_framebuffer(gl::FRAMEBUFFER, 0);
|
||||
|
@ -88,10 +116,9 @@ pub fn draw_img(
|
|||
for y in 0..height {
|
||||
let dst_start = y * stride;
|
||||
let src_start = (height - y - 1) * stride;
|
||||
let src_slice = &orig_pixels[src_start .. src_start + stride];
|
||||
(&mut pixels[dst_start .. dst_start + stride]).clone_from_slice(&src_slice[..stride]);
|
||||
let src_slice = &orig_pixels[src_start..src_start + stride];
|
||||
(&mut pixels[dst_start..dst_start + stride]).clone_from_slice(&src_slice[..stride]);
|
||||
}
|
||||
|
||||
RgbImage::from_raw(width as u32, height as u32, pixels)
|
||||
.expect("Flipping image failed!")
|
||||
RgbImage::from_raw(width as u32, height as u32, pixels).expect("Flipping image failed!")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue