After running filter-branch, move root directory into sky/
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import("//sky/build/skyx.gni")
|
||||
|
||||
template("sky_app") {
|
||||
skyx_target_name = target_name
|
||||
|
||||
if (is_android) {
|
||||
skyx_target_name = "app"
|
||||
}
|
||||
|
||||
skyx(skyx_target_name) {
|
||||
main_dart = invoker.main_dart
|
||||
|
||||
if (defined(invoker.manifest)) {
|
||||
manifest = invoker.manifest
|
||||
}
|
||||
|
||||
if (defined(invoker.sources)) {
|
||||
sources = invoker.sources
|
||||
}
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
import("//build/config/android/rules.gni")
|
||||
|
||||
bundle_prefix = target_name
|
||||
|
||||
copy("copy_${bundle_prefix}_bundle") {
|
||||
sources = [
|
||||
"$target_gen_dir/app.skyx",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/${bundle_prefix}.skyx",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":app",
|
||||
]
|
||||
}
|
||||
|
||||
copy_ex("assets") {
|
||||
clear_dir = true
|
||||
dest = "$target_gen_dir/assets"
|
||||
|
||||
sources = [
|
||||
"$root_build_dir/icudtl.dat",
|
||||
"$target_gen_dir/app.skyx",
|
||||
]
|
||||
deps = [
|
||||
"//third_party/icu",
|
||||
":copy_${bundle_prefix}_bundle",
|
||||
]
|
||||
|
||||
if (defined(invoker.bundles)) {
|
||||
foreach(bundle, invoker.bundles) {
|
||||
bundle_gen_dir = get_label_info(bundle, "target_gen_dir")
|
||||
bundle_name = get_label_info(bundle, "name")
|
||||
sources += [ "$bundle_gen_dir/${bundle_name}.skyx" ]
|
||||
deps += [ bundle ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android_apk(target_name) {
|
||||
apk_name = invoker.apk_name
|
||||
android_manifest = "apk/AndroidManifest.xml"
|
||||
|
||||
native_libs = [ "libsky_shell.so" ]
|
||||
asset_location = "$target_gen_dir/assets"
|
||||
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//sky/shell:assets",
|
||||
"//sky/shell:java",
|
||||
"//sky/shell:sky_shell",
|
||||
":assets",
|
||||
]
|
||||
|
||||
if (defined(invoker.deps)) {
|
||||
deps += invoker.deps
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
# 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.
|
||||
|
||||
package_root = "$root_gen_dir/dart-pkg/packages"
|
||||
|
||||
template("skyx") {
|
||||
bundle_prefix = target_name
|
||||
bundle = "$target_gen_dir/${bundle_prefix}.skyx"
|
||||
snapshot = "$target_gen_dir/${bundle_prefix}_snapshot.bin"
|
||||
|
||||
action("gen_${bundle_prefix}_snapshot") {
|
||||
main_dart = invoker.main_dart
|
||||
|
||||
inputs = [
|
||||
main_dart,
|
||||
]
|
||||
outputs = [
|
||||
snapshot,
|
||||
]
|
||||
|
||||
if (defined(invoker.sources)) {
|
||||
inputs += sources
|
||||
}
|
||||
|
||||
sky_packager_dir =
|
||||
get_label_info("//sky/tools/packager($host_toolchain)", "root_out_dir")
|
||||
|
||||
script = "//sky/tools/sky_packager.py"
|
||||
|
||||
src_dir = "//"
|
||||
cwd = rebase_path(src_dir, root_build_dir)
|
||||
|
||||
args = [
|
||||
rebase_path("$sky_packager_dir/sky_packager", src_dir),
|
||||
rebase_path(main_dart, src_dir),
|
||||
"--package-root",
|
||||
rebase_path(package_root, src_dir),
|
||||
"--snapshot",
|
||||
rebase_path(snapshot, src_dir),
|
||||
"-C",
|
||||
cwd,
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//sky/tools/packager($host_toolchain)",
|
||||
"//sky/sdk",
|
||||
]
|
||||
|
||||
if (defined(invoker.deps)) {
|
||||
deps += invoker.deps
|
||||
}
|
||||
}
|
||||
|
||||
action("gen_${bundle_prefix}_bundle") {
|
||||
asset_base = "$package_root/sky/assets/material-design-icons"
|
||||
|
||||
sources = [
|
||||
"//sky/tools/skyx/bin/skyx.dart",
|
||||
snapshot,
|
||||
]
|
||||
|
||||
outputs = [
|
||||
bundle,
|
||||
]
|
||||
|
||||
script = "//sky/tools/skyx.py"
|
||||
args = [
|
||||
"--package-root",
|
||||
rebase_path(package_root, root_build_dir),
|
||||
"--asset-base",
|
||||
rebase_path(asset_base, root_build_dir),
|
||||
"--snapshot",
|
||||
rebase_path(snapshot, root_build_dir),
|
||||
"-o",
|
||||
rebase_path(bundle, root_build_dir),
|
||||
]
|
||||
|
||||
if (defined(invoker.manifest)) {
|
||||
sources += [ invoker.manifest ]
|
||||
args += [
|
||||
"--manifest",
|
||||
rebase_path(invoker.manifest, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
":gen_${bundle_prefix}_snapshot",
|
||||
"//third_party/dart-pkg",
|
||||
]
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
deps = [
|
||||
":gen_${bundle_prefix}_bundle",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
# 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.
|
||||
|
||||
common_deps = [
|
||||
"//base",
|
||||
"//base:i18n",
|
||||
"//build/config/sanitizers:deps",
|
||||
"//dart/runtime:libdart",
|
||||
"//mojo/common",
|
||||
"//mojo/edk/system",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//mojo/services/asset_bundle/public/interfaces",
|
||||
"//mojo/services/navigation/public/interfaces",
|
||||
"//mojo/services/network/public/interfaces",
|
||||
"//services/asset_bundle:lib",
|
||||
"//skia",
|
||||
"//sky/engine",
|
||||
"//sky/engine/tonic",
|
||||
"//sky/engine/wtf",
|
||||
"//sky/services/engine:interfaces",
|
||||
"//sky/shell/dart",
|
||||
"//ui/gfx/geometry",
|
||||
"//ui/gl",
|
||||
]
|
||||
|
||||
source_set("common") {
|
||||
sources = [
|
||||
"gpu/ganesh_context.cc",
|
||||
"gpu/ganesh_context.h",
|
||||
"gpu/ganesh_surface.cc",
|
||||
"gpu/ganesh_surface.h",
|
||||
"gpu/picture_serializer.cc",
|
||||
"gpu/picture_serializer.h",
|
||||
"gpu/rasterizer.cc",
|
||||
"gpu/rasterizer.h",
|
||||
"gpu_delegate.cc",
|
||||
"gpu_delegate.h",
|
||||
"platform_view.cc",
|
||||
"platform_view.h",
|
||||
"service_provider.cc",
|
||||
"service_provider.h",
|
||||
"shell.cc",
|
||||
"shell.h",
|
||||
"shell_view.cc",
|
||||
"shell_view.h",
|
||||
"switches.cc",
|
||||
"switches.h",
|
||||
"ui/animator.cc",
|
||||
"ui/animator.h",
|
||||
"ui/engine.cc",
|
||||
"ui/engine.h",
|
||||
"ui/input_event_converter.cc",
|
||||
"ui/input_event_converter.h",
|
||||
"ui/internals.cc",
|
||||
"ui/internals.h",
|
||||
"ui/platform_impl.cc",
|
||||
"ui/platform_impl.h",
|
||||
"ui_delegate.cc",
|
||||
"ui_delegate.h",
|
||||
]
|
||||
|
||||
deps = common_deps
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
import("//build/config/android/config.gni")
|
||||
import("//build/config/android/rules.gni")
|
||||
|
||||
generate_jni("jni_headers") {
|
||||
sources = [
|
||||
"android/org/domokit/sky/shell/PlatformServiceProvider.java",
|
||||
"android/org/domokit/sky/shell/PlatformViewAndroid.java",
|
||||
"android/org/domokit/sky/shell/SkyMain.java",
|
||||
"android/org/domokit/sky/shell/TracingController.java",
|
||||
]
|
||||
jni_package = "sky/shell"
|
||||
}
|
||||
|
||||
shared_library("sky_shell") {
|
||||
sources = [
|
||||
"android/library_loader.cc",
|
||||
"android/platform_service_provider_android.cc",
|
||||
"android/platform_service_provider_android.h",
|
||||
"android/platform_view_android.cc",
|
||||
"android/platform_view_android.h",
|
||||
"android/sky_main.cc",
|
||||
"android/sky_main.h",
|
||||
"android/tracing_controller.cc",
|
||||
"android/tracing_controller.h",
|
||||
]
|
||||
|
||||
deps = common_deps + [
|
||||
"//mojo/android:libsystem_java",
|
||||
":jni_headers",
|
||||
":common",
|
||||
]
|
||||
}
|
||||
|
||||
android_library("java") {
|
||||
java_files = [
|
||||
"android/org/domokit/sky/shell/GestureProvider.java",
|
||||
"android/org/domokit/sky/shell/PlatformServiceProvider.java",
|
||||
"android/org/domokit/sky/shell/PlatformViewAndroid.java",
|
||||
"android/org/domokit/sky/shell/ResourceCleaner.java",
|
||||
"android/org/domokit/sky/shell/ResourceExtractor.java",
|
||||
"android/org/domokit/sky/shell/ServiceFactory.java",
|
||||
"android/org/domokit/sky/shell/ServiceRegistry.java",
|
||||
"android/org/domokit/sky/shell/SkyActivity.java",
|
||||
"android/org/domokit/sky/shell/SkyApplication.java",
|
||||
"android/org/domokit/sky/shell/SkyMain.java",
|
||||
"android/org/domokit/sky/shell/TracingController.java",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//mojo/android:system_java",
|
||||
"//mojo/public/interfaces/application:application_java",
|
||||
"//mojo/public/java:bindings",
|
||||
"//mojo/public/java:system",
|
||||
"//mojo/services/keyboard/public/interfaces:interfaces_java",
|
||||
"//mojo/services/network/public/interfaces:interfaces_java",
|
||||
"//services/keyboard",
|
||||
"//sky/services/activity:activity_lib",
|
||||
"//sky/services/activity:interfaces_java",
|
||||
"//sky/services/engine:interfaces_java",
|
||||
"//sky/services/oknet",
|
||||
]
|
||||
}
|
||||
|
||||
copy_ex("assets") {
|
||||
clear_dir = true
|
||||
dest = "$root_build_dir/sky_shell/assets"
|
||||
sources = [
|
||||
"$root_build_dir/icudtl.dat",
|
||||
]
|
||||
deps = [
|
||||
"//third_party/icu",
|
||||
]
|
||||
}
|
||||
} else if (is_ios) {
|
||||
import("//build/config/ios/rules.gni")
|
||||
import("//build/config/ios/ios_sdk.gni")
|
||||
|
||||
ios_app("shell") {
|
||||
app_name = "Sky"
|
||||
info_plist = "ios/Info.plist"
|
||||
scaffolding_target = "ios_scaffolding"
|
||||
entitlements_path = "ios/Entitlements.xcent"
|
||||
code_signing_identity = ios_code_signing_identity
|
||||
|
||||
resource_copy_ios("sky_resources") {
|
||||
resources = [ "//third_party/icu/android/icudtl.dat" ]
|
||||
bundle_directory = "."
|
||||
}
|
||||
|
||||
source_set(scaffolding_target) {
|
||||
sources = [
|
||||
"ios/main_ios.mm",
|
||||
"ios/platform_service_provider_ios.cc",
|
||||
"ios/platform_view_ios.h",
|
||||
"ios/platform_view_ios.mm",
|
||||
"ios/sky_app_delegate.h",
|
||||
"ios/sky_app_delegate.mm",
|
||||
"ios/sky_surface.h",
|
||||
"ios/sky_surface.mm",
|
||||
"ios/sky_view_controller.h",
|
||||
"ios/sky_view_controller.mm",
|
||||
]
|
||||
|
||||
deps = common_deps + [
|
||||
":common",
|
||||
"//sky/services/ns_net",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
":$scaffolding_target",
|
||||
":sky_resources",
|
||||
]
|
||||
}
|
||||
} else if (is_linux) {
|
||||
executable("shell") {
|
||||
output_name = "sky_shell"
|
||||
|
||||
sources = [
|
||||
"linux/main.cc",
|
||||
"linux/platform_service_provider_linux.cc",
|
||||
"linux/platform_view_linux.cc",
|
||||
"testing/test_runner.cc",
|
||||
"testing/test_runner.h",
|
||||
]
|
||||
|
||||
deps = common_deps + [
|
||||
":common",
|
||||
"//sky/services/testing:interfaces",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
assert(false, "Unsupported platform")
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// 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 "base/android/base_jni_onload.h"
|
||||
#include "base/android/base_jni_registrar.h"
|
||||
#include "base/android/jni_android.h"
|
||||
#include "base/android/jni_registrar.h"
|
||||
#include "base/android/library_loader/library_loader_hooks.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "mojo/android/system/base_run_loop.h"
|
||||
#include "mojo/android/system/core_impl.h"
|
||||
#include "sky/shell/android/platform_service_provider_android.h"
|
||||
#include "sky/shell/android/platform_view_android.h"
|
||||
#include "sky/shell/android/sky_main.h"
|
||||
#include "sky/shell/android/tracing_controller.h"
|
||||
|
||||
namespace {
|
||||
|
||||
base::android::RegistrationMethod kSkyRegisteredMethods[] = {
|
||||
{"CoreImpl", mojo::android::RegisterCoreImpl},
|
||||
{"BaseRunLoop", mojo::android::RegisterBaseRunLoop},
|
||||
{"PlatformServiceProvider", sky::shell::RegisterPlatformServiceProvider},
|
||||
{"PlatformViewAndroid", sky::shell::PlatformViewAndroid::Register},
|
||||
{"SkyMain", sky::shell::RegisterSkyMain},
|
||||
{"TracingController", sky::shell::RegisterTracingController},
|
||||
};
|
||||
|
||||
bool RegisterJNI(JNIEnv* env) {
|
||||
if (!base::android::RegisterJni(env))
|
||||
return false;
|
||||
|
||||
return RegisterNativeMethods(env, kSkyRegisteredMethods,
|
||||
arraysize(kSkyRegisteredMethods));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// This is called by the VM when the shared library is first loaded.
|
||||
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
std::vector<base::android::RegisterCallback> register_callbacks;
|
||||
register_callbacks.push_back(base::Bind(&RegisterJNI));
|
||||
if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
|
||||
!base::android::OnJNIOnLoadInit(
|
||||
std::vector<base::android::InitCallback>())) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.chromium.mojom.sky.EventType;
|
||||
import org.chromium.mojom.sky.GestureData;
|
||||
import org.chromium.mojom.sky.InputEvent;
|
||||
|
||||
/**
|
||||
* Knows how to drive a GestureDetector to turn MotionEvents into Sky's
|
||||
* InputEvents. Seems like this should not be needed. That there must exist
|
||||
* some Android class to do most of this work for us?
|
||||
*/
|
||||
public class GestureProvider implements GestureDetector.OnGestureListener {
|
||||
private static final String TAG = "GestureProvider";
|
||||
|
||||
/**
|
||||
* Callback interface
|
||||
*/
|
||||
public interface OnGestureListener {
|
||||
void onGestureEvent(InputEvent e);
|
||||
}
|
||||
|
||||
private OnGestureListener mListener;
|
||||
private GestureDetector mDetector;
|
||||
private boolean mScrolling;
|
||||
private boolean mFlinging;
|
||||
|
||||
public GestureProvider(Context context, OnGestureListener listener) {
|
||||
mListener = listener;
|
||||
mDetector = new GestureDetector(context, this);
|
||||
}
|
||||
|
||||
private InputEvent createGestureEvent(MotionEvent event) {
|
||||
int pointerIndex = event.getActionIndex();
|
||||
GestureData gestureData = new GestureData();
|
||||
gestureData.primaryPointer = event.getPointerId(pointerIndex);
|
||||
gestureData.x = event.getX(pointerIndex);
|
||||
gestureData.y = event.getY(pointerIndex);
|
||||
InputEvent inputEvent = new InputEvent();
|
||||
inputEvent.timeStamp = event.getEventTime();
|
||||
inputEvent.gestureData = gestureData;
|
||||
return inputEvent;
|
||||
}
|
||||
|
||||
public void onTouchEvent(MotionEvent event) {
|
||||
// TODO(eseidel): I am not confident that these stops are correct.
|
||||
int maskedAction = event.getActionMasked();
|
||||
if (mScrolling && maskedAction == MotionEvent.ACTION_UP) {
|
||||
mScrolling = false;
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_SCROLL_END;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
}
|
||||
|
||||
if (mFlinging && maskedAction == MotionEvent.ACTION_DOWN) {
|
||||
mFlinging = false;
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_FLING_CANCEL;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
}
|
||||
|
||||
mDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent event) {
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_TAP_DOWN;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2,
|
||||
float velocityX, float velocityY) {
|
||||
mFlinging = true;
|
||||
|
||||
// Use the first event as a scroll start (for the target hit-test)
|
||||
InputEvent inputEvent = createGestureEvent(e1);
|
||||
inputEvent.gestureData.velocityX = velocityX;
|
||||
inputEvent.gestureData.velocityY = velocityY;
|
||||
inputEvent.type = EventType.GESTURE_FLING_START;
|
||||
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent event) {
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_LONG_PRESS;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
|
||||
float distanceY) {
|
||||
// Use the first event as a scroll start (for the target hit-test)
|
||||
InputEvent inputEvent = createGestureEvent(e1);
|
||||
inputEvent.gestureData.dx = distanceX;
|
||||
inputEvent.gestureData.dy = -distanceY;
|
||||
|
||||
// If we haven't started scrolling, send a scroll_begin.
|
||||
if (!mScrolling) {
|
||||
mScrolling = true;
|
||||
inputEvent.type = EventType.GESTURE_SCROLL_BEGIN;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
}
|
||||
|
||||
inputEvent.type = EventType.GESTURE_SCROLL_UPDATE;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent event) {
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_SHOW_PRESS;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent event) {
|
||||
InputEvent inputEvent = createGestureEvent(event);
|
||||
inputEvent.type = EventType.GESTURE_TAP;
|
||||
mListener.onGestureEvent(inputEvent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.chromium.base.CalledByNative;
|
||||
import org.chromium.base.JNINamespace;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojom.mojo.ServiceProvider;
|
||||
|
||||
/**
|
||||
* A collection of services implemented in Java.
|
||||
**/
|
||||
@JNINamespace("sky::shell")
|
||||
public class PlatformServiceProvider implements ServiceProvider {
|
||||
private Core mCore;
|
||||
private Context mContext;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@CalledByNative
|
||||
public static void create(Context context, int nativeHandle) {
|
||||
Core core = CoreImpl.getInstance();
|
||||
MessagePipeHandle pipe = core.acquireNativeHandle(nativeHandle).toMessagePipeHandle();
|
||||
ServiceProvider.MANAGER.bind(new PlatformServiceProvider(core, context), pipe);
|
||||
}
|
||||
|
||||
public PlatformServiceProvider(Core core, Context context) {
|
||||
assert core != null;
|
||||
assert context != null;
|
||||
mCore = core;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
@Override
|
||||
public void connectToService(String interfaceName, MessagePipeHandle pipe) {
|
||||
ServiceFactory factory = ServiceRegistry.SHARED.get(interfaceName);
|
||||
if (factory == null) {
|
||||
pipe.close();
|
||||
return;
|
||||
}
|
||||
factory.connectToService(mContext, mCore, pipe);
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
|
||||
import org.chromium.base.JNINamespace;
|
||||
import org.chromium.mojo.bindings.InterfaceRequest;
|
||||
import org.chromium.mojo.keyboard.KeyboardServiceImpl;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.Pair;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojom.sky.EventType;
|
||||
import org.chromium.mojom.sky.InputEvent;
|
||||
import org.chromium.mojom.sky.PointerData;
|
||||
import org.chromium.mojom.sky.PointerKind;
|
||||
import org.chromium.mojom.sky.SkyEngine;
|
||||
import org.chromium.mojom.sky.ViewportMetrics;
|
||||
|
||||
/**
|
||||
* A view containing Sky
|
||||
*/
|
||||
@JNINamespace("sky::shell")
|
||||
public class PlatformViewAndroid extends SurfaceView
|
||||
implements GestureProvider.OnGestureListener {
|
||||
private static final String TAG = "PlatformViewAndroid";
|
||||
|
||||
private long mNativePlatformView;
|
||||
private SkyEngine.Proxy mSkyEngine;
|
||||
private final SurfaceHolder.Callback mSurfaceCallback;
|
||||
private GestureProvider mGestureProvider;
|
||||
private final EdgeDims mPadding;
|
||||
|
||||
/**
|
||||
* Dimensions in each of the four cardinal directions.
|
||||
*/
|
||||
public static class EdgeDims {
|
||||
public double top = 0.0;
|
||||
public double right = 0.0;
|
||||
public double bottom = 0.0;
|
||||
public double left = 0.0;
|
||||
}
|
||||
|
||||
public PlatformViewAndroid(Context context, EdgeDims padding) {
|
||||
super(context);
|
||||
mPadding = padding;
|
||||
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
attach();
|
||||
assert mNativePlatformView != 0;
|
||||
|
||||
final float density = context.getResources().getDisplayMetrics().density;
|
||||
|
||||
mSurfaceCallback = new SurfaceHolder.Callback() {
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
assert mSkyEngine != null;
|
||||
ViewportMetrics metrics = new ViewportMetrics();
|
||||
metrics.physicalWidth = width;
|
||||
metrics.physicalHeight = height;
|
||||
metrics.devicePixelRatio = density;
|
||||
if (mPadding != null) {
|
||||
metrics.paddingTop = mPadding.top;
|
||||
metrics.paddingRight = mPadding.right;
|
||||
metrics.paddingBottom = mPadding.bottom;
|
||||
metrics.paddingLeft = mPadding.left;
|
||||
}
|
||||
mSkyEngine.onViewportMetricsChanged(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
assert mNativePlatformView != 0;
|
||||
nativeSurfaceCreated(mNativePlatformView, holder.getSurface());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
assert mNativePlatformView != 0;
|
||||
nativeSurfaceDestroyed(mNativePlatformView);
|
||||
}
|
||||
};
|
||||
getHolder().addCallback(mSurfaceCallback);
|
||||
|
||||
mGestureProvider = new GestureProvider(context, this);
|
||||
KeyboardServiceImpl.setActiveView(this);
|
||||
}
|
||||
|
||||
SkyEngine getEngine() {
|
||||
return mSkyEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
getHolder().removeCallback(mSurfaceCallback);
|
||||
nativeDetach(mNativePlatformView);
|
||||
mNativePlatformView = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWindowVisibilityChanged(int visibility) {
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
if (visibility == View.VISIBLE) {
|
||||
requestFocusFromTouch();
|
||||
requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCheckIsTextEditor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||
return KeyboardServiceImpl.createInputConnection(outAttrs);
|
||||
}
|
||||
|
||||
private int getTypeForAction(int maskedAction) {
|
||||
// Primary pointer:
|
||||
if (maskedAction == MotionEvent.ACTION_DOWN) {
|
||||
return EventType.POINTER_DOWN;
|
||||
}
|
||||
if (maskedAction == MotionEvent.ACTION_UP) {
|
||||
return EventType.POINTER_UP;
|
||||
}
|
||||
// Secondary pointer:
|
||||
if (maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
|
||||
return EventType.POINTER_DOWN;
|
||||
}
|
||||
if (maskedAction == MotionEvent.ACTION_POINTER_UP) {
|
||||
return EventType.POINTER_UP;
|
||||
}
|
||||
// All pointers:
|
||||
if (maskedAction == MotionEvent.ACTION_MOVE) {
|
||||
return EventType.POINTER_MOVE;
|
||||
}
|
||||
if (maskedAction == MotionEvent.ACTION_CANCEL) {
|
||||
return EventType.POINTER_CANCEL;
|
||||
}
|
||||
return EventType.UNKNOWN;
|
||||
}
|
||||
|
||||
private void sendInputEventForIndex(MotionEvent event, int pointerIndex) {
|
||||
PointerData pointerData = new PointerData();
|
||||
pointerData.pointer = event.getPointerId(pointerIndex);
|
||||
pointerData.kind = PointerKind.TOUCH;
|
||||
pointerData.x = event.getX(pointerIndex);
|
||||
pointerData.y = event.getY(pointerIndex);
|
||||
|
||||
pointerData.pressure = event.getPressure(pointerIndex);
|
||||
// TODO(eseidel): Could get the calibrated range if necessary:
|
||||
// event.getDevice().getMotionRange(MotionEvent.AXIS_PRESSURE)
|
||||
pointerData.pressureMin = 0.0f;
|
||||
pointerData.pressureMax = 1.0f;
|
||||
|
||||
InputEvent inputEvent = new InputEvent();
|
||||
inputEvent.type = getTypeForAction(event.getActionMasked());
|
||||
inputEvent.timeStamp = event.getEventTime();
|
||||
inputEvent.pointerData = pointerData;
|
||||
|
||||
mSkyEngine.onInputEvent(inputEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
// TODO(abarth): This version check might not be effective in some
|
||||
// versions of Android that statically compile code and will be upset
|
||||
// at the lack of |requestUnbufferedDispatch|. Instead, we should factor
|
||||
// version-dependent code into separate classes for each supported
|
||||
// version and dispatch dynamically.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
requestUnbufferedDispatch(event);
|
||||
}
|
||||
mGestureProvider.onTouchEvent(event);
|
||||
|
||||
// TODO(abarth): Rather than unpacking these events here, we should
|
||||
// probably send them in one packet to the engine.
|
||||
int maskedAction = event.getActionMasked();
|
||||
// ACTION_UP, ACTION_POINTER_UP, ACTION_DOWN, and ACTION_POINTER_DOWN
|
||||
// only apply to a single pointer, other events apply to all pointers.
|
||||
if (maskedAction == MotionEvent.ACTION_UP
|
||||
|| maskedAction == MotionEvent.ACTION_POINTER_UP
|
||||
|| maskedAction == MotionEvent.ACTION_DOWN
|
||||
|| maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
|
||||
sendInputEventForIndex(event, event.getActionIndex());
|
||||
} else {
|
||||
// ACTION_MOVE may not actually mean all pointers have moved
|
||||
// but it's the responsibility of a later part of the system to
|
||||
// ignore 0-deltas if desired.
|
||||
for (int p = 0; p < event.getPointerCount(); p++) {
|
||||
sendInputEventForIndex(event, p);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGestureEvent(InputEvent event) {
|
||||
mSkyEngine.onInputEvent(event);
|
||||
}
|
||||
|
||||
private void attach() {
|
||||
Core core = CoreImpl.getInstance();
|
||||
Pair<SkyEngine.Proxy, InterfaceRequest<SkyEngine>> result =
|
||||
SkyEngine.MANAGER.getInterfaceRequest(core);
|
||||
mSkyEngine = result.first;
|
||||
mNativePlatformView = nativeAttach(result.second.passHandle().releaseNativeHandle());
|
||||
}
|
||||
|
||||
private static native long nativeAttach(int inputObserverHandle);
|
||||
private static native void nativeDetach(long nativePlatformViewAndroid);
|
||||
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
|
||||
Surface surface);
|
||||
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* A class to clean up orphaned resource directories after unclean shutdowns.
|
||||
**/
|
||||
public class ResourceCleaner {
|
||||
private static final String TAG = "ResourceCleaner";
|
||||
private static final String TEMPORARY_RESOURCE_PREFIX = ".org.chromium.Chromium.";
|
||||
private static final long DELAY_MS = 5000;
|
||||
|
||||
private class CleanTask extends AsyncTask<Void, Void, Void> {
|
||||
private final File[] mFilesToDelete;
|
||||
|
||||
public CleanTask(File[] filesToDelete) {
|
||||
mFilesToDelete = filesToDelete;
|
||||
}
|
||||
|
||||
public boolean hasFilesToDelete() {
|
||||
return mFilesToDelete.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
Log.i(TAG, "Cleaning " + mFilesToDelete.length + " resources.");
|
||||
for (File file : mFilesToDelete) {
|
||||
if (file.exists()) {
|
||||
deleteRecursively(file);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void deleteRecursively(File parent) {
|
||||
if (parent.isDirectory()) {
|
||||
for (File child : parent.listFiles()) {
|
||||
deleteRecursively(child);
|
||||
}
|
||||
}
|
||||
parent.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public ResourceCleaner(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
File cacheDir = mContext.getCacheDir();
|
||||
if (cacheDir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CleanTask task = new CleanTask(cacheDir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean result = name.startsWith(TEMPORARY_RESOURCE_PREFIX);
|
||||
return result;
|
||||
}
|
||||
}));
|
||||
|
||||
if (!task.hasFilesToDelete()) {
|
||||
return;
|
||||
}
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}, DELAY_MS);
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.chromium.base.PathUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* A class to intialize the native code.
|
||||
**/
|
||||
public class ResourceExtractor {
|
||||
private static final String TAG = "ResourceExtractor";
|
||||
private static final String TIMESTAMP_PREFIX = "res_timestamp-";
|
||||
|
||||
private class ExtractTask extends AsyncTask<Void, Void, Void> {
|
||||
private static final int BUFFER_SIZE = 16 * 1024;
|
||||
|
||||
public ExtractTask() { }
|
||||
|
||||
private void extractResources() {
|
||||
final File dataDir = new File(PathUtils.getDataDirectory(mContext));
|
||||
|
||||
final String timestamp = checkTimestamp(dataDir);
|
||||
if (timestamp != null) {
|
||||
deleteFiles();
|
||||
}
|
||||
|
||||
final AssetManager manager = mContext.getResources().getAssets();
|
||||
try {
|
||||
byte[] buffer = null;
|
||||
final String[] assets = manager.list("");
|
||||
for (String asset : assets) {
|
||||
if (!mResources.contains(asset))
|
||||
continue;
|
||||
final File output = new File(dataDir, asset);
|
||||
if (output.exists())
|
||||
continue;
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = manager.open(asset);
|
||||
os = new FileOutputStream(output);
|
||||
if (buffer == null) {
|
||||
buffer = new byte[BUFFER_SIZE];
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
|
||||
os.write(buffer, 0, count);
|
||||
}
|
||||
os.flush();
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} finally {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Exception unpacking resources: " + e.getMessage());
|
||||
deleteFiles();
|
||||
return;
|
||||
}
|
||||
|
||||
if (timestamp != null) {
|
||||
try {
|
||||
new File(dataDir, timestamp).createNewFile();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to write resource timestamp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String checkTimestamp(File dataDir) {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
|
||||
try {
|
||||
packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return TIMESTAMP_PREFIX;
|
||||
}
|
||||
|
||||
if (packageInfo == null) {
|
||||
return TIMESTAMP_PREFIX;
|
||||
}
|
||||
|
||||
String expectedTimestamp =
|
||||
TIMESTAMP_PREFIX + packageInfo.versionCode + "-" + packageInfo.lastUpdateTime;
|
||||
|
||||
final String[] existingTimestamps = getExistingTimestamps(dataDir);
|
||||
if (existingTimestamps.length != 1
|
||||
|| !expectedTimestamp.equals(existingTimestamps[0])) {
|
||||
return expectedTimestamp;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
extractResources();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
private final HashSet<String> mResources;
|
||||
private ExtractTask mExtractTask;
|
||||
|
||||
public ResourceExtractor(Context context) {
|
||||
mContext = context;
|
||||
mResources = new HashSet<String>();
|
||||
}
|
||||
|
||||
public void addResources(String[] resources) {
|
||||
for (String resource : resources) {
|
||||
mResources.add(resource);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
assert mExtractTask == null;
|
||||
mExtractTask = new ExtractTask();
|
||||
mExtractTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void waitForCompletion() {
|
||||
assert mExtractTask != null;
|
||||
|
||||
try {
|
||||
mExtractTask.get();
|
||||
} catch (CancellationException e) {
|
||||
deleteFiles();
|
||||
} catch (ExecutionException e2) {
|
||||
deleteFiles();
|
||||
} catch (InterruptedException e3) {
|
||||
deleteFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getExistingTimestamps(File dataDir) {
|
||||
return dataDir.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.startsWith(TIMESTAMP_PREFIX);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteFiles() {
|
||||
final File dataDir = new File(PathUtils.getDataDirectory(mContext));
|
||||
for (String resource : mResources) {
|
||||
final File file = new File(dataDir, resource);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
for (String timestamp : getExistingTimestamps(dataDir)) {
|
||||
new File(dataDir, timestamp).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
|
||||
/**
|
||||
* An interface for creating services. Instances of this interface can be
|
||||
* registered with ServiceRegistry and thereby made available to non-Java
|
||||
* clients.
|
||||
**/
|
||||
public interface ServiceFactory {
|
||||
public void connectToService(Context context, Core core, MessagePipeHandle pipe);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* An registry for services.
|
||||
**/
|
||||
public class ServiceRegistry {
|
||||
private static final String TAG = "ServiceRegistry";
|
||||
private Map<String, ServiceFactory> mRegistrations;
|
||||
|
||||
public static final ServiceRegistry SHARED = new ServiceRegistry();
|
||||
|
||||
private ServiceRegistry() {
|
||||
mRegistrations = new TreeMap<String, ServiceFactory>();
|
||||
}
|
||||
|
||||
public void register(String interfaceName, ServiceFactory connector) {
|
||||
assert !mRegistrations.containsKey(interfaceName);
|
||||
assert connector != null;
|
||||
mRegistrations.put(interfaceName, connector);
|
||||
}
|
||||
|
||||
public ServiceFactory get(String interfaceName) {
|
||||
if (!mRegistrations.containsKey(interfaceName)) {
|
||||
Log.e(TAG, "Unknown service " + interfaceName);
|
||||
}
|
||||
return mRegistrations.get(interfaceName);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import org.chromium.base.PathUtils;
|
||||
import org.chromium.mojom.sky.EventType;
|
||||
import org.chromium.mojom.sky.InputEvent;
|
||||
|
||||
import org.domokit.activity.ActivityImpl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Base class for activities that use Sky.
|
||||
*/
|
||||
public class SkyActivity extends Activity {
|
||||
private TracingController mTracingController;
|
||||
private PlatformViewAndroid mView;
|
||||
|
||||
/**
|
||||
* @see android.app.Activity#onCreate(android.os.Bundle)
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
PlatformViewAndroid.EdgeDims edgeDims = new PlatformViewAndroid.EdgeDims();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
getWindow().setStatusBarColor(0x40000000);
|
||||
// TODO(abarth): We should get this value from the Android framework somehow.
|
||||
edgeDims.top = 25.0;
|
||||
}
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
|
||||
SkyMain.ensureInitialized(getApplicationContext());
|
||||
mView = new PlatformViewAndroid(this, edgeDims);
|
||||
ActivityImpl.setCurrentActivity(this);
|
||||
setContentView(mView);
|
||||
mTracingController = new TracingController(this);
|
||||
|
||||
onSkyReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see android.app.Activity#onDestroy()
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// Do we need to shut down Sky too?
|
||||
mTracingController.stop();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mView != null) {
|
||||
InputEvent event = new InputEvent();
|
||||
event.type = EventType.BACK;
|
||||
mView.getEngine().onInputEvent(event);
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (mView != null) {
|
||||
mView.getEngine().onActivityPaused();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
if (mView != null) {
|
||||
mView.getEngine().onActivityResumed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to customize startup behavior.
|
||||
*/
|
||||
protected void onSkyReady() {
|
||||
File dataDir = new File(PathUtils.getDataDirectory(this));
|
||||
File snapshot = new File(dataDir, SkyApplication.SNAPSHOT);
|
||||
if (snapshot.exists()) {
|
||||
mView.getEngine().runFromSnapshot(snapshot.getPath());
|
||||
return;
|
||||
}
|
||||
File appBundle = new File(dataDir, SkyApplication.APP_BUNDLE);
|
||||
if (appBundle.exists()) {
|
||||
mView.getEngine().runFromBundle(appBundle.getPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUrl(String url) {
|
||||
mView.getEngine().runFromNetwork(url);
|
||||
}
|
||||
|
||||
public boolean loadBundleByName(String name) {
|
||||
File dataDir = new File(PathUtils.getDataDirectory(this));
|
||||
File bundle = new File(dataDir, name);
|
||||
if (!bundle.exists()) {
|
||||
return false;
|
||||
}
|
||||
mView.getEngine().runFromBundle(bundle.getPath());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.chromium.base.BaseChromiumApplication;
|
||||
import org.chromium.base.PathUtils;
|
||||
import org.chromium.base.library_loader.LibraryLoader;
|
||||
import org.chromium.base.library_loader.LibraryProcessType;
|
||||
import org.chromium.base.library_loader.ProcessInitException;
|
||||
import org.chromium.mojo.keyboard.KeyboardServiceImpl;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojom.activity.Activity;
|
||||
import org.chromium.mojom.keyboard.KeyboardService;
|
||||
import org.chromium.mojom.mojo.NetworkService;
|
||||
import org.domokit.activity.ActivityImpl;
|
||||
import org.domokit.oknet.NetworkServiceImpl;
|
||||
|
||||
/**
|
||||
* Sky implementation of {@link android.app.Application}, managing application-level global
|
||||
* state and initializations.
|
||||
*/
|
||||
public class SkyApplication extends BaseChromiumApplication {
|
||||
static final String SNAPSHOT = "snapshot_blob.bin";
|
||||
static final String APP_BUNDLE = "app.skyx";
|
||||
|
||||
private static final String TAG = "SkyApplication";
|
||||
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "sky_shell";
|
||||
private static final String[] SKY_RESOURCES = {"icudtl.dat", SNAPSHOT, APP_BUNDLE};
|
||||
|
||||
private ResourceExtractor mResourceExtractor;
|
||||
|
||||
public ResourceExtractor getResourceExtractor() {
|
||||
return mResourceExtractor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
initJavaUtils();
|
||||
initResources();
|
||||
initNative();
|
||||
onServiceRegistryAvailable(ServiceRegistry.SHARED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to add more resources for extraction.
|
||||
*/
|
||||
protected void onBeforeResourceExtraction(ResourceExtractor extractor) {
|
||||
extractor.addResources(SKY_RESOURCES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this function to register more services.
|
||||
*/
|
||||
protected void onServiceRegistryAvailable(ServiceRegistry registry) {
|
||||
registry.register(NetworkService.MANAGER.getName(), new ServiceFactory() {
|
||||
@Override
|
||||
public void connectToService(Context context, Core core, MessagePipeHandle pipe) {
|
||||
// TODO(eseidel): Refactor ownership to match other services.
|
||||
new NetworkServiceImpl(context, core, pipe);
|
||||
}
|
||||
});
|
||||
|
||||
registry.register(KeyboardService.MANAGER.getName(), new ServiceFactory() {
|
||||
@Override
|
||||
public void connectToService(Context context, Core core, MessagePipeHandle pipe) {
|
||||
KeyboardService.MANAGER.bind(new KeyboardServiceImpl(context), pipe);
|
||||
}
|
||||
});
|
||||
|
||||
registry.register(Activity.MANAGER.getName(), new ServiceFactory() {
|
||||
@Override
|
||||
public void connectToService(Context context, Core core, MessagePipeHandle pipe) {
|
||||
Activity.MANAGER.bind(new ActivityImpl(), pipe);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initJavaUtils() {
|
||||
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX,
|
||||
getApplicationContext());
|
||||
}
|
||||
|
||||
private void initResources() {
|
||||
Context context = getApplicationContext();
|
||||
new ResourceCleaner(context).start();
|
||||
mResourceExtractor = new ResourceExtractor(context);
|
||||
onBeforeResourceExtraction(mResourceExtractor);
|
||||
mResourceExtractor.start();
|
||||
}
|
||||
|
||||
private void initNative() {
|
||||
try {
|
||||
LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
|
||||
} catch (ProcessInitException e) {
|
||||
Log.e(TAG, "Unable to load Sky Engine binary.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.chromium.base.JNINamespace;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
|
||||
/**
|
||||
* A class to intialize the native code.
|
||||
**/
|
||||
@JNINamespace("sky::shell")
|
||||
public class SkyMain {
|
||||
private static final String TAG = "SkyMain";
|
||||
|
||||
/**
|
||||
* A guard flag for calling nativeInit() only once.
|
||||
**/
|
||||
private static boolean sInitialized = false;
|
||||
|
||||
/**
|
||||
* Initializes the native system.
|
||||
**/
|
||||
public static void ensureInitialized(Context applicationContext) {
|
||||
if (sInitialized) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SkyApplication app = (SkyApplication) applicationContext;
|
||||
app.getResourceExtractor().waitForCompletion();
|
||||
nativeInit(applicationContext);
|
||||
// Create the mojo run loop.
|
||||
CoreImpl.getInstance().createDefaultRunLoop();
|
||||
sInitialized = true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "SkyMain initialization failed.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void nativeInit(Context context);
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// 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.
|
||||
|
||||
package org.domokit.sky.shell;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
|
||||
import org.chromium.base.JNINamespace;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* A controller for the tracing system.
|
||||
*/
|
||||
@JNINamespace("sky::shell")
|
||||
class TracingController {
|
||||
private static final String TAG = "TracingController";
|
||||
private static final String TRACING_START = ".TRACING_START";
|
||||
private static final String TRACING_STOP = ".TRACING_STOP";
|
||||
|
||||
private final Context mContext;
|
||||
private final TracingBroadcastReceiver mBroadcastReceiver;
|
||||
private final TracingIntentFilter mIntentFilter;
|
||||
|
||||
public TracingController(Context context) {
|
||||
mContext = context;
|
||||
mBroadcastReceiver = new TracingBroadcastReceiver();
|
||||
mIntentFilter = new TracingIntentFilter(context);
|
||||
|
||||
mContext.registerReceiver(mBroadcastReceiver, mIntentFilter);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
mContext.unregisterReceiver(mBroadcastReceiver);
|
||||
}
|
||||
|
||||
private String generateTracingFilePath() {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HHmmss", Locale.US);
|
||||
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
File dir = mContext.getCacheDir();
|
||||
String date = formatter.format(new Date());
|
||||
File file = new File(dir, "sky-trace-" + date + ".json");
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
class TracingIntentFilter extends IntentFilter {
|
||||
TracingIntentFilter(Context context) {
|
||||
addAction(context.getPackageName() + TRACING_START);
|
||||
addAction(context.getPackageName() + TRACING_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
class TracingBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().endsWith(TRACING_START)) {
|
||||
nativeStartTracing();
|
||||
} else if (intent.getAction().endsWith(TRACING_STOP)) {
|
||||
nativeStopTracing(generateTracingFilePath());
|
||||
} else {
|
||||
Log.e(TAG, "Unexpected intent: " + intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static native void nativeStartTracing();
|
||||
private static native void nativeStopTracing(String path);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// 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/android/platform_service_provider_android.h"
|
||||
|
||||
#include "base/android/jni_android.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "jni/PlatformServiceProvider_jni.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
void CreatePlatformServiceProvider(
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
|
||||
Java_PlatformServiceProvider_create(
|
||||
base::android::AttachCurrentThread(),
|
||||
base::android::GetApplicationContext(),
|
||||
request.PassMessagePipe().release().value());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool RegisterPlatformServiceProvider(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
mojo::ServiceProviderPtr CreateServiceProvider(
|
||||
ServiceProviderContext* context) {
|
||||
mojo::MessagePipe pipe;
|
||||
context->platform_task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(CreatePlatformServiceProvider,
|
||||
base::Passed(mojo::MakeRequest<mojo::ServiceProvider>(
|
||||
pipe.handle1.Pass()))));
|
||||
return mojo::MakeProxy(
|
||||
mojo::InterfacePtrInfo<mojo::ServiceProvider>(pipe.handle0.Pass(), 0u));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,18 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_
|
||||
#define SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
bool RegisterPlatformServiceProvider(JNIEnv* env);
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_
|
||||
@@ -1,83 +0,0 @@
|
||||
// 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/android/platform_view_android.h"
|
||||
|
||||
#include <android/input.h>
|
||||
#include <android/native_window_jni.h>
|
||||
|
||||
#include "base/android/jni_android.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/location.h"
|
||||
#include "jni/PlatformViewAndroid_jni.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/shell_view.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
static jlong Attach(JNIEnv* env, jclass clazz, jint skyEngineHandle) {
|
||||
ShellView* shell_view = new ShellView(Shell::Shared());
|
||||
auto view = static_cast<PlatformViewAndroid*>(shell_view->view());
|
||||
view->SetShellView(make_scoped_ptr(shell_view));
|
||||
view->ConnectToEngine(
|
||||
mojo::MakeRequest<SkyEngine>(mojo::ScopedMessagePipeHandle(
|
||||
mojo::MessagePipeHandle(skyEngineHandle))));
|
||||
return reinterpret_cast<jlong>(shell_view->view());
|
||||
}
|
||||
|
||||
// static
|
||||
bool PlatformViewAndroid::Register(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
PlatformView* PlatformView::Create(const Config& config) {
|
||||
return new PlatformViewAndroid(config);
|
||||
}
|
||||
|
||||
PlatformViewAndroid::PlatformViewAndroid(const Config& config)
|
||||
: PlatformView(config) {
|
||||
}
|
||||
|
||||
PlatformViewAndroid::~PlatformViewAndroid() {
|
||||
if (window_)
|
||||
ReleaseWindow();
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) {
|
||||
DCHECK(!window_);
|
||||
shell_view_.reset();
|
||||
// Note: |this| has been destroyed at this point.
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) {
|
||||
base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface);
|
||||
// Note: This ensures that any local references used by
|
||||
// ANativeWindow_fromSurface are released immediately. This is needed as a
|
||||
// workaround for https://code.google.com/p/android/issues/detail?id=68174
|
||||
{
|
||||
base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
|
||||
window_ = ANativeWindow_fromSurface(env, jsurface);
|
||||
}
|
||||
SurfaceWasCreated();
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) {
|
||||
DCHECK(window_);
|
||||
SurfaceWasDestroyed();
|
||||
ReleaseWindow();
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::SetShellView(scoped_ptr<ShellView> shell_view) {
|
||||
DCHECK(!shell_view_);
|
||||
shell_view_ = shell_view.Pass();
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::ReleaseWindow() {
|
||||
ANativeWindow_release(window_);
|
||||
window_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,45 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_PLATFORM_VIEW_ANDROID_H_
|
||||
#define SKY_SHELL_PLATFORM_VIEW_ANDROID_H_
|
||||
|
||||
#include "sky/shell/platform_view.h"
|
||||
|
||||
struct ANativeWindow;
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class ShellView;
|
||||
|
||||
class PlatformViewAndroid : public PlatformView {
|
||||
public:
|
||||
static bool Register(JNIEnv* env);
|
||||
|
||||
PlatformViewAndroid(const Config& config);
|
||||
~PlatformViewAndroid() override;
|
||||
|
||||
// Called from Java
|
||||
void Detach(JNIEnv* env, jobject obj);
|
||||
void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface);
|
||||
void SurfaceDestroyed(JNIEnv* env, jobject obj);
|
||||
|
||||
void SetShellView(scoped_ptr<ShellView> shell_view);
|
||||
|
||||
private:
|
||||
void ReleaseWindow();
|
||||
|
||||
// In principle, the ShellView should own the PlatformView, but because our
|
||||
// lifetime is controlled by the Android view hierarchy, we flip around the
|
||||
// ownership and have the shell_view owned by Java. We reset this pointer in
|
||||
// |Detach|, which will eventually cause |~PlatformViewAndroid|.
|
||||
scoped_ptr<ShellView> shell_view_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_PLATFORM_VIEW_ANDROID_H_
|
||||
@@ -1,70 +0,0 @@
|
||||
// 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/android/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/service_provider.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;
|
||||
|
||||
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 context) {
|
||||
base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
|
||||
base::android::InitApplicationContext(env, scoped_context);
|
||||
|
||||
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();
|
||||
|
||||
Shell::Init(make_scoped_ptr(new ServiceProviderContext(
|
||||
g_java_message_loop.Get()->task_runner())));
|
||||
}
|
||||
|
||||
bool RegisterSkyMain(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
} // namespace sky
|
||||
} // namespace mojo
|
||||
@@ -1,18 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_SKY_MAIN_H_
|
||||
#define SKY_SHELL_SKY_MAIN_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
bool RegisterSkyMain(JNIEnv* env);
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_SKY_MAIN_H_
|
||||
@@ -1,70 +0,0 @@
|
||||
// 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/android/tracing_controller.h"
|
||||
|
||||
#include "base/android/jni_android.h"
|
||||
#include "base/android/jni_string.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/trace_event/trace_config.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "jni/TracingController_jni.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
const char kStart[] = "{\"traceEvents\":[";
|
||||
const char kEnd[] = "]}";
|
||||
|
||||
static FILE* g_file = NULL;
|
||||
|
||||
void Write(const std::string& data) {
|
||||
ignore_result(fwrite(data.data(), data.length(), 1, g_file));
|
||||
}
|
||||
|
||||
void HandleChunk(const scoped_refptr<base::RefCountedString>& chunk,
|
||||
bool has_more_events) {
|
||||
Write(chunk->data());
|
||||
if (has_more_events)
|
||||
Write(",");
|
||||
|
||||
if (!has_more_events) {
|
||||
Write(kEnd);
|
||||
base::CloseFile(g_file);
|
||||
g_file = NULL;
|
||||
|
||||
LOG(INFO) << "Trace complete";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
static void StartTracing(JNIEnv* env, jclass clazz) {
|
||||
LOG(INFO) << "Starting trace";
|
||||
|
||||
base::trace_event::TraceLog::GetInstance()->SetEnabled(
|
||||
base::trace_event::TraceConfig("*", base::trace_event::RECORD_UNTIL_FULL),
|
||||
base::trace_event::TraceLog::RECORDING_MODE);
|
||||
}
|
||||
|
||||
static void StopTracing(JNIEnv* env, jclass clazz, jstring path) {
|
||||
base::trace_event::TraceLog::GetInstance()->SetDisabled();
|
||||
|
||||
base::FilePath file_path(base::android::ConvertJavaStringToUTF8(env, path));
|
||||
g_file = base::OpenFile(file_path, "w");
|
||||
CHECK(g_file) << "Failed to open file " << file_path.LossyDisplayName();
|
||||
|
||||
LOG(INFO) << "Saving trace to " << file_path.LossyDisplayName();
|
||||
Write(kStart);
|
||||
base::trace_event::TraceLog::GetInstance()->Flush(base::Bind(&HandleChunk));
|
||||
}
|
||||
|
||||
bool RegisterTracingController(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,19 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_TRACING_CONTROLLER_H_
|
||||
#define SKY_SHELL_TRACING_CONTROLLER_H_
|
||||
|
||||
#include "base/android/jni_weak_ref.h"
|
||||
#include "base/android/scoped_java_ref.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
bool RegisterTracingController(JNIEnv* env);
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_TRACING_CONTROLLER_H_
|
||||
@@ -1,24 +0,0 @@
|
||||
# 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.
|
||||
|
||||
source_set("dart") {
|
||||
sources = [
|
||||
"dart_library_provider_files.cc",
|
||||
"dart_library_provider_files.h",
|
||||
"dart_library_provider_network.cc",
|
||||
"dart_library_provider_network.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//build/config/sanitizers:deps",
|
||||
"//dart/runtime:libdart",
|
||||
"//mojo/common",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/services/network/public/interfaces",
|
||||
"//sky/engine/tonic",
|
||||
"//sky/engine/wtf",
|
||||
"//url",
|
||||
]
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
// 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/dart/dart_library_provider_files.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "mojo/common/data_pipe_utils.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
void CopyComplete(base::FilePath file, bool success) {
|
||||
if (!success)
|
||||
LOG(ERROR) << "Failed to load " << file.AsUTF8Unsafe();
|
||||
}
|
||||
|
||||
base::FilePath SimplifyPath(const base::FilePath& path) {
|
||||
std::vector<base::FilePath::StringType> components;
|
||||
path.GetComponents(&components);
|
||||
auto it = components.begin();
|
||||
base::FilePath result(*it++);
|
||||
for (; it != components.end(); it++) {
|
||||
auto& component = *it;
|
||||
if (component == base::FilePath::kCurrentDirectory)
|
||||
continue;
|
||||
if (component == base::FilePath::kParentDirectory)
|
||||
result = result.DirName();
|
||||
else
|
||||
result = result.Append(component);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DartLibraryProviderFiles::DartLibraryProviderFiles(
|
||||
const base::FilePath& package_root)
|
||||
: package_root_(package_root) {
|
||||
CHECK(base::DirectoryExists(package_root_)) << "Invalid --package-root "
|
||||
<< "\"" << package_root_.LossyDisplayName() << "\"";
|
||||
}
|
||||
|
||||
DartLibraryProviderFiles::~DartLibraryProviderFiles() {
|
||||
}
|
||||
|
||||
void DartLibraryProviderFiles::GetLibraryAsStream(
|
||||
const std::string& name,
|
||||
blink::DataPipeConsumerCallback callback) {
|
||||
mojo::DataPipe pipe;
|
||||
callback.Run(pipe.consumer_handle.Pass());
|
||||
|
||||
base::FilePath source(name);
|
||||
scoped_refptr<base::TaskRunner> runner =
|
||||
base::WorkerPool::GetTaskRunner(true);
|
||||
mojo::common::CopyFromFile(source, pipe.producer_handle.Pass(), 0,
|
||||
runner.get(), base::Bind(&CopyComplete, source));
|
||||
}
|
||||
|
||||
std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) {
|
||||
DCHECK(StartsWithASCII(url, "package:", true));
|
||||
ReplaceFirstSubstringAfterOffset(&url, 0, "package:", "");
|
||||
return package_root_.Append(url).AsUTF8Unsafe();
|
||||
}
|
||||
|
||||
Dart_Handle DartLibraryProviderFiles::CanonicalizeURL(Dart_Handle library,
|
||||
Dart_Handle url) {
|
||||
std::string string = blink::StdStringFromDart(url);
|
||||
if (StartsWithASCII(string, "dart:", true))
|
||||
return url;
|
||||
if (StartsWithASCII(string, "package:", true))
|
||||
return blink::StdStringToDart(CanonicalizePackageURL(string));
|
||||
base::FilePath base_path(blink::StdStringFromDart(Dart_LibraryUrl(library)));
|
||||
base::FilePath resolved_path = base_path.DirName().Append(string);
|
||||
base::FilePath normalized_path = SimplifyPath(resolved_path);
|
||||
return blink::StdStringToDart(normalized_path.AsUTF8Unsafe());
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,36 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_DART_DART_LIBRARY_PROVIDER_FILES_H_
|
||||
#define SKY_SHELL_DART_DART_LIBRARY_PROVIDER_FILES_H_
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "sky/engine/tonic/dart_library_provider.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class DartLibraryProviderFiles : public blink::DartLibraryProvider {
|
||||
public:
|
||||
explicit DartLibraryProviderFiles(const base::FilePath& package_root);
|
||||
~DartLibraryProviderFiles() override;
|
||||
|
||||
protected:
|
||||
// |DartLibraryProvider| implementation:
|
||||
void GetLibraryAsStream(const std::string& name,
|
||||
blink::DataPipeConsumerCallback callback) override;
|
||||
Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url) override;
|
||||
|
||||
private:
|
||||
std::string CanonicalizePackageURL(std::string url);
|
||||
|
||||
base::FilePath package_root_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DartLibraryProviderFiles);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_DART_DART_LIBRARY_PROVIDER_FILES_H_
|
||||
@@ -1,88 +0,0 @@
|
||||
// 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/dart/dart_library_provider_network.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
mojo::URLLoaderPtr Fetch(mojo::NetworkService* network_service,
|
||||
const std::string& url,
|
||||
base::Callback<void(mojo::URLResponsePtr)> callback) {
|
||||
mojo::URLLoaderPtr loader;
|
||||
network_service->CreateURLLoader(GetProxy(&loader));
|
||||
|
||||
mojo::URLRequestPtr request = mojo::URLRequest::New();
|
||||
request->url = url;
|
||||
request->auto_follow_redirects = true;
|
||||
loader->Start(request.Pass(), callback);
|
||||
|
||||
return loader.Pass();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class DartLibraryProviderNetwork::Job {
|
||||
public:
|
||||
Job(DartLibraryProviderNetwork* provider,
|
||||
const std::string& name,
|
||||
blink::DataPipeConsumerCallback callback)
|
||||
: provider_(provider), callback_(callback), weak_factory_(this) {
|
||||
url_loader_ =
|
||||
Fetch(provider_->network_service(), name,
|
||||
base::Bind(&Job::OnReceivedResponse, weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
private:
|
||||
void OnReceivedResponse(mojo::URLResponsePtr response) {
|
||||
mojo::ScopedDataPipeConsumerHandle data;
|
||||
if (response->status_code == 200)
|
||||
data = response->body.Pass();
|
||||
callback_.Run(data.Pass());
|
||||
provider_->jobs_.remove(this);
|
||||
// We're deleted now.
|
||||
}
|
||||
|
||||
DartLibraryProviderNetwork* provider_;
|
||||
blink::DataPipeConsumerCallback callback_;
|
||||
mojo::URLLoaderPtr url_loader_;
|
||||
|
||||
base::WeakPtrFactory<Job> weak_factory_;
|
||||
};
|
||||
|
||||
DartLibraryProviderNetwork::DartLibraryProviderNetwork(
|
||||
mojo::NetworkService* network_service)
|
||||
: network_service_(network_service) {
|
||||
}
|
||||
|
||||
DartLibraryProviderNetwork::~DartLibraryProviderNetwork() {
|
||||
}
|
||||
|
||||
void DartLibraryProviderNetwork::GetLibraryAsStream(
|
||||
const std::string& name,
|
||||
blink::DataPipeConsumerCallback callback) {
|
||||
jobs_.add(adoptPtr(new Job(this, name, callback)));
|
||||
}
|
||||
|
||||
Dart_Handle DartLibraryProviderNetwork::CanonicalizeURL(Dart_Handle library,
|
||||
Dart_Handle url) {
|
||||
std::string string = blink::StdStringFromDart(url);
|
||||
if (StartsWithASCII(string, "dart:", true))
|
||||
return url;
|
||||
// TODO(abarth): The package root should be configurable.
|
||||
if (StartsWithASCII(string, "package:", true))
|
||||
ReplaceFirstSubstringAfterOffset(&string, 0, "package:", "/packages/");
|
||||
GURL library_url(blink::StdStringFromDart(Dart_LibraryUrl(library)));
|
||||
GURL resolved_url = library_url.Resolve(string);
|
||||
return blink::StdStringToDart(resolved_url.spec());
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_DART_DART_LIBRARY_PROVIDER_NETWORK_H_
|
||||
#define SKY_SHELL_DART_DART_LIBRARY_PROVIDER_NETWORK_H_
|
||||
|
||||
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
|
||||
#include "sky/engine/tonic/dart_library_provider.h"
|
||||
#include "sky/engine/wtf/HashSet.h"
|
||||
#include "sky/engine/wtf/OwnPtr.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class DartLibraryProviderNetwork : public blink::DartLibraryProvider {
|
||||
public:
|
||||
explicit DartLibraryProviderNetwork(mojo::NetworkService* network_service);
|
||||
~DartLibraryProviderNetwork() override;
|
||||
|
||||
mojo::NetworkService* network_service() const { return network_service_; }
|
||||
|
||||
protected:
|
||||
// |DartLibraryProvider| implementation:
|
||||
void GetLibraryAsStream(const std::string& name,
|
||||
blink::DataPipeConsumerCallback callback) override;
|
||||
Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url) override;
|
||||
|
||||
private:
|
||||
class Job;
|
||||
|
||||
mojo::NetworkService* network_service_;
|
||||
HashSet<OwnPtr<Job>> jobs_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DartLibraryProviderNetwork);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_DART_DART_LIBRARY_PROVIDER_NETWORK_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
// 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/gpu/ganesh_context.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
|
||||
#include "ui/gl/gl_bindings_skia_in_process.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
// The limit of the number of GPU resources we hold in the GrContext's
|
||||
// GPU cache.
|
||||
const int kMaxGaneshResourceCacheCount = 2048;
|
||||
|
||||
// The limit of the bytes allocated toward GPU resources in the GrContext's
|
||||
// GPU cache.
|
||||
const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
|
||||
|
||||
} // namespace
|
||||
|
||||
GaneshContext::GaneshContext(scoped_refptr<gfx::GLContext> gl_context)
|
||||
: gl_context_(gl_context) {
|
||||
skia::RefPtr<GrGLInterface> interface =
|
||||
skia::AdoptRef(gfx::CreateInProcessSkiaGLBinding());
|
||||
DCHECK(interface);
|
||||
|
||||
gr_context_ = skia::AdoptRef(GrContext::Create(
|
||||
kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
|
||||
DCHECK(gr_context_) << "Failed to create GrContext.";
|
||||
gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
|
||||
kMaxGaneshResourceCacheBytes);
|
||||
}
|
||||
|
||||
GaneshContext::~GaneshContext() {
|
||||
gr_context_->abandonContext();
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,37 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_GPU_GANESH_CONTEXT_H_
|
||||
#define SKY_SHELL_GPU_GANESH_CONTEXT_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "third_party/skia/include/gpu/GrContext.h"
|
||||
#include "ui/gl/gl_context.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
// GaneshContext holds the top-level context object for Ganesh (known as
|
||||
// GrContext). We construct the GrContext using the OpenGL interface provided by
|
||||
// gfx::GLContext.
|
||||
class GaneshContext {
|
||||
public:
|
||||
explicit GaneshContext(scoped_refptr<gfx::GLContext> gl_context);
|
||||
~GaneshContext();
|
||||
|
||||
GrContext* gr() const { return gr_context_.get(); }
|
||||
|
||||
private:
|
||||
scoped_refptr<gfx::GLContext> gl_context_;
|
||||
skia::RefPtr<GrContext> gr_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GaneshContext);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_GPU_GANESH_CONTEXT_H_
|
||||
@@ -1,34 +0,0 @@
|
||||
// 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/gpu/ganesh_surface.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "third_party/skia/include/gpu/GrContext.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
GaneshSurface::GaneshSurface(intptr_t window_fbo,
|
||||
GaneshContext* context,
|
||||
const gfx::Size& size) {
|
||||
GrBackendRenderTargetDesc desc;
|
||||
desc.fWidth = size.width();
|
||||
desc.fHeight = size.height();
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
||||
desc.fRenderTargetHandle = window_fbo;
|
||||
|
||||
auto target = skia::AdoptRef(
|
||||
context->gr()->textureProvider()->wrapBackendRenderTarget(desc));
|
||||
DCHECK(target);
|
||||
surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect(target.get()));
|
||||
DCHECK(surface_);
|
||||
}
|
||||
|
||||
GaneshSurface::~GaneshSurface() {
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_GPU_GANESH_SURFACE_H_
|
||||
#define SKY_SHELL_GPU_GANESH_SURFACE_H_
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "sky/shell/gpu/ganesh_context.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
// GaneshSurface holds an SkSurface configured to render with Ganesh. Using the
|
||||
// provided GaneshContext, GaneshSurface wraps an SkSurface around the window
|
||||
// bound FBO so that you can use |canvas()| to draw to that window bound FBO.
|
||||
class GaneshSurface {
|
||||
public:
|
||||
GaneshSurface(intptr_t window_fbo,
|
||||
GaneshContext* context,
|
||||
const gfx::Size& size);
|
||||
~GaneshSurface();
|
||||
|
||||
SkCanvas* canvas() const { return surface_->getCanvas(); }
|
||||
gfx::Size size() const {
|
||||
return gfx::Size(surface_->width(), surface_->height());
|
||||
}
|
||||
|
||||
private:
|
||||
skia::RefPtr<SkSurface> surface_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GaneshSurface);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_GPU_GANESH_SURFACE_H_
|
||||
@@ -1,36 +0,0 @@
|
||||
// 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/gpu/picture_serializer.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkData.h"
|
||||
#include "third_party/skia/include/core/SkPixelSerializer.h"
|
||||
#include "third_party/skia/include/core/SkStream.h"
|
||||
#include "ui/gfx/codec/png_codec.h"
|
||||
|
||||
namespace sky {
|
||||
|
||||
class PngPixelSerializer : public SkPixelSerializer {
|
||||
public:
|
||||
bool onUseEncodedData(const void*, size_t) override { return true; }
|
||||
SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
|
||||
size_t row_bytes) override {
|
||||
std::vector<unsigned char> data;
|
||||
|
||||
SkBitmap bm;
|
||||
if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes))
|
||||
return nullptr;
|
||||
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data))
|
||||
return nullptr;
|
||||
return SkData::NewWithCopy(&data.front(), data.size());
|
||||
}
|
||||
};
|
||||
|
||||
void SerializePicture(const char* file_name, SkPicture* picture) {
|
||||
SkFILEWStream stream(file_name);
|
||||
PngPixelSerializer serializer;
|
||||
picture->serialize(&stream, &serializer);
|
||||
}
|
||||
|
||||
} // namespace sky
|
||||
@@ -1,16 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
|
||||
#define SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
|
||||
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
|
||||
namespace sky {
|
||||
|
||||
void SerializePicture(const char* file_name, SkPicture*);
|
||||
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
|
||||
@@ -1,99 +0,0 @@
|
||||
// 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/gpu/rasterizer.h"
|
||||
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "sky/shell/gpu/ganesh_context.h"
|
||||
#include "sky/shell/gpu/ganesh_surface.h"
|
||||
#include "sky/shell/gpu/picture_serializer.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_context.h"
|
||||
#include "ui/gl/gl_share_group.h"
|
||||
#include "ui/gl/gl_surface.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
gfx::Size GetSize(SkPicture* picture) {
|
||||
const SkRect& rect = picture->cullRect();
|
||||
return gfx::Size(rect.width(), rect.height());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Rasterizer::Rasterizer()
|
||||
: share_group_(new gfx::GLShareGroup()), weak_factory_(this) {
|
||||
}
|
||||
|
||||
Rasterizer::~Rasterizer() {
|
||||
}
|
||||
|
||||
base::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
void Rasterizer::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
|
||||
surface_ = gfx::GLSurface::CreateViewGLSurface(widget,
|
||||
gfx::SurfaceConfiguration());
|
||||
CHECK(surface_) << "GLSurface required.";
|
||||
}
|
||||
|
||||
void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) {
|
||||
TRACE_EVENT0("sky", "Rasterizer::Draw");
|
||||
|
||||
if (!surface_)
|
||||
return;
|
||||
|
||||
gfx::Size size = GetSize(picture.get());
|
||||
if (size.IsEmpty())
|
||||
return;
|
||||
|
||||
EnsureGLContext();
|
||||
CHECK(context_->MakeCurrent(surface_.get()));
|
||||
EnsureGaneshSurface(surface_->GetBackingFrameBufferObject(), size);
|
||||
|
||||
DrawPicture(picture.get());
|
||||
surface_->SwapBuffers();
|
||||
|
||||
// SerializePicture("/data/data/org.domokit.sky.demo/cache/layer0.skp", picture.get());
|
||||
}
|
||||
|
||||
void Rasterizer::DrawPicture(SkPicture* picture) {
|
||||
TRACE_EVENT0("sky", "Rasterizer::DrawPicture");
|
||||
SkCanvas* canvas = ganesh_surface_->canvas();
|
||||
canvas->drawPicture(picture);
|
||||
canvas->flush();
|
||||
}
|
||||
|
||||
void Rasterizer::OnOutputSurfaceDestroyed() {
|
||||
CHECK(context_->MakeCurrent(surface_.get()));
|
||||
ganesh_surface_.reset();
|
||||
ganesh_context_.reset();
|
||||
context_ = nullptr;
|
||||
surface_ = nullptr;
|
||||
}
|
||||
|
||||
void Rasterizer::EnsureGLContext() {
|
||||
if (context_)
|
||||
return;
|
||||
context_ = gfx::GLContext::CreateGLContext(share_group_.get(), surface_.get(),
|
||||
gfx::PreferIntegratedGpu);
|
||||
CHECK(context_) << "GLContext required.";
|
||||
CHECK(context_->MakeCurrent(surface_.get()));
|
||||
ganesh_context_.reset(new GaneshContext(context_.get()));
|
||||
}
|
||||
|
||||
void Rasterizer::EnsureGaneshSurface(intptr_t window_fbo,
|
||||
const gfx::Size& size) {
|
||||
if (!ganesh_surface_ || ganesh_surface_->size() != size)
|
||||
ganesh_surface_.reset(
|
||||
new GaneshSurface(window_fbo, ganesh_context_.get(), size));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,59 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_GPU_RASTERIZER_H_
|
||||
#define SKY_SHELL_GPU_RASTERIZER_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "sky/shell/gpu_delegate.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
|
||||
class SkPicture;
|
||||
|
||||
namespace gfx {
|
||||
class GLContext;
|
||||
class GLShareGroup;
|
||||
class GLSurface;
|
||||
}
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class GaneshContext;
|
||||
class GaneshSurface;
|
||||
|
||||
class Rasterizer : public GPUDelegate {
|
||||
public:
|
||||
explicit Rasterizer();
|
||||
~Rasterizer() override;
|
||||
|
||||
base::WeakPtr<Rasterizer> GetWeakPtr();
|
||||
|
||||
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
|
||||
void OnOutputSurfaceDestroyed() override;
|
||||
void Draw(skia::RefPtr<SkPicture> picture) override;
|
||||
|
||||
private:
|
||||
void EnsureGLContext();
|
||||
void EnsureGaneshSurface(intptr_t window_fbo, const gfx::Size& size);
|
||||
void DrawPicture(SkPicture* picture);
|
||||
|
||||
scoped_refptr<gfx::GLShareGroup> share_group_;
|
||||
scoped_refptr<gfx::GLSurface> surface_;
|
||||
scoped_refptr<gfx::GLContext> context_;
|
||||
|
||||
scoped_ptr<GaneshContext> ganesh_context_;
|
||||
scoped_ptr<GaneshSurface> ganesh_surface_;
|
||||
|
||||
base::WeakPtrFactory<Rasterizer> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Rasterizer);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_GPU_RASTERIZER_H_
|
||||
@@ -1,14 +0,0 @@
|
||||
// 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/gpu_delegate.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
GPUDelegate::~GPUDelegate() {
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,29 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_GPU_DELEGATE_H_
|
||||
#define SKY_SHELL_GPU_DELEGATE_H_
|
||||
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
|
||||
class SkPicture;
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class GPUDelegate {
|
||||
public:
|
||||
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0;
|
||||
virtual void OnOutputSurfaceDestroyed() = 0;
|
||||
virtual void Draw(skia::RefPtr<SkPicture> picture) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~GPUDelegate();
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_GPU_DELEGATE_H_
|
||||
3
engine/src/flutter/shell/ios/.gitignore
vendored
3
engine/src/flutter/shell/ios/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
*.pbxproj
|
||||
*.xcworkspace
|
||||
*.xcodeproj
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>application-identifier</key>
|
||||
<string>F5T262WGN6.com.google.sky</string>
|
||||
<key>com.apple.developer.team-identifier</key>
|
||||
<string>F5T262WGN6</string>
|
||||
<key>get-task-allow</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>F5T262WGN6.com.google.sky</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
|
||||
<!--
|
||||
This executable name must match the name of the app provided to the
|
||||
ios_app GN template
|
||||
-->
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>Sky</string>
|
||||
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.google.sky</string>
|
||||
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Sky</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
|
||||
<!--
|
||||
mojo:// URL handlers
|
||||
-->
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Viewer</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>com.google.mojo</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>mojo</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
||||
<!--
|
||||
Sky Load URL
|
||||
-->
|
||||
<key>com.google.sky.load_url</key>
|
||||
<string>https://domokit.github.io/home.dart</string>
|
||||
|
||||
<!--
|
||||
FIXME(csg): Xcode, as part of its build process, adds the following
|
||||
items to the Info.plist. It is not immediately clear if there is a
|
||||
command line utility that generates these. For now, just add the same
|
||||
manually
|
||||
-->
|
||||
<key>DTPlatformName</key>
|
||||
<string>iphonesimulator</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>iphonesimulator8.3</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>8.3</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>iPhoneSimulator</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,70 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#include <asl.h>
|
||||
#import "sky_app_delegate.h"
|
||||
#include "base/at_exit.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "ui/gl/gl_surface.h"
|
||||
|
||||
extern "C" {
|
||||
// TODO(csg): HACK! boringssl accesses this on Android using a weak symbol
|
||||
// instead of a global. Till the patch for that lands and propagates to Sky, we
|
||||
// specify the same here to get workable builds on iOS. This is a hack! Will
|
||||
// go away.
|
||||
unsigned long getauxval(unsigned long type) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void InitializeLogging() {
|
||||
logging::LoggingSettings settings;
|
||||
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
||||
logging::InitLogging(settings);
|
||||
logging::SetLogItems(false, // Process ID
|
||||
false, // Thread ID
|
||||
false, // Timestamp
|
||||
false); // Tick count
|
||||
}
|
||||
|
||||
static void RedirectIOConnectionsToSyslog() {
|
||||
asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO,
|
||||
ASL_LOG_DESCRIPTOR_WRITE);
|
||||
asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO,
|
||||
ASL_LOG_DESCRIPTOR_WRITE);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
static void SkyDebuggerHookMain(void) {
|
||||
// By default, LLDB breaks way too early. This is before libraries have been
|
||||
// loaded and __attribute__((constructor)) methods have been called. In most
|
||||
// situations, this is unnecessary. Also, breakpoint resolution is not
|
||||
// immediate. So we provide this hook to break on.
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#ifndef NDEBUG
|
||||
SkyDebuggerHookMain();
|
||||
#endif
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
base::AtExitManager exit_manager;
|
||||
RedirectIOConnectionsToSyslog();
|
||||
auto result = false;
|
||||
result = base::CommandLine::Init(0, nullptr);
|
||||
DLOG_ASSERT(result);
|
||||
InitializeLogging();
|
||||
result = base::i18n::InitializeICU();
|
||||
DLOG_ASSERT(result);
|
||||
result = gfx::GLSurface::InitializeOneOff();
|
||||
DLOG_ASSERT(result);
|
||||
return UIApplicationMain(argc, argv, nil,
|
||||
NSStringFromClass([SkyAppDelegate class]));
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// 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/engine/wtf/Assertions.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/location.h"
|
||||
#include "mojo/public/cpp/application/service_provider_impl.h"
|
||||
#include "sky/services/ns_net/network_service_impl.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
// FIXME(csg): Put this in an application owned context
|
||||
base::LazyInstance<scoped_ptr<mojo::ServiceProviderImpl>> g_service_provider =
|
||||
LAZY_INSTANCE_INITIALIZER;
|
||||
base::LazyInstance<scoped_ptr<mojo::NetworkServiceFactory>>
|
||||
g_network_service_factory = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
static void CreatePlatformServiceProvider(
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
|
||||
g_service_provider.Get().reset(new mojo::ServiceProviderImpl(request.Pass()));
|
||||
g_network_service_factory.Get().reset(new mojo::NetworkServiceFactory());
|
||||
g_service_provider.Get()->AddService(g_network_service_factory.Get().get());
|
||||
}
|
||||
|
||||
mojo::ServiceProviderPtr CreateServiceProvider(
|
||||
ServiceProviderContext* context) {
|
||||
DCHECK(context);
|
||||
mojo::MessagePipe pipe;
|
||||
auto request = mojo::MakeRequest<mojo::ServiceProvider>(pipe.handle1.Pass());
|
||||
context->platform_task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(CreatePlatformServiceProvider, base::Passed(request.Pass())));
|
||||
return mojo::MakeProxy(
|
||||
mojo::InterfacePtrInfo<mojo::ServiceProvider>(pipe.handle0.Pass(), 0u));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,27 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_PLATFORM_VIEW_IOS_H_
|
||||
#define SKY_SHELL_PLATFORM_VIEW_IOS_H_
|
||||
|
||||
#include "sky/shell/platform_view.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class PlatformViewIOS : public PlatformView {
|
||||
public:
|
||||
explicit PlatformViewIOS(const Config& config);
|
||||
~PlatformViewIOS() override;
|
||||
void SurfaceCreated(gfx::AcceleratedWidget widget);
|
||||
void SurfaceDestroyed(void);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_PLATFORM_VIEW_IOS_H_
|
||||
@@ -1,34 +0,0 @@
|
||||
// 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 "platform_view_ios.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
PlatformView* PlatformView::Create(const Config& config) {
|
||||
return new PlatformViewIOS(config);
|
||||
}
|
||||
|
||||
PlatformViewIOS::PlatformViewIOS(const Config& config)
|
||||
: PlatformView(config) {
|
||||
}
|
||||
|
||||
PlatformViewIOS::~PlatformViewIOS() {
|
||||
}
|
||||
|
||||
void PlatformViewIOS::SurfaceCreated(gfx::AcceleratedWidget widget) {
|
||||
DCHECK(window_ == 0);
|
||||
window_ = widget;
|
||||
SurfaceWasCreated();
|
||||
}
|
||||
|
||||
void PlatformViewIOS::SurfaceDestroyed() {
|
||||
DCHECK(window_);
|
||||
window_ = 0;
|
||||
SurfaceWasDestroyed();
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,11 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface SkyAppDelegate : UIResponder<UIApplicationDelegate>
|
||||
|
||||
@property(strong, nonatomic) UIWindow* window;
|
||||
|
||||
@end
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import "sky_app_delegate.h"
|
||||
#import "sky_view_controller.h"
|
||||
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "sky/shell/ui_delegate.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
|
||||
@implementation SkyAppDelegate {
|
||||
base::LazyInstance<scoped_ptr<base::MessageLoop>> _main_message_loop;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication*)application
|
||||
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
|
||||
[self setupSkyShell];
|
||||
[self setupViewport];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setupSkyShell {
|
||||
[self adoptPlatformRunLoop];
|
||||
|
||||
auto service_provider_context =
|
||||
make_scoped_ptr(new sky::shell::ServiceProviderContext(
|
||||
_main_message_loop.Get()->task_runner()));
|
||||
sky::shell::Shell::Init(service_provider_context.Pass());
|
||||
}
|
||||
|
||||
- (void)adoptPlatformRunLoop {
|
||||
_main_message_loop.Get().reset(new base::MessageLoopForUI);
|
||||
// One cannot start the message loop on the platform main thread. Instead,
|
||||
// we attach to the CFRunLoop
|
||||
base::MessageLoopForUI::current()->Attach();
|
||||
}
|
||||
|
||||
- (void)setupViewport {
|
||||
CGRect frame = [UIScreen mainScreen].bounds;
|
||||
UIWindow* window = [[UIWindow alloc] initWithFrame:frame];
|
||||
SkyViewController* viewController = [[SkyViewController alloc] init];
|
||||
window.rootViewController = viewController;
|
||||
[viewController release];
|
||||
self.window = window;
|
||||
[window release];
|
||||
[self.window makeKeyAndVisible];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,12 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "sky/shell/shell_view.h"
|
||||
|
||||
@interface SkySurface : UIView
|
||||
|
||||
-(instancetype) initWithShellView:(sky::shell::ShellView *) shellView;
|
||||
|
||||
@end
|
||||
@@ -1,298 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import "sky_surface.h"
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <OpenGLES/EAGL.h>
|
||||
#import <OpenGLES/EAGLDrawable.h>
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "sky/services/engine/input_event.mojom.h"
|
||||
#include "sky/shell/ios/platform_view_ios.h"
|
||||
#include "sky/shell/shell_view.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/ui_delegate.h"
|
||||
|
||||
static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
|
||||
switch (phase) {
|
||||
case UITouchPhaseBegan:
|
||||
return sky::EVENT_TYPE_POINTER_DOWN;
|
||||
case UITouchPhaseMoved:
|
||||
case UITouchPhaseStationary:
|
||||
// There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
|
||||
// with the same coordinates
|
||||
return sky::EVENT_TYPE_POINTER_MOVE;
|
||||
case UITouchPhaseEnded:
|
||||
return sky::EVENT_TYPE_POINTER_UP;
|
||||
case UITouchPhaseCancelled:
|
||||
return sky::EVENT_TYPE_POINTER_CANCEL;
|
||||
}
|
||||
|
||||
return sky::EVENT_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
static inline int64 InputEventTimestampFromNSTimeInterval(
|
||||
NSTimeInterval interval) {
|
||||
return base::TimeDelta::FromSecondsD(interval).InMilliseconds();
|
||||
}
|
||||
|
||||
static sky::InputEventPtr BasicInputEventFromRecognizer(
|
||||
sky::EventType type,
|
||||
UIGestureRecognizer* recognizer) {
|
||||
auto input = sky::InputEvent::New();
|
||||
input->type = type;
|
||||
input->time_stamp = InputEventTimestampFromNSTimeInterval(
|
||||
CACurrentMediaTime());
|
||||
|
||||
input->gesture_data = sky::GestureData::New();
|
||||
|
||||
CGPoint windowCoordinates = [recognizer locationInView:recognizer.view];
|
||||
const CGFloat scale = [UIScreen mainScreen].scale;
|
||||
input->gesture_data->x = windowCoordinates.x * scale;
|
||||
input->gesture_data->y = windowCoordinates.y * scale;
|
||||
return input.Pass();
|
||||
}
|
||||
|
||||
@implementation SkySurface {
|
||||
BOOL _platformViewInitialized;
|
||||
|
||||
sky::SkyEnginePtr _sky_engine;
|
||||
scoped_ptr<sky::shell::ShellView> _shell_view;
|
||||
}
|
||||
|
||||
-(instancetype) initWithShellView:(sky::shell::ShellView *) shellView {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_shell_view.reset(shellView);
|
||||
[self installGestureRecognizers];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (gfx::AcceleratedWidget)acceleratedWidget {
|
||||
return (gfx::AcceleratedWidget)self.layer;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
[self configureLayerDefaults];
|
||||
|
||||
[self setupPlatformViewIfNecessary];
|
||||
|
||||
CGSize size = self.bounds.size;
|
||||
CGFloat scale = [UIScreen mainScreen].scale;
|
||||
|
||||
sky::ViewportMetricsPtr metrics = sky::ViewportMetrics::New();
|
||||
metrics->physical_width = size.width * scale;
|
||||
metrics->physical_height = size.height * scale;
|
||||
metrics->device_pixel_ratio = scale;
|
||||
_sky_engine->OnViewportMetricsChanged(metrics.Pass());
|
||||
}
|
||||
|
||||
- (void)configureLayerDefaults {
|
||||
CAEAGLLayer* layer = reinterpret_cast<CAEAGLLayer*>(self.layer);
|
||||
layer.allowsGroupOpacity = YES;
|
||||
layer.opaque = YES;
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
layer.contentsScale = screenScale;
|
||||
// Note: shouldRasterize is still NO. This is just a defensive measure
|
||||
layer.rasterizationScale = screenScale;
|
||||
}
|
||||
|
||||
- (void)setupPlatformViewIfNecessary {
|
||||
if (_platformViewInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
_platformViewInitialized = YES;
|
||||
|
||||
[self notifySurfaceCreation];
|
||||
[self connectToEngineAndLoad];
|
||||
}
|
||||
|
||||
- (sky::shell::PlatformViewIOS*)platformView {
|
||||
auto view = static_cast<sky::shell::PlatformViewIOS*>(_shell_view->view());
|
||||
DCHECK(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)notifySurfaceCreation {
|
||||
self.platformView->SurfaceCreated(self.acceleratedWidget);
|
||||
}
|
||||
|
||||
- (NSString*)skyInitialLoadURL {
|
||||
return [NSBundle mainBundle].infoDictionary[@"com.google.sky.load_url"];
|
||||
}
|
||||
|
||||
- (void)connectToEngineAndLoad {
|
||||
auto interface_request = mojo::GetProxy(&_sky_engine);
|
||||
self.platformView->ConnectToEngine(interface_request.Pass());
|
||||
|
||||
mojo::String string(self.skyInitialLoadURL.UTF8String);
|
||||
_sky_engine->RunFromNetwork(string);
|
||||
}
|
||||
|
||||
- (void)notifySurfaceDestruction {
|
||||
self.platformView->SurfaceDestroyed();
|
||||
}
|
||||
|
||||
#pragma mark - UIResponder overrides for raw touches
|
||||
|
||||
- (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
|
||||
auto eventType = EventTypeFromUITouchPhase(phase);
|
||||
const CGFloat scale = [UIScreen mainScreen].scale;
|
||||
|
||||
for (UITouch* touch in touches) {
|
||||
auto input = sky::InputEvent::New();
|
||||
input->type = eventType;
|
||||
input->time_stamp = InputEventTimestampFromNSTimeInterval(touch.timestamp);
|
||||
|
||||
input->pointer_data = sky::PointerData::New();
|
||||
input->pointer_data->kind = sky::POINTER_KIND_TOUCH;
|
||||
|
||||
CGPoint windowCoordinates = [touch locationInView:nil];
|
||||
|
||||
input->pointer_data->x = windowCoordinates.x * scale;
|
||||
input->pointer_data->y = windowCoordinates.y * scale;
|
||||
|
||||
_sky_engine->OnInputEvent(input.Pass());
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
[self dispatchTouches:touches phase:UITouchPhaseBegan];
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
[self dispatchTouches:touches phase:UITouchPhaseMoved];
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
[self dispatchTouches:touches phase:UITouchPhaseEnded];
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
|
||||
[self dispatchTouches:touches phase:UITouchPhaseCancelled];
|
||||
}
|
||||
|
||||
#pragma mark - Gesture Recognizers
|
||||
|
||||
-(void) installGestureRecognizers {
|
||||
// For:
|
||||
// GESTURE_FLING_CANCEL
|
||||
// GESTURE_FLING_START
|
||||
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(onFling:)];
|
||||
[self addGestureRecognizer: swipe];
|
||||
[swipe release];
|
||||
|
||||
// For:
|
||||
// GESTURE_LONG_PRESS
|
||||
// GESTURE_SHOW_PRESS
|
||||
UILongPressGestureRecognizer *longPress =
|
||||
[[UILongPressGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(onLongPress:)];
|
||||
[self addGestureRecognizer: longPress];
|
||||
[longPress release];
|
||||
|
||||
// For:
|
||||
// GESTURE_SCROLL_BEGIN
|
||||
// GESTURE_SCROLL_END
|
||||
// GESTURE_SCROLL_UPDATE
|
||||
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(onScroll:)];
|
||||
[self addGestureRecognizer: pan];
|
||||
[pan release];
|
||||
|
||||
// For:
|
||||
// GESTURE_TAP
|
||||
// GESTURE_TAP_DOWN
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
|
||||
initWithTarget:self action:@selector(onTap:)];
|
||||
[self addGestureRecognizer: tap];
|
||||
[tap release];
|
||||
}
|
||||
|
||||
-(void) onFling:(UISwipeGestureRecognizer *) recognizer {
|
||||
// Swipes are discrete gestures already. So there is no equivalent to a cancel
|
||||
if (recognizer.state != UIGestureRecognizerStateEnded) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto input = BasicInputEventFromRecognizer(
|
||||
sky::EVENT_TYPE_GESTURE_FLING_START, recognizer);
|
||||
_sky_engine->OnInputEvent(input.Pass());
|
||||
}
|
||||
|
||||
-(void) onLongPress:(UILongPressGestureRecognizer *) recognizer {
|
||||
if (recognizer.state != UIGestureRecognizerStateEnded) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto input = BasicInputEventFromRecognizer(sky::EVENT_TYPE_GESTURE_LONG_PRESS,
|
||||
recognizer);
|
||||
_sky_engine->OnInputEvent(input.Pass());
|
||||
}
|
||||
|
||||
-(void) onScroll:(UIPanGestureRecognizer *) recognizer {
|
||||
sky::EventType type = sky::EVENT_TYPE_UNKNOWN;
|
||||
switch (recognizer.state) {
|
||||
case UIGestureRecognizerStateBegan:
|
||||
type = sky::EVENT_TYPE_GESTURE_SCROLL_BEGIN;
|
||||
break;
|
||||
case UIGestureRecognizerStateChanged:
|
||||
type = sky::EVENT_TYPE_GESTURE_SCROLL_UPDATE;
|
||||
break;
|
||||
case UIGestureRecognizerStateEnded:
|
||||
case UIGestureRecognizerStateCancelled:
|
||||
case UIGestureRecognizerStateFailed:
|
||||
type = sky::EVENT_TYPE_GESTURE_SCROLL_END;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (type == sky::EVENT_TYPE_UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto input = BasicInputEventFromRecognizer(type, recognizer);
|
||||
auto scale = [UIScreen mainScreen].scale;
|
||||
auto translation = [recognizer translationInView: self];
|
||||
auto velocity = [recognizer velocityInView: self];
|
||||
|
||||
input->gesture_data->dx = translation.x * scale;
|
||||
input->gesture_data->dy = translation.y * scale;
|
||||
input->gesture_data->velocityX = velocity.x * scale;
|
||||
input->gesture_data->velocityY = velocity.y * scale;
|
||||
|
||||
_sky_engine->OnInputEvent(input.Pass());
|
||||
}
|
||||
|
||||
-(void) onTap:(UITapGestureRecognizer *) recognizer {
|
||||
|
||||
if (recognizer.state != UIGestureRecognizerStateEnded) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto input = BasicInputEventFromRecognizer(sky::EVENT_TYPE_GESTURE_TAP,
|
||||
recognizer);
|
||||
_sky_engine->OnInputEvent(input.Pass());
|
||||
}
|
||||
|
||||
#pragma mark - Misc.
|
||||
|
||||
+ (Class)layerClass {
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self notifySurfaceDestruction];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,9 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface SkyViewController : UIViewController
|
||||
|
||||
@end
|
||||
@@ -1,28 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#import "sky_view_controller.h"
|
||||
#import "sky_surface.h"
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/shell_view.h"
|
||||
|
||||
@implementation SkyViewController
|
||||
|
||||
- (void)loadView {
|
||||
auto shell_view = new sky::shell::ShellView(sky::shell::Shell::Shared());
|
||||
SkySurface* surface = [[SkySurface alloc] initWithShellView: shell_view];
|
||||
|
||||
surface.autoresizingMask =
|
||||
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
self.view = surface;
|
||||
|
||||
[surface release];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,89 +0,0 @@
|
||||
// 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 <iostream>
|
||||
|
||||
#include "base/at_exit.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "sky/engine/public/web/WebRuntimeFeatures.h"
|
||||
#include "sky/shell/platform_view.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/shell_view.h"
|
||||
#include "sky/shell/switches.h"
|
||||
#include "sky/shell/testing/test_runner.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
void Usage() {
|
||||
std::cerr << "Usage: sky_shell"
|
||||
<< " --" << switches::kNonInteractive
|
||||
<< " --" << switches::kPackageRoot << "=PACKAGE_ROOT"
|
||||
<< " --" << switches::kSnapshot << "=SNAPSHOT"
|
||||
<< " [ MAIN_DART ]" << std::endl;
|
||||
}
|
||||
|
||||
void Init() {
|
||||
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
|
||||
blink::WebRuntimeFeatures::enableObservatory(
|
||||
!command_line.HasSwitch(switches::kNonInteractive));
|
||||
|
||||
Shell::Init(make_scoped_ptr(new ServiceProviderContext(
|
||||
base::MessageLoop::current()->task_runner())));
|
||||
// Explicitly boot the shared test runner.
|
||||
TestRunner& runner = TestRunner::Shared();
|
||||
|
||||
std::string package_root =
|
||||
command_line.GetSwitchValueASCII(switches::kPackageRoot);
|
||||
runner.set_package_root(package_root);
|
||||
|
||||
scoped_ptr<TestRunner::SingleTest> single_test;
|
||||
if (command_line.HasSwitch(switches::kSnapshot)) {
|
||||
single_test.reset(new TestRunner::SingleTest);
|
||||
single_test->path = command_line.GetSwitchValueASCII(switches::kSnapshot);
|
||||
single_test->is_snapshot = true;
|
||||
} else {
|
||||
auto args = command_line.GetArgs();
|
||||
if (!args.empty()) {
|
||||
single_test.reset(new TestRunner::SingleTest);
|
||||
single_test->path = args[0];
|
||||
}
|
||||
}
|
||||
|
||||
runner.Start(single_test.Pass());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
base::AtExitManager exit_manager;
|
||||
base::CommandLine::Init(argc, argv);
|
||||
|
||||
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (command_line.HasSwitch(sky::shell::switches::kHelp) ||
|
||||
(!command_line.HasSwitch(sky::shell::switches::kPackageRoot) &&
|
||||
!command_line.HasSwitch(sky::shell::switches::kSnapshot))) {
|
||||
sky::shell::Usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
base::MessageLoop message_loop;
|
||||
|
||||
base::i18n::InitializeICU();
|
||||
|
||||
message_loop.PostTask(FROM_HERE, base::Bind(&sky::shell::Init));
|
||||
message_loop.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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 "base/bind.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/location.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "mojo/public/cpp/application/service_provider_impl.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "sky/shell/testing/test_runner.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
base::LazyInstance<scoped_ptr<mojo::ServiceProviderImpl>> g_service_provider =
|
||||
LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
static void CreateServiceProviderImpl(
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> request) {
|
||||
g_service_provider.Get().reset(new mojo::ServiceProviderImpl(request.Pass()));
|
||||
g_service_provider.Get()->AddService(&TestRunner::Shared());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
mojo::ServiceProviderPtr CreateServiceProvider(
|
||||
ServiceProviderContext* context) {
|
||||
DCHECK(context);
|
||||
mojo::MessagePipe pipe;
|
||||
auto request = mojo::MakeRequest<mojo::ServiceProvider>(pipe.handle1.Pass());
|
||||
context->platform_task_runner->PostTask(
|
||||
FROM_HERE, base::Bind(CreateServiceProviderImpl, base::Passed(&request)));
|
||||
return mojo::MakeProxy(
|
||||
mojo::InterfacePtrInfo<mojo::ServiceProvider>(pipe.handle0.Pass(), 0u));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,15 +0,0 @@
|
||||
// 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/platform_view.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
PlatformView* PlatformView::Create(const Config& config) {
|
||||
return new PlatformView(config);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,47 +0,0 @@
|
||||
// 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/platform_view.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/location.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
PlatformView::Config::Config() {
|
||||
}
|
||||
|
||||
PlatformView::Config::~Config() {
|
||||
}
|
||||
|
||||
PlatformView::PlatformView(const PlatformView::Config& config)
|
||||
: config_(config), window_(0) {
|
||||
}
|
||||
|
||||
PlatformView::~PlatformView() {
|
||||
}
|
||||
|
||||
void PlatformView::ConnectToEngine(
|
||||
mojo::InterfaceRequest<SkyEngine> request) {
|
||||
config_.ui_task_runner->PostTask(
|
||||
FROM_HERE, base::Bind(&UIDelegate::ConnectToEngine,
|
||||
config_.ui_delegate, base::Passed(&request)));
|
||||
}
|
||||
|
||||
void PlatformView::SurfaceWasCreated() {
|
||||
config_.ui_task_runner->PostTask(
|
||||
FROM_HERE, base::Bind(&UIDelegate::OnAcceleratedWidgetAvailable,
|
||||
config_.ui_delegate, window_));
|
||||
}
|
||||
|
||||
void PlatformView::SurfaceWasDestroyed() {
|
||||
config_.ui_task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, config_.ui_delegate));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,47 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_PLATFORM_VIEW_H_
|
||||
#define SKY_SHELL_PLATFORM_VIEW_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "sky/shell/ui_delegate.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class PlatformView {
|
||||
public:
|
||||
struct Config {
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
base::WeakPtr<UIDelegate> ui_delegate;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner;
|
||||
};
|
||||
|
||||
static PlatformView* Create(const Config& config);
|
||||
|
||||
virtual ~PlatformView();
|
||||
|
||||
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request);
|
||||
|
||||
protected:
|
||||
explicit PlatformView(const Config& config);
|
||||
|
||||
void SurfaceWasCreated();
|
||||
void SurfaceWasDestroyed();
|
||||
|
||||
Config config_;
|
||||
gfx::AcceleratedWidget window_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformView);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_PLATFORM_VIEW_H_
|
||||
@@ -1,20 +0,0 @@
|
||||
// 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/service_provider.h"
|
||||
|
||||
#include "base/single_thread_task_runner.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
ServiceProviderContext::ServiceProviderContext(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> runner)
|
||||
: platform_task_runner(runner.Pass()) {}
|
||||
|
||||
ServiceProviderContext::~ServiceProviderContext() {
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,33 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_SERVICE_PROVIDER_H_
|
||||
#define SKY_SHELL_SERVICE_PROVIDER_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
|
||||
namespace base {
|
||||
class SingleThreadTaskRunner;
|
||||
}
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class ServiceProviderContext {
|
||||
public:
|
||||
ServiceProviderContext(scoped_refptr<base::SingleThreadTaskRunner> runner);
|
||||
~ServiceProviderContext();
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> platform_task_runner;
|
||||
};
|
||||
|
||||
// Implemented in platform_service_provider.cc for each platform.
|
||||
mojo::ServiceProviderPtr CreateServiceProvider(ServiceProviderContext* context);
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_SERVICE_PROVIDER_H_
|
||||
@@ -1,57 +0,0 @@
|
||||
// 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/shell.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "mojo/common/message_pump_mojo.h"
|
||||
#include "mojo/edk/embedder/embedder.h"
|
||||
#include "mojo/edk/embedder/simple_platform_support.h"
|
||||
#include "sky/shell/ui/engine.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
static Shell* g_shell = nullptr;
|
||||
|
||||
scoped_ptr<base::MessagePump> CreateMessagePumpMojo() {
|
||||
return make_scoped_ptr(new mojo::common::MessagePumpMojo);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context)
|
||||
: service_provider_context_(service_provider_context.Pass()) {
|
||||
DCHECK(!g_shell);
|
||||
mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>(
|
||||
new mojo::embedder::SimplePlatformSupport()));
|
||||
|
||||
base::Thread::Options options;
|
||||
options.message_pump_factory = base::Bind(&CreateMessagePumpMojo);
|
||||
|
||||
gpu_thread_.reset(new base::Thread("gpu_thread"));
|
||||
gpu_thread_->StartWithOptions(options);
|
||||
|
||||
ui_thread_.reset(new base::Thread("ui_thread"));
|
||||
ui_thread_->StartWithOptions(options);
|
||||
|
||||
ui_task_runner()->PostTask(FROM_HERE, base::Bind(&Engine::Init));
|
||||
}
|
||||
|
||||
Shell::~Shell() {
|
||||
}
|
||||
|
||||
void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) {
|
||||
g_shell = new Shell(service_provider_context.Pass());
|
||||
}
|
||||
|
||||
Shell& Shell::Shared() {
|
||||
DCHECK(g_shell);
|
||||
return *g_shell;
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,55 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_SHELL_H_
|
||||
#define SKY_SHELL_SHELL_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class ServiceProviderContext;
|
||||
|
||||
class Shell {
|
||||
public:
|
||||
~Shell();
|
||||
|
||||
static void Init(
|
||||
scoped_ptr<ServiceProviderContext> service_provider_context);
|
||||
static Shell& Shared();
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner() const {
|
||||
return gpu_thread_->message_loop()->task_runner();
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() const {
|
||||
return ui_thread_->message_loop()->task_runner();
|
||||
}
|
||||
|
||||
ServiceProviderContext* service_provider_context() const {
|
||||
return service_provider_context_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
explicit Shell(scoped_ptr<ServiceProviderContext> service_provider_context);
|
||||
|
||||
void InitGPU(const base::Thread::Options& options);
|
||||
void InitUI(const base::Thread::Options& options);
|
||||
|
||||
scoped_ptr<base::Thread> gpu_thread_;
|
||||
scoped_ptr<base::Thread> ui_thread_;
|
||||
scoped_ptr<ServiceProviderContext> service_provider_context_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Shell);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_SHELL_H_
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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/shell_view.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "sky/shell/gpu/rasterizer.h"
|
||||
#include "sky/shell/platform_view.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/ui/engine.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
void Drop(scoped_ptr<T> ptr) { }
|
||||
|
||||
} // namespace
|
||||
|
||||
ShellView::ShellView(Shell& shell)
|
||||
: shell_(shell) {
|
||||
rasterizer_.reset(new Rasterizer());
|
||||
CreateEngine();
|
||||
CreatePlatformView();
|
||||
}
|
||||
|
||||
ShellView::~ShellView() {
|
||||
shell_.gpu_task_runner()->PostTask(FROM_HERE,
|
||||
base::Bind(&Drop<Rasterizer>, base::Passed(&rasterizer_)));
|
||||
shell_.ui_task_runner()->PostTask(FROM_HERE,
|
||||
base::Bind(&Drop<Engine>, base::Passed(&engine_)));
|
||||
}
|
||||
|
||||
void ShellView::CreateEngine() {
|
||||
Engine::Config config;
|
||||
config.service_provider_context = shell_.service_provider_context();
|
||||
config.gpu_task_runner = shell_.gpu_task_runner();
|
||||
config.gpu_delegate = rasterizer_->GetWeakPtr();
|
||||
engine_.reset(new Engine(config));
|
||||
}
|
||||
|
||||
void ShellView::CreatePlatformView() {
|
||||
PlatformView::Config config;
|
||||
config.ui_task_runner = shell_.ui_task_runner();
|
||||
config.ui_delegate = engine_->GetWeakPtr();
|
||||
view_.reset(PlatformView::Create(config));
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,40 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_SHELL_VIEW_H_
|
||||
#define SKY_SHELL_SHELL_VIEW_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class Engine;
|
||||
class PlatformView;
|
||||
class Rasterizer;
|
||||
class Shell;
|
||||
|
||||
class ShellView {
|
||||
public:
|
||||
explicit ShellView(Shell& shell);
|
||||
~ShellView();
|
||||
|
||||
PlatformView* view() const { return view_.get(); }
|
||||
|
||||
private:
|
||||
void CreateEngine();
|
||||
void CreatePlatformView();
|
||||
|
||||
Shell& shell_;
|
||||
scoped_ptr<PlatformView> view_;
|
||||
scoped_ptr<Rasterizer> rasterizer_;
|
||||
scoped_ptr<Engine> engine_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ShellView);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_SHELL_VIEW_H_
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright 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 "sky/shell/switches.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace switches {
|
||||
|
||||
const char kHelp[] = "help";
|
||||
const char kNonInteractive[] = "non-interactive";
|
||||
const char kPackageRoot[] = "package-root";
|
||||
const char kSnapshot[] = "snapshot";
|
||||
|
||||
} // namespace switches
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef SKY_SHELL_SWITCHES_H_
|
||||
#define SKY_SHELL_SWITCHES_H_
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace switches {
|
||||
|
||||
extern const char kHelp[];
|
||||
extern const char kPackageRoot[];
|
||||
extern const char kNonInteractive[];
|
||||
extern const char kSnapshot[];
|
||||
|
||||
} // namespace switches
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_SWITCHES_H_
|
||||
@@ -1,137 +0,0 @@
|
||||
// Copyright 2014 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/testing/test_runner.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "sky/shell/platform_view.h"
|
||||
#include "sky/shell/shell.h"
|
||||
#include "sky/shell/shell_view.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
struct UrlData {
|
||||
std::string url;
|
||||
std::string expected_pixel_hash;
|
||||
bool enable_pixel_dumping = false;
|
||||
bool is_snapshot = false;
|
||||
};
|
||||
|
||||
void WaitForURL(UrlData& data) {
|
||||
// A test name is formated like file:///path/to/test'--pixel-test'pixelhash
|
||||
std::cin >> data.url;
|
||||
|
||||
std::string pixel_switch;
|
||||
std::string::size_type separator_position = data.url.find('\'');
|
||||
if (separator_position != std::string::npos) {
|
||||
pixel_switch = data.url.substr(separator_position + 1);
|
||||
data.url.erase(separator_position);
|
||||
}
|
||||
|
||||
std::string pixel_hash;
|
||||
separator_position = pixel_switch.find('\'');
|
||||
if (separator_position != std::string::npos) {
|
||||
pixel_hash = pixel_switch.substr(separator_position + 1);
|
||||
pixel_switch.erase(separator_position);
|
||||
}
|
||||
|
||||
data.enable_pixel_dumping = pixel_switch == "--pixel-test";
|
||||
data.expected_pixel_hash = pixel_hash;
|
||||
}
|
||||
|
||||
void PrintAndFlush(const std::string& value) {
|
||||
std::cout << value;
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
const char kFileUrlPrefix[] = "file://";
|
||||
static TestRunner* g_test_runner = nullptr;
|
||||
|
||||
} // namespace
|
||||
|
||||
TestRunner::TestRunner()
|
||||
: shell_view_(new ShellView(Shell::Shared())),
|
||||
weak_ptr_factory_(this) {
|
||||
CHECK(!g_test_runner) << "Only create one TestRunner.";
|
||||
|
||||
shell_view_->view()->ConnectToEngine(GetProxy(&sky_engine_));
|
||||
ViewportMetricsPtr metrics = ViewportMetrics::New();
|
||||
metrics->physical_width = 800;
|
||||
metrics->physical_height = 600;
|
||||
sky_engine_->OnViewportMetricsChanged(metrics.Pass());
|
||||
}
|
||||
|
||||
TestRunner::~TestRunner() {
|
||||
}
|
||||
|
||||
TestRunner& TestRunner::Shared() {
|
||||
if (!g_test_runner)
|
||||
g_test_runner = new TestRunner();
|
||||
return *g_test_runner;
|
||||
}
|
||||
|
||||
void TestRunner::Start(scoped_ptr<SingleTest> single_test) {
|
||||
single_test_ = single_test.Pass();
|
||||
PrintAndFlush("#READY\n");
|
||||
ScheduleRun();
|
||||
}
|
||||
|
||||
void TestRunner::OnTestComplete(const mojo::String& test_result,
|
||||
const mojo::Array<uint8_t> pixels) {
|
||||
std::cout << "Content-Type: text/plain\n";
|
||||
std::cout << test_result << "\n";
|
||||
PrintAndFlush("#EOF\n"); // Text result complete
|
||||
PrintAndFlush("#EOF\n"); // Pixel result complete
|
||||
std::cerr << "#EOF\n";
|
||||
std::cerr.flush();
|
||||
bindings_.CloseAllBindings();
|
||||
|
||||
if (single_test_)
|
||||
exit(0);
|
||||
ScheduleRun();
|
||||
}
|
||||
|
||||
void TestRunner::DispatchInputEvent(mojo::EventPtr event) {
|
||||
// TODO(abarth): Not implemented.
|
||||
}
|
||||
|
||||
void TestRunner::Create(mojo::ApplicationConnection* app,
|
||||
mojo::InterfaceRequest<TestHarness> request) {
|
||||
bindings_.AddBinding(this, request.Pass());
|
||||
}
|
||||
|
||||
void TestRunner::ScheduleRun() {
|
||||
base::MessageLoop::current()->PostTask(FROM_HERE,
|
||||
base::Bind(&TestRunner::Run, weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void TestRunner::Run() {
|
||||
UrlData data;
|
||||
if (single_test_) {
|
||||
data.url = single_test_->path;
|
||||
data.is_snapshot = single_test_->is_snapshot;
|
||||
} else {
|
||||
WaitForURL(data);
|
||||
}
|
||||
|
||||
std::cout << "#BEGIN\n";
|
||||
std::cout.flush();
|
||||
|
||||
if (StartsWithASCII(data.url, kFileUrlPrefix, true))
|
||||
ReplaceFirstSubstringAfterOffset(&data.url, 0, kFileUrlPrefix, "");
|
||||
|
||||
if (data.is_snapshot)
|
||||
sky_engine_->RunFromSnapshot(data.url);
|
||||
else
|
||||
sky_engine_->RunFromFile(data.url, package_root_);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,67 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_TESTING_TEST_RUNNER_H_
|
||||
#define SKY_SHELL_TESTING_TEST_RUNNER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/common/weak_binding_set.h"
|
||||
#include "mojo/public/cpp/application/interface_factory_impl.h"
|
||||
#include "sky/services/engine/sky_engine.mojom.h"
|
||||
#include "sky/services/testing/test_harness.mojom.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
class ShellView;
|
||||
|
||||
class TestRunner : public mojo::InterfaceFactory<TestHarness>,
|
||||
public TestHarness {
|
||||
public:
|
||||
static TestRunner& Shared();
|
||||
|
||||
void set_package_root(const std::string& package_root) {
|
||||
package_root_ = package_root;
|
||||
}
|
||||
|
||||
struct SingleTest {
|
||||
std::string path;
|
||||
bool is_snapshot = false;
|
||||
};
|
||||
|
||||
void Start(scoped_ptr<SingleTest> single_test);
|
||||
|
||||
private:
|
||||
// mojo::InterfaceFactory<TestHarness> implementation:
|
||||
void Create(mojo::ApplicationConnection* app,
|
||||
mojo::InterfaceRequest<TestHarness> request) override;
|
||||
|
||||
// TestHarness implementation:
|
||||
void OnTestComplete(const mojo::String& test_result,
|
||||
const mojo::Array<uint8_t> pixels) override;
|
||||
void DispatchInputEvent(mojo::EventPtr event) override;
|
||||
|
||||
TestRunner();
|
||||
~TestRunner() override;
|
||||
void ScheduleRun();
|
||||
void Run();
|
||||
|
||||
std::string package_root_;
|
||||
scoped_ptr<ShellView> shell_view_;
|
||||
SkyEnginePtr sky_engine_;
|
||||
|
||||
scoped_ptr<SingleTest> single_test_;
|
||||
mojo::WeakBindingSet<TestHarness> bindings_;
|
||||
|
||||
base::WeakPtrFactory<TestRunner> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TestRunner);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_TESTING_TEST_RUNNER_H_
|
||||
@@ -1,82 +0,0 @@
|
||||
// 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/ui/animator.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
Animator::Animator(const Engine::Config& config, Engine* engine)
|
||||
: config_(config),
|
||||
engine_(engine),
|
||||
engine_requested_frame_(false),
|
||||
frame_in_progress_(false),
|
||||
paused_(false),
|
||||
weak_factory_(this) {
|
||||
}
|
||||
|
||||
Animator::~Animator() {
|
||||
}
|
||||
|
||||
void Animator::RequestFrame() {
|
||||
if (engine_requested_frame_)
|
||||
return;
|
||||
|
||||
TRACE_EVENT_ASYNC_BEGIN0("sky", "Frame request pending", this);
|
||||
engine_requested_frame_ = true;
|
||||
|
||||
if (!frame_in_progress_) {
|
||||
frame_in_progress_ = true;
|
||||
base::MessageLoop::current()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::Stop() {
|
||||
paused_ = true;
|
||||
engine_requested_frame_ = false;
|
||||
}
|
||||
|
||||
void Animator::Start() {
|
||||
paused_ = false;
|
||||
RequestFrame();
|
||||
}
|
||||
|
||||
void Animator::BeginFrame() {
|
||||
DCHECK(frame_in_progress_);
|
||||
// There could be a request in the message loop at time of cancel.
|
||||
if (!engine_requested_frame_) {
|
||||
frame_in_progress_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
engine_requested_frame_ = false;
|
||||
TRACE_EVENT_ASYNC_END0("sky", "Frame request pending", this);
|
||||
|
||||
engine_->BeginFrame(base::TimeTicks::Now());
|
||||
config_.gpu_task_runner->PostTaskAndReply(
|
||||
FROM_HERE,
|
||||
base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, engine_->Paint()),
|
||||
base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void Animator::OnFrameComplete() {
|
||||
DCHECK(frame_in_progress_);
|
||||
frame_in_progress_ = false;
|
||||
if (paused_)
|
||||
return;
|
||||
|
||||
if (engine_requested_frame_) {
|
||||
frame_in_progress_ = true;
|
||||
BeginFrame();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_ANIMATOR_H_
|
||||
#define SKY_SHELL_UI_ANIMATOR_H_
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "sky/shell/ui/engine.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class Animator {
|
||||
public:
|
||||
explicit Animator(const Engine::Config& config, Engine* engine);
|
||||
~Animator();
|
||||
|
||||
void RequestFrame();
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
void BeginFrame();
|
||||
void OnFrameComplete();
|
||||
|
||||
Engine::Config config_;
|
||||
Engine* engine_;
|
||||
bool engine_requested_frame_;
|
||||
bool frame_in_progress_;
|
||||
bool paused_;
|
||||
|
||||
base::WeakPtrFactory<Animator> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Animator);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_UI_ANIMATOR_H_
|
||||
@@ -1,251 +0,0 @@
|
||||
// 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/ui/engine.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "mojo/common/data_pipe_utils.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
#include "services/asset_bundle/asset_unpacker_job.h"
|
||||
#include "sky/engine/public/platform/WebInputEvent.h"
|
||||
#include "sky/engine/public/platform/sky_display_metrics.h"
|
||||
#include "sky/engine/public/platform/sky_display_metrics.h"
|
||||
#include "sky/engine/public/web/Sky.h"
|
||||
#include "sky/shell/dart/dart_library_provider_files.h"
|
||||
#include "sky/shell/dart/dart_library_provider_network.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "sky/shell/ui/animator.h"
|
||||
#include "sky/shell/ui/input_event_converter.h"
|
||||
#include "sky/shell/ui/internals.h"
|
||||
#include "sky/shell/ui/platform_impl.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
const char kSnapshotKey[] = "snapshot_blob.bin";
|
||||
|
||||
namespace {
|
||||
|
||||
void Ignored(bool) {
|
||||
}
|
||||
|
||||
mojo::ScopedDataPipeConsumerHandle Fetch(const base::FilePath& path) {
|
||||
mojo::DataPipe pipe;
|
||||
auto runner = base::WorkerPool::GetTaskRunner(true);
|
||||
mojo::common::CopyFromFile(base::FilePath(path), pipe.producer_handle.Pass(),
|
||||
0, runner.get(), base::Bind(&Ignored));
|
||||
return pipe.consumer_handle.Pass();
|
||||
}
|
||||
|
||||
PlatformImpl* g_platform_impl = nullptr;
|
||||
|
||||
} // namespace
|
||||
|
||||
using mojo::asset_bundle::AssetUnpackerJob;
|
||||
|
||||
Engine::Config::Config() {
|
||||
}
|
||||
|
||||
Engine::Config::~Config() {
|
||||
}
|
||||
|
||||
Engine::Engine(const Config& config)
|
||||
: config_(config),
|
||||
animator_(new Animator(config, this)),
|
||||
binding_(this),
|
||||
activity_running_(false),
|
||||
have_surface_(false),
|
||||
weak_factory_(this) {
|
||||
mojo::ServiceProviderPtr service_provider =
|
||||
CreateServiceProvider(config.service_provider_context);
|
||||
mojo::ConnectToService(service_provider.get(), &network_service_);
|
||||
}
|
||||
|
||||
Engine::~Engine() {
|
||||
}
|
||||
|
||||
base::WeakPtr<Engine> Engine::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
TRACE_EVENT0("sky", "Engine::Init");
|
||||
|
||||
DCHECK(!g_platform_impl);
|
||||
g_platform_impl = new PlatformImpl();
|
||||
blink::initialize(g_platform_impl);
|
||||
}
|
||||
|
||||
void Engine::BeginFrame(base::TimeTicks frame_time) {
|
||||
TRACE_EVENT0("sky", "Engine::BeginFrame");
|
||||
|
||||
if (sky_view_)
|
||||
sky_view_->BeginFrame(frame_time);
|
||||
}
|
||||
|
||||
skia::RefPtr<SkPicture> Engine::Paint() {
|
||||
TRACE_EVENT0("sky", "Engine::Paint");
|
||||
|
||||
SkRTreeFactory factory;
|
||||
SkPictureRecorder recorder;
|
||||
auto canvas = skia::SharePtr(recorder.beginRecording(
|
||||
physical_size_.width(), physical_size_.height(), &factory,
|
||||
SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
|
||||
|
||||
if (sky_view_) {
|
||||
skia::RefPtr<SkPicture> picture = sky_view_->Paint();
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
canvas->scale(display_metrics_.device_pixel_ratio,
|
||||
display_metrics_.device_pixel_ratio);
|
||||
if (picture)
|
||||
canvas->drawPicture(picture.get());
|
||||
}
|
||||
|
||||
return skia::AdoptRef(recorder.endRecordingAsPicture());
|
||||
}
|
||||
|
||||
void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) {
|
||||
binding_.Bind(request.Pass());
|
||||
}
|
||||
|
||||
void Engine::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
|
||||
config_.gpu_task_runner->PostTask(
|
||||
FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable,
|
||||
config_.gpu_delegate, widget));
|
||||
have_surface_ = true;
|
||||
StartAnimatorIfPossible();
|
||||
if (sky_view_)
|
||||
ScheduleFrame();
|
||||
}
|
||||
|
||||
void Engine::OnOutputSurfaceDestroyed() {
|
||||
have_surface_ = false;
|
||||
StopAnimator();
|
||||
config_.gpu_task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate));
|
||||
}
|
||||
|
||||
void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) {
|
||||
physical_size_.SetSize(metrics->physical_width, metrics->physical_height);
|
||||
|
||||
display_metrics_.physical_size = physical_size_;
|
||||
display_metrics_.device_pixel_ratio = metrics->device_pixel_ratio;
|
||||
display_metrics_.padding_top = metrics->padding_top;
|
||||
display_metrics_.padding_right = metrics->padding_right;
|
||||
display_metrics_.padding_bottom = metrics->padding_bottom;
|
||||
display_metrics_.padding_left = metrics->padding_left;
|
||||
|
||||
if (sky_view_)
|
||||
sky_view_->SetDisplayMetrics(display_metrics_);
|
||||
}
|
||||
|
||||
void Engine::OnInputEvent(InputEventPtr event) {
|
||||
TRACE_EVENT0("sky", "Engine::OnInputEvent");
|
||||
scoped_ptr<blink::WebInputEvent> web_event =
|
||||
ConvertEvent(event, display_metrics_.device_pixel_ratio);
|
||||
if (!web_event)
|
||||
return;
|
||||
if (sky_view_)
|
||||
sky_view_->HandleInputEvent(*web_event);
|
||||
}
|
||||
|
||||
void Engine::RunFromLibrary(const std::string& name) {
|
||||
sky_view_ = blink::SkyView::Create(this);
|
||||
sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name),
|
||||
dart_library_provider_.get());
|
||||
sky_view_->SetDisplayMetrics(display_metrics_);
|
||||
}
|
||||
|
||||
void Engine::RunFromSnapshotStream(
|
||||
const std::string& name,
|
||||
mojo::ScopedDataPipeConsumerHandle snapshot) {
|
||||
sky_view_ = blink::SkyView::Create(this);
|
||||
sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(name), snapshot.Pass());
|
||||
sky_view_->SetDisplayMetrics(display_metrics_);
|
||||
}
|
||||
|
||||
void Engine::RunFromNetwork(const mojo::String& url) {
|
||||
dart_library_provider_.reset(
|
||||
new DartLibraryProviderNetwork(network_service_.get()));
|
||||
RunFromLibrary(url);
|
||||
}
|
||||
|
||||
void Engine::RunFromFile(const mojo::String& main,
|
||||
const mojo::String& package_root) {
|
||||
dart_library_provider_.reset(
|
||||
new DartLibraryProviderFiles(base::FilePath(package_root)));
|
||||
RunFromLibrary(main);
|
||||
}
|
||||
|
||||
void Engine::RunFromSnapshot(const mojo::String& path) {
|
||||
std::string path_str = path;
|
||||
RunFromSnapshotStream(path_str, Fetch(base::FilePath(path_str)));
|
||||
}
|
||||
|
||||
void Engine::RunFromBundle(const mojo::String& path) {
|
||||
AssetUnpackerJob* unpacker = new AssetUnpackerJob(
|
||||
mojo::GetProxy(&root_bundle_), base::WorkerPool::GetTaskRunner(true));
|
||||
std::string path_str = path;
|
||||
unpacker->Unpack(Fetch(base::FilePath(path_str)));
|
||||
root_bundle_->GetAsStream(kSnapshotKey,
|
||||
base::Bind(&Engine::RunFromSnapshotStream,
|
||||
weak_factory_.GetWeakPtr(), path_str));
|
||||
}
|
||||
|
||||
void Engine::OnActivityPaused() {
|
||||
activity_running_ = false;
|
||||
StopAnimator();
|
||||
}
|
||||
|
||||
void Engine::OnActivityResumed() {
|
||||
activity_running_ = true;
|
||||
StartAnimatorIfPossible();
|
||||
}
|
||||
|
||||
void Engine::DidCreateIsolate(Dart_Isolate isolate) {
|
||||
Internals::Create(isolate,
|
||||
CreateServiceProvider(config_.service_provider_context),
|
||||
root_bundle_.Pass());
|
||||
}
|
||||
|
||||
void Engine::StopAnimator() {
|
||||
animator_->Stop();
|
||||
}
|
||||
|
||||
void Engine::StartAnimatorIfPossible() {
|
||||
if (activity_running_ && have_surface_)
|
||||
animator_->Start();
|
||||
}
|
||||
|
||||
void Engine::ScheduleFrame() {
|
||||
animator_->RequestFrame();
|
||||
}
|
||||
|
||||
mojo::NavigatorHost* Engine::NavigatorHost() {
|
||||
return this;
|
||||
}
|
||||
|
||||
void Engine::RequestNavigate(mojo::Target target,
|
||||
mojo::URLRequestPtr request) {
|
||||
// Ignoring target for now.
|
||||
base::MessageLoop::current()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&Engine::RunFromNetwork, GetWeakPtr(), request->url));
|
||||
}
|
||||
|
||||
void Engine::DidNavigateLocally(const mojo::String& url) {
|
||||
}
|
||||
|
||||
void Engine::RequestNavigateHistory(int32_t delta) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,122 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_ENGINE_H_
|
||||
#define SKY_SHELL_UI_ENGINE_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
#include "mojo/services/asset_bundle/public/interfaces/asset_bundle.mojom.h"
|
||||
#include "mojo/services/navigation/public/interfaces/navigation.mojom.h"
|
||||
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
|
||||
#include "skia/ext/refptr.h"
|
||||
#include "sky/engine/public/platform/ServiceProvider.h"
|
||||
#include "sky/engine/public/sky/sky_view.h"
|
||||
#include "sky/engine/public/sky/sky_view_client.h"
|
||||
#include "sky/shell/gpu_delegate.h"
|
||||
#include "sky/shell/service_provider.h"
|
||||
#include "sky/shell/ui_delegate.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
|
||||
namespace sky {
|
||||
class PlatformImpl;
|
||||
namespace shell {
|
||||
class Animator;
|
||||
|
||||
class Engine : public UIDelegate,
|
||||
public SkyEngine,
|
||||
public blink::ServiceProvider,
|
||||
public mojo::NavigatorHost,
|
||||
public blink::SkyViewClient {
|
||||
public:
|
||||
struct Config {
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
ServiceProviderContext* service_provider_context;
|
||||
|
||||
base::WeakPtr<GPUDelegate> gpu_delegate;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner;
|
||||
};
|
||||
|
||||
explicit Engine(const Config& config);
|
||||
~Engine() override;
|
||||
|
||||
base::WeakPtr<Engine> GetWeakPtr();
|
||||
|
||||
static void Init();
|
||||
|
||||
void BeginFrame(base::TimeTicks frame_time);
|
||||
skia::RefPtr<SkPicture> Paint();
|
||||
|
||||
private:
|
||||
// UIDelegate implementation:
|
||||
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) override;
|
||||
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
|
||||
void OnOutputSurfaceDestroyed() override;
|
||||
|
||||
// SkyEngine implementation:
|
||||
void OnViewportMetricsChanged(ViewportMetricsPtr metrics) override;
|
||||
void OnInputEvent(InputEventPtr event) override;
|
||||
|
||||
void RunFromNetwork(const mojo::String& url) override;
|
||||
void RunFromFile(const mojo::String& main,
|
||||
const mojo::String& package_root) override;
|
||||
void RunFromSnapshot(const mojo::String& path) override;
|
||||
void RunFromBundle(const mojo::String& path) override;
|
||||
|
||||
void OnActivityPaused() override;
|
||||
void OnActivityResumed() override;
|
||||
|
||||
// SkyViewClient methods:
|
||||
void ScheduleFrame() override;
|
||||
void DidCreateIsolate(Dart_Isolate isolate) override;
|
||||
|
||||
// Services methods:
|
||||
mojo::NavigatorHost* NavigatorHost() override;
|
||||
|
||||
// NavigatorHost methods:
|
||||
void RequestNavigate(mojo::Target target,
|
||||
mojo::URLRequestPtr request) override;
|
||||
void DidNavigateLocally(const mojo::String& url) override;
|
||||
void RequestNavigateHistory(int32_t delta) override;
|
||||
|
||||
void RunFromLibrary(const std::string& name);
|
||||
void RunFromSnapshotStream(const std::string& name,
|
||||
mojo::ScopedDataPipeConsumerHandle snapshot);
|
||||
|
||||
void StopAnimator();
|
||||
void StartAnimatorIfPossible();
|
||||
|
||||
Config config_;
|
||||
scoped_ptr<Animator> animator_;
|
||||
|
||||
mojo::NetworkServicePtr network_service_;
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle_;
|
||||
scoped_ptr<blink::DartLibraryProvider> dart_library_provider_;
|
||||
std::unique_ptr<blink::SkyView> sky_view_;
|
||||
|
||||
gfx::Size physical_size_;
|
||||
blink::SkyDisplayMetrics display_metrics_;
|
||||
mojo::Binding<SkyEngine> binding_;
|
||||
|
||||
// TODO(eseidel): This should move into an AnimatorStateMachine.
|
||||
bool activity_running_;
|
||||
bool have_surface_;
|
||||
|
||||
base::WeakPtrFactory<Engine> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Engine);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_UI_ENGINE_H_
|
||||
@@ -1,142 +0,0 @@
|
||||
// Copyright 2014 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/ui/input_event_converter.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/time/time.h"
|
||||
#include "sky/engine/public/platform/WebInputEvent.h"
|
||||
|
||||
namespace sky {
|
||||
namespace {
|
||||
|
||||
scoped_ptr<blink::WebInputEvent> BuildWebPointerEvent(
|
||||
const InputEventPtr& event, float device_pixel_ratio) {
|
||||
scoped_ptr<blink::WebPointerEvent> web_event(new blink::WebPointerEvent);
|
||||
|
||||
web_event->timeStampMS = event->time_stamp;
|
||||
|
||||
switch (event->type) {
|
||||
case EVENT_TYPE_POINTER_DOWN:
|
||||
web_event->type = blink::WebInputEvent::PointerDown;
|
||||
break;
|
||||
case EVENT_TYPE_POINTER_UP:
|
||||
web_event->type = blink::WebInputEvent::PointerUp;
|
||||
break;
|
||||
case EVENT_TYPE_POINTER_MOVE:
|
||||
web_event->type = blink::WebInputEvent::PointerMove;
|
||||
break;
|
||||
case EVENT_TYPE_POINTER_CANCEL:
|
||||
web_event->type = blink::WebInputEvent::PointerCancel;
|
||||
break;
|
||||
default:
|
||||
NOTIMPLEMENTED() << "Received unexpected event: " << event->type;
|
||||
break;
|
||||
}
|
||||
|
||||
if (event->pointer_data) {
|
||||
if (event->pointer_data->kind == POINTER_KIND_TOUCH)
|
||||
web_event->kind = blink::WebPointerEvent::Touch;
|
||||
web_event->pointer = event->pointer_data->pointer;
|
||||
web_event->x = event->pointer_data->x / device_pixel_ratio;
|
||||
web_event->y = event->pointer_data->y / device_pixel_ratio;
|
||||
web_event->pressure = event->pointer_data->pressure;
|
||||
web_event->pressureMin = event->pointer_data->pressure_min;
|
||||
web_event->pressureMax = event->pointer_data->pressure_max;
|
||||
}
|
||||
|
||||
return web_event.Pass();
|
||||
}
|
||||
|
||||
scoped_ptr<blink::WebInputEvent> BuildWebGestureEvent(
|
||||
const InputEventPtr& event, float device_pixel_ratio) {
|
||||
scoped_ptr<blink::WebGestureEvent> web_event(new blink::WebGestureEvent);
|
||||
|
||||
web_event->timeStampMS = event->time_stamp;
|
||||
|
||||
switch (event->type) {
|
||||
case EVENT_TYPE_GESTURE_SCROLL_BEGIN:
|
||||
web_event->type = blink::WebInputEvent::GestureScrollBegin;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_SCROLL_END:
|
||||
web_event->type = blink::WebInputEvent::GestureScrollEnd;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_SCROLL_UPDATE:
|
||||
web_event->type = blink::WebInputEvent::GestureScrollUpdate;
|
||||
web_event->data.scrollUpdate.deltaX =
|
||||
event->gesture_data->dx / device_pixel_ratio;
|
||||
web_event->data.scrollUpdate.deltaY =
|
||||
event->gesture_data->dy / device_pixel_ratio;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_FLING_START:
|
||||
web_event->type = blink::WebInputEvent::GestureFlingStart;
|
||||
web_event->data.flingStart.velocityX =
|
||||
event->gesture_data->velocityX / device_pixel_ratio;
|
||||
web_event->data.flingStart.velocityY =
|
||||
event->gesture_data->velocityY / device_pixel_ratio;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_FLING_CANCEL:
|
||||
web_event->type = blink::WebInputEvent::GestureFlingCancel;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_LONG_PRESS:
|
||||
web_event->type = blink::WebInputEvent::GestureLongPress;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_SHOW_PRESS:
|
||||
web_event->type = blink::WebInputEvent::GestureShowPress;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_TAP:
|
||||
web_event->type = blink::WebInputEvent::GestureTap;
|
||||
break;
|
||||
case EVENT_TYPE_GESTURE_TAP_DOWN:
|
||||
web_event->type = blink::WebInputEvent::GestureTapDown;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (event->gesture_data) {
|
||||
web_event->primaryPointer = event->gesture_data->primary_pointer;
|
||||
web_event->x = event->gesture_data->x / device_pixel_ratio;
|
||||
web_event->y = event->gesture_data->y / device_pixel_ratio;
|
||||
}
|
||||
|
||||
return web_event.Pass();
|
||||
}
|
||||
|
||||
scoped_ptr<blink::WebInputEvent> BuildWebBackEvent(const InputEventPtr& event) {
|
||||
scoped_ptr<blink::WebInputEvent> web_event(blink::WebInputEvent::create());
|
||||
web_event->type = blink::WebInputEvent::Back;
|
||||
return web_event.Pass();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event,
|
||||
float device_pixel_ratio) {
|
||||
switch (event->type) {
|
||||
case EVENT_TYPE_POINTER_DOWN:
|
||||
case EVENT_TYPE_POINTER_UP:
|
||||
case EVENT_TYPE_POINTER_MOVE:
|
||||
case EVENT_TYPE_POINTER_CANCEL:
|
||||
return BuildWebPointerEvent(event, device_pixel_ratio);
|
||||
case EVENT_TYPE_GESTURE_FLING_CANCEL:
|
||||
case EVENT_TYPE_GESTURE_FLING_START:
|
||||
case EVENT_TYPE_GESTURE_LONG_PRESS:
|
||||
case EVENT_TYPE_GESTURE_SCROLL_BEGIN:
|
||||
case EVENT_TYPE_GESTURE_SCROLL_END:
|
||||
case EVENT_TYPE_GESTURE_SCROLL_UPDATE:
|
||||
case EVENT_TYPE_GESTURE_SHOW_PRESS:
|
||||
case EVENT_TYPE_GESTURE_TAP:
|
||||
case EVENT_TYPE_GESTURE_TAP_DOWN:
|
||||
return BuildWebGestureEvent(event, device_pixel_ratio);
|
||||
case EVENT_TYPE_BACK:
|
||||
return BuildWebBackEvent(event);
|
||||
case EVENT_TYPE_UNKNOWN:
|
||||
NOTIMPLEMENTED() << "ConvertEvent received unexpected EVENT_TYPE_UNKNOWN";
|
||||
}
|
||||
|
||||
return scoped_ptr<blink::WebInputEvent>();
|
||||
}
|
||||
|
||||
} // namespace mojo
|
||||
@@ -1,21 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
|
||||
#define SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "sky/services/engine/input_event.mojom.h"
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
}
|
||||
|
||||
namespace sky {
|
||||
|
||||
scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event,
|
||||
float device_pixel_ratio);
|
||||
}
|
||||
|
||||
#endif // SKY_SHELL_UI_INPUT_EVENT_CONVERTER_H_
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright 2014 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/ui/internals.h"
|
||||
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
#include "mojo/public/cpp/bindings/array.h"
|
||||
#include "services/asset_bundle/asset_unpacker_impl.h"
|
||||
#include "sky/engine/tonic/dart_builtin.h"
|
||||
#include "sky/engine/tonic/dart_converter.h"
|
||||
#include "sky/engine/tonic/dart_error.h"
|
||||
#include "sky/engine/tonic/dart_state.h"
|
||||
|
||||
using namespace blink;
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
int kInternalsKey = 0;
|
||||
|
||||
Internals* GetInternals() {
|
||||
DartState* state = DartState::Current();
|
||||
return static_cast<Internals*>(state->GetUserData(&kInternalsKey));
|
||||
}
|
||||
|
||||
void NotifyTestComplete(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
void TakeRootBundleHandle(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(
|
||||
args, GetInternals()->TakeRootBundleHandle().value());
|
||||
}
|
||||
|
||||
void TakeShellProxyHandle(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(args, 0);
|
||||
}
|
||||
|
||||
void TakeServicesProvidedByEmbedder(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(
|
||||
args, GetInternals()->TakeServicesProvidedByEmbedder().value());
|
||||
}
|
||||
|
||||
void TakeServicesProvidedToEmbedder(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(args, 0);
|
||||
}
|
||||
|
||||
void TakeServiceRegistry(Dart_NativeArguments args) {
|
||||
Dart_SetIntegerReturnValue(args, 0);
|
||||
}
|
||||
|
||||
const DartBuiltin::Natives kNativeFunctions[] = {
|
||||
{"notifyTestComplete", NotifyTestComplete, 1},
|
||||
{"takeRootBundleHandle", TakeRootBundleHandle, 0},
|
||||
{"takeServiceRegistry", TakeServiceRegistry, 0},
|
||||
{"takeServicesProvidedByEmbedder", TakeServicesProvidedByEmbedder, 0},
|
||||
{"takeServicesProvidedToEmbedder", TakeServicesProvidedToEmbedder, 0},
|
||||
{"takeShellProxyHandle", TakeShellProxyHandle, 0},
|
||||
};
|
||||
|
||||
const DartBuiltin& GetBuiltin() {
|
||||
static DartBuiltin& builtin = *new DartBuiltin(kNativeFunctions,
|
||||
arraysize(kNativeFunctions));
|
||||
return builtin;
|
||||
}
|
||||
|
||||
Dart_NativeFunction Resolver(Dart_Handle name,
|
||||
int argument_count,
|
||||
bool* auto_setup_scope) {
|
||||
return GetBuiltin().Resolver(name, argument_count, auto_setup_scope);
|
||||
}
|
||||
|
||||
const uint8_t* Symbolizer(Dart_NativeFunction native_function) {
|
||||
return GetBuiltin().Symbolizer(native_function);
|
||||
}
|
||||
|
||||
const char kLibraryName[] = "dart:sky.internals";
|
||||
|
||||
} // namespace
|
||||
|
||||
void Internals::Create(Dart_Isolate isolate,
|
||||
mojo::ServiceProviderPtr service_provider,
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle) {
|
||||
DartState* state = DartState::From(isolate);
|
||||
state->SetUserData(&kInternalsKey, new Internals(service_provider.Pass(),
|
||||
root_bundle.Pass()));
|
||||
Dart_Handle library =
|
||||
Dart_LookupLibrary(Dart_NewStringFromCString(kLibraryName));
|
||||
CHECK(!LogIfError(library));
|
||||
CHECK(!LogIfError(Dart_SetNativeResolver(library, Resolver, Symbolizer)));
|
||||
}
|
||||
|
||||
Internals::Internals(mojo::ServiceProviderPtr platform_service_provider,
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle)
|
||||
: root_bundle_(root_bundle.Pass()),
|
||||
service_provider_impl_(GetProxy(&service_provider_)),
|
||||
platform_service_provider_(platform_service_provider.Pass()) {
|
||||
service_provider_impl_.set_fallback_service_provider(
|
||||
platform_service_provider_.get());
|
||||
service_provider_impl_.AddService<mojo::asset_bundle::AssetUnpacker>(this);
|
||||
}
|
||||
|
||||
Internals::~Internals() {
|
||||
}
|
||||
|
||||
void Internals::Create(
|
||||
mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker> request) {
|
||||
new mojo::asset_bundle::AssetUnpackerImpl(
|
||||
request.Pass(), base::WorkerPool::GetTaskRunner(true));
|
||||
}
|
||||
|
||||
mojo::Handle Internals::TakeServicesProvidedByEmbedder() {
|
||||
return service_provider_.PassInterface().PassHandle().release();
|
||||
}
|
||||
|
||||
mojo::Handle Internals::TakeRootBundleHandle() {
|
||||
return root_bundle_.PassInterface().PassHandle().release();
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_INTERNALS_H_
|
||||
#define SKY_SHELL_UI_INTERNALS_H_
|
||||
|
||||
#include "base/supports_user_data.h"
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
#include "mojo/public/cpp/application/interface_factory.h"
|
||||
#include "mojo/public/cpp/application/service_provider_impl.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
#include "mojo/services/asset_bundle/public/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace mojo {
|
||||
class ApplicationConnection;
|
||||
}
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class Internals
|
||||
: public base::SupportsUserData::Data,
|
||||
public mojo::InterfaceFactory<mojo::asset_bundle::AssetUnpacker> {
|
||||
public:
|
||||
~Internals() override;
|
||||
|
||||
static void Create(Dart_Isolate isolate,
|
||||
mojo::ServiceProviderPtr platform_service_provider,
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle);
|
||||
|
||||
mojo::Handle TakeServicesProvidedByEmbedder();
|
||||
mojo::Handle TakeRootBundleHandle();
|
||||
|
||||
private:
|
||||
explicit Internals(mojo::ServiceProviderPtr platform_service_provider,
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle);
|
||||
|
||||
// |mojo::InterfaceFactory<mojo::asset_bundle::AssetUnpacker>| implementation:
|
||||
void Create(
|
||||
mojo::ApplicationConnection* connection,
|
||||
mojo::InterfaceRequest<mojo::asset_bundle::AssetUnpacker>) override;
|
||||
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle_;
|
||||
mojo::ServiceProviderPtr service_provider_;
|
||||
mojo::ServiceProviderImpl service_provider_impl_;
|
||||
mojo::ServiceProviderPtr platform_service_provider_;
|
||||
|
||||
MOJO_DISALLOW_COPY_AND_ASSIGN(Internals);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_UI_INTERNALS_H_
|
||||
@@ -1,26 +0,0 @@
|
||||
// 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/ui/platform_impl.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
PlatformImpl::PlatformImpl()
|
||||
: main_thread_task_runner_(base::MessageLoop::current()->task_runner()) {
|
||||
}
|
||||
|
||||
PlatformImpl::~PlatformImpl() {
|
||||
}
|
||||
|
||||
blink::WebString PlatformImpl::defaultLocale() {
|
||||
return blink::WebString::fromUTF8("en-US");
|
||||
}
|
||||
|
||||
base::SingleThreadTaskRunner* PlatformImpl::mainThreadTaskRunner() {
|
||||
return main_thread_task_runner_.get();
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_PLATFORM_IMPL_H_
|
||||
#define SKY_SHELL_UI_PLATFORM_IMPL_H_
|
||||
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "sky/engine/public/platform/Platform.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class PlatformImpl : public blink::Platform {
|
||||
public:
|
||||
explicit PlatformImpl();
|
||||
~PlatformImpl() override;
|
||||
|
||||
// blink::Platform methods:
|
||||
blink::WebString defaultLocale() override;
|
||||
base::SingleThreadTaskRunner* mainThreadTaskRunner() override;
|
||||
|
||||
private:
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformImpl);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_UI_PLATFORM_IMPL_H_
|
||||
@@ -1,14 +0,0 @@
|
||||
// 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/ui_delegate.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
UIDelegate::~UIDelegate() {
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
@@ -1,29 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SKY_SHELL_UI_DELEGATE_H_
|
||||
#define SKY_SHELL_UI_DELEGATE_H_
|
||||
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "sky/services/engine/sky_engine.mojom.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
|
||||
namespace sky {
|
||||
namespace shell {
|
||||
|
||||
class UIDelegate {
|
||||
public:
|
||||
virtual void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) = 0;
|
||||
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) = 0;
|
||||
virtual void OnOutputSurfaceDestroyed() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~UIDelegate();
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
} // namespace sky
|
||||
|
||||
#endif // SKY_SHELL_UI_DELEGATE_H_
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user