1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Multiply-included message file, hence no include guard here, but see below
6 // for a much smaller-than-usual include guard section.
11 #include "base/shared_memory.h"
12 #include "content/common/gpu/gpu_process_launch_causes.h"
13 #include "content/public/common/common_param_traits.h"
14 #include "content/public/common/gpu_info.h"
15 #include "gpu/command_buffer/common/command_buffer.h"
16 #include "gpu/command_buffer/common/constants.h"
17 #include "gpu/ipc/gpu_command_buffer_traits.h"
18 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_message_macros.h"
20 #include "media/video/video_decode_accelerator.h"
21 #include "ui/gfx/gl/gpu_preference.h"
22 #include "ui/gfx/native_widget_types.h"
23 #include "ui/gfx/size.h"
24 #include "ui/gfx/surface/transport_dib.h"
26 #define IPC_MESSAGE_START GpuMsgStart
28 IPC_STRUCT_BEGIN(GPUCreateCommandBufferConfig
)
29 IPC_STRUCT_MEMBER(int32
, share_group_id
)
30 IPC_STRUCT_MEMBER(std::string
, allowed_extensions
)
31 IPC_STRUCT_MEMBER(std::vector
<int>, attribs
)
32 IPC_STRUCT_MEMBER(GURL
, active_url
)
33 IPC_STRUCT_MEMBER(gfx::GpuPreference
, gpu_preference
)
36 IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceNew_Params
)
37 IPC_STRUCT_MEMBER(int32
, renderer_id
)
38 IPC_STRUCT_MEMBER(int32
, render_view_id
)
39 IPC_STRUCT_MEMBER(int32
, width
)
40 IPC_STRUCT_MEMBER(int32
, height
)
41 IPC_STRUCT_MEMBER(uint64
, surface_id
)
42 IPC_STRUCT_MEMBER(int32
, route_id
)
43 #if defined(OS_MACOSX)
44 IPC_STRUCT_MEMBER(gfx::PluginWindowHandle
, window
)
45 IPC_STRUCT_MEMBER(bool, create_transport_dib
)
49 IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
)
50 IPC_STRUCT_MEMBER(int32
, renderer_id
)
51 IPC_STRUCT_MEMBER(int32
, render_view_id
)
52 IPC_STRUCT_MEMBER(uint64
, surface_id
)
53 IPC_STRUCT_MEMBER(int32
, route_id
)
55 IPC_STRUCT_MEMBER(gfx::Size
, size
)
56 #elif defined(OS_MACOSX)
57 IPC_STRUCT_MEMBER(gfx::PluginWindowHandle
, window
)
61 IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
)
62 IPC_STRUCT_MEMBER(int32
, renderer_id
)
63 IPC_STRUCT_MEMBER(int32
, render_view_id
)
64 IPC_STRUCT_MEMBER(uint64
, surface_id
)
65 IPC_STRUCT_MEMBER(int32
, route_id
)
66 IPC_STRUCT_MEMBER(int, x
)
67 IPC_STRUCT_MEMBER(int, y
)
68 IPC_STRUCT_MEMBER(int, width
)
69 IPC_STRUCT_MEMBER(int, height
)
70 #if defined(OS_MACOSX)
71 IPC_STRUCT_MEMBER(gfx::PluginWindowHandle
, window
)
75 IPC_STRUCT_BEGIN(GpuHostMsg_AcceleratedSurfaceRelease_Params
)
76 IPC_STRUCT_MEMBER(int32
, renderer_id
)
77 IPC_STRUCT_MEMBER(int32
, render_view_id
)
78 IPC_STRUCT_MEMBER(uint64
, identifier
)
79 IPC_STRUCT_MEMBER(int32
, route_id
)
80 #if defined(OS_MACOSX)
81 IPC_STRUCT_MEMBER(gfx::PluginWindowHandle
, window
)
85 IPC_STRUCT_BEGIN(GPUCommandBufferConsoleMessage
)
86 IPC_STRUCT_MEMBER(int32
, id
)
87 IPC_STRUCT_MEMBER(std::string
, message
)
90 IPC_STRUCT_TRAITS_BEGIN(content::DxDiagNode
)
91 IPC_STRUCT_TRAITS_MEMBER(values
)
92 IPC_STRUCT_TRAITS_MEMBER(children
)
93 IPC_STRUCT_TRAITS_END()
95 IPC_STRUCT_TRAITS_BEGIN(content::GPUInfo
)
96 IPC_STRUCT_TRAITS_MEMBER(finalized
)
97 IPC_STRUCT_TRAITS_MEMBER(initialization_time
)
98 IPC_STRUCT_TRAITS_MEMBER(vendor_id
)
99 IPC_STRUCT_TRAITS_MEMBER(device_id
)
100 IPC_STRUCT_TRAITS_MEMBER(driver_vendor
)
101 IPC_STRUCT_TRAITS_MEMBER(driver_version
)
102 IPC_STRUCT_TRAITS_MEMBER(driver_date
)
103 IPC_STRUCT_TRAITS_MEMBER(pixel_shader_version
)
104 IPC_STRUCT_TRAITS_MEMBER(vertex_shader_version
)
105 IPC_STRUCT_TRAITS_MEMBER(gl_version
)
106 IPC_STRUCT_TRAITS_MEMBER(gl_version_string
)
107 IPC_STRUCT_TRAITS_MEMBER(gl_vendor
)
108 IPC_STRUCT_TRAITS_MEMBER(gl_renderer
)
109 IPC_STRUCT_TRAITS_MEMBER(gl_extensions
)
110 IPC_STRUCT_TRAITS_MEMBER(can_lose_context
)
112 IPC_STRUCT_TRAITS_MEMBER(dx_diagnostics
)
114 IPC_STRUCT_TRAITS_END()
116 IPC_ENUM_TRAITS(content::CauseForGpuLaunch
)
117 IPC_ENUM_TRAITS(gfx::GpuPreference
)
118 IPC_ENUM_TRAITS(gpu::error::ContextLostReason
)
120 IPC_ENUM_TRAITS(media::VideoDecodeAccelerator::Profile
)
122 //------------------------------------------------------------------------------
124 // These are messages from the browser to the GPU process.
126 // Tells the GPU process to initialize itself. The browser explicitly
127 // requests this be done so that we are guaranteed that the channel is set
128 // up between the browser and GPU process before doing any work that might
129 // potentially crash the GPU process. Detection of the child process
130 // exiting abruptly is predicated on having the IPC channel set up.
131 IPC_MESSAGE_CONTROL0(GpuMsg_Initialize
)
133 // Tells the GPU process to create a new channel for communication with a
134 // given renderer. The channel name is returned in a
135 // GpuHostMsg_ChannelEstablished message. The renderer ID is passed so that
136 // the GPU process reuses an existing channel to that process if it exists.
137 // This ID is a unique opaque identifier generated by the browser process.
138 IPC_MESSAGE_CONTROL1(GpuMsg_EstablishChannel
,
139 int /* renderer_id */)
141 // Tells the GPU process to close the channel identified by IPC channel
142 // handle. If no channel can be identified, do nothing.
143 IPC_MESSAGE_CONTROL1(GpuMsg_CloseChannel
,
144 IPC::ChannelHandle
/* channel_handle */)
146 IPC_MESSAGE_CONTROL3(GpuMsg_VisibilityChanged
,
147 int32
, /*render_view_id */
148 int32
, /* renderer_id */
149 bool /* is_visible */)
151 // Tells the GPU process to create a new command buffer that renders directly
152 // to a native view. A corresponding GpuCommandBufferStub is created.
153 IPC_MESSAGE_CONTROL4(GpuMsg_CreateViewCommandBuffer
,
154 gfx::PluginWindowHandle
, /* compositing_surface */
155 int32
, /* render_view_id */
156 int32
, /* renderer_id */
157 GPUCreateCommandBufferConfig
/* init_params */)
159 // Tells the GPU process to create a context for collecting graphics card
161 IPC_MESSAGE_CONTROL0(GpuMsg_CollectGraphicsInfo
)
163 // Tells the GPU process that the browser process has finished resizing the
165 IPC_MESSAGE_ROUTED0(AcceleratedSurfaceMsg_ResizeViewACK
)
167 // Tells the GPU process that it's safe to start rendering to the surface.
168 IPC_MESSAGE_ROUTED2(AcceleratedSurfaceMsg_NewACK
,
169 uint64
/* surface_id */,
170 TransportDIB::Handle
/* shared memory buffer */)
172 // Tells the GPU process that the browser process handled the swap
174 IPC_MESSAGE_ROUTED0(AcceleratedSurfaceMsg_BuffersSwappedACK
)
176 // Tells the GPU process that the browser process handled the
177 // PostSubBuffer command.
178 IPC_MESSAGE_ROUTED0(AcceleratedSurfaceMsg_PostSubBufferACK
)
180 // Tells the GPU process to remove all contexts.
181 IPC_MESSAGE_CONTROL0(GpuMsg_Clean
)
183 // Tells the GPU process to crash.
184 IPC_MESSAGE_CONTROL0(GpuMsg_Crash
)
186 // Tells the GPU process to hang.
187 IPC_MESSAGE_CONTROL0(GpuMsg_Hang
)
189 //------------------------------------------------------------------------------
191 // These are messages to the browser.
193 // A renderer sends this when it wants to create a connection to the GPU
194 // process. The browser will create the GPU process if necessary, and will
195 // return a handle to the channel via a GpuChannelEstablished message.
196 IPC_SYNC_MESSAGE_CONTROL1_3(GpuHostMsg_EstablishGpuChannel
,
197 content::CauseForGpuLaunch
,
198 IPC::ChannelHandle
/* handle to channel */,
199 base::ProcessHandle
/* renderer_process_for_gpu */,
200 content::GPUInfo
/* stats about GPU process*/)
202 // A renderer sends this to the browser process when it wants to
203 // create a GL context associated with the given view_id.
204 IPC_SYNC_MESSAGE_CONTROL2_1(GpuHostMsg_CreateViewCommandBuffer
,
205 int32
, /* render_view_id */
206 GPUCreateCommandBufferConfig
, /* init_params */
207 int32
/* route_id */)
209 // Response from GPU to a GpuHostMsg_EstablishChannel message.
210 IPC_MESSAGE_CONTROL1(GpuHostMsg_ChannelEstablished
,
211 IPC::ChannelHandle
/* channel_handle */)
213 // Respond from GPU to a GpuMsg_CreateViewCommandBuffer message.
214 IPC_MESSAGE_CONTROL1(GpuHostMsg_CommandBufferCreated
,
215 int32
/* route_id */)
217 // Request from GPU to free the browser resources associated with the
219 IPC_MESSAGE_CONTROL3(GpuHostMsg_DestroyCommandBuffer
,
220 gfx::PluginWindowHandle
, /* view */
221 int32
, /* render_view_id */
222 int32
/* renderer_id */)
224 // Response from GPU to a GpuMsg_CollectGraphicsInfo.
225 IPC_MESSAGE_CONTROL1(GpuHostMsg_GraphicsInfoCollected
,
226 content::GPUInfo
/* GPU logging stats */)
228 // Message from GPU to add a GPU log message to the about:gpu page.
229 IPC_MESSAGE_CONTROL3(GpuHostMsg_OnLogMessage
,
231 std::string
/* header */,
232 std::string
/* message */)
234 // Resize the window that is being drawn into. It's important that this
235 // resize be synchronized with the swapping of the front and back buffers.
236 IPC_MESSAGE_CONTROL4(GpuHostMsg_ResizeView
,
237 int32
/* renderer_id */,
238 int32
/* render_view_id */,
239 int32
/* route_id */,
240 gfx::Size
/* size */)
242 // This message is sent from the GPU process to the browser to notify about a
243 // new or resized surface in the GPU. The browser allocates any resources
244 // needed for it on its end and replies with an ACK containing any shared
245 // resources/identifiers to be used in the GPU.
246 IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceNew
,
247 GpuHostMsg_AcceleratedSurfaceNew_Params
)
249 // Same as above with a rect of the part of the surface that changed.
250 IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceBuffersSwapped
,
251 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params
)
253 // This message notifies the browser process that the renderer
254 // swapped a portion of the buffers associated with the given "window", which
255 // should cause the browser to redraw the compositor's contents.
256 IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfacePostSubBuffer
,
257 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params
)
259 // Tells the browser to release whatever resources are associated with
260 // the given surface. The browser must send an ACK once this operation
262 IPC_MESSAGE_CONTROL1(GpuHostMsg_AcceleratedSurfaceRelease
,
263 GpuHostMsg_AcceleratedSurfaceRelease_Params
)
265 //------------------------------------------------------------------------------
266 // GPU Channel Messages
267 // These are messages from a renderer process to the GPU process.
269 // Initialize a channel between a renderer process and a GPU process. The
270 // renderer passes its process handle to the GPU process, which gives gives the
271 // GPU process the ability to map handles from the renderer process. This must
272 // be the first message sent on a newly connected channel.
273 IPC_MESSAGE_CONTROL1(GpuChannelMsg_Initialize
,
274 base::ProcessHandle
/* renderer_process_for_gpu */)
276 // Tells the GPU process to create a new command buffer that renders to an
277 // offscreen frame buffer.
278 IPC_SYNC_MESSAGE_CONTROL2_1(GpuChannelMsg_CreateOffscreenCommandBuffer
,
279 gfx::Size
, /* size */
280 GPUCreateCommandBufferConfig
, /* init_params */
281 int32
/* route_id */)
283 // The CommandBufferProxy sends this to the GpuCommandBufferStub in its
284 // destructor, so that the stub deletes the actual CommandBufferService
285 // object that it's hosting.
286 IPC_SYNC_MESSAGE_CONTROL1_0(GpuChannelMsg_DestroyCommandBuffer
,
287 int32
/* instance_id */)
289 // Request that the GPU process reply with the given message.
290 IPC_MESSAGE_CONTROL1(GpuChannelMsg_Echo
,
291 IPC::Message
/* reply */)
293 // Asks the GPU process whether the creation or destruction of a
294 // command buffer on the given GPU (integrated or discrete) will cause
295 // the system to switch which GPU it is using. All contexts that share
296 // resources need to be created on the same GPU.
297 IPC_SYNC_MESSAGE_CONTROL2_1(GpuChannelMsg_WillGpuSwitchOccur
,
298 bool /* is_creating_context */,
299 gfx::GpuPreference
/* preference */,
300 bool /* will_cause_switch */)
302 // Forcibly closes the channel on the GPU process side, in order to
303 // have the side effect that all contexts associated with this
304 // renderer go into the lost state.
305 IPC_MESSAGE_CONTROL0(GpuChannelMsg_CloseChannel
)
307 //------------------------------------------------------------------------------
308 // GPU Command Buffer Messages
309 // These are messages between a renderer process to the GPU process relating to
310 // a single OpenGL context.
311 // Initialize a command buffer with the given number of command entries.
312 // Returns the shared memory handle for the command buffer mapped to the
314 IPC_SYNC_MESSAGE_ROUTED0_1(GpuCommandBufferMsg_Initialize
,
317 // Sets the shared memory buffer used for commands.
318 IPC_SYNC_MESSAGE_ROUTED1_0(GpuCommandBufferMsg_SetGetBuffer
,
321 // Sets the parent command buffer. This allows the parent and child to share
323 IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_SetParent
,
324 int32
/* parent_route_id */,
325 uint32
/* parent_texture_id */,
328 // Get the current state of the command buffer.
329 IPC_SYNC_MESSAGE_ROUTED0_1(GpuCommandBufferMsg_GetState
,
330 gpu::CommandBuffer::State
/* state */)
332 // Get the current state of the command buffer, as fast as possible.
333 IPC_SYNC_MESSAGE_ROUTED0_1(GpuCommandBufferMsg_GetStateFast
,
334 gpu::CommandBuffer::State
/* state */)
336 // Asynchronously synchronize the put and get offsets of both processes.
337 // Caller passes its current put offset. Current state (including get offset)
338 // is returned via an UpdateState message.
339 IPC_MESSAGE_ROUTED2(GpuCommandBufferMsg_AsyncFlush
,
340 int32
/* put_offset */,
341 uint32
/* flush_count */)
343 // Asynchronously process any commands known to the GPU process. This is only
344 // used in the event that a channel is unscheduled and needs to be flushed
345 // again to process any commands issued subsequent to unscheduling. The GPU
346 // process actually sends it (deferred) to itself.
347 IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_Rescheduled
)
349 // Return the current state of the command buffer following a request via
350 // an AsyncGetState or AsyncFlush message. (This message is sent from the
351 // GPU process to the renderer process.)
352 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_UpdateState
,
353 gpu::CommandBuffer::State
/* state */)
355 // Sent by the GPU process to display messages in the console.
356 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_ConsoleMsg
,
357 GPUCommandBufferConsoleMessage
/* msg */)
359 // Create a shared memory transfer buffer. Returns an id that can be used to
360 // identify the transfer buffer from a comment.
361 IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_CreateTransferBuffer
,
363 int32
/* id_request (-1 means any) */,
366 // Register an existing shared memory transfer buffer. Returns an id that can be
367 // used to identify the transfer buffer from a command buffer.
368 IPC_SYNC_MESSAGE_ROUTED3_1(GpuCommandBufferMsg_RegisterTransferBuffer
,
369 base::SharedMemoryHandle
/* transfer_buffer */,
371 int32
/* id_request (-1 means any) */,
374 // Destroy a previously created transfer buffer.
375 IPC_SYNC_MESSAGE_ROUTED1_0(GpuCommandBufferMsg_DestroyTransferBuffer
,
378 // Get the shared memory handle for a transfer buffer mapped to the callers
380 IPC_SYNC_MESSAGE_ROUTED1_2(GpuCommandBufferMsg_GetTransferBuffer
,
382 base::SharedMemoryHandle
/* transfer_buffer */,
385 // Create and initialize a hardware video decoder, returning its new route_id.
386 IPC_SYNC_MESSAGE_ROUTED1_1(GpuCommandBufferMsg_CreateVideoDecoder
,
387 media::VideoDecodeAccelerator::Profile
/* profile */,
390 // Release all resources held by the named hardware video decoder.
391 IPC_SYNC_MESSAGE_ROUTED1_0(GpuCommandBufferMsg_DestroyVideoDecoder
,
394 // Send from command buffer stub to proxy when window is invalid and must be
396 IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_NotifyRepaint
)
398 // Tells the GPU process to resize an offscreen frame buffer.
399 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_ResizeOffscreenFrameBuffer
,
400 gfx::Size
/* size */)
402 #if defined(OS_MACOSX)
403 // On Mac OS X the GPU plugin must be offscreen, because there is no
404 // true cross-process window hierarchy. For this reason we must send
405 // resize events explicitly to the command buffer stub so it can
406 // reallocate its backing store and send the new one back to the
407 // browser. This message is currently used only on 10.6 and later.
408 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetWindowSize
,
409 gfx::Size
/* size */)
412 // Tells the proxy that there was an error and the command buffer had to be
413 // destroyed for some reason.
414 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_Destroyed
,
415 gpu::error::ContextLostReason
/* reason */)
417 // Response to a GpuChannelMsg_Echo message.
418 IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_EchoAck
)
420 IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetSurfaceVisible
, bool /* visible */)
422 //------------------------------------------------------------------------------
423 // Accelerated Video Decoder Messages
424 // These messages are sent from Renderer process to GPU process.
426 // Send input buffer for decoding.
427 IPC_MESSAGE_ROUTED3(AcceleratedVideoDecoderMsg_Decode
,
428 base::SharedMemoryHandle
, /* input_buffer_handle */
429 int32
, /* bitstream_buffer_id */
432 // Sent from Renderer process to the GPU process to give the texture IDs for
433 // the textures the decoder will use for output.
434 IPC_MESSAGE_ROUTED3(AcceleratedVideoDecoderMsg_AssignPictureBuffers
,
435 std::vector
<int32
>, /* Picture buffer ID */
436 std::vector
<uint32
>, /* Texture ID */
437 std::vector
<gfx::Size
>) /* Size */
439 // Send from Renderer process to the GPU process to recycle the given picture
440 // buffer for further decoding.
441 IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderMsg_ReusePictureBuffer
,
442 int32
) /* Picture buffer ID */
444 // Send flush request to the decoder.
445 IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderMsg_Flush
)
447 // Send reset request to the decoder.
448 IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderMsg_Reset
)
450 // Send destroy request to the decoder.
451 IPC_SYNC_MESSAGE_ROUTED0_0(AcceleratedVideoDecoderMsg_Destroy
)
453 //------------------------------------------------------------------------------
454 // Accelerated Video Decoder Host Messages
455 // These messages are sent from GPU process to Renderer process.
456 // Inform AcceleratedVideoDecoderHost that AcceleratedVideoDecoder has been
459 // Accelerated video decoder has consumed input buffer from transfer buffer.
460 IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed
,
461 int32
) /* Processed buffer ID */
463 // Allocate video frames for output of the hardware video decoder.
464 IPC_MESSAGE_ROUTED2(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers
,
465 int32
, /* Number of video frames to generate */
466 gfx::Size
) /* Requested size of buffer */
468 // Decoder reports that a picture is ready and buffer does not need to be passed
469 // back to the decoder.
470 IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer
,
471 int32
) /* Picture buffer ID */
473 // Decoder reports that a picture is ready.
474 IPC_MESSAGE_ROUTED2(AcceleratedVideoDecoderHostMsg_PictureReady
,
475 int32
, /* Picture buffer ID */
476 int32
) /* Bitstream buffer ID */
478 // Confirm decoder has been flushed.
479 IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderHostMsg_FlushDone
)
481 // Confirm decoder has been reset.
482 IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderHostMsg_ResetDone
)
484 // Decoder has faced end of stream marker in the stream.
485 IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderHostMsg_EndOfStream
)
487 // Video decoder has encountered an error.
488 IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderHostMsg_ErrorNotification
,
489 uint32
) /* Error ID */