src/java.desktop/share/classes/java/awt/Component.java
changeset 55172 1a80806e7d15
parent 54397 65030bbf5ac1
child 58309 c6f8b2c3dc66
--- a/src/java.desktop/share/classes/java/awt/Component.java	Fri May 17 22:48:03 2019 -0700
+++ b/src/java.desktop/share/classes/java/awt/Component.java	Sat May 18 23:35:40 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2019, 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
@@ -352,7 +352,7 @@
      * @see java.awt.image.BufferStrategy
      * @see #getBufferStrategy()
      */
-    transient BufferStrategy bufferStrategy = null;
+    private transient BufferStrategy bufferStrategy = null;
 
     /**
      * True when the object should ignore all repaint events.
@@ -4038,12 +4038,12 @@
          /**
           * The width of the back buffers
           */
-        int width;
+        private int width;
 
         /**
          * The height of the back buffers
          */
-        int height;
+        private int height;
 
         /**
          * Creates a new flipping buffer strategy for this component.
@@ -4116,9 +4116,7 @@
 
             if (drawBuffer != null) {
                 // dispose the existing backbuffers
-                drawBuffer = null;
-                drawVBuffer = null;
-                destroyBuffers();
+                invalidate();
                 // ... then recreate the backbuffers
             }
 
@@ -4206,6 +4204,15 @@
         }
 
         /**
+         * 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() {
@@ -4244,14 +4251,11 @@
          * Restore the drawing buffer if it has been lost
          */
         protected void revalidate() {
-            revalidate(true);
-        }
-
-        void revalidate(boolean checkSize) {
             validatedContents = false;
-
-            if (checkSize && (getWidth() != width || getHeight() != height)) {
-                // component has been resized; recreate the backbuffers
+            if (getWidth() != width || getHeight() != height
+                    || drawBuffer == null) {
+                // component has been resized or the peer was recreated;
+                // recreate the backbuffers
                 try {
                     createBuffers(numBuffers, caps);
                 } catch (AWTException e) {
@@ -4329,7 +4333,7 @@
             if (Component.this.bufferStrategy == this) {
                 Component.this.bufferStrategy = null;
                 if (peer != null) {
-                    destroyBuffers();
+                    invalidate();
                 }
             }
         }
@@ -7156,7 +7160,7 @@
                 boolean isLightweight = isLightweight();
 
                 if (bufferStrategy instanceof FlipBufferStrategy) {
-                    ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
+                    ((FlipBufferStrategy)bufferStrategy).invalidate();
                 }
 
                 if (dropTarget != null) dropTarget.removeNotify();