Index: chrome/browser/gpu_process_host_ui_shim.cc |
diff --git a/chrome/browser/gpu_process_host_ui_shim.cc b/chrome/browser/gpu_process_host_ui_shim.cc |
index 73be07dda11448eb114a4a17a2017fe38de71f14..b70b3a4956fb6d79e7b5c29a3ab9020101eea45e 100644 |
--- a/chrome/browser/gpu_process_host_ui_shim.cc |
+++ b/chrome/browser/gpu_process_host_ui_shim.cc |
@@ -112,52 +112,31 @@ void RouteToGpuProcessHostUIShimTask::Run() { |
ui_shim->OnMessageReceived(msg_); |
} |
-class GpuProcessHostUIShim::ViewSurface { |
+#if defined(OS_LINUX) |
+// Used to put a lock on surfaces so that the window to which the GPU |
+// process is drawing to doesn't disappear while it is drawing when |
+// a tab is closed. |
+class GpuProcessHostUIShim::SurfaceLock { |
jam
2011/04/14 22:42:00
nit: lock implies that locking is taking place, wh
jonathan.backer
2011/04/15 19:02:51
Done.
|
public: |
- explicit ViewSurface(ViewID view_id); |
- ~ViewSurface(); |
- gfx::PluginWindowHandle surface() { return surface_; } |
+ explicit SurfaceLock(gfx::PluginWindowHandle surface); |
+ ~SurfaceLock(); |
private: |
- RenderWidgetHostView* GetRenderWidgetHostView(); |
- ViewID view_id_; |
gfx::PluginWindowHandle surface_; |
}; |
-GpuProcessHostUIShim::ViewSurface::ViewSurface(ViewID view_id) |
- : view_id_(view_id), surface_(gfx::kNullPluginWindow) { |
- RenderWidgetHostView* view = GetRenderWidgetHostView(); |
- if (view) |
- surface_ = view->AcquireCompositingSurface(); |
+GpuProcessHostUIShim::SurfaceLock::SurfaceLock(gfx::PluginWindowHandle surface) |
+ : surface_(surface) { |
+ GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
+ DCHECK(manager->AddRefPermanentXID(surface_)); |
jam
2011/04/14 22:42:00
DCHECK is compiled away in release builds, so you'
jonathan.backer
2011/04/15 19:02:51
Good catch! Done.
|
} |
-GpuProcessHostUIShim::ViewSurface::~ViewSurface() { |
- if (!surface_) |
- return; |
- |
- RenderWidgetHostView* view = GetRenderWidgetHostView(); |
- if (view) |
- view->ReleaseCompositingSurface(surface_); |
-} |
- |
-// We do separate lookups for the RenderWidgetHostView when acquiring |
-// and releasing surfaces (rather than caching) because the |
-// RenderWidgetHostView could die without warning. In such a case, |
-// it's the RenderWidgetHostView's responsibility to cleanup. |
-RenderWidgetHostView* GpuProcessHostUIShim::ViewSurface:: |
- GetRenderWidgetHostView() { |
- RenderProcessHost* process = RenderProcessHost::FromID(view_id_.first); |
- RenderWidgetHost* host = NULL; |
- if (process) { |
- host = static_cast<RenderWidgetHost*>( |
- process->GetListenerByID(view_id_.second)); |
- } |
- |
- RenderWidgetHostView* view = NULL; |
- if (host) |
- view = host->view(); |
- |
- return view; |
+GpuProcessHostUIShim::SurfaceLock::~SurfaceLock() { |
+ // TODO(backer): ReleasePermanentXID has to be done on the UI thread. |
+ // Post task to release once we move this code to the IO thread. |
+ GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); |
+ manager->ReleasePermanentXID(surface_); |
} |
+#endif // defined(OS_LINUX) |
GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id, |
content::CauseForGpuLaunch cause_for_gpu_launch) |
@@ -415,31 +394,39 @@ void GpuProcessHostUIShim::Synchronize(SynchronizeCallback* callback) { |
} |
void GpuProcessHostUIShim::CreateViewCommandBuffer( |
+ gfx::PluginWindowHandle compositing_surface, |
int32 render_view_id, |
int32 renderer_id, |
const GPUCreateCommandBufferConfig& init_params, |
CreateCommandBufferCallback* callback) { |
+ // FIXME(backer): We're gonna have to fix the ref counting on the |
+ // compositing_surface being passed in (at least for Linux). |
DCHECK(CalledOnValidThread()); |
linked_ptr<CreateCommandBufferCallback> wrapped_callback(callback); |
+ |
+#if defined(OS_LINUX) |
ViewID view_id(renderer_id, render_view_id); |
// There should only be one such command buffer (for the compositor). In |
// practice, if the GPU process lost a context, GraphicsContext3D with |
// associated command buffer and view surface will not be gone until new |
// one is in place and all layers are reattached. |
- linked_ptr<ViewSurface> view_surface; |
- ViewSurfaceMap::iterator it = acquired_surfaces_.find(view_id); |
- if (it != acquired_surfaces_.end()) |
- view_surface = (*it).second; |
+ linked_ptr<SurfaceLock> surface_lock; |
+ SurfaceLockMap::iterator it = surface_locks_.find(view_id); |
+ if (it != surface_locks_.end()) |
+ surface_lock = (*it).second; |
else |
- view_surface.reset(new ViewSurface(view_id)); |
+ surface_lock.reset(new SurfaceLock(compositing_surface)); |
+#endif // defined(OS_LINUX) |
- if (view_surface->surface() != gfx::kNullPluginWindow && |
+ if (compositing_surface != gfx::kNullPluginWindow && |
Send(new GpuMsg_CreateViewCommandBuffer( |
- view_surface->surface(), render_view_id, renderer_id, init_params))) { |
+ compositing_surface, render_view_id, renderer_id, init_params))) { |
create_command_buffer_requests_.push(wrapped_callback); |
- acquired_surfaces_.insert(std::pair<ViewID, linked_ptr<ViewSurface> >( |
- view_id, view_surface)); |
+#if defined(OS_LINUX) |
+ surface_locks_.insert(std::pair<ViewID, linked_ptr<SurfaceLock> >( |
+ view_id, surface_lock)); |
+#endif // defined(OS_LINUX) |
} else { |
CreateCommandBufferError(wrapped_callback.release(), MSG_ROUTING_NONE); |
} |
@@ -591,10 +578,12 @@ void GpuProcessHostUIShim::OnCommandBufferCreated(const int32 route_id) { |
void GpuProcessHostUIShim::OnDestroyCommandBuffer( |
gfx::PluginWindowHandle window, int32 renderer_id, |
int32 render_view_id) { |
+#if defined(OS_LINUX) |
ViewID view_id(renderer_id, render_view_id); |
- ViewSurfaceMap::iterator it = acquired_surfaces_.find(view_id); |
- if (it != acquired_surfaces_.end()) |
- acquired_surfaces_.erase(it); |
+ SurfaceLockMap::iterator it = surface_locks_.find(view_id); |
+ if (it != surface_locks_.end()) |
+ surface_locks_.erase(it); |
+#endif // defined(OS_LINUX) |
} |
void GpuProcessHostUIShim::OnGraphicsInfoCollected(const GPUInfo& gpu_info) { |