changeset 7936:b4976c12c98b 8u40-b04

RT-38511: [Canvas] Several tests get IllegalStateException: Operation requires resource lock Backed out changeset 1777099fe570 for RT-38183
author kcr
date Tue, 02 Sep 2014 09:12:10 -0700
parents b0a0f059cc4e
children 316a7b5f5829 1c2b1f7b7424 043cd5a12fd9
files modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGNode.java modules/graphics/src/main/java/com/sun/scenario/effect/impl/ImagePool.java modules/graphics/src/main/java/com/sun/scenario/effect/impl/PoolFilterable.java modules/graphics/src/main/java/com/sun/scenario/effect/impl/Renderer.java modules/graphics/src/main/java/com/sun/scenario/effect/impl/prism/PrDrawable.java
diffstat 5 files changed, 33 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGNode.java	Mon Sep 01 19:32:54 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGNode.java	Tue Sep 02 09:12:10 2014 -0700
@@ -2432,10 +2432,7 @@
                                 Object renderHelper,
                                 Effect defaultInput)
         {
-            img.lock();
-            ImageData id = new ImageData(fctx, img, new Rectangle(bounds));
-            id.setReusable(true);
-            return id;
+            return new ImageData(fctx, img, new Rectangle(bounds));
         }
 
         @Override
--- a/modules/graphics/src/main/java/com/sun/scenario/effect/impl/ImagePool.java	Mon Sep 01 19:32:54 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/scenario/effect/impl/ImagePool.java	Tue Sep 02 09:12:10 2014 -0700
@@ -76,10 +76,10 @@
 
     static final int QUANT = 32;
 
-    private final List<SoftReference<PoolFilterable>> unlocked =
-        new ArrayList<SoftReference<PoolFilterable>>();
-    private final List<SoftReference<PoolFilterable>> locked =
-        new ArrayList<SoftReference<PoolFilterable>>();
+    private final List<SoftReference<Filterable>> unlocked =
+        new ArrayList<SoftReference<Filterable>>();
+    private final List<SoftReference<Filterable>> locked =
+        new ArrayList<SoftReference<Filterable>>();
 
     // On Canmore with the PowerVR SGX chip, there is a driver issue
     // that causes incorrect rendering if one tries to reuse an FBO
@@ -97,8 +97,8 @@
     // (where there would normally be reuse).
     private final boolean usePurgatory = Boolean.getBoolean("decora.purgatory");
     private final List<Filterable> hardPurgatory = new ArrayList<Filterable>();
