Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: skia/ext/skia_utils_mac.mm

Issue 141037: Get our color channels straight. The reason why the color swap was required... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: ... Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "skia/ext/skia_utils_mac.h" 5 #include "skia/ext/skia_utils_mac.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_cftyperef.h" 10 #include "base/scoped_cftyperef.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return bitmap; // Return |bitmap| which should respond true to isNull(). 120 return bitmap; // Return |bitmap| which should respond true to isNull().
121 121
122 bitmap.setIsOpaque(is_opaque); 122 bitmap.setIsOpaque(is_opaque);
123 123
124 scoped_cftyperef<CGColorSpaceRef> color_space( 124 scoped_cftyperef<CGColorSpaceRef> color_space(
125 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); 125 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
126 void* data = bitmap.getPixels(); 126 void* data = bitmap.getPixels();
127 127
128 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple 128 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple
129 // recommends these flags for improved CG performance. 129 // recommends these flags for improved CG performance.
130 #define HAS_ARGB_SHIFTS(a, r, g, b) \
131 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
132 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b))
133 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
130 scoped_cftyperef<CGContextRef> context( 134 scoped_cftyperef<CGContextRef> context(
131 CGBitmapContextCreate(data, size.width, size.height, 8, size.width*4, 135 CGBitmapContextCreate(data, size.width, size.height, 8, size.width*4,
132 color_space, 136 color_space,
133 kCGImageAlphaPremultipliedFirst | 137 kCGImageAlphaPremultipliedFirst |
134 kCGBitmapByteOrder32Host)); 138 kCGBitmapByteOrder32Host));
139 #else
140 #error We require that Skia's and CoreGraphics's recommended \
141 image memory layout match.
142 #endif
143 #undef HAS_ARGB_SHIFTS
135 144
136 // Something went really wrong. Best guess is that the bitmap data is invalid. 145 // Something went really wrong. Best guess is that the bitmap data is invalid.
137 DCHECK(context != NULL); 146 DCHECK(context != NULL);
138 147
139 // Save the current graphics context so that we can restore it later. 148 // Save the current graphics context so that we can restore it later.
140 NSGraphicsContext* current_context = [NSGraphicsContext currentContext]; 149 NSGraphicsContext* current_context = [NSGraphicsContext currentContext];
141 150
142 // Dummy context that we will draw into. 151 // Dummy context that we will draw into.
143 NSGraphicsContext* context_cocoa = 152 NSGraphicsContext* context_cocoa =
144 [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]; 153 [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
145 [NSGraphicsContext setCurrentContext:context_cocoa]; 154 [NSGraphicsContext setCurrentContext:context_cocoa];
146 155
147 // This will stretch any images to |size| if it does not fit or is non-square. 156 // This will stretch any images to |size| if it does not fit or is non-square.
148 [image drawInRect:NSMakeRect(0, 0, size.width, size.height) 157 [image drawInRect:NSMakeRect(0, 0, size.width, size.height)
149 fromRect:NSZeroRect 158 fromRect:NSZeroRect
150 operation:NSCompositeCopy 159 operation:NSCompositeCopy
151 fraction:1.0]; 160 fraction:1.0];
152 161
153 // Done drawing, restore context. 162 // Done drawing, restore context.
154 [NSGraphicsContext setCurrentContext:current_context]; 163 [NSGraphicsContext setCurrentContext:current_context];
155 164
156 return bitmap; 165 return bitmap;
157 } 166 }
158 167
159 } // namespace gfx 168 } // namespace gfx
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698