Beispiel #1
0
        void IRenderHandler.OnPaint(bool isPopup, Rect dirtyRect, IntPtr buffer, int width, int height, Image image)
        {
            //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + " ONPAINT " + isPopup + " " + buffer + " - " + width + "x" + height + " " + image.GetHashCode() + Environment.NewLine);
            if (image.Dispatcher.HasShutdownStarted ||
                (dirtyRect.X == 0 && dirtyRect.Y == 0 && dirtyRect.Width == 0 && dirtyRect.Height == 0))
            {
                return;
            }

            if (isPopup)
            {
                CurrentPopupRenderInfo = new RenderInfo(isPopup, dirtyRect, buffer, width, height, image);

                ReleaseMemoryMappedView(ref memoryMappedFile, ref memoryMappedViewAccessor);
                memoryMappedFile         = MemoryMappedFile.CreateNew(null, CurrentRenderInfo.NumberOfBytes, MemoryMappedFileAccess.ReadWrite);
                memoryMappedViewAccessor = memoryMappedFile.CreateViewAccessor();

                var data = texA.LockRectangle(0, LockFlags.ReadOnly);
                CopyMemoryGentle(data.DataPointer, memoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), CurrentRenderInfo.NumberOfBytes);
                texA.UnlockRectangle(0);

                ReleaseMemoryMappedView(ref popupMemoryMappedFile, ref popupMemoryMappedViewAccessor);
                popupMemoryMappedFile         = MemoryMappedFile.CreateNew(null, CurrentPopupRenderInfo.NumberOfBytes, MemoryMappedFileAccess.ReadWrite);
                popupMemoryMappedViewAccessor = popupMemoryMappedFile.CreateViewAccessor();
                CopyMemoryGentle(CurrentPopupRenderInfo.Buffer, popupMemoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), CurrentPopupRenderInfo.NumberOfBytes);

                DirectXRender(CurrentPopupRenderInfo);
            }
            else
            {
                CurrentRenderInfo.IsPopup   = isPopup;
                CurrentRenderInfo.DirtyRect = dirtyRect;
                CurrentRenderInfo.Buffer    = buffer;
                CurrentRenderInfo.Width     = width;
                CurrentRenderInfo.Height    = height;
                CurrentRenderInfo.Image     = image;
                DirectXRender(CurrentRenderInfo);
            }
        }
Beispiel #2
0
        private void CopyMemoryGentle(IntPtr source, IntPtr destination, Rect dirtyRect, RenderInfo info)
        {
            IntPtr newDestination = new IntPtr(destination.ToInt64() + dirtyRect.Y * info.Width * info.BytesPerPixel + dirtyRect.X * info.BytesPerPixel);
            IntPtr newSource      = new IntPtr(source.ToInt64() + dirtyRect.Y * info.Width * info.BytesPerPixel + dirtyRect.X * info.BytesPerPixel);
            int    length         = (dirtyRect.Height - 1) * info.Width * info.BytesPerPixel + dirtyRect.Width * info.BytesPerPixel;

            CopyMemory(newDestination, newSource, (uint)length);
        }
Beispiel #3
0
 private void CopyMemoryGentle(IntPtr source, IntPtr destination, RenderInfo popup, RenderInfo info)
 {
     for (int i = 0; i < popup.Height; i++)
     {
         CopyMemory(
             new IntPtr(destination.ToInt64() + (PopupPositionY + i) * info.Width * info.BytesPerPixel + PopupPositionX * popup.BytesPerPixel),
             new IntPtr(source.ToInt64() + i * popup.Width * popup.BytesPerPixel),
             (uint)(popup.Width * popup.BytesPerPixel));
     }
 }
Beispiel #4
0
        private void RenderData(RenderInfo renderInfo, bool forceChangeSource)
        {
            //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + " RenderData" + Environment.NewLine);

            var sec = DateTime.Now.Second;

            if (Framerate_LastSecond != sec)
            {
                Framerate_FramerateValue    = Framerate_FrameCountByDelta;
                Framerate_LastSecond        = sec;
                Framerate_FrameCountByDelta = 1;
            }
            else
            {
                Framerate_FrameCountByDelta++;
            }

            var data = texA.LockRectangle(0, LockFlags.None);

            if (!renderInfo.IsPopup)
            {
                //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + " !popup" + Environment.NewLine);
                //Case of popup
                if (popupMemoryMappedFile != null && PopupVisibility == true)
                {
                    CopyMemoryGentle(memoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), data.DataPointer, CurrentRenderInfo.NumberOfBytes);
                    CopyMemoryGentle(popupMemoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), data.DataPointer, CurrentPopupRenderInfo, renderInfo);
                    Debug.WriteLine("Popup case over redeaw");
                }
                ///After closing popup
                else if (popupMemoryMappedFile != null && PopupVisibility == false)
                {
                    CopyMemoryGentle(renderInfo.Buffer, data.DataPointer, renderInfo.NumberOfBytes);
                    ReleaseMemoryMappedView(ref popupMemoryMappedFile, ref popupMemoryMappedViewAccessor);
                    Debug.WriteLine("After closing popup " + renderInfo.NumberOfBytes);
                }
                else
                {
                    //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + "Global case posX:" + renderInfo.DirtyRect.X + " posY:" + renderInfo.DirtyRect.Y + " w:" + renderInfo.DirtyRect.Width + " h:" + renderInfo.DirtyRect.Height + Environment.NewLine);
                    CopyMemoryGentle(renderInfo.Buffer, data.DataPointer, renderInfo.DirtyRect, renderInfo);
                    Debug.WriteLine("Global case posX:" + renderInfo.DirtyRect.X + " posY:" + renderInfo.DirtyRect.Y + " w:" + renderInfo.DirtyRect.Width + " h:" + renderInfo.DirtyRect.Height);
                }
            }
            else
            {
                //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + " popup" + Environment.NewLine);
                CopyMemoryGentle(popupMemoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), data.DataPointer, CurrentPopupRenderInfo, CurrentRenderInfo);
                Debug.WriteLine("Popup case");
            }

            texA.UnlockRectangle(0);


            device9.Device.UpdateTexture(texA, tex);

            CurrentRenderInfo.Image.Dispatcher.BeginInvoke((Action)(() =>
            {
                //File.AppendAllText("DEBUG.txt", DateTime.Now.ToLongTimeString() + this.GetHashCode() + " InvalidateImageSource" + Environment.NewLine);

                InvalidateImageSource(forceChangeSource);
            }),
                                                           DispatcherPriority.Render);
        }