Author: fejj
Date: 2007-12-14 14:18:36 -0500 (Fri, 14 Dec 2007)
New Revision: 91313
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
Log:
2007-12-14 Jeffrey Stedfast <[EMAIL PROTECTED]>
* runtime.cpp (fps_report_default): Default printf FPS report
callback.
(Surface::render_cb): Use instance-local variables for keeping
track of FPS and use the report func if RUNTIME_INIT_SHOW_FPS bit
is set.
* runtime.h: Added a RUNTIME_INIT_SHOW_FPS flag
(class Surface): New method to set the FPS report callback for a
surface.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-12-14 19:15:25 UTC (rev 91312)
+++ trunk/moon/src/ChangeLog 2007-12-14 19:18:36 UTC (rev 91313)
@@ -1,3 +1,15 @@
+2007-12-14 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * runtime.cpp (fps_report_default): Default printf FPS report
+ callback.
+ (Surface::render_cb): Use instance-local variables for keeping
+ track of FPS and use the report func if RUNTIME_INIT_SHOW_FPS bit
+ is set.
+
+ * runtime.h: Added a RUNTIME_INIT_SHOW_FPS flag
+ (class Surface): New method to set the FPS report callback for a
+ surface.
+
2007-12-14 Chris Toshok <[EMAIL PROTECTED]>
* type.cpp.in, type.cpp (types_init_register_events): need to
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-12-14 19:15:25 UTC (rev 91312)
+++ trunk/moon/src/runtime.cpp 2007-12-14 19:18:36 UTC (rev 91313)
@@ -83,10 +83,18 @@
{ "clipping=hide", RUNTIME_INIT_SHOW_CLIPPING, false },
{ "bbox=show", RUNTIME_INIT_SHOW_BOUNDING_BOXES, true },
{ "bbox=hide", RUNTIME_INIT_SHOW_BOUNDING_BOXES, false },
+ { "fps=show", RUNTIME_INIT_SHOW_FPS, true },
+ { "fps=hide", RUNTIME_INIT_SHOW_FPS, false },
};
#define RENDER_EXPOSE (moonlight_flags & RUNTIME_INIT_SHOW_EXPOSE)
+static void
+fps_report_default (Surface *surface, int nframes, float nsecs, void
*user_data)
+{
+ printf ("Rendered %d frames in %.3fs = %.3f FPS\n", nframes, nsecs,
nframes / nsecs);
+}
+
cairo_t *
runtime_cairo_create (GdkWindow *drawable)
{
@@ -102,8 +110,7 @@
gdk_x11_drawable_get_xid (drawable),
GDK_VISUAL_XVISUAL (visual),
width, height);
-
-
+
cr = cairo_create (surface);
cairo_surface_destroy (surface);
@@ -129,22 +136,22 @@
{
if (drawing_area == NULL || drawing_area->window == NULL)
return;
-
- cairo_t *ctx = runtime_cairo_create (drawing_area->window);
-
- if (cairo_xlib){
- cairo_destroy (cairo_xlib);
- }
-
- cairo_surface_t *xlib_surface = cairo_surface_create_similar (
- cairo_get_target (ctx),
- CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
-
- cairo_destroy (ctx);
-
- cairo_xlib = cairo_create (xlib_surface);
- cairo_surface_destroy (xlib_surface);
+
+ cairo_t *ctx = runtime_cairo_create (drawing_area->window);
+
+ if (cairo_xlib){
+ cairo_destroy (cairo_xlib);
+ }
+
+ cairo_surface_t *xlib_surface = cairo_surface_create_similar (
+ cairo_get_target (ctx),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ width, height);
+
+ cairo_destroy (ctx);
+
+ cairo_xlib = cairo_create (xlib_surface);
+ cairo_surface_destroy (xlib_surface);
}
@@ -191,6 +198,12 @@
full_screen_message = NULL;
source_location = NULL;
+
+ fps_report = fps_report_default;
+ fps_data = NULL;
+
+ fps_nframes = 0;
+ fps_start = 0;
}
Surface::~Surface ()
@@ -714,31 +727,31 @@
void
Surface::render_cb (EventObject *sender, gpointer calldata, gpointer closure)
{
- Surface *s = (Surface*) closure;
- static int64_t start = 0;
- static int nframes = 0;
+ Surface *s = (Surface *) closure;
int64_t now;
- if (start == 0)
- start = get_now ();
+ if ((moonlight_flags & RUNTIME_INIT_SHOW_FPS) && s->fps_start == 0)
+ s->fps_start = get_now ();
gdk_window_process_updates (GTK_WIDGET (s->drawing_area)->window,
FALSE);
- nframes++;
-
- if (false && (now = get_now ()) > (start + TIMESPANTICKS_IN_SECOND)) {
- printf ("Rendered %d frames in %.3fs = %.3f FPS\n", nframes,
- (now - start) / TIMESPANTICKS_IN_SECOND_FLOAT,
- nframes / ((now - start) /
TIMESPANTICKS_IN_SECOND_FLOAT));
- nframes = 0;
- start = now;
+ if ((moonlight_flags & RUNTIME_INIT_SHOW_FPS) && s->fps_report) {
+ s->fps_nframes++;
+
+ if ((now = get_now ()) > (s->fps_start +
TIMESPANTICKS_IN_SECOND)) {
+ float nsecs = (now - s->fps_start) /
TIMESPANTICKS_IN_SECOND_FLOAT;
+
+ s->fps_report (s, s->fps_nframes, nsecs, s->fps_data);
+ s->fps_nframes = 0;
+ s->fps_start = now;
+ }
}
}
void
Surface::update_input_cb (EventObject *sender, gpointer calldata, gpointer
closure)
{
- Surface *s = (Surface*)closure;
+ Surface *s = (Surface *) closure;
MouseCursor new_cursor = MouseCursorDefault;
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-12-14 19:15:25 UTC (rev 91312)
+++ trunk/moon/src/runtime.h 2007-12-14 19:18:36 UTC (rev 91313)
@@ -44,16 +44,18 @@
RUNTIME_INIT_SHOW_EXPOSE = 1 << 4,
RUNTIME_INIT_SHOW_CLIPPING = 1 << 5,
RUNTIME_INIT_SHOW_BOUNDING_BOXES = 1 << 6,
+ RUNTIME_INIT_SHOW_FPS = 1 << 7,
};
#define RUNTIME_INIT_DESKTOP (RUNTIME_INIT_PANGO_TEXT_LAYOUT)
#define RUNTIME_INIT_BROWSER (RUNTIME_INIT_MICROSOFT_CODECS)
+class Surface;
+typedef void (* MoonlightFPSReportFunc) (Surface *surface, int nframes, float
nsecs, void *user_data);
class Surface : public EventObject {
public:
Surface (int width, int height);
-
virtual ~Surface ();
// allows you to redirect painting of the surface to an
@@ -61,12 +63,12 @@
void Paint (cairo_t *ctx, int x, int y, int width, int height);
void Paint (cairo_t *ctx, Region *);
- void Attach (UIElement* toplevel);
+ void Attach (UIElement *toplevel);
void SetCursor (MouseCursor cursor);
bool SetMouseCapture (UIElement *capture);
- UIElement* GetMouseCapture () { return capture_element; }
+ UIElement *GetMouseCapture () { return capture_element; }
void Resize (int width, int height);
int GetWidth () { return width; }
@@ -86,7 +88,7 @@
UIElement *GetToplevel() { return toplevel; }
bool IsTopLevel (UIElement *top);
- UIElement* GetCapturedElement () { return capture_element; }
+ UIElement *GetCapturedElement () { return capture_element; }
static int ResizeEvent;
static int FullScreenChangeEvent;
@@ -100,7 +102,7 @@
int GetActualWidth () { return width; }
int GetActualHeight () { return height; }
- ClockGroup* GetClockGroup () { return clock_group; }
+ ClockGroup *GetClockGroup () { return clock_group; }
virtual Type::Kind GetObjectType () { return Type::SURFACE; };
@@ -114,21 +116,27 @@
return downloader;
}
- static Downloader *CreateDownloader (UIElement* element)
+ static Downloader *CreateDownloader (UIElement *element)
{
- Surface *surface = NULL;
- if (element) {
- surface = element->GetSurface ();
- }
+ Surface *surface = element ? element->GetSurface () : NULL;
+
if (surface) {
return surface->CreateDownloader ();
} else {
- printf ("Surface::CreateDownloader (%p, ID: %i): Unable
to create contextual downloader.\n", element, GET_OBJ_ID (element));
+ //printf ("Surface::CreateDownloader (%p, ID: %i): "
+ // "Unable to create contextual downloader.\n",
+ // element, GET_OBJ_ID (element));
//print_stack_trace ();
return new Downloader ();
}
}
+ void SetFPSReportFunc (MoonlightFPSReportFunc report, void *user_data)
+ {
+ fps_report = report;
+ fps_data = user_data;
+ }
+
private:
gpointer downloader_context;
@@ -204,7 +212,13 @@
int last_event_state;
double last_event_x, last_event_y;
-
+
+ // Variables for reporting FPS
+ MoonlightFPSReportFunc fps_report;
+ int64_t fps_start;
+ int fps_nframes;
+ void *fps_data;
+
void ConnectEvents (bool realization_signals);
void Realloc ();
void InitializeDrawingArea (GtkWidget *drawing_area);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches