< prev index next >

src/java.desktop/share/classes/java/awt/Component.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -350,11 +350,11 @@
      *
      * @since 1.4
      * @see java.awt.image.BufferStrategy
      * @see #getBufferStrategy()
      */
-    private transient BufferStrategy bufferStrategy = null;
+    transient BufferStrategy bufferStrategy = null;
 
     /**
      * True when the object should ignore all repaint events.
      *
      * @since 1.4

@@ -4036,16 +4036,16 @@
          */
 
          /**
           * The width of the back buffers
           */
-        private int width;
+        int width;
 
         /**
          * The height of the back buffers
          */
-        private int height;
+        int height;
 
         /**
          * Creates a new flipping buffer strategy for this component.
          * The component must be a {@code Canvas} or {@code Window} or
          * {@code Applet}.

@@ -4114,11 +4114,13 @@
             width = getWidth();
             height = getHeight();
 
             if (drawBuffer != null) {
                 // dispose the existing backbuffers
-                invalidate();
+                drawBuffer = null;
+                drawVBuffer = null;
+                destroyBuffers();
                 // ... then recreate the backbuffers
             }
 
             if (caps instanceof ExtendedBufferCapabilities) {
                 ExtendedBufferCapabilities ebc =

@@ -4202,19 +4204,10 @@
                     "Component must have a valid peer");
             }
         }
 
         /**
-         * Destroys the buffers and invalidates the state of FlipBufferStrategy.
-         */
-        private void invalidate() {
-            drawBuffer = null;
-            drawVBuffer = null;
-            destroyBuffers();
-        }
-
-        /**
          * Destroys the buffers created through this object
          */
         protected void destroyBuffers() {
             VSyncedBSManager.releaseVsync(this);
             if (peer != null) {

@@ -4249,15 +4242,18 @@
 
         /**
          * Restore the drawing buffer if it has been lost
          */
         protected void revalidate() {
+            revalidate(true);
+        }
+
+        void revalidate(boolean checkSize) {
             validatedContents = false;
-            if (getWidth() != width || getHeight() != height
-                    || drawBuffer == null) {
-                // component has been resized or the peer was recreated;
-                // recreate the backbuffers
+
+            if (checkSize && (getWidth() != width || getHeight() != height)) {
+                // component has been resized; recreate the backbuffers
                 try {
                     createBuffers(numBuffers, caps);
                 } catch (AWTException e) {
                     // shouldn't be possible
                 }

@@ -4331,11 +4327,11 @@
          */
         public void dispose() {
             if (Component.this.bufferStrategy == this) {
                 Component.this.bufferStrategy = null;
                 if (peer != null) {
-                    invalidate();
+                    destroyBuffers();
                 }
             }
         }
 
     } // Inner class FlipBufferStrategy

@@ -7158,11 +7154,11 @@
             ComponentPeer p = peer;
             if (p != null) {
                 boolean isLightweight = isLightweight();
 
                 if (bufferStrategy instanceof FlipBufferStrategy) {
-                    ((FlipBufferStrategy)bufferStrategy).invalidate();
+                    ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
                 }
 
                 if (dropTarget != null) dropTarget.removeNotify();
 
                 // Hide peer first to stop system events such as cursor moves.
< prev index next >