< prev index next >

modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCRenderQueue.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.webkit.graphics;
  27 
  28 import java.lang.annotation.Native;


  29 import com.sun.webkit.Invoker;
  30 import java.nio.ByteBuffer;
  31 import java.util.HashMap;
  32 import java.util.LinkedList;
  33 import java.util.concurrent.atomic.AtomicInteger;
  34 import java.util.logging.Level;
  35 import java.util.logging.Logger;
  36 
  37 public abstract class WCRenderQueue extends Ref {
  38     private final static AtomicInteger idCountObj = new AtomicInteger(0);
  39     private final static Logger log =
  40         Logger.getLogger(WCRenderQueue.class.getName());
  41     @Native public final static int MAX_QUEUE_SIZE = 0x80000;
  42 
  43     private final LinkedList<BufferData> buffers = new LinkedList<BufferData>();
  44     private BufferData currentBuffer = new BufferData();
  45     private final WCRectangle clip;
  46     private int size = 0;
  47     private final boolean opaque;
  48 
  49     // Associated graphics context (currently used to draw to a buffered image).
  50     protected final WCGraphicsContext gc;
  51 
  52     protected WCRenderQueue(WCGraphicsContext gc) {
  53         this.clip = null;
  54         this.opaque = false;
  55         this.gc = gc;
  56     }
  57 
  58     protected WCRenderQueue(WCRectangle clip, boolean opaque) {
  59         this.clip = clip;
  60         this.opaque = opaque;
  61         this.gc = null;
  62     }
  63 
  64     public synchronized int getSize() {
  65         return size;
  66     }
  67 
  68     public synchronized void addBuffer(ByteBuffer buffer) {
  69         if (log.isLoggable(Level.FINE) && buffers.isEmpty()) {
  70             log.log(Level.FINE, "'{'WCRenderQueue{0}[{1}]",
  71                     new Object[]{hashCode(), idCountObj.incrementAndGet()});
  72         }
  73         currentBuffer.setBuffer(buffer);
  74         buffers.addLast(currentBuffer);
  75         currentBuffer = new BufferData();
  76         size += buffer.capacity();
  77         if (size > MAX_QUEUE_SIZE && gc!=null) {
  78             // It is isolated queue over the canvas image [image-gc!=null].
  79             // We need to flush the changes periodically
  80             // by the same reason as in [WebPage.addLastRQ].
  81             flush();
  82         }
  83     }
  84 
  85     public synchronized boolean isEmpty() {
  86         return buffers.isEmpty();
  87     }
  88 
  89     public synchronized void decode(WCGraphicsContext gc) {
  90         for (BufferData bdata : buffers) {


 121     }
 122 
 123     public WCRectangle getClip() {
 124         return clip;
 125     }
 126 
 127     public synchronized void dispose() {
 128         int n = buffers.size();
 129         if (n > 0) {
 130             int i = 0;
 131             final Object[] arr = new Object[n];
 132             for (BufferData bdata: buffers) {
 133                 arr[i++] = bdata.getBuffer();
 134             }
 135             buffers.clear();
 136             Invoker.getInvoker().invokeOnEventThread(() -> {
 137                 twkRelease(arr);
 138             });
 139             size = 0;
 140             if (log.isLoggable(Level.FINE)) {
 141                 log.log(Level.FINE, "'}'WCRenderQueue{0}[{1}]",
 142                         new Object[]{hashCode(), idCountObj.decrementAndGet()});
 143             }
 144         }
 145     }
 146 
 147     protected abstract void disposeGraphics();
 148 
 149     private void fwkDisposeGraphics() {
 150         disposeGraphics();
 151     }
 152 
 153     private native void twkRelease(Object[] bufs);
 154 
 155     /*is called from native*/
 156     private int refString(String str) {
 157         return currentBuffer.addString(str);
 158     }
 159 
 160     /*is called from native*/
 161     private int refIntArr(int[] arr) {




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.webkit.graphics;
  27 
  28 import java.lang.annotation.Native;
  29 import com.sun.javafx.logging.PlatformLogger;
  30 import com.sun.javafx.logging.PlatformLogger.Level;
  31 import com.sun.webkit.Invoker;
  32 import java.nio.ByteBuffer;
  33 import java.util.HashMap;
  34 import java.util.LinkedList;
  35 import java.util.concurrent.atomic.AtomicInteger;


  36 
  37 public abstract class WCRenderQueue extends Ref {
  38     private final static AtomicInteger idCountObj = new AtomicInteger(0);
  39     private final static PlatformLogger log =
  40             PlatformLogger.getLogger(WCRenderQueue.class.getName());
  41     @Native public final static int MAX_QUEUE_SIZE = 0x80000;
  42 
  43     private final LinkedList<BufferData> buffers = new LinkedList<BufferData>();
  44     private BufferData currentBuffer = new BufferData();
  45     private final WCRectangle clip;
  46     private int size = 0;
  47     private final boolean opaque;
  48 
  49     // Associated graphics context (currently used to draw to a buffered image).
  50     protected final WCGraphicsContext gc;
  51 
  52     protected WCRenderQueue(WCGraphicsContext gc) {
  53         this.clip = null;
  54         this.opaque = false;
  55         this.gc = gc;
  56     }
  57 
  58     protected WCRenderQueue(WCRectangle clip, boolean opaque) {
  59         this.clip = clip;
  60         this.opaque = opaque;
  61         this.gc = null;
  62     }
  63 
  64     public synchronized int getSize() {
  65         return size;
  66     }
  67 
  68     public synchronized void addBuffer(ByteBuffer buffer) {
  69         if (log.isLoggable(Level.FINE) && buffers.isEmpty()) {
  70             log.fine("'{'WCRenderQueue{0}[{1}]",
  71                     new Object[]{hashCode(), idCountObj.incrementAndGet()});
  72         }
  73         currentBuffer.setBuffer(buffer);
  74         buffers.addLast(currentBuffer);
  75         currentBuffer = new BufferData();
  76         size += buffer.capacity();
  77         if (size > MAX_QUEUE_SIZE && gc!=null) {
  78             // It is isolated queue over the canvas image [image-gc!=null].
  79             // We need to flush the changes periodically
  80             // by the same reason as in [WebPage.addLastRQ].
  81             flush();
  82         }
  83     }
  84 
  85     public synchronized boolean isEmpty() {
  86         return buffers.isEmpty();
  87     }
  88 
  89     public synchronized void decode(WCGraphicsContext gc) {
  90         for (BufferData bdata : buffers) {


 121     }
 122 
 123     public WCRectangle getClip() {
 124         return clip;
 125     }
 126 
 127     public synchronized void dispose() {
 128         int n = buffers.size();
 129         if (n > 0) {
 130             int i = 0;
 131             final Object[] arr = new Object[n];
 132             for (BufferData bdata: buffers) {
 133                 arr[i++] = bdata.getBuffer();
 134             }
 135             buffers.clear();
 136             Invoker.getInvoker().invokeOnEventThread(() -> {
 137                 twkRelease(arr);
 138             });
 139             size = 0;
 140             if (log.isLoggable(Level.FINE)) {
 141                 log.fine("'}'WCRenderQueue{0}[{1}]",
 142                         new Object[]{hashCode(), idCountObj.decrementAndGet()});
 143             }
 144         }
 145     }
 146 
 147     protected abstract void disposeGraphics();
 148 
 149     private void fwkDisposeGraphics() {
 150         disposeGraphics();
 151     }
 152 
 153     private native void twkRelease(Object[] bufs);
 154 
 155     /*is called from native*/
 156     private int refString(String str) {
 157         return currentBuffer.addString(str);
 158     }
 159 
 160     /*is called from native*/
 161     private int refIntArr(int[] arr) {


< prev index next >