1 /* 2 * Copyright (c) 2017, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 //! 24 //! \file mock_device.h 25 //! \brief Encapsulation of CmDevice for mock run. 26 //! 27 28 #ifndef MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMMOCKDEVICE_H_ 29 #define MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMMOCKDEVICE_H_ 30 31 #include "va/va.h" 32 #include "cm_rt_umd.h" 33 #include "../driver_loader.h" 34 35 namespace CMRT_UMD 36 { 37 typedef int32_t (*ReleaseSurfaceCallback)(void *va_display, 38 void *surface); 39 40 typedef VAStatus (*vaDestroySurfacesFunc)(VADriverContextP ctx, 41 VASurfaceID *surface_list, 42 int num_surfaces); 43 44 int32_t ReleaseVaSurface(void *va_display, void *surface); 45 46 struct CreateDeviceParam 47 { CreateDeviceParamCreateDeviceParam48 CreateDeviceParam(): create_option(CM_DEVICE_CONFIG_MOCK_RUNTIME_ENABLE), 49 release_surface_func(nullptr), 50 device_in_umd(nullptr), 51 version(0), 52 enable_driver_store(0), 53 return_value(0) {} 54 55 uint32_t create_option; 56 ReleaseSurfaceCallback release_surface_func; 57 void *device_in_umd; 58 uint32_t version; 59 uint32_t enable_driver_store; 60 int32_t return_value; 61 };//===================== 62 63 struct DestroyDeviceParam 64 { DestroyDeviceParamDestroyDeviceParam65 DestroyDeviceParam(): device_in_umd(nullptr), 66 return_value(0) {} 67 68 void *device_in_umd; 69 int32_t return_value; 70 };//====================== 71 72 //! Encapsulation of CmDevice created from mock device context. 73 //! Creation is put into contructor and destroy is put into destructor to avoid 74 //! duplications in upcoming cases. 75 class MockDevice 76 { 77 public: 78 static vaDestroySurfacesFunc vaDestroySurfaces; 79 MockDevice()80 MockDevice(): vaCmExtSendReqMsg(nullptr), 81 m_cmDevice(nullptr) 82 { 83 MOS_ZeroMemory(&vaCmExtSendReqMsg, sizeof(vaCmExtSendReqMsg)); 84 MOS_ZeroMemory(&m_vaDisplay, sizeof(m_vaDisplay)); 85 } 86 ~MockDevice()87 ~MockDevice() { Release(); } 88 89 bool Create(DriverDllLoader *driver_loader, uint32_t additinal_options); 90 Create(DriverDllLoader * driver_loader)91 bool Create(DriverDllLoader *driver_loader) 92 { return Create(driver_loader, 0); } 93 94 bool Release(); 95 96 CmDevice* operator->() { return m_cmDevice; } 97 98 CmDevice* CreateNewDevice(uint32_t additional_options); 99 CreateNewDevice()100 CmDevice* CreateNewDevice() { return CreateNewDevice(0); } 101 102 int32_t ReleaseNewDevice(CmDevice *device); 103 104 int32_t CheckAvaliableStream(); 105 106 private: 107 template<class InputData> 108 int32_t SendRequestMessage(InputData *input, uint32_t function_id); 109 110 VADisplayContext m_vaDisplay; 111 CmExtSendReqMsgFunc vaCmExtSendReqMsg; 112 CmDevice *m_cmDevice; 113 }; 114 }; // namespace 115 116 #endif // #ifndef MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMMOCKDEVICE_H_ 117