diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-26 01:09:48 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-26 01:09:48 +0000 |
commit | 5b3a670dc03ac0233f8bdeb1e575c18fe3980082 (patch) | |
tree | 7f663344ee5d1520b75473b1f682fa90bf92c593 /o3d | |
parent | 9f8634d2e7060f157ef9f1050edd8239e68d6bbd (diff) | |
download | chromium_src-5b3a670dc03ac0233f8bdeb1e575c18fe3980082.zip chromium_src-5b3a670dc03ac0233f8bdeb1e575c18fe3980082.tar.gz chromium_src-5b3a670dc03ac0233f8bdeb1e575c18fe3980082.tar.bz2 |
Fixed Mac gyp build. Switched to using Chrome hash_tables.h, changed
how hash functions are specified for certain key types, and deleted
our std_hash.h. Fixed forward reference bug in cmd_buffer_format.h.
Built and tested on Windows and Mac.
Remaining workarounds: enabled C++ exceptions due to use of Objective
C try/catch in plugin_mac.mm; disabled warnings as errors due to
signed / unsigned issues in command buffer code, which will probably
need to be fixed by changing typedefs and argument types.
Review URL: http://codereview.chromium.org/249013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27311 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/base/cross/std_hash.h | 165 | ||||
-rw-r--r-- | o3d/build/common.gypi | 4 | ||||
-rw-r--r-- | o3d/command_buffer/command_buffer.gyp | 13 | ||||
-rw-r--r-- | o3d/command_buffer/common/cross/cmd_buffer_format.h | 12 | ||||
-rw-r--r-- | o3d/plugin/cross/np_v8_bridge.h | 35 | ||||
-rw-r--r-- | o3d/plugin/cross/o3d_glue.h | 43 | ||||
-rw-r--r-- | o3d/tests/tests.gyp | 11 |
7 files changed, 99 insertions, 184 deletions
diff --git a/o3d/base/cross/std_hash.h b/o3d/base/cross/std_hash.h deleted file mode 100644 index ceac439..0000000 --- a/o3d/base/cross/std_hash.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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 declares STL hash map classes in a cross-compiler way, providing a -// GCC-compatible (not MSVC) interface. - -#ifndef O3D_BASE_CROSS_STD_HASH_H_ -#define O3D_BASE_CROSS_STD_HASH_H_ - -#include <build/build_config.h> - -#if defined(COMPILER_MSVC) -#include <hash_map> -#include <hash_set> -namespace o3d { -namespace base { - -struct PortableHashBase { - // These two public members are required by msvc. 4 and 8 are the - // default values. - static const size_t bucket_size = 4; - static const size_t min_buckets = 8; -}; - -template <typename Key> -struct hash; - -// These are missing from MSVC. -template<> struct hash<int> { - size_t operator()(int n) const { - return static_cast<size_t>(n); - } -}; - -template<> struct hash<unsigned int> { - size_t operator()(unsigned int n) const { - return static_cast<size_t>(n); - } -}; - -template<typename T> struct hash<T*> { - size_t operator()(T* t) const { - return reinterpret_cast<size_t>(t); - } -}; - -// If the 3rd template parameter of the GNU interface (KeyEqual) is -// omitted, then we know that it's using the == operator, so we can -// safely use the < operator. -// -// If the third parameter is specified, then we get a compile time -// error, and we know we have to go back and add some #ifdefs. -template <typename Key, typename Hash> -struct HashAndLessOperator : PortableHashBase { - bool operator()(const Key& a, const Key& b) const { - return a < b; - } - size_t operator()(const Key& key) const { - return hasher_(key); - } - Hash hasher_; -}; - -template <class Key, class Hash = hash<Key> > -class hash_set : public stdext::hash_set<Key, HashAndLessOperator<Key, Hash> > { - public: - hash_set() {} - explicit hash_set(int buckets) {} - typedef std::equal_to<Key> key_equal; - size_type bucket_count() const { - return size() / bucket_size; - } -}; - -template <class Key, class Val, class Hash = hash<Key> > -class hash_map : public stdext::hash_map< - Key, Val, HashAndLessOperator<Key, Hash> > { - public: - hash_map() {} - explicit hash_map(int buckets) {} - typedef std::equal_to<Key> key_equal; - size_type bucket_count() const { - return size() / bucket_size; - } -}; - -template <class Key, class Hash = hash<Key> > -class hash_multiset : public stdext::hash_multiset< - Key, HashAndLessOperator<Key, Hash> > { - public: - hash_multiset() {} - explicit hash_multiset(int buckets) {} - typedef std::equal_to<Key> key_equal; - size_type bucket_count() const { - return size() / bucket_size; - } -}; - -template <class Key, class Val, class Hash = hash<Key> > -class hash_multimap : public stdext::hash_multimap< - Key, Val, HashAndLessOperator<Key, Hash> > { - public: - hash_multimap() {} - explicit hash_multimap(int buckets) {} - typedef std::equal_to<Key> key_equal; - size_type bucket_count() const { - return size() / bucket_size; - } -}; - -} // namespace base -} // namespace o3d -#elif defined COMPILER_GCC -#include <ext/hash_map> -#include <ext/hash_set> -#include <tr1/functional> -namespace __gnu_cxx { -template <class T> struct hash<T*> { - size_t operator() (const T* x) const { - return hash<size_t>()(reinterpret_cast<size_t>(x)); - } -}; -} // namespace __gnu_cxx - -namespace o3d { -namespace base { -using __gnu_cxx::hash_map; -using __gnu_cxx::hash_multimap; -using __gnu_cxx::hash_set; -using __gnu_cxx::hash_multiset; -using __gnu_cxx::hash; -} // namespace base -} // namespace o3d -#endif // COMPILER_MSVC - -#endif // O3D_BASE_CROSS_STD_HASH_H_ diff --git a/o3d/build/common.gypi b/o3d/build/common.gypi index b123880..4faaa22 100644 --- a/o3d/build/common.gypi +++ b/o3d/build/common.gypi @@ -34,6 +34,10 @@ ['OS=="mac"', { 'xcode_settings': { 'MACOSX_DEPLOYMENT_TARGET': '10.4', + # TODO(maf): figure out proper fix for the following. + # There is only one place in plugin_mac.mm which attempts + # to use ObjC exception handling. + 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', }, }], ], diff --git a/o3d/command_buffer/command_buffer.gyp b/o3d/command_buffer/command_buffer.gyp index 9d508cc..7ded5aa 100644 --- a/o3d/command_buffer/command_buffer.gyp +++ b/o3d/command_buffer/command_buffer.gyp @@ -16,6 +16,17 @@ '../../<(gtestdir)', '../../<(nacldir)', ], + # TODO(rlp): remove this after fixing signed / unsigned issues in + # command buffer code and tests. + 'target_conditions': [ + ['OS == "mac"', + { + 'xcode_settings': { + 'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO' + }, + }, + ], + ], }, 'targets': [ { @@ -126,7 +137,7 @@ ['OS == "mac"', { 'xcode_settings': { - 'GCC_PREFIX_HEADER': 'command_buffer/service/cross/precompile.h', + 'GCC_PREFIX_HEADER': 'service/cross/precompile.h', }, }, ], diff --git a/o3d/command_buffer/common/cross/cmd_buffer_format.h b/o3d/command_buffer/common/cross/cmd_buffer_format.h index 63bcc8be..96e0578 100644 --- a/o3d/command_buffer/common/cross/cmd_buffer_format.h +++ b/o3d/command_buffer/common/cross/cmd_buffer_format.h @@ -67,6 +67,13 @@ namespace o3d { namespace command_buffer { +namespace cmd { + enum ArgFlags { + kFixed = 0x0, + kAtLeastN = 0x1, + }; +} // namespace cmd + // Computes the number of command buffer entries needed for a certain size. In // other words it rounds up to a multiple of entries. inline uint32 ComputeNumEntries(size_t size_in_bytes) { @@ -457,11 +464,6 @@ void* NextImmediateCmdAddress(void* cmd, uint32 size_of_data_in_bytes) { RoundSizeToMultipleOfEntries(size_of_data_in_bytes); } -enum ArgFlags { - kFixed = 0x0, - kAtLeastN = 0x1, -}; - struct SharedMemory { void Init(uint32 _id, uint32 _offset) { id = _id; diff --git a/o3d/plugin/cross/np_v8_bridge.h b/o3d/plugin/cross/np_v8_bridge.h index 150a3c2..a43d1d6 100644 --- a/o3d/plugin/cross/np_v8_bridge.h +++ b/o3d/plugin/cross/np_v8_bridge.h @@ -39,7 +39,7 @@ #include <npruntime.h> #include <map> -#include "base/cross/std_hash.h" +#include "base/hash_tables.h" #include "core/cross/error_status.h" #include "core/cross/service_dependency.h" #include "core/cross/types.h" @@ -179,15 +179,33 @@ class NPObjectPtr { T* object_; }; +} // namespace o3d + // Hashes an NPObject so it can be used in a hash_map. -template <typename T> -class NPObjectPtrHash { - public: - size_t operator() (const NPObjectPtr<T>& ptr) const { - return o3d::base::hash<size_t>()(reinterpret_cast<size_t>(ptr.Get())); +#if defined(COMPILER_GCC) +namespace __gnu_cxx { + +template<class T> +struct hash<o3d::NPObjectPtr<T> > { + std::size_t operator()(const o3d::NPObjectPtr<T>& ptr) const { + return hash<size_t>()(reinterpret_cast<size_t>(ptr.Get())); } }; +} // namespace __gnu_cxx +#elif defined(COMPILER_MSVC) +namespace stdext { + +template<class T> +inline size_t hash_value(const o3d::NPObjectPtr<T>& ptr) { + return hash_value(reinterpret_cast<size_t>(ptr.Get())); +} + +} // namespace stdext +#endif // COMPILER + +namespace o3d { + // A V8 handle that automatically disposes itself when it is destroyed. There // must be only one of these for each persistent handle, otherwise they might // be disposed more than once. @@ -369,9 +387,8 @@ class NPV8Bridge { NPObjectPtr<NPObject> GetNPConstructFunction(int arity); - typedef o3d::base::hash_map<NPObjectPtr<NPObject>, - AutoV8Persistent<v8::Object>, - NPObjectPtrHash<NPObject> > NPV8ObjectMap; + typedef ::base::hash_map<NPObjectPtr<NPObject>, + AutoV8Persistent<v8::Object> > NPV8ObjectMap; typedef std::map<int, NPObjectPtr<NPObject> > NPConstructFunctionMap; diff --git a/o3d/plugin/cross/o3d_glue.h b/o3d/plugin/cross/o3d_glue.h index 12fb572..bd02228 100644 --- a/o3d/plugin/cross/o3d_glue.h +++ b/o3d/plugin/cross/o3d_glue.h @@ -52,7 +52,7 @@ #include <string> #include <vector> #include "base/scoped_ptr.h" -#include "base/cross/std_hash.h" +#include "base/hash_tables.h" #include "core/cross/display_mode.h" #include "core/cross/display_window.h" #include "core/cross/object_base.h" @@ -75,6 +75,41 @@ class Client; class Renderer; } +// Hashes the NPClass and ObjectBase types so they can be used in a hash_map. +#if defined(COMPILER_GCC) +namespace __gnu_cxx { + +template<> +struct hash<NPClass*> { + std::size_t operator()(NPClass* const& ptr) const { + return hash<size_t>()(reinterpret_cast<size_t>(ptr)); + } +}; + +template<> +struct hash<const o3d::ObjectBase::Class*> { + std::size_t operator()(const o3d::ObjectBase::Class* const& ptr) const { + return hash<size_t>()(reinterpret_cast<size_t>(ptr)); + } +}; + +} // namespace __gnu_cxx +#elif defined(COMPILER_MSVC) +namespace stdext { + +template<> +inline size_t hash_value(NPClass* const& ptr) { + return hash_value(reinterpret_cast<size_t>(ptr)); +} + +template<> +inline size_t hash_value(const o3d::ObjectBase::Class* const& ptr) { + return hash_value(reinterpret_cast<size_t>(ptr)); +} + +} // namespace stdext +#endif // COMPILER + namespace glue { class StreamManager; @@ -119,10 +154,10 @@ void InitializeGlue(NPP npp); typedef glue::namespace_o3d::class_Client::NPAPIObject ClientNPObject; class PluginObject: public NPObject { - typedef o3d::base::hash_map<Id, NPAPIObject *> ClientObjectMap; - typedef o3d::base::hash_map<const ObjectBase::Class *, NPClass *> + typedef ::base::hash_map<Id, NPAPIObject *> ClientObjectMap; + typedef ::base::hash_map<const ObjectBase::Class *, NPClass *> ClientToNPClassMap; - typedef o3d::base::hash_map<NPClass *, const ObjectBase::Class *> + typedef ::base::hash_map<NPClass *, const ObjectBase::Class *> NPToClientClassMap; NPP npp_; diff --git a/o3d/tests/tests.gyp b/o3d/tests/tests.gyp index a4cc2a9..a2d25b3 100644 --- a/o3d/tests/tests.gyp +++ b/o3d/tests/tests.gyp @@ -14,6 +14,17 @@ '..', '../..', ], + # TODO(rlp): remove this after fixing signed / unsigned issues in + # command buffer code and tests. + 'target_conditions': [ + ['OS == "mac"', + { + 'xcode_settings': { + 'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO' + }, + }, + ], + ], }, 'targets': [ { |