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 "webkit/plugins/ppapi/ppb_context_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gpu/command_buffer/common/command_buffer.h" | 8 #include "gpu/command_buffer/common/command_buffer.h" |
| 9 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 10 #include "gpu/command_buffer/client/gles2_implementation.h" |
9 #include "webkit/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
11 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | 13 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
12 | 14 |
13 namespace webkit { | 15 namespace webkit { |
14 namespace ppapi { | 16 namespace ppapi { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // Size of the transfer buffer. | 20 // Size of the transfer buffer. |
19 enum { kTransferBufferSize = 512 * 1024 }; | 21 const int32 kCommandBufferSize = 1024 * 1024; |
| 22 const int32 kTransferBufferSize = 1024 * 1024; |
20 | 23 |
21 PP_Resource Create(PP_Instance instance_id, | 24 PP_Resource Create(PP_Instance instance_id, |
22 PP_Config3D_Dev config, | 25 PP_Config3D_Dev config, |
23 PP_Resource share_context, | 26 PP_Resource share_context, |
24 const int32_t* attrib_list) { | 27 const int32_t* attrib_list) { |
25 // TODO(alokp): Support shared context. | 28 // TODO(alokp): Support shared context. |
26 DCHECK_EQ(0, share_context); | 29 DCHECK_EQ(0, share_context); |
27 if (share_context != 0) | 30 if (share_context != 0) |
28 return 0; | 31 return 0; |
29 | 32 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 &GetAttrib, | 87 &GetAttrib, |
85 &BindSurfaces, | 88 &BindSurfaces, |
86 &GetBoundSurfaces, | 89 &GetBoundSurfaces, |
87 }; | 90 }; |
88 | 91 |
89 } // namespace | 92 } // namespace |
90 | 93 |
91 PPB_Context3D_Impl::PPB_Context3D_Impl(PluginInstance* instance) | 94 PPB_Context3D_Impl::PPB_Context3D_Impl(PluginInstance* instance) |
92 : Resource(instance), | 95 : Resource(instance), |
93 instance_(instance), | 96 instance_(instance), |
94 gles2_impl_(NULL), | 97 transfer_buffer_id_(0), |
95 draw_surface_(NULL), | 98 draw_surface_(NULL), |
96 read_surface_(NULL) { | 99 read_surface_(NULL) { |
97 } | 100 } |
98 | 101 |
99 PPB_Context3D_Impl::~PPB_Context3D_Impl() { | 102 PPB_Context3D_Impl::~PPB_Context3D_Impl() { |
100 Destroy(); | 103 Destroy(); |
101 } | 104 } |
102 | 105 |
103 const PPB_Context3D_Dev* PPB_Context3D_Impl::GetInterface() { | 106 const PPB_Context3D_Dev* PPB_Context3D_Impl::GetInterface() { |
104 return &ppb_context3d; | 107 return &ppb_context3d; |
(...skipping 10 matching lines...) Expand all Loading... |
115 platform_context_.reset(instance()->CreateContext3D()); | 118 platform_context_.reset(instance()->CreateContext3D()); |
116 if (!platform_context_.get()) { | 119 if (!platform_context_.get()) { |
117 Destroy(); | 120 Destroy(); |
118 return false; | 121 return false; |
119 } | 122 } |
120 if (!platform_context_->Init()) { | 123 if (!platform_context_->Init()) { |
121 Destroy(); | 124 Destroy(); |
122 return false; | 125 return false; |
123 } | 126 } |
124 | 127 |
125 gles2_impl_ = platform_context_->GetGLES2Implementation(); | 128 gpu::CommandBuffer* command_buffer = platform_context_->GetCommandBuffer(); |
126 DCHECK(gles2_impl_); | 129 DCHECK(command_buffer); |
| 130 |
| 131 if (!command_buffer->Initialize(kCommandBufferSize)) { |
| 132 Destroy(); |
| 133 return false; |
| 134 } |
| 135 |
| 136 // Create the GLES2 helper, which writes the command buffer protocol. |
| 137 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); |
| 138 if (!helper_->Initialize(kCommandBufferSize)) { |
| 139 Destroy(); |
| 140 return false; |
| 141 } |
| 142 |
| 143 // Create a transfer buffer used to copy resources between the renderer |
| 144 // process and the GPU process. |
| 145 transfer_buffer_id_ = |
| 146 command_buffer->CreateTransferBuffer(kTransferBufferSize); |
| 147 if (transfer_buffer_id_ < 0) { |
| 148 Destroy(); |
| 149 return false; |
| 150 } |
| 151 |
| 152 // Map the buffer into the renderer process's address space. |
| 153 gpu::Buffer transfer_buffer = |
| 154 command_buffer->GetTransferBuffer(transfer_buffer_id_); |
| 155 if (!transfer_buffer.ptr) { |
| 156 Destroy(); |
| 157 return false; |
| 158 } |
| 159 |
| 160 // Create the object exposing the OpenGL API. |
| 161 gles2_impl_.reset(new gpu::gles2::GLES2Implementation( |
| 162 helper_.get(), |
| 163 transfer_buffer.size, |
| 164 transfer_buffer.ptr, |
| 165 transfer_buffer_id_, |
| 166 false)); |
127 | 167 |
128 return true; | 168 return true; |
129 } | 169 } |
130 | 170 |
131 int32_t PPB_Context3D_Impl::BindSurfaces(PPB_Surface3D_Impl* draw, | 171 int32_t PPB_Context3D_Impl::BindSurfaces(PPB_Surface3D_Impl* draw, |
132 PPB_Surface3D_Impl* read) { | 172 PPB_Surface3D_Impl* read) { |
133 // TODO(alokp): Support separate draw-read surfaces. | 173 // TODO(alokp): Support separate draw-read surfaces. |
134 DCHECK_EQ(draw, read); | 174 DCHECK_EQ(draw, read); |
135 if (draw != read) | 175 if (draw != read) |
136 return PP_GRAPHICS3DERROR_BAD_MATCH; | 176 return PP_GRAPHICS3DERROR_BAD_MATCH; |
137 | 177 |
138 if (draw == draw_surface_) | 178 if (draw == draw_surface_) |
139 return PP_OK; | 179 return PP_OK; |
140 | 180 |
141 if (draw && draw->context()) | 181 if (draw && draw->context()) |
142 return PP_GRAPHICS3DERROR_BAD_ACCESS; | 182 return PP_GRAPHICS3DERROR_BAD_ACCESS; |
143 | 183 |
144 if (draw_surface_) | 184 if (draw_surface_) |
145 draw_surface_->BindToContext(NULL); | 185 draw_surface_->BindToContext(NULL); |
146 if (draw && !draw->BindToContext(platform_context_.get())) | 186 if (draw && !draw->BindToContext(this)) |
147 return PP_ERROR_NOMEMORY; | 187 return PP_ERROR_NOMEMORY; |
148 | 188 |
149 draw_surface_ = draw; | 189 draw_surface_ = draw; |
150 read_surface_ = read; | 190 read_surface_ = read; |
151 return PP_OK; | 191 return PP_OK; |
152 } | 192 } |
153 | 193 |
154 void PPB_Context3D_Impl::Destroy() { | 194 void PPB_Context3D_Impl::Destroy() { |
155 if (draw_surface_) | 195 if (draw_surface_) |
156 draw_surface_->BindToContext(NULL); | 196 draw_surface_->BindToContext(NULL); |
157 | 197 |
158 gles2_impl_ = NULL; | 198 gles2_impl_.reset(); |
| 199 |
| 200 if (platform_context_.get() && transfer_buffer_id_ != 0) { |
| 201 gpu::CommandBuffer* command_buffer = platform_context_->GetCommandBuffer(); |
| 202 command_buffer->DestroyTransferBuffer(transfer_buffer_id_); |
| 203 transfer_buffer_id_ = 0; |
| 204 } |
| 205 |
| 206 helper_.reset(); |
159 platform_context_.reset(); | 207 platform_context_.reset(); |
160 } | 208 } |
161 | 209 |
162 } // namespace ppapi | 210 } // namespace ppapi |
163 } // namespace webkit | 211 } // namespace webkit |
164 | 212 |
OLD | NEW |