blob: 07bc81428868cba9a11ca478600c52e5019febb5 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#include <malloc.h>
27#include "sun_java2d_d3d_D3DTextRenderer.h"
28#include "SurfaceData.h"
29#include "Region.h"
30#include "glyphblitting.h"
31
32extern "C" {
33
34#ifndef D3D_GCACHE_WIDTH
35 #define D3D_GCACHE_WIDTH 512
36 #define D3D_GCACHE_HEIGHT 512
37 #define D3D_GCACHE_CELL_WIDTH 16
38 #define D3D_GCACHE_CELL_HEIGHT 16
39#endif
40
41/**
42 * This method is almost exactly the same as the RefineBounds() method
43 * defined in DrawGlyphList.c. The goal is to determine whether the given
44 * GlyphBlitVector intersects with the given bounding box. If any part of
45 * the GBV intersects with the bounding box, this method returns true;
46 * otherwise false is returned. The only step that differs in this method
47 * from RefineBounds() is that we check to see whether all the glyphs in
48 * the GBV will fit in the glyph cache. If any glyph is too big for a
49 * glyph cache cell, we return FALSE in the useCache out parameter; otherwise
50 * useCache is TRUE, indicating that the caller can be assured that all
51 * the glyphs can be stored in the accelerated glyph cache.
52 */
53jboolean
54D3DRefineBounds(GlyphBlitVector *gbv, SurfaceDataBounds *bounds,
55 jboolean *useCache)
56{
57 int index;
58 jint dx1, dy1, dx2, dy2;
59 ImageRef glyphImage;
60 int num = gbv->numGlyphs;
61 SurfaceDataBounds glyphs;
62 jboolean tryCache = JNI_TRUE;
63
64 glyphs.x1 = glyphs.y1 = 0x7fffffff;
65 glyphs.x2 = glyphs.y2 = 0x80000000;
66 for (index = 0; index < num; index++) {
67 glyphImage = gbv->glyphs[index];
68 dx1 = (jint) glyphImage.x;
69 dy1 = (jint) glyphImage.y;
70 dx2 = dx1 + glyphImage.width;
71 dy2 = dy1 + glyphImage.height;
72 if (glyphs.x1 > dx1) glyphs.x1 = dx1;
73 if (glyphs.y1 > dy1) glyphs.y1 = dy1;
74 if (glyphs.x2 < dx2) glyphs.x2 = dx2;
75 if (glyphs.y2 < dy2) glyphs.y2 = dy2;
76
77 if (tryCache &&
78 ((glyphImage.width > D3D_GCACHE_CELL_WIDTH) ||
79 (glyphImage.height > D3D_GCACHE_CELL_HEIGHT)))
80 {
81 tryCache = JNI_FALSE;
82 }
83 }
84
85 *useCache = tryCache;
86
87 SurfaceData_IntersectBounds(bounds, &glyphs);
88 return (bounds->x1 < bounds->x2 && bounds->y1 < bounds->y2);
89}
90
91extern JNIEXPORT void JNICALL
92 D3DDrawGlyphList(JNIEnv *env, jobject d3dtr,
93 jlong pData, jlong pCtx,
94 ImageRef *glyphs, jint totalGlyphs,
95 jboolean useCache);
96
97/*
98 * Class: sun_java2d_d3d_D3DTextRenderer
99 * Method: doDrawGlyphList
100 * Signature: (JLsun/java2d/pipe/Region;Lsun/font/GlyphList;)V
101 */
102JNIEXPORT void JNICALL Java_sun_java2d_d3d_D3DTextRenderer_doDrawGlyphList
103 (JNIEnv *env, jobject d3dtr,
104 jlong pData,
105 jlong pCtx, jobject clip, jobject glyphlist)
106{
107 GlyphBlitVector* gbv;
108 SurfaceDataBounds bounds;
109 jboolean useCache;
110
111 if ((pData == 0) || (pCtx == 0)) {
112 return;
113 }
114
115 Region_GetBounds(env, clip, &bounds);
116
117 if ((gbv = setupBlitVector(env, glyphlist)) == NULL) {
118 return;
119 }
120
121 if (!D3DRefineBounds(gbv, &bounds, &useCache)) {
122 free(gbv);
123 return;
124 }
125
126 D3DDrawGlyphList(env, d3dtr,
127 pData, pCtx,
128 gbv->glyphs, gbv->numGlyphs, useCache);
129 free(gbv);
130}
131
132}