| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/shell/sky_main.h" | 5 #include "sky/shell/sky_main.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/threading/simple_thread.h" | 18 #include "base/threading/simple_thread.h" |
| 19 #include "jni/SkyMain_jni.h" | 19 #include "jni/SkyMain_jni.h" |
| 20 #include "sky/shell/shell.h" |
| 21 #include "ui/gl/gl_surface_egl.h" |
| 20 | 22 |
| 21 using base::LazyInstance; | 23 using base::LazyInstance; |
| 22 | 24 |
| 23 namespace sky { | 25 namespace sky { |
| 24 namespace shell { | 26 namespace shell { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = | 30 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = |
| 29 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 30 | 32 |
| 31 LazyInstance<base::android::ScopedJavaGlobalRef<jobject>> g_main_activiy = | 33 LazyInstance<base::android::ScopedJavaGlobalRef<jobject>> g_main_activiy = |
| 32 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
| 33 | 35 |
| 36 LazyInstance<scoped_ptr<Shell>> g_shell = LAZY_INSTANCE_INITIALIZER; |
| 37 |
| 34 void InitializeLogging() { | 38 void InitializeLogging() { |
| 35 logging::LoggingSettings settings; | 39 logging::LoggingSettings settings; |
| 36 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 40 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 37 logging::InitLogging(settings); | 41 logging::InitLogging(settings); |
| 38 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 42 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
| 39 logging::SetLogItems(false, // Process ID | 43 logging::SetLogItems(false, // Process ID |
| 40 false, // Thread ID | 44 false, // Thread ID |
| 41 false, // Timestamp | 45 false, // Timestamp |
| 42 false); // Tick count | 46 false); // Tick count |
| 43 } | 47 } |
| 44 | 48 |
| 45 } // namespace | 49 } // namespace |
| 46 | 50 |
| 47 static void Init(JNIEnv* env, | 51 static void Init(JNIEnv* env, |
| 48 jclass clazz, | 52 jclass clazz, |
| 49 jobject activity) { | 53 jobject activity) { |
| 50 g_main_activiy.Get().Reset(env, activity); | 54 g_main_activiy.Get().Reset(env, activity); |
| 51 | 55 |
| 52 base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity); | 56 base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity); |
| 53 base::android::InitApplicationContext(env, scoped_activity); | 57 base::android::InitApplicationContext(env, scoped_activity); |
| 54 | 58 |
| 55 base::CommandLine::Init(0, nullptr); | 59 base::CommandLine::Init(0, nullptr); |
| 56 | 60 |
| 57 InitializeLogging(); | 61 InitializeLogging(); |
| 58 | 62 |
| 59 g_java_message_loop.Get().reset(new base::MessageLoopForUI); | 63 g_java_message_loop.Get().reset(new base::MessageLoopForUI); |
| 60 base::MessageLoopForUI::current()->Start(); | 64 base::MessageLoopForUI::current()->Start(); |
| 65 |
| 66 gfx::GLSurface::InitializeOneOff(); |
| 67 |
| 68 g_shell.Get().reset(new Shell(g_java_message_loop.Get()->task_runner())); |
| 69 |
| 70 g_java_message_loop.Get()->PostTask( |
| 71 FROM_HERE, |
| 72 base::Bind(&Shell::Init, base::Unretained(g_shell.Get().get()))); |
| 61 } | 73 } |
| 62 | 74 |
| 63 static jboolean Start(JNIEnv* env, jclass clazz) { | 75 static jboolean Start(JNIEnv* env, jclass clazz) { |
| 64 LOG(INFO) << "Native code started!"; | 76 LOG(INFO) << "Native code started!"; |
| 65 return true; | 77 return true; |
| 66 } | 78 } |
| 67 | 79 |
| 68 bool RegisterSkyMain(JNIEnv* env) { | 80 bool RegisterSkyMain(JNIEnv* env) { |
| 69 return RegisterNativesImpl(env); | 81 return RegisterNativesImpl(env); |
| 70 } | 82 } |
| 71 | 83 |
| 72 } // namespace sky | 84 } // namespace sky |
| 73 } // namespace mojo | 85 } // namespace mojo |
| OLD | NEW |