Expected NEWT Display creation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Expected NEWT Display creation

After looking through the code I realize that the reference count held within the Display is actually a count of the number of times that the static factory method Display.create(type,name,handle) has been called.  What is the expected use of the API with respect to Display creation?

Scenario 1: One display used with two screens.  The reference count of the display is ONE.
   Display d1 = NewtFactory.createDisplay(...)
   Screen s1 = NewtFactory.createScreen (d1, 1)
   Screen s2 = NewtFactory.createScreen (d1, 2)
   // s1 and s2 use the same display instance, but the reference count ONE.

Scenario 2: Two displays used with two screens.  The same display is returned from the factory, resulting in a reference count of TWO.
   Display d1 = NewtFactory.createDisplay(...)
   Screen s1 = NewtFactory.createScreen (d1, 1)
   Display d2 = NewtFactory.createDisplay(...)
   Screen s2 = NewtFactory.createScreen (d2, 2)
   // d1 and d2 are the same instance, but the reference count is TWO.

Are both of these scenarios correct uses of NEWT, or is the expectation that the code is written with with each Window/Screen/Display combination treated as distinct?  This matters because when NewtCanvasAWT reparents a window it calls NewtFactoryAWT.createCompatibleScreen(parent) if the native window is not valid.  Since createCompatibleScreen(...) results in a call to Display.create(...), sometimes this increments the Display reference count and sometimes this results in a new display instance.  With the reference counts inconsistently set, it becomes difficult to consistently ensure the NEWT resources (e.g. each display's EDT thread) is managed correctly.