2013-01-19 02:32:58 +04:00
|
|
|
/* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Routines to set a chunk of memory to a constant.
|
|
|
|
* 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>
|
2013-02-21 14:45:10 +04:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/primitives.h>
|
2013-02-21 14:45:10 +04:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
#include "prim_internal.h"
|
|
|
|
|
|
|
|
/* ========================================================================= */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_set_8u(BYTE val, BYTE* pDst, UINT32 len)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
memset((void*)pDst, (int)val, (size_t)len);
|
2013-01-19 02:32:58 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_zero(void* pDst, size_t len)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
|
|
|
memset(pDst, 0, len);
|
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================================================================= */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_set_32s(INT32 val, INT32* pDst, UINT32 len)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
INT32* dptr = (INT32*)pDst;
|
2013-01-19 02:32:58 +04:00
|
|
|
size_t span, remaining;
|
2016-04-05 18:07:45 +03:00
|
|
|
primitives_t* prims;
|
2013-01-19 02:32:58 +04:00
|
|
|
|
|
|
|
if (len < 256)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
while (len--)
|
|
|
|
*dptr++ = val;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else quadratic growth memcpy algorithm */
|
|
|
|
span = 1;
|
|
|
|
*dptr = val;
|
|
|
|
remaining = len - 1;
|
|
|
|
prims = primitives_get();
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
while (remaining)
|
|
|
|
{
|
|
|
|
size_t thiswidth = span;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (thiswidth > remaining)
|
|
|
|
thiswidth = remaining;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
|
2013-01-19 02:32:58 +04:00
|
|
|
remaining -= thiswidth;
|
|
|
|
span <<= 1;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-06 17:24:51 +03:00
|
|
|
static pstatus_t general_set_32u(UINT32 val, UINT32* pDst, UINT32 len)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32* dptr = (UINT32*)pDst;
|
2013-01-19 02:32:58 +04:00
|
|
|
size_t span, remaining;
|
2016-04-05 18:07:45 +03:00
|
|
|
primitives_t* prims;
|
2013-01-19 02:32:58 +04:00
|
|
|
|
|
|
|
if (len < 256)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
while (len--)
|
|
|
|
*dptr++ = val;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* else quadratic growth memcpy algorithm */
|
|
|
|
span = 1;
|
|
|
|
*dptr = val;
|
|
|
|
remaining = len - 1;
|
|
|
|
prims = primitives_get();
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
while (remaining)
|
|
|
|
{
|
|
|
|
size_t thiswidth = span;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (thiswidth > remaining)
|
|
|
|
thiswidth = remaining;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2);
|
2013-01-19 02:32:58 +04:00
|
|
|
remaining -= thiswidth;
|
|
|
|
span <<= 1;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-06 17:24:51 +03:00
|
|
|
void primitives_init_set(primitives_t* prims)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
|
|
|
/* Start with the default. */
|
2019-11-06 17:24:51 +03:00
|
|
|
prims->set_8u = general_set_8u;
|
2013-01-19 02:32:58 +04:00
|
|
|
prims->set_32s = general_set_32s;
|
|
|
|
prims->set_32u = general_set_32u;
|
|
|
|
prims->zero = general_zero;
|
|
|
|
}
|