|
14 | 14 | #include "include/encode/SkWebpEncoder.h" |
15 | 15 | #include "include/gpu/GrDirectContext.h" |
16 | 16 | #include "include/gpu/gl/GrGLInterface.h" |
17 | | -#if defined(__linux__) |
18 | | -#include "include/gpu/gl/glx/GrGLMakeGLXInterface.h" |
19 | | -#include <X11/Xlib.h> |
20 | | -#include <GL/glx.h> |
21 | | -#include <GL/gl.h> |
22 | | -#endif |
23 | | - |
24 | | -#include "gpu/ganesh/gl/GrGLDirectContext.h" |
25 | | -#include "gpu/ganesh/SkSurfaceGanesh.h" |
26 | | -#include "gpu/ganesh/gl/GrGLBackendSurface.h" |
27 | | -#include "src/gpu/ganesh/gl/GrGLDefines.h" |
28 | | -#include "src/gpu/ganesh/gl/GrGLUtil.h" |
29 | | -//#include "SkBitmap.h" |
| 17 | + |
30 | 18 |
|
31 | 19 | #include "tracy/Tracy.hpp" |
32 | 20 |
|
|
36 | 24 | #include "marshalling/receive.h" |
37 | 25 | #include "marshalling/send.h" |
38 | 26 |
|
| 27 | +#define QOI_IMPLEMENTATION |
| 28 | +#define QOI_NO_STDIO |
| 29 | +#define QOI_FREE static_assert(false && "free should never be called") |
| 30 | +#define QOI_MALLOC(sz) qoi_malloc(sz) |
| 31 | +static void *qoi_malloc(size_t sz) { |
| 32 | + static void *qoiBuffer = nullptr; |
| 33 | + static size_t lastSz = 0; |
| 34 | + if(qoiBuffer == nullptr) { |
| 35 | + lastSz = sz; |
| 36 | + qoiBuffer = malloc(sz); |
| 37 | + } |
| 38 | + assert(lastSz == sz && "assuming constant width, height and depth of qoi images"); |
| 39 | + return qoiBuffer; |
| 40 | +} |
| 41 | +#include "qoi.h" |
| 42 | + |
39 | 43 | template <typename T> |
40 | 44 | static inline void applyFlag(int &flag,T val,bool v) { |
41 | 45 | if(v) { |
@@ -342,41 +346,72 @@ int App::Run(CliOptions &opts) { |
342 | 346 | options.fQuality = 70.0f; |
343 | 347 | } |
344 | 348 | auto stream = SkFILEWStream(opts.videoRawFramesFile); |
| 349 | + qoi_desc qd{ |
| 350 | + static_cast<unsigned int>(w), |
| 351 | + static_cast<unsigned int>(h), |
| 352 | + 4, |
| 353 | + QOI_SRGB |
| 354 | + }; |
| 355 | + char pamHeader[4096]; |
| 356 | + snprintf(pamHeader, sizeof(pamHeader), "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", w, h); |
| 357 | + auto pamHeaderLen = strlen(pamHeader); |
345 | 358 | while(!done) { |
346 | 359 | ImGui::NewFrame(); |
347 | 360 |
|
348 | 361 | ImGui::ShowMetricsWindow(); |
349 | 362 |
|
350 | 363 | sk_sp<SkImage> img(rasterSurface->makeImageSnapshot(SkIRect::MakeWH(w,h))); |
351 | | - if(true) { |
352 | | - { ZoneScoped; |
353 | | - auto canvas = rasterSurface->getCanvas(); |
354 | | - canvas->clear(clearColor); |
355 | | - Paint(rasterSurface.get(),w,h); // will call ImGui::Render(); |
356 | | - } |
357 | | - { ZoneScoped; |
358 | | - SkPixmap pixmap; |
359 | | - if(img->peekPixels(&pixmap)) { |
360 | | - if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) { |
361 | | - fprintf(stderr,"unable to encode frame as image. Skipping.\n"); |
| 364 | + { ZoneScoped; |
| 365 | + auto canvas = rasterSurface->getCanvas(); |
| 366 | + canvas->clear(clearColor); |
| 367 | + Paint(rasterSurface.get(),w,h); // will call ImGui::Render(); |
| 368 | + } |
| 369 | + switch(1) { |
| 370 | + case 0: |
| 371 | + { ZoneScoped; |
| 372 | + SkPixmap pixmap; |
| 373 | + if(img->peekPixels(&pixmap)) { |
| 374 | + if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) { |
| 375 | + fprintf(stderr,"unable to encode frame as image. Skipping.\n"); |
| 376 | + } |
362 | 377 | } |
363 | 378 | } |
364 | | - } |
365 | | - } else { |
366 | | - Paint(nullptr,w,h); // will call ImGui::Render(); |
367 | | - |
368 | | - snprintf(pathBuffer,sizeof(pathBuffer),"/tmp/video/out_%09u.flatbuffers",frame); |
369 | | - SkFILEWStream stream(pathBuffer); |
370 | | - |
371 | | - const ImDrawData* drawData = ImGui::GetDrawData(); |
372 | | - fTotalVectorCmdSerializedSize = 0; |
373 | | - for (int i = 0; i < drawData->CmdListsCount; ++i) { |
374 | | - ImDrawList* drawList = drawData->CmdLists[i]; |
375 | | - const uint8_t *buf; |
376 | | - size_t sz; |
377 | | - drawList->serializeFB(buf,sz); |
378 | | - stream.write(buf,sz); |
379 | | - } |
| 379 | + break; |
| 380 | + case 1: |
| 381 | + { ZoneScoped; |
| 382 | + SkPixmap pixmap; |
| 383 | + if (img->peekPixels(&pixmap)) { |
| 384 | + int imgLen; |
| 385 | + auto const imgMem = qoi_encode(pixmap.addr(), &qd, &imgLen); |
| 386 | + stream.write(imgMem, static_cast<size_t>(imgLen)); |
| 387 | + stream.flush(); |
| 388 | + } |
| 389 | + } |
| 390 | + break; |
| 391 | + case 2: |
| 392 | + { ZoneScoped; |
| 393 | + SkPixmap pixmap; |
| 394 | + if (img->peekPixels(&pixmap)) { |
| 395 | + stream.write(pamHeader, pamHeaderLen); |
| 396 | + stream.write(pixmap.addr(),pixmap.computeByteSize()); |
| 397 | + stream.flush(); |
| 398 | + } |
| 399 | + } |
| 400 | + break; |
| 401 | + case 3: |
| 402 | + { ZoneScoped; |
| 403 | + const ImDrawData* drawData = ImGui::GetDrawData(); |
| 404 | + fTotalVectorCmdSerializedSize = 0; |
| 405 | + for (int i = 0; i < drawData->CmdListsCount; ++i) { |
| 406 | + ImDrawList* drawList = drawData->CmdLists[i]; |
| 407 | + const uint8_t *buf; |
| 408 | + size_t sz; |
| 409 | + drawList->serializeFB(buf,sz); |
| 410 | + stream.write(buf,sz); |
| 411 | + } |
| 412 | + stream.flush(); |
| 413 | + } |
| 414 | + break; |
380 | 415 | } |
381 | 416 |
|
382 | 417 | { |
|
0 commit comments