-------------------------------------------------------------------------------------- Description: Copies region of a readable render target into current window of the image. Arguments: rt - A render target left, top, right, bottom - Rectangle inside render target to be copied offsetX, offsetY - offset in the image to copy render target to Return Value: AL result of operation --------------------
| 155 | // AL result of operation |
| 156 | // -------------------------------------------------------------------------------------- |
| 157 | ALResult Tr2StreamingBitmapSaver::CopyFromRenderTargetRegion( |
| 158 | Tr2RenderTarget* rt, |
| 159 | int left, |
| 160 | int top, |
| 161 | int right, |
| 162 | int bottom, |
| 163 | int offsetX, |
| 164 | int offsetY ) |
| 165 | { |
| 166 | if( !rt || !rt->IsValid() || !m_output || !m_rowsPerBatch ) |
| 167 | { |
| 168 | return E_INVALIDARG; |
| 169 | } |
| 170 | if( rt->GetRenderTarget().GetFormat() != m_format ) |
| 171 | { |
| 172 | return E_INVALIDARG; |
| 173 | } |
| 174 | |
| 175 | left = max( 0, left ); |
| 176 | top = max( 0, top ); |
| 177 | right = min( int( rt->GetRenderTarget().GetWidth() ), right ); |
| 178 | bottom = min( int( rt->GetRenderTarget().GetHeight() ), bottom ); |
| 179 | |
| 180 | if( offsetX < 0 ) |
| 181 | { |
| 182 | left = max( left, -offsetX ); |
| 183 | right = min( right, int( rt->GetRenderTarget().GetWidth() ) + offsetX ); |
| 184 | } |
| 185 | if( offsetY < int( m_currentOffset ) ) |
| 186 | { |
| 187 | top = max( top, int( m_currentOffset ) - offsetY ); |
| 188 | bottom = min( bottom, int( rt->GetRenderTarget().GetHeight() ) - ( int( m_currentOffset ) - offsetY ) ); |
| 189 | } |
| 190 | offsetX += left; |
| 191 | offsetY += top; |
| 192 | offsetY -= m_currentOffset; |
| 193 | |
| 194 | if( left >= right || |
| 195 | top >= bottom || |
| 196 | int( m_width ) < offsetX || |
| 197 | int( m_rowsPerBatch ) < offsetY ) |
| 198 | { |
| 199 | // source rectangle is empty |
| 200 | return S_OK; |
| 201 | } |
| 202 | |
| 203 | unsigned width = min( unsigned( right - left ), m_width - offsetX ); |
| 204 | unsigned height = min( unsigned( bottom - top ), m_rowsPerBatch - offsetY ); |
| 205 | |
| 206 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 207 | const void* data; |
| 208 | unsigned srcPitch; |
| 209 | HRESULT hr; |
| 210 | |
| 211 | if( FAILED( hr = rt->GetRenderTarget().MapForReading( Tr2TextureSubresource( 0 ), data, srcPitch, renderContext ) ) ) |
| 212 | { |
| 213 | CCP_LOGWARN( "Tr2StreamingBitmapSaver::CopyFromRenderTargetRegion: failed to lock renderTarget" ); |
| 214 | return hr; |
nothing calls this directly
no test coverage detected