6 #include "debugscript.h"
14 extern const char *script_filename;
16 inline void OverlayBMP(Document & doc, const char * input, const char * output, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f))
20 View view(doc, scr, bounds, c);
25 scr.ScreenShot(output);
29 // It is the only way.
30 // Dear god what have I done
31 void RatCatcher(int x, int y, int buttons, int wheel, Screen * scr, View * view)
33 static bool oldButtonDown = false;
34 static int oldx, oldy;
35 if (buttons == 3 && !oldButtonDown)
38 view->ToggleGPUTransform();
43 if (buttons == 2 && !oldButtonDown)
46 view->ToggleGPURendering();
50 if (buttons && !oldButtonDown)
52 // We're beginning a drag.
56 scr->SetMouseCursor(Screen::CursorMove);
60 view->Translate(Real(oldx-x)/Real(scr->ViewportWidth()), Real(oldy-y)/Real(scr->ViewportHeight()));
64 oldButtonDown = false;
65 scr->SetMouseCursor(Screen::CursorArrow);
72 view->ScaleAroundPoint(Real(x)/Real(scr->ViewportWidth()),Real(y)/Real(scr->ViewportHeight()), Real(expf(-wheel/20.f)));
77 void MainLoop(Document & doc, Screen & scr, View & view, int max_frames = -1)
79 // order is important... segfaults occur when screen (which inits GL) is not constructed first -_-
82 scr.DebugFontInit("fonts/DejaVuSansMono.ttf");
83 scr.SetMouseHandler(RatCatcher);
87 script.Load(script_filename);
90 double total_cpu_time = 0;
91 double total_gpu_time = 0;
92 double total_real_time = 0;
93 struct timespec real_clock_start;
94 struct timespec real_clock_now;
95 struct timespec real_clock_prev;
96 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_start);
97 real_clock_now = real_clock_start;
99 double data_rate = 0; // period between data output to stdout (if <= 0 there will be no output)
100 uint64_t data_points = 0;
101 setbuf(stdout, NULL);
102 int frame_number = 0;
103 while (scr.PumpEvents() && (max_frames < 0 || frame_number++ < max_frames))
105 real_clock_prev = real_clock_now;
108 //view.ForceBoundsDirty();
109 //view.ForceBufferDirty();
110 //view.ForceRenderDirty();
114 if (script.Execute(&view, &scr))
118 view.Render(scr.ViewportWidth(), scr.ViewportHeight());
120 double cpu_frame = scr.GetLastFrameTimeCPU();
121 double gpu_frame = scr.GetLastFrameTimeGPU();
122 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_now);
123 double real_frame = (real_clock_now.tv_sec - real_clock_prev.tv_sec) + 1e-9*(real_clock_now.tv_nsec - real_clock_prev.tv_nsec);
126 total_real_time += real_frame; total_cpu_time += cpu_frame; total_gpu_time += gpu_frame;
127 if (data_rate > 0 && total_real_time > data_rate*(data_points+1))
129 printf("%lu\t%f\t%f\t%f\t%f\t%f\t%f\n", (long unsigned int)frames, total_real_time, total_cpu_time, total_gpu_time, real_frame, cpu_frame, gpu_frame);
132 scr.DebugFontPrintF("Rendered frame %lu\n", (uint64_t)frames);
133 scr.DebugFontPrintF("Lazy Rendering = %d\n", view.UsingLazyRendering());
134 if (cpu_frame > 0 && total_cpu_time > 0)
135 scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", cpu_frame*1e3, 1.0/cpu_frame, total_cpu_time,frames/total_cpu_time);
136 if (gpu_frame > 0 && total_gpu_time > 0)
137 scr.DebugFontPrintF("[GPU] Render took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", gpu_frame*1e3, 1.0/gpu_frame, total_gpu_time, frames/total_gpu_time);
138 if (real_frame > 0 && total_real_time > 0)
139 scr.DebugFontPrintF("[REALTIME] Render+Present+Cruft took %lf ms (%lf FPS) (total %lf s, avg FPS %lf)\n", real_frame*1e3, 1.0/real_frame, total_real_time,frames/total_real_time);
141 scr.DebugFontPrintF("View bounds: %s\n", view.GetBounds().Str().c_str());
142 scr.DebugFontPrintF("type of Real == %s\n", g_real_name[REALTYPE]);
143 //#if REALTYPE == REAL_MPFRCPP
144 // scr.DebugFontPrintf("Precision: %s\nRounding: %s\n");
147 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
148 scr.DebugFontPrint("Doing cumulative coordinate transforms on Objects.\n");
150 if (view.UsingGPUTransform())
152 scr.DebugFontPrint("Doing coordinate transform on the GPU.\n");
156 scr.DebugFontPrint("Doing coordinate transform on the CPU.\n");
160 #ifdef TRANSFORM_BEZIERS_TO_PATH
161 scr.DebugFontPrint("Beziers have been transformed to Path\n");
165 if (view.UsingGPURendering())
167 scr.DebugFontPrint("Doing rendering using GPU.\n");
171 scr.DebugFontPrint("Doing rendering using CPU.\n");