OLD | NEW |
1 Creating SkCanvas Objects | 1 Creating SkCanvas Objects |
2 ========================= | 2 ========================= |
3 | 3 |
4 First, read about [the SkCanvas API](skcanvas). | 4 First, read about [the SkCanvas API](skcanvas). |
5 | 5 |
6 Skia has multiple backends which receive SkCanvas drawing commands, | 6 Skia has multiple backends which receive SkCanvas drawing commands, |
7 including: | 7 including: |
8 | 8 |
9 - [Raster](#raster) - CPU-only. | 9 - [Raster](#raster) - CPU-only. |
10 - [Ganesh](#ganesh) - Skia's GPU-accelerated backend. | 10 - [Ganesh](#ganesh) - Skia's GPU-accelerated backend. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 #include "SkImage.h" | 83 #include "SkImage.h" |
84 #include "SkStream.h" | 84 #include "SkStream.h" |
85 #include "SkSurface.h" | 85 #include "SkSurface.h" |
86 void ganesh(int width, int height, | 86 void ganesh(int width, int height, |
87 void(*draw)(SkCanvas*), | 87 void(*draw)(SkCanvas*), |
88 const char* path) { | 88 const char* path) { |
89 GrContextFactory grFactory; | 89 GrContextFactory grFactory; |
90 GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextTy
pe); | 90 GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextTy
pe); |
91 SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height); | 91 SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height); |
92 SkAutoTUnref<SkSurface> gpuSurface( | 92 SkAutoTUnref<SkSurface> gpuSurface( |
93 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, inf
o)); | 93 SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info)); |
94 if (!gpuSurface) { | 94 if (!gpuSurface) { |
95 SkDebugf("SkSurface::NewRenderTarget returned null\n"); | 95 SkDebugf("SkSurface::NewRenderTarget returned null\n"); |
96 return; | 96 return; |
97 } | 97 } |
98 SkCanvas* gpuCanvas = gpuSurface->getCanvas(); | 98 SkCanvas* gpuCanvas = gpuSurface->getCanvas(); |
99 draw(gpuCanvas); | 99 draw(gpuCanvas); |
100 SkAutoTUnref<SkImage> img(s->newImageSnapshot()); | 100 SkAutoTUnref<SkImage> img(s->newImageSnapshot()); |
101 if (!img) { return; } | 101 if (!img) { return; } |
102 SkAutoTUnref<SkData> png(img->encode()); | 102 SkAutoTUnref<SkData> png(img->encode()); |
103 if (!png) { return; } | 103 if (!png) { return; } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 canvas->clear(SK_ColorWHITE); | 241 canvas->clear(SK_ColorWHITE); |
242 canvas->translate(0.5f * scale, 0.5f * scale); | 242 canvas->translate(0.5f * scale, 0.5f * scale); |
243 canvas->drawPath(path, p); | 243 canvas->drawPath(path, p); |
244 } | 244 } |
245 DEF_TEST(FourBackends, r) { | 245 DEF_TEST(FourBackends, r) { |
246 raster( 256, 256, example, "out_raster.png" ); | 246 raster( 256, 256, example, "out_raster.png" ); |
247 ganesh( 256, 256, example, "out_ganesh.png" ); | 247 ganesh( 256, 256, example, "out_ganesh.png" ); |
248 skpdf( 256, 256, example, "out_skpdf.pdf" ); | 248 skpdf( 256, 256, example, "out_skpdf.pdf" ); |
249 picture(256, 256, example, "out_picture.skp"); | 249 picture(256, 256, example, "out_picture.skp"); |
250 } | 250 } |
OLD | NEW |