Browse Source

Switch region code to pixman

This is the current upstream so let's make use of it to get the latest
in features and fixes.
tags/v1.10.90
Pierre Ossman 3 years ago
parent
commit
ecb016fe3f

+ 2
- 0
BUILDING.txt View File

@@ -11,6 +11,8 @@ Build Requirements (All Systems)

-- zlib

-- pixman

-- FLTK 1.3.3 or later

-- If building TLS support:

+ 3
- 0
CMakeLists.txt View File

@@ -137,6 +137,9 @@ endif()
# Check for zlib
find_package(ZLIB REQUIRED)

# Check for pixman
find_package(Pixman REQUIRED)

# Check for gettext
option(ENABLE_NLS "Enable translation of program messages" ON)
if(ENABLE_NLS)

+ 40
- 0
cmake/Modules/FindPixman.cmake View File

@@ -0,0 +1,40 @@
# - Find Pixman
# Find the Pixman libraries
#
# This module defines the following variables:
# PIXMAN_FOUND - true if PIXMAN_INCLUDE_DIR & PIXMAN_LIBRARY are found
# PIXMAN_LIBRARIES - Set when PIXMAN_LIBRARY is found
# PIXMAN_INCLUDE_DIRS - Set when PIXMAN_INCLUDE_DIR is found
#
# PIXMAN_INCLUDE_DIR - where to find pixman.h, etc.
# PIXMAN_LIBRARY - the Pixman library
#

#=============================================================================
# Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
#
# 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.
#=============================================================================

find_path(PIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1)

find_library(PIXMAN_LIBRARY NAMES pixman-1)

find_package_handle_standard_args(pixman-1 DEFAULT_MSG PIXMAN_LIBRARY PIXMAN_INCLUDE_DIR)

if(PIXMAN-1_FOUND)
set(PIXMAN_LIBRARIES ${PIXMAN_LIBRARY})
set(PIXMAN_INCLUDE_DIRS ${PIXMAN_INCLUDE_DIR})
endif()

mark_as_advanced(PIXMAN_INCLUDE_DIR PIXMAN_LIBRARY)

+ 1
- 0
cmake/StaticBuild.cmake View File

@@ -20,6 +20,7 @@ if(BUILD_STATIC)

set(JPEG_LIBRARIES "-Wl,-Bstatic -ljpeg -Wl,-Bdynamic")
set(ZLIB_LIBRARIES "-Wl,-Bstatic -lz -Wl,-Bdynamic")
set(PIXMAN_LIBRARY "-Wl,-Bstatic -lpixman-1 -Wl,-Bdynamic")

# gettext is included in libc on many unix systems
if(NOT LIBC_HAS_DGETTEXT)

+ 1
- 2
common/CMakeLists.txt View File

@@ -1,7 +1,6 @@
add_subdirectory(os)
add_subdirectory(rdr)
add_subdirectory(network)
add_subdirectory(Xregion)
add_subdirectory(rfb)

# For any convenience libraries that are linked into libvnc.so, we need to
@@ -10,6 +9,6 @@ add_subdirectory(rfb)
# is passed (additionally, libvnc is not used on Windows.)

