Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/jules/IdleTileCache.java
32288 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.jules;2627import java.util.*;2829public class IdleTileCache {30final static int IDLE_TILE_SYNC_GRANULARITY = 16;31final static ArrayList<JulesTile> idleBuffers = new ArrayList<JulesTile>();3233ArrayList<JulesTile> idleTileWorkerCacheList = new ArrayList<JulesTile>();34ArrayList<JulesTile> idleTileConsumerCacheList =35new ArrayList<JulesTile>(IDLE_TILE_SYNC_GRANULARITY);3637/**38* Return a cached Tile, if possible from cache.39* Allowed caller: Rasterizer/Producer-Thread40*41* @param: maxCache - Specify the maximum amount of tiles needed42*/43public JulesTile getIdleTileWorker(int maxCache) {44/* Try to fetch idle tiles from the global cache list */45if (idleTileWorkerCacheList.size() == 0) {46idleTileWorkerCacheList.ensureCapacity(maxCache);4748synchronized (idleBuffers) {49for (int i = 0; i < maxCache && idleBuffers.size() > 0; i++) {50idleTileWorkerCacheList.add(51idleBuffers.remove(idleBuffers.size() - 1));52}53}54}5556if (idleTileWorkerCacheList.size() > 0) {57return idleTileWorkerCacheList.remove(idleTileWorkerCacheList.size() - 1);58}5960return new JulesTile();61}6263/**64* Release tile and allow it to be re-used by another thread. Allowed65* Allowed caller: MaskBlit/Consumer-Thread66*/67public void releaseTile(JulesTile tile) {68if (tile != null && tile.hasBuffer()) {69idleTileConsumerCacheList.add(tile);7071if (idleTileConsumerCacheList.size() > IDLE_TILE_SYNC_GRANULARITY) {72synchronized (idleBuffers) {73idleBuffers.addAll(idleTileConsumerCacheList);74}75idleTileConsumerCacheList.clear();76}77}78}7980/**81* Releases thread-local tiles cached for use by the rasterizing thread.82* Allowed caller: Rasterizer/Producer-Thread83*/84public void disposeRasterizerResources() {85releaseTiles(idleTileWorkerCacheList);86}8788/**89* Releases thread-local tiles cached for performance reasons. Allowed90* Allowed caller: MaskBlit/Consumer-Thread91*/92public void disposeConsumerResources() {93releaseTiles(idleTileConsumerCacheList);94}9596/**97* Release a list of tiles and allow it to be re-used by another thread.98* Thread safe.99*/100public void releaseTiles(List<JulesTile> tileList) {101if (tileList.size() > 0) {102synchronized (idleBuffers) {103idleBuffers.addAll(tileList);104}105tileList.clear();106}107}108}109110111