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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_
6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_
9 #if defined(ENABLE_GPU)
14 #include "base/id_map.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
17 #include "gpu/command_buffer/common/constants.h"
18 #include "gpu/command_buffer/service/command_buffer_service.h"
19 #include "gpu/command_buffer/service/context_group.h"
20 #include "gpu/command_buffer/service/gpu_scheduler.h"
21 #include "ipc/ipc_channel.h"
22 #include "ipc/ipc_message.h"
23 #include "ui/gfx/gl/gl_context.h"
24 #include "ui/gfx/gl/gl_surface.h"
25 #include "ui/gfx/gl/gpu_preference.h"
26 #include "ui/gfx/native_widget_types.h"
27 #include "ui/gfx/size.h"
28 #include "ui/gfx/surface/transport_dib.h"
30 #if defined(OS_MACOSX)
31 #include "ui/gfx/surface/accelerated_surface_mac.h"
37 class GpuCommandBufferStub
38 : public IPC::Channel::Listener
,
39 public IPC::Message::Sender
,
40 public base::SupportsWeakPtr
<GpuCommandBufferStub
> {
44 GpuCommandBufferStub
* share_group
,
45 gfx::PluginWindowHandle handle
,
46 const gfx::Size
& size
,
47 const gpu::gles2::DisallowedFeatures
& disallowed_features
,
48 const std::string
& allowed_extensions
,
49 const std::vector
<int32
>& attribs
,
50 gfx::GpuPreference gpu_preference
,
54 GpuWatchdog
* watchdog
,
57 virtual ~GpuCommandBufferStub();
59 // IPC::Channel::Listener implementation:
60 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
62 // IPC::Message::Sender implementation:
63 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
65 // Whether this command buffer can currently handle IPC messages.
68 // Whether this command buffer needs to be polled again in the future.
71 // Set the swap interval according to the command line.
72 void SetSwapInterval();
74 gpu::gles2::GLES2Decoder
* decoder() const { return decoder_
.get(); }
75 gpu::GpuScheduler
* scheduler() const { return scheduler_
.get(); }
77 // Identifies the renderer process.
78 int32
renderer_id() const { return renderer_id_
; }
80 // Identifies a particular renderer belonging to the same renderer process.
81 int32
render_view_id() const { return render_view_id_
; }
83 // Identifies the various GpuCommandBufferStubs in the GPU process belonging
84 // to the same renderer process.
85 int32
route_id() const { return route_id_
; }
87 gfx::GpuPreference
gpu_preference() { return gpu_preference_
; }
89 // Sends a message to the console.
90 void SendConsoleMessage(int32 id
, const std::string
& message
);
95 // Cleans up and sends reply if OnInitialize failed.
96 void OnInitializeFailed(IPC::Message
* reply_message
);
99 void OnInitialize(IPC::Message
* reply_message
);
100 void OnSetGetBuffer(int32 shm_id
, IPC::Message
* reply_message
);
101 void OnSetParent(int32 parent_route_id
,
102 uint32 parent_texture_id
,
103 IPC::Message
* reply_message
);
104 void OnGetState(IPC::Message
* reply_message
);
105 void OnGetStateFast(IPC::Message
* reply_message
);
106 void OnAsyncFlush(int32 put_offset
, uint32 flush_count
);
107 void OnEcho(const IPC::Message
& message
);
108 void OnRescheduled();
109 void OnCreateTransferBuffer(int32 size
,
111 IPC::Message
* reply_message
);
112 void OnRegisterTransferBuffer(base::SharedMemoryHandle transfer_buffer
,
115 IPC::Message
* reply_message
);
116 void OnDestroyTransferBuffer(int32 id
, IPC::Message
* reply_message
);
117 void OnGetTransferBuffer(int32 id
, IPC::Message
* reply_message
);
119 void OnCreateVideoDecoder(
120 media::VideoDecodeAccelerator::Profile profile
,
121 IPC::Message
* reply_message
);
122 void OnDestroyVideoDecoder(int32 decoder_route_id
);
124 void OnSetSurfaceVisible(bool visible
);
126 void OnCommandProcessed();
131 // The lifetime of objects of this class is managed by a GpuChannel. The
132 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they
133 // are destroyed. So a raw pointer is safe.
134 GpuChannel
* channel_
;
136 // The group of contexts that share namespaces with this context.
137 scoped_refptr
<gpu::gles2::ContextGroup
> context_group_
;
139 gfx::PluginWindowHandle handle_
;
140 gfx::Size initial_size_
;
141 gpu::gles2::DisallowedFeatures disallowed_features_
;
142 std::string allowed_extensions_
;
143 std::vector
<int32
> requested_attribs_
;
144 gfx::GpuPreference gpu_preference_
;
147 uint32 last_flush_count_
;
149 // The following two fields are used on Mac OS X to identify the window
150 // for the rendering results on the browser side.
152 int32 render_view_id_
;
154 scoped_ptr
<gpu::CommandBufferService
> command_buffer_
;
155 scoped_ptr
<gpu::gles2::GLES2Decoder
> decoder_
;
156 scoped_ptr
<gpu::GpuScheduler
> scheduler_
;
157 scoped_refptr
<gfx::GLContext
> context_
;
158 scoped_refptr
<gfx::GLSurface
> surface_
;
160 // SetParent may be called before Initialize, in which case we need to keep
161 // around the parent stub, so that Initialize can set the parent correctly.
162 base::WeakPtr
<GpuCommandBufferStub
> parent_stub_for_initialization_
;
163 uint32 parent_texture_for_initialization_
;
165 GpuWatchdog
* watchdog_
;
167 // Zero or more video decoders owned by this stub, keyed by their
169 IDMap
<GpuVideoDecodeAccelerator
, IDMapOwnPointer
> video_decoders_
;
171 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub
);
174 #endif // defined(ENABLE_GPU)
176 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_