if(NOT WIN32)
set_target_properties(os rdr network Xregion rfb
set_target_properties(os rdr network rfb
PROPERTIES COMPILE_FLAGS -fPIC)
endif()

+ 0
- 6
common/Xregion/CMakeLists.txt View File

@@ -1,6 +0,0 @@
add_library(Xregion STATIC
Region.c)

if(UNIX)
libtool_create_control_file(Xregion)
endif()

+ 0
- 1612
common/Xregion/Region.c
File diff suppressed because it is too large
View File


+ 0
- 50
common/Xregion/Xlib.h View File

@@ -1,50 +0,0 @@
/*

Copyright 1985, 1986, 1987, 1991, 1998 The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.

*/


/*
* Xlib.h - Header definition and support file for the C subroutine
* interface library (Xlib) to the X Window System Protocol (V11).
* Structures and symbols starting with "_" are private to the library.
*/
#ifndef _X11_XLIB_H_
#define _X11_XLIB_H_

#define NeedFunctionPrototypes 1

#define Bool int

typedef struct {
short x, y;
} XPoint;

typedef struct {
short x, y;
unsigned short width, height;
} XRectangle;


#endif /* _X11_XLIB_H_ */

+ 0
- 48
common/Xregion/Xlibint.h View File

@@ -1,48 +0,0 @@

/*

Copyright 1984, 1985, 1987, 1989, 1998 The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.

*/

#ifndef _X11_XLIBINT_H_
#define _X11_XLIBINT_H_ 1

/*
* Xlibint.h - Header definition and support file for the internal
* support routines used by the C subroutine interface
* library (Xlib) to the X Window System.
*
* Warning, there be dragons here....
*/

#include <stdlib.h>

#define Xfree(ptr) free((ptr))
#define Xmalloc(size) malloc((size))
#define Xrealloc(ptr, size) realloc((ptr), (size))
#define Xcalloc(nelem, elsize) calloc((nelem), (elsize))

#endif /* _X11_XLIBINT_H_ */

+ 0
- 190
common/Xregion/Xregion.h View File

@@ -1,190 +0,0 @@
/************************************************************************

Copyright 1987, 1998 The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

************************************************************************/

#ifndef _X11_XREGION_H_
#define _X11_XREGION_H_

typedef struct {
short x1, x2, y1, y2;
} Box, BOX, BoxRec, *BoxPtr;

typedef struct {
short x, y, width, height;
}RECTANGLE, RectangleRec, *RectanglePtr;

#define TRUE 1
#define FALSE 0
#define MAXSHORT 32767
#define MINSHORT -MAXSHORT
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif


/*
* clip region
*/

typedef struct _XRegion {
long size;
long numRects;
BOX *rects;
BOX extents;
} REGION;

/* Xutil.h contains the declaration:
* typedef struct _XRegion *Region;
*/

/* 1 if two BOXs overlap.
* 0 if two BOXs do not overlap.
* Remember, x2 and y2 are not in the region
*/
#define EXTENTCHECK(r1, r2) \
((r1)->x2 > (r2)->x1 && \
(r1)->x1 < (r2)->x2 && \
(r1)->y2 > (r2)->y1 && \
(r1)->y1 < (r2)->y2)

/*
* update region extents
*/
#define EXTENTS(r,idRect){\
if((r)->x1 < (idRect)->extents.x1)\
(idRect)->extents.x1 = (r)->x1;\
if((r)->y1 < (idRect)->extents.y1)\
(idRect)->extents.y1 = (r)->y1;\
if((r)->x2 > (idRect)->extents.x2)\
(idRect)->extents.x2 = (r)->x2;\
if((r)->y2 > (idRect)->extents.y2)\
(idRect)->extents.y2 = (r)->y2;\
}

/*
* Check to see if there is enough memory in the present region.
*/
#define MEMCHECK(reg, rect, firstrect){\
if ((reg)->numRects >= ((reg)->size - 1)){\
BoxPtr tmpRect = Xrealloc ((firstrect), \
(2 * (sizeof(BOX)) * ((reg)->size))); \
if (tmpRect == NULL) \
return(0);\
(firstrect) = tmpRect; \
(reg)->size *= 2;\
(rect) = &(firstrect)[(reg)->numRects];\
}\
}

/* this routine checks to see if the previous rectangle is the same
* or subsumes the new rectangle to add.
*/

#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
(!(((Reg)->numRects > 0)&&\
((R-1)->y1 == (Ry1)) &&\
((R-1)->y2 == (Ry2)) &&\
((R-1)->x1 <= (Rx1)) &&\
((R-1)->x2 >= (Rx2))))

/* add a rectangle to the given Region */
#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
(r)->x1 = (rx1);\
(r)->y1 = (ry1);\
(r)->x2 = (rx2);\
(r)->y2 = (ry2);\
EXTENTS((r), (reg));\
(reg)->numRects++;\
(r)++;\
}\
}



