OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 paint->setTypeface(tf)->unref(); | 31 paint->setTypeface(tf)->unref(); |
32 return true; | 32 return true; |
33 } | 33 } |
34 return false; | 34 return false; |
35 } | 35 } |
36 | 36 |
37 #ifdef SK_BUILD_FOR_MAC | 37 #ifdef SK_BUILD_FOR_MAC |
38 #import <ApplicationServices/ApplicationServices.h> | 38 #import <ApplicationServices/ApplicationServices.h> |
39 #define BITMAP_INFO_RGB (kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Ho
st) | 39 #define BITMAP_INFO_RGB (kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Ho
st) |
40 | 40 |
41 static CGContextRef makeCG(const SkImageInfo& info, const void* addr, | 41 static CGContextRef makeCG(const SkBitmap& bm) { |
42 size_t rowBytes) { | 42 if (SkBitmap::kARGB_8888_Config != bm.config() || |
43 if (kPMColor_SkColorType != info.colorType() || NULL == addr) { | 43 NULL == bm.getPixels()) { |
44 return NULL; | 44 return NULL; |
45 } | 45 } |
46 CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); | 46 CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); |
47 CGContextRef cg = CGBitmapContextCreate((void*)addr, info.width(), info.heig
ht(), | 47 CGContextRef cg = CGBitmapContextCreate(bm.getPixels(), bm.width(), bm.heigh
t(), |
48 8, rowBytes, space, BITMAP_INFO_RGB)
; | 48 8, bm.rowBytes(), space, BITMAP_INFO
_RGB); |
49 CFRelease(space); | 49 CFRelease(space); |
50 | 50 |
51 CGContextSetAllowsFontSubpixelQuantization(cg, false); | 51 CGContextSetAllowsFontSubpixelQuantization(cg, false); |
52 CGContextSetShouldSubpixelQuantizeFonts(cg, false); | 52 CGContextSetShouldSubpixelQuantizeFonts(cg, false); |
53 | 53 |
54 return cg; | 54 return cg; |
55 } | 55 } |
56 | 56 |
57 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); | 57 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); |
58 | 58 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 canvas->clear(SK_ColorRED); | 137 canvas->clear(SK_ColorRED); |
138 SkPaint paint; | 138 SkPaint paint; |
139 paint.setShader(s)->unref(); | 139 paint.setShader(s)->unref(); |
140 SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) }; | 140 SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) }; |
141 canvas->drawRect(r, paint); | 141 canvas->drawRect(r, paint); |
142 } | 142 } |
143 | 143 |
144 virtual void onDraw(SkCanvas* canvas) { | 144 virtual void onDraw(SkCanvas* canvas) { |
145 #ifdef SK_BUILD_FOR_MAC | 145 #ifdef SK_BUILD_FOR_MAC |
146 CGContextRef cg = 0; | 146 CGContextRef cg = makeCG(canvas->getDevice()->accessBitmap(false)); |
147 { | |
148 SkImageInfo info; | |
149 size_t rowBytes; | |
150 const void* addr = canvas->peekPixels(&info, &rowBytes); | |
151 if (addr) { | |
152 cg = makeCG(info, addr, rowBytes); | |
153 } | |
154 } | |
155 #endif | 147 #endif |
156 | 148 |
157 drawGrad(canvas); | 149 drawGrad(canvas); |
158 | 150 |
159 const SkColor fg[] = { | 151 const SkColor fg[] = { |
160 0xFFFFFFFF, | 152 0xFFFFFFFF, |
161 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, | 153 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, |
162 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, | 154 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, |
163 0xFF000000, | 155 0xFF000000, |
164 }; | 156 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 private: | 193 private: |
202 typedef GM INHERITED; | 194 typedef GM INHERITED; |
203 }; | 195 }; |
204 | 196 |
205 ////////////////////////////////////////////////////////////////////////////// | 197 ////////////////////////////////////////////////////////////////////////////// |
206 | 198 |
207 static GM* MyFactory(void*) { return new GammaTextGM; } | 199 static GM* MyFactory(void*) { return new GammaTextGM; } |
208 static GMRegistry reg(MyFactory); | 200 static GMRegistry reg(MyFactory); |
209 | 201 |
210 } | 202 } |
OLD | NEW |