Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef D3D9_Direct3DResource9_hpp |
| 16 | #define D3D9_Direct3DResource9_hpp |
| 17 | |
| 18 | #include "Unknown.hpp" |
| 19 | |
| 20 | #include <d3d9.h> |
| 21 | |
| 22 | #include <map> |
| 23 | |
| 24 | namespace D3D9 |
| 25 | { |
| 26 | class Direct3DDevice9; |
| 27 | |
| 28 | class Direct3DResource9 : public IDirect3DResource9, public Unknown |
| 29 | { |
| 30 | public: |
| 31 | Direct3DResource9(Direct3DDevice9 *device, D3DRESOURCETYPE type, D3DPOOL pool, unsigned int size); |
| 32 | |
Nicolas Capens | 3b9e1ea | 2017-06-12 12:43:48 -0400 | [diff] [blame] | 33 | ~Direct3DResource9() override; |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 34 | |
| 35 | // IUnknown methods |
Nicolas Capens | 3b9e1ea | 2017-06-12 12:43:48 -0400 | [diff] [blame] | 36 | long __stdcall QueryInterface(const IID &iid, void **object) override; |
| 37 | unsigned long __stdcall AddRef() override; |
| 38 | unsigned long __stdcall Release() override; |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 39 | |
| 40 | // IDirect3DResource9 methods |
Nicolas Capens | 3b9e1ea | 2017-06-12 12:43:48 -0400 | [diff] [blame] | 41 | long __stdcall GetDevice(IDirect3DDevice9 **device) override; |
| 42 | long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override; |
| 43 | long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override; |
| 44 | long __stdcall FreePrivateData(const GUID &guid) override; |
| 45 | unsigned long __stdcall SetPriority(unsigned long newPriority) override; |
| 46 | unsigned long __stdcall GetPriority() override; |
| 47 | void __stdcall PreLoad() override; |
| 48 | D3DRESOURCETYPE __stdcall GetType() override; |
Nicolas Capens | ee16f0d | 2015-07-16 17:40:10 -0400 | [diff] [blame] | 49 | |
| 50 | // Internal methods |
| 51 | static unsigned int getMemoryUsage(); |
| 52 | D3DPOOL getPool() const; |
| 53 | |
| 54 | protected: |
| 55 | // Creation parameters |
| 56 | Direct3DDevice9 *const device; |
| 57 | const D3DRESOURCETYPE type; |
| 58 | const D3DPOOL pool; |
| 59 | const unsigned int size; |
| 60 | |
| 61 | private: |
| 62 | unsigned long priority; |
| 63 | |
| 64 | struct PrivateData |
| 65 | { |
| 66 | PrivateData(); |
| 67 | PrivateData(const void *data, int size, bool managed); |
| 68 | |
| 69 | ~PrivateData(); |
| 70 | |
| 71 | PrivateData &operator=(const PrivateData &privateData); |
| 72 | |
| 73 | void *data; |
| 74 | unsigned long size; |
| 75 | bool managed; // IUnknown interface |
| 76 | }; |
| 77 | |
| 78 | struct CompareGUID |
| 79 | { |
| 80 | bool operator()(const GUID& left, const GUID& right) const |
| 81 | { |
| 82 | return memcmp(&left, &right, sizeof(GUID)) < 0; |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | typedef std::map<GUID, PrivateData, CompareGUID> PrivateDataMap; |
| 87 | typedef PrivateDataMap::iterator Iterator; |
| 88 | PrivateDataMap privateData; |
| 89 | |
| 90 | static unsigned int memoryUsage; |
| 91 | }; |
| 92 | } |
| 93 | |
| 94 | #endif // D3D9_Direct3DResource9_hpp |