Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: sky/shell/android/platform_view_android.cc

Issue 1187503003: Refactor SkyShell to allow multiple SkyViews (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: s/instance/sky_shell/ Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/shell/android/platform_view_android.h ('k') | sky/shell/ios/platform_view_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/shell/android/platform_view_android.h" 5 #include "sky/shell/android/platform_view_android.h"
6 6
7 #include <android/input.h> 7 #include <android/input.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "jni/PlatformViewAndroid_jni.h" 13 #include "jni/PlatformViewAndroid_jni.h"
14 #include "sky/shell/shell.h" 14 #include "sky/shell/shell.h"
15 #include "sky/shell/shell_view.h"
15 16
16 namespace sky { 17 namespace sky {
17 namespace shell { 18 namespace shell {
18 19
19 static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) { 20 static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) {
20 PlatformView* view = Shell::Shared().view(); 21 ShellView* shell_view = new ShellView(Shell::Shared());
22 auto view = static_cast<PlatformViewAndroid*>(shell_view->view());
23 view->SetShellView(make_scoped_ptr(shell_view));
21 view->ConnectToViewportObserver( 24 view->ConnectToViewportObserver(
22 mojo::MakeRequest<ViewportObserver>(mojo::ScopedMessagePipeHandle( 25 mojo::MakeRequest<ViewportObserver>(mojo::ScopedMessagePipeHandle(
23 mojo::MessagePipeHandle(viewportObserverHandle)))); 26 mojo::MessagePipeHandle(viewportObserverHandle))));
24 return reinterpret_cast<jlong>(view); 27 return reinterpret_cast<jlong>(shell_view->view());
25 } 28 }
26 29
27 // static 30 // static
28 bool PlatformViewAndroid::Register(JNIEnv* env) { 31 bool PlatformViewAndroid::Register(JNIEnv* env) {
29 return RegisterNativesImpl(env); 32 return RegisterNativesImpl(env);
30 } 33 }
31 34
35 PlatformView* PlatformView::Create(const Config& config) {
36 return new PlatformViewAndroid(config);
37 }
38
39 PlatformViewAndroid::PlatformViewAndroid(const Config& config)
40 : PlatformView(config) {
41 }
42
32 PlatformViewAndroid::~PlatformViewAndroid() { 43 PlatformViewAndroid::~PlatformViewAndroid() {
33 if (window_) 44 if (window_)
34 ReleaseWindow(); 45 ReleaseWindow();
35 } 46 }
36 47
37 void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) { 48 void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) {
38 DCHECK(!window_); 49 DCHECK(!window_);
50 shell_view_.reset();
51 // Note: |this| has been destroyed at this point.
39 } 52 }
40 53
41 void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurf ace) { 54 void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurf ace) {
42 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); 55 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface);
43 // Note: This ensures that any local references used by 56 // Note: This ensures that any local references used by
44 // ANativeWindow_fromSurface are released immediately. This is needed as a 57 // ANativeWindow_fromSurface are released immediately. This is needed as a
45 // workaround for https://code.google.com/p/android/issues/detail?id=68174 58 // workaround for https://code.google.com/p/android/issues/detail?id=68174
46 { 59 {
47 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 60 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
48 window_ = ANativeWindow_fromSurface(env, jsurface); 61 window_ = ANativeWindow_fromSurface(env, jsurface);
49 } 62 }
50 SurfaceWasCreated(); 63 SurfaceWasCreated();
51 } 64 }
52 65
53 void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { 66 void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) {
54 DCHECK(window_); 67 DCHECK(window_);
55 SurfaceWasDestroyed(); 68 SurfaceWasDestroyed();
56 ReleaseWindow(); 69 ReleaseWindow();
57 } 70 }
58 71
72 void PlatformViewAndroid::SetShellView(scoped_ptr<ShellView> shell_view) {
73 DCHECK(!shell_view_);
74 shell_view_ = shell_view.Pass();
75 }
76
59 void PlatformViewAndroid::ReleaseWindow() { 77 void PlatformViewAndroid::ReleaseWindow() {
60 ANativeWindow_release(window_); 78 ANativeWindow_release(window_);
61 window_ = nullptr; 79 window_ = nullptr;
62 } 80 }
63 81
64 } // namespace shell 82 } // namespace shell
65 } // namespace sky 83 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/android/platform_view_android.h ('k') | sky/shell/ios/platform_view_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698