2370N/A/*
2685N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2370N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2370N/A *
2370N/A * This code is free software; you can redistribute it and/or modify it
2370N/A * under the terms of the GNU General Public License version 2 only, as
2685N/A * published by the Free Software Foundation. Oracle designates this
2370N/A * particular file as subject to the "Classpath" exception as provided
2685N/A * by Oracle in the LICENSE file that accompanied this code.
2370N/A *
2370N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2370N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2370N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2370N/A * version 2 for more details (a copy is included in the LICENSE file that
2370N/A * accompanied this code).
2370N/A *
2370N/A * You should have received a copy of the GNU General Public License version
2370N/A * 2 along with this work; if not, write to the Free Software Foundation,
2370N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2370N/A *
2685N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2685N/A * or visit www.oracle.com if you need additional information or have any
2685N/A * questions.
2370N/A */
2370N/A
2370N/Apackage sun.java2d.xr;
2370N/A
2370N/Aimport java.awt.GraphicsConfiguration;
2370N/Aimport java.awt.ImageCapabilities;
2370N/Aimport java.awt.image.ColorModel;
2370N/Aimport sun.awt.image.SunVolatileImage;
2370N/Aimport sun.awt.image.VolatileSurfaceManager;
2370N/Aimport sun.java2d.SurfaceData;
2370N/A
2370N/A/**
2370N/A * XRender platform implementation of the VolatileSurfaceManager class.
2370N/A */
2370N/Apublic class XRVolatileSurfaceManager extends VolatileSurfaceManager {
2370N/A
2370N/A public XRVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
2370N/A super(vImg, context);
2370N/A }
2370N/A
2370N/A protected boolean isAccelerationEnabled() {
2370N/A return true;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Create a pixmap-based SurfaceData object
2370N/A */
2370N/A protected SurfaceData initAcceleratedSurface() {
2370N/A SurfaceData sData;
2370N/A
2370N/A try {
2370N/A XRGraphicsConfig gc = (XRGraphicsConfig) vImg.getGraphicsConfig();
2370N/A ColorModel cm = gc.getColorModel();
2370N/A long drawable = 0;
2370N/A if (context instanceof Long) {
2370N/A drawable = ((Long)context).longValue();
2370N/A }
2370N/A sData = XRSurfaceData.createData(gc,
2370N/A vImg.getWidth(),
2370N/A vImg.getHeight(),
2370N/A cm, vImg, drawable,
2370N/A vImg.getTransparency());
2370N/A } catch (NullPointerException ex) {
2370N/A sData = null;
2370N/A } catch (OutOfMemoryError er) {
2370N/A sData = null;
2370N/A }
2370N/A
2370N/A return sData;
2370N/A }
2370N/A
2370N/A /**
2370N/A * XRender should allow copies between different formats and depths.
2370N/A * TODO: verify that this assumption is correct.
2370N/A */
2370N/A protected boolean isConfigValid(GraphicsConfiguration gc) {
2370N/A return true;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Need to override the default behavior because Pixmaps-based
2370N/A * images are accelerated but not volatile.
2370N/A */
2370N/A @Override
2370N/A public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
2370N/A if (isConfigValid(gc) && isAccelerationEnabled()) {
2370N/A return new ImageCapabilities(true);
2370N/A }
2370N/A return new ImageCapabilities(false);
2370N/A }
2370N/A}