| Index: content/public/android/java/src/org/chromium/content/browser/ExternalVideoSurfaceViewHolder.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ExternalVideoSurfaceViewHolder.java b/content/public/android/java/src/org/chromium/content/browser/ExternalVideoSurfaceViewHolder.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..505ef2093716e5ccca0cf2b35acdb456f547437a
|
| --- /dev/null
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/ExternalVideoSurfaceViewHolder.java
|
| @@ -0,0 +1,110 @@
|
| +// Copyright (c) 2013 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.content.browser;
|
| +
|
| +import android.content.Context;
|
| +import android.util.Log;
|
| +import android.view.Gravity;
|
| +import android.view.Surface;
|
| +import android.view.SurfaceHolder;
|
| +import android.view.SurfaceView;
|
| +import android.widget.FrameLayout;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.JNINamespace;
|
| +
|
| +/**
|
| + * Provides a container that may hold an external video surface.
|
| + * The surface will be created on-demand.
|
| + */
|
| +@JNINamespace("content")
|
| +public class ExternalVideoSurfaceViewHolder extends FrameLayout implements SurfaceHolder.Callback {
|
| + private static final String TAG = ExternalVideoSurfaceViewHolder.class.getSimpleName();
|
| +
|
| + // SurfaceView object that holding an external surface to render video.
|
| + private SurfaceView mSurfaceView = null;
|
| +
|
| + // Native pointer to C++ ExternalVideoSurfaceViewHolder object which will be set by
|
| + // nativeInit().
|
| + private int mNativeExternalVideoSurfaceViewHolder = 0;
|
| +
|
| + /**
|
| + * Constructs a new ExternalVideoSurfaceViewHolder.
|
| + *
|
| + * @param context The context used to create this.
|
| + */
|
| + public ExternalVideoSurfaceViewHolder(Context context) {
|
| + super(context);
|
| + mNativeExternalVideoSurfaceViewHolder = nativeInit();
|
| + assert mNativeExternalVideoSurfaceViewHolder != 0;
|
| + }
|
| +
|
| + /**
|
| + * Destroy the internal state of ExternalVideoSurfaceViewHolder.
|
| + */
|
| + public void destroy() {
|
| + if (mSurfaceView != null) {
|
| + mSurfaceView.getHolder().removeCallback(this);
|
| + removeView(mSurfaceView);
|
| + }
|
| + nativeDestroy(mNativeExternalVideoSurfaceViewHolder);
|
| + mNativeExternalVideoSurfaceViewHolder = 0;
|
| + }
|
| +
|
| + /**
|
| + * Request external video surface to be created.
|
| + */
|
| + @CalledByNative
|
| + public void requestExternalVideoSurface() {
|
| + if (mSurfaceView == null) {
|
| + mSurfaceView = new SurfaceView(getContext());
|
| + mSurfaceView.getHolder().addCallback(this);
|
| +
|
| + addView(mSurfaceView, new FrameLayout.LayoutParams(
|
| + FrameLayout.LayoutParams.MATCH_PARENT,
|
| + FrameLayout.LayoutParams.MATCH_PARENT,
|
| + Gravity.NO_GRAVITY));
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * For ContentViewCore to inject native pointer to ContentViewCoreImpl C++ object.
|
| + * @return native pointer to C++ object.
|
| + */
|
| + int getNativeExternalVideoSurfaceViewHolder() {
|
| + return mNativeExternalVideoSurfaceViewHolder;
|
| + }
|
| +
|
| + // SurfaceHolder.Callback implementations.
|
| +
|
| + @Override
|
| + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
| + }
|
| +
|
| + @Override
|
| + public void surfaceCreated(SurfaceHolder holder) {
|
| + if (mNativeExternalVideoSurfaceViewHolder == 0) {
|
| + Log.e(TAG, "Destroyed native object already.");
|
| + return;
|
| + }
|
| + nativeAttachExternalVideoSurface(mNativeExternalVideoSurfaceViewHolder,
|
| + holder.getSurface());
|
| + }
|
| +
|
| + @Override
|
| + public void surfaceDestroyed(SurfaceHolder holder) {
|
| + if (mNativeExternalVideoSurfaceViewHolder == 0) {
|
| + Log.e(TAG, "Destroyed native object already.");
|
| + return;
|
| + }
|
| + nativeDetachExternalVideoSurface(mNativeExternalVideoSurfaceViewHolder);
|
| + }
|
| +
|
| + private native int nativeInit();
|
| + private native void nativeDestroy(int nativeExternalVideoSurfaceViewHolder);
|
| + private native void nativeAttachExternalVideoSurface(int nativeExternalVideoSurfaceViewHolder,
|
| + Surface surface);
|
| + private native void nativeDetachExternalVideoSurface(int nativeExternalVideoSurfaceViewHolder);
|
| +}
|
|
|