| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/lazy_instance.h" |
| 12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 13 #include "content/browser/gpu/gpu_data_manager.h" | 14 #include "content/browser/gpu/gpu_data_manager.h" |
| 14 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
| 15 #include "content/browser/renderer_host/render_process_host.h" | 16 #include "content/browser/renderer_host/render_process_host.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view.h" | 18 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 18 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
| 19 | 20 |
| 20 #if defined(TOOLKIT_USES_GTK) | 21 #if defined(TOOLKIT_USES_GTK) |
| 21 // These two #includes need to come after gpu_messages.h. | 22 // These two #includes need to come after gpu_messages.h. |
| 22 #include <gdk/gdkwindow.h> // NOLINT | 23 #include <gdk/gdkwindow.h> // NOLINT |
| 23 #include <gdk/gdkx.h> // NOLINT | 24 #include <gdk/gdkx.h> // NOLINT |
| 24 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 25 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
| 26 #endif | 27 #endif |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // One of the linux specific headers defines this as a macro. | 30 // One of the linux specific headers defines this as a macro. |
| 30 #ifdef DestroyAll | 31 #ifdef DestroyAll |
| 31 #undef DestroyAll | 32 #undef DestroyAll |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 IDMap<GpuProcessHostUIShim> g_hosts_by_id; | 35 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id( |
| 36 base::LINKER_INITIALIZED); |
| 35 | 37 |
| 36 class SendOnIOThreadTask : public Task { | 38 class SendOnIOThreadTask : public Task { |
| 37 public: | 39 public: |
| 38 SendOnIOThreadTask(int host_id, IPC::Message* msg) | 40 SendOnIOThreadTask(int host_id, IPC::Message* msg) |
| 39 : host_id_(host_id), | 41 : host_id_(host_id), |
| 40 msg_(msg) { | 42 msg_(msg) { |
| 41 } | 43 } |
| 42 | 44 |
| 43 private: | 45 private: |
| 44 void Run() { | 46 void Run() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 } | 66 } |
| 65 | 67 |
| 66 void RouteToGpuProcessHostUIShimTask::Run() { | 68 void RouteToGpuProcessHostUIShimTask::Run() { |
| 67 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_); | 69 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_); |
| 68 if (ui_shim) | 70 if (ui_shim) |
| 69 ui_shim->OnMessageReceived(msg_); | 71 ui_shim->OnMessageReceived(msg_); |
| 70 } | 72 } |
| 71 | 73 |
| 72 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) | 74 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) |
| 73 : host_id_(host_id) { | 75 : host_id_(host_id) { |
| 74 g_hosts_by_id.AddWithID(this, host_id_); | 76 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); |
| 75 } | 77 } |
| 76 | 78 |
| 77 // static | 79 // static |
| 78 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { | 80 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { |
| 79 DCHECK(!FromID(host_id)); | 81 DCHECK(!FromID(host_id)); |
| 80 return new GpuProcessHostUIShim(host_id); | 82 return new GpuProcessHostUIShim(host_id); |
| 81 } | 83 } |
| 82 | 84 |
| 83 // static | 85 // static |
| 84 void GpuProcessHostUIShim::Destroy(int host_id) { | 86 void GpuProcessHostUIShim::Destroy(int host_id) { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 86 delete FromID(host_id); | 88 delete FromID(host_id); |
| 87 } | 89 } |
| 88 | 90 |
| 89 // static | 91 // static |
| 90 void GpuProcessHostUIShim::DestroyAll() { | 92 void GpuProcessHostUIShim::DestroyAll() { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 92 while (!g_hosts_by_id.IsEmpty()) { | 94 while (!g_hosts_by_id.Pointer()->IsEmpty()) { |
| 93 IDMap<GpuProcessHostUIShim>::iterator it(&g_hosts_by_id); | 95 IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer()); |
| 94 delete it.GetCurrentValue(); | 96 delete it.GetCurrentValue(); |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 // static | 100 // static |
| 99 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { | 101 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 101 return g_hosts_by_id.Lookup(host_id); | 103 return g_hosts_by_id.Pointer()->Lookup(host_id); |
| 102 } | 104 } |
| 103 | 105 |
| 104 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { | 106 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { |
| 105 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 106 return BrowserThread::PostTask(BrowserThread::IO, | 108 return BrowserThread::PostTask(BrowserThread::IO, |
| 107 FROM_HERE, | 109 FROM_HERE, |
| 108 new SendOnIOThreadTask(host_id_, msg)); | 110 new SendOnIOThreadTask(host_id_, msg)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { | 113 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 if (!ui_shim) | 132 if (!ui_shim) |
| 131 return; | 133 return; |
| 132 | 134 |
| 133 ui_shim->Send(msg); | 135 ui_shim->Send(msg); |
| 134 } | 136 } |
| 135 | 137 |
| 136 #endif | 138 #endif |
| 137 | 139 |
| 138 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 140 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 139 DCHECK(CalledOnValidThread()); | 141 DCHECK(CalledOnValidThread()); |
| 140 g_hosts_by_id.Remove(host_id_); | 142 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 141 } | 143 } |
| 142 | 144 |
| 143 bool GpuProcessHostUIShim::OnControlMessageReceived( | 145 bool GpuProcessHostUIShim::OnControlMessageReceived( |
| 144 const IPC::Message& message) { | 146 const IPC::Message& message) { |
| 145 DCHECK(CalledOnValidThread()); | 147 DCHECK(CalledOnValidThread()); |
| 146 | 148 |
| 147 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 149 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
| 148 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, | 150 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, |
| 149 OnLogMessage) | 151 OnLogMessage) |
| 150 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) || defined(OS_WIN) | 152 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) || defined(OS_WIN) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 params.render_view_id); | 287 params.render_view_id); |
| 286 if (!host) | 288 if (!host) |
| 287 return; | 289 return; |
| 288 RenderWidgetHostView* view = host->view(); | 290 RenderWidgetHostView* view = host->view(); |
| 289 if (!view) | 291 if (!view) |
| 290 return; | 292 return; |
| 291 view->AcceleratedSurfaceRelease(params.identifier); | 293 view->AcceleratedSurfaceRelease(params.identifier); |
| 292 } | 294 } |
| 293 | 295 |
| 294 #endif | 296 #endif |
| OLD | NEW |