📄 mastercontrol.java
字号:
synchronized (mcThreadLock) { synchronized (requestObjList) { if (!pendingRequest) { mcThread = null; if (renderingAttributesStructure.updateThread != null) { renderingAttributesStructure.updateThread.finish(); renderingAttributesStructure.updateThread = null; } renderingAttributesStructure = new RenderingAttributesStructure(); if (timerThread != null) { timerThread.finish(); timerThread = null; } if (notificationThread != null) { notificationThread.finish(); notificationThread = null; } requestObjList.clear(); requestTypeList.clear(); return true; } running = true; createMCThreads(); return false; } } } /** * Returns whether we are using D3D. * TODO: most code that cares about this should move into the pipeline */ final boolean isD3D() { return Pipeline.getPipeline().getPipelineType() == Pipeline.Type.NATIVE_D3D; } /** * Returns whether we are running on Windows * TODO: most code that cares about this should move into the pipeline */ static final boolean isWindows() { return isWindowsOs; } /** * Returns a flag indicating whether the sun.jnlp.applet.launcher system * property is set to true. */ static boolean isAppletLauncher() { return appletLauncher; } /** * This method increments and returns the next time value * timeLock must get before this procedure is invoked */ final long getTime() { return (time++); } /** * This takes a given message and parses it out to the structures and * marks its time value. */ void processMessage(J3dMessage message) { synchronized (timeLock) { message.time = getTime(); sendMessage(message); } setWork(); } /** * This takes an array of messages and parses them out to the structures and * marks the time value. Make sure, setWork() is done at the very end * to make sure all the messages will be processed in the same frame */ void processMessage(J3dMessage[] messages) { synchronized (timeLock) { long time = getTime(); for (int i = 0; i < messages.length; i++) { messages[i].time = time; sendMessage(messages[i]); } } setWork(); } /** * This takes the specified notification message and sends it to the * notification thread for processing. */ void sendNotification(J3dNotification notification) { notificationThread.addNotification(notification); } /** * Create and start the MasterControl Thread. */ void createMasterControlThread() { // Issue 364: don't create master control thread if already created if (mcThread != null) { return; } running = true; workToDo = true; state = RUNNING; java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { synchronized (rootThreadGroup) { mcThread = new MasterControlThread(rootThreadGroup); mcThread.setPriority(threadPriority); } return null; } }); } // assuming the timeLock is already acquired /** * Send a message to another Java 3D thread. */ void sendMessage(J3dMessage message) { synchronized (message) { VirtualUniverse u = message.universe; int targetThreads = message.threads; if (isCoreLoggable(Level.FINEST)) { dumpMessage("sendMessage", message); } if ((targetThreads & J3dThread.UPDATE_RENDERING_ATTRIBUTES) != 0) { renderingAttributesStructure.addMessage(message); } // GraphicsContext3D send message with universe = null if (u != null) { if ((targetThreads & J3dThread.UPDATE_GEOMETRY) != 0) { u.geometryStructure.addMessage(message); } if ((targetThreads & J3dThread.UPDATE_TRANSFORM) != 0) { u.transformStructure.addMessage(message); } if ((targetThreads & J3dThread.UPDATE_BEHAVIOR) != 0) { u.behaviorStructure.addMessage(message); } if ((targetThreads & J3dThread.UPDATE_SOUND) != 0) { u.soundStructure.addMessage(message); } if ((targetThreads & J3dThread.UPDATE_RENDERING_ENVIRONMENT) != 0) { u.renderingEnvironmentStructure.addMessage(message); } } if ((targetThreads & J3dThread.SOUND_SCHEDULER) != 0) { // Note that we don't check for active view if (message.view != null && message.view.soundScheduler != null ) { // This make sure that message won't lost even // though this view not yet register message.view.soundScheduler.addMessage(message); } else { synchronized (views) { View v[] = (View []) views.toArray(false); int i = views.arraySize()-1; if (u == null) { while (i>=0) { v[i--].soundScheduler.addMessage(message); } } else { while (i>=0) { if (v[i].universe == u) { v[i].soundScheduler.addMessage(message); } i--; } } } } } if ((targetThreads & J3dThread.UPDATE_RENDER) != 0) { // Note that we don't check for active view if (message.view != null && message.view.renderBin != null) { // This make sure that message won't lost even // though this view not yet register message.view.renderBin.addMessage(message); } else { synchronized (views) { View v[] = (View []) views.toArray(false); int i = i=views.arraySize()-1; if (u == null) { while (i>=0) { v[i--].renderBin.addMessage(message); } } else { while (i>=0) { if (v[i].universe == u) { v[i].renderBin.addMessage(message); } i--; } } } } } if (message.getRefcount() == 0) { message.clear(); } } } /** * Send a message to another Java 3D thread. * This variant is only call by TimerThread for Input Device Scheduler * or to redraw all View for RenderThread */ void sendRunMessage(int targetThreads) { synchronized (timeLock) { long time = getTime(); if ((targetThreads & J3dThread.INPUT_DEVICE_SCHEDULER) != 0) { synchronized (inputDeviceThreads) { InputDeviceScheduler ds[] = (InputDeviceScheduler []) inputDeviceThreads.toArray(false); for (int i=inputDeviceThreads.size()-1; i >=0; i--) { if (ds[i].physicalEnv.activeViewRef > 0) { ds[i].getThreadData().lastUpdateTime = time; } } // timerThread instance in MC will set to null in // destroyUniverseThreads() so we need to check if // TimerThread kick in to sendRunMessage() after that. // It happens because TimerThread is the only thread run // asychronizously with MasterControl thread. if (timerThread != null) { // Notify TimerThread to wakeup this procedure // again next time. timerThread.addInputDeviceSchedCond(); } } } if ((targetThreads & J3dThread.RENDER_THREAD) != 0) { synchronized (renderThreadData) { J3dThreadData[] threads = (J3dThreadData []) renderThreadData.toArray(false); int i=renderThreadData.arraySize()-1; J3dThreadData thr; while (i>=0) { thr = threads[i--]; if ( thr.view.renderBinReady) { thr.lastUpdateTime = time; } } } } } setWork(); } /** * Send a message to another Java 3D thread. * This variant is only call by TimerThread for Sound Scheduler */ void sendRunMessage(long waitTime, View view, int targetThreads) { synchronized (timeLock) { long time = getTime(); if ((targetThreads & J3dThread.SOUND_SCHEDULER) != 0) { if (view.soundScheduler != null) { view.soundScheduler.threadData.lastUpdateTime = time; } // wakeup this procedure next time // QUESTION: waitTime calculated some milliseconds BEFORE // this methods getTime() called - shouldn't actual // sound Complete time be passed by SoundScheduler // QUESTION: will this wake up only soundScheduler associated // with this view?? (since only it's lastUpdateTime is set) // or all soundSchedulers?? timerThread.addSoundSchedCond(time+waitTime); } } setWork(); } /** * Send a message to another Java 3D thread. * This variant is only called to update Render Thread */ void sendRunMessage(View v, int targetThreads) { synchronized (timeLock) { long time = getTime(); if ((targetThreads & J3dThread.RENDER_THREAD) != 0) { synchronized (renderThreadData) { J3dThreadData[] threads = (J3dThreadData []) renderThreadData.toArray(false); int i=renderThreadData.arraySize()-1; J3dThreadData thr; while (i>=0) { thr = threads[i--]; if (thr.view == v && v.renderBinReady) { thr.lastUpdateTime = time; } } } } } setWork(); } /** * This sends a run message to the given threads. */ void sendRunMessage(VirtualUniverse u, int targetThreads) { // We don't sendRunMessage to update structure except Behavior synchronized (timeLock) { long time = getTime(); if ((targetThreads & J3dThread.BEHAVIOR_SCHEDULER) != 0) { if (u.behaviorScheduler != null) { u.behaviorScheduler.getThreadData(null, null).lastUpdateTime = time; } } if ((targetThreads & J3dThread.UPDATE_BEHAVIOR) != 0) { u.behaviorStructure.threadData.lastUpdateTime = time; } if ((targetThreads & J3dThread.UPDATE_GEOMETRY) != 0) { u.geometryStructure.threadData.lastUpdateTime = time; } if ((targetThreads & J3dThread.UPDATE_SOUND) != 0) { u.soundStructure.threadData.lastUpdateTime = time; } if ((targetThreads & J3dThread.SOUND_SCHEDULER) != 0) { synchronized (views) { View v[] = (View []) views.toArray(false); for (int i= views.arraySize()-1; i >=0; i--) { if ((v[i].soundScheduler != null) && (v[i].universe == u)) { v[i].soundScheduler.threadData.lastUpdateTime = time; } } } } if ((targetThreads & J3dThread.RENDER_THREAD) != 0) { synchronized (renderThreadData) { J3dThreadData[] threads = (J3dThreadData []) renderThreadData.toArray(false); int i=renderThreadData.arraySize()-1; J3dThreadData thr; while (i>=0) { thr = threads[i--]; if (thr.view.universe == u && thr.view.renderBinReady) { thr.lastUpdateTime = time; } } } } } setWork(); } /** * Return a clone of View, we can't access * individual element of View after getting the size * in separate API call without synchronized views. */ UnorderList cloneView() { return (UnorderList) views.clone(); } /** * Return true if view is already registered with MC */ boolean isRegistered(View view) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -