<commit_before>// Copyright 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ozone/wayland/dispatcher.h"
#include "ozone/impl/ozone_display.h"

#include "ozone/impl/desktop_screen_wayland.h"
#include "ozone/impl/event_factory_wayland.h"
#include "ozone/wayland/display.h"
#include "ozone/wayland/dispatcher.h"
#include "ozone/wayland/screen.h"
#include "ozone/wayland/window.h"
#include "ozone/wayland/egl/egl_window.h"

#include "ozone/impl/ipc/child_process_observer.h"
#include "ozone/impl/ipc/display_channel.h"
#include "ozone/impl/ipc/display_channel_host.h"

#include "base/native_library.h"
#include "content/child/child_process.h"

namespace ozonewayland {

OzoneDisplay* OzoneDisplay::instance_ = NULL;

OzoneDisplay* OzoneDisplay::GetInstance()
{
  return instance_;
}

OzoneDisplay::OzoneDisplay() : state_(UnInitialized),
    desktop_screen_(NULL),
    dispatcher_(NULL),
    display_(NULL),
    child_process_observer_(NULL),
    channel_(NULL),
    host_(NULL),
    e_factory_(NULL),
    spec_(NULL),
    kMaxDisplaySize_(20)
{
  instance_ = this;
}

OzoneDisplay::~OzoneDisplay()
{
  Terminate();
  instance_ = NULL;
}

const char* OzoneDisplay::DefaultDisplaySpec() {
  if (spec_[0] == '\0')
    NOTREACHED() << "OutputHandleMode should come from Wayland compositor first";

  return spec_;
}

gfx::Screen* OzoneDisplay::CreateDesktopScreen() {
  if (!desktop_screen_) {
    desktop_screen_ = new DesktopScreenWayland;
    LookAheadOutputGeometry();
  }

  return desktop_screen_;
}

gfx::SurfaceFactoryOzone::HardwareState OzoneDisplay::InitializeHardware()
{
  if (state_ & Initialized)
    return initialized_state_;

  DCHECK(base::MessageLoop::current());
  base::MessageLoop::current()->AddDestructionObserver(this);

  state_ |= Initialized;
  display_ = new WaylandDisplay(WaylandDisplay::RegisterAsNeeded);
  initialized_state_ = display_->display() ? gfx::SurfaceFactoryOzone::INITIALIZED
                                           : gfx::SurfaceFactoryOzone::FAILED;

  if (initialized_state_ != gfx::SurfaceFactoryOzone::INITIALIZED)
    LOG(ERROR) << "OzoneDisplay failed to initialize hardware";
  else if (!content::ChildProcess::current()) {<commit_msg>Missing changes from "Fix destruction observer."<commit_after>// Copyright 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ozone/wayland/dispatcher.h"
#include "ozone/impl/ozone_display.h"

#include "ozone/impl/desktop_screen_wayland.h"
#include "ozone/impl/event_factory_wayland.h"
#include "ozone/wayland/display.h"
#include "ozone/wayland/dispatcher.h"
#include "ozone/wayland/screen.h"
#include "ozone/wayland/window.h"
#include "ozone/wayland/egl/egl_window.h"

#include "ozone/impl/ipc/child_process_observer.h"
#include "ozone/impl/ipc/display_channel.h"
#include "ozone/impl/ipc/display_channel_host.h"

#include "base/native_library.h"
#include "content/child/child_process.h"

namespace ozonewayland {

OzoneDisplay* OzoneDisplay::instance_ = NULL;

OzoneDisplay* OzoneDisplay::GetInstance()
{
  return instance_;
}

OzoneDisplay::OzoneDisplay() : state_(UnInitialized),
    desktop_screen_(NULL),
    dispatcher_(NULL),
    display_(NULL),
    child_process_observer_(NULL),
    channel_(NULL),
    host_(NULL),
    e_factory_(NULL),
    spec_(NULL),
    kMaxDisplaySize_(20)
{
  instance_ = this;
}

OzoneDisplay::~OzoneDisplay()
{
  Terminate();
  instance_ = NULL;
}

const char* OzoneDisplay::DefaultDisplaySpec() {
  if (spec_[0] == '\0')
    NOTREACHED() << "OutputHandleMode should come from Wayland compositor first";

  return spec_;
}

gfx::Screen* OzoneDisplay::CreateDesktopScreen() {
  if (!desktop_screen_) {
    desktop_screen_ = new DesktopScreenWayland;
    LookAheadOutputGeometry();
  }

  return desktop_screen_;
}

gfx::SurfaceFactoryOzone::HardwareState OzoneDisplay::InitializeHardware()
{
  if (state_ & Initialized)
    return initialized_state_;

  state_ |= Initialized;
  display_ = new WaylandDisplay(WaylandDisplay::RegisterAsNeeded);
  initialized_state_ = display_->display() ? gfx::SurfaceFactoryOzone::INITIALIZED
                                           : gfx::SurfaceFactoryOzone::FAILED;

  if (initialized_state_ != gfx::SurfaceFactoryOzone::INITIALIZED)
    LOG(ERROR) << "OzoneDisplay failed to initialize hardware";
  else if (!content::ChildProcess::current()) {
{'fraction_non_alphanumeric': 0.12483429076447194, 'fraction_numerical': 0.003535130357931949, 'mean_word_length': 5.027962716378163, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3670994', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1457, 'n_words': 277}