| 1 | /* |
| 2 | * Copyright (c) 2007-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 | //! \file cm_sampler8x8_state_rt.cpp |
| 24 | //! \brief Contains CmSampler8x8State_RT implementations. |
| 25 | //! |
| 26 | |
| 27 | #include "cm_sampler8x8_state_rt.h" |
| 28 | |
| 29 | #include "cm_device.h" |
| 30 | #include "cm_debug.h" |
| 31 | #include "cm_mem.h" |
| 32 | |
| 33 | namespace CMRT_UMD |
| 34 | { |
| 35 | //*----------------------------------------------------------------------------- |
| 36 | //| Purpose: Get the Index of CmSampler8x8State_RT |
| 37 | //| Returns: Result of the operation. |
| 38 | //*----------------------------------------------------------------------------- |
| 39 | int32_t CmSampler8x8State_RT::GetIndex( SamplerIndex* & index ) |
| 40 | { |
| 41 | index=m_index; |
| 42 | return CM_SUCCESS; |
| 43 | } |
| 44 | |
| 45 | //*----------------------------------------------------------------------------- |
| 46 | //| Purpose: Create the CmSampler8x8State_RT |
| 47 | //| Returns: Result of the operation. |
| 48 | //*----------------------------------------------------------------------------- |
| 49 | int32_t CmSampler8x8State_RT::Create( const CM_SAMPLER_8X8_DESCR& sampleState, uint32_t index, CmSampler8x8State_RT* & sampler ) |
| 50 | { |
| 51 | int32_t result = CM_SUCCESS; |
| 52 | sampler = new (std::nothrow) CmSampler8x8State_RT( sampleState ); |
| 53 | if( sampler ) |
| 54 | { |
| 55 | result = sampler->Initialize( index ); |
| 56 | if( result != CM_SUCCESS ) |
| 57 | { |
| 58 | CmSampler8x8State_RT::Destroy( sampler ); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | CM_ASSERTMESSAGE("Error: Failed to create CmSampler8x8State due to out of system memory.") |
| 65 | result = CM_OUT_OF_HOST_MEMORY; |
| 66 | } |
| 67 | |
| 68 | return result; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | //*----------------------------------------------------------------------------- |
| 73 | //| Purpose: Destroy CmSampler8x8State_RT |
| 74 | //| Returns: CM_SUCCESS. |
| 75 | //*----------------------------------------------------------------------------- |
| 76 | int32_t CmSampler8x8State_RT::Destroy( CmSampler8x8State_RT* &sampler ) |
| 77 | { |
| 78 | CmSafeDelete( sampler ); |
| 79 | return CM_SUCCESS; |
| 80 | |
| 81 | } |
| 82 | |
| 83 | //*----------------------------------------------------------------------------- |
| 84 | //| Purpose: Constructor of CmSampler8x8State_RT |
| 85 | //| Returns: Result of the operation. |
| 86 | //*----------------------------------------------------------------------------- |
| 87 | CmSampler8x8State_RT::CmSampler8x8State_RT( const CM_SAMPLER_8X8_DESCR& sampleState ): |
| 88 | m_index( nullptr ) |
| 89 | { |
| 90 | CmSafeMemSet( & m_avsState, 0, sizeof(CM_AVS_STATE_MSG)); |
| 91 | CmSafeMemSet( & m_convolveState, 0, sizeof(CM_CONVOLVE_STATE_MSG)); |
| 92 | CmSafeMemSet( & m_miscState, 0, sizeof(CM_MISC_STATE_MSG)); |
| 93 | |
| 94 | if(sampleState.stateType == CM_SAMPLER8X8_AVS) |
| 95 | { |
| 96 | CmSafeMemCopy( &this->m_avsState, sampleState.avs, sizeof(CM_AVS_STATE_MSG) ); |
| 97 | } else if(sampleState.stateType == CM_SAMPLER8X8_CONV) |
| 98 | { |
| 99 | CmSafeMemCopy( &this->m_convolveState, sampleState.conv, sizeof(CM_CONVOLVE_STATE_MSG) ); |
| 100 | } else if(sampleState.stateType == CM_SAMPLER8X8_MISC) |
| 101 | { |
| 102 | CmSafeMemCopy( &this->m_miscState, sampleState.misc, sizeof(CM_MISC_STATE_MSG) ); |
| 103 | } else { |
| 104 | CM_ASSERTMESSAGE("Error: Invalid sampler8x8 state type.") |
| 105 | } |
| 106 | |
| 107 | m_stateType = sampleState.stateType; |
| 108 | } |
| 109 | |
| 110 | //*----------------------------------------------------------------------------- |
| 111 | //| Purpose: Destructor of CmSampler8x8State_RT |
| 112 | //| Returns: Result of the operation. |
| 113 | //*----------------------------------------------------------------------------- |
| 114 | CmSampler8x8State_RT::~CmSampler8x8State_RT( void ) |
| 115 | { |
| 116 | MosSafeDelete(m_index); |
| 117 | } |
| 118 | |
| 119 | //*----------------------------------------------------------------------------- |
| 120 | //| Purpose: Initialize CmSampler8x8State_RT |
| 121 | //| Returns: Result of the operation. |
| 122 | //*----------------------------------------------------------------------------- |
| 123 | int32_t CmSampler8x8State_RT::Initialize( uint32_t index ) |
| 124 | { |
| 125 | int status = CM_FAILURE; |
| 126 | // using CM compiler data structure |
| 127 | m_index = MOS_New(SamplerIndex, index); |
| 128 | if( m_index ) |
| 129 | { |
| 130 | status = CM_SUCCESS; |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | return CM_OUT_OF_HOST_MEMORY; |
| 135 | } |
| 136 | return status; |
| 137 | } |
| 138 | } // namespace |