sky/shell updates for Android and iOS

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1169983005.
This commit is contained in:
Chinmay Garde
2015-06-10 16:19:49 -07:00
parent dc70797319
commit 2101e26e19
12 changed files with 306 additions and 187 deletions

View File

@@ -2,111 +2,181 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
assert(is_android)
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/navigation/public/interfaces",
"//mojo/services/network/public/interfaces",
"//skia",
"//sky/engine",
"//sky/engine/wtf",
"//sky/engine/tonic",
"//sky/services/platform",
"//sky/services/viewport",
"//ui/gfx/geometry",
"//ui/gl",
]
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
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/PlatformView.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.cc",
"android/platform_service_provider.h",
"android/platform_view.cc",
"android/platform_view.h",
"android/sky_main.cc",
"android/sky_main.h",
"android/tracing_controller.cc",
"android/tracing_controller.h",
"gpu/ganesh_context.cc",
"gpu/ganesh_context.h",
"gpu/ganesh_surface.cc",
"gpu/ganesh_surface.h",
"gpu/rasterizer.cc",
"gpu/rasterizer.h",
"gpu_delegate.cc",
"gpu_delegate.h",
"service_provider.h",
"shell.cc",
"shell.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_delegate.cc",
"ui_delegate.h",
]
deps = [
"//base",
"//base:i18n",
"//build/config/sanitizers:deps",
"//dart/runtime:libdart",
"//mojo/android:libsystem_java",
"//mojo/common",
"//mojo/edk/system",
"//mojo/public/cpp/application",
"//mojo/public/interfaces/application",
"//mojo/services/navigation/public/interfaces",
"//mojo/services/network/public/interfaces",
"//skia",
"//sky/engine",
"//sky/engine/tonic",
"//sky/services/platform",
"//sky/services/viewport",
"//ui/gfx/geometry",
"//ui/gl",
":jni_headers",
]
}
android_library("java") {
java_files = [
"android/org/domokit/sky/shell/GestureProvider.java",
"android/org/domokit/sky/shell/PlatformServiceProvider.java",
"android/org/domokit/sky/shell/PlatformView.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/network/public/interfaces:interfaces_java",
"//services/keyboard",
"//sky/services/oknet",
"//sky/services/viewport:viewport_java",
]
}
copy_ex("assets") {
clear_dir = true
dest = "$root_build_dir/sky_shell/assets"
sources = [
"$root_build_dir/icudtl.dat",
]
deps = [
"//third_party/icu",
]
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",
"gpu/ganesh_context.cc",
"gpu/ganesh_context.h",
"gpu/ganesh_surface.cc",
"gpu/ganesh_surface.h",
"gpu/rasterizer.cc",
"gpu/rasterizer.h",
"gpu_delegate.cc",
"gpu_delegate.h",
"platform_view.cc",
"platform_view.h",
"service_provider.h",
"shell.cc",
"shell.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_delegate.cc",
"ui_delegate.h",
]
deps = common_deps + [
"//mojo/android:libsystem_java",
":jni_headers",
]
}
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/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/network/public/interfaces:interfaces_java",
"//services/keyboard",
"//sky/services/oknet",
"//sky/services/viewport:viewport_java",
]
}
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 = [
"gpu/ganesh_context.cc",
"gpu/ganesh_context.h",
"gpu/ganesh_surface.cc",
"gpu/ganesh_surface.h",
"gpu/rasterizer.cc",
"gpu/rasterizer.h",
"gpu_delegate.cc",
"gpu_delegate.h",
"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",
"platform_view.cc",
"platform_view.h",
"shell.cc",
"shell.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_delegate.cc",
"ui_delegate.h",
]
ios_deps = [ "//sky/services/ns_net" ]
deps = common_deps + ios_deps
}
deps = [
":$scaffolding_target",
":sky_resources",
]
}
} else {
assert(false, "Unsupported platform")
}

View File

