/[classpath]/classpath/java/awt/Component.java
ViewVC logotype

Diff of /classpath/java/awt/Component.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38.2.8 by gnu_andrew, Sun Mar 13 14:38:38 2005 UTC revision 1.38.2.9 by gnu_andrew, Fri May 20 18:20:54 2005 UTC
# Line 5575  p   * <li>the set of backward traversal Line 5575  p   * <li>the set of backward traversal
5575    } // class AccessibleAWTComponent    } // class AccessibleAWTComponent
5576    
5577    /**    /**
5578     * This class provides support for blitting offscreen surfaces.     * This class provides support for blitting offscreen surfaces to a
5579       * component.
5580       *
5581       * @see BufferStrategy
5582     *     *
    * @author Eric Blake (ebb9@email.byu.edu)  
5583     * @since 1.4     * @since 1.4
    * @XXX Shell class, to allow compilation. This needs documentation and  
    * correct implementation.  
5584     */     */
5585    protected class BltBufferStrategy extends BufferStrategy    protected class BltBufferStrategy extends BufferStrategy
5586    {    {
5587        /**
5588         * The capabilities of the image buffer.
5589         */
5590      protected BufferCapabilities caps;      protected BufferCapabilities caps;
5591    
5592        /**
5593         * The back buffers used in this strategy.
5594         */
5595      protected VolatileImage[] backBuffers;      protected VolatileImage[] backBuffers;
5596    
5597        /**
5598         * Whether or not the image buffer resources are allocated and
5599         * ready to be drawn into.
5600         */
5601      protected boolean validatedContents;      protected boolean validatedContents;
5602    
5603        /**
5604         * The width of the back buffers.
5605         */
5606      protected int width;      protected int width;
5607    
5608        /**
5609         * The height of the back buffers.
5610         */
5611      protected int height;      protected int height;
5612      protected BltBufferStrategy(int num, BufferCapabilities caps)  
5613        /**
5614         * The front buffer.
5615         */
5616        private VolatileImage frontBuffer;
5617    
5618        /**
5619         * Creates a blitting buffer strategy.
5620         *
5621         * @param numBuffers the number of buffers, including the front
5622         * buffer
5623         * @param caps the capabilities of this strategy
5624         */
5625        protected BltBufferStrategy(int numBuffers, BufferCapabilities caps)
5626      {      {
5627        this.caps = caps;        this.caps = caps;
5628        createBackBuffers(num);        createBackBuffers(numBuffers - 1);
5629          width = getWidth();
5630          height = getHeight();
5631      }      }
5632      protected void createBackBuffers(int num)  
5633        /**
5634         * Initializes the backBuffers field with an array of numBuffers
5635         * VolatileImages.
5636         *
5637         * @param numBuffers the number of backbuffers to create
5638         */
5639        protected void createBackBuffers(int numBuffers)
5640      {      {
5641        backBuffers = new VolatileImage[num];        GraphicsConfiguration c =
5642            GraphicsEnvironment.getLocalGraphicsEnvironment()
5643            .getDefaultScreenDevice().getDefaultConfiguration();
5644    
5645          backBuffers = new VolatileImage[numBuffers];
5646    
5647          for (int i = 0; i < numBuffers; i++)
5648            backBuffers[i] = c.createCompatibleVolatileImage(width, height);
5649      }      }
5650    
5651        /**
5652         * Retrieves the capabilities of this buffer strategy.
5653         *
5654         * @return the capabilities of this buffer strategy
5655         */
5656      public BufferCapabilities getCapabilities()      public BufferCapabilities getCapabilities()
5657      {      {
5658        return caps;        return caps;
5659      }      }
5660      public Graphics getDrawGraphics() { return null; }  
5661      public void show() {}      /**
5662      protected void revalidate() {}       * Retrieves a graphics object that can be used to draw into this
5663      public boolean contentsLost() { return false; }       * strategy's image buffer.
5664      public boolean contentsRestored() { return false; }       *
5665    } // class BltBufferStrategy       * @return a graphics object
5666         */
5667        public Graphics getDrawGraphics()
5668        {
5669          // Return the backmost buffer's graphics.
5670          return backBuffers[0].getGraphics();
5671        }
5672    
5673        /**
5674         * Bring the contents of the back buffer to the front buffer.
5675         */
5676        public void show()
5677        {
5678          GraphicsConfiguration c =
5679            GraphicsEnvironment.getLocalGraphicsEnvironment()
5680            .getDefaultScreenDevice().getDefaultConfiguration();
5681    
5682          // draw the front buffer.
5683          getGraphics().drawImage(backBuffers[backBuffers.length - 1],
5684                                  width, height, null);
5685    
5686          BufferCapabilities.FlipContents f = getCapabilities().getFlipContents();
5687    
5688          // blit the back buffers.
5689          for (int i = backBuffers.length - 1; i > 0 ; i--)
5690            backBuffers[i] = backBuffers[i - 1];
5691    
5692          // create new backmost buffer.
5693          if (f == BufferCapabilities.FlipContents.UNDEFINED)
5694            backBuffers[0] = c.createCompatibleVolatileImage(width, height);
5695    
5696          // create new backmost buffer and clear it to the background
5697          // color.
5698          if (f == BufferCapabilities.FlipContents.BACKGROUND)
5699            {
5700              backBuffers[0] = c.createCompatibleVolatileImage(width, height);
5701              backBuffers[0].getGraphics().clearRect(0, 0, width, height);
5702            }
5703    
5704          // FIXME: set the backmost buffer to the prior contents of the
5705          // front buffer.  How do we retrieve the contents of the front
5706          // buffer?
5707          //
5708          //      if (f == BufferCapabilities.FlipContents.PRIOR)
5709    
5710          // set the backmost buffer to a copy of the new front buffer.
5711          if (f == BufferCapabilities.FlipContents.COPIED)
5712            backBuffers[0] = backBuffers[backBuffers.length - 1];
5713        }
5714    
5715        /**
5716         * Re-create the image buffer resources if they've been lost.
5717         */
5718        protected void revalidate()
5719        {
5720          GraphicsConfiguration c =
5721            GraphicsEnvironment.getLocalGraphicsEnvironment()
5722            .getDefaultScreenDevice().getDefaultConfiguration();
5723    
5724          for (int i = 0; i < backBuffers.length; i++)
5725            {
5726              int result = backBuffers[i].validate(c);
5727              if (result == VolatileImage.IMAGE_INCOMPATIBLE)
5728                backBuffers[i] = c.createCompatibleVolatileImage(width, height);
5729            }
5730          validatedContents = true;
5731        }
5732    
5733        /**
5734         * Returns whether or not the image buffer resources have been
5735         * lost.
5736         *
5737         * @return true if the resources have been lost, false otherwise
5738         */
5739        public boolean contentsLost()
5740        {
5741          for (int i = 0; i < backBuffers.length; i++)
5742            {
5743              if (backBuffers[i].contentsLost())
5744                {
5745                  validatedContents = false;
5746                  return true;
5747                }
5748            }
5749          // we know that the buffer resources are valid now because we
5750          // just checked them
5751          validatedContents = true;
5752          return false;
5753        }
5754    
5755        /**
5756         * Returns whether or not the image buffer resources have been
5757         * restored.
5758         *
5759         * @return true if the resources have been restored, false
5760         * otherwise
5761         */
5762        public boolean contentsRestored()
5763        {
5764          GraphicsConfiguration c =
5765            GraphicsEnvironment.getLocalGraphicsEnvironment()
5766            .getDefaultScreenDevice().getDefaultConfiguration();
5767    
5768          boolean imageRestored = false;
5769    
5770          for (int i = 0; i < backBuffers.length; i++)
5771            {
5772              int result = backBuffers[i].validate(c);
5773              if (result == VolatileImage.IMAGE_RESTORED)
5774                imageRestored = true;
5775              else if (result == VolatileImage.IMAGE_INCOMPATIBLE)
5776                return false;
5777            }
5778          // we know that the buffer resources are valid now because we
5779          // just checked them
5780          validatedContents = true;
5781          return imageRestored;
5782        }
5783      }
5784    
5785    /**    /**
5786     * This class provides support for flipping component buffers. It is only     * This class provides support for flipping component buffers. It
5787     * designed for use by Canvas and Window.     * can only be used on Canvases and Windows.
5788     *     *
    * @author Eric Blake (ebb9@email.byu.edu)  
5789     * @since 1.4     * @since 1.4
    * @XXX Shell class, to allow compilation. This needs documentation and  
    * correct implementation.  
5790     */     */
5791    protected class FlipBufferStrategy extends BufferStrategy    protected class FlipBufferStrategy extends BufferStrategy
5792    {    {
5793        /**
5794         * The number of buffers.
5795         */
5796      protected int numBuffers;      protected int numBuffers;
5797    
5798        /**
5799         * The capabilities of this buffering strategy.
5800         */
5801      protected BufferCapabilities caps;      protected BufferCapabilities caps;
5802    
5803        /**
5804         * An Image reference to the drawing buffer.
5805         */
5806      protected Image drawBuffer;      protected Image drawBuffer;
5807    
5808        /**
5809         * A VolatileImage reference to the drawing buffer.
5810         */
5811      protected VolatileImage drawVBuffer;      protected VolatileImage drawVBuffer;
5812    
5813        /**
5814         * Whether or not the image buffer resources are allocated and
5815         * ready to be drawn into.
5816         */
5817      protected boolean validatedContents;      protected boolean validatedContents;
5818      protected FlipBufferStrategy(int num, BufferCapabilities caps)  
5819        /**
5820         * The width of the back buffer.
5821         */
5822        private int width;
5823    
5824        /**
5825         * The height of the back buffer.
5826         */
5827        private int height;
5828    
5829        /**
5830         * Creates a flipping buffer strategy.  The only supported
5831         * strategy for FlipBufferStrategy itself is a double-buffer page
5832         * flipping strategy.  It forms the basis for more complex derived
5833         * strategies.
5834         *
5835         * @param numBuffers the number of buffers
5836         * @param caps the capabilities of this buffering strategy
5837         *
5838         * @throws AWTException if the requested
5839         * number-of-buffers/capabilities combination is not supported
5840         */
5841        protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps)
5842        throws AWTException        throws AWTException
5843      {      {
5844        this.caps = caps;        this.caps = caps;
5845        createBuffers(num, caps);        width = getWidth();
5846          height = getHeight();
5847    
5848          if (numBuffers > 1)
5849            createBuffers(numBuffers, caps);
5850          else
5851            {
5852              drawVBuffer = peer.createVolatileImage(width, height);
5853              drawBuffer = drawVBuffer;
5854            }
5855        }
5856    
5857        /**
5858         * Creates a multi-buffer flipping strategy.  The number of
5859         * buffers must be greater than one and the buffer capabilities
5860         * must specify page flipping.
5861         *
5862         * @param numBuffers the number of flipping buffers; must be
5863         * greater than one
5864         * @param caps the buffering capabilities; caps.isPageFlipping()
5865         * must return true
5866         *
5867         * @throws IllegalArgumentException if numBuffers is not greater
5868         * than one or if the page flipping capability is not requested
5869         *
5870         * @throws AWTException if the requested flipping strategy is not
5871         * supported
5872         */
5873        protected void createBuffers(int numBuffers, BufferCapabilities caps)
5874          throws AWTException
5875        {
5876          if (numBuffers <= 1)
5877            throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:"
5878                                               + " numBuffers must be greater than"
5879                                               + " one.");
5880    
5881          if (!caps.isPageFlipping())
5882            throw new IllegalArgumentException("FlipBufferStrategy.createBuffers:"
5883                                               + " flipping must be a specified"
5884                                               + " capability.");
5885    
5886          peer.createBuffers(numBuffers, caps);
5887      }      }
5888      protected void createBuffers(int num, BufferCapabilities caps)  
5889        throws AWTException {}      /**
5890         * Return a direct reference to the back buffer image.
5891         *
5892         * @return a direct reference to the back buffer image.
5893         */
5894      protected Image getBackBuffer()      protected Image getBackBuffer()
5895      {      {
5896        return drawBuffer;        return peer.getBackBuffer();
5897        }
5898    
5899        /**
5900         * Perform a flip operation to transfer the contents of the back
5901         * buffer to the front buffer.
5902         */
5903        protected void flip(BufferCapabilities.FlipContents flipAction)
5904        {
5905          peer.flip(flipAction);
5906      }      }
5907      protected void flip(BufferCapabilities.FlipContents flipAction) {}  
5908      protected void destroyBuffers() {}      /**
5909         * Release the back buffer's resources.
5910         */
5911        protected void destroyBuffers()
5912        {
5913          peer.destroyBuffers();
5914        }
5915    
5916        /**
5917         * Retrieves the capabilities of this buffer strategy.
5918         *
5919         * @return the capabilities of this buffer strategy
5920         */
5921      public BufferCapabilities getCapabilities()      public BufferCapabilities getCapabilities()
5922      {      {
5923        return caps;        return caps;
5924      }      }
5925      public Graphics getDrawGraphics() { return null; }  
5926      protected void revalidate() {}      /**
5927      public boolean contentsLost() { return false; }       * Retrieves a graphics object that can be used to draw into this
5928      public boolean contentsRestored() { return false; }       * strategy's image buffer.
5929      public void show() {}       *
5930    } // class FlipBufferStrategy       * @return a graphics object
5931  } // class Component       */
5932        public Graphics getDrawGraphics()
5933        {
5934          return drawVBuffer.getGraphics();
5935        }
5936    
5937        /**
5938         * Re-create the image buffer resources if they've been lost.
5939         */
5940        protected void revalidate()
5941        {
5942          GraphicsConfiguration c =
5943            GraphicsEnvironment.getLocalGraphicsEnvironment()
5944            .getDefaultScreenDevice().getDefaultConfiguration();
5945    
5946          if (drawVBuffer.validate(c) == VolatileImage.IMAGE_INCOMPATIBLE)
5947            drawVBuffer = peer.createVolatileImage(width, height);
5948          validatedContents = true;
5949        }
5950    
5951        /**
5952         * Returns whether or not the image buffer resources have been
5953         * lost.
5954         *
5955         * @return true if the resources have been lost, false otherwise
5956         */
5957        public boolean contentsLost()
5958        {
5959          if (drawVBuffer.contentsLost())
5960            {
5961              validatedContents = false;
5962              return true;
5963            }
5964          // we know that the buffer resources are valid now because we
5965          // just checked them
5966          validatedContents = true;
5967          return false;
5968        }
5969    
5970        /**
5971         * Returns whether or not the image buffer resources have been
5972         * restored.
5973         *
5974         * @return true if the resources have been restored, false
5975         * otherwise
5976         */
5977        public boolean contentsRestored()
5978        {
5979          GraphicsConfiguration c =
5980            GraphicsEnvironment.getLocalGraphicsEnvironment()
5981            .getDefaultScreenDevice().getDefaultConfiguration();
5982    
5983          int result = drawVBuffer.validate(c);
5984    
5985          boolean imageRestored = false;
5986    
5987          if (result == VolatileImage.IMAGE_RESTORED)
5988            imageRestored = true;
5989          else if (result == VolatileImage.IMAGE_INCOMPATIBLE)
5990            return false;
5991    
5992          // we know that the buffer resources are valid now because we
5993          // just checked them
5994          validatedContents = true;
5995          return imageRestored;
5996        }
5997    
5998        /**
5999         * Bring the contents of the back buffer to the front buffer.
6000         */
6001        public void show()
6002        {
6003          flip(caps.getFlipContents());
6004        }
6005      }
6006    }

Legend:
Removed from v.1.38.2.8  
changed lines
  Added in v.1.38.2.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26