2013-01-19 02:32:58 +04:00
|
|
|
/* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Copy operations.
|
|
|
|
* vi:ts=4 sw=4:
|
|
|
|
*
|
|
|
|
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License. You may obtain
|
|
|
|
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-01-19 23:27:34 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/primitives.h>
|
|
|
|
#ifdef WITH_IPP
|
2019-11-06 17:24:51 +03:00
|
|
|
#include <ipps.h>
|
|
|
|
#include <ippi.h>
|
2013-01-19 02:32:58 +04:00
|
|
|
#endif /* WITH_IPP */
|
|
|
|
#include "prim_internal.h"
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static primitives_t* generic = NULL;
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/*static inline BOOL memory_regions_overlap_1d(*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL memory_regions_overlap_1d(const BYTE* p1, const BYTE* p2, size_t bytes)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const ULONG_PTR p1m = (const ULONG_PTR)p1;
|
|
|
|
const ULONG_PTR p2m = (const ULONG_PTR)p2;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
if (p1m <= p2m)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (p1m + bytes > p2m)
|
|
|
|
return TRUE;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (p2m + bytes > p1m)
|
|
|
|
return TRUE;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* else */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/*static inline BOOL memory_regions_overlap_2d( */
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL memory_regions_overlap_2d(const BYTE* p1, int p1Step, int p1Size, const BYTE* p2,
|
|
|
|
int p2Step, int p2Size, int width, int height)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG_PTR p1m = (ULONG_PTR)p1;
|
|
|
|
ULONG_PTR p2m = (ULONG_PTR)p2;
|
2013-01-19 02:32:58 +04:00
|
|
|
|
|
|
|
if (p1m <= p2m)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
ULONG_PTR p1mEnd = p1m + (height - 1) * p1Step + width * p1Size;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (p1mEnd > p2m)
|
|
|
|
return TRUE;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
ULONG_PTR p2mEnd = p2m + (height - 1) * p2Step + width * p2Size;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (p2mEnd > p1m)
|
|
|
|
return TRUE;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* else */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_copy_8u(const BYTE* pSrc, BYTE* pDst, INT32 len)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (memory_regions_overlap_1d(pSrc, pDst, (size_t)len))
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
memmove((void*)pDst, (const void*)pSrc, (size_t)len);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
memcpy((void*)pDst, (const void*)pSrc, (size_t)len);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Copy a block of pixels from one buffer to another.
|
|
|
|
* The addresses are assumed to have been already offset to the upper-left
|
|
|
|
* corners of the source and destination region of interest.
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_copy_8u_AC4r(const BYTE* pSrc, INT32 srcStep, BYTE* pDst, INT32 dstStep,
|
|
|
|
INT32 width, INT32 height)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const BYTE* src = (const BYTE*)pSrc;
|
|
|
|
BYTE* dst = (BYTE*)pDst;
|
2013-01-19 02:32:58 +04:00
|
|
|
int rowbytes = width * sizeof(UINT32);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((width == 0) || (height == 0))
|
|
|
|
return PRIMITIVES_SUCCESS;
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (memory_regions_overlap_2d(pSrc, srcStep, sizeof(UINT32), pDst, dstStep, sizeof(UINT32),
|
|
|
|
width, height))
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
generic->copy(src, dst, rowbytes);
|
2013-01-19 02:32:58 +04:00
|
|
|
src += srcStep;
|
|
|
|
dst += dstStep;
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (--height);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TODO: do it in one operation when the rowdata is adjacent. */
|
2016-04-05 18:07:45 +03:00
|
|
|
do
|
|
|
|
{
|
2013-01-19 02:32:58 +04:00
|
|
|
/* If we find a replacement for memcpy that is consistently
|
|
|
|
* faster, this could be replaced with that.
|
|
|
|
*/
|
|
|
|
memcpy(dst, src, rowbytes);
|
|
|
|
src += srcStep;
|
|
|
|
dst += dstStep;
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (--height);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_IPP
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* This is just ippiCopy_8u_AC4R without the IppiSize structure parameter. */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t ippiCopy_8u_AC4r(const BYTE* pSrc, INT32 srcStep, BYTE* pDst, INT32 dstStep,
|
|
|
|
INT32 width, INT32 height)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
|
|
|
IppiSize roi;
|
2019-11-06 17:24:51 +03:00
|
|
|
roi.width = width;
|
2013-01-19 02:32:58 +04:00
|
|
|
roi.height = height;
|
2019-11-06 17:24:51 +03:00
|
|
|
return (pstatus_t)ippiCopy_8u_AC4R(pSrc, srcStep, pDst, dstStep, roi);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
#endif /* WITH_IPP */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-06 17:24:51 +03:00
|
|
|
void primitives_init_copy(primitives_t* prims)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
|
|
|
/* Start with the default. */
|
|
|
|
prims->copy_8u = general_copy_8u;
|
|
|
|
prims->copy_8u_AC4r = general_copy_8u_AC4r;
|
2016-04-05 18:07:45 +03:00
|
|
|
/* This is just an alias with void* parameters */
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->copy = (__copy_t)(prims->copy_8u);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void primitives_init_copy_opt(primitives_t* prims)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
generic = primitives_get_generic();
|
|
|
|
primitives_init_copy(prims);
|
2013-01-19 02:32:58 +04:00
|
|
|
/* Pick tuned versions if possible. */
|
|
|
|
#ifdef WITH_IPP
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->copy_8u = (__copy_8u_t)ippsCopy_8u;
|
|
|
|
prims->copy_8u_AC4r = (__copy_8u_AC4r_t)ippiCopy_8u_AC4r;
|
2013-01-19 02:32:58 +04:00
|
|
|
#endif
|
|
|
|
/* Performance with an SSE2 version with no prefetch seemed to be
|
2016-04-05 18:07:45 +03:00
|
|
|
* all over the map vs. memcpy.
|
2013-01-19 02:32:58 +04:00
|
|
|
* Sometimes it was significantly faster, sometimes dreadfully slower,
|
|
|
|
* and it seemed to vary a lot depending on block size and processor.
|
|
|
|
* Hence, no SSE version is used here unless once can be written that
|
|
|
|
* is consistently faster than memcpy.
|
|
|
|
*/
|
|
|
|
/* This is just an alias with void* parameters */
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->copy = (__copy_t)(prims->copy_8u);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|