<commit_before>//! Render to an SDL window

use ppu::{SCREEN_WIDTH, SCREEN_HEIGHT};

use sdl2::Sdl;
use sdl2::pixels::PixelFormatEnum;
use sdl2::render::{Renderer, Texture, TextureAccess};

pub struct SdlRenderer {
    renderer: Renderer<'static>,
    texture: Texture,
    sdl: Sdl,
}

impl SdlRenderer {
    /// Creates a new SDL renderer. This also creates a window.
    pub fn new(sdl: &Sdl) -> SdlRenderer {
        info!("initializing SDL renderer");

        // FIXME: Support linear filtering and nearest neighbor

        let video = sdl.video().unwrap();
        let window = video.window("sneeze", SCREEN_WIDTH as u32 * 3, SCREEN_HEIGHT as u32 * 3)
            .build().unwrap();
        let renderer = window.renderer().accelerated().build().unwrap();
        debug!("renderer: {:?}", renderer.info());
        let texture = renderer.create_texture(
            PixelFormatEnum::RGB24,
            TextureAccess::Static,
            (SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32)).unwrap();

        SdlRenderer {
            renderer: renderer,
            texture: texture,
            sdl: sdl.clone(),
        }
    }
}

impl super::Renderer for SdlRenderer {
    fn render(&mut self, frame_data: &[u8]) {
        self.texture.update(None, frame_data, SCREEN_WIDTH as usize * 3).unwrap();
        self.renderer.clear();<commit_msg>Actually...<commit_after>//! Render to an SDL window

use ppu::{SCREEN_WIDTH, SCREEN_HEIGHT};

use sdl2::Sdl;
use sdl2::pixels::PixelFormatEnum;
use sdl2::render::{Renderer, Texture, TextureAccess};

pub struct SdlRenderer {
    renderer: Renderer<'static>,
    texture: Texture,
    sdl: Sdl,
}

impl SdlRenderer {
    /// Creates a new SDL renderer. This also creates a window.
    pub fn new(sdl: &Sdl) -> SdlRenderer {
        info!("initializing SDL renderer");

        // FIXME: Support linear filtering and nearest neighbor

        let video = sdl.video().unwrap();
        let window = video.window("sneeze", SCREEN_WIDTH as u32 * 3, SCREEN_HEIGHT as u32 * 3)
            .build().unwrap();
        let renderer = window.renderer().accelerated().build().unwrap();
        debug!("renderer: {:?}", renderer.info());
        let texture = renderer.create_texture(
            PixelFormatEnum::RGB24,
            TextureAccess::Static,
            (SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32)).unwrap();

        SdlRenderer {
            renderer: renderer,
            texture: texture,
            sdl: sdl.clone(),
        }
    }
}

impl super::Renderer for SdlRenderer {
    fn render(&mut self, frame_data: &[u8]) {
        // FIXME Can this be done with fewer copies?
        self.texture.update(None, frame_data, SCREEN_WIDTH as usize * 3).unwrap();
        self.renderer.clear();
{'fraction_non_alphanumeric': 0.12924424972617743, 'fraction_numerical': 0.012413289521723256, 'mean_word_length': 2.658210947930574, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1833345', 'n_tokens_mistral': 871, 'n_tokens_neox': 860, 'n_words': 221}