Chromium Code Reviews| Index: content/shell/android/shell_manager.cc |
| diff --git a/content/shell/android/shell_manager.cc b/content/shell/android/shell_manager.cc |
| index 26c2240778ec4c646dbc8e0714a21555fc6cdf50..470c41e6c08d6c821921713d2160bfac7b651514 100644 |
| --- a/content/shell/android/shell_manager.cc |
| +++ b/content/shell/android/shell_manager.cc |
| @@ -9,42 +9,51 @@ |
| #include "base/android/scoped_java_ref.h" |
| #include "base/bind.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "content/shell/shell.h" |
| #include "content/shell/shell_browser_context.h" |
| #include "content/shell/shell_content_browser_client.h" |
| +#include "content/public/browser/android/compositor.h" |
| #include "content/public/browser/android/draw_delegate.h" |
| -#include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| -#include "content/shell/android/draw_context.h" |
| #include "content/shell/shell.h" |
| #include "googleurl/src/gurl.h" |
| #include "jni/ShellManager_jni.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
| #include "ui/gfx/size.h" |
| #include <android/native_window_jni.h> |
| using base::android::ScopedJavaLocalRef; |
| -using content::DrawContext; |
| +using content::Compositor; |
| using content::DrawDelegate; |
| namespace { |
| struct GlobalState { |
| - GlobalState() |
| - : context(NULL) { |
| - } |
| base::android::ScopedJavaGlobalRef<jobject> j_obj; |
| - DrawContext* context; |
| + scoped_ptr<content::Compositor> compositor; |
| + scoped_ptr<WebKit::WebLayer> root_layer; |
| }; |
| base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; |
| +content::Compositor* GetCompositor() { |
| + return g_global_state.Get().compositor.get(); |
| +} |
| + |
| +static void SurfacePresented( |
| + const DrawDelegate::SurfacePresentedCallback& callback, |
| + uint32 sync_point) { |
| + callback.Run(sync_point); |
| +} |
| + |
| static void SurfaceUpdated( |
| uint64 texture, |
| content::RenderWidgetHostView* view, |
| const DrawDelegate::SurfacePresentedCallback& callback) { |
| - uint32 sync_point = g_global_state.Get().context->Draw(texture); |
| - callback.Run(sync_point); |
| + GetCompositor()->OnSurfaceUpdated(base::Bind( |
| + &SurfacePresented, callback)); |
| } |
| } // anonymous namespace |
| @@ -74,25 +83,27 @@ static void SurfaceCreated( |
| JNIEnv* env, jclass clazz, jobject jsurface) { |
| ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); |
| if (native_window) { |
| - if (g_global_state.Get().context) |
| - delete g_global_state.Get().context; |
| - |
| - g_global_state.Get().context = new DrawContext(native_window); |
| + if (!GetCompositor()) { |
| + Compositor::Initialize(); |
|
klobag.chromium
2012/08/29 04:29:43
I like the old way (in #3) where you create compos
no sievers
2012/08/29 16:17:52
But I cannot call Initialize() in Init() because i
klobag.chromium
2012/08/29 22:55:05
How about in CreateShellView()?
On 2012/08/29 16:
no sievers
2012/08/29 23:09:22
That works. Done.
|
| + g_global_state.Get().compositor.reset(Compositor::Create()); |
| + } |
| + GetCompositor()->SetWindowSurface(native_window); |
| ANativeWindow_release(native_window); |
| + if (!g_global_state.Get().root_layer.get()) |
|
klobag.chromium
2012/08/29 04:29:43
If compositor is created once, do we want to set r
no sievers
2012/08/29 16:17:52
Yes, I'll change that.
|
| + g_global_state.Get().root_layer.reset(WebKit::WebLayer::create()); |
| + GetCompositor()->SetRootLayer(g_global_state.Get().root_layer.get()); |
| } |
| } |
| static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { |
| - if (g_global_state.Get().context) |
| - delete g_global_state.Get().context; |
| + GetCompositor()->SetWindowSurface(NULL); |
| } |
| static void SurfaceSetSize( |
| JNIEnv* env, jclass clazz, jint width, jint height) { |
| gfx::Size size = gfx::Size(width, height); |
| DrawDelegate::GetInstance()->SetBounds(size); |
| - DCHECK(g_global_state.Get().context); |
| - g_global_state.Get().context->Reshape(width, height); |
| + GetCompositor()->SetWindowBounds(size); |
| } |
| void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) { |
| @@ -107,4 +118,13 @@ void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) { |
| NULL); |
| } |
| +void ShellAttachLayer(WebKit::WebLayer* layer) { |
| + g_global_state.Get().root_layer->addChild(layer); |
| +} |
| + |
| + |
| +void ShellRemoveLayer(WebKit::WebLayer* layer) { |
| + layer->removeFromParent(); |
| +} |
| + |
| } // namespace content |