Search in sources :

Example 1 with D3DWindowSurfaceData

use of sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData in project jdk8u_jdk by JetBrains.

the class D3DScreenUpdateManager method createGraphics.

/**
     * Creates a graphics object for the passed in surface data. If
     * the surface is lost, it is restored.
     * If the surface wasn't lost or the restoration was successful
     * the surface is added to the list of maintained surfaces
     * (if it hasn't been already).
     *
     * If the updater thread hasn't been created yet , it will be created and
     * started.
     *
     * @param sd surface data for which to create SunGraphics2D
     * @param peer peer associated with the surface data
     * @param fgColor fg color to be used in graphics
     * @param bgColor bg color to be used in graphics
     * @param font font to be used in graphics
     * @return a SunGraphics2D object for the surface (or for temp GDI
     * surface data)
     */
@Override
public Graphics2D createGraphics(SurfaceData sd, WComponentPeer peer, Color fgColor, Color bgColor, Font font) {
    if (!done && sd instanceof D3DWindowSurfaceData) {
        D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData) sd;
        if (!d3dw.isSurfaceLost() || validate(d3dw)) {
            trackScreenSurface(d3dw);
            return new SunGraphics2D(sd, fgColor, bgColor, font);
        }
        // could not restore the d3dw surface, use the cached gdi surface
        // instead for this graphics object; note that we do not track
        // this new gdi surface, it is only used for this graphics
        // object
        sd = getGdiSurface(d3dw);
    }
    return super.createGraphics(sd, peer, fgColor, bgColor, font);
}
Also used : SunGraphics2D(sun.java2d.SunGraphics2D) D3DWindowSurfaceData(sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)

Example 2 with D3DWindowSurfaceData

use of sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData in project jdk8u_jdk by JetBrains.

the class D3DScreenUpdateManager method run.

public void run() {
    while (!done) {
        synchronized (runLock) {
            // If the list is empty, suspend the thread until a
            // new surface is added. Note that we have to check before
            // wait() (and inside the runLock), otherwise we could miss a
            // notify() when a new surface is added and sleep forever.
            long timeout = d3dwSurfaces.size() > 0 ? 100 : 0;
            // don't go to sleep if there's a thread waiting for an update
            if (!needsUpdateNow) {
                try {
                    runLock.wait(timeout);
                } catch (InterruptedException e) {
                }
            }
        // if we were woken up, there are probably surfaces in the list,
        // no need to check if the list is empty
        }
        // make a copy to avoid synchronization during the loop
        D3DWindowSurfaceData[] surfaces = new D3DWindowSurfaceData[] {};
        synchronized (this) {
            surfaces = d3dwSurfaces.toArray(surfaces);
        }
        for (D3DWindowSurfaceData sd : surfaces) {
            // after we made a copy of the list) - just a precaution
            if (sd.isValid() && (sd.isDirty() || sd.isSurfaceLost())) {
                if (!sd.isSurfaceLost()) {
                    // the flip and the clearing of the dirty state
                    // must be done under the lock, otherwise it's
                    // possible to miss an update to the surface
                    D3DRenderQueue rq = D3DRenderQueue.getInstance();
                    rq.lock();
                    try {
                        Rectangle r = sd.getBounds();
                        D3DSurfaceData.swapBuffers(sd, 0, 0, r.width, r.height);
                        sd.markClean();
                    } finally {
                        rq.unlock();
                    }
                } else if (!validate(sd)) {
                    // it is possible that the validation may never
                    // succeed, we need to detect this and replace
                    // the d3dw surface with gdi; the replacement of
                    // the surface will also trigger a repaint
                    sd.getPeer().replaceSurfaceDataLater();
                }
            }
        }
        synchronized (runLock) {
            needsUpdateNow = false;
            runLock.notifyAll();
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) D3DWindowSurfaceData(sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)

Example 3 with D3DWindowSurfaceData

use of sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData in project jdk8u_jdk by JetBrains.

the class D3DScreenUpdateManager method getGdiSurface.

/**
     * Creates (or returns a cached one) gdi surface for the same peer as
     * the passed d3dw surface has.
     *
     * @param d3dw surface used as key into the cache
     * @return gdi window surface associated with the d3d window surfaces' peer
     */
private synchronized SurfaceData getGdiSurface(D3DWindowSurfaceData d3dw) {
    if (gdiSurfaces == null) {
        gdiSurfaces = new HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData>();
    }
    GDIWindowSurfaceData gdisd = gdiSurfaces.get(d3dw);
    if (gdisd == null) {
        gdisd = GDIWindowSurfaceData.createData(d3dw.getPeer());
        gdiSurfaces.put(d3dw, gdisd);
    }
    return gdisd;
}
Also used : GDIWindowSurfaceData(sun.java2d.windows.GDIWindowSurfaceData) D3DWindowSurfaceData(sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)

Example 4 with D3DWindowSurfaceData

use of sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData in project jdk8u_jdk by JetBrains.

the class D3DScreenUpdateManager method dropScreenSurface.

@Override
public synchronized void dropScreenSurface(SurfaceData sd) {
    if (d3dwSurfaces != null && sd instanceof D3DWindowSurfaceData) {
        D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData) sd;
        removeGdiSurface(d3dw);
        d3dwSurfaces.remove(d3dw);
    }
}
Also used : D3DWindowSurfaceData(sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)

Aggregations

D3DWindowSurfaceData (sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData)4 Rectangle (java.awt.Rectangle)1 SunGraphics2D (sun.java2d.SunGraphics2D)1 GDIWindowSurfaceData (sun.java2d.windows.GDIWindowSurfaceData)1