src/java.desktop/share/classes/java/awt/Component.java
changeset 55172 1a80806e7d15
parent 54397 65030bbf5ac1
child 58309 c6f8b2c3dc66
equal deleted inserted replaced
55171:9ee0b8733ee4 55172:1a80806e7d15
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   350      *
   350      *
   351      * @since 1.4
   351      * @since 1.4
   352      * @see java.awt.image.BufferStrategy
   352      * @see java.awt.image.BufferStrategy
   353      * @see #getBufferStrategy()
   353      * @see #getBufferStrategy()
   354      */
   354      */
   355     transient BufferStrategy bufferStrategy = null;
   355     private transient BufferStrategy bufferStrategy = null;
   356 
   356 
   357     /**
   357     /**
   358      * True when the object should ignore all repaint events.
   358      * True when the object should ignore all repaint events.
   359      *
   359      *
   360      * @since 1.4
   360      * @since 1.4
  4036          */
  4036          */
  4037 
  4037 
  4038          /**
  4038          /**
  4039           * The width of the back buffers
  4039           * The width of the back buffers
  4040           */
  4040           */
  4041         int width;
  4041         private int width;
  4042 
  4042 
  4043         /**
  4043         /**
  4044          * The height of the back buffers
  4044          * The height of the back buffers
  4045          */
  4045          */
  4046         int height;
  4046         private int height;
  4047 
  4047 
  4048         /**
  4048         /**
  4049          * Creates a new flipping buffer strategy for this component.
  4049          * Creates a new flipping buffer strategy for this component.
  4050          * The component must be a {@code Canvas} or {@code Window} or
  4050          * The component must be a {@code Canvas} or {@code Window} or
  4051          * {@code Applet}.
  4051          * {@code Applet}.
  4114             width = getWidth();
  4114             width = getWidth();
  4115             height = getHeight();
  4115             height = getHeight();
  4116 
  4116 
  4117             if (drawBuffer != null) {
  4117             if (drawBuffer != null) {
  4118                 // dispose the existing backbuffers
  4118                 // dispose the existing backbuffers
  4119                 drawBuffer = null;
  4119                 invalidate();
  4120                 drawVBuffer = null;
       
  4121                 destroyBuffers();
       
  4122                 // ... then recreate the backbuffers
  4120                 // ... then recreate the backbuffers
  4123             }
  4121             }
  4124 
  4122 
  4125             if (caps instanceof ExtendedBufferCapabilities) {
  4123             if (caps instanceof ExtendedBufferCapabilities) {
  4126                 ExtendedBufferCapabilities ebc =
  4124                 ExtendedBufferCapabilities ebc =
  4204                     "Component must have a valid peer");
  4202                     "Component must have a valid peer");
  4205             }
  4203             }
  4206         }
  4204         }
  4207 
  4205 
  4208         /**
  4206         /**
       
  4207          * Destroys the buffers and invalidates the state of FlipBufferStrategy.
       
  4208          */
       
  4209         private void invalidate() {
       
  4210             drawBuffer = null;
       
  4211             drawVBuffer = null;
       
  4212             destroyBuffers();
       
  4213         }
       
  4214 
       
  4215         /**
  4209          * Destroys the buffers created through this object
  4216          * Destroys the buffers created through this object
  4210          */
  4217          */
  4211         protected void destroyBuffers() {
  4218         protected void destroyBuffers() {
  4212             VSyncedBSManager.releaseVsync(this);
  4219             VSyncedBSManager.releaseVsync(this);
  4213             if (peer != null) {
  4220             if (peer != null) {
  4242 
  4249 
  4243         /**
  4250         /**
  4244          * Restore the drawing buffer if it has been lost
  4251          * Restore the drawing buffer if it has been lost
  4245          */
  4252          */
  4246         protected void revalidate() {
  4253         protected void revalidate() {
  4247             revalidate(true);
       
  4248         }
       
  4249 
       
  4250         void revalidate(boolean checkSize) {
       
  4251             validatedContents = false;
  4254             validatedContents = false;
  4252 
  4255             if (getWidth() != width || getHeight() != height
  4253             if (checkSize && (getWidth() != width || getHeight() != height)) {
  4256                     || drawBuffer == null) {
  4254                 // component has been resized; recreate the backbuffers
  4257                 // component has been resized or the peer was recreated;
       
  4258                 // recreate the backbuffers
  4255                 try {
  4259                 try {
  4256                     createBuffers(numBuffers, caps);
  4260                     createBuffers(numBuffers, caps);
  4257                 } catch (AWTException e) {
  4261                 } catch (AWTException e) {
  4258                     // shouldn't be possible
  4262                     // shouldn't be possible
  4259                 }
  4263                 }
  4327          */
  4331          */
  4328         public void dispose() {
  4332         public void dispose() {
  4329             if (Component.this.bufferStrategy == this) {
  4333             if (Component.this.bufferStrategy == this) {
  4330                 Component.this.bufferStrategy = null;
  4334                 Component.this.bufferStrategy = null;
  4331                 if (peer != null) {
  4335                 if (peer != null) {
  4332                     destroyBuffers();
  4336                     invalidate();
  4333                 }
  4337                 }
  4334             }
  4338             }
  4335         }
  4339         }
  4336 
  4340 
  4337     } // Inner class FlipBufferStrategy
  4341     } // Inner class FlipBufferStrategy
  7154             ComponentPeer p = peer;
  7158             ComponentPeer p = peer;
  7155             if (p != null) {
  7159             if (p != null) {
  7156                 boolean isLightweight = isLightweight();
  7160                 boolean isLightweight = isLightweight();
  7157 
  7161 
  7158                 if (bufferStrategy instanceof FlipBufferStrategy) {
  7162                 if (bufferStrategy instanceof FlipBufferStrategy) {
  7159                     ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
  7163                     ((FlipBufferStrategy)bufferStrategy).invalidate();
  7160                 }
  7164                 }
  7161 
  7165 
  7162                 if (dropTarget != null) dropTarget.removeNotify();
  7166                 if (dropTarget != null) dropTarget.removeNotify();
  7163 
  7167 
  7164                 // Hide peer first to stop system events such as cursor moves.
  7168                 // Hide peer first to stop system events such as cursor moves.