-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiling): add fps meter (#192)
Signed-off-by: Vasilyy Balyasnyy <v.balyasnyy@gmail.com>
- Loading branch information
1 parent
9d0b5c2
commit f60015f
Showing
7 changed files
with
229 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* widget_fpsmeter.h -- The widget fps meter operation set. | ||
* | ||
* Copyright (c) 2020, Vasilyy Balyasnyy <v.balyasnyy@gmail.com> All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of LCUI nor the names of its contributors may be used | ||
* to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef LCUI_WIDGET_FPSMETER_H | ||
#define LCUI_WIDGET_FPSMETER_H | ||
|
||
LCUI_BEGIN_HEADER | ||
|
||
#include <LCUI/LCUI.h> | ||
#include <LCUI/gui/widget.h> | ||
#include <LCUI/gui/widget/textview.h> | ||
|
||
typedef struct LCUI_FpsMeterRec_ { | ||
LCUI_Widget widget; | ||
|
||
int64_t last_time; | ||
size_t frame_count; | ||
|
||
size_t fps; | ||
int render_thread_count; | ||
size_t render_count; | ||
size_t widget_update_count; | ||
} LCUI_FpsMeterRec, *LCUI_FpsMeter; | ||
|
||
void LCUI_InitFpsMeter(void); | ||
|
||
void LCUI_FreeFpsMeter(void); | ||
|
||
void LCUI_FpsMeter_FrameCount(void); | ||
|
||
void LCUI_FpsMeter_RenderThreadCount(int count); | ||
|
||
void LCUI_FpsMeter_RenderCount(size_t count); | ||
|
||
void LCUI_FpsMeter_WidgetUpdateCount(size_t count); | ||
|
||
void LCUI_FpsMeter_Enable(void); | ||
|
||
void LCUI_FpsMeter_Disable(void); | ||
|
||
LCUI_END_HEADER | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* widget_fpsmeter.h -- The widget fps meter operation set. | ||
* | ||
* Copyright (c) 2020, Vasilyy Balyasnyy <v.balyasnyy@gmail.com> All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of LCUI nor the names of its contributors may be used | ||
* to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <LCUI_Build.h> | ||
#include <LCUI/LCUI.h> | ||
#include <LCUI/graph.h> | ||
#include <LCUI/font/fontlibrary.h> | ||
#include <LCUI/gui/css_library.h> | ||
#include <LCUI/gui/css_fontstyle.h> | ||
#include <LCUI/font/textlayer.h> | ||
#include <LCUI/gui/widget_fpsmeter.h> | ||
|
||
#define FPS_METER_TEXT_SIZE_MAX (256) | ||
#define FPS_METER_UPDATE_TIME_MS (1000) | ||
|
||
static LCUI_FpsMeterRec self; | ||
|
||
static void LCUI_FpsMeter_Create(void) | ||
{ | ||
self.widget = LCUIWidget_New("textview"); | ||
TextView_SetColor(self.widget, RGB(255, 255, 255)); | ||
Widget_SetFontStyle(self.widget, key_font_size, 16, px); | ||
Widget_SetFontStyle(self.widget, key_text_align, SV_LEFT, style); | ||
Widget_SetStyleString(self.widget, "z-index", "999"); | ||
Widget_SetPosition(self.widget, SV_ABSOLUTE); | ||
Widget_SetPadding(self.widget, 20, 20, 20, 20 ); | ||
Widget_SetStyle(self.widget, key_background_color, RGB(60, 60, 60), color); | ||
Widget_SetStyle(self.widget, key_opacity, 0.5, scale); | ||
Widget_UpdateStyle(self.widget, TRUE); | ||
} | ||
|
||
void LCUI_FpsMeter_Update() | ||
{ | ||
char buf[FPS_METER_TEXT_SIZE_MAX]; | ||
snprintf(buf, FPS_METER_TEXT_SIZE_MAX, | ||
"FPS: %ld\n" | ||
"Render thread count: %d\n" | ||
"Widget update count: %ld\n" | ||
"Render count: %ld", | ||
self.fps, | ||
self.render_thread_count, | ||
self.widget_update_count, | ||
self.render_count); | ||
TextView_SetText(self.widget, buf); | ||
} | ||
|
||
void LCUI_InitFpsMeter(void) | ||
{ | ||
self.last_time = LCUI_GetTime(); | ||
self.frame_count = 0; | ||
self.fps = 0; | ||
self.render_thread_count = 1; | ||
|
||
LCUI_FpsMeter_Create(); | ||
LCUI_FpsMeter_Update(); | ||
} | ||
|
||
void LCUI_FreeFpsMeter(void) | ||
{ | ||
Widget_Unlink(self.widget); | ||
} | ||
|
||
void LCUI_FpsMeter_FrameCount(void) | ||
{ | ||
self.frame_count++; | ||
if (LCUI_GetTimeDelta(self.last_time) >= FPS_METER_UPDATE_TIME_MS) { | ||
self.fps = (self.frame_count * 1000 ) / FPS_METER_UPDATE_TIME_MS; | ||
self.frame_count = 0; | ||
self.last_time = LCUI_GetTime(); | ||
|
||
LCUI_FpsMeter_Update(); | ||
} | ||
} | ||
|
||
void LCUI_FpsMeter_RenderThreadCount(int count) | ||
{ | ||
if (self.render_thread_count != count) { | ||
self.render_thread_count = count; | ||
} | ||
} | ||
|
||
void LCUI_FpsMeter_RenderCount(size_t count) | ||
{ | ||
if (self.render_count != count) { | ||
self.render_count = count; | ||
} | ||
} | ||
|
||
void LCUI_FpsMeter_WidgetUpdateCount(size_t count) | ||
{ | ||
if (self.widget_update_count != count) { | ||
self.widget_update_count = count; | ||
} | ||
} | ||
|
||
void LCUI_FpsMeter_Enable() | ||
{ | ||
Widget_Append(LCUIWidget_GetRoot(), self.widget); | ||
} | ||
|
||
void LCUI_FpsMeter_Disable() | ||
{ | ||
Widget_Unlink(self.widget); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters