4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4691N/A
4632N/Apackage sun.lwawt;
4632N/A
4801N/Aimport sun.awt.CGraphicsConfig;
4801N/A
4632N/Aimport java.awt.BufferCapabilities;
4801N/Aimport java.awt.BufferCapabilities.FlipContents;
4632N/Aimport java.awt.Canvas;
4632N/Aimport java.awt.Component;
4801N/Aimport java.awt.Graphics;
4801N/Aimport java.awt.Graphics2D;
4632N/Aimport java.awt.GraphicsConfiguration;
4632N/Aimport java.awt.Image;
4801N/Aimport java.awt.image.VolatileImage;
4632N/Aimport java.awt.peer.CanvasPeer;
4632N/A
4632N/Aimport javax.swing.JComponent;
4632N/A
4691N/Afinal class LWCanvasPeer extends LWComponentPeer<Component, JComponent>
4691N/A implements CanvasPeer {
4691N/A
4801N/A /**
4801N/A * The back buffer provide user with a BufferStrategy.
4801N/A */
4801N/A private VolatileImage backBuffer;
4801N/A
4801N/A LWCanvasPeer(final Canvas target,
4801N/A final PlatformComponent platformComponent) {
4632N/A super(target, platformComponent);
4632N/A }
4632N/A
4632N/A @Override
4801N/A public void createBuffers(final int numBuffers,
4801N/A final BufferCapabilities caps) {
4801N/A //TODO parameters should be used.
4801N/A final CGraphicsConfig gc = (CGraphicsConfig) getGraphicsConfiguration();
4801N/A final VolatileImage buffer = gc.createBackBufferImage(getTarget(), 0);
4801N/A synchronized (getStateLock()) {
4801N/A backBuffer = buffer;
4801N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public Image getBackBuffer() {
4801N/A synchronized (getStateLock()) {
4801N/A return backBuffer;
4801N/A }
4632N/A }
4632N/A
4632N/A @Override
4801N/A public void flip(final int x1, final int y1, final int x2, final int y2,
4801N/A final FlipContents flipAction) {
4801N/A final VolatileImage buffer = (VolatileImage) getBackBuffer();
4801N/A if (buffer == null) {
4801N/A throw new IllegalStateException("Buffers have not been created");
4801N/A }
4801N/A final Graphics g = getGraphics();
4801N/A try {
4801N/A g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
4801N/A } finally {
4801N/A g.dispose();
4801N/A }
4801N/A if (flipAction == FlipContents.BACKGROUND) {
4801N/A final Graphics2D bg = (Graphics2D) buffer.getGraphics();
4801N/A try {
4801N/A bg.setBackground(getBackground());
4801N/A bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
4801N/A } finally {
4801N/A bg.dispose();
4801N/A }
4801N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void destroyBuffers() {
4801N/A final Image buffer = getBackBuffer();
4801N/A if (buffer != null) {
4801N/A synchronized (getStateLock()) {
4801N/A if (buffer == backBuffer) {
4801N/A backBuffer = null;
4801N/A }
4801N/A }
4801N/A buffer.flush();
4801N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public GraphicsConfiguration getAppropriateGraphicsConfiguration(
4632N/A GraphicsConfiguration gc)
4632N/A {
4632N/A // TODO
4632N/A return gc;
4632N/A }
4632N/A}