Exemple #1
0
/**
 * Adds the given glyph to the glyph cache (texture and data structure)
 * associated with the given OGLContext.
 */
static void
OGLTR_AddToGlyphCache(GlyphInfo *glyph, jboolean rgbOrder)
{
    GLenum pixelFormat;
    CacheCellInfo *ccinfo;

    J2dTraceLn(J2D_TRACE_INFO, "OGLTR_AddToGlyphCache");

    if ((glyphCache == NULL) || (glyph->image == NULL)) {
        return;
    }

    if (cacheStatus == CACHE_LCD) {
        pixelFormat = rgbOrder ? GL_RGB : GL_BGR;
    } else {
        pixelFormat = GL_LUMINANCE;
    }

    AccelGlyphCache_AddGlyph(glyphCache, glyph);
    ccinfo = (CacheCellInfo *) glyph->cellInfo;

    if (ccinfo != NULL) {
        // store glyph image in texture cell
        j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
                            ccinfo->x, ccinfo->y,
                            glyph->width, glyph->height,
                            pixelFormat, GL_UNSIGNED_BYTE, glyph->image);
    }
}
Exemple #2
0
HRESULT
D3DGlyphCache::AddGlyph(GlyphInfo *glyph)
{
    HRESULT res = S_OK;

    RETURN_STATUS_IF_NULL(pGlyphCacheRes, E_FAIL);

    CacheCellInfo *cellInfo = AccelGlyphCache_AddGlyph(pGlyphCache, glyph);
    if (cellInfo != NULL) {
        jint pixelsTouchedL = 0, pixelsTouchedR = 0;
        // store glyph image in texture cell
        res = pCtx->UploadTileToTexture(pGlyphCacheRes,
                                        glyph->image,
                                        cellInfo->x, cellInfo->y,
                                        0, 0,
                                        glyph->width, glyph->height,
                                        glyph->rowBytes, tileFormat,
                                        &pixelsTouchedL,
                                        &pixelsTouchedR);
        // LCD text rendering optimization: if the number of pixels touched on
        // the first or last column of the glyph image is less than 1/3 of the
        // height of the glyph we do not consider them touched.
        // See D3DTextRenderer.cpp:UpdateCachedDestination for more information.
        // The leftOff/rightOff are only used in LCD cache case.
        if (gcType == CACHE_LCD) {
            jint threshold = glyph->height/3;

            cellInfo->leftOff  = pixelsTouchedL < threshold ?  1 : 0;
            cellInfo->rightOff = pixelsTouchedR < threshold ? -1 : 0;
        } else {
            cellInfo->leftOff  = 0;
            cellInfo->rightOff = 0;
        }
    }

    return res;
}