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..b7a45f6bf49366c5be9778aa1d628313bb07aea8 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,69 @@ class TransientUIResource : public cc::ScopedUIResource { |
bool retrieved_; |
}; |
+class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { |
+ public: |
+ SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {} |
+ |
+ // Overridden from gfx::SurfaceTextureTracker: |
+ virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( |
+ int surface_texture_id) OVERRIDE { |
+ base::AutoLock lock(surface_textures_lock_); |
+ for (SurfaceTextureMap::iterator it = surface_textures_.begin(); |
+ it != surface_textures_.end(); |
+ ++it) { |
+ if (it->first.second == surface_texture_id) { |
+ scoped_ptr<SurfaceTextureInfo> info = |
+ surface_textures_.take_and_erase(it); |
+ DCHECK(info); |
+ return info->surface_texture; |
+ } |
+ } |
+ return NULL; |
+ } |
+ |
+ int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture, |
no sievers
2014/03/14 01:24:51
How do they ever get deleted? :)
reveman
2014/03/14 19:44:53
Removed using AcquireSurfaceTexture() above, which
|
+ int render_process_id) { |
+ int surface_texture_id = next_surface_texture_id_++; |
+ if (next_surface_texture_id_ == INT_MAX) |
+ next_surface_texture_id_ = 1; |
+ |
+ base::AutoLock lock(surface_textures_lock_); |
no sievers
2014/03/14 01:24:51
You should hold the lock when modifying next_surfa
reveman
2014/03/14 19:44:53
This should always be called from browser IO threa
|
+ SurfaceTextureMapKey key(render_process_id, surface_texture_id); |
+ DCHECK(surface_textures_.find(key) == surface_textures_.end()); |
+ surface_textures_.set( |
+ key, make_scoped_ptr(new SurfaceTextureInfo(surface_texture))); |
+ return surface_texture_id; |
+ } |
+ |
+ jobject GetSurface(int render_process_id, int surface_texture_id) const { |
+ base::AutoLock lock(surface_textures_lock_); |
+ SurfaceTextureMap::const_iterator it = surface_textures_.find( |
+ SurfaceTextureMapKey(render_process_id, 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 std::pair<int, int> SurfaceTextureMapKey; |
+ typedef base::ScopedPtrHashMap<SurfaceTextureMapKey, SurfaceTextureInfo> |
+ SurfaceTextureMap; |
+ SurfaceTextureMap surface_textures_; |
+ mutable base::Lock surface_textures_lock_; |
+ int next_surface_texture_id_; |
+}; |
+base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
static bool g_initialized = false; |
} // anonymous namespace |
@@ -152,6 +219,9 @@ Compositor* Compositor::Create(CompositorClient* client, |
// static |
void Compositor::Initialize() { |
DCHECK(!CompositorImpl::IsInitialized()); |
+ // SurfaceTextureTracker instance must be set before we create a GPU thread |
+ // that could be using it to initialize GLImage instances. |
+ gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer()); |
g_initialized = true; |
} |
@@ -171,6 +241,26 @@ jobject CompositorImpl::GetSurface(int surface_id) { |
return jsurface; |
} |
+// static |
+jobject CompositorImpl::GetSurfaceTextureSurface(int render_process_id, |
+ int surface_texture_id) { |
+ jobject jsurface = g_surface_texture_tracker.Pointer()->GetSurface( |
+ render_process_id, surface_texture_id); |
+ |
+ LOG_IF(WARNING, !jsurface) << "No surface for surface texture id " |
+ << surface_texture_id; |
+ return jsurface; |
+} |
+ |
+// static |
+int CompositorImpl::AllocateSurfaceTexture(int render_process_id) { |
+ const int kDummyTextureId = 0; |
+ scoped_refptr<gfx::SurfaceTexture> surface_texture = |
+ gfx::SurfaceTexture::Create(kDummyTextureId); |
+ return g_surface_texture_tracker.Pointer()->AddSurfaceTexture( |
+ surface_texture.get(), render_process_id); |
+} |
+ |
CompositorImpl::CompositorImpl(CompositorClient* client, |
gfx::NativeWindow root_window) |
: root_layer_(cc::Layer::Create()), |