/* add a rectangle to the given Region */
#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
if ((rx1 < rx2) && (ry1 < ry2) &&\
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
(r)->x1 = (rx1);\
(r)->y1 = (ry1);\
(r)->x2 = (rx2);\
(r)->y2 = (ry2);\
(reg)->numRects++;\
(r)++;\
}\
}

#define EMPTY_REGION(pReg) pReg->numRects = 0

#define REGION_NOT_EMPTY(pReg) pReg->numRects

#define INBOX(r, x, y) \
( ( ((r).x2 > x)) && \
( ((r).x1 <= x)) && \
( ((r).y2 > y)) && \
( ((r).y1 <= y)) )

/*
* number of points to buffer before sending them off
* to scanlines() : Must be an even number
*/
#define NUMPTSTOBUFFER 200

/*
* used to allocate buffers for points and link
* the buffers together
*/
typedef struct _POINTBLOCK {
XPoint pts[NUMPTSTOBUFFER];
struct _POINTBLOCK *next;
} POINTBLOCK;

#endif /* _X11_XREGION_H_ */

+ 0
- 167
common/Xregion/Xutil.h View File

@@ -1,167 +0,0 @@

/***********************************************************

Copyright 1987, 1998 The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

#ifndef _X11_XUTIL_H_
#define _X11_XUTIL_H_

/* You must include <X11/Xlib.h> before including this file */
#include "Xlib.h"

/****** Avoid symbol clash with "real" libX11 ******/
#define XClipBox vncXClipBox
#define XCreateRegion vncXCreateRegion
#define XDestroyRegion vncXDestroyRegion
#define XEmptyRegion vncXEmptyRegion
#define XEqualRegion vncXEqualRegion
#define XIntersectRegion vncXIntersectRegion
#define XOffsetRegion vncXOffsetRegion
#define XPointInRegion vncXPointInRegion
#define XPolygonRegion vncXPolygonRegion
#define XRectInRegion vncXRectInRegion
#define XShrinkRegion vncXShrinkRegion
#define XSubtractRegion vncXSubtractRegion
#define XUnionRectWithRegion vncXUnionRectWithRegion
#define XUnionRegion vncXUnionRegion
#define XXorRegion vncXXorRegion

/*
* opaque reference to Region data type
*/
typedef struct _XRegion *Region;

/* Return values from XRectInRegion() */

#define RectangleOut 0
#define RectangleIn 1
#define RectanglePart 2

extern int XClipBox(
Region /* r */,
XRectangle* /* rect_return */
);

extern Region XCreateRegion(
void
);

extern int XDestroyRegion(
Region /* r */
);

extern int XEmptyRegion(
Region /* r */
);

extern int XEqualRegion(
Region /* r1 */,
Region /* r2 */
);

extern int XIntersectRegion(
Region /* sra */,
Region /* srb */,
Region /* dr_return */
);

extern int XOffsetRegion(
Region /* r */,
int /* dx */,
int /* dy */
);

extern Bool XPointInRegion(
Region /* r */,
int /* x */,
int /* y */
);

extern Region XPolygonRegion(
XPoint* /* points */,
int /* n */,
int /* fill_rule */
);

extern int XRectInRegion(
Region /* r */,
int /* x */,
int /* y */,
unsigned int /* width */,
unsigned int /* height */
);

extern int XShrinkRegion(
Region /* r */,
int /* dx */,
int /* dy */
);

extern int XSubtractRegion(
Region /* sra */,
Region /* srb */,
Region /* dr_return */
);

extern int XUnionRectWithRegion(
XRectangle* /* rectangle */,
Region /* src_region */,
Region /* dest_region_return */
);

extern int XUnionRegion(
Region /* sra */,
Region /* srb */,
Region /* dr_return */
);

extern int XXorRegion(
Region /* sra */,
Region /* srb */,
Region /* dr_return */
);

#endif /* _X11_XUTIL_H_ */

+ 2
- 2
common/rfb/CMakeLists.txt View File

@@ -1,4 +1,4 @@
include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/common ${JPEG_INCLUDE_DIR} ${PIXMAN_INCLUDE_DIR})

