OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/gpu/gpu_thread.h" | 5 #include "chrome/gpu/gpu_thread.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/gfx/gl/gl_context.h" | 10 #include "app/gfx/gl/gl_context.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/common/child_process.h" | 13 #include "chrome/common/child_process.h" |
14 #include "chrome/common/child_process_logging.h" | 14 #include "chrome/common/child_process_logging.h" |
15 #include "chrome/common/gpu_info.h" | 15 #include "chrome/common/gpu_info.h" |
16 #include "chrome/common/gpu_messages.h" | 16 #include "chrome/common/gpu_messages.h" |
17 #include "chrome/gpu/gpu_info_collector.h" | 17 #include "chrome/gpu/gpu_info_collector.h" |
18 #include "ipc/ipc_channel_handle.h" | 18 #include "ipc/ipc_channel_handle.h" |
19 | 19 |
20 #if defined(OS_WIN) | |
21 #include "chrome/gpu/gpu_view_win.h" | |
22 #elif defined(GPU_USE_GLX) | |
23 #include "chrome/gpu/gpu_backing_store_glx_context.h" | |
24 #include "chrome/gpu/gpu_view_x.h" | |
25 | |
26 #include <X11/Xutil.h> // Must be last. | |
27 #endif | |
28 | |
29 #if defined(OS_LINUX) | 20 #if defined(OS_LINUX) |
30 #include "app/x11_util.h" | 21 #include "app/x11_util.h" |
31 #include <gtk/gtk.h> | 22 #include <gtk/gtk.h> |
32 #endif | 23 #endif |
33 | 24 |
34 GpuThread::GpuThread() { | 25 GpuThread::GpuThread() { |
35 #if defined(GPU_USE_GLX) | |
36 display_ = ::XOpenDisplay(NULL); | |
37 #endif | |
38 #if defined(OS_LINUX) | 26 #if defined(OS_LINUX) |
39 { | 27 { |
40 // The X11 port of the command buffer code assumes it can access the X | 28 // The X11 port of the command buffer code assumes it can access the X |
41 // display via the macro GDK_DISPLAY(), which implies that Gtk has been | 29 // display via the macro GDK_DISPLAY(), which implies that Gtk has been |
42 // initialized. This code was taken from PluginThread. TODO(kbr): | 30 // initialized. This code was taken from PluginThread. TODO(kbr): |
43 // rethink whether initializing Gtk is really necessary or whether we | 31 // rethink whether initializing Gtk is really necessary or whether we |
44 // should just send the display connection down to the GPUProcessor. | 32 // should just send a raw display connection down to the GPUProcessor. |
45 g_thread_init(NULL); | 33 g_thread_init(NULL); |
46 const std::vector<std::string>& args = | 34 const std::vector<std::string>& args = |
47 CommandLine::ForCurrentProcess()->argv(); | 35 CommandLine::ForCurrentProcess()->argv(); |
48 int argc = args.size(); | 36 int argc = args.size(); |
49 scoped_array<char *> argv(new char *[argc + 1]); | 37 scoped_array<char *> argv(new char *[argc + 1]); |
50 for (size_t i = 0; i < args.size(); ++i) { | 38 for (size_t i = 0; i < args.size(); ++i) { |
51 // TODO(piman@google.com): can gtk_init modify argv? Just being safe | 39 // TODO(piman@google.com): can gtk_init modify argv? Just being safe |
52 // here. | 40 // here. |
53 argv[i] = strdup(args[i].c_str()); | 41 argv[i] = strdup(args[i].c_str()); |
54 } | 42 } |
55 argv[argc] = NULL; | 43 argv[argc] = NULL; |
56 char **argv_pointer = argv.get(); | 44 char **argv_pointer = argv.get(); |
57 | 45 |
58 gtk_init(&argc, &argv_pointer); | 46 gtk_init(&argc, &argv_pointer); |
59 for (size_t i = 0; i < args.size(); ++i) { | 47 for (size_t i = 0; i < args.size(); ++i) { |
60 free(argv[i]); | 48 free(argv[i]); |
61 } | 49 } |
62 x11_util::SetDefaultX11ErrorHandlers(); | 50 x11_util::SetDefaultX11ErrorHandlers(); |
63 } | 51 } |
64 #endif | 52 #endif |
65 } | 53 } |
66 | 54 |
67 GpuThread::~GpuThread() { | 55 GpuThread::~GpuThread() { |
68 } | 56 } |
69 | 57 |
70 #if defined(GPU_USE_GLX) | |
71 GpuBackingStoreGLXContext* GpuThread::GetGLXContext() { | |
72 if (!glx_context_.get()) | |
73 glx_context_.reset(new GpuBackingStoreGLXContext(this)); | |
74 return glx_context_.get(); | |
75 } | |
76 #endif | |
77 | |
78 void GpuThread::RemoveChannel(int renderer_id) { | 58 void GpuThread::RemoveChannel(int renderer_id) { |
79 gpu_channels_.erase(renderer_id); | 59 gpu_channels_.erase(renderer_id); |
80 } | 60 } |
81 | 61 |
82 void GpuThread::OnControlMessageReceived(const IPC::Message& msg) { | 62 void GpuThread::OnControlMessageReceived(const IPC::Message& msg) { |
83 bool msg_is_ok = true; | 63 bool msg_is_ok = true; |
84 IPC_BEGIN_MESSAGE_MAP_EX(GpuThread, msg, msg_is_ok) | 64 IPC_BEGIN_MESSAGE_MAP_EX(GpuThread, msg, msg_is_ok) |
85 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, | 65 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, |
86 OnEstablishChannel) | 66 OnEstablishChannel) |
87 IPC_MESSAGE_HANDLER(GpuMsg_Synchronize, | 67 IPC_MESSAGE_HANDLER(GpuMsg_Synchronize, |
88 OnSynchronize) | 68 OnSynchronize) |
89 IPC_MESSAGE_HANDLER(GpuMsg_NewRenderWidgetHostView, | |
90 OnNewRenderWidgetHostView) | |
91 IPC_MESSAGE_HANDLER(GpuMsg_CollectGraphicsInfo, | 69 IPC_MESSAGE_HANDLER(GpuMsg_CollectGraphicsInfo, |
92 OnCollectGraphicsInfo) | 70 OnCollectGraphicsInfo) |
93 IPC_MESSAGE_HANDLER(GpuMsg_Crash, | 71 IPC_MESSAGE_HANDLER(GpuMsg_Crash, |
94 OnCrash) | 72 OnCrash) |
95 IPC_MESSAGE_HANDLER(GpuMsg_Hang, | 73 IPC_MESSAGE_HANDLER(GpuMsg_Hang, |
96 OnHang) | 74 OnHang) |
97 IPC_END_MESSAGE_MAP_EX() | 75 IPC_END_MESSAGE_MAP_EX() |
98 } | 76 } |
99 | 77 |
100 void GpuThread::OnEstablishChannel(int renderer_id) { | 78 void GpuThread::OnEstablishChannel(int renderer_id) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 113 } |
136 } | 114 } |
137 | 115 |
138 Send(new GpuHostMsg_ChannelEstablished(channel_handle, gpu_info)); | 116 Send(new GpuHostMsg_ChannelEstablished(channel_handle, gpu_info)); |
139 } | 117 } |
140 | 118 |
141 void GpuThread::OnSynchronize() { | 119 void GpuThread::OnSynchronize() { |
142 Send(new GpuHostMsg_SynchronizeReply()); | 120 Send(new GpuHostMsg_SynchronizeReply()); |
143 } | 121 } |
144 | 122 |
145 void GpuThread::OnNewRenderWidgetHostView(GpuNativeWindowHandle parent_window, | |
146 int32 routing_id) { | |
147 // The GPUView class' lifetime is controlled by the host, which will send a | |
148 // message to destroy the GpuRWHView when necessary. So we don't manage the | |
149 // lifetime of this object. | |
150 #if defined(OS_WIN) | |
151 new GpuViewWin(this, parent_window, routing_id); | |
152 #elif defined(GPU_USE_GLX) | |
153 new GpuViewX(this, parent_window, routing_id); | |
154 #else | |
155 NOTIMPLEMENTED(); | |
156 #endif | |
157 } | |
158 | |
159 void GpuThread::OnCollectGraphicsInfo() { | 123 void GpuThread::OnCollectGraphicsInfo() { |
160 // Fail to establish a channel if some implementation of GL cannot be | 124 // Fail to establish a channel if some implementation of GL cannot be |
161 // initialized. | 125 // initialized. |
162 GPUInfo gpu_info; | 126 GPUInfo gpu_info; |
163 if (gfx::GLContext::InitializeOneOff()) { | 127 if (gfx::GLContext::InitializeOneOff()) { |
164 gpu_info_collector::CollectGraphicsInfo(&gpu_info); | 128 gpu_info_collector::CollectGraphicsInfo(&gpu_info); |
165 } | 129 } |
166 | 130 |
167 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info)); | 131 Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info)); |
168 } | 132 } |
169 | 133 |
170 void GpuThread::OnCrash() { | 134 void GpuThread::OnCrash() { |
171 // Good bye, cruel world. | 135 // Good bye, cruel world. |
172 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; | 136 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; |
173 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; | 137 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; |
174 } | 138 } |
175 | 139 |
176 void GpuThread::OnHang() { | 140 void GpuThread::OnHang() { |
177 for (;;) | 141 for (;;) |
178 PlatformThread::Sleep(1000); | 142 PlatformThread::Sleep(1000); |
179 } | 143 } |
OLD | NEW |