<commit_before>// LAF OS Library
// Copyright (C) 2012-2018  <NAME>
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "os/skia/skia_display.h"

#include "os/event.h"
#include "os/event_queue.h"
#include "os/skia/skia_surface.h"
#include "os/system.h"

namespace os {

SkiaDisplay::SkiaDisplay(int width, int height, int scale)
  : m_initialized(false)
  , m_window(instance()->eventQueue(), this, width, height, scale)
  , m_surface(new SkiaSurface)
  , m_customSurface(false)
  , m_nativeCursor(kArrowCursor)
{
  m_window.setScale(scale);
  m_window.setVisible(true);

  resetSkiaSurface();

  m_initialized = true;
}

void SkiaDisplay::setSkiaSurface(SkiaSurface* surface)
{
  m_surface->dispose();
  m_surface = surface;
  m_customSurface = true;
}

void SkiaDisplay::resetSkiaSurface()
{
  if (m_surface) {
    m_surface->dispose();
    m_surface = nullptr;
  }

  gfx::Size size = m_window.clientSize() / m_window.scale();
  m_surface = new SkiaSurface;
  m_surface->create(size.w, size.h);
  m_customSurface = false;
}

void SkiaDisplay::resize(const gfx::Size& size)
{
  if (!m_initialized || m_customSurface)
    return;

  gfx::Size newSize(size.w / m_window.scale(),
                    size.h / m_window.scale());

  if (m_initialized && m_surface &&
      m_surface->width() == newSize.w &&
      m_surface->height() == newSize.h) {
    return;
  }

  m_surface->dispose();
  m_surface = new SkiaSurface;
  m_surface->create(newSize.w, newSize.h);

#if !defined(__APPLE__)
  Event ev;
  ev.setType(Event::ResizeDisplay);
  ev.setDisplay(this);
#endif
}

void SkiaDisplay::dispose()
{
  delete this;
}

int SkiaDisplay::width() const
{
  return m_window.clientSize().w;
}

int SkiaDisplay::height() const
{
  return m_window.clientSize().h;
}<commit_msg>Add missing queue_event() for ResizeDisplay (regression introduced in 30481c99dcd37a1abf2f098c49a3822f4c5c6153)<commit_after>// LAF OS Library
// Copyright (C) 2012-2018  <NAME>
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "os/skia/skia_display.h"

#include "os/event.h"
#include "os/event_queue.h"
#include "os/skia/skia_surface.h"
#include "os/system.h"

namespace os {

SkiaDisplay::SkiaDisplay(int width, int height, int scale)
  : m_initialized(false)
  , m_window(instance()->eventQueue(), this, width, height, scale)
  , m_surface(new SkiaSurface)
  , m_customSurface(false)
  , m_nativeCursor(kArrowCursor)
{
  m_window.setScale(scale);
  m_window.setVisible(true);

  resetSkiaSurface();

  m_initialized = true;
}

void SkiaDisplay::setSkiaSurface(SkiaSurface* surface)
{
  m_surface->dispose();
  m_surface = surface;
  m_customSurface = true;
}

void SkiaDisplay::resetSkiaSurface()
{
  if (m_surface) {
    m_surface->dispose();
    m_surface = nullptr;
  }

  gfx::Size size = m_window.clientSize() / m_window.scale();
  m_surface = new SkiaSurface;
  m_surface->create(size.w, size.h);
  m_customSurface = false;
}

void SkiaDisplay::resize(const gfx::Size& size)
{
  if (!m_initialized || m_customSurface)
    return;

  gfx::Size newSize(size.w / m_window.scale(),
                    size.h / m_window.scale());

  if (m_initialized && m_surface &&
      m_surface->width() == newSize.w &&
      m_surface->height() == newSize.h) {
    return;
  }

  m_surface->dispose();
  m_surface = new SkiaSurface;
  m_surface->create(newSize.w, newSize.h);

#if !defined(__APPLE__)
  Event ev;
  ev.setType(Event::ResizeDisplay);
  ev.setDisplay(this);
  os::queue_event(ev);
#endif
}

void SkiaDisplay::dispose()
{
  delete this;
}

int SkiaDisplay::width() const
{
  return m_window.clientSize().w;
}

int SkiaDisplay::height() const
{
  return m_window.clientSize().h;
}
{'fraction_non_alphanumeric': 0.14300438031435198, 'fraction_numerical': 0.010821953104869879, 'mean_word_length': 4.2037533512064345, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4519675', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1425, 'n_words': 281}