summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoramanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 21:51:10 +0000
committeramanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 21:51:10 +0000
commit265cf96b080c4196c268c0cc1a87186b0aee3b61 (patch)
tree820b7cd18d60618c2239da446c5b21678ca09280
parent172d0abca7044b8b5662f376a2645c22d2351c65 (diff)
downloadchromium_src-265cf96b080c4196c268c0cc1a87186b0aee3b61.zip
chromium_src-265cf96b080c4196c268c0cc1a87186b0aee3b61.tar.gz
chromium_src-265cf96b080c4196c268c0cc1a87186b0aee3b61.tar.bz2
Adjust color spaces so that Mac Chrome renders colors properly.
BUG=19951,20552 TEST=compare pages rendered in Chromium and Safari. They should appear the same. mark: review jrg/brettw: FYI Review URL: http://codereview.chromium.org/194013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25380 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mac_util.h8
-rw-r--r--base/mac_util.mm24
-rw-r--r--chrome/browser/renderer_host/backing_store_mac.mm14
-rw-r--r--chrome/plugin/webplugin_proxy.cc9
-rw-r--r--chrome/renderer/renderer_main_platform_delegate_mac.mm4
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc6
6 files changed, 47 insertions, 18 deletions
diff --git a/base/mac_util.h b/base/mac_util.h
index 96d77b2..2235377 100644
--- a/base/mac_util.h
+++ b/base/mac_util.h
@@ -51,6 +51,14 @@ OSType CreatorCodeForApplication();
// Returns the ~/Library directory.
FilePath GetUserLibraryPath();
+// Returns an sRGB color space. The return value is a static value; do not
+// release it!
+CGColorSpaceRef GetSRGBColorSpace();
+
+// Returns the color space being used by the main display. The return value
+// is a static value; do not release it!
+CGColorSpaceRef GetSystemColorSpace();
+
} // namespace mac_util
#endif // BASE_MAC_UTIL_H_
diff --git a/base/mac_util.mm b/base/mac_util.mm
index 1fce49a..ea43d11 100644
--- a/base/mac_util.mm
+++ b/base/mac_util.mm
@@ -104,5 +104,29 @@ FilePath GetUserLibraryPath() {
return FilePath(library_dir_path);
}
+CGColorSpaceRef GetSRGBColorSpace() {
+ // Leaked. That's OK, it's scoped to the lifetime of the application.
+ static CGColorSpaceRef g_color_space_sRGB =
+ CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ return g_color_space_sRGB;
+}
+
+CGColorSpaceRef GetSystemColorSpace() {
+ // Leaked. That's OK, it's scoped to the lifetime of the application.
+ static CGColorSpaceRef g_system_color_space = NULL;
+
+ if (!g_system_color_space) {
+ // Get the System Profile for the main display
+ CMProfileRef system_profile = NULL;
+ if (CMGetSystemProfile(&system_profile) == noErr) {
+ // Create a colorspace with the system profile
+ g_system_color_space =
+ CGColorSpaceCreateWithPlatformColorSpace(system_profile);
+ // Close the profile
+ CMCloseProfile(system_profile);
+ }
+ }
+ return g_system_color_space;
+}
} // namespace mac_util
diff --git a/chrome/browser/renderer_host/backing_store_mac.mm b/chrome/browser/renderer_host/backing_store_mac.mm
index c877a52..6a5a177a 100644
--- a/chrome/browser/renderer_host/backing_store_mac.mm
+++ b/chrome/browser/renderer_host/backing_store_mac.mm
@@ -9,6 +9,7 @@
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "base/logging.h"
+#include "base/mac_util.h"
#include "chrome/common/transport_dib.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -32,10 +33,8 @@ BackingStore::BackingStore(RenderWidgetHost* widget, const gfx::Size& size)
if (!containing_window) {
// If we are not in a containing window yet, create a CGBitmapContext
// to use as a stand-in for the layer.
- scoped_cftyperef<CGColorSpaceRef>
- color_space(CGColorSpaceCreateDeviceRGB());
cg_bitmap_.reset(CGBitmapContextCreate(NULL, size.width(), size.height(),
- 8, size.width() * 8, color_space,
+ 8, size.width() * 8, mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
} else {
CGContextRef context = static_cast<CGContextRef>(
@@ -57,13 +56,12 @@ size_t BackingStore::MemorySize() {
void BackingStore::PaintRect(base::ProcessHandle process,
TransportDIB* bitmap,
const gfx::Rect& bitmap_rect) {
- scoped_cftyperef<CGColorSpaceRef> color_space(CGColorSpaceCreateDeviceRGB());
scoped_cftyperef<CGDataProviderRef> data_provider(
CGDataProviderCreateWithData(NULL, bitmap->memory(),
bitmap_rect.width() * bitmap_rect.height() * 4, NULL));
scoped_cftyperef<CGImageRef> image(
CGImageCreate(bitmap_rect.width(), bitmap_rect.height(), 8, 32,
- 4 * bitmap_rect.width(), color_space,
+ 4 * bitmap_rect.width(), mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
data_provider, NULL, false, kCGRenderingIntentDefault));
@@ -111,8 +109,6 @@ void BackingStore::ScrollRect(base::ProcessHandle process,
int dx, int dy,
const gfx::Rect& clip_rect,
const gfx::Size& view_size) {
- if (!cg_layer()) return;
-
// "Scroll" the contents of the layer by creating a new CGLayer,
// copying the contents of the old one into the new one offset by the scroll
// amount, swapping in the new CGLayer, and then painting in the new data.
@@ -145,11 +141,9 @@ void BackingStore::ScrollRect(base::ProcessHandle process,
cg_layer_.swap(new_layer);
} else {
// We don't have a layer, so scroll the contents of the CGBitmapContext.
- scoped_cftyperef<CGColorSpaceRef>
- color_space(CGColorSpaceCreateDeviceRGB());
scoped_cftyperef<CGContextRef> new_bitmap(
CGBitmapContextCreate(NULL, size_.width(), size_.height(), 8,
- size_.width() * 8, color_space,
+ size_.width() * 8, mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
scoped_cftyperef<CGImageRef> bitmap_image(
CGBitmapContextCreateImage(cg_bitmap_));
diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc
index 739fc74..f2f5090 100644
--- a/chrome/plugin/webplugin_proxy.cc
+++ b/chrome/plugin/webplugin_proxy.cc
@@ -11,6 +11,9 @@
#include "app/win_util.h"
#endif
#include "base/gfx/blit.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
#include "base/scoped_handle.h"
#include "base/shared_memory.h"
#include "base/singleton.h"
@@ -562,14 +565,12 @@ void WebPluginProxy::SetWindowlessBuffer(
// and then use that to create a CGContextRef.
windowless_dib_.reset(TransportDIB::Map(windowless_buffer));
background_dib_.reset(TransportDIB::Map(background_buffer));
- scoped_cftyperef<CGColorSpaceRef> rgb_colorspace(
- CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
windowless_context_.reset(CGBitmapContextCreate(
windowless_dib_->memory(),
delegate_->GetRect().width(),
delegate_->GetRect().height(),
8, 4 * delegate_->GetRect().width(),
- rgb_colorspace,
+ mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst |
kCGBitmapByteOrder32Host));
CGContextTranslateCTM(windowless_context_, 0, delegate_->GetRect().height());
@@ -580,7 +581,7 @@ void WebPluginProxy::SetWindowlessBuffer(
delegate_->GetRect().width(),
delegate_->GetRect().height(),
8, 4 * delegate_->GetRect().width(),
- rgb_colorspace,
+ mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst |
kCGBitmapByteOrder32Host));
CGContextTranslateCTM(background_context_, 0,
diff --git a/chrome/renderer/renderer_main_platform_delegate_mac.mm b/chrome/renderer/renderer_main_platform_delegate_mac.mm
index a165909..c50a163 100644
--- a/chrome/renderer/renderer_main_platform_delegate_mac.mm
+++ b/chrome/renderer/renderer_main_platform_delegate_mac.mm
@@ -51,6 +51,10 @@ void SandboxWarmup() {
CGColorSpaceRelease(rgb_colorspace);
CGContextRelease(tmp);
+
+ // load in the color profiles we'll need (as a side effect).
+ (void) mac_util::GetSRGBColorSpace();
+ (void) mac_util::GetSystemColorSpace();
}
{ // [-NSColor colorUsingColorSpaceName] - 10.5.6
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index 56150ce..0f77406 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -6,6 +6,7 @@
#include <time.h>
+#include "base/mac_util.h"
#include "base/ref_counted.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkMatrix.h"
@@ -45,8 +46,6 @@ bool Constrain(int available_size, int* position, int *size) {
}
static CGContextRef CGContextForData(void* data, int width, int height) {
- CGColorSpaceRef color_space =
- CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
#define HAS_ARGB_SHIFTS(a, r, g, b) \
(SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
&& SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b))
@@ -55,7 +54,7 @@ static CGContextRef CGContextForData(void* data, int width, int height) {
// recommends these flags for improved CG performance.
CGContextRef context =
CGBitmapContextCreate(data, width, height, 8, width * 4,
- color_space,
+ mac_util::GetSystemColorSpace(),
kCGImageAlphaPremultipliedFirst |
kCGBitmapByteOrder32Host);
#else
@@ -63,7 +62,6 @@ static CGContextRef CGContextForData(void* data, int width, int height) {
image memory layout match.
#endif
#undef HAS_ARGB_SHIFTS
- CGColorSpaceRelease(color_space);
if (!context)
return NULL;