Makefile.am (gtk_awt_peer_sources): Add GtkVolatileImage.java.
2005-05-06 Thomas Fitzsimmons <fitzsim@redhat.com> * Makefile.am (gtk_awt_peer_sources): Add GtkVolatileImage.java. * Makefile.in: Regenerate. * gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java (createCompatibleVolatileImage(int,int)): Implement. (createCompatibleVolatileImage(int,int,ImageCapabilities)): Likewise. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (backBuffer, caps): New fields. (createVolatileImage): Implement. (createBuffers): Likewise. (getBackBuffer): Likewise. (flip): Likewise. (destroyBuffers): Likewise. * gnu/java/awt/peer/gtk/GtkVolatileImage.java: New file. * java/awt/Canvas.java (CanvasBltBufferStrategy): New class. (CanvasFlipBufferStrategy): Likewise. (createBufferStrategy(int)): New method. (createBufferStrategy(int,BufferCapabilities)): Likewise. * java/awt/Component.java (BltBufferStrategy): Implement and document class. (FlipBufferStrategy): Likewise. * java/awt/Window.java (WindowBltBufferStrategy): New class. (WindowFlipBufferStrategy): Likewise. (createBufferStrategy(int)): New method. (createBufferStrategy(int,BufferCapabilities)): Likewise. (getBufferStrategy): Likewise. * java/awt/BufferCapabilities.java (BufferCapabilities): Rename front to frontCaps and back to backCaps. From-SVN: r99336
This commit is contained in:
parent
91a01f21ab
commit
2ed0018eb4
13 changed files with 966 additions and 73 deletions
|
@ -5574,78 +5574,432 @@ p * <li>the set of backward traversal keys
|
|||
} // class AccessibleAWTComponent
|
||||
|
||||
/**
|
||||
* This class provides support for blitting offscreen surfaces.
|
||||
* This class provides support for blitting offscreen surfaces to a
|
||||
* component.
|
||||
*
|
||||
* @see BufferStrategy
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.4
|
||||
* @XXX Shell class, to allow compilation. This needs documentation and
|
||||
* correct implementation.
|
||||
*/
|
||||
protected class BltBufferStrategy extends BufferStrategy
|
||||
{
|
||||
/**
|
||||
* The capabilities of the image buffer.
|
||||
*/
|
||||
protected BufferCapabilities caps;
|
||||
|
||||
/**
|
||||
* The back buffers used in this strategy.
|
||||
*/
|
||||
protected VolatileImage[] backBuffers;
|
||||
|
||||
/**
|
||||
* Whether or not the image buffer resources are allocated and
|
||||
* ready to be drawn into.
|
||||
*/
|
||||
protected boolean validatedContents;
|
||||
|
||||
/**
|
||||
* The width of the back buffers.
|
||||
*/
|
||||
protected int width;
|
||||
|
||||
/**
|
||||
* The height of the back buffers.
|
||||
*/
|
||||
protected int height;
|
||||
protected BltBufferStrategy(int num, BufferCapabilities caps)
|
||||
|
||||
/**
|
||||
* The front buffer.
|
||||
*/
|
||||
private VolatileImage frontBuffer;
|
||||
|
||||
/**
|
||||
* Creates a blitting buffer strategy.
|
||||
*
|
||||
* @param numBuffers the number of buffers, including the front
|
||||
* buffer
|
||||
* @param caps the capabilities of this strategy
|
||||
*/
|
||||
protected BltBufferStrategy(int numBuffers, BufferCapabilities caps)
|
||||
{
|
||||
this.caps = caps;
|
||||
createBackBuffers(num);
|
||||
createBackBuffers(numBuffers - 1);
|
||||
width = getWidth();
|
||||
height = getHeight();
|
||||
}
|
||||
protected void createBackBuffers(int num)
|
||||
|
||||
/**
|
||||
* Initializes the backBuffers field with an array of numBuffers
|
||||
* VolatileImages.
|
||||
*
|
||||
* @param numBuffers the number of backbuffers to create
|
||||
*/
|
||||
protected void createBackBuffers(int numBuffers)
|
||||
{
|
||||
backBuffers = new VolatileImage[num];
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
backBuffers = new VolatileImage[numBuffers];
|
||||
|
||||
for (int i = 0; i < numBuffers; i++)
|
||||
backBuffers[i] = c.createCompatibleVolatileImage(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the capabilities of this buffer strategy.
|
||||
*
|
||||
* @return the capabilities of this buffer strategy
|
||||
*/
|
||||
public BufferCapabilities getCapabilities()
|
||||
{
|
||||
return caps;
|
||||
}
|
||||
public Graphics getDrawGraphics() { return null; }
|
||||
public void show() {}
|
||||
protected void revalidate() {}
|
||||
public boolean contentsLost() { return false; }
|
||||
public boolean contentsRestored() { return false; }
|
||||
} // class BltBufferStrategy
|
||||
|
||||
/**
|
||||
* Retrieves a graphics object that can be used to draw into this
|
||||
* strategy's image buffer.
|
||||
*
|
||||
* @return a graphics object
|
||||
*/
|
||||
public Graphics getDrawGraphics()
|
||||
{
|
||||
// Return the backmost buffer's graphics.
|
||||
return backBuffers[0].getGraphics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the contents of the back buffer to the front buffer.
|
||||
*/
|
||||
public void show()
|
||||
{
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
// draw the front buffer.
|
||||
getGraphics().drawImage(backBuffers[backBuffers.length - 1],
|
||||
width, height, null);
|
||||
|
||||
BufferCapabilities.FlipContents f = getCapabilities().getFlipContents();
|
||||
|
||||
// blit the back buffers.
|
||||
for (int i = backBuffers.length - 1; i > 0 ; i--)
|
||||
backBuffers[i] = backBuffers[i - 1];
|
||||
|
||||
// create new backmost buffer.
|
||||
if (f == BufferCapabilities.FlipContents.UNDEFINED)
|
||||
backBuffers[0] = c.createCompatibleVolatileImage(width, height);
|
||||
|
||||
// create new backmost buffer and clear it to the background
|
||||
// color.
|
||||
if (f == BufferCapabilities.FlipContents.BACKGROUND)
|
||||
{
|
||||
backBuffers[0] = c.createCompatibleVolatileImage(width, height);
|
||||
backBuffers[0].getGraphics().clearRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
// FIXME: set the backmost buffer to the prior contents of the
|
||||
// front buffer. How do we retrieve the contents of the front
|
||||
// buffer?
|
||||
//
|
||||
// if (f == BufferCapabilities.FlipContents.PRIOR)
|
||||
|
||||
// set the backmost buffer to a copy of the new front buffer.
|
||||
if (f == BufferCapabilities.FlipContents.COPIED)
|
||||
backBuffers[0] = backBuffers[backBuffers.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-create the image buffer resources if they've been lost.
|
||||
*/
|
||||
protected void revalidate()
|
||||
{
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
for (int i = 0; i < backBuffers.length; i++)
|
||||
{
|
||||
int result = backBuffers[i].validate(c);
|
||||
if (result == VolatileImage.IMAGE_INCOMPATIBLE)
|
||||
backBuffers[i] = c.createCompatibleVolatileImage(width, height);
|
||||
}
|
||||
validatedContents = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer resources have been
|
||||
* lost.
|
||||
*
|
||||
* @return true if the resources have been lost, false otherwise
|
||||
*/
|
||||
public boolean contentsLost()
|
||||
{
|
||||
for (int i = 0; i < backBuffers.length; i++)
|
||||
{
|
||||
if (backBuffers[i].contentsLost())
|
||||
{
|
||||
validatedContents = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// we know that the buffer resources are valid now because we
|
||||
// just checked them
|
||||
validatedContents = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer resources have been
|
||||
* restored.
|
||||
*
|
||||
* @return true if the resources have been restored, false
|
||||
* otherwise
|
||||
*/
|
||||
public boolean contentsRestored()
|
||||
{
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
boolean imageRestored = false;
|
||||
|
||||
for (int i = 0; i < backBuffers.length; i++)
|
||||
{
|
||||
int result = backBuffers[i].validate(c);
|
||||
if (result == VolatileImage.IMAGE_RESTORED)
|
||||
imageRestored = true;
|
||||
else if (result == VolatileImage.IMAGE_INCOMPATIBLE)
|
||||
return false;
|
||||
}
|
||||
// we know that the buffer resources are valid now because we
|
||||
// just checked them
|
||||
validatedContents = true;
|
||||
return imageRestored;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides support for flipping component buffers. It is only
|
||||
* designed for use by Canvas and Window.
|
||||
* This class provides support for flipping component buffers. It
|
||||
* can only be used on Canvases and Windows.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.4
|
||||
* @XXX Shell class, to allow compilation. This needs documentation and
|
||||
* correct implementation.
|
||||
*/
|
||||
protected class FlipBufferStrategy extends BufferStrategy
|
||||
{
|
||||
/**
|
||||
* The number of buffers.
|
||||
*/
|
||||
protected int numBuffers;
|
||||
|
||||
/**
|
||||
* The capabilities of this buffering strategy.
|
||||
*/
|
||||
protected BufferCapabilities caps;
|
||||
|
||||
/**
|
||||
* An Image reference to the drawing buffer.
|
||||
*/
|
||||
protected Image drawBuffer;
|
||||
|
||||
/**
|
||||
* A VolatileImage reference to the drawing buffer.
|
||||
*/
|
||||
protected VolatileImage drawVBuffer;
|
||||
|
||||
/**
|
||||
* Whether or not the image buffer resources are allocated and
|
||||
* ready to be drawn into.
|
||||
*/
|
||||
protected boolean validatedContents;
|
||||
protected FlipBufferStrategy(int num, BufferCapabilities caps)
|
||||
|
||||
/**
|
||||
* The width of the back buffer.
|
||||
*/
|
||||
private int width;
|
||||
|
||||
/**
|
||||
* The height of the back buffer.
|
||||
*/
|
||||
private int height;
|
||||
|
||||
/**
|
||||
* Creates a flipping buffer strategy. The only supported
|
||||
* strategy for FlipBufferStrategy itself is a double-buffer page
|
||||
* flipping strategy. It forms the basis for more complex derived
|
||||
* strategies.
|
||||
*
|
||||
* @param numBuffers the number of buffers
|
||||
* @param caps the capabilities of this buffering strategy
|
||||
*
|
||||
* @throws AWTException if the requested
|
||||
* number-of-buffers/capabilities combination is not supported
|
||||
*/
|
||||
protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps)
|
||||
throws AWTException
|
||||
{
|
||||
this.caps = caps;
|
||||
createBuffers(num, caps);
|
||||
width = getWidth();
|
||||
height = getHeight();
|
||||
|
||||
if (numBuffers > 1)
|
||||
createBuffers(numBuffers, caps);
|
||||
else
|
||||
{
|
||||
drawVBuffer = peer.createVolatileImage(width, height);
|
||||
drawBuffer = drawVBuffer;
|
||||
}
|
||||
}
|
||||
protected void createBuffers(int num, BufferCapabilities caps)
|
||||
throws AWTException {}
|
||||
|
||||
/**
|
||||
* Creates a multi-buffer flipping strategy. The number of
|
||||
* buffers must be greater than one and the buffer capabilities
|
||||
* must specify page flipping.
|
||||
*
|
||||
* @param numBuffers the number of flipping buffers; must be
|
||||
* greater than one
|
||||
* @param caps the buffering capabilities; caps.isPageFlipping()
|
||||
* must return true
|
||||
*
|
||||
* @throws IllegalArgumentException if numBuffers is not greater
|
||||
* than one or if the page flipping capability is not requested
|
||||
*
|
||||
* @throws AWTException if the requested flipping strategy is not
|
||||
* supported
|
||||
*/
|
||||
protected void createBuffers(int numBuffers, BufferCapabilities caps)
|
||||
throws AWTException
|
||||
{
|
||||
if (numBuffers <= 1)
|
||||
throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:"
|
||||
+ " numBuffers must be greater than"
|
||||
+ " one.");
|
||||
|
||||
if (!caps.isPageFlipping())
|
||||
throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:"
|
||||
+ " flipping must be a specified"
|
||||
+ " capability.");
|
||||
|
||||
peer.createBuffers(numBuffers, caps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a direct reference to the back buffer image.
|
||||
*
|
||||
* @return a direct reference to the back buffer image.
|
||||
*/
|
||||
protected Image getBackBuffer()
|
||||
{
|
||||
return drawBuffer;
|
||||
return peer.getBackBuffer();
|
||||
}
|
||||
protected void flip(BufferCapabilities.FlipContents flipAction) {}
|
||||
protected void destroyBuffers() {}
|
||||
|
||||
/**
|
||||
* Perform a flip operation to transfer the contents of the back
|
||||
* buffer to the front buffer.
|
||||
*/
|
||||
protected void flip(BufferCapabilities.FlipContents flipAction)
|
||||
{
|
||||
peer.flip(flipAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the back buffer's resources.
|
||||
*/
|
||||
protected void destroyBuffers()
|
||||
{
|
||||
peer.destroyBuffers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the capabilities of this buffer strategy.
|
||||
*
|
||||
* @return the capabilities of this buffer strategy
|
||||
*/
|
||||
public BufferCapabilities getCapabilities()
|
||||
{
|
||||
return caps;
|
||||
}
|
||||
public Graphics getDrawGraphics() { return null; }
|
||||
protected void revalidate() {}
|
||||
public boolean contentsLost() { return false; }
|
||||
public boolean contentsRestored() { return false; }
|
||||
public void show() {}
|
||||
} // class FlipBufferStrategy
|
||||
} // class Component
|
||||
|
||||
/**
|
||||
* Retrieves a graphics object that can be used to draw into this
|
||||
* strategy's image buffer.
|
||||
*
|
||||
* @return a graphics object
|
||||
*/
|
||||
public Graphics getDrawGraphics()
|
||||
{
|
||||
return drawVBuffer.getGraphics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-create the image buffer resources if they've been lost.
|
||||
*/
|
||||
protected void revalidate()
|
||||
{
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
if (drawVBuffer.validate(c) == VolatileImage.IMAGE_INCOMPATIBLE)
|
||||
drawVBuffer = peer.createVolatileImage(width, height);
|
||||
validatedContents = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer resources have been
|
||||
* lost.
|
||||
*
|
||||
* @return true if the resources have been lost, false otherwise
|
||||
*/
|
||||
public boolean contentsLost()
|
||||
{
|
||||
if (drawVBuffer.contentsLost())
|
||||
{
|
||||
validatedContents = false;
|
||||
return true;
|
||||
}
|
||||
// we know that the buffer resources are valid now because we
|
||||
// just checked them
|
||||
validatedContents = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer resources have been
|
||||
* restored.
|
||||
*
|
||||
* @return true if the resources have been restored, false
|
||||
* otherwise
|
||||
*/
|
||||
public boolean contentsRestored()
|
||||
{
|
||||
GraphicsConfiguration c =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
|
||||
int result = drawVBuffer.validate(c);
|
||||
|
||||
boolean imageRestored = false;
|
||||
|
||||
if (result == VolatileImage.IMAGE_RESTORED)
|
||||
imageRestored = true;
|
||||
else if (result == VolatileImage.IMAGE_INCOMPATIBLE)
|
||||
return false;
|
||||
|
||||
// we know that the buffer resources are valid now because we
|
||||
// just checked them
|
||||
validatedContents = true;
|
||||
return imageRestored;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring the contents of the back buffer to the front buffer.
|
||||
*/
|
||||
public void show()
|
||||
{
|
||||
flip(caps.getFlipContents());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue