Index: webkit/plugins/ppapi/ppb_graphics_3d_trusted_impl.cc |
=================================================================== |
--- webkit/plugins/ppapi/ppb_graphics_3d_trusted_impl.cc (revision 0) |
+++ webkit/plugins/ppapi/ppb_graphics_3d_trusted_impl.cc (revision 0) |
@@ -0,0 +1,172 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
+ |
+#include "gpu/command_buffer/common/command_buffer.h" |
+#include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" |
+ |
+namespace webkit { |
+namespace ppapi { |
+ |
+namespace { |
+ |
+bool ShmToHandle(base::SharedMemory* shm, |
+ size_t size, |
+ int* shm_handle, |
+ uint32_t* shm_size) { |
+ if (!shm || !shm_handle || !shm_size) |
+ return false; |
+#if defined(OS_POSIX) |
+ *shm_handle = shm->handle().fd; |
+#elif defined(OS_WIN) |
+ *shm_handle = reinterpret_cast<int>(shm->handle()); |
+#else |
+ #error "Platform not supported." |
+#endif |
+ *shm_size = size; |
+ return true; |
+} |
+ |
+PP_Context3DTrustedState PPStateFromGPUState(gpu::CommandBuffer::State s) { |
+ PP_Context3DTrustedState state = { |
+ s.num_entries, |
+ s.get_offset, |
+ s.put_offset, |
+ s.token, |
+ static_cast<PPB_Context3DTrustedError>(s.error) |
+ }; |
+ return state; |
+} |
+ |
+PP_Resource CreateRaw(PP_Instance instance_id, |
+ PP_Config3D_Dev config, |
+ PP_Resource share_context, |
+ const int32_t* attrib_list) { |
+ // TODO(alokp): Support shared context. |
+ DCHECK_EQ(0, share_context); |
+ if (share_context != 0) |
+ return 0; |
+ |
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
+ if (!instance) |
+ return 0; |
+ |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ new PPB_Graphics3D_Impl(instance)); |
+ if (!context->InitRaw(config, share_context, attrib_list)) |
+ return 0; |
+ |
+ return context->GetReference(); |
+} |
+ |
+PP_Bool Initialize(PP_Resource context_id, int32_t size) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return PP_FALSE; |
+ |
+ return context->GetCommandBuffer()->Initialize(size) ? PP_TRUE : PP_FALSE; |
+} |
+ |
+PP_Bool GetRingBuffer(PP_Resource context_id, |
+ int* shm_handle, |
+ uint32_t* shm_size) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return PP_FALSE; |
+ |
+ gpu::Buffer buffer = context->GetCommandBuffer()->GetRingBuffer(); |
+ return ShmToHandle(buffer.shared_memory, buffer.size, shm_handle, shm_size) |
+ ? PP_TRUE : PP_FALSE; |
+} |
+ |
+PP_Context3DTrustedState GetState(PP_Resource context_id) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) { |
+ PP_Context3DTrustedState error_state = { 0 }; |
+ return error_state; |
+ } |
+ |
+ return PPStateFromGPUState(context->GetCommandBuffer()->GetState()); |
+} |
+ |
+PP_Bool Flush(PP_Resource context_id, int32_t put_offset) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return PP_FALSE; |
+ |
+ context->GetCommandBuffer()->Flush(put_offset); |
+ return PP_TRUE; |
+} |
+ |
+PP_Context3DTrustedState FlushSync(PP_Resource context_id, int32_t put_offset) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) { |
+ PP_Context3DTrustedState error_state = { 0 }; |
+ return error_state; |
+ } |
+ |
+ return PPStateFromGPUState( |
+ context->GetCommandBuffer()->FlushSync(put_offset)); |
+} |
+ |
+int32_t CreateTransferBuffer(PP_Resource context_id, uint32_t size) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return 0; |
+ |
+ return context->GetCommandBuffer()->CreateTransferBuffer(size); |
+} |
+ |
+PP_Bool DestroyTransferBuffer(PP_Resource context_id, int32_t id) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return PP_FALSE; |
+ |
+ context->GetCommandBuffer()->DestroyTransferBuffer(id); |
+ return PP_TRUE; |
+} |
+ |
+PP_Bool GetTransferBuffer(PP_Resource context_id, |
+ int32_t id, |
+ int* shm_handle, |
+ uint32_t* shm_size) { |
+ scoped_refptr<PPB_Graphics3D_Impl> context( |
+ Resource::GetAs<PPB_Graphics3D_Impl>(context_id)); |
+ if (!context.get() || !context->GetCommandBuffer()) |
+ return PP_FALSE; |
+ |
+ gpu::Buffer buffer = context->GetCommandBuffer()->GetTransferBuffer(id); |
+ return ShmToHandle(buffer.shared_memory, buffer.size, shm_handle, shm_size) |
+ ? PP_TRUE : PP_FALSE; |
+} |
+ |
+} // namespace |
+ |
+// static |
+const PPB_Context3DTrusted_Dev* PPB_Graphics3D_Impl::GetTrustedInterface() { |
+ static const PPB_Context3DTrusted_Dev ppb_context3d_trusted = { |
+ &CreateRaw, |
+ &Initialize, |
+ &GetRingBuffer, |
+ &GetState, |
+ &Flush, |
+ &FlushSync, |
+ &CreateTransferBuffer, |
+ &DestroyTransferBuffer, |
+ &GetTransferBuffer |
+ }; |
+ return &ppb_context3d_trusted; |
+} |
+ |
+} // namespace ppapi |
+} // namespace webkit |
+ |
Property changes on: webkit\plugins\ppapi\ppb_graphics_3d_trusted_impl.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |