| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h" | 7 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h" |
| 8 | 8 |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h" | 10 #include "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h" |
| 11 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | 11 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
| 12 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" | 12 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 36 num += 2; | 36 num += 2; |
| 37 // Add one more for PP_GRAPHICS3DATTRIB_NONE. | 37 // Add one more for PP_GRAPHICS3DATTRIB_NONE. |
| 38 num += 1; | 38 num += 1; |
| 39 } | 39 } |
| 40 return num; | 40 return num; |
| 41 } | 41 } |
| 42 | 42 |
| 43 int32_t GetAttribMaxValue(PP_Instance instance, | 43 int32_t GetAttribMaxValue(PP_Instance instance, |
| 44 int32_t attrib, | 44 int32_t attrib, |
| 45 int32_t* attrib_value) { | 45 int32_t* attrib_value) { |
| 46 DebugPrintf("PPB_Graphics3D::GetAttribMaxValue: instance=%"NACL_PRIu32"\n", | 46 DebugPrintf("PPB_Graphics3D::GetAttribMaxValue: instance=%"NACL_PRId32"\n", |
| 47 instance); | 47 instance); |
| 48 int32_t pp_error; | 48 int32_t pp_error; |
| 49 NaClSrpcError retval = | 49 NaClSrpcError retval = |
| 50 PpbGraphics3DRpcClient::PPB_Graphics3D_GetAttribMaxValue( | 50 PpbGraphics3DRpcClient::PPB_Graphics3D_GetAttribMaxValue( |
| 51 GetMainSrpcChannel(), | 51 GetMainSrpcChannel(), |
| 52 instance, | 52 instance, |
| 53 attrib, | 53 attrib, |
| 54 attrib_value, | 54 attrib_value, |
| 55 &pp_error); | 55 &pp_error); |
| 56 if (retval != NACL_SRPC_RESULT_OK) { | 56 if (retval != NACL_SRPC_RESULT_OK) { |
| 57 return PP_ERROR_BADARGUMENT; | 57 return PP_ERROR_BADARGUMENT; |
| 58 } | 58 } |
| 59 return pp_error; | 59 return pp_error; |
| 60 } | 60 } |
| 61 | 61 |
| 62 PP_Resource Create(PP_Instance instance, | 62 PP_Resource Create(PP_Instance instance, |
| 63 PP_Resource share_context, | 63 PP_Resource share_context, |
| 64 const int32_t* attrib_list) { | 64 const int32_t* attrib_list) { |
| 65 DebugPrintf("PPB_Graphics3D::Create: instance=%"NACL_PRIu32"\n", instance); | 65 DebugPrintf("PPB_Graphics3D::Create: instance=%"NACL_PRId32"\n", instance); |
| 66 PP_Resource graphics3d_id = kInvalidResourceId; | 66 PP_Resource graphics3d_id = kInvalidResourceId; |
| 67 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list); | 67 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list); |
| 68 NaClSrpcError retval = | 68 NaClSrpcError retval = |
| 69 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_CreateRaw( | 69 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_CreateRaw( |
| 70 GetMainSrpcChannel(), | 70 GetMainSrpcChannel(), |
| 71 instance, | 71 instance, |
| 72 share_context, | 72 share_context, |
| 73 num_attribs, const_cast<int32_t *>(attrib_list), | 73 num_attribs, const_cast<int32_t *>(attrib_list), |
| 74 &graphics3d_id); | 74 &graphics3d_id); |
| 75 if (retval == NACL_SRPC_RESULT_OK) { | 75 if (retval == NACL_SRPC_RESULT_OK) { |
| 76 scoped_refptr<PluginGraphics3D> graphics_3d = | 76 scoped_refptr<PluginGraphics3D> graphics_3d = |
| 77 PluginResource::AdoptAs<PluginGraphics3D>(graphics3d_id); | 77 PluginResource::AdoptAs<PluginGraphics3D>(graphics3d_id); |
| 78 if (graphics_3d.get()) { | 78 if (graphics_3d.get()) { |
| 79 graphics_3d->set_instance_id(instance); | 79 graphics_3d->set_instance_id(instance); |
| 80 return graphics3d_id; | 80 return graphics3d_id; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return kInvalidResourceId; | 83 return kInvalidResourceId; |
| 84 } | 84 } |
| 85 | 85 |
| 86 PP_Bool IsGraphics3D(PP_Resource resource) { | 86 PP_Bool IsGraphics3D(PP_Resource resource) { |
| 87 DebugPrintf("PPB_Graphics3D::IsGraphics3D: resource=%"NACL_PRIu32"\n", | 87 DebugPrintf("PPB_Graphics3D::IsGraphics3D: resource=%"NACL_PRId32"\n", |
| 88 resource); | 88 resource); |
| 89 return PluginResource::GetAs<PluginGraphics3D>(resource).get() | 89 return PP_FromBool(PluginResource::GetAs<PluginGraphics3D>(resource).get()); |
| 90 ? PP_TRUE : PP_FALSE; | |
| 91 } | 90 } |
| 92 | 91 |
| 93 int32_t GetAttribs(PP_Resource graphics3d_id, | 92 int32_t GetAttribs(PP_Resource graphics3d_id, |
| 94 int32_t* attrib_list) { | 93 int32_t* attrib_list) { |
| 95 int32_t pp_error; | 94 int32_t pp_error; |
| 96 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list); | 95 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list); |
| 97 NaClSrpcError retval = | 96 NaClSrpcError retval = |
| 98 PpbGraphics3DRpcClient::PPB_Graphics3D_GetAttribs( | 97 PpbGraphics3DRpcClient::PPB_Graphics3D_GetAttribs( |
| 99 GetMainSrpcChannel(), | 98 GetMainSrpcChannel(), |
| 100 graphics3d_id, | 99 graphics3d_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 117 graphics3d_id, | 116 graphics3d_id, |
| 118 num_attribs, attrib_list, | 117 num_attribs, attrib_list, |
| 119 &pp_error); | 118 &pp_error); |
| 120 if (retval != NACL_SRPC_RESULT_OK) { | 119 if (retval != NACL_SRPC_RESULT_OK) { |
| 121 return PP_ERROR_BADARGUMENT; | 120 return PP_ERROR_BADARGUMENT; |
| 122 } | 121 } |
| 123 return pp_error; | 122 return pp_error; |
| 124 } | 123 } |
| 125 | 124 |
| 126 int32_t GetError(PP_Resource graphics3d_id) { | 125 int32_t GetError(PP_Resource graphics3d_id) { |
| 127 DebugPrintf("PPB_Graphics3D::GetError: graphics3d_id=%"NACL_PRIu32"\n", | 126 DebugPrintf("PPB_Graphics3D::GetError: graphics3d_id=%"NACL_PRId32"\n", |
| 128 graphics3d_id); | 127 graphics3d_id); |
| 129 int32_t pp_error; | 128 int32_t pp_error; |
| 130 NaClSrpcError retval = | 129 NaClSrpcError retval = |
| 131 PpbGraphics3DRpcClient::PPB_Graphics3D_GetError( | 130 PpbGraphics3DRpcClient::PPB_Graphics3D_GetError( |
| 132 GetMainSrpcChannel(), | 131 GetMainSrpcChannel(), |
| 133 graphics3d_id, | 132 graphics3d_id, |
| 134 &pp_error); | 133 &pp_error); |
| 135 if (retval != NACL_SRPC_RESULT_OK) { | 134 if (retval != NACL_SRPC_RESULT_OK) { |
| 136 DebugPrintf("PPB_Graphics3D::GetError: retval != NACL_SRPC_RESULT_OK\n"); | 135 DebugPrintf("PPB_Graphics3D::GetError: retval != NACL_SRPC_RESULT_OK\n"); |
| 137 return PP_ERROR_BADARGUMENT; | 136 return PP_ERROR_BADARGUMENT; |
| 138 } | 137 } |
| 139 DebugPrintf("PPB_Graphics3D::GetError: pp_error=%"NACL_PRIu32"\n", pp_error); | 138 DebugPrintf("PPB_Graphics3D::GetError: pp_error=%"NACL_PRId32"\n", pp_error); |
| 140 return pp_error; | 139 return pp_error; |
| 141 } | 140 } |
| 142 | 141 |
| 143 int32_t ResizeBuffers(PP_Resource graphics3d_id, | 142 int32_t ResizeBuffers(PP_Resource graphics3d_id, |
| 144 int32_t width, | 143 int32_t width, |
| 145 int32_t height) { | 144 int32_t height) { |
| 146 if ((width < 0) || (height < 0)) | 145 if ((width < 0) || (height < 0)) |
| 147 return PP_ERROR_BADARGUMENT; | 146 return PP_ERROR_BADARGUMENT; |
| 148 gpu::gles2::GLES2Implementation* impl = | 147 gpu::gles2::GLES2Implementation* impl = |
| 149 PluginGraphics3D::implFromResource(graphics3d_id); | 148 PluginGraphics3D::implFromResource(graphics3d_id); |
| 150 if (impl == NULL) | 149 if (impl == NULL) |
| 151 return PP_ERROR_BADRESOURCE; | 150 return PP_ERROR_BADRESOURCE; |
| 152 impl->ResizeCHROMIUM(width, height); | 151 impl->ResizeCHROMIUM(width, height); |
| 153 return PP_OK; | 152 return PP_OK; |
| 154 } | 153 } |
| 155 | 154 |
| 156 int32_t SwapBuffs(PP_Resource graphics3d_id, | 155 int32_t SwapBuffs(PP_Resource graphics3d_id, |
| 157 struct PP_CompletionCallback callback) { | 156 struct PP_CompletionCallback callback) { |
| 158 DebugPrintf("PPB_Graphics3D::SwapBuffers: graphics3d_id=%"NACL_PRIu32"\n", | 157 DebugPrintf("PPB_Graphics3D::SwapBuffers: graphics3d_id=%"NACL_PRId32"\n", |
| 159 graphics3d_id); | 158 graphics3d_id); |
| 160 | 159 |
| 161 scoped_refptr<PluginGraphics3D> graphics3d = | 160 scoped_refptr<PluginGraphics3D> graphics3d = |
| 162 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id).get(); | 161 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id).get(); |
| 163 if (!graphics3d.get()) | 162 if (!graphics3d.get()) |
| 164 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 163 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 165 | 164 |
| 166 return MayForceCallback(callback, | 165 return MayForceCallback(callback, |
| 167 graphics3d->SwapBuffers(graphics3d_id, callback)); | 166 graphics3d->SwapBuffers(graphics3d_id, callback)); |
| 168 } | 167 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 command_buffer_.reset(); | 185 command_buffer_.reset(); |
| 187 // Invalidate the cache. | 186 // Invalidate the cache. |
| 188 cached_graphics3d_id = 0; | 187 cached_graphics3d_id = 0; |
| 189 cached_implementation = NULL; | 188 cached_implementation = NULL; |
| 190 } | 189 } |
| 191 | 190 |
| 192 // static | 191 // static |
| 193 gpu::gles2::GLES2Implementation* PluginGraphics3D::implFromResourceSlow( | 192 gpu::gles2::GLES2Implementation* PluginGraphics3D::implFromResourceSlow( |
| 194 PP_Resource graphics3d_id) { | 193 PP_Resource graphics3d_id) { |
| 195 DebugPrintf("PluginGraphics3D::implFromResourceSlow: " | 194 DebugPrintf("PluginGraphics3D::implFromResourceSlow: " |
| 196 "resource=%"NACL_PRIu32"\n", graphics3d_id); | 195 "resource=%"NACL_PRId32"\n", graphics3d_id); |
| 197 | 196 |
| 198 // For performance reasons, we don't error-check the context, but crash on | 197 // For performance reasons, we don't error-check the context, but crash on |
| 199 // NULL instead. | 198 // NULL instead. |
| 200 gpu::gles2::GLES2Implementation* impl = | 199 gpu::gles2::GLES2Implementation* impl = |
| 201 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id)->impl(); | 200 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id)->impl(); |
| 202 cached_graphics3d_id = graphics3d_id; | 201 cached_graphics3d_id = graphics3d_id; |
| 203 cached_implementation = impl; | 202 cached_implementation = impl; |
| 204 return impl; | 203 return impl; |
| 205 } | 204 } |
| 206 | 205 |
| 207 | 206 |
| 208 bool PluginGraphics3D::InitFromBrowserResource(PP_Resource res) { | 207 bool PluginGraphics3D::InitFromBrowserResource(PP_Resource res) { |
| 209 DebugPrintf("PluginGraphics3D::InitFromBrowserResource: " | 208 DebugPrintf("PluginGraphics3D::InitFromBrowserResource: " |
| 210 "resource=%"NACL_PRIu32"\n", res); | 209 "resource=%"NACL_PRId32"\n", res); |
| 211 | 210 |
| 212 // Create and initialize the objects required to issue GLES2 calls. | 211 // Create and initialize the objects required to issue GLES2 calls. |
| 213 command_buffer_.reset(new CommandBufferNacl(res, PluginCore::GetInterface())); | 212 command_buffer_.reset(new CommandBufferNacl(res, PluginCore::GetInterface())); |
| 214 if (command_buffer_->Initialize()) { | 213 if (command_buffer_->Initialize()) { |
| 215 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 214 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
| 216 if (gles2_helper_->Initialize(kRingBufferSize)) { | 215 if (gles2_helper_->Initialize(kRingBufferSize)) { |
| 217 // Request id -1 to signify 'don't care' | 216 // Request id -1 to signify 'don't care' |
| 218 int32 transfer_buffer_id = | 217 int32 transfer_buffer_id = |
| 219 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1); | 218 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1); |
| 220 gpu::Buffer transfer_buffer = | 219 gpu::Buffer transfer_buffer = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 &GetAttribs, | 266 &GetAttribs, |
| 268 &SetAttribs, | 267 &SetAttribs, |
| 269 &GetError, | 268 &GetError, |
| 270 &ResizeBuffers, | 269 &ResizeBuffers, |
| 271 &SwapBuffs, | 270 &SwapBuffs, |
| 272 }; | 271 }; |
| 273 return &intf; | 272 return &intf; |
| 274 } | 273 } |
| 275 | 274 |
| 276 } // namespace ppapi_proxy | 275 } // namespace ppapi_proxy |
| 277 | |
| OLD | NEW |