- remove swrenderer

- rearchitect:
 now that MapView is a ViewGroup and MapRenderer is the GLSurfaceView.
- lock/unlock proxy tiles properly to not be removed from cache while in use
This commit is contained in:
Hannes Janetzek
2012-09-16 19:26:53 +02:00
parent caea9cd7c9
commit a1317a9de5
81 changed files with 5271 additions and 5408 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.view.generator;
//import static org.oscim.view.mapgenerator.JobTile.LOADING;
import java.util.ArrayList;
import java.util.PriorityQueue;
/**
* A JobQueue keeps the list of pending jobs for a MapView and prioritizes them.
*/
public class JobQueue {
private static final int INITIAL_CAPACITY = 64;
private PriorityQueue<JobTile> mPriorityQueue;
/**
*/
public JobQueue() {
mPriorityQueue = new PriorityQueue<JobTile>(INITIAL_CAPACITY);
}
/**
* @param tiles
* the job to be added to this queue.
*/
public synchronized void setJobs(ArrayList<JobTile> tiles) {
mPriorityQueue.clear();
// mPriorityQueue.addAll(tiles);
for (int i = 0, n = tiles.size(); i < n; i++) {
JobTile tile = tiles.get(i);
// tile.state = LOADING;
tile.isLoading = true;
mPriorityQueue.offer(tile);
}
}
/**
* Removes all jobs from this queue.
*/
public synchronized void clear() {
for (int i = 0, n = mPriorityQueue.size(); i < n; i++) {
JobTile tile = mPriorityQueue.poll();
// tile.state = 0;
tile.isLoading = false;
}
mPriorityQueue.clear();
}
/**
* @return true if this queue contains no jobs, false otherwise.
*/
public synchronized boolean isEmpty() {
return mPriorityQueue.isEmpty();
}
/**
* @return the most important job from this queue or null, if empty.
*/
public synchronized JobTile poll() {
JobTile tile = mPriorityQueue.poll();
return tile;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.view.generator;
import org.oscim.core.Tile;
/**
*
*/
public class JobTile extends Tile implements Comparable<JobTile> {
// public final static int LOADING = 1;
// public final static int NEWDATA = 1 << 1;
// public final static int READY = 1 << 2;
// public final static int AVAILABLE = 1 << 1 | 1 << 2;
// public final static int CANCELED = 1 << 3;
// public int state;
/**
* tile is in JobQueue
*/
public boolean isLoading;
/**
* distance from map center.
*/
public float distance;
/**
* @param tileX
* ...
* @param tileY
* ...
* @param zoomLevel
* ..
*/
public JobTile(int tileX, int tileY, byte zoomLevel) {
super(tileX, tileY, zoomLevel);
}
@Override
public int compareTo(JobTile o) {
if (this.distance < o.distance) {
return -1;
}
if (this.distance > o.distance) {
return 1;
}
return 0;
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.view.generator;
import org.oscim.utils.PausableThread;
import org.oscim.view.renderer.MapGenerator;
import org.oscim.view.renderer.MapRenderer;
/**
* A MapWorker uses a {@link IMapGenerator} to generate map tiles. It runs in a separate thread to avoid blocking the UI
* thread.
*/
public class MapWorker extends PausableThread {
private final String THREAD_NAME;
private final JobQueue mJobQueue;
private final MapGenerator mMapGenerator;
private final MapRenderer mMapRenderer;
// private final int mPrio;
/**
* @param id
* thread id
* @param mapGenerator
* ...
* @param mapRenderer
* ...
*/
public MapWorker(int id, JobQueue jobQueue, MapGenerator mapGenerator,
MapRenderer mapRenderer) {
super();
mJobQueue = jobQueue;
mMapGenerator = mapGenerator;
mMapRenderer = mapRenderer;
THREAD_NAME = "MapWorker" + id;
// mPrio = Math.max(Thread.MIN_PRIORITY + id, Thread.NORM_PRIORITY - 1);
}
public MapGenerator getMapGenerator() {
return mMapGenerator;
}
@Override
protected void afterRun() {
// empty
}
@Override
protected void doWork() {
JobTile tile = mJobQueue.poll();
if (mMapGenerator == null || tile == null)
return;
boolean success = mMapGenerator.executeJob(tile);
if (!isInterrupted() && success) {
mMapRenderer.passTile(tile);
}
}
@Override
protected String getThreadName() {
return THREAD_NAME;
}
@Override
protected void takeabreak() {
mMapGenerator.getMapDatabase().cancel();
}
@Override
protected int getThreadPriority() {
return (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 3;
// return mPrio;
}
@Override
protected boolean hasWork() {
return !mJobQueue.isEmpty();
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.view.generator;
import java.util.Comparator;
/**
*
*
*/
public class TileDistanceSort implements Comparator<JobTile> {
@Override
public int compare(JobTile tile1, JobTile tile2) {
if (tile1.distance == tile2.distance)
return 0;
return tile1.distance > tile2.distance ? 1 : -1;
}
}