@@ -10,8 +10,8 @@
#include "base/bind.h"
#include "base/logging.h"
#include "mojo/android/system/core_impl.h"
#include "sky/shell/android/platform_service_provider.h"
#include "sky/shell/android/platform_view.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"
@@ -20,7 +20,7 @@ namespace {
base::android::RegistrationMethod kSkyRegisteredMethods[] = {
{"CoreImpl", mojo::android::RegisterCoreImpl},
{"PlatformServiceProvider", sky::shell::RegisterPlatformServiceProvider},
{"PlatformView", sky::shell::PlatformView::Register},
{"PlatformViewAndroid", sky::shell::PlatformViewAndroid::Register},
{"SkyMain", sky::shell::RegisterSkyMain},
{"TracingController", sky::shell::RegisterTracingController},
};

View File

@@ -29,16 +29,16 @@ import org.chromium.mojom.sky.ViewportObserver;
* A view containing Sky
*/
@JNINamespace("sky::shell")
public class PlatformView extends SurfaceView
public class PlatformViewAndroid extends SurfaceView
implements GestureProvider.OnGestureListener {
private static final String TAG = "PlatformView";
private static final String TAG = "PlatformViewAndroid";
private long mNativePlatformView;
private ViewportObserver.Proxy mViewportObserver;
private final SurfaceHolder.Callback mSurfaceCallback;
private GestureProvider mGestureProvider;
public PlatformView(Context context) {
public PlatformViewAndroid(Context context) {
super(context);
setFocusable(true);
@@ -102,20 +102,26 @@ public class PlatformView extends SurfaceView
private int getTypeForAction(int maskedAction) {
// Primary pointer:
if (maskedAction == MotionEvent.ACTION_DOWN)
if (maskedAction == MotionEvent.ACTION_DOWN) {
return EventType.POINTER_DOWN;
if (maskedAction == MotionEvent.ACTION_UP)
}
if (maskedAction == MotionEvent.ACTION_UP) {
return EventType.POINTER_UP;
}
// Secondary pointer:
if (maskedAction == MotionEvent.ACTION_POINTER_DOWN)
if (maskedAction == MotionEvent.ACTION_POINTER_DOWN) {
return EventType.POINTER_DOWN;
if (maskedAction == MotionEvent.ACTION_POINTER_UP)
}
if (maskedAction == MotionEvent.ACTION_POINTER_UP) {
return EventType.POINTER_UP;
}
// All pointers:
if (maskedAction == MotionEvent.ACTION_MOVE)
if (maskedAction == MotionEvent.ACTION_MOVE) {
return EventType.POINTER_MOVE;
if (maskedAction == MotionEvent.ACTION_CANCEL)
}
if (maskedAction == MotionEvent.ACTION_CANCEL) {
return EventType.POINTER_CANCEL;
}
return EventType.UNKNOWN;
}
@@ -183,7 +189,8 @@ public class PlatformView extends SurfaceView
}
private static native long nativeAttach(int inputObserverHandle);
private static native void nativeDetach(long nativePlatformView);
private static native void nativeSurfaceCreated(long nativePlatformView, Surface surface);
private static native void nativeSurfaceDestroyed(long nativePlatformView);
private static native void nativeDetach(long nativePlatformViewAndroid);
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
Surface surface);
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
}

View File

@@ -15,7 +15,7 @@ import android.view.WindowManager;
*/
public class SkyActivity extends Activity {
private TracingController mTracingController;
private PlatformView mView;
private PlatformViewAndroid mView;
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
@@ -33,7 +33,7 @@ public class SkyActivity extends Activity {
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
SkyMain.ensureInitialized(getApplicationContext());
mView = new PlatformView(this);
mView = new PlatformViewAndroid(this);
setContentView(mView);
mTracingController = new TracingController(this);
}

View File

@@ -2,7 +2,7 @@
// 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.h"
#include "sky/shell/android/platform_service_provider_android.h"
#include "base/android/jni_android.h"
#include "base/bind.h"
@@ -23,16 +23,16 @@ void CreatePlatformServiceProvider(
request.PassMessagePipe().release().value());
}
} // namespace
} // namespace
bool RegisterPlatformServiceProvider(JNIEnv* env) {
return RegisterNativesImpl(env);
}
mojo::ServiceProviderPtr CreateServiceProvider(
ServiceProviderContext* context) {
ServiceProviderContext* context) {
mojo::MessagePipe pipe;
context->java_task_runner->PostTask(
context->platform_task_runner->PostTask(
FROM_HERE,
base::Bind(CreatePlatformServiceProvider,
base::Passed(mojo::MakeRequest<mojo::ServiceProvider>(

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_ANDROID_PLATFORM_SERVICE_PROVIDER_H_
#define SKY_SHELL_ANDROID_PLATFORM_SERVICE_PROVIDER_H_
#ifndef SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_
#define SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_
#include <jni.h>
@@ -15,4 +15,4 @@ bool RegisterPlatformServiceProvider(JNIEnv* env);
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_ANDROID_PLATFORM_SERVICE_PROVIDER_H_
#endif // SKY_SHELL_PLATFORM_SERVICE_PROVIDER_ANDROID_H_

View File

@@ -2,7 +2,7 @@
// 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.h"
#include "sky/shell/android/platform_view_android.h"
#include <android/input.h>
#include <android/native_window_jni.h>
@@ -10,7 +10,7 @@
#include "base/android/jni_android.h"
#include "base/bind.h"
#include "base/location.h"
#include "jni/PlatformView_jni.h"
#include "jni/PlatformViewAndroid_jni.h"
#include "sky/shell/shell.h"
namespace sky {
@@ -25,32 +25,20 @@ static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) {
}
// static
bool PlatformView::Register(JNIEnv* env) {
bool PlatformViewAndroid::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
PlatformView::PlatformView(const Config& config)
: config_(config), window_(nullptr) {
}
PlatformView::~PlatformView() {
PlatformViewAndroid::~PlatformViewAndroid() {
if (window_)
ReleaseWindow();
}
void PlatformView::ConnectToViewportObserver(
mojo::InterfaceRequest<ViewportObserver> request) {
config_.ui_task_runner->PostTask(
FROM_HERE,
base::Bind(&UIDelegate::ConnectToViewportObserver, config_.ui_delegate,
base::Passed(&request)));
}
void PlatformView::Detach(JNIEnv* env, jobject obj) {
void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) {
DCHECK(!window_);
}
void PlatformView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) {
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
@@ -59,20 +47,16 @@ void PlatformView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) {
base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
window_ = ANativeWindow_fromSurface(env, jsurface);
}
config_.ui_task_runner->PostTask(
FROM_HERE, base::Bind(&UIDelegate::OnAcceleratedWidgetAvailable,
config_.ui_delegate, window_));
SurfaceWasCreated();
}
void PlatformView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) {
DCHECK(window_);
config_.ui_task_runner->PostTask(
FROM_HERE,
base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, config_.ui_delegate));
SurfaceWasDestroyed();
ReleaseWindow();
}
void PlatformView::ReleaseWindow() {
void PlatformViewAndroid::ReleaseWindow() {
ANativeWindow_release(window_);
window_ = nullptr;
}

View File

@@ -0,0 +1,36 @@
// 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 PlatformViewAndroid : public PlatformView {
public:
static bool Register(JNIEnv* env);
~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);
private:
void ReleaseWindow();
ANativeWindow* window_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewAndroid);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_PLATFORM_VIEW_ANDROID_H_

View File

@@ -0,0 +1,41 @@
// 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::PlatformView(const PlatformView::Config& config)
: config_(config), window_(0) {
}
PlatformView::~PlatformView() {
}
void PlatformView::ConnectToViewportObserver(
mojo::InterfaceRequest<ViewportObserver> request) {
config_.ui_task_runner->PostTask(
FROM_HERE, base::Bind(&UIDelegate::ConnectToViewportObserver,
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

View File

@@ -2,18 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_SKY_VIEW_H_
#define SKY_SHELL_SKY_VIEW_H_
#ifndef SKY_SHELL_PLATFORM_VIEW_H_
#define SKY_SHELL_PLATFORM_VIEW_H_
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "sky/shell/ui_delegate.h"
struct ANativeWindow;
namespace sky {
namespace shell {
@@ -24,34 +19,24 @@ class PlatformView {
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner;
};
static bool Register(JNIEnv* env);
explicit PlatformView(const Config& config);
~PlatformView();
virtual ~PlatformView();
void ConnectToViewportObserver(
mojo::InterfaceRequest<ViewportObserver> request);
// Called from Java
void Detach(JNIEnv* env, jobject obj);
void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface);
void SurfaceDestroyed(JNIEnv* env, jobject obj);
void SurfaceSetSize(JNIEnv* env,
jobject obj,
jint width,
jint height,
jfloat density);
private:
void ReleaseWindow();
protected:
void SurfaceWasCreated();
void SurfaceWasDestroyed();
Config config_;
ANativeWindow* window_;
gfx::AcceleratedWidget window_;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformView);
};
} // namespace shell
} // namespace sky
#endif // SKY_SHELL_SKY_VIEW_H_
#endif // SKY_SHELL_PLATFORM_VIEW_H_

View File

@@ -18,13 +18,10 @@ namespace shell {
class ServiceProviderContext {
public:
#if defined(OS_ANDROID)
ServiceProviderContext(
scoped_refptr<base::SingleThreadTaskRunner> runner)
: java_task_runner(runner.Pass()) {}
ServiceProviderContext(scoped_refptr<base::SingleThreadTaskRunner> runner)
: platform_task_runner(runner.Pass()) {}
scoped_refptr<base::SingleThreadTaskRunner> java_task_runner;
#endif
scoped_refptr<base::SingleThreadTaskRunner> platform_task_runner;
};
// Implemented in platform_service_provider.cc for each platform.

View File

@@ -9,8 +9,7 @@
#include "mojo/common/message_pump_mojo.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/simple_platform_support.h"
#include "sky/shell/android/platform_service_provider.h"
#include "sky/shell/android/platform_view.h"
#include "sky/shell/platform_view.h"
#include "sky/shell/gpu/rasterizer.h"
#include "sky/shell/ui/engine.h"