Skip to content

Hit-test-only masks #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f576c59
Fumbling toward a transformation on CoronaTotalTime, so far the comma…
ggcrunchy Feb 7, 2019
6626191
Moved some of the time transform stuff into ShaderResource with link …
ggcrunchy Feb 8, 2019
e59f04a
Better argument checking for time transforms
ggcrunchy Feb 9, 2019
e05f972
Whoops, wasn't always linking Program back to ShaderResource
ggcrunchy Feb 10, 2019
c7af750
Removed notes to self about changes
ggcrunchy Feb 11, 2019
9058c1f
timeTransform ignored if no time dependency
ggcrunchy Feb 11, 2019
c01d916
Minor changes
ggcrunchy May 29, 2020
08dc3b6
Maintenance Revert Test
scottrules44 Sep 20, 2021
05b91fb
Simulator: Adding Samsung Galaxy 21 as a skin
scottrules44 Sep 22, 2021
f44be24
Maintenance
scottrules44 Sep 22, 2021
581d844
Android: adding rest of media intents for Android 11
scottrules44 Sep 22, 2021
265be3c
Merge
ggcrunchy Sep 23, 2021
e217c80
Merge
ggcrunchy Oct 4, 2021
ca300c1
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Oct 19, 2021
0b5e1e9
First go at graphics.undefineEffect()
ggcrunchy Nov 9, 2021
b41e624
Revert "First go at graphics.undefineEffect()"
ggcrunchy Nov 10, 2021
5be6193
Merging upstream
ggcrunchy Aug 18, 2022
f38ecec
Merge branch 'master' of https://github.com/ggcrunchy/corona
ggcrunchy Aug 18, 2022
bb395b8
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Dec 16, 2022
dfe75aa
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Jan 25, 2023
5a3c9e5
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Mar 24, 2023
0a67355
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 1, 2023
bb34246
More or less functional bitmap-based masking
ggcrunchy Apr 1, 2023
e8b2d71
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
5c006cd
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
ecf8ee0
Merge branch 'master' into MaskFromBitmap2
ggcrunchy Apr 18, 2023
ed674ef
Using weak table instead of encoding the filename to indicate hit-tes…
ggcrunchy Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Using weak table instead of encoding the filename to indicate hit-tes…
…t-only masks (probably not the issue, but paranoid :) )

Doing no-bitmap test before trying to make paint, to avoid bool pointer (much more suspect)

Workaround for Windows doing double-lock (non-issue with another upcoming PR)

Wasn't passing along hit-test-only-ness through CreateAndAdd()

File-based technique seems to not work
  • Loading branch information
ggcrunchy committed Apr 18, 2023
commit ed674ef7fafb9f8059d6411c9024bdddeab850c1
30 changes: 4 additions & 26 deletions librtt/Display/Rtt_BitmapMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ namespace Rtt
// ----------------------------------------------------------------------------

BitmapMask*
BitmapMask::Create( Runtime& runtime, const FilePath& maskData )
BitmapMask::Create( Runtime& runtime, const FilePath& maskData, bool onlyForHitTests )
{
bool onlyForHitTests = false;
BitmapPaint *paint = BitmapPaint::NewBitmap( runtime, maskData, PlatformBitmap::kIsBitsFullResolution, true, &onlyForHitTests );
BitmapPaint *paint = BitmapPaint::NewBitmap( runtime, maskData, PlatformBitmap::kIsBitsFullResolution, true, onlyForHitTests );
BitmapMask *result = NULL;

if ( Rtt_VERIFY( paint || onlyForHitTests ) )
Expand All @@ -45,7 +44,7 @@ BitmapMask::BitmapMask( BitmapPaint *paint, bool onlyForHitTests, bool isTempora
fOnlyForHitTests( onlyForHitTests ),
fIsTemporary( isTemporary )
{
Rtt_ASSERT( paint );
Rtt_ASSERT( paint || onlyForHitTests );
}

BitmapMask::BitmapMask( BitmapPaint *paint, Real contentW, Real contentH )
Expand All @@ -66,28 +65,7 @@ BitmapMask::~BitmapMask()
}
}

static const char kHitTestOnlyPrefix[] = "hitTestOnly://";

const char*
BitmapMask::StripHitTestPrefix( const char* filename )
{
if ( Rtt_StringStartsWith( filename, kHitTestOnlyPrefix ) )
{
return filename + strlen( kHitTestOnlyPrefix );
}

else
{
return filename;
}
}

void
BitmapMask::EncodeFilenameForHitTests( String& encoded, const char* filename )
{
encoded.Set( kHitTestOnlyPrefix );
encoded.Append( filename );
}
const char BitmapMask::kHitTestOnlyTable[] = "hitTestOnlyTableKey";

