/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
#include <stdlib.h>
#include "jni.h"
#include "AccelGlyphCache.h"
#include "Trace.h"
/**
* When the cache is full, we will try to reuse the cache cells that have
* been used relatively less than the others (and we will save the cells that
* have been rendered more than the threshold defined here).
*/
/**
* Creates a new GlyphCacheInfo structure, fills in the initial values, and
* then returns a pointer to the GlyphCacheInfo record.
*
* Note that this method only sets up a data structure describing a
* rectangular region of accelerated memory, containing "virtual" cells of
* the requested size. The cell information is added lazily to the linked
* list describing the cache as new glyphs are added. Platform specific
* glyph caching code is responsible for actually creating the accelerated
* memory surface that will contain the individual glyph images.
*
* Each glyph contains a reference to a list of cell infos - one per glyph
* cache. There may be multiple glyph caches (for example, one per graphics
* adapter), so if the glyph is cached on two devices its cell list will
* consists of two elements corresponding to different glyph caches.
*
* The platform-specific glyph caching code is supposed to use
* GetCellInfoForCache method for retrieving cache infos from the glyph's list.
*
* Note that if it is guaranteed that there will be only one global glyph
* cache then it one does not have to use AccelGlyphCache_GetCellInfoForCache
* for retrieving cell info for the glyph, but instead just use the struct's
* field directly.
*/
{
"AccelGlyphCache_Init: could not allocate GlyphCacheInfo");
return NULL;
}
return gcinfo;
}
/**
* Attempts to add the provided glyph to the specified cache. If the
* operation is successful, a pointer to the newly occupied cache cell is
* stored in the glyph's cellInfo field; otherwise, its cellInfo field is
* set to NULL, indicating that the glyph's original bits should be rendered
* instead. If the cache is full, the least-recently-used glyph is
* invalidated and its cache cell is reassigned to the new glyph being added.
*
* Note that this method only ensures that a rectangular region in the
* "virtual" glyph cache is available for the glyph image. Platform specific
* glyph caching code is responsible for actually caching the glyph image
* in the associated accelerated memory surface.
*
* Returns created cell info if it was successfully created and added to the
* cache and glyph's cell lists, NULL otherwise.
*/
{
{
return NULL;
}
jint x, y;
x = 0;
y = 0;
} else {
x = 0;
y += cache->cellHeight;
// no room left for a new cell; we'll go through the
// isFull path below
}
}
}
// create new CacheCellInfo
return NULL;
}
cellinfo->timesRendered = 0;
cellinfo->x = x;
cellinfo->y = y;
// initialize the head cell
} else {
// update existing tail cell
}
// add the new cell to the end of the list
}
}
/**
* Search through the cells, and for each cell:
* - reset its timesRendered counter to zero
* - toss it to the end of the list
* Eventually we will find a cell that either:
* - is empty, or
* - has been used less than the threshold
* When we find such a cell, we will:
* - break out of the loop
* - invalidate any glyph that may be residing in that cell
* - update the cell with the new resident glyph's information
*
* The goal here is to keep the glyphs rendered most often in the
* cache, while younger glyphs hang out near the end of the list.
* Those young glyphs that have only been used a few times will move
* towards the head of the list and will eventually be kicked to
* the curb.
*
* In the worst-case scenario, all cells will be occupied and they
* will all have timesRendered counts above the threshold, so we will
* end up iterating through all the cells exactly once. Since we are
* resetting their counters along the way, we are guaranteed to
* eventually hit the original "head" cell, whose counter is now zero.
* This avoids the possibility of an infinite loop.
*/
do {
// the head cell will be updated on each iteration
{
// all bow before the chosen one (we will break out of the
// loop now that we've found an appropriate cell)
}
// move cell to the end of the list; update existing head and
// tail pointers
current->timesRendered = 0;
// flush in case any pending vertices are depending on the
// glyph that is about to be kicked out
}
// if the cell is occupied, notify the base glyph that the
// cached version for this cache is about to be kicked out
}
// update cellinfo with glyph's occupied region information
}
// add cache cell to the glyph's cells list
return cellinfo;
}
/**
* Invalidates all cells in the cache. Note that this method does not
* attempt to compact the cache in any way; it just invalidates any cells
* that already exist.
*/
void
{
return;
}
// flush any pending vertices that may be depending on the current
// glyph cache layout
}
// if the cell is occupied, notify the base glyph that its
// cached version for this cache is about to be invalidated
}
}
}
/**
* Invalidates and frees all cells and the cache itself. The "cache" pointer
* becomes invalid after this function returns.
*/
void
{
return;
}
// flush any pending vertices that may be depending on the current
// glyph cache
}
// if the cell is occupied, notify the base glyph that its
// cached version for this cache is about to be invalidated
}
}
}
/**
* Add cell info to the head of the glyph's list of cached cells.
*/
void
{
// assert (glyph != NULL && cellInfo != NULL)
}
/**
* Removes cell info from the glyph's list of cached cells.
*/
void
{
// assert (glyph!= NULL && glyph->cellInfo != NULL && cellInfo != NULL)
do {
if (currCellInfo == cellInfo) {
" glyph 0x%x: removing cell 0x%x from glyph's list",
} else {
}
return;
}
} while (currCellInfo != NULL);
"no cell 0x%x in glyph 0x%x's cell list",
}
/**
* Removes cell info from the glyph's list of cached cells.
*/
JNIEXPORT void
{
return;
}
// invalidate all of this glyph's accelerated cache cells
do {
}
/**
* Returns cell info associated with particular cache from the glyph's list of
* cached cells.
*/
{
// assert (glyph != NULL && cache != NULL)
do {
" glyph 0x%x: found cell 0x%x for cache 0x%x",
return cellInfo;
}
}
return NULL;
}