File indexing completed on 2024-04-28 12:07:01

0001 /********************************************************************
0002  KolorServer - color server based on the X Color Management Specification
0003  This file is part of the KDE project.
0004 
0005 Copyright (C) 2012 Casian Andrei <skeletk13@gmail.com>
0006 
0007 Redistribution and use in source and binary forms, with or without
0008 modification, are permitted provided that the following conditions
0009 are met:
0010 
0011 1. Redistributions of source code must retain the above copyright
0012    notice, this list of conditions and the following disclaimer.
0013 2. Redistributions in binary form must reproduce the above copyright
0014    notice, this list of conditions and the following disclaimer in the
0015    documentation and/or other materials provided with the distribution.
0016 
0017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 *********************************************************************/
0028 
0029 #ifndef KOLOR_SERVER_SCREEN_H_
0030 #define KOLOR_SERVER_SCREEN_H_
0031 
0032 #include "color-lookup-table.h"
0033 #include "x11-helpers.h"
0034 
0035 namespace KolorServer
0036 {
0037 
0038 class ColorOutput;
0039 class Display;
0040 
0041 /**
0042  * X11 Screen
0043  *
0044  * May have multiple outputs.
0045  *
0046  * \note PrivScreen
0047  *
0048  * \todo privatize some of those methods
0049  * \todo review the atoms and profiles stuff
0050  */
0051 class Screen : public QObject
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056     /**
0057      * \note pluginInitScreen
0058      * - init empty list for outputs
0059      * - init Xrandr stuff (like property notify)
0060      */
0061     Screen(X11::Display *display, int number, KolorServer::Display *parent);
0062 
0063     /**
0064      * \note pluginFiniScreen
0065      * \warning Only in CompICC:
0066      * - get all devices from Oyranos
0067      * - for each device call moveICCprofileAtoms
0068      * - call freeOutput
0069      *
0070      * Destroys all associated outputs.
0071      */
0072     virtual ~Screen();
0073 
0074     /**
0075      * \return The X11 display associated with this screen
0076      */
0077     X11::Display *display() const;
0078 
0079     /**
0080      * \return The X11 screen number
0081      */
0082     int screenNumber() const;
0083 
0084     /**
0085      * \return The X11 root window associated with this screen
0086      */
0087     X11::Window rootWindow() const;
0088 
0089     /**
0090      * \return A list with the color lookup tables for all the outputs.
0091      */
0092     const ClutList& outputCluts() const;
0093 
0094     /**
0095      * \return A map of region-specific lookup tables to window XID's.
0096      */
0097     const RegionalClutMap& regionCluts() const;
0098 
0099     /**
0100      * \note cleanDisplayProfiles
0101      * - get number of connected devices
0102      * - for each output, if it has a profile, clean it with cleanScreenProfile
0103      *
0104      * Used by: setupOutputs
0105      */
0106     void cleanProfileAtoms();
0107 
0108     /**
0109      * \note freeOutput
0110      * \warning Only in CompICC
0111      * - go through all contexts
0112      * - free their dst profiles (destroy them?)
0113      * - clear the contexts list
0114      *
0115      * Used by: setupOutputs, pluginFiniScreen
0116      */
0117     void cleanOutputs();
0118 
0119     /**
0120      * \note setupOutputs
0121      * \warning Only in CompICC
0122      * - call freeOutput
0123      * - call cleanDisplayProfiles
0124      * - redo contexts - init n empty contexts
0125      * - call cleanDisplay
0126      *
0127      * Used by: pluginHandleEvent on netDesktopGeometry, randr output change, initialize
0128      */
0129     void setupOutputs();
0130 
0131     /**
0132      * \note updateOutputConfiguration
0133      * - list devices using Oyranos
0134      * - for each device
0135      *  - on init, call getDeviceProfile
0136      *  - if a dst_profile appears on that context, call moveICCprofileAtoms
0137      *  - call setupOutputTable on that device
0138      *
0139      * Used by: pluginHandleEvent
0140      */
0141     void updateOutputConfiguration(bool init);
0142 
0143     /**
0144      * \note updateScreenProfiles
0145      * - get profiles data from display property (whole)
0146      * - separate them and iterate (with Xcolor)
0147      * - add them to the oyHash
0148      *
0149      * " Called when new profiles have been attached to the root window. Fetches
0150      * these and saves them in a local database."
0151      *
0152      * Used by: property notify event, iccColorProfiles atom
0153      *
0154      * "_ICC_COLOR_PROFILES:
0155      * Is used to upload color profiles to the compositing manager. Clients attach a
0156      * a list of one or more XColorProfile to the root window. Compositing manager then
0157      * fetches the list and saves the profiles in an internal database and deletes the
0158      * property."
0159      */
0160     void updateProfiles();
0161 
0162     /**
0163      * Updates the profile for an output deduced from \param atomName,
0164      * with the new profile data being in \param atom. Tries to conform
0165      * to the XCM spec.
0166      * \see Display::handleEvent
0167      */
0168     void updateProfileForAtom(const char *atomName, X11::Atom atom);
0169 
0170     /**
0171      * \return The number of outputs that have a valid profile set up.
0172      */
0173     int profileCount() const;
0174 
0175 signals:
0176     void outputClutsChanged();
0177 
0178 private:
0179     Display *m_parent;
0180     X11::Display *m_display;
0181     int m_screen;
0182     int icc_profile_flags;              ///< profile selection flags from oyProfile_s.h
0183 
0184     QList<ColorOutput*> m_outputs; // or contexts
0185 
0186 private:
0187     ClutList m_outputCluts;
0188     RegionalClutMap m_regionCluts;     // TODO
0189 };
0190 
0191 } // KolorServer namespace
0192 
0193 #endif // KOLOR_SERVER_SCREEN_H_