| 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 #include "ppapi/proxy/ppb_surface_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_surface_3d_proxy.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/c/dev/ppb_surface_3d_dev.h" | 10 #include "ppapi/c/dev/ppb_surface_3d_dev.h" |
| 11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 12 #include "ppapi/proxy/plugin_resource.h" | 12 #include "ppapi/proxy/plugin_resource.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 14 #include "ppapi/proxy/ppb_context_3d_proxy.h" | 14 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
| 15 #include "ppapi/thunk/common.h" |
| 15 | 16 |
| 16 namespace pp { | 17 namespace pp { |
| 17 namespace proxy { | 18 namespace proxy { |
| 18 | 19 |
| 19 Surface3D::~Surface3D() { | 20 Surface3D::~Surface3D() { |
| 20 if (context_) | 21 if (context_) |
| 21 context_->BindSurfaces(NULL, NULL); | 22 context_->BindSurfaces(NULL, NULL); |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int32_t attribute, | 70 int32_t attribute, |
| 70 int32_t* value) { | 71 int32_t* value) { |
| 71 // TODO(alokp): Implement me. | 72 // TODO(alokp): Implement me. |
| 72 return 0; | 73 return 0; |
| 73 } | 74 } |
| 74 | 75 |
| 75 int32_t SwapBuffers(PP_Resource surface_id, | 76 int32_t SwapBuffers(PP_Resource surface_id, |
| 76 PP_CompletionCallback callback) { | 77 PP_CompletionCallback callback) { |
| 77 Surface3D* object = PluginResource::GetAs<Surface3D>(surface_id); | 78 Surface3D* object = PluginResource::GetAs<Surface3D>(surface_id); |
| 78 if (!object) | 79 if (!object) |
| 79 return PP_ERROR_BADRESOURCE; | 80 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 80 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 81 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 81 object->instance()); | 82 object->instance()); |
| 82 if (!dispatcher) | 83 if (!dispatcher) |
| 83 return PP_ERROR_FAILED; | 84 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_FAILED); |
| 84 | 85 |
| 85 // For now, disallow blocking calls. We'll need to add support for other | 86 // For now, disallow blocking calls. We'll need to add support for other |
| 86 // threads to this later. | 87 // threads to this later. |
| 87 if (!callback.func) | 88 if (!callback.func) |
| 88 return PP_ERROR_BADARGUMENT; | 89 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADARGUMENT); |
| 89 | 90 |
| 90 if (object->is_flush_pending()) | 91 if (object->is_flush_pending()) { |
| 91 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. | 92 // Can't have >1 flush pending. |
| 93 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_INPROGRESS); |
| 94 } |
| 92 | 95 |
| 93 if (!object->context()) | 96 if (!object->context()) |
| 94 return PP_ERROR_FAILED; | 97 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_FAILED); |
| 95 | 98 |
| 96 object->set_current_flush_callback(callback); | 99 object->set_current_flush_callback(callback); |
| 97 | 100 |
| 98 IPC::Message* msg = new PpapiHostMsg_PPBSurface3D_SwapBuffers( | 101 IPC::Message* msg = new PpapiHostMsg_PPBSurface3D_SwapBuffers( |
| 99 INTERFACE_ID_PPB_SURFACE_3D, object->host_resource()); | 102 INTERFACE_ID_PPB_SURFACE_3D, object->host_resource()); |
| 100 msg->set_unblock(true); | 103 msg->set_unblock(true); |
| 101 dispatcher->Send(msg); | 104 dispatcher->Send(msg); |
| 102 | 105 |
| 103 object->context()->gles2_impl()->SwapBuffers(); | 106 object->context()->gles2_impl()->SwapBuffers(); |
| 104 | 107 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 std::vector<int32_t> attribs, | 165 std::vector<int32_t> attribs, |
| 163 HostResource* result) { | 166 HostResource* result) { |
| 164 DCHECK(attribs.size() % 2 == 1); | 167 DCHECK(attribs.size() % 2 == 1); |
| 165 DCHECK(attribs.back() == PP_GRAPHICS3DATTRIB_NONE); | 168 DCHECK(attribs.back() == PP_GRAPHICS3DATTRIB_NONE); |
| 166 PP_Resource resource = | 169 PP_Resource resource = |
| 167 ppb_surface_3d_target()->Create(instance, config, &attribs.front()); | 170 ppb_surface_3d_target()->Create(instance, config, &attribs.front()); |
| 168 result->SetHostResource(instance, resource); | 171 result->SetHostResource(instance, resource); |
| 169 } | 172 } |
| 170 | 173 |
| 171 void PPB_Surface3D_Proxy::OnMsgSwapBuffers(const HostResource& surface_3d) { | 174 void PPB_Surface3D_Proxy::OnMsgSwapBuffers(const HostResource& surface_3d) { |
| 172 CompletionCallback callback = callback_factory_.NewCallback( | 175 CompletionCallback callback = callback_factory_.NewOptionalCallback( |
| 173 &PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin, surface_3d); | 176 &PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin, surface_3d); |
| 174 int32_t result = ppb_surface_3d_target()->SwapBuffers( | 177 int32_t result = ppb_surface_3d_target()->SwapBuffers( |
| 175 surface_3d.host_resource(), callback.pp_completion_callback()); | 178 surface_3d.host_resource(), callback.pp_completion_callback()); |
| 176 if (result != PP_OK_COMPLETIONPENDING) { | 179 if (result != PP_OK_COMPLETIONPENDING) { |
| 177 // There was some error, so we won't get a flush callback. We need to now | 180 // There was some error, so we won't get a flush callback. We need to now |
| 178 // issue the ACK to the plugin hears about the error. This will also clean | 181 // issue the ACK to the plugin hears about the error. This will also clean |
| 179 // up the data associated with the callback. | 182 // up the data associated with the callback. |
| 180 callback.Run(result); | 183 callback.Run(result); |
| 181 } | 184 } |
| 182 } | 185 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 204 | 207 |
| 205 void PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin( | 208 void PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin( |
| 206 int32_t result, | 209 int32_t result, |
| 207 const HostResource& surface_3d) { | 210 const HostResource& surface_3d) { |
| 208 dispatcher()->Send(new PpapiMsg_PPBSurface3D_SwapBuffersACK( | 211 dispatcher()->Send(new PpapiMsg_PPBSurface3D_SwapBuffersACK( |
| 209 INTERFACE_ID_PPB_SURFACE_3D, surface_3d, result)); | 212 INTERFACE_ID_PPB_SURFACE_3D, surface_3d, result)); |
| 210 } | 213 } |
| 211 | 214 |
| 212 } // namespace proxy | 215 } // namespace proxy |
| 213 } // namespace pp | 216 } // namespace pp |
| OLD | NEW |