xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_dsh.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018-2019, 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 //! \file      cm_dsh.cpp
24 //! \brief     Contains Class CmDSH  definitions
25 //!
26 
27 #include "cm_dsh.h"
28 #include "cm_media_state.h"
29 #include "heap_manager.h"
30 
CmDSH(CM_HAL_STATE * cmhal)31 CmDSH::CmDSH(CM_HAL_STATE* cmhal) :
32     m_heapMgr(nullptr),
33     m_cmhal(cmhal)
34 {
35 }
36 
~CmDSH()37 CmDSH::~CmDSH()
38 {
39     MOS_Delete(m_heapMgr);
40 }
41 
Initialize(FrameTrackerProducer * trackerProducer)42 MOS_STATUS CmDSH::Initialize(FrameTrackerProducer *trackerProducer)
43 {
44     m_heapMgr = MOS_New(HeapManager);
45 
46     CM_CHK_NULL_RETURN_MOSERROR(m_heapMgr);
47     CM_CHK_MOSSTATUS_RETURN(m_heapMgr->RegisterOsInterface(m_cmhal->osInterface));
48 
49     m_heapMgr->SetDefaultBehavior(HeapManager::Behavior::destructiveExtend);
50     CM_CHK_MOSSTATUS_RETURN(m_heapMgr->SetInitialHeapSize(m_initSize));
51     CM_CHK_MOSSTATUS_RETURN(m_heapMgr->SetExtendHeapSize(m_stepSize));
52     CM_CHK_MOSSTATUS_RETURN(m_heapMgr->RegisterTrackerProducer(trackerProducer));
53     // lock the heap in the beginning, so cpu doesn't need to wait gpu finishing occupying it to lock it again
54     CM_CHK_MOSSTATUS_RETURN(m_heapMgr->LockHeapsOnAllocate());
55 
56     return MOS_STATUS_SUCCESS;
57 }
58 
CreateMediaState()59 CmMediaState* CmDSH::CreateMediaState()
60 {
61     CmMediaState *mediaState = MOS_New(CmMediaState, m_cmhal);
62     if (mediaState == nullptr)
63     {
64         return nullptr;
65     }
66     mediaState->Initialize(m_heapMgr);
67 
68     return mediaState;
69 }
70 
DestroyMediaState(CmMediaState * mediaState)71 void CmDSH::DestroyMediaState(CmMediaState *mediaState)
72 {
73     MOS_Delete(mediaState);
74 }
75 
76