summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa_common.m
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2015-01-07 18:47:27 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2015-01-07 18:47:27 +0100
commitf811348d0caabccdc72100c7d7d2f9df8332518a (patch)
tree99d41cf5ad4ffcda57f1b3fa4b8fe3d87d3f8fa5 /video/out/cocoa_common.m
parentd66598eeed10175b946fda8c76712714f578bb56 (diff)
downloadmpv-f811348d0caabccdc72100c7d7d2f9df8332518a.tar.bz2
mpv-f811348d0caabccdc72100c7d7d2f9df8332518a.tar.xz
vo_opengl: add support for in memory icc profiles
Previously we just forced loading a profile from file, but that has poor integration for querying the OS / display server for an ICC profile, and generating profiles on the fly (which we might use in the future for creating preset 3dluts). Also changed the previous icc-profile-auto code to use this mechanism, and moved gl_lcms to be an opaque type with state instead of just providing pure functions.
Diffstat (limited to 'video/out/cocoa_common.m')
-rw-r--r--video/out/cocoa_common.m122
1 files changed, 11 insertions, 111 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 6dcdc16bae..a893d0448a 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -52,7 +52,6 @@
#define cocoa_unlock(s) pthread_mutex_unlock(&s->mutex)
static void vo_cocoa_fullscreen(struct vo *vo);
-static void cocoa_change_profile(struct vo *vo, char **store, NSScreen *screen);
static void cocoa_rm_fs_screen_profile_observer(struct vo *vo);
struct vo_cocoa_state {
@@ -80,8 +79,8 @@ struct vo_cocoa_state {
uint32_t old_dwidth;
uint32_t old_dheight;
- char *icc_wnd_profile_path;
- char *icc_fs_profile_path;
+ NSData *icc_wnd_profile;
+ NSData *icc_fs_profile;
id fs_icc_changed_ns_observer;
void (*resize_redraw)(struct vo *vo, int w, int h);
@@ -420,7 +419,6 @@ static void cocoa_add_fs_screen_profile_observer(struct vo *vo)
return;
void (^nblock)(NSNotification *n) = ^(NSNotification *n) {
- cocoa_change_profile(vo, &s->icc_fs_profile_path, s->fs_screen);
s->pending_events |= VO_EVENT_ICC_PROFILE_PATH_CHANGED;
};
@@ -586,119 +584,22 @@ static void vo_cocoa_fullscreen(struct vo *vo)
draw_changes_after_next_frame(vo);
[(MpvEventsView *)s->view setFullScreen:opts->fullscreen];
- if (s->icc_fs_profile_path != s->icc_wnd_profile_path)
- s->pending_events = VO_EVENT_ICC_PROFILE_PATH_CHANGED;
-
+ s->pending_events |= VO_EVENT_ICC_PROFILE_PATH_CHANGED;
s->pending_events |= VO_EVENT_RESIZE;
}
-static char *cocoa_get_icc_profile_path(struct vo *vo, NSScreen *screen)
+static void vo_cocoa_control_get_icc_profile(struct vo *vo, void *arg)
{
- assert(screen);
-
struct vo_cocoa_state *s = vo->cocoa;
- char *result = NULL;
- CFDictionaryRef device_info = NULL;
-
- CGDirectDisplayID displayID = (CGDirectDisplayID)
- [[screen deviceDescription][@"NSScreenNumber"] unsignedLongValue];
-
- CFUUIDRef uuid = CGDisplayCreateUUIDFromDisplayID(displayID);
- if (CFGetTypeID(uuid) == CFNullGetTypeID()) {
- MP_ERR(s, "cannot get display UUID.\n");
- goto get_icc_profile_path_err_out;
- }
-
- device_info =
- ColorSyncDeviceCopyDeviceInfo(kColorSyncDisplayDeviceClass, uuid);
-
- CFRelease(uuid);
-
- if (!device_info) {
- MP_ERR(s, "cannot get display info.\n");
- goto get_icc_profile_path_err_out;
- }
-
- CFDictionaryRef factory_info =
- CFDictionaryGetValue(device_info, kColorSyncFactoryProfiles);
- if (!factory_info) {
- MP_ERR(s, "cannot get display factory settings.\n");
- goto get_icc_profile_path_err_out;
- }
-
- CFStringRef default_profile_id =
- CFDictionaryGetValue(factory_info, kColorSyncDeviceDefaultProfileID);
- if (!default_profile_id) {
- MP_ERR(s, "cannot get display default profile ID.\n");
- goto get_icc_profile_path_err_out;
- }
-
- CFURLRef icc_url;
- CFDictionaryRef custom_profile_info =
- CFDictionaryGetValue(device_info, kColorSyncCustomProfiles);
- if (custom_profile_info) {
- icc_url = CFDictionaryGetValue(custom_profile_info, default_profile_id);
- // If icc_url is NULL, the ICC profile URL could not be retrieved
- // although a custom profile was specified. This points to a
- // configuration error, so we should not fall back to the factory
- // profile, but return an error instead.
- if (!icc_url) {
- MP_ERR(s, "cannot get display profile URL\n");
- goto get_icc_profile_path_err_out;
- }
- } else {
- // No custom profile specified; try factory profile for the device
- CFDictionaryRef factory_profile_info =
- CFDictionaryGetValue(factory_info, default_profile_id);
- if (!factory_profile_info) {
- MP_ERR(s, "cannot get display profile info\n");
- goto get_icc_profile_path_err_out;
- }
-
- icc_url = CFDictionaryGetValue(factory_profile_info,
- kColorSyncDeviceProfileURL);
- if (!icc_url) {
- MP_ERR(s, "cannot get display factory profile URL.\n");
- goto get_icc_profile_path_err_out;
- }
- }
-
- result = talloc_strdup(vo, (char *)[[(NSURL *)icc_url path] UTF8String]);
- if (!result)
- MP_ERR(s, "cannot get display profile path.\n");
-
-get_icc_profile_path_err_out:
- CF_RELEASE(device_info);
- return result;
-}
-
-static void cocoa_change_profile(struct vo *vo, char **store, NSScreen *screen)
-{
- if (*store)
- talloc_free(*store);
- *store = cocoa_get_icc_profile_path(vo, screen);
-}
-
-static void vo_cocoa_control_get_icc_profile_path(struct vo *vo, void *arg)
-{
- struct vo_cocoa_state *s = vo->cocoa;
- char **p = arg;
+ bstr *p = arg;
vo_cocoa_update_screen_info(vo, NULL);
- NSScreen *screen;
- char **path;
-
- if (vo->opts->fullscreen) {
- screen = s->fs_screen;
- path = &s->icc_fs_profile_path;
- } else {
- screen = s->current_screen;
- path = &s->icc_wnd_profile_path;
- }
+ NSScreen *screen = vo->opts->fullscreen ? s->fs_screen : s->current_screen;
+ NSData *profile = [[screen colorSpace] ICCProfileData];
- cocoa_change_profile(vo, path, screen);
- *p = *path;
+ p->start = talloc_memdup(NULL, (void *)[profile bytes], [profile length]);
+ p->len = [profile length];
}
int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
@@ -740,8 +641,8 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
case VOCTRL_KILL_SCREENSAVER:
disable_power_management(vo);
return VO_TRUE;
- case VOCTRL_GET_ICC_PROFILE_PATH:
- vo_cocoa_control_get_icc_profile_path(vo, arg);
+ case VOCTRL_GET_ICC_PROFILE:
+ vo_cocoa_control_get_icc_profile(vo, arg);
return VO_TRUE;
}
return VO_NOTIMPL;
@@ -830,7 +731,6 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
- (void)didChangeWindowedScreenProfile:(NSScreen *)screen
{
struct vo_cocoa_state *s = self.vout->cocoa;
- cocoa_change_profile(self.vout, &s->icc_wnd_profile_path, screen);
s->pending_events |= VO_EVENT_ICC_PROFILE_PATH_CHANGED;
}
@end