This structure specifies a 32 bpp ARGB or XRGB color value
        /// <summary>
        /// Method to implement SurfaceToCache functionality
        /// </summary>
        /// <param name="surf">The surface to be filled.</param>
        /// <param name="cacheRect">The rectangle to be cached on the surface.</param>
        /// <param name="cacheKey">The cacheKey of rectangle bitmap data on client.</param>
        /// <param name="cacheSlot">Specify a cacheslot</param>
        /// <param name="fillColor">The color that rectangle to be filled.</param>
        public uint CacheSurface(Surface surf, RDPGFX_RECT16 cacheRect, ulong cacheKey, ushort? cacheSlot, RDPGFX_COLOR32? fillColor = null)
        {
            uint fid = MakeStartFramePdu();

            if (fillColor != null)
            {
                // Send solid fill request to client to fill cacheRect of surface with color.
                RDPGFX_RECT16[] rects = { cacheRect };
                MakeSolidFillPdu(surf.Id, fillColor.Value, rects);
            }

            if (cacheSlot == null)
            {
                cacheSlot = 1;
            }

            if (currentTestType == RdpegfxNegativeTypes.CacheManagement_Default_ExceedMaxCacheSlot)
            {
                // 25600 is the max cache slots number for default cache size.
                for (ushort index = 1; index <= 25601; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                    if (index % 100 == 0)
                        PackAndSendServerPdu();
                }
            }
            else if (currentTestType == RdpegfxNegativeTypes.CacheManagement_SmallCache_ExceedMaxCacheSlot)
            {
                // 12800 is the max cache slots number for small cache size.
                for (ushort index = 1; index <= 12801; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                    if (index % 100 == 0)
                        PackAndSendServerPdu();
                }
            }
            else if (currentTestType == RdpegfxNegativeTypes.CacheManagement_ThinCient_ExceedMaxCacheslot)
            {
                // 4096 is the max cache slots number for thin client cache size.
                for (ushort index = 1; index <= 4097; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                    if (index % 100 == 0)
                        PackAndSendServerPdu();
                }
            }
            else if (currentTestType == RdpegfxNegativeTypes.CacheManagement_Default_ExceedMaxCacheSize)
            {
                // Every cache slot has the size of 1MB here,
                // 100MB is the max cache size for default flag, cache 101 MB here which exceeds max cache size.
                for (ushort index = 1; index <= 101; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                }
            }
            else if (currentTestType == RdpegfxNegativeTypes.CacheManagement_SmallCache_ExceedMaxCacheSize)
            {
                // Every cache slot has the size of 1MB here,
                // 50MB is the max cache size for SmallCache flag, cache 51 MB here which exceeds max cache size.
                for (ushort index = 1; index <= 51; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                }
            }
            else if (currentTestType == RdpegfxNegativeTypes.CacheManagement_ThinClient_ExceedMaxCacheSize)
            {
                // Every cache slot has the size of 1MB here,
                // 16MB is the max cache size for SmallCache flag, cache 17 MB here which exceeds max cache size.
                for (ushort index = 1; index <= 17; ++index)
                {
                    cacheSlot = index;
                    MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
                }
            }
            else
            {
                MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);
            }

            if (currentTestType == RdpegfxNegativeTypes.CacheManagement_Delete_InexistentCacheSlot)
            {
                // Delete an inexistent cache slot.
                MakeEvictCacheEntryPdu(0xfefe);    // 0xfefe is an inexistent cache slot.
            }

            MakeEndFramePdu(fid);
            PackAndSendServerPdu();
            return fid;
        }
        /// <summary>
        /// Method to send nested frames
        /// </summary>
        /// <param name="surf">The surface that the frames belong to</param>
        /// <param name="colors">The color to fill the surface</param>
        /// <param name="rects">The rectangles to be filled in the surface</param>
        public void SendNestedFrames(Surface surf, RDPGFX_COLOR32[] colors, RDPGFX_RECT16[] rects)
        {
            uint fid1 = MakeStartFramePdu();
            uint fid2 = MakeStartFramePdu();
            MakeSolidFillPdu(surf.Id, colors[0], new RDPGFX_RECT16[] { rects[0] });
            MakeSolidFillPdu(surf.Id, colors[1], new RDPGFX_RECT16[] { rects[1] });
            MakeEndFramePdu(fid2);
            MakeEndFramePdu(fid1);

            PackAndSendServerPdu();
            //ExpectFrameAck(fid2);
            //ExpectFrameAck(fid1);
        }
        /// <summary>
        /// Method to implement SurfaceToCache and CacheToSurface functionality.
        /// </summary>
        /// <param name="surf">The surface to be filled.</param>
        /// <param name="cacheRect">The rectangle to be cached on the surface.</param>
        /// <param name="cacheKey">The cacheKey of rectangle bitmap data on client.</param>
        /// <param name="destPoints">This is used to specify destination points of source rectangle bitmap to be copied </param>
        /// <param name="cacheSlot">Specify a cacheslot</param>
        /// <param name="fillColor">The color that rectangle to be filled.</param>
        /// <returns> Frame Id </returns>
        public uint FillSurfaceByCachedBitmap(Surface surf, RDPGFX_RECT16 cacheRect, ulong cacheKey, RDPGFX_POINT16[] destPoints, ushort? cacheSlot, RDPGFX_COLOR32? fillColor = null)
        {
            uint fid = MakeStartFramePdu();

            if (fillColor != null)
            {
                // Send solid fill request to client to fill cacheRect of surface with color
                RDPGFX_RECT16[] rects = { cacheRect };
                MakeSolidFillPdu(surf.Id, fillColor.Value, rects);
            }

            // Copy a rectangle bitmap data to cache and move it from cache to other positions of surface.
            if (cacheSlot == null)
            {
                cacheSlot = 1;  //set slot# to 1
            }
            MakeSurfaceToCachePdu(surf.Id, cacheKey, cacheSlot.Value, cacheRect);

            if (currentTestType == RdpegfxNegativeTypes.CacheManagement_CacheToSurface_InexistentCacheSlot)
            {
                cacheSlot = (ushort)(cacheSlot.Value + 1);
            }
            ushort sid = surf.Id;
            if (currentTestType == RdpegfxNegativeTypes.CacheManagement_CacheToSurface_InexistentSurface)
            {
                sid++;
            }
            MakeCacheToSurfacePdu(cacheSlot.Value, sid, destPoints);

            MakeEndFramePdu(fid);

            PackAndSendServerPdu();
            return fid;
        }
        /// <summary>
        /// Method to copy bitmap of a rectangle in a surface to other position in another surface
        /// </summary>
        /// <param name="surf">The source surface where the rectangle to be copied.</param>
        /// <param name="srcRect">The rectangle to be copied.</param>
        /// <param name="fillColor">The color of rectangle to be filled.</param>
        /// <param name="surfDest">The destination surface where the rectangle is copied to.</param>
        /// <param name="destPos">The position array that rectangle is copied to.</param>
        /// <returns> Frame Id </returns>
        public uint InterSurfaceCopy(Surface surfSrc, RDPGFX_RECT16 srcRect, RDPGFX_COLOR32 fillColor, Surface surfDest, RDPGFX_POINT16[] destPos)
        {
            uint fid = MakeStartFramePdu();
            RDPGFX_RECT16[] rects = { srcRect };
            MakeSolidFillPdu(surfSrc.Id, fillColor, rects);
            MakeSurfaceToSurfacePdu(surfSrc.Id, surfDest.Id, srcRect, destPos);
            if (currentTestType != RdpegfxNegativeTypes.SurfaceManagement_InterSurfaceCopy_DestPtsCount_Mismatch)
            {
                MakeEndFramePdu(fid);
            }

            PackAndSendServerPdu();

            return fid;
        }
        /// <summary>
        /// Method to make a solid fill Pdu
        /// </summary>
        /// <param name="sid">This is used to indicate surface id to be filled.</param>
        /// <param name="pixel">This is used to indicate color to fill.</param>
        /// <param name="rects">This is to specify rectangle areas in surface </param>
        void MakeSolidFillPdu(ushort sid, RDPGFX_COLOR32 color, RDPGFX_RECT16[] rects)
        {
            RDPGFX_SOLIDFILL solidFill = egfxServer.CreateSolidFillPdu(sid, color, rects);
            // Change pdu based testtype.
            if (currentTestType == RdpegfxNegativeTypes.SurfaceManagement_SolidFill_ToInexistentSurface)
                solidFill.surfaceId = 0xffff;   // Set the surface id to an inexsit surface's id 0xffff

            AddPdusToBuffer(solidFill);

            if (this.bcgrAdapter.SimulatedScreen != null)
            {
                this.bcgrAdapter.SimulatedScreen.SolidFill(sid, color, rects);
            }
        }
        /// <summary>
        /// Method to solidfill a surface with color
        /// </summary>
        /// <param name="surf">The surface to be filled.</param>
        /// <param name="color">The color to fill the surface.</param>
        /// <param name="rects">The rectangles to be filled in the surface.</param>
        /// <param name="frameId">Specify the frame Id.</param>
        /// <returns> Frame Id </returns>
        public uint SolidFillSurface(Surface surf, RDPGFX_COLOR32 color, RDPGFX_RECT16[] rects, uint? frameId = null)
        {
            uint fid = MakeStartFramePdu(frameId);
            MakeSolidFillPdu(surf.Id, color, rects);
            MakeEndFramePdu(fid);

            PackAndSendServerPdu();
            return fid;
        }
        /// <summary>
        /// Constructor, create a RDPGFX_SOLIDFILL message with one rectangle to fill default.
        /// </summary>
        /// <param name="sid">This is used to indicate surface id to be filled.</param>
        /// <param name="pixel">This is used to indicate color to fill.</param>
        public RDPGFX_SOLIDFILL(ushort sid, RDPGFX_COLOR32 pixel)
        {
            this.Header.cmdId = PacketTypeValues.RDPGFX_CMDID_SOLIDFILL;
            this.Header.flags = 0x0;
            this.Header.pduLength = (uint)Marshal.SizeOf(Header) + 8;

            this.surfaceId = sid;
            this.fillPixel = pixel;
            this.fillRectCount = 0;
            this.fillRectList = new List<RDPGFX_RECT16>();
            this.fillRectList.Clear();
        }
            public void SolidFill(RDPGFX_COLOR32 fillPixel, RDPGFX_RECT16[] fillRects)
            {
                if (fillRects != null && fillRects.Length > 0)
                {
                    Color c = Color.Black;
                    if (this.pixelFormat == PixelFormat.PIXEL_FORMAT_ARGB_8888)
                    {
                        c = Color.FromArgb(fillPixel.XA, fillPixel.R, fillPixel.G, fillPixel.B);
                    }
                    else
                    {
                        c = Color.FromArgb(fillPixel.R, fillPixel.G, fillPixel.B);
                    }
                    Brush brush = new SolidBrush(c);
                    Rectangle[] rects = new Rectangle[fillRects.Length];
                    for (int i = 0; i < fillRects.Length; i++)
                    {
                        rects[i] = new Rectangle(fillRects[i].left, fillRects[i].top, fillRects[i].right - fillRects[i].left, fillRects[i].bottom - fillRects[i].top);
                    }
                    imageGraphic.FillRectangles(brush, rects);

                    if (mapPoints.Count > 0)
                    {
                        List<Rectangle> rectList = new List<Rectangle>();
                        foreach (Point p in mapPoints)
                        {
                            foreach(Rectangle rect in rects)
                            {
                                rectList.Add(new Rectangle(rect.Left+p.X, rect.Top+p.Y, rect.Width, rect.Height));
                            }
                        }
                        Graphics baseImageGraphics = Graphics.FromImage(screen.BaseImage);

                        baseImageGraphics.FillRectangles(brush, rectList.ToArray());

                        baseImageGraphics.Dispose();
                    }

                }
            }
 /// <summary>
 /// Fill a collection of rectangles on a destination surface with a solid color
 /// </summary>
 /// <param name="surfaceId"></param>
 /// <param name="fillPixel"></param>
 /// <param name="fillRects"></param>
 public void SolidFill(ushort surfaceId, RDPGFX_COLOR32 fillPixel, RDPGFX_RECT16[] fillRects)
 {
     if (surfaceDic.ContainsKey(surfaceId))
     {
         surfaceDic[surfaceId].SolidFill(fillPixel, fillRects);
     }
 }