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 #ifndef CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ | 5 #ifndef CONTENT_COMMON_GPU_GPU_SURFACE_STUB_H_ |
6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ | 6 #define CONTENT_COMMON_GPU_GPU_SURFACE_STUB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #if defined(ENABLE_GPU) | 9 #if defined(ENABLE_GPU) |
10 | 10 |
11 #include <queue> | 11 #include "base/memory/scoped_ptr.h" |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
16 #include "base/process.h" | |
17 #include "base/task.h" | |
18 #include "gpu/command_buffer/service/command_buffer_service.h" | |
19 #include "gpu/command_buffer/service/gpu_scheduler.h" | |
20 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
21 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
22 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/gl/gl_surface.h" |
23 #include "ui/gfx/size.h" | |
24 | 16 |
25 class GpuChannel; | 17 class GpuChannel; |
26 class GpuWatchdog; | |
27 | 18 |
28 class GpuCommandBufferStub | 19 class GpuSurfaceStub |
29 : public IPC::Channel::Listener, | 20 : public IPC::Channel::Listener, |
30 public IPC::Message::Sender, | 21 public IPC::Message::Sender, |
31 public base::SupportsWeakPtr<GpuCommandBufferStub> { | 22 public base::SupportsWeakPtr<GpuSurfaceStub> { |
32 public: | 23 public: |
33 GpuCommandBufferStub( | 24 // Takes ownership of surface. |
34 GpuChannel* channel, | 25 GpuSurfaceStub(GpuChannel* channel, int route_id, gfx::GLSurface* surface); |
35 gfx::PluginWindowHandle handle, | 26 virtual ~GpuSurfaceStub(); |
36 GpuCommandBufferStub* parent, | |
37 const gfx::Size& size, | |
38 const gpu::gles2::DisallowedExtensions& disallowed_extensions, | |
39 const std::string& allowed_extensions, | |
40 const std::vector<int32>& attribs, | |
41 uint32 parent_texture_id, | |
42 int32 route_id, | |
43 int32 renderer_id, | |
44 int32 render_view_id, | |
45 GpuWatchdog* watchdog); | |
46 | |
47 virtual ~GpuCommandBufferStub(); | |
48 | 27 |
49 // IPC::Channel::Listener implementation: | 28 // IPC::Channel::Listener implementation: |
50 virtual bool OnMessageReceived(const IPC::Message& message); | 29 virtual bool OnMessageReceived(const IPC::Message& message); |
51 | 30 |
52 // IPC::Message::Sender implementation: | 31 // IPC::Message::Sender implementation: |
53 virtual bool Send(IPC::Message* msg); | 32 virtual bool Send(IPC::Message* msg); |
54 | 33 |
55 // Get the GLContext associated with this object. | 34 private: |
56 gpu::GpuScheduler* scheduler() const { return scheduler_.get(); } | 35 // Message handlers. |
| 36 // None yet. |
57 | 37 |
58 // Identifies the renderer process. | 38 // This is a weak pointer. The GpuChannel controls the lifetime of the |
59 int32 renderer_id() const { return renderer_id_; } | 39 // GpuSurfaceStub and always outlives it. |
60 | |
61 // Identifies a particular renderer belonging to the same renderer process. | |
62 int32 render_view_id() const { return render_view_id_; } | |
63 | |
64 // Identifies the various GpuCommandBufferStubs in the GPU process belonging | |
65 // to the same renderer process. | |
66 int32 route_id() const { return route_id_; } | |
67 | |
68 #if defined(OS_WIN) | |
69 // Called only by the compositor window's window proc | |
70 void OnCompositorWindowPainted(); | |
71 #endif // defined(OS_WIN) | |
72 | |
73 void ViewResized(); | |
74 | |
75 #if defined(OS_MACOSX) | |
76 // Called only by the GpuChannel. | |
77 void AcceleratedSurfaceBuffersSwapped(uint64 swap_buffers_count); | |
78 #endif // defined(OS_MACOSX) | |
79 | |
80 private: | |
81 // Message handlers: | |
82 void OnInitialize(base::SharedMemoryHandle ring_buffer, | |
83 int32 size, | |
84 IPC::Message* reply_message); | |
85 void OnGetState(IPC::Message* reply_message); | |
86 void OnFlush(int32 put_offset, | |
87 int32 last_known_get, | |
88 IPC::Message* reply_message); | |
89 void OnAsyncFlush(int32 put_offset); | |
90 void OnCreateTransferBuffer(int32 size, | |
91 int32 id_request, | |
92 IPC::Message* reply_message); | |
93 void OnRegisterTransferBuffer(base::SharedMemoryHandle transfer_buffer, | |
94 size_t size, | |
95 int32 id_request, | |
96 IPC::Message* reply_message); | |
97 void OnDestroyTransferBuffer(int32 id, IPC::Message* reply_message); | |
98 void OnGetTransferBuffer(int32 id, IPC::Message* reply_message); | |
99 void OnResizeOffscreenFrameBuffer(const gfx::Size& size); | |
100 | |
101 void OnSwapBuffers(); | |
102 void OnCommandProcessed(); | |
103 void HandleDeferredMessages(); | |
104 void OnScheduled(); | |
105 | |
106 #if defined(OS_MACOSX) | |
107 void OnSetWindowSize(const gfx::Size& size); | |
108 void SwapBuffersCallback(); | |
109 #endif // defined(OS_MACOSX) | |
110 | |
111 void ResizeCallback(gfx::Size size); | |
112 void ReportState(); | |
113 | |
114 // The lifetime of objects of this class is managed by a GpuChannel. The | |
115 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they | |
116 // are destroyed. So a raw pointer is safe. | |
117 GpuChannel* channel_; | 40 GpuChannel* channel_; |
118 | 41 |
119 gfx::PluginWindowHandle handle_; | 42 int route_id_; |
120 base::WeakPtr<GpuCommandBufferStub> parent_; | 43 scoped_ptr<gfx::GLSurface> surface_; |
121 gfx::Size initial_size_; | 44 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceStub); |
122 gpu::gles2::DisallowedExtensions disallowed_extensions_; | |
123 std::string allowed_extensions_; | |
124 std::vector<int32> requested_attribs_; | |
125 uint32 parent_texture_id_; | |
126 int32 route_id_; | |
127 | |
128 // The following two fields are used on Mac OS X to identify the window | |
129 // for the rendering results on the browser side. | |
130 int32 renderer_id_; | |
131 int32 render_view_id_; | |
132 | |
133 scoped_ptr<gpu::CommandBufferService> command_buffer_; | |
134 scoped_ptr<gpu::GpuScheduler> scheduler_; | |
135 std::queue<IPC::Message*> deferred_messages_; | |
136 | |
137 GpuWatchdog* watchdog_; | |
138 ScopedRunnableMethodFactory<GpuCommandBufferStub> task_factory_; | |
139 | |
140 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); | |
141 }; | 45 }; |
142 | 46 |
143 #endif // defined(ENABLE_GPU) | 47 #endif // defined(ENABLE_GPU) |
144 | 48 |
145 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ | 49 #endif // CONTENT_COMMON_GPU_GPU_SURFACE_STUB_H_ |
OLD | NEW |