-    private final List<SoftReference<PoolFilterable>> softPurgatory =
-        new ArrayList<SoftReference<PoolFilterable>>();
+    private final List<SoftReference<Filterable>> softPurgatory =
+        new ArrayList<SoftReference<Filterable>>();
 
     /**
      * Package-private constructor.
@@ -106,7 +106,7 @@
     ImagePool() {
     }
 
-    public synchronized PoolFilterable checkOut(Renderer renderer, int w, int h) {
+    public synchronized Filterable checkOut(Renderer renderer, int w, int h) {
         if (w <= 0 || h <= 0) {
             // if image is empty in any way, return a small non-empty image.
             w = h = 1;
@@ -123,13 +123,13 @@
         pixelsAccessed += ((long) w) * h;
         // first look for an already cached image of sufficient size,
         // choosing the one that is closest in size to the requested dimensions
-        SoftReference<PoolFilterable> chosenEntry = null;
-        PoolFilterable chosenImage = null;
+        SoftReference<Filterable> chosenEntry = null;
+        Filterable chosenImage = null;
         int mindiff = Integer.MAX_VALUE;
-        Iterator<SoftReference<PoolFilterable>> entries = unlocked.iterator();
+        Iterator<SoftReference<Filterable>> entries = unlocked.iterator();
         while (entries.hasNext()) {
-            SoftReference<PoolFilterable> entry = entries.next();
-            PoolFilterable eimg = entry.get();
+            SoftReference<Filterable> entry = entries.next();
+            Filterable eimg = entry.get();
             if (eimg == null) {
                 entries.remove();
                 continue;
@@ -170,7 +170,7 @@
         // get rid of expired entries from locked list
         entries = locked.iterator();
         while (entries.hasNext()) {
-            SoftReference<PoolFilterable> entry = entries.next();
+            SoftReference<Filterable> entry = entries.next();
             Filterable eimg = entry.get();
             if (eimg == null) {
                 entries.remove();
@@ -178,7 +178,7 @@
         }
 
         // if all else fails, just create a new one...
-        PoolFilterable img = null;
+        Filterable img = null;
         try {
             img = renderer.createCompatibleImage(w, h);
         } catch (OutOfMemoryError e) {}
@@ -191,20 +191,19 @@
             } catch (OutOfMemoryError e) {}
         }
         if (img != null) {
-            img.setImagePool(this);
-            locked.add(new SoftReference<PoolFilterable>(img));
+            locked.add(new SoftReference<Filterable>(img));
             numCreated++;
             pixelsCreated += ((long) w) * h;
         }
         return img;
     }
 
-    public synchronized void checkIn(PoolFilterable img) {
-        SoftReference<PoolFilterable> chosenEntry = null;
+    public synchronized void checkIn(Filterable img) {
+        SoftReference<Filterable> chosenEntry = null;
         Filterable chosenImage = null;
-        Iterator<SoftReference<PoolFilterable>> entries = locked.iterator();
+        Iterator<SoftReference<Filterable>> entries = locked.iterator();
         while (entries.hasNext()) {
-            SoftReference<PoolFilterable> entry = entries.next();
+            SoftReference<Filterable> entry = entries.next();
             Filterable eimg = entry.get();
             if (eimg == null) {
                 entries.remove();
@@ -245,7 +244,7 @@
 
     private void pruneCache() {
         // flush all unlocked images
-        for (SoftReference<PoolFilterable> r : unlocked) {
+        for (SoftReference<Filterable> r : unlocked) {
             Filterable image = r.get();
             if (image != null) {
                 image.flush();
@@ -261,7 +260,7 @@
     }
 
     public synchronized void dispose() {
-        for (SoftReference<PoolFilterable> r : unlocked) {
+        for (SoftReference<Filterable> r : unlocked) {
             Filterable image = r.get();
             if (image != null) {
                 image.flush();
--- a/modules/graphics/src/main/java/com/sun/scenario/effect/impl/PoolFilterable.java	Mon Sep 01 19:32:54 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.scenario.effect.impl;
-
-import com.sun.scenario.effect.Filterable;
-
-public interface PoolFilterable extends Filterable {
-    public void setImagePool(ImagePool pool);
-    public ImagePool getImagePool();
-}
--- a/modules/graphics/src/main/java/com/sun/scenario/effect/impl/Renderer.java	Mon Sep 01 19:32:54 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/scenario/effect/impl/Renderer.java	Tue Sep 02 09:12:10 2014 -0700
@@ -110,23 +110,14 @@
 
     public abstract int getCompatibleWidth(int w);
     public abstract int getCompatibleHeight(int h);
-    public abstract PoolFilterable createCompatibleImage(int w, int h);
+    public abstract Filterable createCompatibleImage(int w, int h);
 
-    public PoolFilterable getCompatibleImage(int w, int h) {
+    public Filterable getCompatibleImage(int w, int h) {
         return imagePool.checkOut(this, w, h);
     }
 
     public void releaseCompatibleImage(Filterable image) {
-        if (image instanceof PoolFilterable) {
-            ImagePool pool = ((PoolFilterable) image).getImagePool();
-            if (pool != null) {
-                pool.checkIn((PoolFilterable) image);
-                return;
-            }
-//        } else {
-            // Error?
-        }
-        image.unlock();
+        imagePool.checkIn(image);
     }
 
     /**
--- a/modules/graphics/src/main/java/com/sun/scenario/effect/impl/prism/PrDrawable.java	Mon Sep 01 19:32:54 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/scenario/effect/impl/prism/PrDrawable.java	Tue Sep 02 09:12:10 2014 -0700
@@ -28,14 +28,11 @@
 import com.sun.prism.Graphics;
 import com.sun.prism.RTTexture;
 import com.sun.scenario.effect.FilterContext;
-import com.sun.scenario.effect.impl.ImagePool;
-import com.sun.scenario.effect.impl.PoolFilterable;
+import com.sun.scenario.effect.Filterable;
 import com.sun.scenario.effect.impl.Renderer;
-import java.lang.ref.WeakReference;
 
-public abstract class PrDrawable extends PrTexture<RTTexture> implements PoolFilterable {
-    private WeakReference<ImagePool> pool;
-
+public abstract class PrDrawable extends PrTexture<RTTexture> implements Filterable {
+    
     public static PrDrawable create(FilterContext fctx, RTTexture rtt) {
         return ((PrRenderer) Renderer.getRenderer(fctx)).createDrawable(rtt);
     }
@@ -44,34 +41,24 @@
         super(rtt);
     }
 
-    @Override
-    public void setImagePool(ImagePool pool) {
-        this.pool = new WeakReference<>(pool);
-    }
-
-    @Override
-    public ImagePool getImagePool() {
-        return pool == null ? null : pool.get();
-    }
-
-    @Override public float getPixelScale() {
+    public float getPixelScale() {
         return 1.0f;
     }
 
     @Override public int getMaxContentWidth() {
-        return getTextureObject().getMaxContentWidth();
+        return ((RTTexture)getTextureObject()).getMaxContentWidth();
     }
     
     @Override public int getMaxContentHeight() {
-        return getTextureObject().getMaxContentHeight();
+        return ((RTTexture)getTextureObject()).getMaxContentHeight();
     }
     
     @Override public void setContentWidth(int contentW) {
-        getTextureObject().setContentWidth(contentW);
+        ((RTTexture)getTextureObject()).setContentWidth(contentW);
     }
 
     @Override public void setContentHeight(int contentH) {
-        getTextureObject().setContentHeight(contentH);
+        ((RTTexture)getTextureObject()).setContentHeight(contentH);
     }
  
     public abstract Graphics createGraphics();