<commit_before>#include "swc.h"
#include "compositor.h"
#include "compositor_surface.h"
#include "cursor_surface.h"
#include "data_device_manager.h"
#include "internal.h"
#include "output.h"
#include "pointer.h"
#include "region.h"
#include "seat.h"
#include "surface.h"
#include "util.h"

#include <stdlib.h>
#include <stdio.h>
#include <xkbcommon/xkbcommon-keysyms.h>

static const char default_seat[] = "seat0";

static void calculate_damage(struct swc_compositor * compositor)
{
    struct swc_surface * surface;
    struct swc_compositor_surface_state * state;
    pixman_region32_t surface_opaque;

    pixman_region32_clear(&compositor->opaque);
    pixman_region32_init(&surface_opaque);

    /* Go through surfaces top-down to calculate clipping regions. */
    wl_list_for_each(surface, &compositor->surfaces, link)
    {
        state = surface->class_state;

        /* Clip the surface by the opaque region covering it. */
        pixman_region32_copy(&state->clip, &compositor->opaque);

        /* Translate the opaque region to global coordinates. */
        pixman_region32_copy(&surface_opaque, &surface->state.opaque);
        pixman_region32_translate(&surface_opaque, surface->geometry.x,
                                  surface->geometry.y);

        /* Add the surface's opaque region to the accumulated opaque
         * region. */
        pixman_region32_union(&compositor->opaque, &compositor->opaque,
                              &surface_opaque);

        if (pixman_region32_not_empty(&surface->state.damage))
        {
            swc_renderer_flush(&compositor->renderer, surface);

            /* Translate surface damage to global coordinates. */
            pixman_region32_translate(&surface->state.damage,
                                      surface->geometry.x,
                                      surface->geometry.y);

            /* Add the surface damage to the compositor damage. */
            pixman_region32_union(&compositor->damage, &compositor->damage,
                                  &surface->state.damage);
            pixman_region32_clear(&surface->state.damage);
        }

        if (state->border.damaged)
        {
            pixman_region32_t border_region, surface_region;

            pixman_region32_init_with_extents(&border_region, &state->extents);
            pixman_region32_init_rect
                (&surface_region, surface->geometry.x, surface->geometry.y,
                 surface->geometry.width, surface->geometry.height);

            pixman_region32_subtract(&border_region, &border_region,
                                     &surface_region);

            pixman_region32_union(&compositor->damage, &compositor->damage,
                                  &border_region);

            pixman_region32_fini(&border_region);
            pixman_region32_fini(&surface_region);

            state->border.damaged = false;
        }
    }

    pixman_region32_fini(&surface_opaque);
}

static void repaint_output(struct swc_compositor * compositor,
                           struct swc_output * output,
                           pixman_region32_t * damage)
{
    pixman_region32_t base_damage;

    pixman_region32_init(&base_damage);
    pixman_region32_subtract(&base_damage, damage, &compositor->opaque);

    swc_renderer_set_target(&compositor->renderer, &output->framebuffer_plane);
    swc_renderer_repaint(&compositor->renderer, damage, &base_damage,
                         &compositor->surfaces);

    pixman_region32_fini(&base_damage);

    if (!swc_plane_flip(&output->framebuffer_plane))
        fprintf(stderr, "Plane flip failed\n");
}

static void update_output_damage(struct swc_output * output,
                                 pixman_region32_t * damage)
{
    pixman_region32_union
        (&output->current_damage, &output->current_damage, damage);
    pixman_region32_intersect_rect
        (&output->current_damage, &output->current_damage,
         output->geometry.x, output->geometry.y,
         output->geometry.width, output->geometry.height);
}

static void flush_output_damage(struct swc_output * output,
                                pixman_region32_t * damage)
{
    /* The total damage is composed of the damage from the new frame, and the
     * damage from the last frame. */
    pixman_region32_union(damage,
                          &output->current_damage, &output->previous_damage);

    /* We must save the damage from the previous frame because the back buffer
     * is also damaged in this region. */
    pixman_region32_copy(&output->previous_damage, &output->current_damage);
    pixman_region32_clear(&output->current_damage);
}

static void perform_update(void * data)
{
    struct swc_compositor * compositor = data;
    struct swc_output * output;
    uint32_t updates = compositor->scheduled_updates
                       & ~compositor->pending_flips;

    if (updates)
    {
        pixman_region32_t damage;

        printf("performing update\n");
        calculate_damage(compositor);
        pixman_region32_init(&damage);

        wl_list_for_each(output, &compositor->outputs, link)
        {
            if (compositor->scheduled_updates & SWC_OUTPUT_MASK(output))
            {
                update_output_damage(output, &compositor->damage);

                if (!(compositor->pending_flips & SWC_OUTPUT_MASK(output)))
                {
                    flush_output_damage(output, &damage);
                    repaint_output(compositor, output, &damage);
                }
            }
        }

        pixman_region32_fini(&damage);
        /* XXX: Should assert that all damage was covered by some output */
        pixman_region32_clear(&compositor->damage);
        compositor->pending_flips |= updates;
        compositor->scheduled_updates &= ~updates;
    }

}