set(RFB_SOURCES
Blacklist.cxx
@@ -73,7 +73,7 @@ if(WIN32)
set(RFB_SOURCES ${RFB_SOURCES} WinPasswdValidator.cxx)
endif(WIN32)

set(RFB_LIBRARIES ${JPEG_LIBRARIES} os rdr Xregion)
set(RFB_LIBRARIES ${JPEG_LIBRARIES} ${PIXMAN_LIBRARY} os rdr)

if(UNIX AND NOT APPLE)
set(RFB_SOURCES ${RFB_SOURCES} UnixPasswordValidator.cxx

+ 59
- 109
common/rfb/Region.cxx View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2016-2020 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,189 +17,134 @@
* USA.
*/

// Cross-platform Region class based on the X11 region implementation. Note
// that for efficiency this code manipulates the Xlib region structure
// directly. Apart from the layout of the structure, there is one other key
// assumption made: a Region returned from XCreateRegion must always have its
// rects member allocated so that there is space for at least one rectangle.
//

#include <rfb/Region.h>
#include <rfb/LogWriter.h>
#include <assert.h>
#include <stdio.h>

extern "C" {
#include <Xregion/Xlibint.h>
#include <Xregion/Xutil.h>
#include <Xregion/Xregion.h>
#include <pixman.h>
}

static rfb::LogWriter vlog("Region");

// A _RectRegion must never be passed as a return parameter to the Xlib region
// operations. This is because for efficiency its "rects" member has not been
// allocated with Xmalloc. It is however safe to pass it as an input
// parameter.

class _RectRegion {
public:
_RectRegion(const rfb::Rect& r) {
region.rects = &region.extents;
region.numRects = 1;
region.extents.x1 = r.tl.x;
region.extents.y1 = r.tl.y;
region.extents.x2 = r.br.x;
region.extents.y2 = r.br.y;
region.size = 1;
if (r.is_empty())
region.numRects = 0;
}
REGION region;
};


rfb::Region::Region() {
xrgn = XCreateRegion();
assert(xrgn);
rgn = new struct pixman_region16;
pixman_region_init(rgn);
}

rfb::Region::Region(const Rect& r) {
xrgn = XCreateRegion();
assert(xrgn);
reset(r);
rgn = new struct pixman_region16;
pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height());
}

rfb::Region::Region(const rfb::Region& r) {
xrgn = XCreateRegion();
assert(xrgn);
XUnionRegion(xrgn, r.xrgn, xrgn);
rgn = new struct pixman_region16;
pixman_region_init(rgn);
pixman_region_copy(rgn, r.rgn);
}

rfb::Region::~Region() {
XDestroyRegion(xrgn);
pixman_region_fini(rgn);
delete rgn;
}

rfb::Region& rfb::Region::operator=(const rfb::Region& r) {
clear();
XUnionRegion(xrgn, r.xrgn, xrgn);
pixman_region_copy(rgn, r.rgn);
return *this;
}

void rfb::Region::clear() {
xrgn->numRects = 0;
xrgn->extents.x1 = 0;
xrgn->extents.y1 = 0;
xrgn->extents.x2 = 0;
xrgn->extents.y2 = 0;
// pixman_region_clear() isn't available on some older systems
pixman_region_fini(rgn);
pixman_region_init(rgn);
}

void rfb::Region::reset(const Rect& r) {
if (r.is_empty()) {
clear();
} else {
xrgn->numRects = 1;
xrgn->rects[0].x1 = xrgn->extents.x1 = r.tl.x;
xrgn->rects[0].y1 = xrgn->extents.y1 = r.tl.y;
xrgn->rects[0].x2 = xrgn->extents.x2 = r.br.x;
xrgn->rects[0].y2 = xrgn->extents.y2 = r.br.y;
}
pixman_region_fini(rgn);
pixman_region_init_rect(rgn, r.tl.x, r.tl.y, r.width(), r.height());
}

void rfb::Region::translate(const Point& delta) {
XOffsetRegion(xrgn, delta.x, delta.y);
pixman_region_translate(rgn, delta.x, delta.y);
}

void rfb::Region::setOrderedRects(const std::vector<Rect>& rects) {
clear();
std::vector<Rect>::const_iterator i;
for (i=rects.begin(); i != rects.end(); i++) {
_RectRegion rr(*i);
XUnionRegion(xrgn, &rr.region, xrgn);
}
for (i=rects.begin(); i != rects.end(); i++)
pixman_region_union_rect(rgn, rgn, i->tl.x, i->tl.y, i->width(), i->height());
}

void rfb::Region::setExtentsAndOrderedRects(const ShortRect* extents,
int nRects, const ShortRect* rects)
{
if (xrgn->size < nRects)
{
BOX* prevRects = xrgn->rects;
xrgn->rects = (BOX*)Xrealloc((char*)xrgn->rects, nRects * sizeof(BOX));
if (!xrgn->rects) {
vlog.error("Xrealloc failed");
Xfree(prevRects);
return;
}
xrgn->size = nRects;
}

xrgn->numRects = nRects;
xrgn->extents.x1 = extents->x1;
xrgn->extents.y1 = extents->y1;
xrgn->extents.x2 = extents->x2;
xrgn->extents.y2 = extents->y2;
clear();
std::vector<Rect>::const_iterator i;
for (int i = 0; i < nRects; i++) {
xrgn->rects[i].x1 = rects[i].x1;
xrgn->rects[i].y1 = rects[i].y1;
xrgn->rects[i].x2 = rects[i].x2;
xrgn->rects[i].y2 = rects[i].y2;
pixman_region_union_rect(rgn, rgn, rects[i].x1, rects[i].y1,
rects[i].x2 - rects[i].x1,
rects[i].y2 - rects[i].y1);
}
}

void rfb::Region::assign_intersect(const rfb::Region& r) {
XIntersectRegion(xrgn, r.xrgn, xrgn);
pixman_region_intersect(rgn, rgn, r.rgn);
}

void rfb::Region::assign_union(const rfb::Region& r) {
XUnionRegion(xrgn, r.xrgn, xrgn);
pixman_region_union(rgn, rgn, r.rgn);
}

void rfb::Region::assign_subtract(const rfb::Region& r) {
XSubtractRegion(xrgn, r.xrgn, xrgn);
pixman_region_subtract(rgn, rgn, r.rgn);
}

rfb::Region rfb::Region::intersect(const rfb::Region& r) const {
rfb::Region ret;
XIntersectRegion(xrgn, r.xrgn, ret.xrgn);
pixman_region_intersect(ret.rgn, rgn, r.rgn);
return ret;
}

rfb::Region rfb::Region::union_(const rfb::Region& r) const {
rfb::Region ret;
XUnionRegion(xrgn, r.xrgn, ret.xrgn);
pixman_region_union(ret.rgn, rgn, r.rgn);
return ret;
}

rfb::Region rfb::Region::subtract(const rfb::Region& r) const {
rfb::Region ret;
XSubtractRegion(xrgn, r.xrgn, ret.xrgn);
pixman_region_subtract(ret.rgn, rgn, r.rgn);
return ret;
}

bool rfb::Region::equals(const rfb::Region& r) const {
return XEqualRegion(xrgn, r.xrgn);
return pixman_region_equal(rgn, r.rgn);
}

int rfb::Region::numRects() const {
return xrgn->numRects;
return pixman_region_n_rects(rgn);
}

bool rfb::Region::get_rects(std::vector<Rect>* rects,
bool left2right, bool topdown) const
{
int nRects = xrgn->numRects;
int xInc = left2right ? 1 : -1;
int yInc = topdown ? 1 : -1;
int i = topdown ? 0 : nRects-1;
int nRects;
const pixman_box16_t* boxes;
int xInc, yInc, i;

boxes = pixman_region_rectangles(rgn, &nRects);

rects->clear();
rects->reserve(nRects);

xInc = left2right ? 1 : -1;
yInc = topdown ? 1 : -1;
i = topdown ? 0 : nRects-1;

while (nRects > 0) {
int firstInNextBand = i;
int nRectsInBand = 0;

while (nRects > 0 && xrgn->rects[firstInNextBand].y1 == xrgn->rects[i].y1)
while (nRects > 0 && boxes[firstInNextBand].y1 == boxes[i].y1)
{
firstInNextBand += yInc;
nRects--;
@@ -209,8 +155,7 @@ bool rfb::Region::get_rects(std::vector<Rect>* rects,
i = firstInNextBand - yInc;

while (nRectsInBand > 0) {
Rect r(xrgn->rects[i].x1, xrgn->rects[i].y1,
xrgn->rects[i].x2, xrgn->rects[i].y2);
Rect r(boxes[i].x1, boxes[i].y1, boxes[i].x2, boxes[i].y2);
rects->push_back(r);
i += xInc;
nRectsInBand--;
@@ -223,22 +168,27 @@ bool rfb::Region::get_rects(std::vector<Rect>* rects,
}

rfb::Rect rfb::Region::get_bounding_rect() const {
return Rect(xrgn->extents.x1, xrgn->extents.y1,
xrgn->extents.x2, xrgn->extents.y2);
const pixman_box16_t* extents;
extents = pixman_region_extents(rgn);
return Rect(extents->x1, extents->y1, extents->x2, extents->y2);
}


void rfb::Region::debug_print(const char* prefix) const
{
Rect extents;
std::vector<Rect> rects;
std::vector<Rect>::const_iterator iter;

extents = get_bounding_rect();
get_rects(&rects);

vlog.debug("%s num rects %3ld extents %3d,%3d %3dx%3d",
prefix, xrgn->numRects, xrgn->extents.x1, xrgn->extents.y1,
xrgn->extents.x2-xrgn->extents.x1,
xrgn->extents.y2-xrgn->extents.y1);
prefix, (long)rects.size(), extents.tl.x, extents.tl.y,
extents.width(), extents.height());

for (int i = 0; i < xrgn->numRects; i++) {
for (iter = rects.begin(); iter != rects.end(); ++iter) {
vlog.debug(" rect %3d,%3d %3dx%3d",
xrgn->rects[i].x1, xrgn->rects[i].y1,
xrgn->rects[i].x2-xrgn->rects[i].x1,
xrgn->rects[i].y2-xrgn->rects[i].y1);
iter->tl.x, iter->tl.y, iter->width(), iter->height());
}
}

+ 4
- 3
common/rfb/Region.h View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2016-2020 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* USA.
*/

// Cross-platform Region class based on the X11 region implementation
// Region class wrapper around pixman's region operations

#ifndef __RFB_REGION_INCLUDED__
#define __RFB_REGION_INCLUDED__
@@ -24,7 +25,7 @@
#include <rfb/Rect.h>
#include <vector>

struct _XRegion;
struct pixman_region16;

namespace rfb {

@@ -75,7 +76,7 @@ namespace rfb {

protected:

struct _XRegion* xrgn;
struct pixman_region16* rgn;
};

};

+ 1
- 2
unix/xserver/hw/vnc/Makefile.am View File

@@ -5,9 +5,8 @@ RFB_LIB=$(TIGERVNC_BUILDDIR)/common/rfb/librfb.la
RDR_LIB=$(TIGERVNC_BUILDDIR)/common/rdr/librdr.la
OS_LIB=$(TIGERVNC_BUILDDIR)/common/os/libos.la
NETWORK_LIB=$(TIGERVNC_BUILDDIR)/common/network/libnetwork.la
XREGION_LIB=$(TIGERVNC_BUILDDIR)/common/Xregion/libXregion.la
UNIXCOMMON_LIB=$(TIGERVNC_BUILDDIR)/unix/common/libunixcommon.la
COMMON_LIBS=$(NETWORK_LIB) $(RFB_LIB) $(RDR_LIB) $(XREGION_LIB) $(OS_LIB) $(UNIXCOMMON_LIB)
COMMON_LIBS=$(NETWORK_LIB) $(RFB_LIB) $(RDR_LIB) $(OS_LIB) $(UNIXCOMMON_LIB)

noinst_LTLIBRARIES = libvnccommon.la


Loading…
Cancel
Save