Allow caching cursor position on X11 to work around slow XQueryPointer calls. Resolves patch 3476712. Thanks @ hendu for reporting and patch-proposal. For more info: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=45525

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4251 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2012-07-20 12:25:32 +00:00
parent 90052d1ed9
commit b52a040fe6
4 changed files with 47 additions and 1 deletions

View File

@ -1,5 +1,7 @@
Changes in 1.8 (??.??.2011)
- Allow caching cursor position on X11 to work around slow XQueryPointer calls.
- Struct packing works now with gcc 4.7 changes on MinGW (thx @Sudi for reporting).
- Struct packing uses now same solution throughout (by including headers in corresponding places)

View File

@ -78,6 +78,21 @@ namespace gui
core::position2d<s32> HotSpot;
};
//! platform specific behavior flags for the cursor
enum ECURSOR_PLATFORM_BEHAVIOR
{
//! default - no platform specific behaviour
ECPB_NONE = 0,
//! On X11 try caching cursor updates as XQueryPointer calls can be expensive.
/** Update cursor positions only when the irrlicht timer has been updated or the timer is stopped.
This means you usually get one cursor update per device->run() which will be fine in most cases.
See this forum-thread for a more detailed explanation:
http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=45525
*/
ECPB_X11_CACHE_UPDATES = 1
};
//! Interface to manipulate the mouse cursor.
class ICursorControl : public virtual IReferenceCounted
{
@ -159,6 +174,14 @@ namespace gui
//! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work.
virtual core::dimension2di getSupportedIconSize() const { return core::dimension2di(0,0); }
//! Set platform specific behavior flags.
virtual void setPlatformBehavior(ECURSOR_PLATFORM_BEHAVIOR behavior) {}
//! Return platform specific behavior.
/** \return Behavior set by setPlatformBehavior or ECPB_NONE for platforms not implementing specific behaviors.
*/
virtual ECURSOR_PLATFORM_BEHAVIOR getPlatformBehavior() const { return ECPB_NONE; }
};

View File

@ -2090,7 +2090,11 @@ Cursor CIrrDeviceLinux::TextureToCursor(irr::video::ITexture * tex, const core::
CIrrDeviceLinux::CCursorControl::CCursorControl(CIrrDeviceLinux* dev, bool null)
: Device(dev), IsVisible(true), Null(null), UseReferenceRect(false)
: Device(dev)
#ifdef _IRR_COMPILE_WITH_X11_
, PlatformBehavior(gui::ECPB_NONE), lastQuery(0)
#endif
, IsVisible(true), Null(null), UseReferenceRect(false)
, ActiveIcon(gui::ECI_NORMAL), ActiveIconStartTime(0)
{
#ifdef _IRR_COMPILE_WITH_X11_

View File

@ -13,6 +13,7 @@
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
#include "ICursorControl.h"
#include "os.h"
#ifdef _IRR_COMPILE_WITH_X11_
@ -293,6 +294,12 @@ namespace irr
virtual core::dimension2di getSupportedIconSize() const;
#ifdef _IRR_COMPILE_WITH_X11_
//! Set platform specific behavior flags.
virtual void setPlatformBehavior(gui::ECURSOR_PLATFORM_BEHAVIOR behavior) {PlatformBehavior = behavior; }
//! Return platform specific behavior.
virtual gui::ECURSOR_PLATFORM_BEHAVIOR getPlatformBehavior() const { return PlatformBehavior; }
void update();
void clearCursors();
#endif
@ -304,6 +311,14 @@ namespace irr
if (Null)
return;
if ( PlatformBehavior&gui::ECPB_X11_CACHE_UPDATES && !os::Timer::isStopped() )
{
u32 now = os::Timer::getTime();
if (now <= lastQuery)
return;
lastQuery = now;
}
Window tmp;
int itmp1, itmp2;
unsigned int maskreturn;
@ -327,6 +342,8 @@ namespace irr
core::position2d<s32> CursorPos;
core::rect<s32> ReferenceRect;
#ifdef _IRR_COMPILE_WITH_X11_
gui::ECURSOR_PLATFORM_BEHAVIOR PlatformBehavior;
u32 lastQuery;
Cursor invisCursor;
struct CursorFrameX11