--------------------------------------------------------------------------------
-- <auto-generated>                                                           --
--     This code was generated by a tool.                                     --
--                                                                            --
--     Changes to this file may cause incorrect behavior and will be lost if  --
--     the code is regenerated.                                               --
-- </auto-generated>                                                          --
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--                                                                            --
--    Copyright(c) 2018 Alexander Gamper, All Rights Reserved.                --
--                                                                            --
--    Ada-WinRT                                                               --
--                                                                            --
-- This program is free software: you can redistribute it and / or modify     --
-- it under the terms of the GNU Lesser General Public License as published by--
-- the Free Software Foundation, either version 3 of the License, or          --
-- (at your option) any later version.                                        --
--                                                                            --
-- This program is distributed in the hope that it will be useful,            --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               --
-- GNU Lesser General Public License for more details.                        --
--                                                                            --
-- You should have received a copy of the GNU Lesser General Public License   --
-- along with this program.If not, see http://www.gnu.org/licenses            --
--                                                                            --
--------------------------------------------------------------------------------
with Windows.Graphics;
with Windows.Graphics.DirectX;
with Windows.Graphics.DirectX.Direct3D11;
with Windows.System;
with Windows.UI.Composition;
with Ada.Unchecked_Conversion;
--------------------------------------------------------------------------------
package body Windows.Graphics.Capture is

   ------------------------------------------------------------------------
   -- Delegates/Events
   ------------------------------------------------------------------------
   
   function Invoke
   (
      This       : access AsyncOperationCompletedHandler_IGraphicsCaptureItem_Interface
      ; asyncInfo : Windows.Graphics.Capture.IAsyncOperation_IGraphicsCaptureItem
      ; asyncStatus : Windows.Foundation.AsyncStatus
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(asyncInfo, asyncStatus);
      return Hr;
   end;
   
   function Invoke
   (
      This       : access TypedEventHandler_IDirect3D11CaptureFramePool_add_FrameArrived_Interface
      ; sender : Windows.Graphics.Capture.IDirect3D11CaptureFramePool
      ; args : Windows.Object
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(Windows.Graphics.Capture.IDirect3D11CaptureFramePool(sender), args);
      return Hr;
   end;
   
   function Invoke
   (
      This       : access TypedEventHandler_IGraphicsCaptureItem_add_Closed_Interface
      ; sender : Windows.Graphics.Capture.IGraphicsCaptureItem
      ; args : Windows.Object
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(Windows.Graphics.Capture.IGraphicsCaptureItem(sender), args);
      return Hr;
   end;
   
   ------------------------------------------------------------------------
   -- Create functions (for activatable classes)
   ------------------------------------------------------------------------
   
   function Create return Windows.Graphics.Capture.IGraphicsCapturePicker is
      Hr            : Windows.HResult := S_OK;
      m_hString     : Windows.String := To_String("Windows.Graphics.Capture.GraphicsCapturePicker");
      Instance      : aliased IInspectable := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased IUnknown := null;
      function Convert is new Ada.Unchecked_Conversion(IUnknown , Windows.Graphics.Capture.IGraphicsCapturePicker) with inline;
   begin
      Hr := RoActivateInstance(m_hString, Instance'Address);
      if Hr = 0 then
         Hr := Instance.QueryInterface(Windows.Graphics.Capture.IID_IGraphicsCapturePicker'Access, RetVal'access);
         RefCount := Instance.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return Convert(RetVal);
   end;
   
   ------------------------------------------------------------------------
   -- Override Implementations
   ------------------------------------------------------------------------
   
   ------------------------------------------------------------------------
   -- Static procedures/functions
   ------------------------------------------------------------------------
   
   function Create
   (
      device : Windows.Graphics.DirectX.Direct3D11.IDirect3DDevice
      ; pixelFormat : Windows.Graphics.DirectX.DirectXPixelFormat
      ; numberOfBuffers : Windows.Int32
      ; size : Windows.Graphics.SizeInt32
   )
   return Windows.Graphics.Capture.IDirect3D11CaptureFramePool is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Graphics.Capture.Direct3D11CaptureFramePool");
      m_Factory     : IDirect3D11CaptureFramePoolStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Graphics.Capture.IDirect3D11CaptureFramePool;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IDirect3D11CaptureFramePoolStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.Create(device, pixelFormat, numberOfBuffers, size, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function CreateFreeThreaded
   (
      device : Windows.Graphics.DirectX.Direct3D11.IDirect3DDevice
      ; pixelFormat : Windows.Graphics.DirectX.DirectXPixelFormat
      ; numberOfBuffers : Windows.Int32
      ; size : Windows.Graphics.SizeInt32
   )
   return Windows.Graphics.Capture.IDirect3D11CaptureFramePool is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Graphics.Capture.Direct3D11CaptureFramePool");
      m_Factory     : IDirect3D11CaptureFramePoolStatics2 := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Graphics.Capture.IDirect3D11CaptureFramePool;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IDirect3D11CaptureFramePoolStatics2'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.CreateFreeThreaded(device, pixelFormat, numberOfBuffers, size, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function CreateFromVisual
   (
      visual : Windows.UI.Composition.IVisual
   )
   return Windows.Graphics.Capture.IGraphicsCaptureItem is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Graphics.Capture.GraphicsCaptureItem");
      m_Factory     : IGraphicsCaptureItemStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Graphics.Capture.IGraphicsCaptureItem;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IGraphicsCaptureItemStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.CreateFromVisual(visual, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function IsSupported
   return Windows.Boolean is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Graphics.Capture.GraphicsCaptureSession");
      m_Factory     : IGraphicsCaptureSessionStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Boolean;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IGraphicsCaptureSessionStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.IsSupported(RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
end;
