<commit_before>{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- | State of the graphics system
module Haskus.Arch.Linux.Graphics.State
   ( GraphicsState (..)
   , readGraphicsState
   -- ** Entities
   , Controller (..)
   , Encoder(..)
   , EncoderType(..)
   , FrameBufferPos (..)
   , Connector (..)
   , Connection (..)
   , ConnectedDevice (..)
   , ConnectorType(..)
   , SubPixel(..)
   , Resources(..)
   , setController'
   , switchFrameBuffer'
   , getControllers
   , getControllerGamma
   , setControllerGamma
   , getEncoders
   , getEncoderFromID
   , getControllerFromID
   , fromStructController
   , getConnectorFromID
   , getResources
   , getEntities
   , pickEncoders
   , pickControllers
   , getPlaneResources
   , InvalidPlane (..)
   , Plane (..)
   , getPlane
   , setPlane
   , disablePlane
   , DestRect (..)
   , SrcRect (..)
   , InvalidDestRect (..)
   , InvalidSrcRect (..)
   )
where

import Haskus.Arch.Linux.Graphics.IDs
import Haskus.Arch.Linux.Graphics.Mode
import Haskus.Arch.Linux.Graphics.Property
import Haskus.Arch.Linux.Graphics.FrameBuffer
import Haskus.Arch.Linux.Graphics.PixelFormat
import Haskus.Arch.Linux.Internals.Graphics
import Haskus.Arch.Linux.ErrorCode
import Haskus.Arch.Linux.Error
import Haskus.Arch.Linux.Handle
import Haskus.Utils.Memory (peekArrays,allocaArrays,withArrays)
import Haskus.Utils.Flow
import Haskus.Utils.Variant
import Haskus.Format.Binary.Word
import Haskus.Format.Binary.Ptr
import Haskus.Format.Binary.Storable
import Haskus.Format.Binary.BitSet as BitSet
import Haskus.Format.Binary.Enum
import Haskus.Format.Binary.BitField
import Haskus.Format.Binary.FixedPoint
import Control.Monad (liftM2)
import qualified Data.Map as Map
import Data.Map (Map)


-- | Graph of graphics entities
data GraphicsState = GraphicsState
   { graphicsConnectors   :: Map ConnectorID   Connector
   , graphicsEncoders     :: Map EncoderID     Encoder
   , graphicsControllers  :: Map ControllerID  Controller
   , graphicsPlanes       :: Map PlaneID       Plane
   , graphicsFrameBuffers :: [FrameBufferID]
   }

-- | Graphic card ressources
data Resources = Resources
   { resFrameBufferIDs  :: [FrameBufferID]   -- ^ Frame buffer IDs
   , resControllerIDs   :: [ControllerID]    -- ^ Controller IDs
   , resConnectorIDs    :: [ConnectorID]     -- ^ Connector IDs
   , resEncoderIDs      :: [EncoderID]       -- ^ Encoder IDs
   , resMinWidth        :: Word32            -- ^ Minimal width
   , resMaxWidth        :: Word32            -- ^ Maximal width
   , resMinHeight       :: Word32            -- ^ Minimal height
   , resMaxHeight       :: Word32            -- ^ Maximal height
   } deriving (Show)

-- | An encoder
--
-- An encoder converts data obtained from the controller (i.e. from the frame
-- buffer associated with the controller) into suitable data for the connector
-- (i.e. for the device connected to the connector). Hence it only supports a
-- set of connectors. In addition, it may not work with all controllers.
data Encoder = Encoder
   { encoderID                  :: EncoderID          -- ^ Encoder identifier
   , encoderType                :: EncoderType        -- ^ Type of the encoder
   , encoderControllerID        :: Maybe ControllerID -- ^ Associated controller
   , encoderPossibleControllers :: [ControllerID]     -- ^ Valid controllers
   , encoderPossibleClones      :: [EncoderID]        -- ^ Valid clone encoders
   , encoderHandle              :: Handle             -- ^ Graphic card
   } deriving (Show)
<commit_msg>Add Show instance for GraphicsState<commit_after>{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- | State of the graphics system
module Haskus.Arch.Linux.Graphics.State
   ( GraphicsState (..)
   , readGraphicsState
   -- ** Entities
   , Controller (..)
   , Encoder(..)
   , EncoderType(..)
   , FrameBufferPos (..)
   , Connector (..)
   , Connection (..)
   , ConnectedDevice (..)
   , ConnectorType(..)
   , SubPixel(..)
   , Resources(..)
   , setController'
   , switchFrameBuffer'
   , getControllers
   , getControllerGamma
   , setControllerGamma
   , getEncoders
   , getEncoderFromID
   , getControllerFromID
   , fromStructController
   , getConnectorFromID
   , getResources
   , getEntities
   , pickEncoders
   , pickControllers
   , getPlaneResources
   , InvalidPlane (..)
   , Plane (..)
   , getPlane
   , setPlane
   , disablePlane
   , DestRect (..)
   , SrcRect (..)
   , InvalidDestRect (..)
   , InvalidSrcRect (..)
   )
where

import Haskus.Arch.Linux.Graphics.IDs
import Haskus.Arch.Linux.Graphics.Mode
import Haskus.Arch.Linux.Graphics.Property
import Haskus.Arch.Linux.Graphics.FrameBuffer
import Haskus.Arch.Linux.Graphics.PixelFormat
import Haskus.Arch.Linux.Internals.Graphics
import Haskus.Arch.Linux.ErrorCode
import Haskus.Arch.Linux.Error
import Haskus.Arch.Linux.Handle
import Haskus.Utils.Memory (peekArrays,allocaArrays,withArrays)
import Haskus.Utils.Flow
import Haskus.Utils.Variant
import Haskus.Format.Binary.Word
import Haskus.Format.Binary.Ptr
import Haskus.Format.Binary.Storable
import Haskus.Format.Binary.BitSet as BitSet
import Haskus.Format.Binary.Enum
import Haskus.Format.Binary.BitField
import Haskus.Format.Binary.FixedPoint
import Control.Monad (liftM2)
import qualified Data.Map as Map
import Data.Map (Map)


-- | Graph of graphics entities
data GraphicsState = GraphicsState
   { graphicsConnectors   :: Map ConnectorID   Connector  -- ^ Connectors
   , graphicsEncoders     :: Map EncoderID     Encoder    -- ^ Encoders
   , graphicsControllers  :: Map ControllerID  Controller -- ^ Controllers
   , graphicsPlanes       :: Map PlaneID       Plane      -- ^ Planes
   , graphicsFrameBuffers :: [FrameBufferID]              -- ^ Framebuffers
   } deriving (Show)

-- | Graphic card ressources
data Resources = Resources
   { resFrameBufferIDs  :: [FrameBufferID]   -- ^ Frame buffer IDs
   , resControllerIDs   :: [ControllerID]    -- ^ Controller IDs
   , resConnectorIDs    :: [ConnectorID]     -- ^ Connector IDs
   , resEncoderIDs      :: [EncoderID]       -- ^ Encoder IDs
   , resMinWidth        :: Word32            -- ^ Minimal width
   , resMaxWidth        :: Word32            -- ^ Maximal width
   , resMinHeight       :: Word32            -- ^ Minimal height
   , resMaxHeight       :: Word32            -- ^ Maximal height
   } deriving (Show)

-- | An encoder
--
-- An encoder converts data obtained from the controller (i.e. from the frame
-- buffer associated with the controller) into suitable data for the connector
-- (i.e. for the device connected to the connector). Hence it only supports a
-- set of connectors. In addition, it may not work with all controllers.
data Encoder = Encoder
   { encoderID                  :: EncoderID          -- ^ Encoder identifier
   , encoderType                :: EncoderType        -- ^ Type of the encoder
   , encoderControllerID        :: Maybe ControllerID -- ^ Associated controller
   , encoderPossibleControllers :: [ControllerID]     -- ^ Valid controllers
   , encoderPossibleClones      :: [EncoderID]        -- ^ Valid clone encoders
   , encoderHandle              :: Handle             -- ^ Graphic card
   } deriving (Show)

{'fraction_non_alphanumeric': 0.10565691035568972, 'fraction_numerical': 0.0023625147657172856, 'mean_word_length': 2.746312684365782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4322289', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2288, 'n_words': 537}