| 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 5427692d5ea970b3874e18cf14f67eb3737f2592..0ed33f4b9fad49dc19df2323ddfc2962d2f39f0a 100644
|
| --- a/content/browser/renderer_host/compositor_impl_android.cc
|
| +++ b/content/browser/renderer_host/compositor_impl_android.cc
|
| @@ -12,7 +12,6 @@
|
| #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"
|
| @@ -37,6 +36,7 @@
|
| #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
|
| #include "content/common/gpu/gpu_process_launch_causes.h"
|
| #include "content/public/browser/android/compositor_client.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "gpu/command_buffer/client/gles2_interface.h"
|
| #include "third_party/khronos/GLES2/gl2.h"
|
| #include "third_party/khronos/GLES2/gl2ext.h"
|
| @@ -136,25 +136,13 @@ class TransientUIResource : public cc::ScopedUIResource {
|
| bool retrieved_;
|
| };
|
|
|
| -class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
|
| +class SurfaceTextureManager {
|
| public:
|
| - SurfaceTextureTrackerImpl() : next_surface_texture_id_(1) {
|
| + SurfaceTextureManager() : next_surface_texture_id_(1) {
|
| thread_checker_.DetachFromThread();
|
| }
|
|
|
| - // Overridden from gfx::SurfaceTextureTracker:
|
| - virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture(
|
| - int primary_id,
|
| - int secondary_id) OVERRIDE {
|
| - base::AutoLock lock(surface_textures_lock_);
|
| - scoped_ptr<SurfaceTextureInfo> info =
|
| - surface_textures_.take_and_erase(SurfaceTextureMapKey(
|
| - primary_id, static_cast<base::ProcessHandle>(secondary_id)));
|
| - return info ? info->surface_texture : NULL;
|
| - }
|
| -
|
| - int AddSurfaceTexture(gfx::SurfaceTexture* surface_texture,
|
| - base::ProcessHandle process_handle) {
|
| + int AddSurfaceTexture(base::ProcessHandle process_handle) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| int surface_texture_id = next_surface_texture_id_++;
|
| if (next_surface_texture_id_ == INT_MAX)
|
| @@ -163,8 +151,7 @@ class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
|
| base::AutoLock lock(surface_textures_lock_);
|
| SurfaceTextureMapKey key(surface_texture_id, process_handle);
|
| DCHECK(surface_textures_.find(key) == surface_textures_.end());
|
| - surface_textures_.set(
|
| - key, make_scoped_ptr(new SurfaceTextureInfo(surface_texture)));
|
| + surface_textures_[key].Reset();
|
| return surface_texture_id;
|
| }
|
|
|
| @@ -187,27 +174,20 @@ class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker {
|
| SurfaceTextureMapKey(surface_texture_id, process_handle));
|
| return it == surface_textures_.end()
|
| ? NULL
|
| - : it->second->surface.j_surface().obj();
|
| + : it->second.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, base::ProcessHandle> SurfaceTextureMapKey;
|
| - typedef base::ScopedPtrHashMap<SurfaceTextureMapKey, SurfaceTextureInfo>
|
| + typedef std::map<SurfaceTextureMapKey,
|
| + base::android::ScopedJavaGlobalRef<jobject> >
|
| SurfaceTextureMap;
|
| SurfaceTextureMap surface_textures_;
|
| mutable base::Lock surface_textures_lock_;
|
| int next_surface_texture_id_;
|
| base::ThreadChecker thread_checker_;
|
| };
|
| -base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker =
|
| +base::LazyInstance<SurfaceTextureManager> g_surface_texture_manager =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| static bool g_initialized = false;
|
| @@ -231,9 +211,6 @@ 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;
|
| }
|
|
|
| @@ -257,7 +234,7 @@ jobject CompositorImpl::GetSurface(int surface_id) {
|
| jobject CompositorImpl::GetSurfaceTextureSurface(
|
| int surface_texture_id,
|
| base::ProcessHandle process_handle) {
|
| - jobject jsurface = g_surface_texture_tracker.Pointer()->GetSurface(
|
| + jobject jsurface = g_surface_texture_manager.Pointer()->GetSurface(
|
| surface_texture_id, process_handle);
|
|
|
| LOG_IF(WARNING, !jsurface) << "No surface for surface texture id "
|
| @@ -266,18 +243,36 @@ jobject CompositorImpl::GetSurfaceTextureSurface(
|
| }
|
|
|
| // static
|
| -int CompositorImpl::AllocateSurfaceTexture(base::ProcessHandle process_handle) {
|
| - const int kDummyTextureId = 0;
|
| - scoped_refptr<gfx::SurfaceTexture> surface_texture =
|
| - gfx::SurfaceTexture::Create(kDummyTextureId);
|
| - return g_surface_texture_tracker.Pointer()->AddSurfaceTexture(
|
| - surface_texture.get(), process_handle);
|
| +void CompositorImpl::CreateSurfaceTexture(
|
| + base::ProcessHandle process_handle,
|
| + const CreateSurfaceTextureCallback& callback) {
|
| + int surface_texture_id =
|
| + g_surface_texture_manager.Pointer()->AddSurfaceTexture(process_handle);
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + BrowserGpuChannelHostFactory* factory =
|
| + BrowserGpuChannelHostFactory::instance();
|
| + factory->CreateSurfaceTexture(
|
| + surface_texture_id,
|
| + process_handle,
|
| + base::Bind(&CompositorImpl::OnSurfaceTextureCreated,
|
| + surface_texture_id,
|
| + process_handle,
|
| + callback));
|
| }
|
|
|
| // static
|
| void CompositorImpl::DestroyAllSurfaceTextures(
|
| base::ProcessHandle process_handle) {
|
| - g_surface_texture_tracker.Pointer()->RemoveAllSurfaceTextures(process_handle);
|
| + g_surface_texture_manager.Pointer()->RemoveAllSurfaceTextures(process_handle);
|
| +}
|
| +
|
| +// static
|
| +void CompositorImpl::OnSurfaceTextureCreated(
|
| + int surface_texture_id,
|
| + base::ProcessHandle process_handle,
|
| + const CreateSurfaceTextureCallback& callback) {
|
| + // TODO(reveman): Get surface texture surface from GPU service.
|
| + NOTIMPLEMENTED();
|
| }
|
|
|
| CompositorImpl::CompositorImpl(CompositorClient* client,
|
|
|