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

Side by Side Diff: gm/aaclip.cpp

Issue 243463005: expose CGImage -> SkBitmap (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | « no previous file | include/utils/mac/SkCGUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 draw_rect_tests(canvas); 101 draw_rect_tests(canvas);
102 } 102 }
103 103
104 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } 104 virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; }
105 105
106 private: 106 private:
107 typedef skiagm::GM INHERITED; 107 typedef skiagm::GM INHERITED;
108 }; 108 };
109 109
110 DEF_GM( return SkNEW(AAClipGM); ) 110 DEF_GM( return SkNEW(AAClipGM); )
111
112 /////////////////////////////////////////////////////////////////////////
113
114 #ifdef SK_BUILD_FOR_MAC
115
116 static SkCanvas* make_canvas(const SkBitmap& bm) {
117 const SkImageInfo& info = bm.info();
118 if (info.bytesPerPixel() == 4) {
119 return SkCanvas::NewRasterDirectN32(info.width(), info.height(),
120 (SkPMColor*)bm.getPixels(),
121 bm.rowBytes());
122 } else {
123 return SkNEW_ARGS(SkCanvas, (bm));
124 }
125 }
126
127 #include "SkCGUtils.h"
128 static void test_image(SkCanvas* canvas, const SkImageInfo& info) {
129 SkBitmap bm;
130 bm.allocPixels(info);
131
132 SkAutoTUnref<SkCanvas> newc(make_canvas(bm));
133 if (info.isOpaque()) {
134 bm.eraseColor(SK_ColorGREEN);
135 } else {
136 bm.eraseColor(0);
137 }
138
139 SkPaint paint;
140 paint.setAntiAlias(true);
141 paint.setColor(SK_ColorBLUE);
142 newc->drawCircle(50, 50, 49, paint);
143 canvas->drawBitmap(bm, 10, 10);
144
145 CGImageRef image = SkCreateCGImageRefWithColorspace(bm, NULL);
146
147 SkBitmap bm2;
148 SkCreateBitmapFromCGImage(&bm2, image);
149 CGImageRelease(image);
150
151 canvas->drawBitmap(bm2, 10, 120);
152 }
153
154 class CGImageGM : public skiagm::GM {
155 public:
156 CGImageGM() {}
157
158 protected:
159 virtual SkString onShortName() SK_OVERRIDE {
160 return SkString("cgimage");
161 }
162
163 virtual SkISize onISize() SK_OVERRIDE {
164 return SkISize::Make(800, 250);
165 }
166
167 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
168 const struct {
169 SkColorType fCT;
170 SkAlphaType fAT;
171 } rec[] = {
172 { kRGB_565_SkColorType, kOpaque_SkAlphaType },
173
174 { kRGBA_8888_SkColorType, kPremul_SkAlphaType },
175 { kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
176 { kRGBA_8888_SkColorType, kOpaque_SkAlphaType },
177
178 { kBGRA_8888_SkColorType, kPremul_SkAlphaType },
179 { kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
180 { kBGRA_8888_SkColorType, kOpaque_SkAlphaType },
181 };
182
183 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
184 SkImageInfo info = SkImageInfo::Make(100, 100, rec[i].fCT, rec[i].fA T);
185 test_image(canvas, info);
186 canvas->translate(info.width() + 10, 0);
187 }
188 }
189
190 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPipe_Flag; }
191
192 private:
193 typedef skiagm::GM INHERITED;
194 };
195
196 DEF_GM( return SkNEW(CGImageGM); )
197
198 #endif
OLDNEW
« no previous file with comments | « no previous file | include/utils/mac/SkCGUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698