Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
get_current_monitor_profile.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
10#if defined(SK_BUILD_FOR_MAC)
11#include <ApplicationServices/ApplicationServices.h>
12#elif defined(SK_BUILD_FOR_WIN)
13#include <windows.h>
14#endif
15
16int main(int argc, char** argv) {
17#if defined(SK_BUILD_FOR_MAC)
18 CGColorSpaceRef cs = CGDisplayCopyColorSpace(CGMainDisplayID());
19 CFDataRef dataRef = CGColorSpaceCopyICCProfile(cs);
20 const uint8_t* data = CFDataGetBytePtr(dataRef);
21 size_t size = CFDataGetLength(dataRef);
22
23 SkFILEWStream file("monitor_0.icc");
24 file.write(data, size);
25
26 CFRelease(cs);
27 CFRelease(dataRef);
28 return 0;
29#elif defined(SK_BUILD_FOR_WIN)
30 DISPLAY_DEVICE dd = { sizeof(DISPLAY_DEVICE) };
31 SkString outputFilename;
32
33 // Chrome's code for this currently just gets the primary monitor's profile. This code iterates
34 // over all attached monitors, so it's "better" in that sense. Making intelligent use of this
35 // information (via things like MonitorFromWindow or MonitorFromRect to pick the correct
36 // profile for a particular window or region of a window), is an exercise left to the reader.
37 for (int i = 0; EnumDisplayDevices(nullptr, i, &dd, 0); ++i) {
38 if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
39 // There are other helpful things in dd at this point:
40 // dd.DeviceString has a longer name for the adapter
41 // dd.StateFlags indicates primary display, mirroring, etc...
42 HDC dc = CreateDC(nullptr, dd.DeviceName, nullptr, nullptr);
43 if (dc) {
44 char icmPath[MAX_PATH + 1];
45 DWORD pathLength = MAX_PATH;
46 if (GetICMProfile(dc, &pathLength, icmPath)) {
47 // GetICMProfile just returns the path to the installed profile (not the data)
48 outputFilename = SkStringPrintf("monitor_%d.icc", i);
49 CopyFile(icmPath, outputFilename.c_str(), FALSE);
50 }
51 DeleteDC(dc);
52 }
53 }
54 }
55
56 return 0;
57#else
58 SkDebugf("ERROR: Unsupported platform\n");
59 return 1;
60#endif
61}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
const char * c_str() const
Definition SkString.h:133
return FALSE
Definition main.py:1
#define CopyFile
#define MAX_PATH
unsigned long DWORD