1 | /* |
---|---|
2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
3 | * |
4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
5 | * and proprietary rights in and to this software, related documentation |
6 | * and any modifications thereto. Any use, reproduction, disclosure or |
7 | * distribution of this software and related documentation without an express |
8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
9 | */ |
10 | |
11 | #ifndef PX_PROFILE_CONTEXT_PROVIDER_H |
12 | #define PX_PROFILE_CONTEXT_PROVIDER_H |
13 | |
14 | #include "physxprofilesdk/PxProfileBase.h" |
15 | |
16 | namespace physx { |
17 | |
18 | struct PxProfileEventExecutionContext |
19 | { |
20 | PxU32 mThreadId; |
21 | PxU8 mCpuId; |
22 | PxU8 mThreadPriority; |
23 | |
24 | PxProfileEventExecutionContext( PxU32 inThreadId = 0, PxU8 inThreadPriority = 2 /*eThreadPriorityNormal*/, PxU8 inCpuId = 0 ) |
25 | : mThreadId( inThreadId ) |
26 | , mCpuId( inCpuId ) |
27 | , mThreadPriority( inThreadPriority ) |
28 | { |
29 | } |
30 | |
31 | bool operator==( const PxProfileEventExecutionContext& inOther ) const |
32 | { |
33 | return mThreadId == inOther.mThreadId |
34 | && mCpuId == inOther.mCpuId |
35 | && mThreadPriority == inOther.mThreadPriority; |
36 | } |
37 | }; |
38 | |
39 | //Provides the context in which the event is happening. |
40 | class PxProfileContextProvider |
41 | { |
42 | protected: |
43 | virtual ~PxProfileContextProvider(){} |
44 | public: |
45 | virtual PxProfileEventExecutionContext getExecutionContext() = 0; |
46 | virtual PxU32 getThreadId() = 0; |
47 | }; |
48 | //Provides pre-packaged context. |
49 | struct PxProfileTrivialContextProvider |
50 | { |
51 | PxProfileEventExecutionContext mContext; |
52 | PxProfileTrivialContextProvider( PxProfileEventExecutionContext inContext = PxProfileEventExecutionContext() ) |
53 | : mContext( inContext ) |
54 | { |
55 | } |
56 | PxProfileEventExecutionContext getExecutionContext() { return mContext; } |
57 | PxU32 getThreadId() { return mContext.mThreadId; } |
58 | }; |
59 | |
60 | //Forwards the get context calls to another (perhaps shared) context. |
61 | template<typename TProviderType> |
62 | struct PxProfileContextProviderForward |
63 | { |
64 | TProviderType* mProvider; |
65 | PxProfileContextProviderForward( TProviderType* inProvider ) : mProvider( inProvider ) {} |
66 | PxProfileEventExecutionContext getExecutionContext() { return mProvider->getExecutionContext(); } |
67 | PxU32 getThreadId() { return mProvider->getThreadId(); } |
68 | }; |
69 | template<typename TProviderType> |
70 | struct PxProfileContextProviderImpl : public PxProfileContextProvider |
71 | { |
72 | PxProfileContextProviderForward<TProviderType> mContext; |
73 | PxProfileContextProviderImpl( TProviderType* inP ) : mContext( inP ) {} |
74 | PxProfileEventExecutionContext getExecutionContext() { return mContext.getExecutionContext(); } |
75 | PxU32 getThreadId() { return mContext.getThreadId(); } |
76 | }; |
77 | } |
78 | |
79 | #endif // PX_PROFILE_CONTEXT_PROVIDER_H |
80 |