1/*
2 * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if USE(GLIB)
29#include <wtf/Function.h>
30#endif
31
32#if PLATFORM(MAC)
33#include <wtf/HashMap.h>
34
35OBJC_CLASS NSScreen;
36OBJC_CLASS NSWindow;
37#ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
38typedef struct CGRect NSRect;
39typedef struct CGPoint NSPoint;
40#else
41typedef struct _NSRect NSRect;
42typedef struct _NSPoint NSPoint;
43#endif
44#endif
45
46#if PLATFORM(IOS_FAMILY)
47OBJC_CLASS UIScreen;
48#endif
49
50#if USE(CG)
51typedef struct CGColorSpace *CGColorSpaceRef;
52#endif
53
54namespace WebCore {
55
56class FloatRect;
57class FloatSize;
58class Widget;
59
60using PlatformDisplayID = uint32_t;
61using IORegistryGPUID = int64_t; // Global IOKit I/O registryID that can match a GPU across process boundaries.
62
63int screenDepth(Widget*);
64int screenDepthPerComponent(Widget*);
65bool screenIsMonochrome(Widget*);
66
67bool screenHasInvertedColors();
68#if USE(GLIB)
69double screenDPI();
70void setScreenDPIObserverHandler(Function<void()>&&, void*);
71#endif
72
73FloatRect screenRect(Widget*);
74FloatRect screenAvailableRect(Widget*);
75
76WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* = nullptr);
77
78#if USE(CG)
79WEBCORE_EXPORT CGColorSpaceRef screenColorSpace(Widget* = nullptr);
80#endif
81
82#if PLATFORM(MAC)
83struct ScreenProperties;
84
85WEBCORE_EXPORT PlatformDisplayID displayID(NSScreen *);
86
87WEBCORE_EXPORT NSScreen *screen(NSWindow *);
88NSScreen *screen(PlatformDisplayID);
89
90FloatRect screenRectForDisplay(PlatformDisplayID);
91WEBCORE_EXPORT FloatRect screenRectForPrimaryScreen();
92
93WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&, NSWindow *destination);
94FloatRect toUserSpaceForPrimaryScreen(const NSRect&);
95WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source);
96
97NSPoint flipScreenPoint(const NSPoint&, NSScreen *);
98
99WEBCORE_EXPORT ScreenProperties collectScreenProperties();
100WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
101
102WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
103
104uint32_t primaryOpenGLDisplayMask();
105uint32_t displayMaskForDisplay(PlatformDisplayID);
106
107#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
108IORegistryGPUID primaryGPUID();
109IORegistryGPUID gpuIDForDisplay(PlatformDisplayID);
110IORegistryGPUID gpuIDForDisplayMask(uint32_t);
111#endif
112
113#endif // !PLATFORM(MAC)
114
115#if PLATFORM(IOS_FAMILY)
116
117float screenPPIFactor();
118WEBCORE_EXPORT FloatSize screenSize();
119WEBCORE_EXPORT FloatSize availableScreenSize();
120WEBCORE_EXPORT FloatSize overrideScreenSize();
121WEBCORE_EXPORT float screenScaleFactor(UIScreen * = nullptr);
122
123#endif
124
125#if ENABLE(TOUCH_EVENTS)
126#if PLATFORM(GTK) || PLATFORM(WPE)
127bool screenHasTouchDevice();
128bool screenIsTouchPrimaryInputDevice();
129#else
130constexpr bool screenHasTouchDevice() { return true; }
131constexpr bool screenIsTouchPrimaryInputDevice() { return true; }
132#endif
133#endif
134
135} // namespace WebCore
136