<commit_before>#include <stdlib.h>
#include <limits.h>
#include <wayland-server.h>
#include <chck/string/string.h>
#include <chck/math/math.h>
#include <chck/overflow/overflow.h>
#include "internal.h"
#include "visibility.h"
#include "macros.h"
#include "output.h"
#include "view.h"
#include "resources/types/surface.h"

// FIXME: this is a hack
static EGLNativeDisplayType INVALID_DISPLAY = (EGLNativeDisplayType)~0;

bool
wlc_output_information_add_mode(struct wlc_output_information *info, struct wlc_output_mode *mode)
{
   assert(info && mode);
   return chck_iter_pool_push_back(&info->modes, mode);
}

bool
wlc_output_information(struct wlc_output_information *info)
{
   assert(info);
   memset(info, 0, sizeof(struct wlc_output_information));
   return chck_iter_pool(&info->modes, 1, 0, sizeof(struct wlc_output_mode));
}

void
wlc_output_information_release(struct wlc_output_information *info)
{
   if (!info)
      return;

   chck_iter_pool_release(&info->modes);
   chck_string_release(&info->make);
   chck_string_release(&info->model);
}

static void
wl_output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
   struct wlc_output *output = data;
   assert(output);

   wlc_resource r;
   if (!(r = wlc_resource_create(&output->resources, client, &wl_output_interface, version, 2, id)))
      return;

   wlc_resource_implement(r, NULL, (void*)convert_to_wlc_handle(output));

   struct wl_resource *resource;
   if (!(resource = wl_resource_from_wlc_resource(r, "output")))
      return;

   // FIXME: update on wlc_output_set_information
   wl_output_send_geometry(resource, output->information.x, output->information.y,
       output->information.physical_width, output->information.physical_height, output->information.subpixel,
       (output->information.make.data ? output->information.make.data : "unknown"),
       (output->information.model.data ? output->information.model.data : "model"),
       output->information.transform);

   assert(output->information.scale > 0);
   if (version >= WL_OUTPUT_SCALE_SINCE_VERSION)
      wl_output_send_scale(resource, output->information.scale);

   output->active.mode = UINT_MAX;
   struct wlc_output_mode *mode;
   chck_iter_pool_for_each(&output->information.modes, mode) {
      wl_output_send_mode(resource, mode->flags, mode->width, mode->height, mode->refresh);

      if (mode->flags & WL_OUTPUT_MODE_CURRENT || (output->active.mode == UINT_MAX && (mode->flags & WL_OUTPUT_MODE_PREFERRED)))
         output->active.mode = _I - 1;
   }

   assert(output->active.mode != UINT_MAX && "output should have at least one current mode!");

   if (version >= WL_OUTPUT_DONE_SINCE_VERSION)
      wl_output_send_done(resource);

   return;
}

static bool
view_visible(struct wlc_view *view, struct wlc_surface *surface, uint32_t mask)
{
   if (!view || !surface)
      return false;

   return (surface->commit.attached && (view->mask & mask));
}

static bool
is_visible(struct wlc_output *output)
{
   assert(output);
   struct wlc_geometry g = { { INT_MAX, INT_MAX }, { 0, 0 } }, root = { { 0, 0 }, output->resolution };

   wlc_handle *h;
   chck_iter_pool_for_each(&output->views, h) {
      struct wlc_view *v;
      struct wlc_surface *s;
      if (!(v = convert_from_wlc_handle(*h, "view")) ||
          !(s = convert_from_wlc_resource(v->surface, "surface")))
         continue;

      if (!view_visible(v, s, output->active.mask))
         continue;

      struct wlc_geometry vg;
      wlc_view_get_opaque(v, &vg);

      struct wlc_size size = {
         vg.origin.x + vg.size.w,
         vg.origin.y + vg.size.h
      };

      wlc_origin_min(&g.origin, &vg.origin, &g.origin);
      wlc_size_max(&g.size, &size, &g.size);
   }

   return !wlc_geometry_contains(&g, &root);
}

static bool
view_contains_output(struct wlc_view *view, struct wlc_output *output)
{
   assert(view && output);

   if (!view_visible(view, convert_from_wlc_resource(view->surface, "surface"), output->active.mask))
      return false;

   struct wlc_geometry vg, root = { { 0, 0 }, output->resolution };
   wlc_view_get_opaque(view, &vg);
   return wlc_geometry_contains(&vg, &root);
}

