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 D3D9_Direct3DSurface9_hpp 16 #define D3D9_Direct3DSurface9_hpp 17 18 #include "Direct3DResource9.hpp" 19 20 #include "Surface.hpp" 21 22 #include <d3d9.h> 23 24 namespace D3D9 25 { 26 class Direct3DBaseTexture9; 27 28 class Direct3DSurface9 : public IDirect3DSurface9, public Direct3DResource9, public sw::Surface 29 { 30 public: 31 Direct3DSurface9(Direct3DDevice9 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, bool lockableOverride, unsigned long usage); 32 33 ~Direct3DSurface9() override; 34 35 // Surface methods 36 void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override; 37 void unlockInternal() override; 38 39 // IUnknown methods 40 long __stdcall QueryInterface(const IID &iid, void **object) override; 41 unsigned long __stdcall AddRef() override; 42 unsigned long __stdcall Release() override; 43 44 // IDirect3DResource9 methods 45 long __stdcall FreePrivateData(const GUID &guid) override; 46 long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override; 47 void __stdcall PreLoad() override; 48 long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override; 49 long __stdcall GetDevice(IDirect3DDevice9 **device) override; 50 unsigned long __stdcall SetPriority(unsigned long newPriority) override; 51 unsigned long __stdcall GetPriority() override; 52 D3DRESOURCETYPE __stdcall GetType() override; 53 54 // IDirect3DSurface9 methods 55 long __stdcall GetDC(HDC *deviceContext) override; 56 long __stdcall ReleaseDC(HDC deviceContext) override; 57 long __stdcall LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long Flags) override; 58 long __stdcall UnlockRect() override; 59 long __stdcall GetContainer(const IID &iid, void **container) override; 60 long __stdcall GetDesc(D3DSURFACE_DESC *desc) override; 61 62 // Internal methods 63 static sw::Format translateFormat(D3DFORMAT format); 64 static int bytes(D3DFORMAT format); 65 66 private: 67 static unsigned int memoryUsage(int width, int height, D3DFORMAT format); 68 69 // Creation parameters 70 Unknown *const container; 71 const int width; 72 const int height; 73 const D3DFORMAT format; 74 const D3DMULTISAMPLE_TYPE multiSample; 75 const unsigned int quality; 76 const D3DPOOL pool; 77 const bool lockable; 78 const unsigned long usage; 79 80 Direct3DBaseTexture9 *parentTexture; 81 }; 82 } 83 84 #endif // D3D9_Direct3DSurface9_hpp 85