Kaydet (Commit) ca1fb20a authored tarafından Michael Meeks's avatar Michael Meeks

vcldemo: add threading mode.

Change-Id: I6ad5524c518a79cac7ec343398242515ef0bbb5f
üst 2005e341
...@@ -25,12 +25,13 @@ $(eval $(call gb_Executable_set_include,vcldemo,\ ...@@ -25,12 +25,13 @@ $(eval $(call gb_Executable_set_include,vcldemo,\
$(eval $(call gb_Executable_use_libraries,vcldemo,\ $(eval $(call gb_Executable_use_libraries,vcldemo,\
basegfx \ basegfx \
comphelper \
cppu \
cppuhelper \
tl \ tl \
sal \ sal \
salhelper \
vcl \ vcl \
cppu \
cppuhelper \
comphelper \
)) ))
$(eval $(call gb_Executable_add_exception_objects,vcldemo,\ $(eval $(call gb_Executable_add_exception_objects,vcldemo,\
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <vcl/vclmain.hxx> #include <vcl/vclmain.hxx>
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
#include <salhelper/thread.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
...@@ -1196,16 +1197,42 @@ class DemoWin : public WorkWindow ...@@ -1196,16 +1197,42 @@ class DemoWin : public WorkWindow
{ {
DemoRenderer &mrRenderer; DemoRenderer &mrRenderer;
bool underTesting; bool underTesting;
bool testThreads;
class RenderThread : public salhelper::Thread {
DemoWin &mrWin;
public:
RenderThread(DemoWin &rWin)
: Thread("vcldemo render thread")
, mrWin(rWin)
{
launch();
}
virtual ~RenderThread()
{
join();
}
virtual void execute()
{
SolarMutexGuard aGuard;
fprintf (stderr, "render from a different thread\n");
mrWin.Paint(Rectangle());
}
};
rtl::Reference<RenderThread> mxThread;
public: public:
DemoWin(DemoRenderer &rRenderer) : DemoWin(DemoRenderer &rRenderer, bool bThreads) :
WorkWindow(NULL, WB_APP | WB_STDWORK), WorkWindow(NULL, WB_APP | WB_STDWORK),
mrRenderer(rRenderer) mrRenderer(rRenderer),
testThreads(bThreads)
{ {
mrRenderer.addInvalidate(this); mrRenderer.addInvalidate(this);
underTesting = false; underTesting = false;
} }
virtual ~DemoWin() virtual ~DemoWin()
{ {
mxThread.clear();
mrRenderer.removeInvalidate(this); mrRenderer.removeInvalidate(this);
} }
virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE
...@@ -1213,9 +1240,16 @@ public: ...@@ -1213,9 +1240,16 @@ public:
mrRenderer.SetSizePixel(GetSizePixel()); mrRenderer.SetSizePixel(GetSizePixel());
if (!mrRenderer.MouseButtonDown(rMEvt)) if (!mrRenderer.MouseButtonDown(rMEvt))
{ {
DemoWin *pNewWin = new DemoWin(mrRenderer); if (testThreads)
pNewWin->SetText("Another interactive VCL demo window"); { // render this window asynchronously in a new thread
pNewWin->Show(); mxThread = new RenderThread(*this);
}
else
{ // spawn another window
DemoWin *pNewWin = new DemoWin(mrRenderer, testThreads);
pNewWin->SetText("Another interactive VCL demo window");
pNewWin->Show();
}
} }
} }
virtual void KeyInput(const KeyEvent& rKEvt) SAL_OVERRIDE virtual void KeyInput(const KeyEvent& rKEvt) SAL_OVERRIDE
...@@ -1314,7 +1348,8 @@ class DemoApp : public Application ...@@ -1314,7 +1348,8 @@ class DemoApp : public Application
fprintf(stderr," %s\n", fprintf(stderr," %s\n",
rtl::OUStringToOString(aRenderers, RTL_TEXTENCODING_UTF8).getStr()); rtl::OUStringToOString(aRenderers, RTL_TEXTENCODING_UTF8).getStr());
fprintf(stderr," --test <iterCount> - create benchmark data\n"); fprintf(stderr," --test <iterCount> - create benchmark data\n");
fprintf(stderr, " --widgets - launch the widget test.\n"); fprintf(stderr," --widgets - launch the widget test.\n");
fprintf(stderr," --threads - render from multiple threads.\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
return 0; return 0;
} }
...@@ -1326,7 +1361,7 @@ public: ...@@ -1326,7 +1361,7 @@ public:
{ {
try try
{ {
bool bWidgets = false; bool bWidgets = false, bThreads = false;
DemoRenderer aRenderer; DemoRenderer aRenderer;
for (sal_Int32 i = 0; i < GetCommandLineParamCount(); i++) for (sal_Int32 i = 0; i < GetCommandLineParamCount(); i++)
...@@ -1351,9 +1386,11 @@ public: ...@@ -1351,9 +1386,11 @@ public:
} }
else if (aArg == "--widgets") else if (aArg == "--widgets")
bWidgets = true; bWidgets = true;
else if (aArg == "--threads")
bThreads = true;
} }
DemoWin aMainWin(aRenderer); DemoWin aMainWin(aRenderer, bThreads);
boost::scoped_ptr<DemoWidgets> aWidgets; boost::scoped_ptr<DemoWidgets> aWidgets;
aMainWin.SetText("Interactive VCL demo #1"); aMainWin.SetText("Interactive VCL demo #1");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment