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 127e25a3d97ad546d8eb15d24c4145aff2046db1..03ca4edc3ec400a67c5d9715d0f5f1f875a17d44 100644 |
| --- a/content/shell/android/shell_manager.cc |
| +++ b/content/shell/android/shell_manager.cc |
| @@ -6,20 +6,49 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/scoped_java_ref.h" |
| +#include "base/bind.h" |
| #include "base/lazy_instance.h" |
| #include "jni/ShellManager_jni.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 "ui/gfx/size.h" |
| + |
| +#include <android/native_window_jni.h> |
| using base::android::ScopedJavaLocalRef; |
| +using content::DrawDelegate; |
| + |
| +namespace { |
| + |
| +struct GlobalState { |
| + GlobalState() |
| + : context(NULL) { |
| + } |
| + base::android::ScopedJavaGlobalRef<jobject> j_obj; |
| + DrawContext* context; |
| +}; |
| + |
| +base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; |
| -base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > |
| - g_content_shell_manager = LAZY_INSTANCE_INITIALIZER; |
| +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); |
| +} |
| + |
| +} // anonymous namespace |
| namespace content { |
| jobject CreateShellView() { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| return Java_ShellManager_createShell( |
| - env, g_content_shell_manager.Get().obj()).Release(); |
| + env, g_global_state.Get().j_obj.obj()).Release(); |
| } |
| // Register native methods |
| @@ -28,8 +57,45 @@ bool RegisterShellManager(JNIEnv* env) { |
| } |
| static void Init(JNIEnv* env, jclass clazz, jobject obj) { |
| - g_content_shell_manager.Get().Reset( |
| + g_global_state.Get().j_obj.Reset( |
| base::android::ScopedJavaLocalRef<jobject>(env, obj)); |
| + DrawDelegate::SurfaceUpdatedCallback cb = base::Bind( |
| + &SurfaceUpdated); |
| + DrawDelegate::GetInstance()->SetUpdateCallback(cb); |
| +} |
| + |
| +static void SurfaceCreated( |
| + JNIEnv* env, jclass clazz, jobject jsurface) { |
| + ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); |
| + if (native_window) { |
| + LOG(INFO) << "SurfaceCreated"; |
|
Ted C
2012/07/27 20:31:15
remove log?
no sievers
2012/07/31 01:28:44
Done.
|
| + |
| + if (g_global_state.Get().context) |
| + delete g_global_state.Get().context; |
| + |
| + g_global_state.Get().context = new DrawContext(native_window); |
| + ANativeWindow_release(native_window); |
| + } |
| +} |
| + |
| +static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { |
| + LOG(INFO) << "SurfaceDestroyed"; |
| + NOTIMPLEMENTED(); |
|
klobag.chromium
2012/07/27 19:42:22
Should we delete the context here as we can't touc
no sievers
2012/07/31 01:28:44
Done.
|
| +} |
| + |
| +static void SurfaceSetSize( |
| + JNIEnv* env, jclass clazz, jint width, jint height) { |
| + std::vector<Shell*> shells = Shell::windows(); |
| + for (size_t n = 0; n < shells.size(); n++) { |
| + WebContents* contents = shells[n]->web_contents(); |
| + RenderWidgetHostView* view = contents->GetRenderWidgetHostView(); |
| + if (view) { |
|
Ted C
2012/07/27 20:31:15
no braces needed
no sievers
2012/07/31 01:28:44
Done.
|
| + view->SetSize(gfx::Size(width, height)); |
| + } |
| + } |
| + |
| + DCHECK(g_global_state.Get().context); |
| + g_global_state.Get().context->Reshape(width, height); |
| } |
| } // namespace content |