예제 #1
0
        public static Surface LoadFromGZippedBytes(string path)
        {
            using FileStream compressedData   = new(path, FileMode.Open);
            using GZipStream uncompressedData = new(compressedData, CompressionMode.Decompress);
            using MemoryStream resultBytes    = new();
            uncompressedData.CopyTo(resultBytes);

            byte[] bytes  = resultBytes.ToArray();
            int    width  = BitConverter.ToInt32(bytes, 0);
            int    height = BitConverter.ToInt32(bytes, 4);

            SKImageInfo info = new SKImageInfo(width, height, SKColorType.RgbaF16);
            var         ptr  = Marshal.AllocHGlobal(bytes.Length - 8);

            try
            {
                Marshal.Copy(bytes, 8, ptr, bytes.Length - 8);
                SKPixmap  map          = new(info, ptr);
                SKSurface surface      = SKSurface.Create(map);
                var       finalSurface = new Surface(width, height);
                surface.Draw(finalSurface.SkiaSurface.Canvas, 0, 0, Surface.ReplacingPaint);
                return(finalSurface);
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
 public void DrawSurface(SKSurface surface, float x, float y, SKPaint paint = null)
 {
     surface.Draw(canvas, x, y, paint);
     if (calculateBounds)
     {
         displayObject.addBoundingRect(x, y, canvas.LocalClipBounds.Width, canvas.LocalClipBounds.Height);
     }
 }
예제 #3
0
        void DrawBackground()
        {
            var backgroundOffset = GetBackgroundOffset();

            Background.Draw(Canvas, backgroundOffset.X, backgroundOffset.Y, null);
        }
예제 #4
0
        public void Visualize(SKCanvas canvas, SKRect rect)
        {
            // Initialize visualize cache if it has not yet been initialized.
            InitVisualizeSurface(rect);

            var cache_canvas = visualize_cache_surface_.Canvas;
            var paint        = new SKPaint();

            // Establish the graph position.
            float x      = 0f;
            float y      = 0f;
            float width  = rect.Width;
            float height = rect.Height;

            // Scale the graph to show frame times up to those that are 3 times the frame
            // time.
            float max_interval      = kOneFrameMS * 3.0f;
            float max_unit_interval = UnitFrameInterval(max_interval);

            float sample_unit_width = (1.0f / kMaxSamples);

            // Draw vertical replacement bar to erase old/stale pixels.
            paint.Color     = new SKColor(0x99FFFFFF);
            paint.Style     = SKPaintStyle.Fill;
            paint.BlendMode = SKBlendMode.Src;
            float sample_x    = x + width * ((float)prev_drawn_sample_index_ / kMaxSamples);
            var   eraser_rect = new SKRect(sample_x, y, sample_x + width * sample_unit_width, height);

            cache_canvas.DrawRect(eraser_rect, paint);

            // Draws blue timing bar for new data.
            paint.Color     = new SKColor(0xAA0000FF);
            paint.BlendMode = SKBlendMode.SrcOver;
            var bar_rect = new SKRect(
                sample_x,
                y + height *
                (1.0f - UnitHeight((float)laps_[current_sample_ == 0 ? kMaxSamples - 1 : current_sample_ - 1].TotalMilliseconds, max_unit_interval)),
                sample_x + width * sample_unit_width,
                height);

            cache_canvas.DrawRect(bar_rect, paint);

            // Draw horizontal frame markers.
            paint.StrokeWidth = 0; // hairline
            paint.Style       = SKPaintStyle.Stroke;
            paint.Color       = new SKColor(0xCC000000);

            if (max_interval > kOneFrameMS)
            {
                // Paint the horizontal markers
                int frame_marker_count = (int)(max_interval / kOneFrameMS);

                // Limit the number of markers displayed. After a certain point, the graph
                // becomes crowded
                if (frame_marker_count > kMaxFrameMarkers)
                {
                    frame_marker_count = 1;
                }

                for (int frame_index = 0; frame_index < frame_marker_count; frame_index++)
                {
                    float frame_height =
                        height * (1.0f - (UnitFrameInterval((frame_index + 1) * kOneFrameMS) / max_unit_interval));
                    cache_canvas.DrawLine(
                        x,
                        y + frame_height,
                        width,
                        y + frame_height,
                        paint);
                }
            }

            // Paint the vertical marker for the current frame.
            // We paint it over the current frame, not after it, because when we
            // paint this we don't yet have all the times for the current frame.
            paint.Style     = SKPaintStyle.Fill;
            paint.BlendMode = SKBlendMode.SrcOver;
            if (UnitFrameInterval((float)LastLap().TotalMilliseconds) > 1.0f)
            {
                // budget exceeded
                paint.Color = SKColors.Red;
            }
            else
            {
                // within budget
                paint.Color = SKColors.Green;
            }

            sample_x = x + width * ((float)current_sample_ / kMaxSamples);
            var marker_rect = new SKRect(
                sample_x,
                y,
                sample_x + width * sample_unit_width,
                height);

            cache_canvas.DrawRect(marker_rect, paint);
            prev_drawn_sample_index_ = current_sample_;

            // Draw the cached surface onto the output canvas.
            paint = new SKPaint();
            visualize_cache_surface_.Draw(canvas, rect.Left, rect.Top, paint);
        }