<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/examples/aura_demo/root_window_host_mojo.h"

#include "mojo/examples/aura_demo/demo_context_factory.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/gles2/gles2.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host_delegate.h"
#include "ui/compositor/compositor.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"

namespace mojo {
namespace examples {

// static
ui::ContextFactory* WindowTreeHostMojo::context_factory_ = NULL;

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, public:

WindowTreeHostMojo::WindowTreeHostMojo(
    ScopedMessagePipeHandle viewport_handle,
    const gfx::Rect& bounds,
    const base::Callback<void()>& compositor_created_callback)
    : native_viewport_(viewport_handle.Pass(), this),
      compositor_created_callback_(compositor_created_callback),
      bounds_(bounds) {
  AllocationScope scope;
  native_viewport_->Create(bounds);

  ScopedMessagePipeHandle gles2_client_handle;
  CreateMessagePipe(&gles2_handle_, &gles2_client_handle);

  // The ContextFactory must exist before any Compositors are created.
  if (!context_factory_) {
    scoped_ptr<DemoContextFactory> cf(new DemoContextFactory(this));
    if (cf->Initialize())
      context_factory_ = cf.release();
    ui::ContextFactory::SetInstance(context_factory_);
  }
  CHECK(context_factory_) << "No GL bindings.";

  native_viewport_->CreateGLES2Context(gles2_client_handle.Pass());
}

WindowTreeHostMojo::~WindowTreeHostMojo() {}

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, aura::WindowTreeHost implementation:

aura::RootWindow* WindowTreeHostMojo::GetRootWindow() {
  return delegate_->AsRootWindow();
}

gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() {
  NOTIMPLEMENTED() << "GetAcceleratedWidget";
  return gfx::kNullAcceleratedWidget;
}

void WindowTreeHostMojo::Show() {
  window()->Show();
  native_viewport_->Show();
}

void WindowTreeHostMojo::Hide() {
  native_viewport_->Hide();
  window()->Hide();
}

void WindowTreeHostMojo::ToggleFullScreen() {
  NOTIMPLEMENTED();
}

gfx::Rect WindowTreeHostMojo::GetBounds() const {
  return bounds_;
}

void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
  AllocationScope scope;
  native_viewport_->SetBounds(bounds);
}

gfx::Insets WindowTreeHostMojo::GetInsets() const {
  NOTIMPLEMENTED();
  return gfx::Insets();
}

void WindowTreeHostMojo::SetInsets(const gfx::Insets& insets) {
  NOTIMPLEMENTED();
}

gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
  return gfx::Point(0, 0);
}

void WindowTreeHostMojo::SetCapture() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::ReleaseCapture() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::SetCursor(gfx::NativeCursor cursor) {
  NOTIMPLEMENTED();
}

bool WindowTreeHostMojo::QueryMouseLocation(gfx::Point* location_return) {
  NOTIMPLEMENTED() << "QueryMouseLocation";
  return false;
}

bool WindowTreeHostMojo::ConfineCursorToRootWindow() {
  NOTIMPLEMENTED();
  return false;
}

void WindowTreeHostMojo::UnConfineCursor() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::OnCursorVisibilityChanged(bool show) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::MoveCursorTo(const gfx::Point& location) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::PostNativeEvent(
    const base::NativeEvent& native_event) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::OnDeviceScaleFactorChanged(float device_scale_factor) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::PrepareForShutdown() {
  NOTIMPLEMENTED();
}

ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
  return delegate_->GetEventProcessor();
}

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, NativeViewportClient implementation:

void WindowTreeHostMojo::OnCreated() {
}

void WindowTreeHostMojo::OnBoundsChanged(const Rect& bounds) {
  bounds_ = gfx::Rect(bounds.position().x(), bounds.position().y(),
                      bounds.size().width(), bounds.size().height());
  if (delegate_)
    window()->SetBounds(gfx::Rect(bounds_.size()));
  CreateCompositor(GetAcceleratedWidget());
  compositor_created_callback_.Run();
  NotifyHostResized(bounds_.size());
}<commit_msg>Fix VM/launcher with GLES changes.<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/examples/aura_demo/root_window_host_mojo.h"

#include "mojo/examples/aura_demo/demo_context_factory.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/gles2/gles2.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host_delegate.h"
#include "ui/compositor/compositor.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"

