merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / java / BackBuffer.java
blob47b8f419fb7694cfcc5c17f0ba251b5cb434a6c3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BackBuffer.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // Java AWT
32 import java.awt.*;
33 import java.awt.image.*;
35 public class BackBuffer
37 private BufferedImage backBuffer;
38 //private VolatileImage backBuffer;
39 private Graphics2D backBufferGraphics;
40 private Graphics2D referenceDevice;
42 public BackBuffer( Graphics2D _referenceDevice,
43 int width,
44 int height )
46 referenceDevice = _referenceDevice;
47 setSize( width, height );
50 public Graphics2D getGraphics()
52 return backBufferGraphics;
55 public void setSize( int width,
56 int height )
58 if( backBuffer != null &&
59 width == backBuffer.getWidth() &&
60 height == backBuffer.getHeight() )
62 return;
65 if( backBufferGraphics != null )
66 backBufferGraphics.dispose();
68 if( backBuffer != null )
69 backBuffer.flush();
71 // TODO: Maybe VolatileImage with another BufferedImage as a backup is
72 // a tad faster here.
73 backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleImage(width,
74 height);
75 // backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleVolatileImage(width,
76 // height);
78 backBufferGraphics = backBuffer.createGraphics();
79 CanvasUtils.initGraphics( backBufferGraphics );
81 // clear the buffer to white (to have a defined state here)
82 backBufferGraphics.setColor( java.awt.Color.white );
83 backBufferGraphics.fillRect( 0,0,width,height );
86 public void redraw( Graphics2D graph )
88 if( graph != null &&
89 backBuffer != null )
91 CanvasUtils.printLog("BackBuffer.redraw(): using buffer of size (" +
92 backBuffer.getWidth() + "," + backBuffer.getHeight() + ")" );
94 graph.drawImage(backBuffer, 0, 0, null);
96 // TODO: this is just twiddled to work. I cannot be sure
97 // that this volatile backbuffer will survive in the first
98 // place, nor that it wise to leave it in VRAM.
100 // only flush non-volatile images
101 // CanvasUtils.postRenderImageTreatment( backBuffer );
105 public java.awt.Image getBackBuffer()
107 return backBuffer;
110 public void dispose()
112 backBufferGraphics.dispose();
113 backBuffer.flush();