adding color management capabilities -- preffed off. bug 16769. patch from tor....
[mozilla-central.git] / gfx / thebes / src / gfxPlatformMac.cpp
blob6c76425f2e759bef30113cc02ef480f04101e806
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is thebes gfx code.
17 * The Initial Developer of the Original Code is Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Vladimir Vukicevic <vladimir@pobox.com>
23 * Masayuki Nakano <masayuki@d-toybox.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "gfxPlatformMac.h"
41 #include "gfxImageSurface.h"
42 #include "gfxQuartzSurface.h"
44 #include "gfxQuartzFontCache.h"
45 #include "gfxAtsuiFonts.h"
47 #ifdef MOZ_ENABLE_GLITZ
48 #include "gfxGlitzSurface.h"
49 #include "glitz-agl.h"
50 #endif
52 #include "lcms.h"
54 gfxPlatformMac::gfxPlatformMac()
56 #ifdef MOZ_ENABLE_GLITZ
57 if (UseGlitz())
58 glitz_agl_init();
59 #endif
62 already_AddRefed<gfxASurface>
63 gfxPlatformMac::CreateOffscreenSurface(const gfxIntSize& size,
64 gfxASurface::gfxImageFormat imageFormat)
66 gfxASurface *newSurface = nsnull;
68 if (!UseGlitz()) {
69 newSurface = new gfxQuartzSurface(size, imageFormat);
70 } else {
71 #ifdef MOZ_ENABLE_GLITZ
72 int bpp, glitzf;
73 switch (imageFormat) {
74 case gfxASurface::ImageFormatARGB32:
75 bpp = 32;
76 glitzf = 0; // GLITZ_STANDARD_ARGB32;
77 break;
78 case gfxASurface::ImageFormatRGB24:
79 bpp = 24;
80 glitzf = 1; // GLITZ_STANDARD_RGB24;
81 break;
82 case gfxASurface::ImageFormatA8:
83 bpp = 8;
84 glitzf = 2; // GLITZ_STANDARD_A8;
85 case gfxASurface::ImageFormatA1:
86 bpp = 1;
87 glitzf = 3; // GLITZ_STANDARD_A1;
88 break;
89 default:
90 return nsnull;
93 // XXX look for the right kind of format based on bpp
94 glitz_drawable_format_t templ;
95 memset(&templ, 0, sizeof(templ));
96 templ.color.red_size = 8;
97 templ.color.green_size = 8;
98 templ.color.blue_size = 8;
99 if (bpp == 32)
100 templ.color.alpha_size = 8;
101 else
102 templ.color.alpha_size = 0;
103 templ.doublebuffer = FALSE;
104 templ.samples = 1;
106 unsigned long mask =
107 GLITZ_FORMAT_RED_SIZE_MASK |
108 GLITZ_FORMAT_GREEN_SIZE_MASK |
109 GLITZ_FORMAT_BLUE_SIZE_MASK |
110 GLITZ_FORMAT_ALPHA_SIZE_MASK |
111 GLITZ_FORMAT_SAMPLES_MASK |
112 GLITZ_FORMAT_DOUBLEBUFFER_MASK;
114 glitz_drawable_format_t *gdformat =
115 glitz_agl_find_pbuffer_format(mask, &templ, 0);
117 glitz_drawable_t *gdraw =
118 glitz_agl_create_pbuffer_drawable(gdformat, width, height);
120 glitz_format_t *gformat =
121 glitz_find_standard_format(gdraw, (glitz_format_name_t) glitzf);
123 glitz_surface_t *gsurf =
124 glitz_surface_create(gdraw,
125 gformat,
126 width,
127 height,
129 NULL);
131 glitz_surface_attach(gsurf, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
133 newSurface = new gfxGlitzSurface(gdraw, gsurf, PR_TRUE);
134 #endif
137 NS_IF_ADDREF(newSurface);
138 return newSurface;
141 nsresult
142 gfxPlatformMac::ResolveFontName(const nsAString& aFontName,
143 FontResolverCallback aCallback,
144 void *aClosure, PRBool& aAborted)
146 nsAutoString resolvedName;
147 if (!gfxQuartzFontCache::SharedFontCache()->
148 ResolveFontName(aFontName, resolvedName)) {
149 aAborted = PR_FALSE;
150 return NS_OK;
152 aAborted = !(*aCallback)(resolvedName, aClosure);
153 return NS_OK;
156 gfxFontGroup *
157 gfxPlatformMac::CreateFontGroup(const nsAString &aFamilies,
158 const gfxFontStyle *aStyle)
160 return new gfxAtsuiFontGroup(aFamilies, aStyle);
163 nsresult
164 gfxPlatformMac::GetFontList(const nsACString& aLangGroup,
165 const nsACString& aGenericFamily,
166 nsStringArray& aListOfFonts)
168 gfxQuartzFontCache::SharedFontCache()->
169 GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
170 return NS_OK;
173 nsresult
174 gfxPlatformMac::UpdateFontList()
176 gfxQuartzFontCache::SharedFontCache()->UpdateFontList();
177 return NS_OK;
180 cmsHPROFILE
181 gfxPlatformMac::GetPlatformCMSOutputProfile()
183 CMProfileLocation device;
184 CMError err = CMGetDeviceProfile(cmDisplayDeviceClass,
185 cmDefaultDeviceID,
186 cmDefaultProfileID,
187 &device);
188 if (err != noErr)
189 return nsnull;
191 cmsHPROFILE profile = nsnull;
192 switch (device.locType) {
193 case cmFileBasedProfile: {
194 FSRef fsRef;
195 if (!FSpMakeFSRef(&device.u.fileLoc.spec, &fsRef)) {
196 char path[512];
197 if (!FSRefMakePath(&fsRef, (UInt8*)(path), sizeof(path))) {
198 profile = cmsOpenProfileFromFile(path, "r");
199 #ifdef DEBUG_tor
200 if (profile)
201 fprintf(stderr,
202 "ICM profile read from %s fileLoc successfully\n", path);
203 #endif
206 break;
208 case cmPathBasedProfile:
209 profile = cmsOpenProfileFromFile(device.u.pathLoc.path, "r");
210 #ifdef DEBUG_tor
211 if (profile)
212 fprintf(stderr,
213 "ICM profile read from %s pathLoc successfully\n",
214 device.u.pathLoc.path);
215 #endif
216 break;
217 default:
218 #ifdef DEBUG_tor
219 fprintf(stderr, "Unhandled ColorSync profile location\n");
220 #endif
221 break;
224 return profile;