javauis/m3g_akn/javasrc/javax/microedition/m3g/Graphics3D.java
branchRCL_3
changeset 60 6c158198356e
parent 34 71c436fe3ce0
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
   105     // for checking if Background is used for clearing
   105     // for checking if Background is used for clearing
   106     // entire canvas area.
   106     // entire canvas area.
   107     private Rect viewport;
   107     private Rect viewport;
   108     private Rect clip;
   108     private Rect clip;
   109     private boolean ngaEnabled = false;
   109     private boolean ngaEnabled = false;
   110     private boolean foreground;
   110     private boolean pendingGLESRelease = false;
   111 
   111 
   112 
   112 
   113     //------------------------------------------------------------------
   113     //------------------------------------------------------------------
   114     // Constructor(s)
   114     // Constructor(s)
   115     //------------------------------------------------------------------
   115     //------------------------------------------------------------------
   126             {
   126             {
   127                 throw new RuntimeException("Graphics3D closed");
   127                 throw new RuntimeException("Graphics3D closed");
   128             }
   128             }
   129             if (instance.graphics3D == null)
   129             if (instance.graphics3D == null)
   130             {
   130             {
   131                 // graphics3D must be assigned to interface before asking foreground status
       
   132                 instance.graphics3D = new Graphics3D();
   131                 instance.graphics3D = new Graphics3D();
   133                 instance.graphics3D.foreground = ToolkitInvoker.getToolkitInvoker().isForeground();
       
   134             }
   132             }
   135             return instance.graphics3D;
   133             return instance.graphics3D;
   136         }
   134         }
   137     }
   135     }
   138 
   136 
   156         // Initializes the viewport and clipping rectangles
   154         // Initializes the viewport and clipping rectangles
   157         this.viewport = new Rect();
   155         this.viewport = new Rect();
   158         this.clip = new Rect();
   156         this.clip = new Rect();
   159         // Initializes NGA status - enabled or disabled
   157         // Initializes NGA status - enabled or disabled
   160         ngaEnabled = invoker.isNgaEnabled();
   158         ngaEnabled = invoker.isNgaEnabled();
   161      }
   159     }
   162 
   160 
   163     /**
   161     /**
   164      *
   162      *
   165      */
   163      */
   166     void doDestroyNotify()
   164     void doDestroyNotify()
   183     /**
   181     /**
   184      *
   182      *
   185      */
   183      */
   186     public void bindTarget(java.lang.Object target, boolean depth, int flags)
   184     public void bindTarget(java.lang.Object target, boolean depth, int flags)
   187     {
   185     {
   188         synchronized (Interface.getInstance()) 
   186         synchronized (Interface.getInstance())
   189         {
   187         {
   190             integrityCheck();
   188             integrityCheck();
   191             int eventSrcHandle = 0;
   189             int eventSrcHandle = 0;
   192             if (currentTarget != null)
   190             if (currentTarget != null)
   193             {
   191             {
   286     /**
   284     /**
   287      *
   285      *
   288      */
   286      */
   289     public void releaseTarget()
   287     public void releaseTarget()
   290     {
   288     {
   291         synchronized (Interface.getInstance()) 
   289         synchronized (Interface.getInstance())
   292         {
   290         {
   293             integrityCheck();
   291             integrityCheck();
   294             if (currentTarget == null)
   292             if (currentTarget == null)
   295             {
   293             {
   296                 return;
   294                 return;
   297             }
   295             }
   298         
   296 
   299             int eventSrcHandle = 0;
   297             int eventSrcHandle = 0;
   300         
   298 
   301             try
   299             try
   302             {
   300             {
   303                 // Bind event source
   301                 // Bind event source
   304                 eventSrcHandle = Interface.bindEventSource();
   302                 eventSrcHandle = Interface.bindEventSource();
   305                 if (currentTarget instanceof Graphics)
   303                 if (currentTarget instanceof Graphics)
   326                 }
   324                 }
   327             }
   325             }
   328             finally
   326             finally
   329             {
   327             {
   330                 currentTarget = null;
   328                 currentTarget = null;
   331                         
   329 
   332                 if (ngaEnabled && !foreground && eventSrcHandle != 0)
   330                 if (ngaEnabled  &&
       
   331                         pendingGLESRelease &&
       
   332                         eventSrcHandle != 0)
   333                 {
   333                 {
       
   334                     pendingGLESRelease = false;
   334                     _freeGLESResources(eventSrcHandle, handle);
   335                     _freeGLESResources(eventSrcHandle, handle);
   335                 }
   336                 }
   336 
   337 
   337                 // Release event source
   338                 // Release event source
   338                 Interface.releaseEventSource();
   339                 Interface.releaseEventSource();
   746                 Interface.releaseEventSource();
   747                 Interface.releaseEventSource();
   747             }
   748             }
   748         }
   749         }
   749     }
   750     }
   750 
   751 
   751     void setForeground(boolean foreground) 
   752     void freeGraphicsMemory()
   752     {
   753     {
   753         synchronized (Interface.getInstance())
   754         synchronized (Interface.getInstance())
   754         {
   755         {
   755             this.foreground = foreground;
   756             if (!ngaEnabled)
   756             if (ngaEnabled &&
   757             {
   757                 !foreground && 
   758                 return;
   758                 currentTarget == null)
   759             }
   759             {
   760 
   760                 try 
   761             if (currentTarget == null)
       
   762             {
       
   763                 pendingGLESRelease = false;
       
   764                 try
   761                 {
   765                 {
   762                     _freeGLESResources(Interface.bindEventSource(), handle);
   766                     _freeGLESResources(Interface.bindEventSource(), handle);
   763                 }
   767                 }
   764                 finally
   768                 finally
   765                 {
   769                 {
   766                     Interface.releaseEventSource();
   770                     Interface.releaseEventSource();
   767                 }
   771                 }
   768             }
   772             }
   769         }
   773             else
   770     }
   774             {
   771     
   775                 pendingGLESRelease = true;
       
   776             }
       
   777         }
       
   778     }
       
   779 
   772     private native static int _ctor(int hInterface);
   780     private native static int _ctor(int hInterface);
   773     private native static void _addRef(int hObject);
   781     private native static void _addRef(int hObject);
   774 
   782 
   775     private native static int _addLight(int handle,
   783     private native static int _addLight(int handle,
   776                                         int hLight,
   784                                         int hLight,
   848     // NGA specific changes.
   856     // NGA specific changes.
   849     private native static int _getTargetHeight(int graphicsHandle);
   857     private native static int _getTargetHeight(int graphicsHandle);
   850     private native static int _getTargetWidth(int graphicsHandle);
   858     private native static int _getTargetWidth(int graphicsHandle);
   851     private native static void _updateEglContent(int eventSourceHandle,
   859     private native static void _updateEglContent(int eventSourceHandle,
   852             int graphicsHandle);
   860             int graphicsHandle);
   853     private native static void _freeGLESResources(int eventSourceHandle, 
   861     private native static void _freeGLESResources(int eventSourceHandle,
   854             int handle);
   862             int handle);
   855 }
   863 }