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

Side by Side Diff: sky/shell/platform_view.cc

Issue 1139873004: Make android directory for Android-specific bits of SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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/platform_view.h ('k') | sky/shell/service_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sky/shell/platform_view.h"
6
7 #include <android/input.h>
8 #include <android/native_window_jni.h>
9
10 #include "base/android/jni_android.h"
11 #include "base/bind.h"
12 #include "base/location.h"
13 #include "jni/PlatformView_jni.h"
14 #include "sky/shell/shell.h"
15
16 namespace sky {
17 namespace shell {
18
19 static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) {
20 PlatformView* view = Shell::Shared().view();
21 view->ConnectToViewportObserver(
22 mojo::MakeRequest<ViewportObserver>(mojo::ScopedMessagePipeHandle(
23 mojo::MessagePipeHandle(viewportObserverHandle))));
24 return reinterpret_cast<jlong>(view);
25 }
26
27 // static
28 bool PlatformView::Register(JNIEnv* env) {
29 return RegisterNativesImpl(env);
30 }
31
32 PlatformView::PlatformView(const Config& config)
33 : config_(config), window_(nullptr) {
34 }
35
36 PlatformView::~PlatformView() {
37 if (window_)
38 ReleaseWindow();
39 }
40
41 void PlatformView::ConnectToViewportObserver(
42 mojo::InterfaceRequest<ViewportObserver> request) {
43 config_.ui_task_runner->PostTask(
44 FROM_HERE,
45 base::Bind(&UIDelegate::ConnectToViewportObserver, config_.ui_delegate,
46 base::Passed(&request)));
47 }
48
49 void PlatformView::Detach(JNIEnv* env, jobject obj) {
50 DCHECK(!window_);
51 }
52
53 void PlatformView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) {
54 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface);
55 // Note: This ensures that any local references used by
56 // ANativeWindow_fromSurface are released immediately. This is needed as a
57 // workaround for https://code.google.com/p/android/issues/detail?id=68174
58 {
59 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
60 window_ = ANativeWindow_fromSurface(env, jsurface);
61 }
62 config_.ui_task_runner->PostTask(
63 FROM_HERE, base::Bind(&UIDelegate::OnAcceleratedWidgetAvailable,
64 config_.ui_delegate, window_));
65 }
66
67 void PlatformView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
68 DCHECK(window_);
69 config_.ui_task_runner->PostTask(
70 FROM_HERE,
71 base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, config_.ui_delegate));
72 ReleaseWindow();
73 }
74
75 void PlatformView::ReleaseWindow() {
76 ANativeWindow_release(window_);
77 window_ = nullptr;
78 }
79
80 } // namespace shell
81 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/platform_view.h ('k') | sky/shell/service_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698