Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/d3d/D3DRenderQueue.java
32288 views
/*1* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.d3d;2627import sun.java2d.ScreenUpdateManager;28import sun.java2d.pipe.RenderBuffer;29import sun.java2d.pipe.RenderQueue;30import static sun.java2d.pipe.BufferedOpCodes.*;3132/**33* D3D-specific implementation of RenderQueue.34*/35public class D3DRenderQueue extends RenderQueue {3637private static D3DRenderQueue theInstance;38private static Thread rqThread;3940private D3DRenderQueue() {41}4243/**44* Returns the single D3DRenderQueue instance. If it has not yet been45* initialized, this method will first construct the single instance46* before returning it.47*/48public static synchronized D3DRenderQueue getInstance() {49if (theInstance == null) {50theInstance = new D3DRenderQueue();51// no need to lock, noone has reference to this instance yet52theInstance.flushAndInvokeNow(new Runnable() {53public void run() {54rqThread = Thread.currentThread();55}56});57}58return theInstance;59}6061/**62* Flushes the single D3DRenderQueue instance synchronously. If an63* D3DRenderQueue has not yet been instantiated, this method is a no-op.64* This method is useful in the case of Toolkit.sync(), in which we want65* to flush the D3D pipeline, but only if the D3D pipeline is currently66* enabled. Since this class has few external dependencies, callers need67* not be concerned that calling this method will trigger initialization68* of the D3D pipeline and related classes.69*/70public static void sync() {71if (theInstance != null) {72// need to make sure any/all screen surfaces are presented prior73// to completing the sync operation74D3DScreenUpdateManager mgr =75(D3DScreenUpdateManager)ScreenUpdateManager.getInstance();76mgr.runUpdateNow();7778theInstance.lock();79try {80theInstance.ensureCapacity(4);81theInstance.getBuffer().putInt(SYNC);82theInstance.flushNow();83} finally {84theInstance.unlock();85}86}87}8889/**90* Attempt to restore the devices if they're in the lost state.91* (used when a full-screen window is activated/deactivated)92*/93public static void restoreDevices() {94D3DRenderQueue rq = getInstance();95rq.lock();96try {97rq.ensureCapacity(4);98rq.getBuffer().putInt(RESTORE_DEVICES);99rq.flushNow();100} finally {101rq.unlock();102}103}104105/**106* @return true if current thread is the render queue thread,107* false otherwise108*/109public static boolean isRenderQueueThread() {110return (Thread.currentThread() == rqThread);111}112113/**114* Disposes the native memory associated with the given native115* graphics config info pointer on the single queue flushing thread.116*/117public static void disposeGraphicsConfig(long pConfigInfo) {118D3DRenderQueue rq = getInstance();119rq.lock();120try {121122RenderBuffer buf = rq.getBuffer();123rq.ensureCapacityAndAlignment(12, 4);124buf.putInt(DISPOSE_CONFIG);125buf.putLong(pConfigInfo);126127// this call is expected to complete synchronously, so flush now128rq.flushNow();129} finally {130rq.unlock();131}132}133134public void flushNow() {135// assert lock.isHeldByCurrentThread();136flushBuffer(null);137}138139public void flushAndInvokeNow(Runnable r) {140// assert lock.isHeldByCurrentThread();141flushBuffer(r);142}143144private native void flushBuffer(long buf, int limit, Runnable task);145146private void flushBuffer(Runnable task) {147// assert lock.isHeldByCurrentThread();148int limit = buf.position();149if (limit > 0 || task != null) {150// process the queue151flushBuffer(buf.getAddress(), limit, task);152}153// reset the buffer position154buf.clear();155// clear the set of references, since we no longer need them156refSet.clear();157}158}159160161