static void
finish_frame_tasks(struct wlc_output *output)<commit_msg>NULL view argument is valid to contains_output<commit_after>#include <stdlib.h>
#include <limits.h>
#include <wayland-server.h>
#include <chck/string/string.h>
#include <chck/math/math.h>
#include <chck/overflow/overflow.h>
#include "internal.h"
#include "visibility.h"
#include "macros.h"
#include "output.h"
#include "view.h"
#include "resources/types/surface.h"

// FIXME: this is a hack
static EGLNativeDisplayType INVALID_DISPLAY = (EGLNativeDisplayType)~0;

bool
wlc_output_information_add_mode(struct wlc_output_information *info, struct wlc_output_mode *mode)
{
   assert(info && mode);
   return chck_iter_pool_push_back(&info->modes, mode);
}

bool
wlc_output_information(struct wlc_output_information *info)
{
   assert(info);
   memset(info, 0, sizeof(struct wlc_output_information));
   return chck_iter_pool(&info->modes, 1, 0, sizeof(struct wlc_output_mode));
}

void
wlc_output_information_release(struct wlc_output_information *info)
{
   if (!info)
      return;

   chck_iter_pool_release(&info->modes);
   chck_string_release(&info->make);
   chck_string_release(&info->model);
}

static void
wl_output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
   struct wlc_output *output = data;
   assert(output);

   wlc_resource r;
   if (!(r = wlc_resource_create(&output->resources, client, &wl_output_interface, version, 2, id)))
      return;

   wlc_resource_implement(r, NULL, (void*)convert_to_wlc_handle(output));

   struct wl_resource *resource;
   if (!(resource = wl_resource_from_wlc_resource(r, "output")))
      return;

   // FIXME: update on wlc_output_set_information
   wl_output_send_geometry(resource, output->information.x, output->information.y,
       output->information.physical_width, output->information.physical_height, output->information.subpixel,
       (output->information.make.data ? output->information.make.data : "unknown"),
       (output->information.model.data ? output->information.model.data : "model"),
       output->information.transform);

   assert(output->information.scale > 0);
   if (version >= WL_OUTPUT_SCALE_SINCE_VERSION)
      wl_output_send_scale(resource, output->information.scale);

   output->active.mode = UINT_MAX;
   struct wlc_output_mode *mode;
   chck_iter_pool_for_each(&output->information.modes, mode) {
      wl_output_send_mode(resource, mode->flags, mode->width, mode->height, mode->refresh);

      if (mode->flags & WL_OUTPUT_MODE_CURRENT || (output->active.mode == UINT_MAX && (mode->flags & WL_OUTPUT_MODE_PREFERRED)))
         output->active.mode = _I - 1;
   }

   assert(output->active.mode != UINT_MAX && "output should have at least one current mode!");

   if (version >= WL_OUTPUT_DONE_SINCE_VERSION)
      wl_output_send_done(resource);

   return;
}

static bool
view_visible(struct wlc_view *view, struct wlc_surface *surface, uint32_t mask)
{
   if (!view || !surface)
      return false;

   return (surface->commit.attached && (view->mask & mask));
}

static bool
is_visible(struct wlc_output *output)
{
   assert(output);
   struct wlc_geometry g = { { INT_MAX, INT_MAX }, { 0, 0 } }, root = { { 0, 0 }, output->resolution };

   wlc_handle *h;
   chck_iter_pool_for_each(&output->views, h) {
      struct wlc_view *v;
      struct wlc_surface *s;
      if (!(v = convert_from_wlc_handle(*h, "view")) ||
          !(s = convert_from_wlc_resource(v->surface, "surface")))
         continue;

      if (!view_visible(v, s, output->active.mask))
         continue;

      struct wlc_geometry vg;
      wlc_view_get_opaque(v, &vg);

      struct wlc_size size = {
         vg.origin.x + vg.size.w,
         vg.origin.y + vg.size.h
      };

      wlc_origin_min(&g.origin, &vg.origin, &g.origin);
      wlc_size_max(&g.size, &size, &g.size);
   }

   return !wlc_geometry_contains(&g, &root);
}

static bool
view_contains_output(struct wlc_view *view, struct wlc_output *output)
{
   assert(output);

   if (!view_visible(view, convert_from_wlc_resource(view->surface, "surface"), output->active.mask))
      return false;

   struct wlc_geometry vg, root = { { 0, 0 }, output->resolution };
   wlc_view_get_opaque(view, &vg);
   return wlc_geometry_contains(&vg, &root);
}

static void
finish_frame_tasks(struct wlc_output *output)
{'fraction_non_alphanumeric': 0.1331608046112222, 'fraction_numerical': 0.004470062345606399, 'mean_word_length': 4.297196261682243, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 97, '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': '2191634', 'n_tokens_mistral': 2991, 'n_tokens_neox': 2877, 'n_words': 570}