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

Unified Diff: blimp/client/android/java/src/org/chromium/blimp/BlimpView.java

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some cleanup nits. Created 5 years, 4 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
Index: blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
new file mode 100644
index 0000000000000000000000000000000000000000..b358ae7dc7cbc358cc5cffbb6d2f99f89e383225
--- /dev/null
+++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpView.java
@@ -0,0 +1,127 @@
+// 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.chromium.blimp;
+
+import android.content.Context;
+import android.graphics.Point;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.WindowManager;
+
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * A {@link View} that will visually represent the Blimp rendered content. This {@link View} starts
+ * a native compositor.
+ */
+@JNINamespace("blimp")
+public class BlimpView extends SurfaceView implements SurfaceHolder.Callback2 {
+ private long mNativeBlimpViewPtr;
Wez 2015/08/27 02:01:51 n00b: Is mFoo the preferred form for member variab
David Trainor- moved to gerrit 2015/08/28 01:23:46 Ah yeah that's part of the Android style guide (ht
Wez 2015/09/03 00:49:26 Acknowledged.
+
+ /**
+ * Builds a new {@link BlimpView}.
+ * @param context A {@link Context} instance.
+ * @param attrs An {@link AttributeSet} instance.
+ */
+ public BlimpView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onFinishInflate() {
Wez 2015/08/27 02:01:51 Add a comment to clarify which interface this is o
David Trainor- moved to gerrit 2015/08/28 01:23:46 It's overriding a base class method. I can move i
Wez 2015/09/03 00:49:27 Acknowledged.
+ super.onFinishInflate();
+
+ setZOrderMediaOverlay(true);
+ setVisibility(GONE);
+ }
+
+ /**
+ * Starts up rendering for this {@link View}. This will start up the native compositor and will
+ * display it's contents.
+ */
+ public void initializeRenderer() {
+ assert mNativeBlimpViewPtr == 0;
+
+ WindowManager windowManager =
+ (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
+ Point displaySize = new Point();
+ windowManager.getDefaultDisplay().getSize(displaySize);
+ Point physicalSize = new Point();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ windowManager.getDefaultDisplay().getRealSize(physicalSize);
+ }
+ // TODO(dtrainor): Change 1.f to dpToPx once native fully supports dp.
+ float compositorDensity = 1.f;
+ mNativeBlimpViewPtr = nativeInit(
+ physicalSize.x, physicalSize.y, displaySize.x, displaySize.y, compositorDensity);
+ getHolder().addCallback(this);
+ setVisibility(VISIBLE);
+ }
+
+ /**
+ * Stops rendering for this {@link View} and destroys all internal state. This {@link View}
+ * should not be used after this.
+ */
+ public void destroyRenderer() {
+ getHolder().removeCallback(this);
+ if (mNativeBlimpViewPtr != 0) {
+ nativeDestroy(mNativeBlimpViewPtr);
+ mNativeBlimpViewPtr = 0;
+ }
+ }
+
+ /**
+ * Triggers a redraw of the native compositor, pushing a new frame.
+ */
+ public void setNeedsComposite() {
+ if (mNativeBlimpViewPtr == 0) return;
Wez 2015/08/27 02:01:51 nit: Braces, here and below
David Trainor- moved to gerrit 2015/08/28 01:23:46 See java style guide comment above.
Wez 2015/09/03 00:49:27 Acknowledged.
+ nativeSetNeedsComposite(mNativeBlimpViewPtr);
+ }
+
+ /**
+ * Toggles whether or not the native compositor draws to this {@link View} or not.
+ * @param visible Whether or not the compositor should draw or not.
+ */
+ public void setCompositorVisibility(boolean visible) {
+ if (mNativeBlimpViewPtr == 0) return;
+ nativeSetVisibility(mNativeBlimpViewPtr, visible);
+ }
+
+ // SurfaceHolder.Callback2 Implementation ------------------------------------------------------
Wez 2015/08/27 02:01:51 n00b nit: I thought this trailing --- thing was fr
David Trainor- moved to gerrit 2015/08/28 01:23:45 I think it helps see a clear break in between sect
Wez 2015/09/03 00:49:27 My personal preference is to do that with a larger
David Trainor- moved to gerrit 2015/09/03 06:33:21 I removed them all. I think you're right and this
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ if (mNativeBlimpViewPtr == 0) return;
+ nativeSurfaceChanged(mNativeBlimpViewPtr, format, width, height, holder.getSurface());
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (mNativeBlimpViewPtr == 0) return;
+ nativeSurfaceCreated(mNativeBlimpViewPtr);
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (mNativeBlimpViewPtr == 0) return;
+ nativeSurfaceDestroyed(mNativeBlimpViewPtr);
+ }
+
+ @Override
+ public void surfaceRedrawNeeded(SurfaceHolder holder) {}
+
+ // Native Methods ------------------------------------------------------------------------------
+ private native long nativeInit(int physicalWidth, int physicalHeight, int displayWidth,
+ int displayHeight, float dpToPixel);
+ private native void nativeDestroy(long nativeBlimpView);
+ private native void nativeSetNeedsComposite(long nativeBlimpView);
+ private native void nativeSurfaceChanged(
+ long nativeBlimpView, int format, int width, int height, Surface surface);
+ private native void nativeSurfaceCreated(long nativeBlimpView);
+ private native void nativeSurfaceDestroyed(long nativeBlimpView);
+ private native void nativeSetVisibility(long nativeBlimpView, boolean visible);
+}

Powered by Google App Engine
This is Rietveld 408576698