namespace mojo {
namespace examples {

// static
ui::ContextFactory* WindowTreeHostMojo::context_factory_ = NULL;

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, public:

WindowTreeHostMojo::WindowTreeHostMojo(
    ScopedMessagePipeHandle viewport_handle,
    const gfx::Rect& bounds,
    const base::Callback<void()>& compositor_created_callback)
    : native_viewport_(viewport_handle.Pass(), this),
      compositor_created_callback_(compositor_created_callback),
      bounds_(bounds) {
  AllocationScope scope;
  native_viewport_->Create(bounds);

  ScopedMessagePipeHandle gles2_client_handle;
  CreateMessagePipe(&gles2_handle_, &gles2_client_handle);

  // The ContextFactory must exist before any Compositors are created.
  if (!context_factory_) {
    scoped_ptr<DemoContextFactory> cf(new DemoContextFactory(this));
    if (cf->Initialize())
      context_factory_ = cf.release();
    ui::ContextFactory::SetInstance(context_factory_);
  }
  CHECK(context_factory_) << "No GL bindings.";

  native_viewport_->CreateGLES2Context(gles2_client_handle.Pass());
}

WindowTreeHostMojo::~WindowTreeHostMojo() {}

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, aura::WindowTreeHost implementation:

aura::RootWindow* WindowTreeHostMojo::GetRootWindow() {
  return delegate_->AsRootWindow();
}

gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() {
  NOTIMPLEMENTED() << "GetAcceleratedWidget";
  return gfx::kNullAcceleratedWidget;
}

void WindowTreeHostMojo::Show() {
  window()->Show();
  native_viewport_->Show();
}

void WindowTreeHostMojo::Hide() {
  native_viewport_->Hide();
  window()->Hide();
}

void WindowTreeHostMojo::ToggleFullScreen() {
  NOTIMPLEMENTED();
}

gfx::Rect WindowTreeHostMojo::GetBounds() const {
  return bounds_;
}

void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
  AllocationScope scope;
  native_viewport_->SetBounds(bounds);
}

gfx::Insets WindowTreeHostMojo::GetInsets() const {
  NOTIMPLEMENTED();
  return gfx::Insets();
}

void WindowTreeHostMojo::SetInsets(const gfx::Insets& insets) {
  NOTIMPLEMENTED();
}

gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
  return gfx::Point(0, 0);
}

void WindowTreeHostMojo::SetCapture() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::ReleaseCapture() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::SetCursor(gfx::NativeCursor cursor) {
  NOTIMPLEMENTED();
}

bool WindowTreeHostMojo::QueryMouseLocation(gfx::Point* location_return) {
  NOTIMPLEMENTED() << "QueryMouseLocation";
  return false;
}

bool WindowTreeHostMojo::ConfineCursorToRootWindow() {
  NOTIMPLEMENTED();
  return false;
}

void WindowTreeHostMojo::UnConfineCursor() {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::OnCursorVisibilityChanged(bool show) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::MoveCursorTo(const gfx::Point& location) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::PostNativeEvent(
    const base::NativeEvent& native_event) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::OnDeviceScaleFactorChanged(float device_scale_factor) {
  NOTIMPLEMENTED();
}

void WindowTreeHostMojo::PrepareForShutdown() {
  NOTIMPLEMENTED();
}

ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
  return delegate_->GetEventProcessor();
}

////////////////////////////////////////////////////////////////////////////////
// WindowTreeHostMojo, NativeViewportClient implementation:

void WindowTreeHostMojo::OnCreated() {
  CreateCompositor(GetAcceleratedWidget());
  compositor_created_callback_.Run();
}

void WindowTreeHostMojo::OnBoundsChanged(const Rect& bounds) {
  bounds_ = gfx::Rect(bounds.position().x(), bounds.position().y(),
                      bounds.size().width(), bounds.size().height());
  if (delegate_)
    window()->SetBounds(gfx::Rect(bounds_.size()));
  NotifyHostResized(bounds_.size());
}
{'fraction_non_alphanumeric': 0.17356162926725513, 'fraction_numerical': 0.0027650749760714665, 'mean_word_length': 4.600952948183442, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '7550974', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2945, 'n_words': 472}