Пример #1
0
  public void changeWorkingSet(WorkingSet<String> newSet) {
    // cancel any pending jobs so that we don't waste time loading images no longer needed
    loaderPool.clearJobs();

    if (DEBUG) {
      System.out.println("RamTextureCache: changeWorkingSet:");
      for (String imageId : newSet.getPrioritizedList())
        System.out.printf("\t%s (pri %d)\n", imageId, newSet.getPriority(imageId));
    }

    synchronized (cache) // because of race with imageLoaded()
    {
      // adjust priorities of already cached items.
      // (No longer needed items get super low priority)
      cache.updatePriority(newSet);

      // switch working sets
      curSet = newSet;

      // Start loading those which we are missing
      for (String imageId : newSet.getPrioritizedList()) {
        if (!cache.contains(imageId)) {
          if (DEBUG) System.out.printf("RamTextureCache: not cached: %s\n", imageId);
          loaderPool.addJob(imageId);
        }
      }
    }
  }
Пример #2
0
  public boolean shouldLoad(String filePath, int estimatedImageSize) {
    synchronized (cache) // because of race with changeWorkingSet() and getGLImage
    {
      // if somebody is waiting for it we have no choice
      if (urgentImageIds.contains(filePath) && curSet.contains(filePath)) return true;
      else {
        int priority = curSet.getPriority(filePath);

        // lower priority by one - ImageLoaderPool should not bother loading an image
        // if it's just going to replace one of equal priority - there's no point
        if (priority > Integer.MIN_VALUE) priority--;

        return cache.canStore(estimatedImageSize, priority);
      }
    }
  }
Пример #3
0
  public void imageLoaded(String filePath, GLImage image) {
    synchronized (cache) // because of race with changeWorkingSet() and getGLImage
    {
      int priority = curSet.getPriority(filePath);
      boolean isInCurSet = priority > Integer.MIN_VALUE;

      if (DEBUG) System.out.printf("RamTextureCache: loaded %s (pri=%d)\n", filePath, priority);

      // Store the loaded image in cache
      boolean full = !cache.store(filePath, image, image.nBytes, priority);

      // Stop loading images if the cache is full.
      // Second condition is important in case image was from previous
      // working set - we don't want to abort loading the new set
      if (full && isInCurSet) {
        if (DEBUG) System.out.println("RamTextureCache: cache is full, stop loading");
        loaderPool.clearJobs();
      }

      // wake up threads inside getGLImage()
      cache.notifyAll();
    }
  }