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", 32);
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;
94 // MINGW doesn't support a lot of ctime stuff here
96 struct timespec real_clock_start;
97 struct timespec real_clock_now;
98 struct timespec real_clock_prev;
99 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_start);
100 real_clock_now = real_clock_start;
105 double data_rate = 0; // period between data output to stdout (if <= 0 there will be no output)
106 uint64_t data_points = 0;
107 setbuf(stdout, NULL);
108 int frame_number = 0;
109 while (scr.PumpEvents() && (max_frames < 0 || frame_number++ < max_frames))
112 real_clock_prev = real_clock_now;
116 //view.ForceBoundsDirty();
117 //view.ForceBufferDirty();
118 //view.ForceRenderDirty();
122 if (script.Execute(&view, &scr))
126 view.Render(scr.ViewportWidth(), scr.ViewportHeight());
128 double cpu_frame = scr.GetLastFrameTimeCPU();
129 double gpu_frame = scr.GetLastFrameTimeGPU();
130 total_cpu_time += cpu_frame; total_gpu_time += gpu_frame;
133 clock_gettime(CLOCK_MONOTONIC_RAW, &real_clock_now);
134 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);
136 double real_frame = cpu_frame;
139 total_real_time += real_frame;
140 if (data_rate > 0 && total_real_time > data_rate*(data_points+1))
142 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);
146 scr.DebugFontPrintF("View Width = %s m\n", Str(view.GetBounds().w * VReal(22e-3)).c_str());
147 scr.DebugFontPrintF("Similar size: %s\n", HumanScale(view.GetBounds().w * VReal(22e-3)));
150 scr.DebugFontPrintF("Rendered frame %lu\n", (uint64_t)frames);
151 scr.DebugFontPrintF("Lazy Rendering = %d\n", view.UsingLazyRendering());
152 if (cpu_frame > 0 && total_cpu_time > 0)
153 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);
154 if (gpu_frame > 0 && total_gpu_time > 0)
155 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);
156 if (real_frame > 0 && total_real_time > 0)
157 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);
159 scr.DebugFontPrintF("View bounds: %s\n", view.GetBounds().Str().c_str());
160 scr.DebugFontPrintF("type of Real == %s\n", g_real_name[REALTYPE]);
161 //#if REALTYPE == REAL_MPFRCPP
162 // scr.DebugFontPrintf("Precision: %s\nRounding: %s\n");
165 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
166 scr.DebugFontPrint("Doing cumulative coordinate transforms on Objects.\n");
168 if (view.UsingGPUTransform())
170 scr.DebugFontPrint("Doing coordinate transform on the GPU.\n");
174 scr.DebugFontPrint("Doing coordinate transform on the CPU.\n");
178 #ifdef TRANSFORM_BEZIERS_TO_PATH
179 scr.DebugFontPrint("Beziers have been transformed to Path\n");
183 if (view.UsingGPURendering())
185 scr.DebugFontPrint("Doing rendering using GPU.\n");
189 scr.DebugFontPrint("Doing rendering using CPU.\n");