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 72fe725d485f71a811b10173a6871ed0c5d5a1cf..08a5ba131b5bd49a57830cecd23c901470230d8e 100644 |
--- a/content/browser/renderer_host/compositor_impl_android.cc |
+++ b/content/browser/renderer_host/compositor_impl_android.cc |
@@ -12,6 +12,7 @@ |
#include "base/android/scoped_java_ref.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/containers/scoped_ptr_hash_map.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/single_thread_task_runner.h" |
@@ -43,6 +44,9 @@ |
#include "ui/gfx/android/device_display_info.h" |
#include "ui/gfx/android/java_bitmap.h" |
#include "ui/gfx/frame_time.h" |
+#include "ui/gl/android/scoped_java_surface.h" |
+#include "ui/gl/android/surface_texture.h" |
+#include "ui/gl/android/surface_texture_tracker.h" |
#include "webkit/common/gpu/context_provider_in_process.h" |
#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
@@ -131,6 +135,62 @@ class TransientUIResource : public cc::ScopedUIResource { |
bool retrieved_; |
}; |
+class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { |
+ public: |
+ SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) { |
+ gfx::SurfaceTextureTracker::InitInstance(this); |
+ } |
+ |
+ virtual ~SurfaceTextureTrackerImpl() { |
+ gfx::SurfaceTextureTracker::InitInstance(NULL); |
+ } |
+ |
+ // Overridden from gfx::SurfaceTextureTracker: |
+ virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( |
+ int surface_texture_id) OVERRIDE { |
+ base::AutoLock lock(surface_textures_lock_); |
+ scoped_ptr<SurfaceTextureInfo> info = |
+ surface_textures_.take_and_erase(surface_texture_id); |
+ return info ? info->surface_texture : NULL; |
+ } |
+ |
+ int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture) { |
+ int surface_texture_id = next_surface_texture_id_++; |
+ base::AutoLock lock(surface_textures_lock_); |
+ DCHECK(surface_textures_.find(surface_texture_id) == |
+ surface_textures_.end()); |
+ surface_textures_.set( |
+ surface_texture_id, |
+ make_scoped_ptr(new SurfaceTextureInfo(surface_texture))); |
+ return surface_texture_id; |
+ } |
+ |
+ jobject GetSurface(int surface_texture_id) const { |
reveman
2014/03/11 22:59:36
This should probably take a renderer_id to prevent
reveman
2014/03/13 21:36:00
Done.
|
+ base::AutoLock lock(surface_textures_lock_); |
+ SurfaceTextureMap::const_iterator it = |
+ surface_textures_.find(surface_texture_id); |
+ return it == surface_textures_.end() |
+ ? NULL |
+ : it->second->surface.j_surface().obj(); |
+ } |
+ |
+ private: |
+ struct SurfaceTextureInfo { |
+ explicit SurfaceTextureInfo(gfx::SurfaceTexture* surface_texture) |
+ : surface_texture(surface_texture), surface(surface_texture) {} |
+ |
+ scoped_refptr<gfx::SurfaceTexture> surface_texture; |
+ gfx::ScopedJavaSurface surface; |
+ }; |
+ |
+ typedef base::ScopedPtrHashMap<int, SurfaceTextureInfo> SurfaceTextureMap; |
+ SurfaceTextureMap surface_textures_; |
+ mutable base::Lock surface_textures_lock_; |
+ int next_surface_texture_id_; |
+}; |
+base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker = |
epennerAtGoogle
2014/03/12 00:45:06
Hold on, I thought the gfx::SurfaceTextureTracker
reveman
2014/03/12 16:07:06
gfx::SurfaceTextureTracker is just an interface an
epennerAtGoogle
2014/03/12 19:46:28
I think if this doesn't have to be a lazy-instance
reveman
2014/03/12 21:19:11
LazyInstance seems like a good match as we should
epennerAtGoogle
2014/03/12 23:10:14
Ah, your other comment cleared up why we can't cre
|
+ LAZY_INSTANCE_INITIALIZER; |
+ |
static bool g_initialized = false; |
} // anonymous namespace |
@@ -171,6 +231,25 @@ jobject CompositorImpl::GetSurface(int surface_id) { |
return jsurface; |
} |
+// static |
+jobject CompositorImpl::GetSurfaceTextureSurface(int surface_texture_id) { |
+ jobject jsurface = |
+ g_surface_texture_tracker.Pointer()->GetSurface(surface_texture_id); |
epennerAtGoogle
2014/03/12 00:45:06
Could CompositorImpl just own this and avoid a glo
reveman
2014/03/12 16:07:06
We need some thread-safe code here to allow the Ja
epennerAtGoogle
2014/03/12 19:46:28
Ahh okay if we've already gone the global route a
|
+ |
+ LOG_IF(WARNING, !jsurface) << "No surface for surface texture id " |
+ << surface_texture_id; |
+ return jsurface; |
+} |
+ |
+// static |
+int CompositorImpl::AllocateSurfaceTexture() { |
+ const int kDummyTextureId = 0; |
+ scoped_refptr<gfx::SurfaceTexture> surface_texture = |
+ make_scoped_refptr(new gfx::SurfaceTexture(kDummyTextureId)); |
epennerAtGoogle
2014/03/12 00:45:06
What thread will this happen on? I believe it has
reveman
2014/03/12 16:07:06
On the IO thread.
Having looked at the SurfaceTex
epennerAtGoogle
2014/03/12 19:46:28
I think you might be right on the creation part. U
reveman
2014/03/12 21:19:11
I'll probably switch this over to a real texture i
|
+ return g_surface_texture_tracker.Pointer()->AddSurfaceTexture( |
+ surface_texture.get()); |
+} |
+ |
CompositorImpl::CompositorImpl(CompositorClient* client, |
gfx::NativeWindow root_window) |
: root_layer_(cc::Layer::Create()), |