Index: content/browser/renderer_host/compositor_impl_android.cc |
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc |
index e6aa5c02788b8f0e8633a6ee2bb89fe37e7cc024..a614ce8d68fbae98feca1caaff33233e71403e38 100644 |
--- a/content/browser/renderer_host/compositor_impl_android.cc |
+++ b/content/browser/renderer_host/compositor_impl_android.cc |
@@ -6,11 +6,15 @@ |
#include <android/bitmap.h> |
#include <android/native_window_jni.h> |
+#include <map> |
+#include "base/android/jni_android.h" |
+#include "base/android/scoped_java_ref.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
+#include "base/synchronization/lock.h" |
#include "cc/context_provider.h" |
#include "cc/input_handler.h" |
#include "cc/layer.h" |
@@ -57,6 +61,12 @@ static bool g_use_direct_gl = false; |
namespace content { |
+typedef std::map<int, base::android::ScopedJavaGlobalRef<jobject> > |
+ SurfaceMap; |
+static base::LazyInstance<SurfaceMap> |
+ g_surface_map = LAZY_INSTANCE_INITIALIZER; |
+static base::LazyInstance<base::Lock> g_surface_map_lock; |
+ |
// static |
Compositor* Compositor::Create(Client* client) { |
return client ? new CompositorImpl(client) : NULL; |
@@ -93,6 +103,17 @@ bool CompositorImpl::UsesDirectGL() { |
return g_use_direct_gl; |
} |
+// static |
+jobject CompositorImpl::GetSurface(int surface_id) { |
+ base::AutoLock lock(g_surface_map_lock.Get()); |
+ SurfaceMap* surfaces = g_surface_map.Pointer(); |
+ SurfaceMap::iterator it = surfaces->find(surface_id); |
+ jobject jsurface = it == surfaces->end() ? NULL : it->second.obj(); |
+ |
+ LOG_IF(WARNING, !jsurface) << "No surface for surface id " << surface_id; |
+ return jsurface; |
+} |
+ |
CompositorImpl::CompositorImpl(Compositor::Client* client) |
: root_layer_(cc::Layer::create()), |
has_transparent_background_(false), |
@@ -138,6 +159,26 @@ void CompositorImpl::SetWindowSurface(ANativeWindow* window) { |
} |
} |
+void CompositorImpl::SetSurface(jobject surface) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface); |
+ if (surface) { |
+ ANativeWindow* window = ANativeWindow_fromSurface(env, surface); |
+ SetWindowSurface(window); |
+ ANativeWindow_release(window); |
+ { |
+ base::AutoLock lock(g_surface_map_lock.Get()); |
+ g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface)); |
+ } |
+ } else { |
+ { |
+ base::AutoLock lock(g_surface_map_lock.Get()); |
+ g_surface_map.Get().erase(surface_id_); |
+ } |
+ SetWindowSurface(NULL); |
+ } |
+} |
+ |
void CompositorImpl::SetVisible(bool visible) { |
if (!visible) { |
host_.reset(); |