static void handle_focus(struct swc_pointer * pointer)
{<commit_msg>Style<commit_after>#include "swc.h"
#include "compositor.h"
#include "compositor_surface.h"
#include "cursor_surface.h"
#include "data_device_manager.h"
#include "internal.h"
#include "output.h"
#include "pointer.h"
#include "region.h"
#include "seat.h"
#include "surface.h"
#include "util.h"

#include <stdlib.h>
#include <stdio.h>
#include <xkbcommon/xkbcommon-keysyms.h>

static const char default_seat[] = "seat0";

static void calculate_damage(struct swc_compositor * compositor)
{
    struct swc_surface * surface;
    struct swc_compositor_surface_state * state;
    pixman_region32_t surface_opaque;

    pixman_region32_clear(&compositor->opaque);
    pixman_region32_init(&surface_opaque);

    /* Go through surfaces top-down to calculate clipping regions. */
    wl_list_for_each(surface, &compositor->surfaces, link)
    {
        state = surface->class_state;

        /* Clip the surface by the opaque region covering it. */
        pixman_region32_copy(&state->clip, &compositor->opaque);

        /* Translate the opaque region to global coordinates. */
        pixman_region32_copy(&surface_opaque, &surface->state.opaque);
        pixman_region32_translate(&surface_opaque, surface->geometry.x,
                                  surface->geometry.y);

        /* Add the surface's opaque region to the accumulated opaque
         * region. */
        pixman_region32_union(&compositor->opaque, &compositor->opaque,
                              &surface_opaque);

        if (pixman_region32_not_empty(&surface->state.damage))
        {
            swc_renderer_flush(&compositor->renderer, surface);

            /* Translate surface damage to global coordinates. */
            pixman_region32_translate(&surface->state.damage,
                                      surface->geometry.x,
                                      surface->geometry.y);

            /* Add the surface damage to the compositor damage. */
            pixman_region32_union(&compositor->damage, &compositor->damage,
                                  &surface->state.damage);
            pixman_region32_clear(&surface->state.damage);
        }

        if (state->border.damaged)
        {
            pixman_region32_t border_region, surface_region;

            pixman_region32_init_with_extents(&border_region, &state->extents);
            pixman_region32_init_rect
                (&surface_region, surface->geometry.x, surface->geometry.y,
                 surface->geometry.width, surface->geometry.height);

            pixman_region32_subtract(&border_region, &border_region,
                                     &surface_region);

            pixman_region32_union(&compositor->damage, &compositor->damage,
                                  &border_region);

            pixman_region32_fini(&border_region);
            pixman_region32_fini(&surface_region);

            state->border.damaged = false;
        }
    }

    pixman_region32_fini(&surface_opaque);
}

static void repaint_output(struct swc_compositor * compositor,
                           struct swc_output * output,
                           pixman_region32_t * damage)
{
    pixman_region32_t base_damage;

    pixman_region32_init(&base_damage);
    pixman_region32_subtract(&base_damage, damage, &compositor->opaque);

    swc_renderer_set_target(&compositor->renderer, &output->framebuffer_plane);
    swc_renderer_repaint(&compositor->renderer, damage, &base_damage,
                         &compositor->surfaces);

    pixman_region32_fini(&base_damage);

    if (!swc_plane_flip(&output->framebuffer_plane))
        fprintf(stderr, "Plane flip failed\n");
}

static void update_output_damage(struct swc_output * output,
                                 pixman_region32_t * damage)
{
    pixman_region32_union
        (&output->current_damage, &output->current_damage, damage);
    pixman_region32_intersect_rect
        (&output->current_damage, &output->current_damage,
         output->geometry.x, output->geometry.y,
         output->geometry.width, output->geometry.height);
}

static void flush_output_damage(struct swc_output * output,
                                pixman_region32_t * damage)
{
    /* The total damage is composed of the damage from the new frame, and the
     * damage from the last frame. */
    pixman_region32_union(damage,
                          &output->current_damage, &output->previous_damage);

    /* We must save the damage from the previous frame because the back buffer
     * is also damaged in this region. */
    pixman_region32_copy(&output->previous_damage, &output->current_damage);
    pixman_region32_clear(&output->current_damage);
}

static void perform_update(void * data)
{
    struct swc_compositor * compositor = data;
    struct swc_output * output;
    pixman_region32_t damage;
    uint32_t updates = compositor->scheduled_updates
                     & ~compositor->pending_flips;

    if (!updates)
        return;

    DEBUG("Performing update\n");

    calculate_damage(compositor);
    pixman_region32_init(&damage);

    wl_list_for_each(output, &compositor->outputs, link)
    {
        if (!(compositor->scheduled_updates & SWC_OUTPUT_MASK(output)))
            continue;

        update_output_damage(output, &compositor->damage);

        /* Don't repaint the output if it is waiting for a page flip. */
        if (compositor->pending_flips & SWC_OUTPUT_MASK(output))
            continue;

        flush_output_damage(output, &damage);
        repaint_output(compositor, output, &damage);
    }

    pixman_region32_fini(&damage);
    /* XXX: Should assert that all damage was covered by some output */
    pixman_region32_clear(&compositor->damage);
    compositor->pending_flips |= updates;
    compositor->scheduled_updates &= ~updates;
}

static void handle_focus(struct swc_pointer * pointer)
{
{'fraction_non_alphanumeric': 0.09871500297846991, 'fraction_numerical': 0.012424474512807421, 'mean_word_length': 2.5644525326053986, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '614970', 'n_tokens_mistral': 3669, 'n_tokens_neox': 3440, 'n_words': 629}