Beispiel #1
0
        public static void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer,
                                        Action <SKSurface> handler)
        {
            var       hwnd = packet.Hwnd;
            Rectangle clientRect;

            User32Methods.GetClientRect(hwnd, out clientRect);
            var size = clientRect.Size;

            pixelBuffer.EnsureSize(size.Width, size.Height);
            PaintStruct ps;
            var         hdc       = User32Methods.BeginPaint(hwnd, out ps);
            var         skPainted = false;

            try
            {
                using (var surface = SKSurface.Create(
                           size.Width,
                           size.Height,
                           SKColorType.Bgra8888,
                           SKAlphaType.Premul,
                           pixelBuffer.Handle,
                           pixelBuffer.Stride))
                {
                    if (surface != null)
                    {
                        handler(surface);
                        skPainted = true;
                    }
                }
            }
            finally
            {
                if (skPainted)
                {
                    Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle);
                }
                User32Methods.EndPaint(hwnd, ref ps);
            }
        }
Beispiel #2
0
            public static unsafe void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer,
                                                   Action <SKSurface> handler)
            {
                var       hwnd = packet.Hwnd;
                Rectangle clientRect;

                User32Methods.GetClientRect(hwnd, out clientRect);
                var size = clientRect.Size;

                pixelBuffer.EnsureSize(size.Width, size.Height);
                PaintStruct ps;
                var         hdc       = User32Methods.BeginPaint(hwnd, out ps);
                var         skPainted = false;

                try
                {
                    using (var surface = SKSurface.Create(
                               size.Width,
                               size.Height,
                               SKColorType.Bgra8888,
                               SKAlphaType.Premul,
                               pixelBuffer.Handle,
                               pixelBuffer.Stride))
                    {
                        if (surface != null)
                        {
                            handler(surface);

                            /*
                             * foreach (var VARIABLE in Enumerable.Range(0, pixelBuffer.Stride * size.Height / 4))
                             * {
                             *  var value = Marshal.ReadInt32(pixelBuffer.Handle, VARIABLE*4);
                             *  // ABGR >> ARGB
                             *  unchecked
                             *  {
                             *      value = ((value & (int)0xff000000) >> 0) +
                             *          ((value & 0xff0000) >> 16 )+
                             *          ((value & 0xff00) << 0) +
                             *          ((value & 0xff) << 16);
                             *  }
                             *
                             *  Marshal.WriteInt32(pixelBuffer.Handle, VARIABLE * 4, value);
                             * }*/

                            var max = pixelBuffer.Stride * size.Height / 4;

                            int *arr = (int *)pixelBuffer.Handle.ToPointer();
                            unchecked
                            {
                                var a = 0;
                                while (a < max)
                                {/*
                                  * arr = ((*arr & (int) 0xff000000) >> 0) +
                                  *        ((*arr & 0xff0000) >> 16) +
                                  *        ((*arr & 0xff00) << 0) +
                                  *        ((*arr & 0xff) << 16);
                                  * arr++;*/
                                    a++;
                                }
                            }

                            skPainted = true;
                        }
                    }
                }
                finally
                {
                    if (skPainted)
                    {
                        Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle);
                    }
                    User32Methods.EndPaint(hwnd, ref ps);
                }
            }