2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 430N/A * The current "glyph mode" state. This variable is used to track the 430N/A * codepath used to render a particular glyph. This variable is reset to 430N/A * MODE_NOT_INITED at the beginning of every call to D3DTR_DrawGlyphList(). 430N/A * As each glyph is rendered, the glyphMode variable is updated to reflect 430N/A * the current mode, so if the current mode is the same as the mode used 430N/A * to render the previous glyph, we can avoid doing costly setup operations 430N/A * The current bounds of the "cached destination" texture, in destination 430N/A * only considered valid when the isCachedDestValid flag is JNI_TRUE. 430N/A * This flag indicates whether the "cached destination" texture contains 430N/A * valid data. This flag is reset to JNI_FALSE at the beginning of every 430N/A * call to D3DTR_DrawGlyphList(). Once we copy valid destination data 430N/A * into the cached texture, this flag is set to JNI_TRUE. This way, we 430N/A * can limit the number of times we need to copy destination data, which 430N/A * is a very costly operation. 430N/A * The bounds of the previously rendered LCD glyph, in destination 430N/A * coordinate space. We use these bounds to determine whether the glyph 430N/A * currently being rendered overlaps the previously rendered glyph (i.e. 430N/A * its bounding box intersects that of the previously rendered glyph). 430N/A * If so, we need to re-read the destination area associated with that 430N/A * previous glyph so that we can correctly blend with the actual 430N/A * Updates the gamma and inverse gamma values for the LCD text shader. 430N/A // update the "invgamma" parameter of the shader program 430N/A // update the "gamma" parameter of the shader program 430N/A * Updates the current gamma-adjusted source color ("src_adj") of the LCD 430N/A * text shader program. Note that we could calculate this value in the 430N/A * shader (e.g. just as we do for "dst_adj"), but would be unnecessary work 430N/A * (and a measurable performance hit, maybe around 5%) since this value is 430N/A * constant over the entire glyph list. So instead we just calculate the 430N/A * gamma-adjusted value once and update the uniform parameter of the LCD 430N/A * Note: Ideally we would update the "srcAdj" uniform parameter only 430N/A * when there is a change in the source color. Fortunately, the cost 430N/A * of querying the current D3D color state and updating the uniform 430N/A * value is quite small, and in the common case we only need to do this 430N/A * once per GlyphList, so we gain little from trying to optimize too 430N/A // get the current D3D primary color state 430N/A // gamma adjust the primary color 430N/A // update the "srcAdj" parameter of the shader program with this value 430N/A * Enables the LCD text shader and updates any related state, such as the 430N/A // glyph cache had been already initialized 430N/A // bind the texture containing glyph data to texture unit 0 430N/A // bind the texture tile containing destination data to texture unit 1 430N/A // update the current contrast settings (note: these change very rarely, 430N/A // but it seems that D3D pixel shader registers aren't maintained as 430N/A // part of the pixel shader instance, so we need to update these 430N/A // everytime around in case another shader blew away the contents 430N/A // update the current color settings 430N/A // glyph cache had been successfully initialized if we got here 430N/A * Disables any pending state associated with the current "glyph mode". 430N/A // attempt to add glyph to accelerated glyph cache 430N/A * the rectangle defined by bounds. 430N/A * This method checks to see if the given LCD glyph bounds fall within the 430N/A * cached destination texture bounds. If so, this method can return 430N/A * immediately. If not, this method will copy a chunk of framebuffer data 430N/A * into the cached destination texture and then update the current cached 430N/A * destination bounds before returning. 430N/A * The agx1, agx2 are "adjusted" glyph bounds, which are only used when checking 430N/A * against the previous glyph bounds. 430N/A // glyph is already within the cached destination bounds; no need 430N/A // to read back the entire destination region again, but we do 430N/A // need to see if the current glyph overlaps the previous glyph... 430N/A // only use the "adjusted" glyph bounds when checking against 430N/A // previous glyph's bounds 430N/A // the current glyph overlaps the destination region touched 430N/A // by the previous glyph, so now we need to read back the part 430N/A // of the destination corresponding to the previous glyph 430N/A // REMIND: make sure we flush any pending primitives that are 430N/A // dependent on the current contents of the cached dest 430N/A // now dxy12 represent the "desired" destination bounds, but the 430N/A // StretchRect() call may fail if these fall outside the actual 430N/A // surface bounds; therefore, we use cxy12 to represent the 430N/A // clamped bounds, and dxy12 are saved for later 430N/A // copy destination into subregion of cached texture tile 430N/A // cx1-cachedDestBounds.x1 == +xoffset from left of texture 430N/A // cy1-cachedDestBounds.y1 == +yoffset from top of texture 430N/A // cx2-cachedDestBounds.x1 == +xoffset from left of texture 430N/A // cy2-cachedDestBounds.y1 == +yoffset from top of texture 430N/A // destination region is not valid, so we need to read back a 430N/A // chunk of the destination into our cached texture 430N/A // position the upper-left corner of the destination region on the 430N/A // "top" line of glyph list 430N/A // REMIND: this isn't ideal; it would be better if we had some idea 430N/A // of the bounding box of the whole glyph list (this is 430N/A // do-able, but would require iterating through the whole 430N/A // list up front, which may present its own problems) 430N/A // estimate the width based on our current position in the glyph 430N/A // list and using the x advance of the current glyph (this is just 430N/A // a quick and dirty heuristic; if this is a "thin" glyph image, 430N/A // then we're likely to underestimate, and if it's "thick" then we 430N/A // may end up reading back more than we need to) 430N/A // in some cases, the x-advance may be slightly smaller 430N/A // than the actual width of the glyph; if so, adjust our 430N/A // estimate so that we can accomodate the entire glyph 430N/A // a negative advance is possible when rendering rotated text, 430N/A // in which case it is difficult to estimate an appropriate 430N/A // region for readback, so we will pick a region that 430N/A // encompasses just the current glyph 430N/A // estimate the height (this is another sloppy heuristic; we'll 430N/A // make the cached destination region tall enough to encompass most 430N/A // glyphs that are small enough to fit in the glyph cache, and then 430N/A // we add a little something extra to account for descenders 430N/A // REMIND: make sure we flush any pending primitives that are 430N/A // dependent on the current contents of the cached dest 430N/A // now dxy12 represent the "desired" destination bounds, but the 430N/A // StretchRect() call may fail if these fall outside the actual 430N/A // surface bounds; therefore, we use cxy12 to represent the 430N/A // clamped bounds, and dxy12 are saved for later 430N/A // copy destination into cached texture tile (the upper-left 430N/A // corner of the destination region will be positioned at the 430N/A // upper-left corner (0,0) of the texture) 430N/A // update the cached bounds and mark it valid 430N/A // always update the previous glyph bounds 430N/A // the glyph cache is initialized before this method is called 430N/A // attempt to add glyph to accelerated glyph cache 430N/A // we'll just no-op in the rare case that the cell is NULL 430N/A // location of the glyph in the destination's coordinate space 430N/A // copy destination into second cached texture, if necessary 430N/A // texture coordinates of the destination tile 430N/A // render composed texture to the destination surface 430N/A // calculate the bounds of the tile to be copied from the 430N/A // destination into the cached tile 430N/A // need to clamp to the destination bounds, otherwise the 430N/A // StretchRect() call may fail 430N/A // copy LCD mask into glyph texture tile 430N/A // update the lower-right glyph texture coordinates 430N/A // calculate the actual destination vertices 430N/A // copy destination into cached texture tile (the upper-left 430N/A // corner of the destination region will be positioned at the 430N/A // upper-left corner (0,0) of the texture) 430N/A // update the remaining destination texture coordinates 430N/A // render composed texture to the destination surface 430N/A // unfortunately we need to flush after each tile 430N/A if ((r)<0) (l) = ((
int)
floor(r));
else (l) = ((
int)(r))
430N/A // this shouldn't happen, but if it does we'll just break out... 430N/A "D3DTR_DrawGlyphList: glyph info is null");
430N/A // grayscale or monochrome glyph data 430N/A // LCD-optimized glyph data 430N/A // reset current state, and ensure rendering is flushed to dest