OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_graphics_3d_impl.h" | 5 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using blink::WebFrame; | 31 using blink::WebFrame; |
32 using blink::WebPluginContainer; | 32 using blink::WebPluginContainer; |
33 using blink::WebString; | 33 using blink::WebString; |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 namespace { | 37 namespace { |
38 const int32 kCommandBufferSize = 1024 * 1024; | 38 const int32 kCommandBufferSize = 1024 * 1024; |
39 const int32 kTransferBufferSize = 1024 * 1024; | 39 const int32 kTransferBufferSize = 1024 * 1024; |
40 | 40 |
41 PP_Bool BufferToHandle(scoped_refptr<gpu::Buffer> buffer, | |
42 int* shm_handle, | |
43 uint32_t* shm_size) { | |
44 if (!buffer || !shm_handle || !shm_size) | |
45 return PP_FALSE; | |
46 #if defined(OS_POSIX) | |
47 *shm_handle = buffer->shared_memory()->handle().fd; | |
48 #elif defined(OS_WIN) | |
49 *shm_handle = reinterpret_cast<int>(buffer->shared_memory()->handle()); | |
50 #else | |
51 #error "Platform not supported." | |
52 #endif | |
53 *shm_size = buffer->size(); | |
54 return PP_TRUE; | |
55 } | |
56 | |
57 } // namespace. | 41 } // namespace. |
58 | 42 |
59 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) | 43 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) |
60 : PPB_Graphics3D_Shared(instance), | 44 : PPB_Graphics3D_Shared(instance), |
61 bound_to_instance_(false), | 45 bound_to_instance_(false), |
62 commit_pending_(false), | 46 commit_pending_(false), |
63 weak_ptr_factory_(this) { | 47 weak_ptr_factory_(this) { |
64 } | 48 } |
65 | 49 |
66 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 50 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 89 |
106 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { | 90 PP_Bool PPB_Graphics3D_Impl::SetGetBuffer(int32_t transfer_buffer_id) { |
107 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); | 91 GetCommandBuffer()->SetGetBuffer(transfer_buffer_id); |
108 return PP_TRUE; | 92 return PP_TRUE; |
109 } | 93 } |
110 | 94 |
111 gpu::CommandBuffer::State PPB_Graphics3D_Impl::GetState() { | 95 gpu::CommandBuffer::State PPB_Graphics3D_Impl::GetState() { |
112 return GetCommandBuffer()->GetState(); | 96 return GetCommandBuffer()->GetState(); |
113 } | 97 } |
114 | 98 |
115 int32_t PPB_Graphics3D_Impl::CreateTransferBuffer(uint32_t size) { | 99 scoped_refptr<gpu::Buffer> PPB_Graphics3D_Impl::CreateTransferBuffer( |
116 int32_t id = -1; | 100 uint32_t size, |
117 GetCommandBuffer()->CreateTransferBuffer(size, &id); | 101 int32_t* id) { |
118 return id; | 102 return GetCommandBuffer()->CreateTransferBuffer(size, id); |
119 } | 103 } |
120 | 104 |
121 PP_Bool PPB_Graphics3D_Impl::DestroyTransferBuffer(int32_t id) { | 105 PP_Bool PPB_Graphics3D_Impl::DestroyTransferBuffer(int32_t id) { |
122 GetCommandBuffer()->DestroyTransferBuffer(id); | 106 GetCommandBuffer()->DestroyTransferBuffer(id); |
123 return PP_TRUE; | 107 return PP_TRUE; |
124 } | 108 } |
125 | 109 |
126 PP_Bool PPB_Graphics3D_Impl::GetTransferBuffer(int32_t id, | |
127 int* shm_handle, | |
128 uint32_t* shm_size) { | |
129 scoped_refptr<gpu::Buffer> buffer = GetCommandBuffer()->GetTransferBuffer(id); | |
130 return BufferToHandle(buffer, shm_handle, shm_size); | |
131 } | |
132 | |
133 PP_Bool PPB_Graphics3D_Impl::Flush(int32_t put_offset) { | 110 PP_Bool PPB_Graphics3D_Impl::Flush(int32_t put_offset) { |
134 GetCommandBuffer()->Flush(put_offset); | 111 GetCommandBuffer()->Flush(put_offset); |
135 return PP_TRUE; | 112 return PP_TRUE; |
136 } | 113 } |
137 | 114 |
138 gpu::CommandBuffer::State PPB_Graphics3D_Impl::WaitForTokenInRange( | 115 gpu::CommandBuffer::State PPB_Graphics3D_Impl::WaitForTokenInRange( |
139 int32_t start, | 116 int32_t start, |
140 int32_t end) { | 117 int32_t end) { |
141 GetCommandBuffer()->WaitForTokenInRange(start, end); | 118 GetCommandBuffer()->WaitForTokenInRange(start, end); |
142 return GetCommandBuffer()->GetLastState(); | 119 return GetCommandBuffer()->GetLastState(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 PPP_GRAPHICS_3D_INTERFACE)); | 310 PPP_GRAPHICS_3D_INTERFACE)); |
334 // We have to check *again* that the instance exists, because it could have | 311 // We have to check *again* that the instance exists, because it could have |
335 // been deleted during GetPluginInterface(). Even the PluginModule could be | 312 // been deleted during GetPluginInterface(). Even the PluginModule could be |
336 // deleted, but in that case, the instance should also be gone, so the | 313 // deleted, but in that case, the instance should also be gone, so the |
337 // GetInstance check covers both cases. | 314 // GetInstance check covers both cases. |
338 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 315 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
339 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 316 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
340 } | 317 } |
341 | 318 |
342 } // namespace content | 319 } // namespace content |
OLD | NEW |