1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BackBuffer.java,v $
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 ************************************************************************/
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
,
46 referenceDevice
= _referenceDevice
;
47 setSize( width
, height
);
50 public Graphics2D
getGraphics()
52 return backBufferGraphics
;
55 public void setSize( int width
,
58 if( backBuffer
!= null &&
59 width
== backBuffer
.getWidth() &&
60 height
== backBuffer
.getHeight() )
65 if( backBufferGraphics
!= null )
66 backBufferGraphics
.dispose();
68 if( backBuffer
!= null )
71 // TODO: Maybe VolatileImage with another BufferedImage as a backup is
73 backBuffer
= referenceDevice
.getDeviceConfiguration().createCompatibleImage(width
,
75 // backBuffer = referenceDevice.getDeviceConfiguration().createCompatibleVolatileImage(width,
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
)
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()
110 public void dispose()
112 backBufferGraphics
.dispose();