Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h"
8
9 #include "gpu/command_buffer/client/gles2_implementation.h"
10 #include "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h"
11 #include "native_client/src/shared/ppapi_proxy/object_serialize.h"
12 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h"
13 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
14 #include "native_client/src/shared/ppapi_proxy/plugin_instance_data.h"
15 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_core.h"
16 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h"
17 #include "native_client/src/shared/ppapi_proxy/utility.h"
18 #include "native_client/src/shared/srpc/nacl_srpc.h"
19 #include "ppapi/c/pp_completion_callback.h"
20 #include "ppapi/c/pp_errors.h"
21 #include "ppapi/c/pp_rect.h"
22 #include "ppapi/c/pp_var.h"
23 #include "srpcgen/ppb_rpc.h"
24
25 namespace ppapi_proxy {
26
27 namespace {
28
29 const int32 kRingBufferSize = 4096 * 1024;
30 const int32 kTransferBufferSize = 4096 * 1024;
31
32 int32_t GetNumAttribs(const int32_t* attrib_list) {
33 int32_t num = 0;
34 if (attrib_list) {
35 // skip over attrib pairs
36 while (attrib_list[num] != PP_GRAPHICS3DATTRIB_NONE)
37 num += 2;
38 // Add one more for PP_GRAPHICS3DATTRIB_NONE.
39 num += 1;
40 }
41 return num;
42 }
43
44 PP_Resource Create(PP_Instance instance,
45 PP_Resource share_context,
46 const int32_t* attrib_list) {
47 DebugPrintf("PPB_Graphics3D::Create: instance=%"NACL_PRIu32"\n", instance);
48 PP_Resource graphics3d_id = kInvalidResourceId;
49 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list);
50 NaClSrpcError retval =
51 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_CreateRaw(
52 GetMainSrpcChannel(),
53 instance,
54 share_context,
55 num_attribs, const_cast<int32_t *>(attrib_list),
56 &graphics3d_id);
57 if (retval == NACL_SRPC_RESULT_OK) {
58 scoped_refptr<PluginGraphics3D> graphics_3d =
59 PluginResource::AdoptAs<PluginGraphics3D>(graphics3d_id);
60 if (graphics_3d.get()) {
61 graphics_3d->set_instance_id(instance);
62 return graphics3d_id;
63 }
64 }
65 return kInvalidResourceId;
66 }
67
68 PP_Bool IsGraphics3D(PP_Resource resource) {
69 DebugPrintf("PPB_Graphics3D::IsGraphics3D: resource=%"NACL_PRIu32"\n",
70 resource);
71 return PluginResource::GetAs<PluginGraphics3D>(resource).get()
72 ? PP_TRUE : PP_FALSE;
73 }
74
75 int32_t GetAttribs(PP_Resource graphics3d_id,
76 int32_t* attrib_list) {
77 int32_t pp_error;
78 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list);
79 NaClSrpcError retval =
80 PpbGraphics3DRpcClient::PPB_Graphics3D_GetAttribs(
81 GetMainSrpcChannel(),
82 graphics3d_id,
83 num_attribs, attrib_list,
84 &num_attribs, attrib_list,
85 &pp_error);
86 if (retval != NACL_SRPC_RESULT_OK) {
87 return PP_ERROR_BADARGUMENT;
88 }
89 return pp_error;
90 }
91
92 int32_t SetAttribs(PP_Resource graphics3d_id,
93 int32_t* attrib_list) {
94 int32_t pp_error;
95 nacl_abi_size_t num_attribs = GetNumAttribs(attrib_list);
96 NaClSrpcError retval =
97 PpbGraphics3DRpcClient::PPB_Graphics3D_SetAttribs(
98 GetMainSrpcChannel(),
99 graphics3d_id,
100 num_attribs, attrib_list,
101 &pp_error);
102 if (retval != NACL_SRPC_RESULT_OK) {
103 return PP_ERROR_BADARGUMENT;
104 }
105 return pp_error;
106 }
107
108 int32_t ResizeBuffers(PP_Resource graphics3d_id,
109 int32_t width,
110 int32_t height) {
111 int32_t pp_error;
112 NaClSrpcError retval =
113 PpbGraphics3DRpcClient::PPB_Graphics3D_ResizeBuffers(
114 GetMainSrpcChannel(),
115 graphics3d_id,
116 width,
117 height,
118 &pp_error);
119 if (retval != NACL_SRPC_RESULT_OK) {
120 return PP_ERROR_BADARGUMENT;
121 }
122 return pp_error;
123 }
124
125
126 int32_t SwapBuffs(PP_Resource graphics3d_id,
127 struct PP_CompletionCallback callback) {
128 DebugPrintf("PPB_Graphics3D::SwapBuffers: graphics3d_id=%"NACL_PRIu32"\n",
129 graphics3d_id);
130
131 scoped_refptr<PluginGraphics3D> graphics3d =
132 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id).get();
133 if (!graphics3d.get())
134 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
135
136 return MayForceCallback(callback,
137 graphics3d->SwapBuffers(graphics3d_id, callback));
138 }
139
140 } // namespace
141
142 __thread PP_Resource PluginGraphics3D::cached_graphics3d_id = 0;
143 __thread gpu::gles2::GLES2Implementation*
144 PluginGraphics3D::cached_implementation = NULL;
145
146 PluginGraphics3D::PluginGraphics3D() : instance_id_(0) { }
147
148 PluginGraphics3D::~PluginGraphics3D() {
149 // Invalidate the cache.
150 cached_graphics3d_id = 0;
151 cached_implementation = NULL;
152 }
153
154 // static
155 gpu::gles2::GLES2Implementation* PluginGraphics3D::implFromResourceSlow(
156 PP_Resource graphics3d_id) {
157 DebugPrintf("PluginGraphics3D::implFromResourceSlow: "
158 "resource=%"NACL_PRIu32"\n", graphics3d_id);
159
160 // For performance reasons, we don't error-check the context, but crash on
161 // NULL instead.
162 gpu::gles2::GLES2Implementation* impl =
163 PluginResource::GetAs<PluginGraphics3D>(graphics3d_id)->impl();
164 cached_graphics3d_id = graphics3d_id;
165 cached_implementation = impl;
166 return impl;
167 }
168
169
170 bool PluginGraphics3D::InitFromBrowserResource(PP_Resource res) {
171 DebugPrintf("PluginGraphics3D::InitFromBrowserResource: "
172 "resource=%"NACL_PRIu32"\n", res);
173
174 // Create and initialize the objects required to issue GLES2 calls.
175 command_buffer_.reset(new CommandBufferNacl(res, PluginCore::GetInterface()));
176 command_buffer_->Initialize(kRingBufferSize);
177 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
178 gpu::Buffer buffer = command_buffer_->GetRingBuffer();
179 DebugPrintf("PluginGraphics3D::InitFromBrowserResource: buffer size: %d\n",
180 buffer.size);
181 if (gles2_helper_->Initialize(buffer.size)) {
182 // Request id -1 to signify 'don't care'
183 int32 transfer_buffer_id =
184 command_buffer_->CreateTransferBuffer(kTransferBufferSize, -1);
185 gpu::Buffer transfer_buffer =
186 command_buffer_->GetTransferBuffer(transfer_buffer_id);
187 if (transfer_buffer.ptr) {
188 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation(
189 gles2_helper_.get(),
190 transfer_buffer.size,
191 transfer_buffer.ptr,
192 transfer_buffer_id,
193 false));
194 return true;
195 }
196 }
197 return false;
198 }
199
200 int32_t PluginGraphics3D::SwapBuffers(PP_Resource graphics3d_id,
201 struct PP_CompletionCallback callback) {
202
203 int32_t callback_id = CompletionCallbackTable::Get()->AddCallback(callback);
204 if (callback_id == 0) // Just like Chrome, for now disallow blocking calls.
205 return PP_ERROR_BADARGUMENT;
206
207 int32_t pp_error;
208 NaClSrpcError retval =
209 PpbGraphics3DRpcClient::PPB_Graphics3D_SwapBuffers(
210 GetMainSrpcChannel(),
211 graphics3d_id,
212 callback_id,
213 &pp_error);
214 if (retval != NACL_SRPC_RESULT_OK)
215 return PP_ERROR_FAILED;
216
217 if ((PP_OK_COMPLETIONPENDING != pp_error) && (PP_OK != pp_error))
218 return pp_error;
219
220 impl()->SwapBuffers();
221 return PP_OK_COMPLETIONPENDING;
222 }
223
224
225 // static
226 const PPB_Graphics3D_Dev* PluginGraphics3D::GetInterface() {
227 static const PPB_Graphics3D_Dev intf = {
228 &Create,
229 &IsGraphics3D,
230 &GetAttribs,
231 &SetAttribs,
232 &ResizeBuffers,
233 &SwapBuffs,
234 };
235 return &intf;
236 }
237
238 } // namespace ppapi_proxy
239
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698