flutter_flutter/shell/sky_main.cc
Adam Barth 1f8dd823f9 sky/shell should link with sky/engine
This CL causes sky/shell to create a blink::WebView to show that sky/shell
links with sky/engine. In the process, I've made it easier to be a trivial
embedder of sky/engine by removing the requirement to implement
blink::ServiceProvider.

This CL also causes sky/shell to link with mojo/edk/system to resolve link
errors with Mojo fabric (e.g., MojoClose, MojoWriteMessage, etc). To make this
work properly, we'll need to initialize the EDK in a future CL.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/873923003
2015-02-04 19:31:17 -08:00

88 lines
2.4 KiB
C++

// Copyright 2015 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 "sky/shell/sky_main.h"
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/simple_thread.h"
#include "jni/SkyMain_jni.h"
#include "sky/shell/shell.h"
#include "ui/gl/gl_surface_egl.h"
using base::LazyInstance;
namespace sky {
namespace shell {
namespace {
LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop =
LAZY_INSTANCE_INITIALIZER;
LazyInstance<base::android::ScopedJavaGlobalRef<jobject>> g_main_activiy =
LAZY_INSTANCE_INITIALIZER;
LazyInstance<scoped_ptr<Shell>> g_shell = LAZY_INSTANCE_INITIALIZER;
void InitializeLogging() {
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
// To view log output with IDs and timestamps use "adb logcat -v threadtime".
logging::SetLogItems(false, // Process ID
false, // Thread ID
false, // Timestamp
false); // Tick count
}
} // namespace
static void Init(JNIEnv* env,
jclass clazz,
jobject activity) {
g_main_activiy.Get().Reset(env, activity);
base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity);
base::android::InitApplicationContext(env, scoped_activity);
base::CommandLine::Init(0, nullptr);
InitializeLogging();
g_java_message_loop.Get().reset(new base::MessageLoopForUI);
base::MessageLoopForUI::current()->Start();
base::i18n::InitializeICU();
gfx::GLSurface::InitializeOneOff();
g_shell.Get().reset(new Shell(g_java_message_loop.Get()->task_runner()));
g_java_message_loop.Get()->PostTask(
FROM_HERE,
base::Bind(&Shell::Init, base::Unretained(g_shell.Get().get())));
}
static jboolean Start(JNIEnv* env, jclass clazz) {
LOG(INFO) << "Native code started!";
return true;
}
bool RegisterSkyMain(JNIEnv* env) {
return RegisterNativesImpl(env);
}
} // namespace sky
} // namespace mojo