From 05b47f7a8c5451f858dc220df0e3a97542edace6 Mon Sep 17 00:00:00 2001 From: "gspencer@google.com" Date: Wed, 27 May 2009 23:15:42 +0000 Subject: This is the O3D source tree's initial commit to the Chromium tree. It is not built or referenced at all by the chrome build yet, and doesn't yet build in it's new home. We'll change that shortly. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17035 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/command_buffer/common/build.scons | 40 + o3d/command_buffer/common/cross/bitfield_helpers.h | 71 ++ .../common/cross/bitfield_helpers_test.cc | 68 ++ o3d/command_buffer/common/cross/buffer_sync_api.cc | 43 ++ o3d/command_buffer/common/cross/buffer_sync_api.h | 168 +++++ .../common/cross/cmd_buffer_format.h | 324 ++++++++ o3d/command_buffer/common/cross/gapi_interface.h | 826 +++++++++++++++++++++ o3d/command_buffer/common/cross/logging.h | 67 ++ o3d/command_buffer/common/cross/mocks.h | 148 ++++ o3d/command_buffer/common/cross/resource.cc | 113 +++ o3d/command_buffer/common/cross/resource.h | 208 ++++++ o3d/command_buffer/common/cross/rpc.h | 160 ++++ o3d/command_buffer/common/cross/rpc_fake.cc | 226 ++++++ o3d/command_buffer/common/cross/rpc_fake.h | 205 +++++ o3d/command_buffer/common/cross/rpc_imc.cc | 231 ++++++ o3d/command_buffer/common/cross/rpc_imc.h | 109 +++ o3d/command_buffer/common/cross/types.h | 61 ++ 17 files changed, 3068 insertions(+) create mode 100644 o3d/command_buffer/common/build.scons create mode 100644 o3d/command_buffer/common/cross/bitfield_helpers.h create mode 100644 o3d/command_buffer/common/cross/bitfield_helpers_test.cc create mode 100644 o3d/command_buffer/common/cross/buffer_sync_api.cc create mode 100644 o3d/command_buffer/common/cross/buffer_sync_api.h create mode 100644 o3d/command_buffer/common/cross/cmd_buffer_format.h create mode 100644 o3d/command_buffer/common/cross/gapi_interface.h create mode 100644 o3d/command_buffer/common/cross/logging.h create mode 100644 o3d/command_buffer/common/cross/mocks.h create mode 100644 o3d/command_buffer/common/cross/resource.cc create mode 100644 o3d/command_buffer/common/cross/resource.h create mode 100644 o3d/command_buffer/common/cross/rpc.h create mode 100644 o3d/command_buffer/common/cross/rpc_fake.cc create mode 100644 o3d/command_buffer/common/cross/rpc_fake.h create mode 100644 o3d/command_buffer/common/cross/rpc_imc.cc create mode 100644 o3d/command_buffer/common/cross/rpc_imc.h create mode 100644 o3d/command_buffer/common/cross/types.h (limited to 'o3d/command_buffer/common') diff --git a/o3d/command_buffer/common/build.scons b/o3d/command_buffer/common/build.scons new file mode 100644 index 0000000..0aefd76 --- /dev/null +++ b/o3d/command_buffer/common/build.scons @@ -0,0 +1,40 @@ +# Copyright 2009, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Import('env') + +INPUTS = [ + 'cross/buffer_sync_api.cc', + 'cross/resource.cc', + 'cross/rpc_imc.cc', +] + +# Create a target library from the sources called 'o3dCmdBuf_common' +o3dcmdbuf_lib = env.ComponentLibrary('o3dCmdBuf_common', INPUTS) diff --git a/o3d/command_buffer/common/cross/bitfield_helpers.h b/o3d/command_buffer/common/cross/bitfield_helpers.h new file mode 100644 index 0000000..09a4b2f --- /dev/null +++ b/o3d/command_buffer/common/cross/bitfield_helpers.h @@ -0,0 +1,71 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains a helper template class used to access bit fields in +// unsigned int_ts. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H__ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H__ + +namespace o3d { +namespace command_buffer { + +// Bitfield template class, used to access bit fields in unsigned int_ts. +template class BitField { + public: + static const unsigned int kShift = shift; + static const unsigned int kLength = length; + // the following is really (1<> kShift) & kMask; + } + + // Makes a value that can be or-ed into this field. + static unsigned int MakeValue(unsigned int value) { + return (value & kMask) << kShift; + } + + // Changes the value of this field. + static void Set(unsigned int *container, unsigned int field_value) { + *container = (*container & ~(kMask << kShift)) | MakeValue(field_value); + } +}; + +} // namespace command_buffer +} // namespace o3d + + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_BITFIELD_HELPERS_H__ diff --git a/o3d/command_buffer/common/cross/bitfield_helpers_test.cc b/o3d/command_buffer/common/cross/bitfield_helpers_test.cc new file mode 100644 index 0000000..ab88de42 --- /dev/null +++ b/o3d/command_buffer/common/cross/bitfield_helpers_test.cc @@ -0,0 +1,68 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// Tests for the bitfield helper class. + +#include "gtest/gtest.h" +#include "command_buffer/common/cross/bitfield_helpers.h" + +namespace o3d { +namespace command_buffer { + +// Tests that BitField<>::Get returns the right bits. +TEST(BitFieldTest, TestGet) { + unsigned int value = 0x12345678; + EXPECT_EQ(0x8, (BitField<0, 4>::Get(value))); + EXPECT_EQ(0x45, (BitField<12, 8>::Get(value))); + EXPECT_EQ(0x12345678, (BitField<0, 32>::Get(value))); +} + +// Tests that BitField<>::MakeValue generates the right bits. +TEST(BitFieldTest, TestMakeValue) { + EXPECT_EQ(0x00000003, (BitField<0, 4>::MakeValue(0x3))); + EXPECT_EQ(0x00023000, (BitField<12, 8>::MakeValue(0x123))); + EXPECT_EQ(0x87654321, (BitField<0, 32>::MakeValue(0x87654321))); +} + +// Tests that BitField<>::Set modifies the right bits. +TEST(BitFieldTest, TestSet) { + unsigned int value = 0x12345678; + BitField<0, 4>::Set(&value, 0x9); + EXPECT_EQ(0x12345679, value); + BitField<12, 8>::Set(&value, 0x123); + EXPECT_EQ(0x12323679, value); + BitField<0, 32>::Set(&value, 0x87654321); + EXPECT_EQ(0x87654321, value); +} + +} // namespace command_buffer +} // namespace o3d diff --git a/o3d/command_buffer/common/cross/buffer_sync_api.cc b/o3d/command_buffer/common/cross/buffer_sync_api.cc new file mode 100644 index 0000000..6679108 --- /dev/null +++ b/o3d/command_buffer/common/cross/buffer_sync_api.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "command_buffer/common/cross/buffer_sync_api.h" + +namespace o3d { +namespace command_buffer { + +#ifndef COMPILER_MSVC +const unsigned int BufferSyncInterface::kInvalidSharedMemoryId; +#endif + +} // namespace command_buffer +} // namespace o3d diff --git a/o3d/command_buffer/common/cross/buffer_sync_api.h b/o3d/command_buffer/common/cross/buffer_sync_api.h new file mode 100644 index 0000000..6892b20 --- /dev/null +++ b/o3d/command_buffer/common/cross/buffer_sync_api.h @@ -0,0 +1,168 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file defines the Command Buffer Synchronous API. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_BUFFER_SYNC_API_H__ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_BUFFER_SYNC_API_H__ + +#include "command_buffer/common/cross/rpc.h" + +namespace o3d { +namespace command_buffer { + +// Command buffer type. +typedef ptrdiff_t CommandBufferOffset; + +// Interface class for the Command Buffer Synchronous API. +// This is the part of the command buffer API that is accessible through the +// RPC mechanism, synchronously. +class BufferSyncInterface { + public: + // Status of the command buffer service. It does not process commands + // (meaning: get will not change) unless in PARSING state. + enum ParserStatus { + NOT_CONNECTED, // The service is not connected - initial state. + NO_BUFFER, // The service is connected but no buffer was set. + PARSING, // The service is connected, and parsing commands from the + // buffer. + PARSE_ERROR, // Parsing stopped because a parse error was found. + }; + + enum ParseError { + PARSE_NO_ERROR, + PARSE_INVALID_SIZE, + PARSE_OUT_OF_BOUNDS, + PARSE_UNKNOWN_COMMAND, + PARSE_INVALID_ARGUMENTS, + }; + + // Invalid shared memory Id, returned by RegisterSharedMemory in case of + // failure. + static const unsigned int kInvalidSharedMemoryId = 0xffffffffU; + + BufferSyncInterface() {} + virtual ~BufferSyncInterface() {} + + // Initializes the connection with the client. + virtual void InitConnection() = 0; + + // Closes the connection with the client. + virtual void CloseConnection() = 0; + + // Registers a shared memory buffer. While a buffer is registered, it can be + // accessed by the service, including the underlying asynchronous API, + // through a single identifier. + // Parameters: + // buffer: the shared memory buffer handle. + // Returns: + // an identifier for the shared memory, or kInvalidSharedMemoryId in case + // of failure. + virtual unsigned int RegisterSharedMemory(RPCShmHandle buffer, + size_t size) = 0; + + // Unregisters a shared memory buffer. + // Parameters: + // shm_id: the identifier for the shared memory buffer. + virtual void UnregisterSharedMemory(unsigned int shm_id) = 0; + + // Initializes the command buffer. + // Parameters: + // shm_id: the registered memory buffer in which the command buffer + // resides. + // offset: the offset of the command buffer, relative to the memory + // buffer. + // size: the size of the command buffer. + // start_get: the inital value for the Get pointer, relative to the + // command buffer, where the parser will start interpreting + // commands. Put is also initialized to that value. + virtual void SetCommandBuffer(unsigned int shm_id, + ptrdiff_t offset, + size_t size, + CommandBufferOffset start_get) = 0; + + // Sets the value of the Put pointer. + // Parameters: + // offset: the new value of the Put pointer, as an offset into the command + // buffer. + virtual void Put(CommandBufferOffset offset) = 0; + + // Gets the value of the Get pointer. + // Returns: + // the current value of the Get pointer, as an offset into the command + // buffer. + virtual CommandBufferOffset Get() = 0; + + // Gets the current token value. + // Returns: + // the current token value. + virtual unsigned int GetToken() = 0; + + // Waits until Get changes from the currently known value. + // Parameters: + // current_value: the currently known value. This call will block until + // Get is different from that value (returning immediately + // if it is different). + // Returns: + // the current (changed) value of Get. + virtual CommandBufferOffset WaitGetChanges( + CommandBufferOffset current_value) = 0; + + // Asks the service to signal the client when Get changes from the currently + // known value. This is a non-blocking version of WaitGetChanges. + // Parameters: + // current_value: the currently known value of Get. + // rpc_message_id: the RPC message ID to call on the client when Get is + // different from current_value. That RPC is called + // immediately if Get is already different from + // current_value. + virtual void SignalGetChanges(CommandBufferOffset current_value, + int rpc_message_id) = 0; + + // Gets the status of the service. + // Returns: + // The status of the service. + virtual ParserStatus GetStatus() = 0; + + // Gets the current parse error. The current parse error is set when the + // service is in the PARSE_ERROR status. It may also be set while in the + // PARSING state, if a recoverable error (like PARSE_UNKNOWN_METHOD) was + // encountered. Getting the error resets it to PARSE_NO_ERROR. + // Returns: + // The current parse error. + virtual ParseError GetParseError() = 0; +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_BUFFER_SYNC_API_H__ diff --git a/o3d/command_buffer/common/cross/cmd_buffer_format.h b/o3d/command_buffer/common/cross/cmd_buffer_format.h new file mode 100644 index 0000000..b0b9386 --- /dev/null +++ b/o3d/command_buffer/common/cross/cmd_buffer_format.h @@ -0,0 +1,324 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains the binary format definition of the command buffer. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ + +#include "base/basictypes.h" +#include "command_buffer/common/cross/types.h" +#include "command_buffer/common/cross/bitfield_helpers.h" + +namespace o3d { +namespace command_buffer { + +// Struct that defines the command header in the command buffer. +struct CommandHeader { + Uint32 size:8; + Uint32 command:24; +}; +COMPILE_ASSERT(sizeof(CommandHeader) == 4, Sizeof_CommandHeader_is_not_4); + +// Union that defines possible command buffer entries. +union CommandBufferEntry { + CommandHeader value_header; + Uint32 value_uint32; + Int32 value_int32; + float value_float; +}; + +COMPILE_ASSERT(sizeof(CommandBufferEntry) == 4, + Sizeof_CommandBufferEntry_is_not_4); + +// Bitfields for the SET_VERTEX_INPUT command. +namespace set_vertex_input_cmd { +// argument 4 +typedef BitField<0, 4> SemanticIndex; +typedef BitField<4, 4> Semantic; +typedef BitField<8, 8> Type; +typedef BitField<16, 16> Stride; +} // namespace set_vertex_input_cmd + +// Bitfields for the CREATE_TEXTURE_2D command. +namespace create_texture_2d_cmd { +// argument 1 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +// argument 2 +typedef BitField<0, 4> Levels; +typedef BitField<4, 4> Unused; +typedef BitField<8, 8> Format; +typedef BitField<16, 16> Flags; +} // namespace create_texture_2d_cmd + +// Bitfields for the CREATE_TEXTURE_3D command. +namespace create_texture_3d_cmd { +// argument 1 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +// argument 2 +typedef BitField<0, 16> Depth; +typedef BitField<16, 16> Unused1; +// argument 3 +typedef BitField<0, 4> Levels; +typedef BitField<4, 4> Unused2; +typedef BitField<8, 8> Format; +typedef BitField<16, 16> Flags; +} // namespace create_texture_3d_cmd + +// Bitfields for the CREATE_TEXTURE_CUBE command. +namespace create_texture_cube_cmd { +// argument 1 +typedef BitField<0, 16> Side; +typedef BitField<16, 16> Unused1; +// argument 2 +typedef BitField<0, 4> Levels; +typedef BitField<4, 4> Unused2; +typedef BitField<8, 8> Format; +typedef BitField<16, 16> Flags; +} // namespace create_texture_cube_cmd + +// Bitfields for the SET_TEXTURE_DATA command. +namespace set_texture_data_cmd { +// argument 1 +typedef BitField<0, 16> X; +typedef BitField<16, 16> Y; +// argument 2 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +// argument 3 +typedef BitField<0, 16> Z; +typedef BitField<16, 16> Depth; +// argument 4 +typedef BitField<0, 4> Level; +typedef BitField<4, 3> Face; +typedef BitField<7, 25> Unused; +} // namespace set_texture_data_cmd + +// Bitfields for the SET_TEXTURE_DATA_IMMEDIATE command. +namespace set_texture_data_immediate_cmd { +// argument 1 +typedef BitField<0, 16> X; +typedef BitField<16, 16> Y; +// argument 2 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +// argument 3 +typedef BitField<0, 16> Z; +typedef BitField<16, 16> Depth; +// argument 4 +typedef BitField<0, 4> Level; +typedef BitField<4, 3> Face; +typedef BitField<7, 25> Unused; +} // namespace set_texture_data_immediate_cmd + +// Bitfields for the GET_TEXTURE_DATA command. +namespace get_texture_data_cmd { +// argument 1 +typedef BitField<0, 16> X; +typedef BitField<16, 16> Y; +// argument 2 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +// argument 3 +typedef BitField<0, 16> Z; +typedef BitField<16, 16> Depth; +// argument 4 +typedef BitField<0, 4> Level; +typedef BitField<4, 3> Face; +typedef BitField<7, 25> Unused; +} // namespace get_texture_data_cmd + +// Bitfields for the SET_SAMPLER_STATES command. +namespace set_sampler_states { +// argument 2 +typedef BitField<0, 3> AddressingU; +typedef BitField<3, 3> AddressingV; +typedef BitField<6, 3> AddressingW; +typedef BitField<9, 3> MagFilter; +typedef BitField<12, 3> MinFilter; +typedef BitField<15, 3> MipFilter; +typedef BitField<18, 6> Unused; +typedef BitField<24, 8> MaxAnisotropy; +} // namespace get_texture_data_cmd + +namespace set_scissor { +// argument 0 +typedef BitField<0, 15> X; +typedef BitField<15, 1> Unused; +typedef BitField<16, 15> Y; +typedef BitField<31, 1> Enable; +// argument 1 +typedef BitField<0, 16> Width; +typedef BitField<16, 16> Height; +} // namespace set_scissor + +namespace set_point_line_raster { +// argument 0 +typedef BitField<0, 1> LineSmoothEnable; +typedef BitField<1, 1> PointSpriteEnable; +typedef BitField<2, 30> Unused; +} // namespace set_point_line_raster + +namespace set_polygon_raster { +// argument 0 +typedef BitField<0, 2> FillMode; +typedef BitField<2, 2> CullMode; +typedef BitField<4, 28> Unused; +} // namespace set_polygon_raster + +namespace set_alpha_test { +// argument 0 +typedef BitField<0, 3> Func; +typedef BitField<3, 28> Unused; +typedef BitField<31, 1> Enable; +} // namespace set_alpha_test + +namespace set_depth_test { +// argument 0 +typedef BitField<0, 3> Func; +typedef BitField<3, 27> Unused; +typedef BitField<30, 1> WriteEnable; +typedef BitField<31, 1> Enable; +} // namespace set_depth_test + +namespace set_stencil_test { +// argument 0 +typedef BitField<0, 8> WriteMask; +typedef BitField<8, 8> CompareMask; +typedef BitField<16, 8> ReferenceValue; +typedef BitField<24, 6> Unused0; +typedef BitField<30, 1> SeparateCCW; +typedef BitField<31, 1> Enable; +// argument 1 +typedef BitField<0, 3> CWFunc; +typedef BitField<3, 3> CWPassOp; +typedef BitField<6, 3> CWFailOp; +typedef BitField<9, 3> CWZFailOp; +typedef BitField<12, 4> Unused1; +typedef BitField<16, 3> CCWFunc; +typedef BitField<19, 3> CCWPassOp; +typedef BitField<22, 3> CCWFailOp; +typedef BitField<25, 3> CCWZFailOp; +typedef BitField<28, 4> Unused2; +} // namespace set_stencil_test + +namespace set_color_write { +// argument 0 +typedef BitField<0, 1> RedMask; +typedef BitField<1, 1> GreenMask; +typedef BitField<2, 1> BlueMask; +typedef BitField<3, 1> AlphaMask; +typedef BitField<0, 4> AllColorsMask; // alias for RGBA +typedef BitField<4, 27> Unused; +typedef BitField<31, 1> DitherEnable; +} // namespace set_color_write + +namespace set_blending { +// argument 0 +typedef BitField<0, 4> ColorSrcFunc; +typedef BitField<4, 4> ColorDstFunc; +typedef BitField<8, 3> ColorEq; +typedef BitField<11, 5> Unused0; +typedef BitField<16, 4> AlphaSrcFunc; +typedef BitField<20, 4> AlphaDstFunc; +typedef BitField<24, 3> AlphaEq; +typedef BitField<27, 3> Unused1; +typedef BitField<30, 1> SeparateAlpha; +typedef BitField<31, 1> Enable; +} // namespace set_blending + +// GAPI commands. +enum CommandId { + NOOP, // No operation. Arbitrary argument size. + SET_TOKEN, // Sets token. 1 argument. + BEGIN_FRAME, // BeginFrame. 0 argument. + END_FRAME, // EndFrame. 0 argument. + CLEAR, // Clear. 7 arguments. + CREATE_VERTEX_BUFFER, // CreateVertexBuffer, 3 arguments. + DESTROY_VERTEX_BUFFER, // DestroyVertexBuffer. 1 argument. + SET_VERTEX_BUFFER_DATA, // SetVertexBufferData, 5 args + SET_VERTEX_BUFFER_DATA_IMMEDIATE, // SetVertexBufferData, 2 args + data + GET_VERTEX_BUFFER_DATA, // GetVertexBufferData, 5 args + CREATE_INDEX_BUFFER, // CreateIndexBuffer, 3 arguments. + DESTROY_INDEX_BUFFER, // DestroyIndexBuffer. 1 argument. + SET_INDEX_BUFFER_DATA, // SetIndexBufferData, 5 args + SET_INDEX_BUFFER_DATA_IMMEDIATE, // SetIndexBufferData, 2 args + data + GET_INDEX_BUFFER_DATA, // GetIndexBufferData, 5 args + CREATE_VERTEX_STRUCT, // CreateVertexStruct, 2 args. + DESTROY_VERTEX_STRUCT, // DestroyVertexStruct. 1 argument. + SET_VERTEX_INPUT, // SetVertexInput, 5 args. + SET_VERTEX_STRUCT, // SetVertexStruct, 1 arg. + DRAW, // Draw, 3 args. + DRAW_INDEXED, // DrawIndexed, 6 args. + CREATE_EFFECT, // CreateEffect, 4 args. + CREATE_EFFECT_IMMEDIATE, // CreateEffect, 2 args + data + DESTROY_EFFECT, // DestroyEffect, 1 arg. + SET_EFFECT, // SetEffect, 1 arg. + GET_PARAM_COUNT, // GetParamCount, 4 args. + CREATE_PARAM, // CreateParam, 3 args. + CREATE_PARAM_BY_NAME, // CreateParamByName, 5 args. + CREATE_PARAM_BY_NAME_IMMEDIATE, // CreateParamByName, 3 args + data + DESTROY_PARAM, // DestroyParam, 1 arg + SET_PARAM_DATA, // SetParamData, 4 args + SET_PARAM_DATA_IMMEDIATE, // SetParamData, 2 args + data + GET_PARAM_DESC, // GetParamDesc, 4 args + DESTROY_TEXTURE, // DestroyTexture, 1 arg + CREATE_TEXTURE_2D, // CreateTexture2D, 3 args + CREATE_TEXTURE_3D, // CreateTexture3D, 4 args + CREATE_TEXTURE_CUBE, // CreateTextureCube, 3 args + SET_TEXTURE_DATA, // SetTextureData, 10 args + SET_TEXTURE_DATA_IMMEDIATE, // SetTextureData, 8 args + data + GET_TEXTURE_DATA, // GetTextureData, 10 args + CREATE_SAMPLER, // CreateSampler, 1 arg + DESTROY_SAMPLER, // DestroySampler, 1 arg + SET_SAMPLER_STATES, // SetSamplerStates, 2 arg + SET_SAMPLER_BORDER_COLOR, // SetSamplerBorderColor, 5 arg + SET_SAMPLER_TEXTURE, // SetSamplerTexture, 2 arg + SET_VIEWPORT, // SetViewport. 6 arguments. + SET_SCISSOR, // SetScissor, 2 args + SET_POINT_LINE_RASTER, // SetPointLineRaster, 2 args + SET_POLYGON_RASTER, // SetPolygonRaster, 1 args + SET_POLYGON_OFFSET, // SetPolygonOffest, 2 args + SET_ALPHA_TEST, // SetAlphaTest, 2 args + SET_DEPTH_TEST, // SetDepthTest, 1 args + SET_STENCIL_TEST, // SetStencilTest, 2 args + SET_BLENDING, // SetBlending, 1 args + SET_BLENDING_COLOR, // SetBlendingColor, 4 args + SET_COLOR_WRITE, // SetColorWrite, 1 args +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ diff --git a/o3d/command_buffer/common/cross/gapi_interface.h b/o3d/command_buffer/common/cross/gapi_interface.h new file mode 100644 index 0000000..9531973 --- /dev/null +++ b/o3d/command_buffer/common/cross/gapi_interface.h @@ -0,0 +1,826 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains the interface class for the low-level graphics API +// (GAPI). + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H__ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H__ + +#include "command_buffer/common/cross/buffer_sync_api.h" +#include "command_buffer/common/cross/resource.h" + +namespace o3d { +namespace command_buffer { + +// RBGA color definition. +struct RGBA { + float red; + float green; + float blue; + float alpha; +}; + +// This class defines the low-level graphics API, as a pure interface class. +class GAPIInterface { + public: + typedef BufferSyncInterface::ParseError ParseError; + + GAPIInterface() {} + virtual ~GAPIInterface() {} + + // Initializes the graphics context. + // Returns: + // true if successful. + virtual bool Initialize() = 0; + + // Destroys the graphics context. + virtual void Destroy() = 0; + + // Bit definitions for buffers to clear. + enum ClearBuffer { + COLOR = 0x1, + DEPTH = 0x2, + STENCIL = 0x4, + ALL_BUFFERS = COLOR | DEPTH | STENCIL + }; + + // Primitive type for Draw and DrawIndexed. + enum PrimitiveType { + POINTS, + LINES, + LINE_STRIPS, + TRIANGLES, + TRIANGLE_STRIPS, + TRIANGLE_FANS, + MAX_PRIMITIVE_TYPE + }; + + // Polygon mode for SetPolygonRaster + enum PolygonMode { + POLYGON_MODE_POINTS, + POLYGON_MODE_LINES, + POLYGON_MODE_FILL, + NUM_POLYGON_MODE + }; + + // Face culling mode for SetPolygonRaster + enum FaceCullMode { + CULL_NONE, + CULL_CW, + CULL_CCW, + NUM_FACE_CULL_MODE + }; + + // Comparison function for alpha or depth test + enum Comparison { + NEVER, + LESS, + EQUAL, + LEQUAL, + GREATER, + NOT_EQUAL, + GEQUAL, + ALWAYS, + NUM_COMPARISON + }; + + // Stencil operation + enum StencilOp { + KEEP, + ZERO, + REPLACE, + INC_NO_WRAP, + DEC_NO_WRAP, + INVERT, + INC_WRAP, + DEC_WRAP, + NUM_STENCIL_OP + }; + + // Blend Equation + enum BlendEq { + BLEND_EQ_ADD, + BLEND_EQ_SUB, + BLEND_EQ_REV_SUB, + BLEND_EQ_MIN, + BLEND_EQ_MAX, + NUM_BLEND_EQ + }; + + // Blend Funtion + enum BlendFunc { + BLEND_FUNC_ZERO, + BLEND_FUNC_ONE, + BLEND_FUNC_SRC_COLOR, + BLEND_FUNC_INV_SRC_COLOR, + BLEND_FUNC_SRC_ALPHA, + BLEND_FUNC_INV_SRC_ALPHA, + BLEND_FUNC_DST_ALPHA, + BLEND_FUNC_INV_DST_ALPHA, + BLEND_FUNC_DST_COLOR, + BLEND_FUNC_INV_DST_COLOR, + BLEND_FUNC_SRC_ALPHA_SATUTRATE, + BLEND_FUNC_BLEND_COLOR, + BLEND_FUNC_INV_BLEND_COLOR, + NUM_BLEND_FUNC + }; + + // Starts a frame. Rendering should occur between BeginFrame and EndFrame. + virtual void BeginFrame() = 0; + + // Ends the frame, and bring the back buffer to front. Rendering should occur + // between BeginFrame and EndFrame. + virtual void EndFrame() = 0; + + // Clear buffers, filling them with a constant value. + // Parameters: + // buffers: which buffers to clear. Can be a combination (bitwise or) of + // values from ClearBuffer. + // color: the RGBA color to clear the color target with. + // depth: the depth to clear the depth buffer with. + // stencil: the stencil value to clear the stencil buffer with. + virtual void Clear(unsigned int buffers, + const RGBA &color, + float depth, + unsigned int stencil) = 0; + + // Creates a vertex buffer. + // Parameters: + // id: the resource ID for the new vertex buffer. + // size: the size of the vertex buffer, in bytes. + // flags: the vertex buffer flags, as a combination of vertex_buffer::Flags + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateVertexBuffer(ResourceID id, + unsigned int size, + unsigned int flags) = 0; + + // Destroys a vertex buffer. + // Parameters: + // id: the resource ID of the vertex buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid vertex buffer + // ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyVertexBuffer(ResourceID id) = 0; + + // Sets data into a vertex buffer. + // Parameters: + // id: the resource ID of the vertex buffer. + // offset: the offset into the vertex buffer where to place the data. + // size: the size of the data. + // data: the source data. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments were + // passed: invalid resource ID, or offset or size out of range. + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetVertexBufferData(ResourceID id, + unsigned int offset, + unsigned int size, + const void *data) = 0; + + // Gets data from a vertex buffer. + // Parameters: + // id: the resource ID of the vertex buffer. + // offset: the offset into the vertex buffer where to get the data. + // size: the size of the data. + // data: the destination buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments were + // passed: invalid resource ID, or offset or size out of range. + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError GetVertexBufferData(ResourceID id, + unsigned int offset, + unsigned int size, + void *data) = 0; + + // Creates an index buffer. + // Parameters: + // id: the resource ID for the new index buffer. + // size: the size of the index buffer, in bytes. + // flags: the index buffer flags, as a combination of index_buffer::Flags. + // Note that indices are 16 bits unless the index_buffer::INDEX_32BIT + // flag is specified. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateIndexBuffer(ResourceID id, + unsigned int size, + unsigned int flags) = 0; + + // Destroys an index buffer. + // Parameters: + // id: the resource ID of the index buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid index buffer + // ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyIndexBuffer(ResourceID id) = 0; + + // Sets data into an index buffer. + // Parameters: + // id: the resource ID of the index buffer. + // offset: the offset into the index buffer where to place the data. + // size: the size of the data. + // data: the source data. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments were + // passed: invalid resource ID, or offset or size out of range. + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetIndexBufferData(ResourceID id, + unsigned int offset, + unsigned int size, + const void *data) = 0; + + // Gets data from an index buffer. + // Parameters: + // id: the resource ID of the index buffer. + // offset: the offset into the index buffer where to get the data. + // size: the size of the data. + // data: the destination buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments were + // passed: invalid resource ID, or offset or size out of range. + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError GetIndexBufferData(ResourceID id, + unsigned int offset, + unsigned int size, + void *data) = 0; + + // Creates a vertex struct. A vertex struct describes the input vertex + // attribute streams. + // Parameters: + // id: the resource ID of the vertex struct. + // input_count: the number of input vertex attributes. + // returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateVertexStruct(ResourceID id, + unsigned int input_count) = 0; + + // Destroys a vertex struct. + // Parameters: + // id: the resource ID of the vertex struct. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid vertex struct + // ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyVertexStruct(ResourceID id) = 0; + + // Sets an input into a vertex struct. + // Parameters: + // vertex_struct_id: the resource ID of the vertex struct. + // input_index: the index of the input being set. + // vertex_buffer_id: the resource ID of the vertex buffer containing the + // data. + // offset: the offset into the vertex buffer of the input data, in bytes. + // stride: the stride of the input data, in bytes. + // type: the type of the input data. + // semantic: the semantic of the input. + // semantic_index: the semantic index of the input. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetVertexInput(ResourceID vertex_struct_id, + unsigned int input_index, + ResourceID vertex_buffer_id, + unsigned int offset, + unsigned int stride, + vertex_struct::Type type, + vertex_struct::Semantic semantic, + unsigned int semantic_index) = 0; + + // Sets the current vertex struct for drawing. + // Parameters: + // id: the resource ID of the vertex struct. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed (invalid vertex struct), BufferSyncInterface::PARSE_NO_ERROR + // otherwise. + virtual ParseError SetVertexStruct(ResourceID id) = 0; + + // Draws primitives, using the current vertex struct and the current effect. + // Parameters: + // primitive_type: the type of primitive to draw. + // first: the index of the first vertex. + // count: the number of primitives to draw. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError Draw(PrimitiveType primitive_type, + unsigned int first, + unsigned int count) = 0; + + // Draws primitives, using the current vertex struct and the current effect, + // as well as an index buffer. + // Parameters: + // primitive_type: the type of primitive to draw. + // index_buffer_id: the resource ID of the index buffer. + // first: the index into the index buffer of the first index to draw. + // count: the number of primitives to draw. + // min_index: the lowest index being drawn. + // max_index: the highest index being drawn. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DrawIndexed(PrimitiveType primitive_type, + ResourceID index_buffer_id, + unsigned int first, + unsigned int count, + unsigned int min_index, + unsigned int max_index) = 0; + + // Creates an effect, from source code. + // Parameters: + // id: the resource ID of the effect. + // size: the size of data. + // data: the source code for the effect. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed or the effect failed to compile, + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateEffect(ResourceID id, + unsigned int size, + const void *data) = 0; + + // Destroys an effect. + // Parameters: + // id: the resource ID of the effect. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid effect ID + // was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyEffect(ResourceID id) = 0; + + // Sets the active effect for drawing. + // Parameters: + // id: the resource ID of the effect. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetEffect(ResourceID id) = 0; + + // Gets the number of parameters in an effect, returning it in a memory + // buffer as a Uint32. + // Parameters: + // id: the resource ID of the effect. + // size: the size of the data buffer. Must be at least 4 (the size of the + // Uint32). + // data: the buffer receiving the data. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError GetParamCount(ResourceID id, + unsigned int size, + void *data) = 0; + + // Creates an effect parameter by index. + // Parameters: + // param_id: the resource ID of the parameter being created. + // effect_id: the resource ID of the effect containing the parameter. + // data_type: the data type for the parameter. Must match the data type in + // the effect source. + // index: the index of the parameter. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, such as invalid effect ID, unmatching data type or invalid + // index, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateParam(ResourceID param_id, + ResourceID effect_id, + unsigned int index) = 0; + + // Creates an effect parameter by name. + // Parameters: + // param_id: the resource ID of the parameter being created. + // effect_id: the resource ID of the effect containing the parameter. + // data_type: the data type for the parameter. Must match the data type in + // the effect source. + // size: the size of the parameter name. + // name: the parameter name, as an array of char. Doesn't have to be + // nul-terminated (though nul will terminate the string). + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, such as invalid effect ID, unmatching data type or no parameter + // was found with this name, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateParamByName(ResourceID param_id, + ResourceID effect_id, + unsigned int size, + const void *name) = 0; + + // Destroys an effect parameter. + // Parameters: + // id: the resource ID of the parameter. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid parameter ID + // was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyParam(ResourceID id) = 0; + + // Sets the effect parameter data. + // Parameters: + // id: the resource ID of the parameter. + // size: the size of the data. Must be at least the size of the parameter + // as described by its type. + // data: the parameter data. + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, such as invalid parameter ID, or unmatching data size, + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetParamData(ResourceID id, + unsigned int size, + const void *data) = 0; + + // Gets the parameter description, storing it into a memory buffer. The + // parameter is described by a effect_param::Desc structure. The size must be + // at least the size of that structure. The name and semantic fields are only + // filled if the character strings fit into the memory buffer. In any case, + // the size field (in the effect_param::Desc) is filled with the size needed + // to fill in the structure, the name and the semantic (if any). Thus to get + // the complete information, GetParamDesc can be called twice, once to get + // the size, and, after allocating a big enough buffer, again to fill in the + // complete information including the text strings. + // Parameters: + // id: the resource ID of the parameter. + // size: the size of the memory buffer that wil receive the parameter + // description. Must be at least sizeof(effect_param::Desc). + // data: the memory buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, such as invalid parameter ID, or unsufficient data size, + // BufferSyncInterface::PARSE_NO_ERROR otherwise. Note that + // BufferSyncInterface::PARSE_NO_ERROR will be returned if the structure + // itself fits, not necessarily the names. To make sure all the information + // is available, the caller should compare the returned size member of the + // effect_param::Desc structure to the size parameter passed in. + virtual ParseError GetParamDesc(ResourceID id, + unsigned int size, + void *data) = 0; + + // Creates a 2D texture resource. + // Parameters: + // id: the resource ID of the texture. + // width: the texture width. Must be positive. + // height: the texture height. Must be positive. + // levels: the number of mipmap levels in the texture, or 0 to use the + // maximum. + // format: the format of the texels in the texture. + // flags: the texture flags, as a combination of texture::Flags. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateTexture2D(ResourceID id, + unsigned int width, + unsigned int height, + unsigned int levels, + texture::Format format, + unsigned int flags) = 0; + + // Creates a 3D texture resource. + // Parameters: + // id: the resource ID of the texture. + // width: the texture width. Must be positive. + // height: the texture height. Must be positive. + // depth: the texture depth. Must be positive. + // levels: the number of mipmap levels in the texture, or 0 to use the + // maximum. + // format: the format of the pixels in the texture. + // flags: the texture flags, as a combination of texture::Flags. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateTexture3D(ResourceID id, + unsigned int width, + unsigned int height, + unsigned int depth, + unsigned int levels, + texture::Format format, + unsigned int flags) = 0; + + // Creates a cube map texture resource. + // Parameters: + // id: the resource ID of the texture. + // side: the texture side length. Must be positive. + // levels: the number of mipmap levels in the texture, or 0 to use the + // maximum. + // format: the format of the pixels in the texture. + // flags: the texture flags, as a combination of texture::Flags. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError CreateTextureCube(ResourceID id, + unsigned int side, + unsigned int levels, + texture::Format format, + unsigned int flags) = 0; + + // Sets texel data into a texture resource. This is a common function for + // each of the texture types, but some restrictions exist based on the + // texture type. The specified rectangle or volume of data, defined by x, y, + // width, height and possibly z and depth must fit into the selected mimmap + // level. Data is encoded by rows of 2D blocks, whose size depends on the + // texel format, usually 1x1 texel, but can be 4x4 for DXT* formats. See + // texture::GetBytesPerBlock, texture::GetBlockSizeX and + // texture::GetBlockSizeY. + // Parameters: + // id: the resource ID of the texture. + // x: the x position of the texel corresponding to the first byte of data. + // y: the y position of the texel corresponding to the first byte of data. + // z: the z position of the texel corresponding to the first byte of data. + // Must be 0 for non-3D textures. + // width: the width of the data rectangle/volume. + // height: the height of the data rectangle/volume. + // depth: the depth of the data volume. Must be 1 for non-3D textures. + // level: the mipmap level to put the data into. + // face: which face of the cube to put the data into. Is ignored for + // non-cube map textures. + // row_pitch: the number of bytes between two consecutive rows of blocks, + // in the source data. + // slice_pitch: the number of bytes between two consecutive slices of + // blocks, in the source data. Is ignored for non-3D textures. + // size: the size of the data. + // data: the texel data. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, for example invalid size, or out-of-bounds rectangle/volume, + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetTextureData(ResourceID id, + unsigned int x, + unsigned int y, + unsigned int z, + unsigned int width, + unsigned int height, + unsigned int depth, + unsigned int level, + texture::Face face, + unsigned int pitch, + unsigned int slice_pitch, + unsigned int size, + const void *data) = 0; + + // Gets texel data from a texture resource. This is a common function for + // each of the texture types, but some restrictions exist based on the + // texture type. The specified rectangle or volume of data, defined by x, y, + // width, height and possibly z and depth must fit into the selected mimmap + // level. Data is encoded by rows of 2D blocks, whose size depends on the + // texel format, usually 1x1 texel, but can be 4x4 for DXT* formats. See + // texture::GetBytesPerBlock, texture::GetBlockSizeX and + // texture::GetBlockSizeY. + // Parameters: + // id: the resource ID of the texture. + // x: the x position of the texel corresponding to the first byte of data. + // y: the y position of the texel corresponding to the first byte of data. + // z: the z position of the texel corresponding to the first byte of data. + // Must be 0 for non-3D textures. + // width: the width of the data rectangle/volume. + // height: the height of the data rectangle/volume. + // depth: the depth of the data volume. Must be 1 for non-3D textures. + // level: the mipmap level to put the data into. + // face: which face of the cube to put the data into. Is ignored for + // non-cube map textures. + // row_pitch: the number of bytes between two consecutive rows of blocks, + // in the destination buffer. + // slice_pitch: the number of bytes between two consecutive slices of + // blocks, in the destination buffer. Is ignored for non-3D textures. + // size: the size of the data. + // data: the destination buffer. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are + // passed, for example invalid size, or out-of-bounds rectangle/volume, + // BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError GetTextureData(ResourceID id, + unsigned int x, + unsigned int y, + unsigned int z, + unsigned int width, + unsigned int height, + unsigned int depth, + unsigned int level, + texture::Face face, + unsigned int pitch, + unsigned int slice_pitch, + unsigned int size, + void *data) = 0; + + // Destroys a texture resource. + // Parameters: + // id: the resource ID of the texture. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid texture + // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroyTexture(ResourceID id) = 0; + + // Creates a sampler resource. + // Parameters: + // id: the resource ID of the sampler. + // Returns: + // BufferSyncInterface::PARSE_NO_ERROR. + virtual ParseError CreateSampler(ResourceID id) = 0; + + // Destroys a sampler resource. + // Parameters: + // id: the resource ID of the sampler. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid sampler + // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError DestroySampler(ResourceID id) = 0; + + // Sets the states in a sampler resource. + // Parameters: + // id: the resource ID of the sampler. + // addressing_u: the addressing mode for the U coordinate. + // addressing_v: the addressing mode for the V coordinate. + // addressing_w: the addressing mode for the W coordinate. + // mag_filter: the filtering mode when magnifying textures. + // min_filter: the filtering mode when minifying textures. + // mip_filter: the filtering mode for mip-map interpolation textures. + // max_anisotropy: the maximum anisotropy. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid sampler + // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetSamplerStates(ResourceID id, + sampler::AddressingMode addressing_u, + sampler::AddressingMode addressing_v, + sampler::AddressingMode addressing_w, + sampler::FilteringMode mag_filter, + sampler::FilteringMode min_filter, + sampler::FilteringMode mip_filter, + unsigned int max_anisotropy) = 0; + + // Sets the color of border pixels. + // Parameters: + // id: the resource ID of the sampler. + // color: the border color. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid sampler + // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetSamplerBorderColor(ResourceID id, + const RGBA &color) = 0; + + // Sets the texture resource used by a sampler resource. + // Parameters: + // id: the resource ID of the sampler. + // texture_id: the resource id of the texture. + // Returns: + // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid sampler + // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise. + virtual ParseError SetSamplerTexture(ResourceID id, + ResourceID texture_id) = 0; + + // Sets the viewport, and depth range. + // Parameters: + // x, y: upper left corner of the viewport. + // width, height: dimensions of the viewport. + // z_min, z_max: depth range. + virtual void SetViewport(unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + float z_min, + float z_max) = 0; + + // Sets the scissor test enable flag and rectangle. + // Parameters: + // enable: whether or not scissor test is enabled. + // x, y: upper left corner of the scissor rectangle. + // width, height: dimensions of the scissor rectangle. + virtual void SetScissor(bool enable, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height) = 0; + + // Sets the point and line rasterization state. + // Parameters: + // line_smooth: Whether or not line anti-aliasing is enabled. + // point_sprite: Whether or not point sprites are enabled. + // point_size: The point size. + virtual void SetPointLineRaster(bool line_smooth, + bool point_sprite, + float point_size) = 0; + + // Sets the polygon rasterization state. + // Parameters: + // fill_mode: The polygon filling mode. + // cull_mode: The polygon face culling mode. + virtual void SetPolygonRaster(PolygonMode fill_mode, + FaceCullMode cull_mode) = 0; + + // Sets the polygon offset state. Polygon offset is enabled if slope_factor + // or units is not 0. + // The applied offset (in window coordinates) is: + // o = max_slope * slope_factor + r * units + // Where max_slope is the maximum slope of the polygon (in window + // coordinates again), and r is the minimum resolvable z unit. + // Parameters: + // slope_factor: slope factor for the offset. + // units: constant factor for the offset. + virtual void SetPolygonOffset(float slope_factor, float units) = 0; + + // Sets the alpha test states. + // Parameters: + // enable: alpha test enable state. + // reference: reference value for comparison. + // comp: alpha comparison function. + virtual void SetAlphaTest(bool enable, + float reference, + Comparison comp) = 0; + + // Sets the depth test states. + // Note: if the depth test is disabled, z values are not written to the z + // buffer (i.e enable/ALWAYS is different from disable/*). + // Parameters: + // enable: depth test enable state. + // write_enable: depth write enable state. + // comp: depth comparison function. + virtual void SetDepthTest(bool enable, + bool write_enable, + Comparison comp) = 0; + + // Sets the stencil test states. + // Parameters: + // enable: stencil test enable state. + // separate_ccw: whether or not counter-clockwise faces use separate + // functions/operations (2-sided stencil). + // write_mask: stencil write mask. + // compare_mask: stencil compare mask. + // ref: stencil reference value. + // func_ops: stencil test function and operations for both clockwise and + // counter-clockwise faces. This is a bitfield following the following + // description (little-endian addressing): + // bits 0 - 11: clockwise functions/operations + // bits 12 - 15: must be 0. + // bits 16 - 28: counter-clockwise functions/operations + // bits 29 - 32: must be 0. + virtual void SetStencilTest(bool enable, + bool separate_ccw, + unsigned int write_mask, + unsigned int compare_mask, + unsigned int ref, + Uint32 func_ops) = 0; + + // Sets the color write paramters. + // Parameters: + // red: enable red write. + // green: enable green write. + // blue: enable blue write. + // alpha: enable alpha write. + // dither: enable dithering. + virtual void SetColorWrite(bool red, + bool green, + bool blue, + bool alpha, + bool dither) = 0; + + // Sets the blending mode. + // Parameters: + // enable: whether or not to enable blending. + // separate_alpha: whether or not alpha uses separate Equation/Functions + // (if false, it uses the color ones). + // color_eq: the equation for blending of color values. + // color_src_func: the source function for blending of color values. + // color_dst_func: the destination function for blending of color values. + // alpha_eq: the equation for blending of alpha values. + // alpha_src_func: the source function for blending of alpha values. + // alpha_dst_func: the destination function for blending of alpha values. + virtual void SetBlending(bool enable, + bool separate_alpha, + BlendEq color_eq, + BlendFunc color_src_func, + BlendFunc color_dst_func, + BlendEq alpha_eq, + BlendFunc alpha_src_func, + BlendFunc alpha_dst_func) = 0; + + // Sets the blending color. + virtual void SetBlendingColor(const RGBA &color) = 0; +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H__ diff --git a/o3d/command_buffer/common/cross/logging.h b/o3d/command_buffer/common/cross/logging.h new file mode 100644 index 0000000..7e249bc --- /dev/null +++ b/o3d/command_buffer/common/cross/logging.h @@ -0,0 +1,67 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file abstracts differences in logging between NaCl and host +// environment. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_LOGGING_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_LOGGING_H_ + +#ifndef __native_client__ +#include "base/logging.h" +#else +#include + +// TODO: implement logging through nacl's debug service runtime if +// available. +#define CHECK(X) do {} while (0) +#define CHECK_EQ(X, Y) do {} while (0) +#define CHECK_NE(X, Y) do {} while (0) +#define CHECK_GT(X, Y) do {} while (0) +#define CHECK_GE(X, Y) do {} while (0) +#define CHECK_LT(X, Y) do {} while (0) +#define CHECK_LE(X, Y) do {} while (0) + +#define DCHECK(X) do {} while (0) +#define DCHECK_EQ(X, Y) do {} while (0) +#define DCHECK_NE(X, Y) do {} while (0) +#define DCHECK_GT(X, Y) do {} while (0) +#define DCHECK_GE(X, Y) do {} while (0) +#define DCHECK_LT(X, Y) do {} while (0) +#define DCHECK_LE(X, Y) do {} while (0) + +#define LOG(LEVEL) if (0) std::ostringstream() +#define DLOG(LEVEL) if (0) std::ostringstream() + +#endif + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_LOGGING_H_ diff --git a/o3d/command_buffer/common/cross/mocks.h b/o3d/command_buffer/common/cross/mocks.h new file mode 100644 index 0000000..9573c6b --- /dev/null +++ b/o3d/command_buffer/common/cross/mocks.h @@ -0,0 +1,148 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains definitions for mock objects, used for testing. + +// TODO: This file "manually" defines some mock objects. Using gMock +// would be definitely preferable, unfortunately it doesn't work on Windows +// yet. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_MOCKS_H__ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_MOCKS_H__ + +#include +#include "gmock/gmock.h" +#include "command_buffer/common/cross/rpc.h" +#include "command_buffer/common/cross/buffer_sync_api.h" + +namespace o3d { +namespace command_buffer { + +// Mocks a RPC send interface. This class only mocks SendCall currently. +// Set call expectations with AddSendCallExpect: one for each call with exact +// parameters, and desired return value, then run the test. +class RPCSendInterfaceMock : public RPCSendInterface { + public: + RPCSendInterfaceMock() : called_(0) {} + virtual ~RPCSendInterfaceMock() { Check(); } + + // Checks that the expected number of calls actually happened. + void Check() { + EXPECT_EQ(expects_.size(), called_); + } + + // Struct describing a SendCall call expectation, with the desired return + // value. + struct SendCallExpect { + RPCImplInterface::ReturnValue _return; + int message_id; + const void * data; + size_t size; + RPCHandle * handles; + size_t handle_count; + }; + + // Adds an expectation for a SendCall call. + void AddSendCallExpect(const SendCallExpect &expect) { + expects_.push_back(expect); + } + + // Mock SendCall implementation. This will check the arguments against the + // expected values (the values pointed by 'data' are compared, not the + // pointer), and return the desired return value. + virtual RPCImplInterface::ReturnValue SendCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) { + if (called_ < expects_.size()) { + const SendCallExpect &expect = expects_[called_]; + ++called_; + EXPECT_EQ(expect.message_id, message_id); + EXPECT_EQ(expect.size, size); + if (expect.size != size) return 0; + EXPECT_EQ(expect.handle_count, handle_count); + if (expect.handle_count != handle_count) return 0; + if (size > 0) { + EXPECT_EQ(0, memcmp(expect.data, data, size)); + } else { + EXPECT_FALSE(data); + } + if (handle_count > 0) { + for (unsigned int i = 0; i < handle_count; ++i) { + EXPECT_TRUE(expect.handles[i] == handles[i]); + } + } else { + EXPECT_FALSE(handles); + } + return expect._return; + } else { + ++called_; + // This is really an EXPECT_FALSE, but we get to display useful values. + EXPECT_GE(expects_.size(), called_); + // We need to return something but we don't know what, we don't have any + // expectation for this call. 0 will do. + return 0; + } + } + private: + size_t called_; + std::vector expects_; +}; + +// Mocks a BufferSyncInterface, using GMock. +class BufferSyncMock : public BufferSyncInterface { + public: + MOCK_METHOD0(InitConnection, void()); + MOCK_METHOD0(CloseConnection, void()); + MOCK_METHOD2(RegisterSharedMemory, unsigned int(RPCShmHandle buffer, + size_t size)); + MOCK_METHOD1(UnregisterSharedMemory, void(unsigned int shm_id)); + MOCK_METHOD4(SetCommandBuffer, void(unsigned int shm_id, + ptrdiff_t offset, + size_t size, + CommandBufferOffset start_get)); + MOCK_METHOD1(Put, void(CommandBufferOffset offset)); + MOCK_METHOD0(Get, CommandBufferOffset()); + MOCK_METHOD0(GetToken, unsigned int()); + MOCK_METHOD1(WaitGetChanges, + CommandBufferOffset(CommandBufferOffset current_value)); + MOCK_METHOD2(SignalGetChanges, void(CommandBufferOffset current_value, + int rpc_message_id)); + MOCK_METHOD0(GetStatus, ParserStatus()); + MOCK_METHOD0(GetParseError, ParseError()); +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_MOCKS_H__ diff --git a/o3d/command_buffer/common/cross/resource.cc b/o3d/command_buffer/common/cross/resource.cc new file mode 100644 index 0000000..7619ba0 --- /dev/null +++ b/o3d/command_buffer/common/cross/resource.cc @@ -0,0 +1,113 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains the implementation of the helper functions for resources. + +#include "command_buffer/common/cross/resource.h" + +namespace o3d { +namespace command_buffer { + +namespace texture { + +// Gets the number of bytes per block for a given format. +unsigned int GetBytesPerBlock(Format format) { + switch (format) { + case XRGB8: + case ARGB8: + return 4; + case ABGR16F: + return 8; + case DXT1: + return 8; + default: + LOG(FATAL) << "Invalid format"; + return 1; + } +} + +// Gets the width of a block for a given format. +unsigned int GetBlockSizeX(Format format) { + switch (format) { + case XRGB8: + case ARGB8: + case ABGR16F: + return 1; + case DXT1: + return 4; + default: + LOG(FATAL) << "Invalid format"; + return 1; + } +} + +// Gets the height of a block for a given format. +unsigned int GetBlockSizeY(Format format) { + // NOTE: currently only supported formats use square blocks. + return GetBlockSizeX(format); +} + +} // namespace texture + +namespace effect_param { + +// Gets the size of the data of a given parameter type. +unsigned int GetDataSize(DataType type) { + switch (type) { + case UNKNOWN: + return 0; + case FLOAT1: + return sizeof(float); // NOLINT + case FLOAT2: + return sizeof(float)*2; // NOLINT + case FLOAT3: + return sizeof(float)*3; // NOLINT + case FLOAT4: + return sizeof(float)*4; // NOLINT + case MATRIX4: + return sizeof(float)*16; // NOLINT + case INT: + return sizeof(int); // NOLINT + case BOOL: + return sizeof(bool); // NOLINT + case SAMPLER: + return sizeof(ResourceID); // NOLINT + default: + LOG(FATAL) << "Invalid type."; + return 0; + } +} + +} // namespace effect_param + +} // namespace command_buffer +} // namespace o3d diff --git a/o3d/command_buffer/common/cross/resource.h b/o3d/command_buffer/common/cross/resource.h new file mode 100644 index 0000000..cbdff26 --- /dev/null +++ b/o3d/command_buffer/common/cross/resource.h @@ -0,0 +1,208 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains definitions for resource flags, enums, and helper +// functions. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_RESOURCE_H__ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_RESOURCE_H__ + +#include +#include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "command_buffer/common/cross/types.h" +#include "command_buffer/common/cross/logging.h" + +namespace o3d { +namespace command_buffer { + +// A resource ID, key to the resource maps. +typedef unsigned int ResourceID; +// Invalid resource ID. +static const ResourceID kInvalidResource = 0xffffffffU; + +namespace vertex_buffer { +// Vertex buffer flags. +enum Flags { + DYNAMIC = 0x01, // This vertex buffer is dynamic and is expected to have + // its data updated often. +}; +} // namespace vertex_buffer + +namespace index_buffer { +// Index buffer flags. +enum Flags { + DYNAMIC = 0x01, // This index buffer is dynamic and is expected to have + // its data updated often. + INDEX_32BIT = 0x02, // Indices contained in this index buffer are 32 bits + // (unsigned int) instead of 16 bit (unsigned short). +}; +} // namespace index_buffer + +namespace vertex_struct { +// Semantics for input data. +enum Semantic { + POSITION, + NORMAL, + COLOR, + TEX_COORD, + NUM_SEMANTICS +}; + +// Input data types. +enum Type { + FLOAT1, + FLOAT2, + FLOAT3, + FLOAT4, + UCHAR4N, + NUM_TYPES +}; +} // namespace vertex_struct + +namespace effect_param { +enum DataType { + UNKNOWN, // A parameter exists in the effect, but the type is not + // representable (e.g. MATRIX3x4). + FLOAT1, + FLOAT2, + FLOAT3, + FLOAT4, + MATRIX4, + INT, + BOOL, + SAMPLER, + NUM_TYPES, + MAKE_32_BIT = 0x7fffffff, +}; +COMPILE_ASSERT(sizeof(DataType) == 4, DataType_should_be_32_bits); + +// Gets the size of the data of a particular type. +unsigned int GetDataSize(DataType type); + +// Structure describing a parameter, filled in by the +// GAPIInterface::GetParamDesc call. +struct Desc { + Uint32 size; // the total memory size needed for the complete + // description. + Uint32 name_offset; // the offset of the parameter name, relative to + // the beginning of the structure. May be 0 if the + // name doesn't fit into the memory buffer. + Uint32 name_size; // the size of the parameter name, including the + // terminating nul character. Will always be set + // even if the name doesn't fit into the buffer. + Uint32 semantic_offset; // the offset of the parameter semantic, relative + // to the beginning of the structure. May be 0 if + // the semantic doesn't fit into the memory + // buffer. + Uint32 semantic_size; // the size of the parameter semantic, including + // the terminating nul character. Will always be + // set even if the semantic doesn't fit into the + // buffer. + DataType data_type; // the data type of the parameter. + Uint32 data_size; // the size of the parameter data, in bytes. +}; +} // namespace effect_param + +namespace texture { +// Texture flags. +enum Flags { + DYNAMIC = 0x01, // This texture is dynamic and is expected to have + // its data updated often. +}; + +// Texel formats. +enum Format { + XRGB8, + ARGB8, + ABGR16F, + DXT1, + NUM_FORMATS +}; + +// Texture type. +enum Type { + TEXTURE_2D, + TEXTURE_3D, + TEXTURE_CUBE, +}; + +// Cube map face. +enum Face { + FACE_POSITIVE_X, + FACE_NEGATIVE_X, + FACE_POSITIVE_Y, + FACE_NEGATIVE_Y, + FACE_POSITIVE_Z, + FACE_NEGATIVE_Z, +}; + +// Gets the number of bytes per block for a given texture format. For most +// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. +unsigned int GetBytesPerBlock(Format format); +// Gets the x dimension of a texel block for a given texture format. For most +// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. +unsigned int GetBlockSizeX(Format format); +// Gets the y dimension of a texel block for a given texture format. For most +// texture formats, a block is 1x1 texels, but DXT* formats have 4x4 blocks. +unsigned int GetBlockSizeY(Format format); +// Gets the dimension of a mipmap level given the dimension of the base +// level. Every mipmap level is half the size of the previous level, rounding +// down. +static unsigned int GetMipMapDimension(unsigned int base, + unsigned int level) { + DCHECK_GT(base, 0); + return std::max(1U, base >> level); +} +} // namespace texture + +namespace sampler { +enum AddressingMode { + WRAP, + MIRROR_REPEAT, + CLAMP_TO_EDGE, + CLAMP_TO_BORDER, + NUM_ADDRESSING_MODE +}; + +enum FilteringMode { + NONE, + POINT, + LINEAR, + NUM_FILTERING_MODE +}; +} // namespace sampler + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_RESOURCE_H__ diff --git a/o3d/command_buffer/common/cross/rpc.h b/o3d/command_buffer/common/cross/rpc.h new file mode 100644 index 0000000..d2e0d9f --- /dev/null +++ b/o3d/command_buffer/common/cross/rpc.h @@ -0,0 +1,160 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_H_ + +#include "base/basictypes.h" + +#include "native_client/intermodule_comm/nacl_htp.h" + +namespace o3d { +namespace command_buffer { + +// Pre-defined message IDs. +enum { + POISONED_MESSAGE_ID, // sent to kill the RPC server. + RESPONSE_ID, // sent as a response to a RPC call. +}; + +typedef nacl::HtpHandle RPCHandle; +typedef RPCHandle RPCShmHandle; +typedef RPCHandle RPCSocketHandle; +static const RPCHandle kRPCInvalidHandle = nacl::kInvalidHtpHandle; + +// Interface for a RPC implementation. This class defines the calls a RPC +// service needs to implement. +class RPCImplInterface { + public: + // The type of return values for RPC calls. The RPC model is an arbitrary + // set of parameters, but a single return value. + typedef unsigned int ReturnValue; + + RPCImplInterface() {} + virtual ~RPCImplInterface() {} + + // De-multiplexes a RPC call. This function takes the message ID and the data + // to deduce a proper function to call, with its arguments, returning a + // single value. Most protocols will select the function from the message ID, + // and take the arguments from the data. + // Parameters: + // message_id: the RPC message ID. + // data: the RPC message payload. + // size: the size of the data. + // Returns: + // a single return value from the function called. + virtual ReturnValue DoCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(RPCImplInterface); +}; + +class RPCSendInterface { + public: + virtual ~RPCSendInterface() {} + // Sends a call to the server thread. This call will be dispatched by the + // server thread to the RPC implementation. This call will block until the + // call is processed and the return value is sent back. + // Parameters: + // message_id: the RPC message ID. + // data: the RPC message payload. + // size: the size of the data. + // handles: an array of RPC handles to transmit + // handle_count: the number of RPC handles in the array + // Returns: + // the return value of the RPC call. + virtual RPCImplInterface::ReturnValue SendCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) = 0; +}; + +class RPCProcessInterface { + public: + virtual ~RPCProcessInterface() {} + // Processes one message, blocking if necessary until a message is available + // or the server is killed. This will dispatch the received message to the + // RPC implementation, and send back a response message with the return + // value to the client. + // Returns: + // false if the server was killed. + virtual bool ProcessMessage() = 0; + + // Checks whether a message is available for processing - allowing to test if + // ProcessMessage will block. + // Returns: + // true if a message is available. + virtual bool HasMessage() = 0; +}; + +// Creates a RPCSendInterface from a RPCSocketHandle. +RPCSendInterface *MakeSendInterface(RPCSocketHandle handle); + +// Creates a shared memory buffer. +// Parameters: +// size: the size of the buffer. +// Returns: +// the handle to the shared memory buffer. +RPCShmHandle CreateShm(size_t size); + +// Destroys a shared memory buffer. +// Parameters: +// handle: the handle to the shared memory buffer. +void DestroyShm(RPCShmHandle handle); + +// Maps a shared memory buffer into the address space. +// Parameters: +// handle: the handle to the shared memory buffer. +// size: the size of the region to map in the memory buffer. May be smaller +// than the shared memory region, but the underlying implementation +// will round it up to the page size or the whole shared memory. +// Returns: +// the address of the mapped region, or NULL if failure. +void *MapShm(RPCShmHandle handle, size_t size); + +// Unmaps a previously mapped memory buffer. +// Parameters: +// address: the address of the mapped region. +// size: the size of the region to un-map. It can be a subset of the +// previously mapped region, but the underlying implementation will +// round it up to the page size. +void UnmapShm(void *address, size_t size); + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_H_ diff --git a/o3d/command_buffer/common/cross/rpc_fake.cc b/o3d/command_buffer/common/cross/rpc_fake.cc new file mode 100644 index 0000000..ed09b90 --- /dev/null +++ b/o3d/command_buffer/common/cross/rpc_fake.cc @@ -0,0 +1,226 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include "command_buffer/common/cross/rpc_fake.h" + +namespace o3d { +namespace command_buffer { + +// Create the queue, initializing the synchronization structures: a mutex for +// the queue itself, and an event to signal the consumers. +RPCQueue::RPCQueue() { + event_ = ::CreateEvent(NULL, FALSE, FALSE, NULL); + ::InitializeCriticalSection(&mutex_); +} + +RPCQueue::~RPCQueue() { + ::DeleteCriticalSection(&mutex_); + ::CloseHandle(event_); +} + +// Adds a message into the queue. Signal waiting threads that a new message is +// available. +void RPCQueue::AddMessage(const RPCMessage &call) { + ::EnterCriticalSection(&mutex_); + queue_.push(call); + ::SetEvent(event_); + ::LeaveCriticalSection(&mutex_); +} + +// Checks whether the queue is empty. +bool RPCQueue::IsEmpty() { + ::EnterCriticalSection(&mutex_); + bool result = queue_.empty(); + ::LeaveCriticalSection(&mutex_); + return result; +} + +// Gets a message, waiting for one if the queue is empty. +void RPCQueue::GetMessage(RPCMessage *message) { + ::EnterCriticalSection(&mutex_); + while (queue_.empty()) { + ::LeaveCriticalSection(&mutex_); + ::WaitForSingleObject(event_, INFINITE); + ::EnterCriticalSection(&mutex_); + } + *message = queue_.front(); + queue_.pop(); + ::LeaveCriticalSection(&mutex_); +} + +// Tries to gets a message, returning immediately if the queue is empty. +bool RPCQueue::TryGetMessage(RPCMessage *message) { + ::EnterCriticalSection(&mutex_); + bool result = !queue_.empty(); + if (result) { + *message = queue_.front(); + queue_.pop(); + } + ::LeaveCriticalSection(&mutex_); + return result; +} + +// Creates the RPC server. The RPC server uses 2 RPC Queues, one for "incoming" +// calls (in_queue_), and one for "outgoing" return values (out_queue_). +RPCServer::RPCServer(RPCImplInterface * impl) { + sender_.reset(new Sender(&in_queue_, &out_queue_)); + processor_.reset(new Processor(&in_queue_, &out_queue_, impl)); +} + +RPCServer::~RPCServer() {} + +// Allocates the data for a message, if needed. Initializes the RPCMessage +// structure. +void RPCServer::AllocMessage(int message_id, + const void *data, + size_t size, + RPCHandle const *handles, + size_t handle_count, + RPCMessage *message) { + message->message_id = message_id; + message->size = size; + message->handle_count = handle_count; + if (data) { + message->data = malloc(size); + memcpy(message->data, data, size); + } else { + DCHECK(size == 0); + message->data = NULL; + } + if (handles) { + DCHECK(handle_count > 0); + message->handles = new RPCHandle[handle_count]; + for (unsigned int i = 0; i < handle_count; ++i) + message->handles[i] = handles[i]; + } else { + DCHECK(handle_count == 0); + message->handles = NULL; + } +} + +// Destroys the message data if needed. +void RPCServer::DestroyMessage(RPCMessage *message) { + if (message->data) free(message->data); + if (message->handles) delete [] message->handles; +} + +// Processes one message, getting one from the incoming queue (blocking), +// dispatching it to the implementation (if not the "poisoned" message), and +// adding the return value to the outgoing queue. +bool RPCServer::Processor::ProcessMessage() { + RPCMessage input; + in_queue_->GetMessage(&input); + RPCImplInterface::ReturnValue result = 0; + int continue_processing = true; + if (input.message_id == POISONED_MESSAGE_ID) { + continue_processing = false; + } else { + result = impl_->DoCall(input.message_id, input.data, input.size, + input.handles, input.handle_count); + } + DestroyMessage(&input); + + RPCMessage output; + AllocMessage(RESPONSE_ID, &result, sizeof(result), NULL, 0, &output); + out_queue_->AddMessage(output); + return continue_processing; +} + +// Checks if the incoming queue is empty. +bool RPCServer::Processor::HasMessage() { + return !in_queue_->IsEmpty(); +} + +// Processes all messages until the server is killed. +void RPCServer::MessageLoop() { + do {} while (processor_->ProcessMessage()); +} + +// Sends a "poisoned" call to the server thread, making it exit the processing +// loop. +void RPCServer::KillServer() { + sender_->SendCall(POISONED_MESSAGE_ID, NULL, 0, NULL, 0); +} + +// Sends a call to the server thread. This puts a message into the "incoming" +// queue, and waits for the return message on the "outgoing" queue. +RPCImplInterface::ReturnValue RPCServer::Sender::SendCall( + int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) { + RPCMessage input; + AllocMessage(message_id, data, size, handles, handle_count, &input); + in_queue_->AddMessage(input); + + RPCMessage output; + out_queue_->GetMessage(&output); + DCHECK(output.message_id == RESPONSE_ID); + DCHECK(output.size == sizeof(RPCImplInterface::ReturnValue)); + RPCImplInterface::ReturnValue result = + *(reinterpret_cast(output.data)); + DestroyMessage(&output); + return result; +} + +class RPCSendProxy : public RPCSendInterface { + public: + explicit RPCSendProxy(RPCSendInterface *interface) : interface_(interface) {} + virtual ~RPCSendProxy() {} + virtual RPCImplInterface::ReturnValue SendCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) { + return interface_->SendCall(message_id, data, size, handles, handle_count); + } + private: + RPCSendInterface *interface_; +}; + +// Create a proxy so that it can be managed as a separate object, to have the +// same semantics as the IMC implementation. +RPCSendInterface *MakeSendInterface(RPCSocketHandle handle) { + return new RPCSendProxy(handle->GetSendInterface()); +} + +void *MapShm(RPCShmHandle handle, size_t size) { + return (size <= handle->size) ? return handle->address : NULL; +} + +void UnmapShm(void * address, size_t size) { +} + +} // namespace command_buffer +} // namespace o3d diff --git a/o3d/command_buffer/common/cross/rpc_fake.h b/o3d/command_buffer/common/cross/rpc_fake.h new file mode 100644 index 0000000..c7727c5 --- /dev/null +++ b/o3d/command_buffer/common/cross/rpc_fake.h @@ -0,0 +1,205 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file defines classes faking the NativeClient RPC mechanism. This is +// intended as a temporary replacement of NativeClient until it is ready. It +// assumes the various clients and services run in separate threads of the same +// process. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_FAKE_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_FAKE_H_ + +#include +#include +#include "core/cross/types.h" +#include "command_buffer/common/cross/rpc.h" + +namespace o3d { +namespace command_buffer { + +typedef CRITICAL_SECTION Mutex; +typedef HANDLE Event; + +// Struct describing a RPC message, as a message ID and a data payload. +// It "owns" the data pointer. +struct RPCMessage { + int message_id; + size_t size; + void *data; + RPCHandle *handles; + size_t handle_count; +}; + +// Implementation of a (thread-safe) RPC message queue (FIFO). It allows simply +// to enqueue and dequeue messages, in a blocking or non-blocking fashion. +class RPCQueue { + public: + RPCQueue(); + ~RPCQueue(); + + // Adds a message into the back of the queue. + // Parameters: + // message: the message to enqueue. Ownership of the message data is taken + // by the queue. + void AddMessage(const RPCMessage &message); + + // Tests whether or not the queue is empty. + // Returns: + // true if the queue is empty. + bool IsEmpty(); + + // Gets a message from the front of the queue. This call blocks until a + // message is available in the queue. + // Parameters: + // message: a pointer to a RPCMessage structure receiving the message. + // That structure takes ownership of the message data. + void GetMessage(RPCMessage *message); + + // Try to get a message from the front of the queue, if any. This call will + // not block if the queue is empty. + // Parameters: + // message: a pointer to a RPCMessage structure receiving the message, if + // any. That structure takes ownership of the message data. If no + // message is available, that structure is unchanged. + // Returns: + // true if a message was available. + bool TryGetMessage(RPCMessage *message); + + private: + std::queue queue_; + Mutex mutex_; + Event event_; + + DISALLOW_COPY_AND_ASSIGN(RPCQueue); +}; + +// Implements a fake RPC server interface. This class is intended to be used +// across different threads (it is thread safe): +// - one server thread, that processes messages (using MessageLoop() or +// ProcessMessage()), to execute the RPC calls. +// - one or several client threads, that can send RPC calls to it. +// +// One of the client threads can "kill" the server so that it exits its +// processing loop. +class RPCServer { + public: + explicit RPCServer(RPCImplInterface *impl); + ~RPCServer(); + + // Server thread functions + + // Processes all messages, until the server is killed. + void MessageLoop(); + RPCProcessInterface *GetProcessInterface() { return processor_.get(); } + + // client thread functions + RPCSendInterface *GetSendInterface() { return sender_.get(); } + + // Kills the server thread, making it exit its processing loop. This call + // will block until the server has finished processing all the previous + // messages. + void KillServer(); + + private: + static void AllocMessage(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count, + RPCMessage *message); + static void DestroyMessage(RPCMessage *message); + + class Sender : public RPCSendInterface { + public: + Sender(RPCQueue *in_queue, RPCQueue *out_queue) + : in_queue_(in_queue), + out_queue_(out_queue) {} + // Sends a call to the server thread. This call will be dispatched by the + // server thread to the RPC implementation. This call will block until the + // call is processed and the return value is sent back. + // Parameters: + // message_id: the RPC message ID. + // data: the RPC message payload. + // size: the size of the data. + // handles: an array of RPC handles to transmit + // handle_count: the number of RPC handles in the array + // Returns: + // the return value of the RPC call. + virtual RPCImplInterface::ReturnValue SendCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count); + private: + RPCQueue *in_queue_; + RPCQueue *out_queue_; + DISALLOW_COPY_AND_ASSIGN(Sender); + }; + + class Processor : public RPCProcessInterface { + public: + Processor(RPCQueue *in_queue, RPCQueue *out_queue, RPCImplInterface *impl) + : in_queue_(in_queue), + out_queue_(out_queue), + impl_(impl) {} + virtual ~Processor() {} + // Processes one message, blocking if necessary until a message is available + // or the server is killed. This will dispatch the received message to the + // RPC implementation, and send back a response message with the return + // value to the client. + // Returns: + // false if the server was killed. + virtual bool ProcessMessage(); + + // Checks whether a message is available for processing - allowing to test + // if ProcessMessage will block. + // Returns: + // true if a message is available. + virtual bool HasMessage(); + private: + RPCQueue *in_queue_; + RPCQueue *out_queue_; + RPCImplInterface *impl_; + DISALLOW_COPY_AND_ASSIGN(Processor); + }; + + RPCQueue in_queue_; + RPCQueue out_queue_; + scoped_ptr sender_; + scoped_ptr processor_; + DISALLOW_COPY_AND_ASSIGN(RPCServer); +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_FAKE_H_ diff --git a/o3d/command_buffer/common/cross/rpc_imc.cc b/o3d/command_buffer/common/cross/rpc_imc.cc new file mode 100644 index 0000000..1fcb9c7 --- /dev/null +++ b/o3d/command_buffer/common/cross/rpc_imc.cc @@ -0,0 +1,231 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include "command_buffer/common/cross/logging.h" +#include "command_buffer/common/cross/rpc_imc.h" +#include "native_client/intermodule_comm/nacl_htp.h" + +namespace o3d { +namespace command_buffer { + +int NaclSendData(nacl::HtpHandle channel, + const void *data, + size_t size, + int flags) { + nacl::HtpHeader msg; + nacl::IOVec vec; + vec.base = const_cast(data); + vec.length = size; + msg.iov = &vec; + msg.iov_length = 1; + msg.handles = NULL; + msg.handle_count = 0; + msg.flags = 0; + return nacl::SendDatagram(channel, &msg, flags); +} + +int NaclSendHandles(nacl::HtpHandle channel, + const nacl::HtpHandle *handles, + size_t count, + int flags) { + nacl::HtpHeader msg; + msg.iov = NULL; + msg.iov_length = 0; + msg.handles = const_cast(handles); + msg.handle_count = count; + msg.flags = 0; + return nacl::SendDatagram(channel, &msg, flags); +} + +int NaclReceiveData(nacl::HtpHandle channel, + void *data, + size_t size, + int flags) { + nacl::HtpHeader msg; + nacl::IOVec vec[1]; + vec[0].base = data; + vec[0].length = size; + msg.iov = vec; + msg.iov_length = 1; + msg.handles = NULL; + msg.handle_count = 0; + msg.flags = 0; + int result = nacl::ReceiveDatagram(channel, &msg, flags); + return result; +} + +int NaclReceiveHandles(nacl::HtpHandle channel, + nacl::HtpHandle *handles, + size_t count, + int flags) { + nacl::HtpHeader msg; + msg.iov = NULL; + msg.iov_length = 0; + msg.handles = handles; + msg.handle_count = count; + msg.flags = 0; + return nacl::ReceiveDatagram(channel, &msg, flags); +} + +struct RPCMessageHeader { + int message_id; + size_t size; + size_t handle_count; +}; + +RPCImplInterface::ReturnValue IMCSender::SendCall( + int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count) { + // Send 3 messages: first contains message id, and data size, second + // contains data and third handles. + // The reason for that is to have the size first so that we can allocate the + // data buffer on the receiving side. + RPCMessageHeader msg = {message_id, size, handle_count}; + int result = NaclSendData(handle_, &msg, sizeof(msg), 0); + DCHECK_NE(-1, result); + if (size > 0) { + result = NaclSendData(handle_, data, size, 0); + DCHECK_NE(-1, result); + } + if (handle_count > 0) { + result = NaclSendHandles(handle_, handles, handle_count, 0); + DCHECK_NE(-1, result); + } + + RPCImplInterface::ReturnValue ret; + result = NaclReceiveData(handle_, &ret, sizeof(ret), 0); + DCHECK_EQ(sizeof(ret), result); + return ret; +} + +bool IMCMessageProcessor::GetMessageIDSize(bool wait) { + if (has_message_) return true; + RPCMessageHeader msg = {0}; + int result = NaclReceiveData(handle_, &msg, sizeof(msg), + wait ? 0 : nacl::kDontWait); + if (result != sizeof(msg)) { + if (result >=0 || wait || !nacl::WouldBlock()) return false; + has_message_ = false; + } else { + incoming_message_id_ = msg.message_id; + incoming_message_size_ = msg.size; + incoming_message_handles_ = msg.handle_count; + has_message_ = true; + } + return true; +} + +bool IMCMessageProcessor::ProcessMessage() { + if (!GetMessageIDSize(true)) return false; + if (incoming_message_size_ > 0) { + if (incoming_message_size_ > data_size_) { + data_size_ = incoming_message_size_; + data_.reset(new char[incoming_message_size_]); + } + int result = NaclReceiveData(handle_, data_.get(), incoming_message_size_, + 0); + if (result < 0) return false; + } + if (incoming_message_handles_ > 0) { + if (incoming_message_handles_ > handle_count_) { + handle_count_ = incoming_message_handles_; + handles_.reset(new nacl::HtpHandle[incoming_message_handles_]); + } + int result = NaclReceiveHandles(handle_, handles_.get(), + incoming_message_handles_, 0); + if (result < 0) return false; + } + has_message_ = false; + RPCImplInterface::ReturnValue retval = 0; + bool continue_processing = true; + if (incoming_message_id_ == POISONED_MESSAGE_ID) { + continue_processing = false; + } else { + retval = impl_->DoCall(incoming_message_id_, data_.get(), + incoming_message_size_, handles_.get(), + incoming_message_handles_); + // Note: the handles that got received are a "copy" of the original handle, + // so they need to be closed eventually. It's hard to impose an + // "ownership" policy onto the RPCImplInterface, because it makes the API + // very clunky. Currently, we only pass handles across for + // RegisterSharedMemory, and so we can safely close the handle immediately + // (the memory will stay mapped). + // TODO: Fix this. Possibly using a global registration mechanism + // and ref-counting would make it work nicely. + for (unsigned int i = 0; i < incoming_message_handles_; ++i) { + nacl::Close(handles_[i]); + } + } + + int result = NaclSendData(handle_, &retval, sizeof(retval), 0); + if (result < 0) return false; + return continue_processing; +} + +bool IMCMessageProcessor::HasMessage() { + GetMessageIDSize(false); + return has_message_; +} + +RPCSendInterface *MakeSendInterface(RPCSocketHandle handle) { + return new IMCSender(handle); +} + +RPCShmHandle CreateShm(size_t size) { + size = (size + nacl::kMapPageSize - 1) & ~(nacl::kMapPageSize - 1); + nacl::Handle nacl_handle = nacl::CreateMemoryObject(size); + return nacl_handle == nacl::kInvalidHandle ? kRPCInvalidHandle : + nacl::CreateShmDesc(nacl_handle, size); +} + +void DestroyShm(RPCShmHandle handle) { + nacl::Close(handle); +} + +void *MapShm(RPCShmHandle handle, size_t size) { + size = (size + nacl::kMapPageSize - 1) & ~(nacl::kMapPageSize - 1); + void *address = nacl::Map(NULL, size, nacl::kProtRead | nacl::kProtWrite, + nacl::kMapShared, handle, 0); + return address == nacl::kMapFailed ? NULL : address; +} + +void UnmapShm(void *address, size_t size) { + size = (size + nacl::kMapPageSize - 1) & ~(nacl::kMapPageSize - 1); + nacl::Unmap(address, size); +} + +} // namespace command_buffer +} // namespace o3d diff --git a/o3d/command_buffer/common/cross/rpc_imc.h b/o3d/command_buffer/common/cross/rpc_imc.h new file mode 100644 index 0000000..5d2624f --- /dev/null +++ b/o3d/command_buffer/common/cross/rpc_imc.h @@ -0,0 +1,109 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_IMC_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_IMC_H_ + +#include "native_client/intermodule_comm/nacl_imc.h" +#include "base/scoped_ptr.h" +#include "command_buffer/common/cross/rpc.h" + +namespace o3d { +namespace command_buffer { + +class IMCSender : public RPCSendInterface { + public: + explicit IMCSender(nacl::HtpHandle handle) : handle_(handle) {} + virtual ~IMCSender() {} + // Sends a call to the server thread. This call will be dispatched by the + // server thread to the RPC implementation. This call will block until the + // call is processed and the return value is sent back. + // Parameters: + // message_id: the RPC message ID. + // data: the RPC message payload. + // size: the size of the data. + // handles: an array of RPC handles to transmit + // handle_count: the number of RPC handles in the array + // Returns: + // the return value of the RPC call. + virtual RPCImplInterface::ReturnValue SendCall(int message_id, + const void * data, + size_t size, + RPCHandle const *handles, + size_t handle_count); + private: + nacl::HtpHandle handle_; +}; + +class IMCMessageProcessor : public RPCProcessInterface { + public: + IMCMessageProcessor(nacl::HtpHandle handle, RPCImplInterface *impl) + : handle_(handle), + impl_(impl), + has_message_(false), + incoming_message_id_(0), + incoming_message_size_(0), + incoming_message_handles_(0), + data_size_(0), + handle_count_(0) {} + virtual ~IMCMessageProcessor() {} + // Processes one message, blocking if necessary until a message is available + // or the server is killed. This will dispatch the received message to the + // RPC implementation, and send back a response message with the return + // value to the client. + // Returns: + // false if the server was killed. + virtual bool ProcessMessage(); + + // Checks whether a message is available for processing - allowing to test if + // ProcessMessage will block. + // Returns: + // true if a message is available. + virtual bool HasMessage(); + private: + bool GetMessageIDSize(bool wait); + nacl::HtpHandle handle_; + RPCImplInterface *impl_; + bool has_message_; + int incoming_message_id_; + size_t incoming_message_size_; + size_t incoming_message_handles_; + size_t data_size_; + scoped_array data_; + size_t handle_count_; + scoped_array handles_; +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_RPC_IMC_H_ diff --git a/o3d/command_buffer/common/cross/types.h b/o3d/command_buffer/common/cross/types.h new file mode 100644 index 0000000..add362f --- /dev/null +++ b/o3d/command_buffer/common/cross/types.h @@ -0,0 +1,61 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file contains cross-platform basic type definitions + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_TYPES_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_TYPES_H_ + +#if !defined(COMPILER_MSVC) +#include +#endif +#include + +namespace o3d { +namespace command_buffer { +#if defined(COMPILER_MSVC) +typedef short Int16; +typedef unsigned short Uint16; +typedef int Int32; +typedef unsigned int Uint32; +#else +typedef int16_t Int16; +typedef uint16_t Uint16; +typedef int32_t Int32; +typedef uint32_t Uint32; +#endif + +typedef std::string String; +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_TYPES_H_ -- cgit v1.1