2016-04-21 01:01:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* graphics/vnc/vnc_rre.c
|
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you 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
|
2016-04-21 01:01:48 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-04-21 01:01:48 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* 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.
|
2016-04-21 01:01:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2016-04-23 17:06:39 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_VNCSERVER_DEBUG) && !defined(CONFIG_DEBUG_GRAPHICS)
|
2016-06-11 22:14:08 +02:00
|
|
|
# undef CONFIG_DEBUG_ERROR
|
|
|
|
# undef CONFIG_DEBUG_WARN
|
2016-06-11 19:50:18 +02:00
|
|
|
# undef CONFIG_DEBUG_INFO
|
2019-03-17 18:34:45 +01:00
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_ERROR
|
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_WARN
|
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_INFO
|
|
|
|
# define CONFIG_DEBUG_ERROR 1
|
|
|
|
# define CONFIG_DEBUG_WARN 1
|
|
|
|
# define CONFIG_DEBUG_INFO 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_ERROR 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_WARN 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_INFO 1
|
2016-04-23 17:06:39 +02:00
|
|
|
#endif
|
2016-04-21 01:01:48 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "vnc_server.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rre_encode8_s
|
2016-04-21 01:01:48 +02:00
|
|
|
{
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rfb_rrehdr8_s hdr;
|
|
|
|
struct rfb_rrerect8_s rect;
|
2016-04-21 01:01:48 +02:00
|
|
|
};
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rre_encode16_s
|
2016-04-21 01:01:48 +02:00
|
|
|
{
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rfb_rrehdr16_s hdr;
|
|
|
|
struct rfb_rrerect16_s rect;
|
2016-04-21 01:01:48 +02:00
|
|
|
};
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rre_encode32_s
|
2016-04-21 01:01:48 +02:00
|
|
|
{
|
2016-04-21 16:16:33 +02:00
|
|
|
struct rfb_rrehdr32_s hdr;
|
|
|
|
struct rfb_rrerect32_s rect;
|
2016-04-21 01:01:48 +02:00
|
|
|
};
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_rreNN
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Encode a single RRE sub-rectangle, NN=bits-per-pixel
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - An instance of the session structure.
|
|
|
|
* dest - The locate to save the RRE encoded data
|
|
|
|
* rect - Describes the rectangle in the local framebuffer.
|
|
|
|
* bgcolor - The local color of the pixel data
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The size of the framebuffer update message is returned..
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
ssize_t vnc_rre8(FAR struct vnc_session_s *session,
|
|
|
|
FAR struct rre_encode8_s *dest,
|
|
|
|
FAR struct nxgl_rect_s *rect,
|
|
|
|
uint8_t bgcolor)
|
|
|
|
{
|
|
|
|
nxgl_coord_t width;
|
|
|
|
nxgl_coord_t height;
|
|
|
|
|
|
|
|
rfb_putbe32(dest->hdr.nsubrects, 1);
|
|
|
|
dest->hdr.pixel = bgcolor;
|
|
|
|
|
|
|
|
dest->rect.pixel = bgcolor;
|
|
|
|
rfb_putbe16(dest->rect.xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(dest->rect.ypos, rect->pt1.y);
|
|
|
|
|
|
|
|
width = rect->pt2.x - rect->pt1.x + 1;
|
|
|
|
height = rect->pt2.y - rect->pt1.y + 1;
|
|
|
|
|
|
|
|
rfb_putbe16(dest->rect.width, width);
|
|
|
|
rfb_putbe16(dest->rect.height, height);
|
|
|
|
|
|
|
|
return sizeof(struct rre_encode8_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t vnc_rre16(FAR struct vnc_session_s *session,
|
|
|
|
FAR struct rre_encode16_s *dest,
|
|
|
|
FAR struct nxgl_rect_s *rect,
|
|
|
|
uint16_t bgcolor)
|
|
|
|
{
|
|
|
|
nxgl_coord_t width;
|
|
|
|
nxgl_coord_t height;
|
|
|
|
|
|
|
|
rfb_putbe32(dest->hdr.nsubrects, 1);
|
|
|
|
rfb_putbe16(dest->hdr.pixel, bgcolor);
|
|
|
|
|
|
|
|
rfb_putbe16(dest->rect.pixel, bgcolor);
|
|
|
|
rfb_putbe16(dest->rect.xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(dest->rect.xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(dest->rect.ypos, rect->pt1.y);
|
|
|
|
|
|
|
|
width = rect->pt2.x - rect->pt1.x + 1;
|
|
|
|
height = rect->pt2.y - rect->pt1.y + 1;
|
|
|
|
|
|
|
|
rfb_putbe16(dest->rect.width, width);
|
|
|
|
rfb_putbe16(dest->rect.height, height);
|
|
|
|
|
|
|
|
return sizeof(struct rre_encode16_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t vnc_rre32(FAR struct vnc_session_s *session,
|
|
|
|
FAR struct rre_encode32_s *dest,
|
|
|
|
FAR struct nxgl_rect_s *rect,
|
|
|
|
uint32_t bgcolor)
|
|
|
|
{
|
|
|
|
nxgl_coord_t width;
|
|
|
|
nxgl_coord_t height;
|
|
|
|
|
|
|
|
rfb_putbe32(dest->hdr.nsubrects, 1);
|
|
|
|
rfb_putbe32(dest->hdr.pixel, bgcolor);
|
|
|
|
|
|
|
|
rfb_putbe32(dest->rect.pixel, bgcolor);
|
|
|
|
rfb_putbe16(dest->rect.xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(dest->rect.xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(dest->rect.ypos, rect->pt1.y);
|
|
|
|
|
|
|
|
width = rect->pt2.x - rect->pt1.x + 1;
|
|
|
|
height = rect->pt2.y - rect->pt1.y + 1;
|
|
|
|
|
|
|
|
rfb_putbe16(dest->rect.width, width);
|
|
|
|
rfb_putbe16(dest->rect.height, height);
|
|
|
|
|
|
|
|
return sizeof(struct rre_encode32_s);
|
|
|
|
}
|
|
|
|
|
2016-04-21 01:01:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_rre
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function does not really do RRE encoding. It just checks if the
|
|
|
|
* update region is one color then uses the RRE encoding format to send
|
|
|
|
* the constant color rectangle.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - An instance of the session structure.
|
|
|
|
* rect - Describes the rectangle in the local framebuffer.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2019-05-03 18:45:38 +02:00
|
|
|
* Zero is returned if RRE coding was not performed (but no error was
|
|
|
|
* encountered). Otherwise, the size of the framebuffer update message
|
2016-04-21 16:16:33 +02:00
|
|
|
* is returned on success or a negated errno value is returned on failure
|
2017-05-11 21:35:56 +02:00
|
|
|
* that indicates the nature of the failure. A failure is only
|
2016-04-21 16:16:33 +02:00
|
|
|
* returned in cases of a network failure and unexpected internal failures.
|
2016-04-21 01:01:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int vnc_rre(FAR struct vnc_session_s *session, FAR struct nxgl_rect_s *rect)
|
|
|
|
{
|
2016-04-21 16:16:33 +02:00
|
|
|
FAR struct rfb_framebufferupdate_s *rre;
|
|
|
|
FAR struct rfb_rectangle_s *rrect;
|
2016-04-21 01:01:48 +02:00
|
|
|
lfb_color_t bgcolor;
|
|
|
|
nxgl_coord_t width;
|
|
|
|
nxgl_coord_t height;
|
2016-04-21 16:16:33 +02:00
|
|
|
size_t nbytes;
|
2016-04-21 01:01:48 +02:00
|
|
|
ssize_t nsent;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check if the client supports the RRE encoding */
|
|
|
|
|
|
|
|
if (session->rre)
|
|
|
|
{
|
|
|
|
/* Check if the update region contains only a single color */
|
|
|
|
|
|
|
|
ret = vnc_colors(session, rect, 1, &bgcolor);
|
|
|
|
if (ret == 1)
|
|
|
|
{
|
2016-04-21 16:16:33 +02:00
|
|
|
width = rect->pt2.x - rect->pt1.x + 1;
|
|
|
|
height = rect->pt2.y - rect->pt1.y + 1;
|
2016-04-21 01:01:48 +02:00
|
|
|
|
|
|
|
/* Format the FrameBuffer Update with a single RRE encoded
|
|
|
|
* rectangle.
|
|
|
|
*/
|
|
|
|
|
2021-02-05 09:05:48 +01:00
|
|
|
rre = (FAR struct rfb_framebufferupdate_s *)session->outbuf;
|
|
|
|
|
2016-04-21 01:01:48 +02:00
|
|
|
rre->msgtype = RFB_FBUPDATE_MSG;
|
|
|
|
rre->padding = 0;
|
|
|
|
rfb_putbe16(rre->nrect, 1);
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
rrect = (FAR struct rfb_rectangle_s *)&rre->rect;
|
2016-04-21 01:01:48 +02:00
|
|
|
rfb_putbe16(rrect->xpos, rect->pt1.x);
|
|
|
|
rfb_putbe16(rrect->ypos, rect->pt1.y);
|
|
|
|
rfb_putbe16(rrect->width, width);
|
|
|
|
rfb_putbe16(rrect->height, height);
|
|
|
|
rfb_putbe32(rrect->encoding, RFB_ENCODING_RRE);
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
/* The sub-rectangle encoding depends of the remote pixel width */
|
|
|
|
|
|
|
|
nbytes = SIZEOF_RFB_FRAMEBUFFERUPDATE_S(SIZEOF_RFB_RECTANGE_S(0));
|
|
|
|
|
|
|
|
switch (session->colorfmt)
|
|
|
|
{
|
|
|
|
case FB_FMT_RGB8_222:
|
|
|
|
nbytes += vnc_rre8(session,
|
|
|
|
(FAR struct rre_encode8_s *)rrect->data,
|
|
|
|
rect, vnc_convert_rgb8_222(bgcolor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB8_332:
|
|
|
|
nbytes += vnc_rre8(session,
|
|
|
|
(FAR struct rre_encode8_s *)rrect->data,
|
|
|
|
rect, vnc_convert_rgb8_332(bgcolor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB16_555:
|
|
|
|
nbytes += vnc_rre16(session,
|
|
|
|
(FAR struct rre_encode16_s *)rrect->data,
|
|
|
|
rect, vnc_convert_rgb16_555(bgcolor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB16_565:
|
|
|
|
nbytes += vnc_rre16(session,
|
|
|
|
(FAR struct rre_encode16_s *)rrect->data,
|
|
|
|
rect, vnc_convert_rgb16_565(bgcolor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB32:
|
|
|
|
nbytes += vnc_rre32(session,
|
|
|
|
(FAR struct rre_encode32_s *)rrect->data,
|
|
|
|
rect, vnc_convert_rgb32_888(bgcolor));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-11 23:50:49 +02:00
|
|
|
gerr("ERROR: Unrecognized color format: %d\n",
|
2016-04-21 16:16:33 +02:00
|
|
|
session->colorfmt);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-04-21 01:01:48 +02:00
|
|
|
|
|
|
|
/* At the very last most, make certain that the supported encoding
|
|
|
|
* has not changed asynchronously.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (session->rre)
|
|
|
|
{
|
|
|
|
/* Okay send until all of the bytes are out. This may
|
|
|
|
* loop for the case where TCP write buffering is enabled
|
|
|
|
* and there are a limited number of IOBs available.
|
|
|
|
*/
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
nsent = psock_send(&session->connect, rre, nbytes, 0);
|
2016-04-21 01:01:48 +02:00
|
|
|
if (nsent < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
gerr("ERROR: Send RRE FrameBufferUpdate failed: %d\n",
|
2017-09-30 01:48:15 +02:00
|
|
|
(int)nsent);
|
|
|
|
return (int)nsent;
|
2016-04-21 01:01:48 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 16:16:33 +02:00
|
|
|
DEBUGASSERT(nsent == nbytes);
|
2016-06-11 19:59:51 +02:00
|
|
|
updinfo("Sent {(%d, %d),(%d, %d)}\n",
|
2016-04-21 17:47:26 +02:00
|
|
|
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y);
|
2016-04-21 16:16:33 +02:00
|
|
|
return nbytes;
|
2016-04-21 01:01:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2019-05-03 18:45:38 +02:00
|
|
|
}
|