summaryrefslogtreecommitdiffstats
path: root/content/browser/android/content_view_render_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/android/content_view_render_view.cc')
-rw-r--r--content/browser/android/content_view_render_view.cc150
1 files changed, 58 insertions, 92 deletions
diff --git a/content/browser/android/content_view_render_view.cc b/content/browser/android/content_view_render_view.cc
index 1db4e61..2e040c5 100644
--- a/content/browser/android/content_view_render_view.cc
+++ b/content/browser/android/content_view_render_view.cc
@@ -11,9 +11,9 @@
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "content/browser/android/content_view_core_impl.h"
#include "content/public/browser/android/compositor.h"
#include "content/public/browser/android/content_view_layer_renderer.h"
-#include "content/public/browser/android/draw_delegate.h"
#include "jni/ContentViewRenderView_jni.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
#include "ui/gfx/size.h"
@@ -21,121 +21,87 @@
#include <android/native_window_jni.h>
using base::android::ScopedJavaLocalRef;
-using base::android::ScopedJavaGlobalRef;
-using content::Compositor;
-using content::DrawDelegate;
-namespace {
-
-class CompositorClient : public Compositor::Client {
- public:
- virtual void ScheduleComposite() OVERRIDE;
-};
+namespace content {
-class ContentViewLayerRendererImpl;
+// static
+bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
-struct GlobalState {
- GlobalState() : g_scheduled_composite(false) {}
- ScopedJavaGlobalRef<jobject> j_obj;
- CompositorClient client;
- scoped_ptr<content::Compositor> compositor;
- scoped_ptr<WebKit::WebLayer> root_layer;
- scoped_ptr<ContentViewLayerRendererImpl> layer_renderer;
- bool g_scheduled_composite;
-};
+ContentViewRenderView::ContentViewRenderView()
+ : scheduled_composite_(false),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
-base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
+ContentViewRenderView::~ContentViewRenderView() {
+}
-content::Compositor* GetCompositor() {
- return g_global_state.Get().compositor.get();
+// static
+jint Init(JNIEnv* env, jclass clazz) {
+ ContentViewRenderView* content_view_render_view =
+ new ContentViewRenderView();
+ return reinterpret_cast<jint>(content_view_render_view);
}
-class ContentViewLayerRendererImpl : public content::ContentViewLayerRenderer {
- public:
- ContentViewLayerRendererImpl() {}
- virtual ~ContentViewLayerRendererImpl() {}
-
- private:
- virtual void AttachLayer(WebKit::WebLayer* layer) OVERRIDE {
- if (GetCompositor())
- g_global_state.Get().root_layer->addChild(layer);
- }
-
- virtual void DetachLayer(WebKit::WebLayer* layer) OVERRIDE {
- if (GetCompositor())
- layer->removeFromParent();
- }
-
- DISALLOW_COPY_AND_ASSIGN(ContentViewLayerRendererImpl);
-};
-
-void Composite() {
- g_global_state.Get().g_scheduled_composite = false;
- if (GetCompositor())
- GetCompositor()->Composite();
+void ContentViewRenderView::Destroy(JNIEnv* env, jobject obj) {
+ delete this;
}
-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));
- }
+void ContentViewRenderView::SetCurrentContentView(
+ JNIEnv* env, jobject obj, int native_content_view) {
+ InitCompositor();
+ ContentViewCoreImpl* content_view =
+ reinterpret_cast<ContentViewCoreImpl*>(native_content_view);
+ if (content_view)
+ compositor_->SetRootLayer(content_view->GetWebLayer());
}
-void InitCompositor() {
- if (GetCompositor())
+void ContentViewRenderView::SurfaceCreated(
+ JNIEnv* env, jobject obj, jobject jsurface) {
+ InitCompositor();
+ ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
+ if (!native_window)
return;
- Compositor::Initialize();
- g_global_state.Get().compositor.reset(
- 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());
- g_global_state.Get().layer_renderer.reset(new ContentViewLayerRendererImpl());
+ compositor_->SetWindowSurface(native_window);
+ ANativeWindow_release(native_window);
}
-} // anonymous namespace
-
-namespace content {
-
-// Register native methods
-bool RegisterContentViewRenderView(JNIEnv* env) {
- return RegisterNativesImpl(env);
+void ContentViewRenderView::SurfaceDestroyed(JNIEnv* env, jobject obj) {
+ compositor_->SetWindowSurface(NULL);
}
-static void Init(JNIEnv* env, jobject obj) {
- g_global_state.Get().j_obj.Reset(ScopedJavaLocalRef<jobject>(env, obj));
+void ContentViewRenderView::SurfaceSetSize(
+ JNIEnv* env, jobject obj, jint width, jint height) {
+ compositor_->SetWindowBounds(gfx::Size(width, height));
}
-static jint GetNativeContentViewLayerRenderer(JNIEnv* env, jclass clazz) {
- // The compositor might not have been initialized yet.
- InitCompositor();
- // Note it's important to static cast to the interface here as we'll
- // reinterpret cast the jint back to the interace later on.
- return reinterpret_cast<jint>(static_cast<content::ContentViewLayerRenderer*>(
- g_global_state.Get().layer_renderer.get()));
-}
+void ContentViewRenderView::ScheduleComposite() {
+ if (scheduled_composite_)
+ return;
-static void SurfaceCreated(
- JNIEnv* env, jclass clazz, jobject jsurface) {
- InitCompositor();
- 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());
- }
+ scheduled_composite_ = true;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ContentViewRenderView::Composite,
+ weak_factory_.GetWeakPtr()));
}
-static void SurfaceDestroyed(JNIEnv* env, jclass clazz) {
- GetCompositor()->SetWindowSurface(NULL);
+void ContentViewRenderView::InitCompositor() {
+ if (compositor_.get())
+ return;
+
+ Compositor::Initialize();
+ compositor_.reset(Compositor::Create(this));
}
-static void SurfaceSetSize(
- JNIEnv* env, jclass clazz, jint width, jint height) {
- gfx::Size size = gfx::Size(width, height);
- DrawDelegate::GetInstance()->SetBounds(size);
- GetCompositor()->SetWindowBounds(size);
+void ContentViewRenderView::Composite() {
+ if (!compositor_.get())
+ return;
+
+ scheduled_composite_ = false;
+ compositor_->Composite();
}
} // namespace content