void
BitmapMask::GetSelfBounds( Rect& rect ) const
Expand Down
8 changes: 4 additions & 4 deletions librtt/Display/Rtt_BitmapMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UserdataWrapper;
class BitmapMask
{
public:
static BitmapMask* Create( Runtime& runtime, const FilePath& maskData );
static BitmapMask* Create( Runtime& runtime, const FilePath& maskData, bool onlyForHitTests );

public:
BitmapMask( BitmapPaint *paint, bool onlyForHitTests, bool isTemporary = false );
Expand All @@ -37,16 +37,16 @@ class BitmapMask
public:
~BitmapMask();

public:
static const char kHitTestOnlyTable[];

public:
const BitmapPaint* GetPaint() const { return fPaint; }
BitmapPaint* GetPaint() { return fPaint; }

public:
bool GetOnlyForHitTests() const { return fOnlyForHitTests; }

static const char* StripHitTestPrefix( const char* filename );
static void EncodeFilenameForHitTests( String& encoded, const char* filename );

public:
const Transform& GetTransform() const { return fTransform; }
Transform& GetTransform() { return fTransform; }
Expand Down
20 changes: 4 additions & 16 deletions librtt/Display/Rtt_BitmapPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,21 @@ BitmapPaint::NewBitmap( Runtime& runtime, const char* filename, MPlatform::Direc
}

BitmapPaint*
BitmapPaint::NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool* onlyForHitTests )
BitmapPaint::NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool onlyForHitTests )
{
BitmapPaint *result = NULL;

const char *filename = data.GetFilename();
MPlatform::Directory baseDir = data.GetBaseDir();

if ( isMask && NULL != onlyForHitTests )
if ( onlyForHitTests && '\0' == *filename )
{
const char *stripped = BitmapMask::StripHitTestPrefix( filename );

if ( stripped != filename )
{
*onlyForHitTests = true;

if ( !*stripped ) // no bitmap?
{
return result;
}

filename = stripped;
}
return NULL;
}

TextureFactory& factory = runtime.GetDisplay().GetTextureFactory();
SharedPtr< TextureResource > pTexture =
factory.FindOrCreate( filename, baseDir, flags, isMask );
factory.FindOrCreate( filename, baseDir, flags, isMask, onlyForHitTests );

if ( pTexture.NotNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion librtt/Display/Rtt_BitmapPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BitmapPaint : public Paint
static BitmapPaint* NewBitmap( Runtime& runtime, const char* filename, MPlatform::Directory baseDir, U32 flags );

// Load bitmap mask from file or reuse bitmap from image cache
static BitmapPaint* NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool* onlyForHitTests = NULL );
static BitmapPaint* NewBitmap( Runtime& runtime, const FilePath& data, U32 flags, bool isMask, bool onlyForHitTests = false );

// Wrap platform bitmap in Paint-compatible interface. Typically used
// in conjunction with PlatformImageProvider
Expand Down
40 changes: 26 additions & 14 deletions librtt/Display/Rtt_LuaLibGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,37 @@ GraphicsLibrary::newMask( lua_State *L )
int
GraphicsLibrary::newHitTestOnlyMask( lua_State *L )
{
if ( lua_isstring( L, 1 ) )
{
String str;
int result = GraphicsLibrary::newMask( L );

BitmapMask::EncodeFilenameForHitTests( str, lua_tostring( L, 1 ) );
if ( result )
{
lua_getfield( L, LUA_REGISTRYINDEX, BitmapMask::kHitTestOnlyTable );

lua_pushstring( L, str.GetString() );
lua_replace( L, 1 );
if ( lua_istable( L, -1 ) )
{
lua_pushvalue( L, -2 );
lua_pushboolean( L, 1 );
lua_rawset( L, -3 );
lua_pop( L, 1 );
}

else
{
result = 0;
}
}

return newMask( L );
return result;
}

// graphics.newHitTestOnlyMaskFromPaint( [opts] )
int
GraphicsLibrary::newHitTestOnlyMaskFromPaint( lua_State *L )
{
lua_settop( L, 0 ); // TODO: any options?
lua_pushliteral( L, "" );

String str;

BitmapMask::EncodeFilenameForHitTests( str, "" );

lua_pushstring( L, str.GetString() );

return newMask( L );
return newHitTestOnlyMask( L );
}

// graphics.newVertexArray( x1, y1 [,x2, y2, ... ] )
Expand Down Expand Up @@ -937,6 +942,13 @@ LuaLibGraphics::Initialize( lua_State *L, Display& display )

CoronaLuaPushModule( L, GraphicsLibrary::kName );
lua_setglobal( L, GraphicsLibrary::kName ); // graphics = library

lua_newtable( L );
lua_createtable( L, 0, 1 );
lua_pushliteral( L, "k" );
lua_setfield( L, -2, "__mode" );
lua_setmetatable( L, -2 );
lua_setfield( L, LUA_REGISTRYINDEX, BitmapMask::kHitTestOnlyTable );
}

// ----------------------------------------------------------------------------
Expand Down
23 changes: 22 additions & 1 deletion librtt/Rtt_LuaProxyVTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,28 @@ setMask( lua_State *L )
FilePath *maskData = *ud;
if ( maskData )
{
mask = BitmapMask::Create( * runtime, * maskData );
bool onlyForHitTests = false;

lua_getfield( L, LUA_REGISTRYINDEX, BitmapMask::kHitTestOnlyTable );

if ( lua_istable( L, -1 ))
{
lua_pushvalue( L, 2 );
lua_rawget( L, -2 );

onlyForHitTests = lua_toboolean( L, -1 );

lua_pop( L, 1 );
}

else
{
Rtt_TRACE_SIM( ( "WARNING: Hit test only table missing for masks.\n" ) );
}

lua_pop( L, 1 );

mask = BitmapMask::Create( * runtime, * maskData, onlyForHitTests );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ WinBitmap::Lock()
if ( fBitmap == NULL )
return;

if ( fLockedBitmapData )
{
Rtt_ASSERT( fData );

return;
}

Gdiplus::Rect rect;

rect.X = rect.Y = 0;
Expand Down