OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> |
9 | 10 |
10 #include <GL/osmesa.h> | 11 #include <GL/osmesa.h> |
11 | 12 |
12 #include "fiddle_main.h" | 13 #include "fiddle_main.h" |
13 | 14 |
14 // Globals externed in fiddle_main.h | 15 // Globals externed in fiddle_main.h |
15 SkBitmap source; | 16 SkBitmap source; |
16 sk_sp<SkImage> image; | 17 sk_sp<SkImage> image; |
17 | 18 |
18 static void encode_to_base64(const void* data, size_t size, FILE* out) { | 19 static void encode_to_base64(const void* data, size_t size, FILE* out) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return 1; | 105 return 1; |
105 } | 106 } |
106 SkAssertResult(image->asLegacyBitmap( | 107 SkAssertResult(image->asLegacyBitmap( |
107 &source, SkImage::kRO_LegacyBitmapMode)); | 108 &source, SkImage::kRO_LegacyBitmapMode)); |
108 } | 109 } |
109 } | 110 } |
110 sk_sp<SkData> rasterData, gpuData, pdfData, skpData; | 111 sk_sp<SkData> rasterData, gpuData, pdfData, skpData; |
111 if (options.raster) { | 112 if (options.raster) { |
112 auto rasterSurface = | 113 auto rasterSurface = |
113 SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(options.size)); | 114 SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(options.size)); |
| 115 srand(0); |
114 draw(rasterSurface->getCanvas()); | 116 draw(rasterSurface->getCanvas()); |
115 rasterData.reset(encode_snapshot(rasterSurface)); | 117 rasterData.reset(encode_snapshot(rasterSurface)); |
116 } | 118 } |
117 if (options.gpu) { | 119 if (options.gpu) { |
118 OSMesaContext osMesaContext = create_osmesa_context(); | 120 OSMesaContext osMesaContext = create_osmesa_context(); |
119 auto grContext = create_mesa_grcontext(); | 121 auto grContext = create_mesa_grcontext(); |
120 if (!grContext) { | 122 if (!grContext) { |
121 fputs("Unable to get Mesa GrContext.\n", stderr); | 123 fputs("Unable to get Mesa GrContext.\n", stderr); |
122 } else { | 124 } else { |
123 auto surface = SkSurface::MakeRenderTarget( | 125 auto surface = SkSurface::MakeRenderTarget( |
124 grContext.get(), | 126 grContext.get(), |
125 SkBudgeted::kNo, | 127 SkBudgeted::kNo, |
126 SkImageInfo::MakeN32Premul(options.size)); | 128 SkImageInfo::MakeN32Premul(options.size)); |
127 if (!surface) { | 129 if (!surface) { |
128 fputs("Unable to get render surface.\n", stderr); | 130 fputs("Unable to get render surface.\n", stderr); |
129 exit(1); | 131 exit(1); |
130 } | 132 } |
| 133 srand(0); |
131 draw(surface->getCanvas()); | 134 draw(surface->getCanvas()); |
132 gpuData.reset(encode_snapshot(surface)); | 135 gpuData.reset(encode_snapshot(surface)); |
133 } | 136 } |
134 if (osMesaContext) { | 137 if (osMesaContext) { |
135 OSMesaDestroyContext(osMesaContext); | 138 OSMesaDestroyContext(osMesaContext); |
136 } | 139 } |
137 } | 140 } |
138 if (options.pdf) { | 141 if (options.pdf) { |
139 SkDynamicMemoryWStream pdfStream; | 142 SkDynamicMemoryWStream pdfStream; |
140 sk_sp<SkDocument> document(SkDocument::MakePDF(&pdfStream)); | 143 sk_sp<SkDocument> document(SkDocument::MakePDF(&pdfStream)); |
| 144 srand(0); |
141 draw(document->beginPage(options.size.width(), options.size.height())); | 145 draw(document->beginPage(options.size.width(), options.size.height())); |
142 document->close(); | 146 document->close(); |
143 pdfData.reset(pdfStream.copyToData()); | 147 pdfData.reset(pdfStream.copyToData()); |
144 } | 148 } |
145 if (options.skp) { | 149 if (options.skp) { |
146 SkSize size; | 150 SkSize size; |
147 size = options.size; | 151 size = options.size; |
148 SkPictureRecorder recorder; | 152 SkPictureRecorder recorder; |
| 153 srand(0); |
149 draw(recorder.beginRecording(size.width(), size.height())); | 154 draw(recorder.beginRecording(size.width(), size.height())); |
150 auto picture = recorder.finishRecordingAsPicture(); | 155 auto picture = recorder.finishRecordingAsPicture(); |
151 SkDynamicMemoryWStream skpStream; | 156 SkDynamicMemoryWStream skpStream; |
152 picture->serialize(&skpStream); | 157 picture->serialize(&skpStream); |
153 skpData.reset(skpStream.copyToData()); | 158 skpData.reset(skpStream.copyToData()); |
154 } | 159 } |
155 | 160 |
156 printf("{\n"); | 161 printf("{\n"); |
157 dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData); | 162 dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData); |
158 dump_output(gpuData, "Gpu", !pdfData && !skpData); | 163 dump_output(gpuData, "Gpu", !pdfData && !skpData); |
159 dump_output(pdfData, "Pdf", !skpData); | 164 dump_output(pdfData, "Pdf", !skpData); |
160 dump_output(skpData, "Skp"); | 165 dump_output(skpData, "Skp"); |
161 printf("}\n"); | 166 printf("}\n"); |
162 | 167 |
163 return 0; | 168 return 0; |
164 } | 169 } |
OLD | NEW |