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

Unified Diff: sky/shell/sky_view.cc

Issue 890803004: SkyShell should be able to draw a green square with GL (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« sky/shell/library_loader.cc ('K') | « sky/shell/sky_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/shell/sky_view.cc
diff --git a/sky/shell/sky_view.cc b/sky/shell/sky_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7e6d2d06c74440f6a7a6bdb4e198b627bd1163e
--- /dev/null
+++ b/sky/shell/sky_view.cc
@@ -0,0 +1,72 @@
+// 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/sky_view.h"
+
+#include <android/input.h>
+#include <android/native_window_jni.h>
+
+#include "base/android/jni_android.h"
+#include "jni/SkyView_jni.h"
+
+namespace sky {
+namespace shell {
+
+// static
+bool SkyView::Register(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+SkyView::Delegate::~Delegate() {
+}
+
+SkyView::SkyView(Delegate* delegate) : delegate_(delegate), window_(NULL) {
+}
+
+SkyView::~SkyView() {
+ if (window_)
+ ReleaseWindow();
+}
+
+void SkyView::Init() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_SkyView_createForActivity(env, base::android::GetApplicationContext(),
+ reinterpret_cast<jlong>(this));
+}
+
+void SkyView::Destroy(JNIEnv* env, jobject obj) {
+ delegate_->OnDestroyed();
+}
+
+void SkyView::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);
+ }
+ delegate_->OnAcceleratedWidgetAvailable(window_);
+}
+
+void SkyView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
+ DCHECK(window_);
+ ReleaseWindow();
+}
+
+void SkyView::SurfaceSetSize(JNIEnv* env,
+ jobject obj,
+ jint width,
+ jint height,
+ jfloat density) {
+}
+
+void SkyView::ReleaseWindow() {
+ ANativeWindow_release(window_);
+ window_ = NULL;
+}
+
+} // namespace shell
+} // namespace sky
« sky/shell/library_loader.cc ('K') | « sky/shell/sky_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698