/*
* 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.
*/
#ifndef HEADLESS
#include <stdlib.h>
#include "sun_java2d_pipe_BufferedOpCodes.h"
#include "jlong.h"
#include "OGLBlitLoops.h"
#include "OGLBufImgOps.h"
#include "OGLContext.h"
#include "OGLMaskBlit.h"
#include "OGLMaskFill.h"
#include "OGLPaints.h"
#include "OGLRenderQueue.h"
#include "OGLRenderer.h"
#include "OGLSurfaceData.h"
#include "OGLTextRenderer.h"
#include "OGLVertexCache.h"
/**
* Used to track whether we are in a series of a simple primitive operations
* or texturing operations. This variable should be controlled only via
* the INIT/CHECK/RESET_PREVIOUS_OP() macros. See the
* OGLRenderQueue_CheckPreviousOp() method below for more information.
*/
/**
* References to the "current" context and destination surface.
*/
/**
* The following methods are implemented in the windowing system (i.e. GLX
* and WGL) source files.
*/
{
unsigned char *b, *end;
"OGLRenderQueue_flushBuffer: limit=%d", limit);
b = (unsigned char *)jlong_to_ptr(buf);
if (b == NULL) {
"OGLRenderQueue_flushBuffer: cannot get direct buffer address");
return;
}
while (b < end) {
"OGLRenderQueue_flushBuffer: opcode=%d, rem=%d",
switch (opcode) {
// draw ops
{
}
break;
{
OGLRenderer_DrawRect(oglc, x, y, w, h);
}
break;
{
}
break;
{
// Note that we could use GL_POINTS here, but the common
// use case for DRAW_PIXEL is when rendering a Path2D,
// which will consist of a mix of DRAW_PIXEL and DRAW_LINE
// calls. So to improve batching we use GL_LINES here,
// even though it requires an extra vertex per pixel.
j2d_glVertex2i(x, y);
}
break;
{
}
break;
{
}
break;
{
}
break;
// fill ops
{
OGLRenderer_FillRect(oglc, x, y, w, h);
}
break;
{
}
break;
{
}
break;
{
}
break;
// text-related ops
{
unsigned char *images = b;
unsigned char *positions;
if (usePositions) {
} else {
}
}
break;
// copy-related ops
{
}
break;
{
if (isoblit) {
} else {
}
}
break;
{
}
break;
{
OGLMaskFill_MaskFill(oglc, x, y, w, h,
SKIP_BYTES(b, masklen);
}
break;
{
SKIP_BYTES(b, masklen);
}
break;
// state-related ops
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
// context-related ops
{
}
}
break;
{
}
}
break;
{
}
}
break;
{
}
}
}
break;
{
// the previous method will call glX/wglMakeCurrent(None),
// so we should nullify the current oglc and dstOps to avoid
// calling glFlush() (or similar) while no context is current
}
break;
{
// flush just in case there are any pending operations in
// the hardware pipe
j2d_glFlush();
}
// invalidate the references to the current context and
// destination surface that are maintained at the native level
}
break;
{
}
break;
{
}
break;
{
}
break;
// multibuffering ops
{
}
}
break;
// special no-op (mainly used for achieving 8-byte alignment)
break;
// paint-related ops
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
{
}
break;
// BufferedImageOp-related ops
{
kernelWidth, kernelHeight, b);
}
break;
{
}
break;
{
unsigned char *scaleFactors = b;
}
break;
{
}
break;
{
void *tableValues = b;
}
break;
{
}
break;
default:
"OGLRenderQueue_flushBuffer: invalid opcode=%d", opcode);
}
return;
}
}
if (sync) {
j2d_glFinish();
} else {
j2d_glFlush();
}
}
}
/**
* Returns a pointer to the "current" context, as set by the last SET_SURFACES
* or SET_SCRATCH_SURFACE operation.
*/
{
return oglc;
}
/**
* Returns a pointer to the "current" destination surface, as set by the last
* SET_SURFACES operation.
*/
OGLSDOps *
{
return dstOps;
}
/**
* Used to track whether we are within a series of simple primitive operations
* or texturing operations. The op parameter determines the nature of the
* operation that is to follow. Valid values for this op parameter are:
*
* GL_QUADS
* GL_LINES
* GL_LINE_LOOP
* GL_LINE_STRIP
* (basically any of the valid parameters for glBegin())
*
* GL_TEXTURE_2D
* GL_TEXTURE_RECTANGLE_ARB
*
* OGL_STATE_RESET
* OGL_STATE_CHANGE
* OGL_STATE_MASK_OP
* OGL_STATE_GLYPH_OP
*
* Note that the above constants are guaranteed to be unique values. The
* last few are defined to be negative values to differentiate them from
* the core GL* constants, which are defined to be non-negative.
*
* For simple primitives, this method allows us to batch similar primitives
* within the same glBegin()/glEnd() pair. For example, if we have 100
* consecutive FILL_RECT operations, we only have to call glBegin(GL_QUADS)
* for the first op, and then subsequent operations will consist only of
* glVertex*() calls, which helps improve performance. The glEnd() call
* only needs to be issued before an operation that cannot happen within a
* glBegin()/glEnd() pair (e.g. updating the clip), or one that requires a
* different primitive mode (e.g. GL_LINES).
*
* For operations that involve texturing, this method helps us to avoid
* calling glEnable(GL_TEXTURE_2D) and glDisable(GL_TEXTURE_2D) around each
* operation. For example, if we have an alternating series of ISO_BLIT
* and MASK_BLIT operations (both of which involve texturing), we need
* only to call glEnable(GL_TEXTURE_2D) before the first ISO_BLIT operation.
* The glDisable(GL_TEXTURE_2D) call only needs to be issued before an
* operation that cannot (or should not) happen while texturing is enabled
* (e.g. a context change, or a simple primitive operation like GL_QUADS).
*/
void
{
if (previousOp == op) {
// The op is the same as last time, so we can return immediately.
return;
}
"OGLRenderQueue_CheckPreviousOp: new op=%d", op);
switch (previousOp) {
case GL_TEXTURE_2D:
case GL_TEXTURE_RECTANGLE_ARB:
if (op == OGL_STATE_CHANGE) {
// Optimization: Certain state changes (those marked as
// OGL_STATE_CHANGE) are allowed while texturing is enabled.
// In this case, we can allow previousOp to remain as it is and
// then return early.
return;
} else {
// Otherwise, op must be a primitive operation, or a reset, so
// we will disable texturing.
// This next step of binding to zero should not be strictly
// necessary, but on some older Nvidia boards (e.g. GeForce 2)
// problems will arise if GL_TEXTURE_2D and
// GL_TEXTURE_RECTANGLE_ARB are bound at the same time, so we
// will do this just to be safe.
}
break;
case OGL_STATE_MASK_OP:
break;
case OGL_STATE_GLYPH_OP:
break;
case OGL_STATE_PGRAM_OP:
break;
case OGL_STATE_RESET:
case OGL_STATE_CHANGE:
// No-op
break;
default:
// In this case, op must be one of:
// - the start of a different primitive type (glBegin())
// - a texturing operation
// - a state change (not allowed within glBegin()/glEnd() pairs)
// - a reset
// so we must first complete the previous primitive operation.
j2d_glEnd();
break;
}
switch (op) {
case GL_TEXTURE_2D:
case GL_TEXTURE_RECTANGLE_ARB:
// We are starting a texturing operation, so enable texturing.
break;
case OGL_STATE_MASK_OP:
break;
case OGL_STATE_GLYPH_OP:
break;
case OGL_STATE_PGRAM_OP:
break;
case OGL_STATE_RESET:
case OGL_STATE_CHANGE:
// No-op
break;
default:
// We are starting a primitive operation, so call glBegin() with
// the given primitive type.
break;
}
previousOp = op;
}
#endif /* !HEADLESS */