| 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 | 9 |
| 10 #include <GL/osmesa.h> | 10 #include <GL/osmesa.h> |
| 11 | 11 |
| 12 #include "fiddle_main.h" | 12 #include "fiddle_main.h" |
| 13 | 13 |
| 14 // Globals externed in fiddle_main.h | 14 // Globals externed in fiddle_main.h |
| 15 SkBitmap source; | 15 SkBitmap source; |
| 16 SkImage* image(nullptr); | 16 sk_sp<SkImage> image; |
| 17 | 17 |
| 18 static void encode_to_base64(const void* data, size_t size, FILE* out) { | 18 static void encode_to_base64(const void* data, size_t size, FILE* out) { |
| 19 const uint8_t* input = reinterpret_cast<const uint8_t*>(data); | 19 const uint8_t* input = reinterpret_cast<const uint8_t*>(data); |
| 20 const uint8_t* end = &input[size]; | 20 const uint8_t* end = &input[size]; |
| 21 static const char codes[] = | 21 static const char codes[] = |
| 22 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 22 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 23 "abcdefghijklmnopqrstuvwxyz0123456789+/"; | 23 "abcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 24 while (input != end) { | 24 while (input != end) { |
| 25 uint8_t b = (*input & 0xFC) >> 2; | 25 uint8_t b = (*input & 0xFC) >> 2; |
| 26 fputc(codes[b], out); | 26 fputc(codes[b], out); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 static void dump_output(const sk_sp<SkData>& data, | 51 static void dump_output(const sk_sp<SkData>& data, |
| 52 const char* name, bool last = true) { | 52 const char* name, bool last = true) { |
| 53 if (data) { | 53 if (data) { |
| 54 printf("\t\"%s\": \"", name); | 54 printf("\t\"%s\": \"", name); |
| 55 encode_to_base64(data->data(), data->size(), stdout); | 55 encode_to_base64(data->data(), data->size(), stdout); |
| 56 fputs(last ? "\"\n" : "\",\n", stdout); | 56 fputs(last ? "\"\n" : "\",\n", stdout); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) { | 60 static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) { |
| 61 sk_sp<SkImage> img(surface->newImageSnapshot()); | 61 sk_sp<SkImage> img(surface->makeImageSnapshot()); |
| 62 return img ? img->encode() : nullptr; | 62 return img ? img->encode() : nullptr; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static OSMesaContext create_osmesa_context() { | 65 static OSMesaContext create_osmesa_context() { |
| 66 OSMesaContext osMesaContext = | 66 OSMesaContext osMesaContext = |
| 67 OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr); | 67 OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr); |
| 68 if (osMesaContext != nullptr) { | 68 if (osMesaContext != nullptr) { |
| 69 static uint32_t buffer[16 * 16]; | 69 static uint32_t buffer[16 * 16]; |
| 70 OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16); | 70 OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16); |
| 71 } | 71 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 int main() { | 93 int main() { |
| 94 const DrawOptions options = GetDrawOptions(); | 94 const DrawOptions options = GetDrawOptions(); |
| 95 if (options.source) { | 95 if (options.source) { |
| 96 sk_sp<SkData> data(SkData::NewFromFileName(options.source)); | 96 sk_sp<SkData> data(SkData::NewFromFileName(options.source)); |
| 97 if (!data) { | 97 if (!data) { |
| 98 perror(options.source); | 98 perror(options.source); |
| 99 return 1; | 99 return 1; |
| 100 } else { | 100 } else { |
| 101 image = SkImage::NewFromEncoded(data.get()); | 101 image = SkImage::MakeFromEncoded(std::move(data)); |
| 102 if (!image) { | 102 if (!image) { |
| 103 perror("Unable to decode the source image."); | 103 perror("Unable to decode the source image."); |
| 104 return 1; | 104 return 1; |
| 105 } | 105 } |
| 106 SkAssertResult(image->asLegacyBitmap( | 106 SkAssertResult(image->asLegacyBitmap( |
| 107 &source, SkImage::kRO_LegacyBitmapMode)); | 107 &source, SkImage::kRO_LegacyBitmapMode)); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 sk_sp<SkData> rasterData, gpuData, pdfData, skpData; | 110 sk_sp<SkData> rasterData, gpuData, pdfData, skpData; |
| 111 if (options.raster) { | 111 if (options.raster) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 skpData.reset(skpStream.copyToData()); | 153 skpData.reset(skpStream.copyToData()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 printf("{\n"); | 156 printf("{\n"); |
| 157 dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData); | 157 dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData); |
| 158 dump_output(gpuData, "Gpu", !pdfData && !skpData); | 158 dump_output(gpuData, "Gpu", !pdfData && !skpData); |
| 159 dump_output(pdfData, "Pdf", !skpData); | 159 dump_output(pdfData, "Pdf", !skpData); |
| 160 dump_output(skpData, "Skp"); | 160 dump_output(skpData, "Skp"); |
| 161 printf("}\n"); | 161 printf("}\n"); |
| 162 | 162 |
| 163 SkSafeSetNull(image); | |
| 164 return 0; | 163 return 0; |
| 165 } | 164 } |
| OLD | NEW |