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

Diff of /classpath/java/awt/Canvas.java

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

revision 1.12 by mkoch, Wed Feb 16 10:39:25 2005 UTC revision 1.13 by fitzsim, Wed May 18 15:03:53 2005 UTC
# Line 179  public class Canvas Line 179  public class Canvas
179    }    }
180    
181    /**    /**
182       * A BltBufferStrategy for canvases.
183       */
184      private class CanvasBltBufferStrategy extends BltBufferStrategy
185      {
186        /**
187         * Creates a block transfer strategy for this canvas.
188         *
189         * @param numBuffers the number of buffers in this strategy
190         * @param accelerated true if the buffer should be accelerated,
191         * false otherwise
192         */
193        CanvasBltBufferStrategy(int numBuffers, boolean accelerated)
194        {
195          super(numBuffers,
196                new BufferCapabilities(new ImageCapabilities(accelerated),
197                                       new ImageCapabilities(accelerated),
198                                       BufferCapabilities.FlipContents.COPIED));
199        }
200      }
201    
202      /**
203       * A FlipBufferStrategy for canvases.
204       */
205      private class CanvasFlipBufferStrategy extends FlipBufferStrategy
206      {
207        /**
208         * Creates a flip buffer strategy for this canvas.
209         *
210         * @param numBuffers the number of buffers in this strategy
211         *
212         * @throws AWTException if the requested number of buffers is not
213         * supported
214         */
215        CanvasFlipBufferStrategy(int numBuffers)
216          throws AWTException
217        {
218          super(numBuffers,
219                new BufferCapabilities(new ImageCapabilities(true),
220                                       new ImageCapabilities(true),
221                                       BufferCapabilities.FlipContents.COPIED));
222        }
223      }
224    
225      /**
226       * Creates a buffering strategy that manages how this canvas is
227       * repainted.  This method attempts to create the optimum strategy
228       * based on the desired number of buffers.  Hardware or software
229       * acceleration may be used.
230       *
231       * createBufferStrategy attempts different levels of optimization,
232       * but guarantees that some strategy with the requested number of
233       * buffers will be created even if it is not optimal.  First it
234       * attempts to create a page flipping strategy, then an accelerated
235       * blitting strategy, then an unaccelerated blitting strategy.
236       *
237       * Calling this method causes any existing buffer strategy to be
238       * destroyed.
239       *
240       * @param numBuffers the number of buffers in this strategy
241       *
242       * @throws IllegalArgumentException if requested number of buffers
243       * is less than one
244       * @throws IllegalStateException if this canvas is not displayable
245       *
246       * @since 1.4
247       */
248      public void createBufferStrategy(int numBuffers)
249      {
250        if (numBuffers < 1)
251          throw new IllegalArgumentException("Canvas.createBufferStrategy: number"
252                                             + " of buffers is less than one");
253    
254        if (!isDisplayable())
255          throw new IllegalStateException("Canvas.createBufferStrategy: canvas is"
256                                          + " not displayable");
257    
258        // try a flipping strategy
259        try
260          {
261            bufferStrategy = new CanvasFlipBufferStrategy(numBuffers);
262            return;
263          }
264        catch (AWTException e)
265          {
266          }
267    
268        // try an accelerated blitting strategy
269        try
270          {
271            bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true);
272          }
273        catch (AWTException e)
274          {
275          }
276    
277        // fall back to an unaccelerated blitting strategy
278        try
279          {
280            bufferStrategy = new CanvasBltBufferStrategy(numBuffers, false);
281          }
282        catch (AWTException e)
283          {
284          }
285      }
286    
287      /**
288       * Creates a buffering strategy that manages how this canvas is
289       * repainted.  This method attempts to create a strategy based on
290       * the specified capabilities and throws an exception if the
291       * requested strategy is not supported.
292       *
293       * Calling this method causes any existing buffer strategy to be
294       * destroyed.
295       *
296       * @param numBuffers the number of buffers in this strategy
297       * @param caps the requested buffering capabilities
298       *
299       * @throws AWTException if the requested capabilities are not
300       * supported
301       * @throws IllegalArgumentException if requested number of buffers
302       * is less than one or if caps is null
303       *
304       * @since 1.4
305       */
306      public void createBufferStrategy(int numBuffers,
307                                       BufferCapabilities caps)
308      {
309        if (numBuffers < 1)
310          throw new IllegalArgumentException("Canvas.createBufferStrategy: number"
311                                             + " of buffers is less than one");
312    
313        if (caps == null)
314          throw new IllegalArgumentException("Canvas.createBufferStrategy:"
315                                             + " capabilities object is null");
316    
317        // a flipping strategy was requested
318        if (caps.isPageFlipping())
319          {
320            try
321              {
322                bufferStrategy = new CanvasFlipBufferStrategy(numBuffers);
323              }
324            catch (AWTException e)
325              {
326              }
327          }
328        else
329          bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true);
330      }
331    
332      /**
333     * Returns the buffer strategy used by the canvas.     * Returns the buffer strategy used by the canvas.
334     *     *
335     * @return the buffer strategy.     * @return the buffer strategy.
# Line 211  public class Canvas Line 362  public class Canvas
362      /* Call the paint method */      /* Call the paint method */
363      paint(graphics);      paint(graphics);
364    }    }
   
365  }  }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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