1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 15 #ifndef D3D8_Direct3DResource8_hpp 16 #define D3D8_Direct3DResource8_hpp 17 18 #include "Unknown.hpp" 19 20 #include <d3d8.h> 21 22 #include <map> 23 24 namespace D3D8 25 { 26 class Direct3DDevice8; 27 28 class Direct3DResource8 : public IDirect3DResource8, public Unknown 29 { 30 public: 31 Direct3DResource8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned int size); 32 33 ~Direct3DResource8() override; 34 35 // IUnknown methods 36 long __stdcall QueryInterface(const IID &iid, void **object) override; 37 unsigned long __stdcall AddRef() override; 38 unsigned long __stdcall Release() override; 39 40 // IDirect3DResource8 methods 41 long __stdcall GetDevice(IDirect3DDevice8 **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; 49 50 // Internal methods 51 static unsigned int getMemoryUsage(); 52 53 protected: 54 // Creation parameters 55 Direct3DDevice8 *const device; 56 const D3DRESOURCETYPE type; 57 const unsigned int size; 58 59 private: 60 unsigned long priority; 61 62 struct PrivateData 63 { 64 PrivateData(); 65 PrivateData(const void *data, int size, bool managed); 66 67 ~PrivateData(); 68 69 PrivateData &operator=(const PrivateData &privateData); 70 71 void *data; 72 unsigned long size; 73 bool managed; // IUnknown interface 74 }; 75 76 struct CompareGUID 77 { operator ()D3D8::Direct3DResource8::CompareGUID78 bool operator()(const GUID& left, const GUID& right) const 79 { 80 return memcmp(&left, &right, sizeof(GUID)) < 0; 81 } 82 }; 83 84 typedef std::map<GUID, PrivateData, CompareGUID> PrivateDataMap; 85 typedef PrivateDataMap::iterator Iterator; 86 PrivateDataMap privateData; 87 88 static unsigned int memoryUsage; 89 }; 90 } 91 92 #endif // D3D8_Direct3DResource8_hpp 93