< Summary

Class:Imagini.App2D
Assembly:Imagini.2D
File(s):/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/App2D.cs
Covered lines:22
Uncovered lines:1
Coverable lines:23
Total lines:81
Line coverage:95.6% (22 of 23)
Covered branches:11
Total branches:12
Branch coverage:91.6% (11 of 12)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)40100%100%
UpdateSurface()2080%50%
AfterDraw(...)20100%100%
OnDispose()40100%100%

File(s)

/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/App2D.cs

#LineLine coverage
 1using System;
 2using Imagini.Drawing;
 3using static SDL2.SDL_error;
 4using static SDL2.SDL_render;
 5using static SDL2.SDL_video;
 6
 7namespace Imagini
 8{
 9    /// <summary>
 10    /// Main class which instantiates a window, an event loop and a
 11    /// 2D accelerated renderer.
 12    /// </summary>
 13    public abstract class App2D : AppBase
 14    {
 15        /// <summary>
 16        /// Provides access to hardware accelerated drawing functions for the app's window.
 17        /// If software renderer is used, returns null.
 18        /// </summary>
 41419        public Graphics Graphics { get; private set; }
 20
 21        /// <summary>
 22        /// Returns the window surface used for software rendering.
 23        /// If a hardware renderer is used, returns null.
 24        /// </summary>
 6825        public Surface Surface { get; private set; }
 26
 27        /// <summary>
 28        /// Gets or sets if this app uses hardware acceleration.
 29        /// </summary>
 30        /// <returns></returns>
 6631        public bool IsHardwareAccelerated { get; private set; }
 32
 33        private readonly bool _useSurfaceApi = false;
 34
 35        /// <summary>
 36        /// Creates a new app with the specified window settings.
 37        /// </summary>
 38        /// <remarks>
 39        /// If you have your own constructor, make sure to call this
 40        /// one because it initializes the window and the event queue.
 41        /// </remarks>
 42        /// <param name="driver">Specifies a renderer to be used. If null, first hardware-accelerated renderer is used.<
 43        /// <param name="useSurfaceApi">If true, initializes <see cref="Surface" /> instead of <see cref="Graphics" /></
 44        public App2D(WindowSettings settings = null, RendererInfo driver = null,
 6445            bool useSurfaceApi = false) : base(settings)
 46        {
 6447            _useSurfaceApi = useSurfaceApi;
 6448            IsHardwareAccelerated = driver?.IsHardwareAccelerated ?? true;
 6449            if (!useSurfaceApi)
 6350                Graphics = new Graphics(Window, driver);
 51            else
 52            {
 253                Resized += (s, e) => UpdateSurface();
 154                UpdateSurface();
 55            }
 156        }
 57
 58        private void UpdateSurface()
 59        {
 260            var handle = SDL_GetWindowSurface(Window.Handle);
 261            if (handle == IntPtr.Zero)
 062                throw new ImaginiException($"Could not obtain window surface: {SDL_GetError()}");
 263            Surface = new Surface(handle);
 264        }
 65
 66        protected override void AfterDraw(TimeSpan frameTime)
 67        {
 8368            if (!_useSurfaceApi)
 8269                SDL_RenderPresent(Graphics.Handle);
 70            else
 171                SDL_UpdateWindowSurface(Window.Handle);
 172        }
 73
 74        protected override void OnDispose()
 75        {
 6476            Graphics?.Destroy();
 6477            Surface?.Dispose();
 178        }
 79    }
 80
 81}