diff options
author | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-10 03:49:11 +0000 |
---|---|---|
committer | jcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-10 03:49:11 +0000 |
commit | 48224a7a9f5cbae5fcf0344bbd24a660f5b5c1c8 (patch) | |
tree | e81ad98492cfec475283a3981f5858cc0ebfa0b5 /chrome/android | |
parent | 49375dc24ab9a6a8a1ec12c4639ea4a71f687a6f (diff) | |
download | chromium_src-48224a7a9f5cbae5fcf0344bbd24a660f5b5c1c8.zip chromium_src-48224a7a9f5cbae5fcf0344bbd24a660f5b5c1c8.tar.gz chromium_src-48224a7a9f5cbae5fcf0344bbd24a660f5b5c1c8.tar.bz2 |
Created a new class ContentViewRenderView which contains the code used to
bridge the compositor to the SurfaceView.
Make ContentShell and ChromiumTestShell use that class.
BUG=None
TEST=ContentShell and ChromiumTestShell should still work.
Review URL: https://chromiumcodereview.appspot.com/11369136
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/android')
3 files changed, 31 insertions, 114 deletions
diff --git a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/TabManager.java b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/TabManager.java index 649b40f..b5f64c7 100644 --- a/chrome/android/testshell/java/src/org/chromium/chrome/testshell/TabManager.java +++ b/chrome/android/testshell/java/src/org/chromium/chrome/testshell/TabManager.java @@ -5,9 +5,6 @@ package org.chromium.chrome.testshell; import android.util.AttributeSet; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; import android.view.ViewGroup; import android.content.Context; import android.widget.FrameLayout; @@ -15,14 +12,14 @@ import android.widget.LinearLayout; import org.chromium.base.JNINamespace; -import org.chromium.chrome.browser.ChromeWebContentsDelegateAndroid; import org.chromium.chrome.browser.TabBase; +import org.chromium.content.browser.ContentViewRenderView; import org.chromium.ui.gfx.NativeWindow; /** * The TabManager hooks together all of the related {@link View}s that are used to represent * a {@link TabBase}. It properly builds a {@link TabBase} and makes sure that the {@link Toolbar} - * and {@link SurfaceView} show the proper content. + * and {@link ContentViewRenderView} show the proper content. */ @JNINamespace("chrome") public class TabManager extends LinearLayout { @@ -30,7 +27,7 @@ public class TabManager extends LinearLayout { private NativeWindow mWindow; private ViewGroup mContentViewHolder; - private SurfaceView mRenderTarget; + private ContentViewRenderView mRenderTarget; private TestShellToolbar mToolbar; private TabBase mCurrentTab; @@ -43,7 +40,6 @@ public class TabManager extends LinearLayout { */ public TabManager(Context context, AttributeSet attrs) { super(context, attrs); - nativeInit(this); } @Override @@ -52,25 +48,16 @@ public class TabManager extends LinearLayout { mContentViewHolder = (ViewGroup) findViewById(R.id.content_container); mToolbar = (TestShellToolbar) findViewById(R.id.toolbar); - mRenderTarget = (SurfaceView) findViewById(R.id.render_target); - mRenderTarget.getHolder().addCallback(new SurfaceHolder.Callback() { + mRenderTarget = new ContentViewRenderView(getContext()) { @Override - public void surfaceDestroyed(SurfaceHolder holder) { - nativeSurfaceDestroyed(); - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - nativeSurfaceCreated(holder.getSurface()); - + protected void onReadyToRender() { if (mCurrentTab == null) createTab(mStartupUrl); } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - nativeSurfaceSetSize(width, height); - } - }); + }; + mContentViewHolder.addView(mRenderTarget, + new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.MATCH_PARENT)); } /** @@ -106,13 +93,14 @@ public class TabManager extends LinearLayout { } private boolean isRenderTargetInitialized() { - return mRenderTarget != null && mRenderTarget.getHolder().getSurface() != null; + return mRenderTarget != null && mRenderTarget.isInitialized(); } private void setCurrentTab(TabBase tab) { + int nativeContentViewLayerRenderer = mRenderTarget.getNativeContentViewLayerRenderer(); if (mCurrentTab != null) { mContentViewHolder.removeView(mCurrentTab.getContentView()); - nativeHideTab(mCurrentTab.getNativeTab()); + nativeHideTab(mCurrentTab.getNativeTab(), nativeContentViewLayerRenderer); mCurrentTab.destroy(); } @@ -121,13 +109,9 @@ public class TabManager extends LinearLayout { mToolbar.showTab(mCurrentTab); mContentViewHolder.addView(mCurrentTab.getContentView()); mCurrentTab.getContentView().requestFocus(); - nativeShowTab(mCurrentTab.getNativeTab()); + nativeShowTab(mCurrentTab.getNativeTab(), nativeContentViewLayerRenderer); } - private static native void nativeShowTab(int jtab); - private static native void nativeHideTab(int jtab); - private static native void nativeInit(Object renderTargetInstance); - private static native void nativeSurfaceCreated(Surface surface); - private static native void nativeSurfaceDestroyed(); - private static native void nativeSurfaceSetSize(int width, int height); + private static native void nativeShowTab(int jtab, int contentViewLayerRenderer); + private static native void nativeHideTab(int jtab, int contentViewLayerRenderer); }
\ No newline at end of file diff --git a/chrome/android/testshell/res/layout/testshell_activity.xml b/chrome/android/testshell/res/layout/testshell_activity.xml index 43323a6..4346e59 100644 --- a/chrome/android/testshell/res/layout/testshell_activity.xml +++ b/chrome/android/testshell/res/layout/testshell_activity.xml @@ -44,9 +44,6 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> - <SurfaceView android:id="@+id/render_target" - android:layout_width="match_parent" - android:layout_height="match_parent" /> </FrameLayout> - + </org.chromium.chrome.testshell.TabManager> diff --git a/chrome/android/testshell/tab_manager.cc b/chrome/android/testshell/tab_manager.cc index fc379dd..0a9da47 100644 --- a/chrome/android/testshell/tab_manager.cc +++ b/chrome/android/testshell/tab_manager.cc @@ -12,52 +12,14 @@ #include "base/lazy_instance.h" #include "base/message_loop.h" #include "chrome/browser/android/tab_base_android_impl.h" -#include "content/public/browser/android/compositor.h" -#include "content/public/browser/android/draw_delegate.h" +#include "content/public/browser/android/content_view_layer_renderer.h" #include "jni/TabManager_jni.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" #include <android/native_window_jni.h> using base::android::ScopedJavaLocalRef; - -namespace { - -class CompositorClient : public content::Compositor::Client { - public: - virtual void ScheduleComposite() OVERRIDE; -}; - -struct GlobalState { - GlobalState() - : g_scheduled_composite(false) {} - CompositorClient client; - scoped_ptr<content::Compositor> compositor; - scoped_ptr<WebKit::WebLayer> root_layer; - bool g_scheduled_composite; -}; - -base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; - -content::Compositor* GetCompositor() { - return g_global_state.Get().compositor.get(); -} - -void Composite() { - g_global_state.Get().g_scheduled_composite = false; - if (GetCompositor()) { - GetCompositor()->Composite(); - } -} - -void CompositorClient::ScheduleComposite() { - if (!g_global_state.Get().g_scheduled_composite) { - g_global_state.Get().g_scheduled_composite = true; - MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&Composite)); - } -} - -} // anonymous namespace +using content::ContentViewLayerRenderer; namespace chrome { @@ -66,48 +28,22 @@ bool RegisterTabManager(JNIEnv* env) { return RegisterNativesImpl(env); } -static void Init(JNIEnv* env, jclass clazz, jobject obj) { - if (!GetCompositor()) { - content::Compositor::Initialize(); - g_global_state.Get().compositor.reset(content::Compositor::Create( - &g_global_state.Get().client)); - DCHECK(!g_global_state.Get().root_layer.get()); - g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); - } -} - -static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) { - ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); - if (native_window) { - GetCompositor()->SetWindowSurface(native_window); - ANativeWindow_release(native_window); - GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get()); - } -} - -static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { - GetCompositor()->SetWindowSurface(NULL); -} - -static void SurfaceSetSize( - JNIEnv* env, jclass clazz, jint width, jint height) { - gfx::Size size = gfx::Size(width, height); - content::DrawDelegate::GetInstance()->SetBounds(size); - GetCompositor()->SetWindowBounds(size); -} - -static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) { - if (!GetCompositor()) - return; +static void ShowTab(JNIEnv* env, jclass clazz, jint jtab, + jint j_content_view_layer_renderer) { TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); - g_global_state.Get().root_layer->addChild(tab->tab_layer()); + ContentViewLayerRenderer* content_view_layer_renderer = + reinterpret_cast<ContentViewLayerRenderer*>( + j_content_view_layer_renderer); + content_view_layer_renderer->AttachLayer(tab->tab_layer()); } -static void HideTab(JNIEnv* env, jclass clazz, jint jtab) { - if (!GetCompositor()) - return; +static void HideTab(JNIEnv* env, jclass clazz, jint jtab, + jint j_content_view_layer_renderer) { TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); - tab->tab_layer()->removeFromParent(); + ContentViewLayerRenderer* content_view_layer_renderer = + reinterpret_cast<ContentViewLayerRenderer*>( + j_content_view_layer_renderer); + content_view_layer_renderer->DetachLayer(tab->tab_layer()); } } // namespace chrome |