1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef _IOKIT_IODISPLAYWRANGLER_H
24#define _IOKIT_IODISPLAYWRANGLER_H
25
26#include <IOKit/IOService.h>
27#define IOFRAMEBUFFER_PRIVATE
28#include <IOKit/graphics/IOFramebuffer.h>
29#include <IOKit/graphics/IODisplay.h>
30
31class IODisplayWrangler : public IOService
32{
33    OSDeclareDefaultStructors( IODisplayWrangler );
34
35private:
36    bool        fOpen;
37    IOLock *    fMatchingLock;
38    OSSet *     fFramebuffers;
39    OSSet *     fDisplays;
40
41    // from control panel: number of idle minutes before going off
42    UInt32      fMinutesToDim;
43    // false: use minutesToDim unless in emergency situation
44    bool        fDimCaptured;
45    bool        fAnnoyed;
46
47    unsigned long fPendingPowerState;
48
49    // ignore activity until time
50    AbsoluteTime  fIdleUntil;
51    // annoyed wake until time
52    AbsoluteTime  fAnnoyanceUntil;
53
54    AbsoluteTime  fDimInterval;
55    AbsoluteTime  fSettingsChanged;
56    AbsoluteTime  fOffInterval[2];
57
58private:
59
60    virtual void initForPM( void );
61    virtual IOReturn setAggressiveness( unsigned long, unsigned long );
62    virtual bool activityTickle( unsigned long, unsigned long );
63    virtual IOReturn setPowerState( unsigned long powerStateOrdinal, IOService* whatDevice );
64
65    virtual unsigned long initialPowerStateForDomainState( IOPMPowerFlags domainState );
66
67    static bool _displayHandler( void * target, void * ref,
68                            IOService * newService, IONotifier * notifier );
69    static bool _displayConnectHandler( void * target, void * ref,
70                            IOService * newService, IONotifier * notifier );
71
72    virtual bool displayHandler( OSSet * set, IODisplay * newDisplay);
73    virtual bool displayConnectHandler( void * ref, IODisplayConnect * connect);
74
75    virtual IODisplayConnect * getDisplayConnect(
76                IOFramebuffer * fb, IOIndex connect );
77
78    virtual IOReturn getConnectFlagsForDisplayMode(
79                IODisplayConnect * connect,
80                IODisplayModeID mode, UInt32 * flags );
81
82public:
83
84    static bool serverStart(void);
85    virtual bool start(IOService * provider);
86
87    static bool makeDisplayConnects( IOFramebuffer * fb );
88    static void destroyDisplayConnects( IOFramebuffer * fb );
89    static void activityChange( IOFramebuffer * fb );
90    static unsigned long getDisplaysPowerState(void);
91
92    virtual OSObject * copyProperty( const char * aKey) const;
93
94    static IOReturn getFlagsForDisplayMode(
95                IOFramebuffer * fb,
96                IODisplayModeID mode, UInt32 * flags );
97
98    // Adaptive Dimming methods
99    virtual SInt32 nextIdleTimeout(AbsoluteTime currentTime,
100        AbsoluteTime lastActivity, unsigned int powerState);
101
102public:
103    virtual IOReturn setProperties( OSObject * properties );
104
105};
106
107void IODisplayUpdateNVRAM( IOService * entry, OSData * property );
108
109#endif /* _IOKIT_IODISPLAYWRANGLER_H */
110