javauis/m3g_akn/javasrc/javax/microedition/m3g/Graphics3D.java
branchRCL_3
changeset 34 71c436fe3ce0
parent 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
25:9ac0a0a7da70 34:71c436fe3ce0
   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 
   111 
   111 
   112 
   112     //------------------------------------------------------------------
   113     //------------------------------------------------------------------
   113     // Constructor(s)
   114     // Constructor(s)
   114     //------------------------------------------------------------------
   115     //------------------------------------------------------------------
   125             {
   126             {
   126                 throw new RuntimeException("Graphics3D closed");
   127                 throw new RuntimeException("Graphics3D closed");
   127             }
   128             }
   128             if (instance.graphics3D == null)
   129             if (instance.graphics3D == null)
   129             {
   130             {
       
   131                 // graphics3D must be assigned to interface before asking foreground status
   130                 instance.graphics3D = new Graphics3D();
   132                 instance.graphics3D = new Graphics3D();
       
   133                 instance.graphics3D.foreground = ToolkitInvoker.getToolkitInvoker().isForeground();
   131             }
   134             }
   132             return instance.graphics3D;
   135             return instance.graphics3D;
   133         }
   136         }
   134     }
   137     }
   135 
   138 
   152         // NGA specific change.
   155         // NGA specific change.
   153         // Initializes the viewport and clipping rectangles
   156         // Initializes the viewport and clipping rectangles
   154         this.viewport = new Rect();
   157         this.viewport = new Rect();
   155         this.clip = new Rect();
   158         this.clip = new Rect();
   156         // Initializes NGA status - enabled or disabled
   159         // Initializes NGA status - enabled or disabled
   157         this.ngaEnabled = ToolkitInvoker.getToolkitInvoker().isNgaEnabled();
   160         ngaEnabled = invoker.isNgaEnabled();
   158     }
   161      }
   159 
   162 
   160     /**
   163     /**
   161      *
   164      *
   162      */
   165      */
   163     void doDestroyNotify()
   166     void doDestroyNotify()
   180     /**
   183     /**
   181      *
   184      *
   182      */
   185      */
   183     public void bindTarget(java.lang.Object target, boolean depth, int flags)
   186     public void bindTarget(java.lang.Object target, boolean depth, int flags)
   184     {
   187     {
   185         integrityCheck();
   188         synchronized (Interface.getInstance()) 
   186         int eventSrcHandle = 0;
   189         {
   187         if (currentTarget != null)
   190             integrityCheck();
   188         {
   191             int eventSrcHandle = 0;
   189             throw new IllegalStateException();
   192             if (currentTarget != null)
   190         }
   193             {
   191 
   194                 throw new IllegalStateException();
   192         if (target == null)
   195             }
   193         {
   196 
   194             throw new NullPointerException();
   197             if (target == null)
   195         }
   198             {
   196         try
   199                 throw new NullPointerException();
   197         {
   200             }
   198             // Bind event source. This need to be released.
   201             try
   199             eventSrcHandle = Interface.bindEventSource();
   202             {
   200             if (target instanceof Graphics)
   203                 // Bind event source. This need to be released.
   201             {
   204                 eventSrcHandle = Interface.bindEventSource();
   202                 Graphics g = (Graphics) target;
   205                 if (target instanceof Graphics)
   203                 Platform.sync(g);
   206                 {
   204 
   207                     Graphics g = (Graphics) target;
   205                 if (g.getClipWidth() > Defs.MAX_VIEWPORT_WIDTH ||
   208                     Platform.sync(g);
   206                         g.getClipHeight() > Defs.MAX_VIEWPORT_HEIGHT)
   209 
       
   210                     if (g.getClipWidth() > Defs.MAX_VIEWPORT_WIDTH ||
       
   211                             g.getClipHeight() > Defs.MAX_VIEWPORT_HEIGHT)
       
   212                     {
       
   213                         throw new IllegalArgumentException();
       
   214                     }
       
   215 
       
   216                     offsetX = g.getTranslateX();
       
   217                     offsetY = g.getTranslateY();
       
   218 
       
   219                     ToolkitInvoker invoker = ToolkitInvoker.getToolkitInvoker();
       
   220 
       
   221                     // NGA specific change.
       
   222                     if (ngaEnabled)
       
   223                     {
       
   224                         // If overwrite is set, there is no need
       
   225                         // to update EGL surface with 2D content
       
   226                         eglContentValid = (flags & OVERWRITE) > 0;
       
   227 
       
   228                         // Clip and viewport are stored for later
       
   229                         // checks regarding Background clear
       
   230                         clip.x = g.getClipX() + offsetX;
       
   231                         clip.y = g.getClipY() + offsetY;
       
   232                         clip.width = g.getClipWidth();
       
   233                         clip.height = g.getClipHeight();
       
   234 
       
   235                         viewport.x = clip.x;
       
   236                         viewport.y = clip.y;
       
   237                         viewport.width = clip.width;
       
   238                         viewport.height = clip.height;
       
   239 
       
   240                         isImageTarget = _bindGraphics(
       
   241                                             eventSrcHandle,
       
   242                                             handle,
       
   243                                             invoker.graphicsGetHandle(g),
       
   244                                             clip.x, clip.y,
       
   245                                             clip.width, clip.height,
       
   246                                             depth, flags,
       
   247                                             isProperRenderer);
       
   248                     }
       
   249                     else
       
   250                     {
       
   251                         isImageTarget = _bindGraphics(
       
   252                                             eventSrcHandle,
       
   253                                             handle,
       
   254                                             invoker.graphicsGetHandle(g),
       
   255                                             g.getClipX() + offsetX, g.getClipY() + offsetY,
       
   256                                             g.getClipWidth(), g.getClipHeight(),
       
   257                                             depth, flags,
       
   258                                             isProperRenderer);
       
   259                     }
       
   260                     currentTarget = g;
       
   261                 }
       
   262                 else if (target instanceof Image2D)
       
   263                 {
       
   264                     Image2D img = (Image2D) target;
       
   265 
       
   266                     offsetX = offsetY = 0;
       
   267 
       
   268                     _bindImage(eventSrcHandle, handle, img.handle, depth, flags);
       
   269                     currentTarget = img;
       
   270                 }
       
   271                 else
   207                 {
   272                 {
   208                     throw new IllegalArgumentException();
   273                     throw new IllegalArgumentException();
   209                 }
   274                 }
   210 
   275             }
   211                 offsetX = g.getTranslateX();
   276             finally
   212                 offsetY = g.getTranslateY();
   277             {
   213 
   278                 // Release event source
   214                 ToolkitInvoker invoker = ToolkitInvoker.getToolkitInvoker();
   279                 Interface.releaseEventSource();
   215 
   280             }
   216                 // NGA specific change.
   281             hints = flags;
   217                 if (ngaEnabled)
   282             depthEnabled = depth;
       
   283         }
       
   284     }
       
   285 
       
   286     /**
       
   287      *
       
   288      */
       
   289     public void releaseTarget()
       
   290     {
       
   291         synchronized (Interface.getInstance()) 
       
   292         {
       
   293             integrityCheck();
       
   294             if (currentTarget == null)
       
   295             {
       
   296                 return;
       
   297             }
       
   298         
       
   299             int eventSrcHandle = 0;
       
   300         
       
   301             try
       
   302             {
       
   303                 // Bind event source
       
   304                 eventSrcHandle = Interface.bindEventSource();
       
   305                 if (currentTarget instanceof Graphics)
   218                 {
   306                 {
   219                     // If overwrite is set, there is no need
   307                     Graphics g = (Graphics) currentTarget;
   220                     // to update EGL surface with 2D content
   308 
   221                     eglContentValid = (flags & OVERWRITE) > 0;
   309                     ToolkitInvoker invoker = ToolkitInvoker.getToolkitInvoker();
   222 
   310 
   223                     // Clip and viewport are stored for later
   311                     // NGA specific change.
   224                     // checks regarding Background clear
   312                     if (ngaEnabled)
   225                     clip.x = g.getClipX() + offsetX;
   313                     {
   226                     clip.y = g.getClipY() + offsetY;
   314                         updateEglContent();
   227                     clip.width = g.getClipWidth();
   315                     }
   228                     clip.height = g.getClipHeight();
   316                     _releaseGraphics(eventSrcHandle, handle,
   229 
   317                                      invoker.graphicsGetHandle(g), isImageTarget, isProperRenderer);
   230                     viewport.x = clip.x;
   318                 }
   231                     viewport.y = clip.y;
   319                 else if (currentTarget instanceof Image2D)
   232                     viewport.width = clip.width;
   320                 {
   233                     viewport.height = clip.height;
   321                     _releaseImage(eventSrcHandle, handle);
   234 
       
   235                     isImageTarget = _bindGraphics(
       
   236                                         eventSrcHandle,
       
   237                                         handle,
       
   238                                         invoker.graphicsGetHandle(g),
       
   239                                         clip.x, clip.y,
       
   240                                         clip.width, clip.height,
       
   241                                         depth, flags,
       
   242                                         isProperRenderer);
       
   243                 }
   322                 }
   244                 else
   323                 else
   245                 {
   324                 {
   246                     isImageTarget = _bindGraphics(
   325                     throw new Error();
   247                                         eventSrcHandle,
       
   248                                         handle,
       
   249                                         invoker.graphicsGetHandle(g),
       
   250                                         g.getClipX() + offsetX, g.getClipY() + offsetY,
       
   251                                         g.getClipWidth(), g.getClipHeight(),
       
   252                                         depth, flags,
       
   253                                         isProperRenderer);
       
   254                 }
   326                 }
   255                 currentTarget = g;
   327             }
   256             }
   328             finally
   257             else if (target instanceof Image2D)
   329             {
   258             {
   330                 currentTarget = null;
   259                 Image2D img = (Image2D) target;
   331                         
   260 
   332                 if (ngaEnabled && !foreground && eventSrcHandle != 0)
   261                 offsetX = offsetY = 0;
       
   262 
       
   263                 _bindImage(eventSrcHandle, handle, img.handle, depth, flags);
       
   264                 currentTarget = img;
       
   265             }
       
   266             else
       
   267             {
       
   268                 throw new IllegalArgumentException();
       
   269             }
       
   270         }
       
   271         finally
       
   272         {
       
   273             // Release event source
       
   274             Interface.releaseEventSource();
       
   275         }
       
   276         hints = flags;
       
   277         depthEnabled = depth;
       
   278     }
       
   279 
       
   280     /**
       
   281      *
       
   282      */
       
   283     public void releaseTarget()
       
   284     {
       
   285         integrityCheck();
       
   286         if (currentTarget == null)
       
   287         {
       
   288             return;
       
   289         }
       
   290         try
       
   291         {
       
   292             // Bind event source
       
   293             int eventSrcHandle = Interface.bindEventSource();
       
   294             if (currentTarget instanceof Graphics)
       
   295             {
       
   296                 Graphics g = (Graphics) currentTarget;
       
   297 
       
   298                 ToolkitInvoker invoker = ToolkitInvoker.getToolkitInvoker();
       
   299 
       
   300                 // NGA specific change.
       
   301                 if (ngaEnabled)
       
   302                 {
   333                 {
   303                     updateEglContent();
   334                     _freeGLESResources(eventSrcHandle, handle);
   304                 }
   335                 }
   305                 _releaseGraphics(eventSrcHandle, handle,
   336 
   306                                  invoker.graphicsGetHandle(g), isImageTarget, isProperRenderer);
   337                 // Release event source
   307             }
   338                 Interface.releaseEventSource();
   308             else if (currentTarget instanceof Image2D)
   339             }
   309             {
       
   310                 _releaseImage(eventSrcHandle, handle);
       
   311             }
       
   312             else
       
   313             {
       
   314                 throw new Error();
       
   315             }
       
   316         }
       
   317         finally
       
   318         {
       
   319             currentTarget = null;
       
   320             // Release event source
       
   321             Interface.releaseEventSource();
       
   322         }
   340         }
   323     }
   341     }
   324 
   342 
   325     /**
   343     /**
   326      *
   344      *
   728                 Interface.releaseEventSource();
   746                 Interface.releaseEventSource();
   729             }
   747             }
   730         }
   748         }
   731     }
   749     }
   732 
   750 
       
   751     void setForeground(boolean foreground) 
       
   752     {
       
   753         synchronized (Interface.getInstance())
       
   754         {
       
   755             this.foreground = foreground;
       
   756             if (ngaEnabled &&
       
   757                 !foreground && 
       
   758                 currentTarget == null)
       
   759             {
       
   760                 try 
       
   761                 {
       
   762                     _freeGLESResources(Interface.bindEventSource(), handle);
       
   763                 }
       
   764                 finally
       
   765                 {
       
   766                     Interface.releaseEventSource();
       
   767                 }
       
   768             }
       
   769         }
       
   770     }
       
   771     
   733     private native static int _ctor(int hInterface);
   772     private native static int _ctor(int hInterface);
   734     private native static void _addRef(int hObject);
   773     private native static void _addRef(int hObject);
   735 
   774 
   736     private native static int _addLight(int handle,
   775     private native static int _addLight(int handle,
   737                                         int hLight,
   776                                         int hLight,
   809     // NGA specific changes.
   848     // NGA specific changes.
   810     private native static int _getTargetHeight(int graphicsHandle);
   849     private native static int _getTargetHeight(int graphicsHandle);
   811     private native static int _getTargetWidth(int graphicsHandle);
   850     private native static int _getTargetWidth(int graphicsHandle);
   812     private native static void _updateEglContent(int eventSourceHandle,
   851     private native static void _updateEglContent(int eventSourceHandle,
   813             int graphicsHandle);
   852             int graphicsHandle);
       
   853     private native static void _freeGLESResources(int eventSourceHandle, 
       
   854             int handle);
   814 }
   855 }