/* * $Id$ * * Copyright (C) 2003-2015 JNode.org * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package org.jnode.driver.video.cirrus; import org.jnode.driver.Device; import org.jnode.driver.DeviceException; import org.jnode.driver.DriverException; import org.jnode.driver.bus.pci.PCIDevice; import org.jnode.driver.video.AbstractFrameBufferDriver; import org.jnode.driver.video.AlreadyOpenException; import org.jnode.driver.video.FrameBufferConfiguration; import org.jnode.driver.video.HardwareCursorAPI; import org.jnode.driver.video.NotOpenException; import org.jnode.driver.video.Surface; import org.jnode.driver.video.UnknownConfigurationException; import org.jnode.driver.video.ddc.DisplayDataChannelAPI; import org.jnode.plugin.ConfigurationElement; import org.jnode.system.resource.ResourceNotFreeException; /** * @author peda */ public class CirrusDriver extends AbstractFrameBufferDriver implements CirrusConstants { private final String architecture; private final String model; private FrameBufferConfiguration currentConfig; private CirrusCore driver; /** * Create a new instance */ public CirrusDriver(ConfigurationElement config) throws DriverException { this(config.getAttribute("architecture"), config.getAttribute("name")); } /** * Create a new instance */ public CirrusDriver(String architecture, String model) { this.architecture = architecture; this.model = model; } /** * @see org.jnode.driver.video.FrameBufferAPI#getConfigurations() */ public final FrameBufferConfiguration[] getConfigurations() { return driver.getConfigurations(); } /** * @see org.jnode.driver.video.FrameBufferAPI#getCurrentConfiguration() */ public final FrameBufferConfiguration getCurrentConfiguration() { return currentConfig; } /** * @see org.jnode.driver.video.FrameBufferAPI#open(org.jnode.driver.video.FrameBufferConfiguration) */ public synchronized Surface open(FrameBufferConfiguration config) throws UnknownConfigurationException, AlreadyOpenException, DeviceException { // TODO: do check if mode is possible driver.open(config); return driver; } /** * @see org.jnode.driver.video.FrameBufferAPI#getCurrentSurface() */ public synchronized Surface getCurrentSurface() throws NotOpenException { if (currentConfig != null) { return driver; } else { throw new NotOpenException(); } } /** * @see org.jnode.driver.video.FrameBufferAPI#isOpen() */ public final synchronized boolean isOpen() { return (currentConfig != null); } /** * close the current config */ public final void close() { this.currentConfig = null; } /** * @see org.jnode.driver.Driver#startDevice() */ protected void startDevice() throws DriverException { try { driver = new CirrusCore(this, architecture, model, (PCIDevice) getDevice()); } catch (ResourceNotFreeException ex) { throw new DriverException(ex); } super.startDevice(); @SuppressWarnings("unused") final Device dev = getDevice(); //dev.registerAPI(DisplayDataChannelAPI.class, driver); // <-- should we register this one? We do read edid our own.. //dev.registerAPI(HardwareCursorAPI.class, driver.getHardwareCursor()); } /** * @see org.jnode.driver.Driver#stopDevice() */ protected void stopDevice() throws DriverException { if (currentConfig != null) { driver.close(); } if (driver != null) { driver.release(); driver = null; } final Device dev = getDevice(); dev.unregisterAPI(DisplayDataChannelAPI.class); dev.unregisterAPI(HardwareCursorAPI.class); super.stopDevice(); } }