430N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
430N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A
430N/Apackage sun.java2d.d3d;
430N/A
430N/Aimport java.awt.Color;
430N/Aimport java.awt.Transparency;
430N/A
430N/Aimport sun.java2d.InvalidPipeException;
430N/Aimport sun.java2d.SurfaceData;
430N/Aimport sun.java2d.SurfaceDataProxy;
430N/Aimport sun.java2d.loops.CompositeType;
430N/A
430N/A/**
430N/A * The proxy class contains the logic for when to replace a
430N/A * SurfaceData with a cached D3D Texture and the code to create
430N/A * the accelerated surfaces.
430N/A */
430N/Apublic class D3DSurfaceDataProxy extends SurfaceDataProxy {
430N/A
430N/A public static SurfaceDataProxy createProxy(SurfaceData srcData,
430N/A D3DGraphicsConfig dstConfig)
430N/A {
430N/A if (srcData instanceof D3DSurfaceData) {
430N/A // srcData must be a VolatileImage which either matches
430N/A // our pixel format or not - either way we do not cache it...
430N/A return UNCACHED;
430N/A }
430N/A
430N/A return new D3DSurfaceDataProxy(dstConfig, srcData.getTransparency());
430N/A }
430N/A
430N/A D3DGraphicsConfig d3dgc;
430N/A int transparency;
430N/A
430N/A public D3DSurfaceDataProxy(D3DGraphicsConfig d3dgc, int transparency) {
430N/A this.d3dgc = d3dgc;
430N/A this.transparency = transparency;
430N/A // REMIND: we may want to change this for the d3d pipeline, it's not
430N/A // necessary to invalidate them all at once on display change
430N/A activateDisplayListener();
430N/A }
430N/A
430N/A @Override
430N/A public SurfaceData validateSurfaceData(SurfaceData srcData,
430N/A SurfaceData cachedData,
430N/A int w, int h)
430N/A {
430N/A if (cachedData == null || cachedData.isSurfaceLost()) {
430N/A try {
430N/A cachedData = d3dgc.createManagedSurface(w, h, transparency);
430N/A } catch (InvalidPipeException e) {
430N/A if (!d3dgc.getD3DDevice().isD3DAvailable()) {
430N/A invalidate();
430N/A flush();
430N/A return null;
430N/A }
430N/A }
430N/A }
430N/A return cachedData;
430N/A }
430N/A
430N/A @Override
430N/A public boolean isSupportedOperation(SurfaceData srcData,
430N/A int txtype,
430N/A CompositeType comp,
430N/A Color bgColor)
430N/A {
430N/A return (bgColor == null || transparency == Transparency.OPAQUE);
430N/A }
430N/A}