0N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef HEADLESS
0N/A
4632N/A#include <stdlib.h>
0N/A
0N/A#include "sun_java2d_pipe_BufferedOpCodes.h"
0N/A
0N/A#include "jlong.h"
0N/A#include "OGLBlitLoops.h"
0N/A#include "OGLBufImgOps.h"
0N/A#include "OGLContext.h"
0N/A#include "OGLMaskBlit.h"
0N/A#include "OGLMaskFill.h"
0N/A#include "OGLPaints.h"
0N/A#include "OGLRenderQueue.h"
0N/A#include "OGLRenderer.h"
0N/A#include "OGLSurfaceData.h"
0N/A#include "OGLTextRenderer.h"
0N/A#include "OGLVertexCache.h"
0N/A
0N/A/**
0N/A * Used to track whether we are in a series of a simple primitive operations
0N/A * or texturing operations. This variable should be controlled only via
0N/A * the INIT/CHECK/RESET_PREVIOUS_OP() macros. See the
0N/A * OGLRenderQueue_CheckPreviousOp() method below for more information.
0N/A */
0N/Ajint previousOp;
0N/A
0N/A/**
0N/A * References to the "current" context and destination surface.
0N/A */
0N/Astatic OGLContext *oglc = NULL;
0N/Astatic OGLSDOps *dstOps = NULL;
0N/A
0N/A/**
0N/A * The following methods are implemented in the windowing system (i.e. GLX
0N/A * and WGL) source files.
0N/A */
0N/Aextern OGLContext *OGLSD_SetScratchSurface(JNIEnv *env, jlong pConfigInfo);
0N/Aextern void OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo);
0N/Aextern void OGLSD_SwapBuffers(JNIEnv *env, jlong window);
4632N/Aextern void OGLSD_Flush(JNIEnv *env);
0N/A
0N/AJNIEXPORT void JNICALL
0N/AJava_sun_java2d_opengl_OGLRenderQueue_flushBuffer
0N/A (JNIEnv *env, jobject oglrq,
0N/A jlong buf, jint limit)
0N/A{
0N/A jboolean sync = JNI_FALSE;
0N/A unsigned char *b, *end;
0N/A
0N/A J2dTraceLn1(J2D_TRACE_INFO,
0N/A "OGLRenderQueue_flushBuffer: limit=%d", limit);
0N/A
0N/A b = (unsigned char *)jlong_to_ptr(buf);
0N/A if (b == NULL) {
0N/A J2dRlsTraceLn(J2D_TRACE_ERROR,
0N/A "OGLRenderQueue_flushBuffer: cannot get direct buffer address");
0N/A return;
0N/A }
0N/A
0N/A INIT_PREVIOUS_OP();
0N/A end = b + limit;
0N/A
0N/A while (b < end) {
0N/A jint opcode = NEXT_INT(b);
0N/A
430N/A J2dTraceLn2(J2D_TRACE_VERBOSE,
430N/A "OGLRenderQueue_flushBuffer: opcode=%d, rem=%d",
430N/A opcode, (end-b));
0N/A
0N/A switch (opcode) {
0N/A
0N/A // draw ops
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
0N/A {
0N/A jint x1 = NEXT_INT(b);
0N/A jint y1 = NEXT_INT(b);
0N/A jint x2 = NEXT_INT(b);
0N/A jint y2 = NEXT_INT(b);
0N/A OGLRenderer_DrawLine(oglc, x1, y1, x2, y2);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:
0N/A {
0N/A jint x = NEXT_INT(b);
0N/A jint y = NEXT_INT(b);
0N/A jint w = NEXT_INT(b);
0N/A jint h = NEXT_INT(b);
0N/A OGLRenderer_DrawRect(oglc, x, y, w, h);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_POLY:
0N/A {
0N/A jint nPoints = NEXT_INT(b);
0N/A jboolean isClosed = NEXT_BOOLEAN(b);
0N/A jint transX = NEXT_INT(b);
0N/A jint transY = NEXT_INT(b);
0N/A jint *xPoints = (jint *)b;
0N/A jint *yPoints = ((jint *)b) + nPoints;
0N/A OGLRenderer_DrawPoly(oglc, nPoints, isClosed,
0N/A transX, transY,
0N/A xPoints, yPoints);
0N/A SKIP_BYTES(b, nPoints * BYTES_PER_POLY_POINT);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_PIXEL:
0N/A {
0N/A jint x = NEXT_INT(b);
0N/A jint y = NEXT_INT(b);
0N/A // Note that we could use GL_POINTS here, but the common
0N/A // use case for DRAW_PIXEL is when rendering a Path2D,
0N/A // which will consist of a mix of DRAW_PIXEL and DRAW_LINE
0N/A // calls. So to improve batching we use GL_LINES here,
0N/A // even though it requires an extra vertex per pixel.
0N/A CONTINUE_IF_NULL(oglc);
0N/A CHECK_PREVIOUS_OP(GL_LINES);
0N/A j2d_glVertex2i(x, y);
0N/A j2d_glVertex2i(x+1, y+1);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_SCANLINES:
0N/A {
0N/A jint count = NEXT_INT(b);
0N/A OGLRenderer_DrawScanlines(oglc, count, (jint *)b);
0N/A SKIP_BYTES(b, count * BYTES_PER_SCANLINE);
0N/A }
0N/A break;
430N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
430N/A {
430N/A jfloat x11 = NEXT_FLOAT(b);
430N/A jfloat y11 = NEXT_FLOAT(b);
430N/A jfloat dx21 = NEXT_FLOAT(b);
430N/A jfloat dy21 = NEXT_FLOAT(b);
430N/A jfloat dx12 = NEXT_FLOAT(b);
430N/A jfloat dy12 = NEXT_FLOAT(b);
430N/A jfloat lwr21 = NEXT_FLOAT(b);
430N/A jfloat lwr12 = NEXT_FLOAT(b);
430N/A OGLRenderer_DrawParallelogram(oglc,
430N/A x11, y11,
430N/A dx21, dy21,
430N/A dx12, dy12,
430N/A lwr21, lwr12);
430N/A }
430N/A break;
430N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_AAPARALLELOGRAM:
430N/A {
430N/A jfloat x11 = NEXT_FLOAT(b);
430N/A jfloat y11 = NEXT_FLOAT(b);
430N/A jfloat dx21 = NEXT_FLOAT(b);
430N/A jfloat dy21 = NEXT_FLOAT(b);
430N/A jfloat dx12 = NEXT_FLOAT(b);
430N/A jfloat dy12 = NEXT_FLOAT(b);
430N/A jfloat lwr21 = NEXT_FLOAT(b);
430N/A jfloat lwr12 = NEXT_FLOAT(b);
430N/A OGLRenderer_DrawAAParallelogram(oglc, dstOps,
430N/A x11, y11,
430N/A dx21, dy21,
430N/A dx12, dy12,
430N/A lwr21, lwr12);
430N/A }
430N/A break;
0N/A
0N/A // fill ops
0N/A case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:
0N/A {
0N/A jint x = NEXT_INT(b);
0N/A jint y = NEXT_INT(b);
0N/A jint w = NEXT_INT(b);
0N/A jint h = NEXT_INT(b);
0N/A OGLRenderer_FillRect(oglc, x, y, w, h);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_FILL_SPANS:
0N/A {
0N/A jint count = NEXT_INT(b);
0N/A OGLRenderer_FillSpans(oglc, count, (jint *)b);
0N/A SKIP_BYTES(b, count * BYTES_PER_SPAN);
0N/A }
0N/A break;
430N/A case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
430N/A {
430N/A jfloat x11 = NEXT_FLOAT(b);
430N/A jfloat y11 = NEXT_FLOAT(b);
430N/A jfloat dx21 = NEXT_FLOAT(b);
430N/A jfloat dy21 = NEXT_FLOAT(b);
430N/A jfloat dx12 = NEXT_FLOAT(b);
430N/A jfloat dy12 = NEXT_FLOAT(b);
430N/A OGLRenderer_FillParallelogram(oglc,
430N/A x11, y11,
430N/A dx21, dy21,
430N/A dx12, dy12);
430N/A }
430N/A break;
430N/A case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:
430N/A {
430N/A jfloat x11 = NEXT_FLOAT(b);
430N/A jfloat y11 = NEXT_FLOAT(b);
430N/A jfloat dx21 = NEXT_FLOAT(b);
430N/A jfloat dy21 = NEXT_FLOAT(b);
430N/A jfloat dx12 = NEXT_FLOAT(b);
430N/A jfloat dy12 = NEXT_FLOAT(b);
430N/A OGLRenderer_FillAAParallelogram(oglc, dstOps,
430N/A x11, y11,
430N/A dx21, dy21,
430N/A dx12, dy12);
430N/A }
430N/A break;
0N/A
0N/A // text-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_DRAW_GLYPH_LIST:
0N/A {
0N/A jint numGlyphs = NEXT_INT(b);
0N/A jint packedParams = NEXT_INT(b);
0N/A jfloat glyphListOrigX = NEXT_FLOAT(b);
0N/A jfloat glyphListOrigY = NEXT_FLOAT(b);
0N/A jboolean usePositions = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_POSITIONS);
0N/A jboolean subPixPos = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_SUBPIXPOS);
0N/A jboolean rgbOrder = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_RGBORDER);
0N/A jint lcdContrast = EXTRACT_BYTE(packedParams,
0N/A OFFSET_CONTRAST);
0N/A unsigned char *images = b;
0N/A unsigned char *positions;
0N/A jint bytesPerGlyph;
0N/A if (usePositions) {
0N/A positions = (b + numGlyphs * BYTES_PER_GLYPH_IMAGE);
0N/A bytesPerGlyph = BYTES_PER_POSITIONED_GLYPH;
0N/A } else {
0N/A positions = NULL;
0N/A bytesPerGlyph = BYTES_PER_GLYPH_IMAGE;
0N/A }
0N/A OGLTR_DrawGlyphList(env, oglc, dstOps,
0N/A numGlyphs, usePositions,
0N/A subPixPos, rgbOrder, lcdContrast,
0N/A glyphListOrigX, glyphListOrigY,
0N/A images, positions);
0N/A SKIP_BYTES(b, numGlyphs * bytesPerGlyph);
0N/A }
0N/A break;
0N/A
0N/A // copy-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_COPY_AREA:
0N/A {
0N/A jint x = NEXT_INT(b);
0N/A jint y = NEXT_INT(b);
0N/A jint w = NEXT_INT(b);
0N/A jint h = NEXT_INT(b);
0N/A jint dx = NEXT_INT(b);
0N/A jint dy = NEXT_INT(b);
0N/A OGLBlitLoops_CopyArea(env, oglc, dstOps,
0N/A x, y, w, h, dx, dy);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_BLIT:
0N/A {
0N/A jint packedParams = NEXT_INT(b);
0N/A jint sx1 = NEXT_INT(b);
0N/A jint sy1 = NEXT_INT(b);
0N/A jint sx2 = NEXT_INT(b);
0N/A jint sy2 = NEXT_INT(b);
0N/A jdouble dx1 = NEXT_DOUBLE(b);
0N/A jdouble dy1 = NEXT_DOUBLE(b);
0N/A jdouble dx2 = NEXT_DOUBLE(b);
0N/A jdouble dy2 = NEXT_DOUBLE(b);
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jlong pDst = NEXT_LONG(b);
0N/A jint hint = EXTRACT_BYTE(packedParams, OFFSET_HINT);
0N/A jboolean texture = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_TEXTURE);
0N/A jboolean rtt = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_RTT);
0N/A jboolean xform = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_XFORM);
0N/A jboolean isoblit = EXTRACT_BOOLEAN(packedParams,
0N/A OFFSET_ISOBLIT);
0N/A if (isoblit) {
0N/A OGLBlitLoops_IsoBlit(env, oglc, pSrc, pDst,
0N/A xform, hint, texture, rtt,
0N/A sx1, sy1, sx2, sy2,
0N/A dx1, dy1, dx2, dy2);
0N/A } else {
0N/A jint srctype = EXTRACT_BYTE(packedParams, OFFSET_SRCTYPE);
0N/A OGLBlitLoops_Blit(env, oglc, pSrc, pDst,
0N/A xform, hint, srctype, texture,
0N/A sx1, sy1, sx2, sy2,
0N/A dx1, dy1, dx2, dy2);
0N/A }
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SURFACE_TO_SW_BLIT:
0N/A {
0N/A jint sx = NEXT_INT(b);
0N/A jint sy = NEXT_INT(b);
0N/A jint dx = NEXT_INT(b);
0N/A jint dy = NEXT_INT(b);
0N/A jint w = NEXT_INT(b);
0N/A jint h = NEXT_INT(b);
0N/A jint dsttype = NEXT_INT(b);
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jlong pDst = NEXT_LONG(b);
0N/A OGLBlitLoops_SurfaceToSwBlit(env, oglc,
0N/A pSrc, pDst, dsttype,
0N/A sx, sy, dx, dy, w, h);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_MASK_FILL:
0N/A {
0N/A jint x = NEXT_INT(b);
0N/A jint y = NEXT_INT(b);
0N/A jint w = NEXT_INT(b);
0N/A jint h = NEXT_INT(b);
0N/A jint maskoff = NEXT_INT(b);
0N/A jint maskscan = NEXT_INT(b);
0N/A jint masklen = NEXT_INT(b);
0N/A unsigned char *pMask = (masklen > 0) ? b : NULL;
0N/A OGLMaskFill_MaskFill(oglc, x, y, w, h,
0N/A maskoff, maskscan, masklen, pMask);
0N/A SKIP_BYTES(b, masklen);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_MASK_BLIT:
0N/A {
0N/A jint dstx = NEXT_INT(b);
0N/A jint dsty = NEXT_INT(b);
0N/A jint width = NEXT_INT(b);
0N/A jint height = NEXT_INT(b);
0N/A jint masklen = width * height * sizeof(jint);
0N/A OGLMaskBlit_MaskBlit(env, oglc,
0N/A dstx, dsty, width, height, b);
0N/A SKIP_BYTES(b, masklen);
0N/A }
0N/A break;
0N/A
0N/A // state-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_RECT_CLIP:
0N/A {
0N/A jint x1 = NEXT_INT(b);
0N/A jint y1 = NEXT_INT(b);
0N/A jint x2 = NEXT_INT(b);
0N/A jint y2 = NEXT_INT(b);
0N/A OGLContext_SetRectClip(oglc, dstOps, x1, y1, x2, y2);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_BEGIN_SHAPE_CLIP:
0N/A {
0N/A OGLContext_BeginShapeClip(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_SHAPE_CLIP_SPANS:
0N/A {
0N/A jint count = NEXT_INT(b);
0N/A OGLRenderer_FillSpans(oglc, count, (jint *)b);
0N/A SKIP_BYTES(b, count * BYTES_PER_SPAN);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_END_SHAPE_CLIP:
0N/A {
0N/A OGLContext_EndShapeClip(oglc, dstOps);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_RESET_CLIP:
0N/A {
0N/A OGLContext_ResetClip(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_ALPHA_COMPOSITE:
0N/A {
0N/A jint rule = NEXT_INT(b);
0N/A jfloat extraAlpha = NEXT_FLOAT(b);
0N/A jint flags = NEXT_INT(b);
0N/A OGLContext_SetAlphaComposite(oglc, rule, extraAlpha, flags);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_XOR_COMPOSITE:
0N/A {
0N/A jint xorPixel = NEXT_INT(b);
0N/A OGLContext_SetXorComposite(oglc, xorPixel);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_RESET_COMPOSITE:
0N/A {
0N/A OGLContext_ResetComposite(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_TRANSFORM:
0N/A {
0N/A jdouble m00 = NEXT_DOUBLE(b);
0N/A jdouble m10 = NEXT_DOUBLE(b);
0N/A jdouble m01 = NEXT_DOUBLE(b);
0N/A jdouble m11 = NEXT_DOUBLE(b);
0N/A jdouble m02 = NEXT_DOUBLE(b);
0N/A jdouble m12 = NEXT_DOUBLE(b);
0N/A OGLContext_SetTransform(oglc, m00, m10, m01, m11, m02, m12);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_RESET_TRANSFORM:
0N/A {
0N/A OGLContext_ResetTransform(oglc);
0N/A }
0N/A break;
0N/A
0N/A // context-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_SURFACES:
0N/A {
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jlong pDst = NEXT_LONG(b);
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A }
0N/A oglc = OGLContext_SetSurfaces(env, pSrc, pDst);
0N/A dstOps = (OGLSDOps *)jlong_to_ptr(pDst);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_SCRATCH_SURFACE:
0N/A {
0N/A jlong pConfigInfo = NEXT_LONG(b);
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A }
0N/A oglc = OGLSD_SetScratchSurface(env, pConfigInfo);
0N/A dstOps = NULL;
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_FLUSH_SURFACE:
0N/A {
0N/A jlong pData = NEXT_LONG(b);
0N/A OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
0N/A if (oglsdo != NULL) {
0N/A CONTINUE_IF_NULL(oglc);
0N/A RESET_PREVIOUS_OP();
4632N/A OGLSD_Delete(env, oglsdo);
0N/A }
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DISPOSE_SURFACE:
0N/A {
0N/A jlong pData = NEXT_LONG(b);
0N/A OGLSDOps *oglsdo = (OGLSDOps *)jlong_to_ptr(pData);
0N/A if (oglsdo != NULL) {
0N/A CONTINUE_IF_NULL(oglc);
0N/A RESET_PREVIOUS_OP();
4632N/A OGLSD_Delete(env, oglsdo);
0N/A if (oglsdo->privOps != NULL) {
0N/A free(oglsdo->privOps);
0N/A }
0N/A }
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DISPOSE_CONFIG:
0N/A {
0N/A jlong pConfigInfo = NEXT_LONG(b);
0N/A CONTINUE_IF_NULL(oglc);
0N/A RESET_PREVIOUS_OP();
0N/A OGLGC_DestroyOGLGraphicsConfig(pConfigInfo);
0N/A
0N/A // the previous method will call glX/wglMakeCurrent(None),
0N/A // so we should nullify the current oglc and dstOps to avoid
0N/A // calling glFlush() (or similar) while no context is current
0N/A oglc = NULL;
0N/A dstOps = NULL;
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_INVALIDATE_CONTEXT:
0N/A {
0N/A // flush just in case there are any pending operations in
0N/A // the hardware pipe
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A j2d_glFlush();
0N/A }
0N/A
0N/A // invalidate the references to the current context and
0N/A // destination surface that are maintained at the native level
0N/A oglc = NULL;
0N/A dstOps = NULL;
0N/A }
0N/A break;
430N/A case sun_java2d_pipe_BufferedOpCodes_SAVE_STATE:
430N/A {
430N/A j2d_glPushAttrib(GL_ALL_ATTRIB_BITS);
430N/A j2d_glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
430N/A j2d_glMatrixMode(GL_MODELVIEW);
430N/A j2d_glPushMatrix();
430N/A j2d_glMatrixMode(GL_PROJECTION);
430N/A j2d_glPushMatrix();
430N/A j2d_glMatrixMode(GL_TEXTURE);
430N/A j2d_glPushMatrix();
430N/A }
430N/A break;
430N/A
430N/A case sun_java2d_pipe_BufferedOpCodes_RESTORE_STATE:
430N/A {
430N/A j2d_glPopAttrib();
430N/A j2d_glPopClientAttrib();
430N/A j2d_glMatrixMode(GL_MODELVIEW);
430N/A j2d_glPopMatrix();
430N/A j2d_glMatrixMode(GL_PROJECTION);
430N/A j2d_glPopMatrix();
430N/A j2d_glMatrixMode(GL_TEXTURE);
430N/A j2d_glPopMatrix();
430N/A }
430N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SYNC:
0N/A {
0N/A sync = JNI_TRUE;
0N/A }
0N/A break;
0N/A
0N/A // multibuffering ops
0N/A case sun_java2d_pipe_BufferedOpCodes_SWAP_BUFFERS:
0N/A {
0N/A jlong window = NEXT_LONG(b);
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A }
0N/A OGLSD_SwapBuffers(env, window);
0N/A }
0N/A break;
0N/A
0N/A // special no-op (mainly used for achieving 8-byte alignment)
0N/A case sun_java2d_pipe_BufferedOpCodes_NOOP:
0N/A break;
0N/A
0N/A // paint-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_RESET_PAINT:
0N/A {
0N/A OGLPaints_ResetPaint(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_COLOR:
0N/A {
0N/A jint pixel = NEXT_INT(b);
0N/A OGLPaints_SetColor(oglc, pixel);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_GRADIENT_PAINT:
0N/A {
0N/A jboolean useMask= NEXT_BOOLEAN(b);
0N/A jboolean cyclic = NEXT_BOOLEAN(b);
0N/A jdouble p0 = NEXT_DOUBLE(b);
0N/A jdouble p1 = NEXT_DOUBLE(b);
0N/A jdouble p3 = NEXT_DOUBLE(b);
0N/A jint pixel1 = NEXT_INT(b);
0N/A jint pixel2 = NEXT_INT(b);
0N/A OGLPaints_SetGradientPaint(oglc, useMask, cyclic,
0N/A p0, p1, p3,
0N/A pixel1, pixel2);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_LINEAR_GRADIENT_PAINT:
0N/A {
0N/A jboolean useMask = NEXT_BOOLEAN(b);
0N/A jboolean linear = NEXT_BOOLEAN(b);
0N/A jint cycleMethod = NEXT_INT(b);
0N/A jint numStops = NEXT_INT(b);
0N/A jfloat p0 = NEXT_FLOAT(b);
0N/A jfloat p1 = NEXT_FLOAT(b);
0N/A jfloat p3 = NEXT_FLOAT(b);
0N/A void *fractions, *pixels;
0N/A fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
0N/A pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));
0N/A OGLPaints_SetLinearGradientPaint(oglc, dstOps,
0N/A useMask, linear,
0N/A cycleMethod, numStops,
0N/A p0, p1, p3,
0N/A fractions, pixels);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_RADIAL_GRADIENT_PAINT:
0N/A {
0N/A jboolean useMask = NEXT_BOOLEAN(b);
0N/A jboolean linear = NEXT_BOOLEAN(b);
0N/A jint numStops = NEXT_INT(b);
0N/A jint cycleMethod = NEXT_INT(b);
0N/A jfloat m00 = NEXT_FLOAT(b);
0N/A jfloat m01 = NEXT_FLOAT(b);
0N/A jfloat m02 = NEXT_FLOAT(b);
0N/A jfloat m10 = NEXT_FLOAT(b);
0N/A jfloat m11 = NEXT_FLOAT(b);
0N/A jfloat m12 = NEXT_FLOAT(b);
0N/A jfloat focusX = NEXT_FLOAT(b);
0N/A void *fractions, *pixels;
0N/A fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
0N/A pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));
0N/A OGLPaints_SetRadialGradientPaint(oglc, dstOps,
0N/A useMask, linear,
0N/A cycleMethod, numStops,
0N/A m00, m01, m02,
0N/A m10, m11, m12,
0N/A focusX,
0N/A fractions, pixels);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_SET_TEXTURE_PAINT:
0N/A {
0N/A jboolean useMask= NEXT_BOOLEAN(b);
0N/A jboolean filter = NEXT_BOOLEAN(b);
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jdouble xp0 = NEXT_DOUBLE(b);
0N/A jdouble xp1 = NEXT_DOUBLE(b);
0N/A jdouble xp3 = NEXT_DOUBLE(b);
0N/A jdouble yp0 = NEXT_DOUBLE(b);
0N/A jdouble yp1 = NEXT_DOUBLE(b);
0N/A jdouble yp3 = NEXT_DOUBLE(b);
0N/A OGLPaints_SetTexturePaint(oglc, useMask, pSrc, filter,
0N/A xp0, xp1, xp3,
0N/A yp0, yp1, yp3);
0N/A }
0N/A break;
0N/A
0N/A // BufferedImageOp-related ops
0N/A case sun_java2d_pipe_BufferedOpCodes_ENABLE_CONVOLVE_OP:
0N/A {
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jboolean edgeZero = NEXT_BOOLEAN(b);
0N/A jint kernelWidth = NEXT_INT(b);
0N/A jint kernelHeight = NEXT_INT(b);
0N/A OGLBufImgOps_EnableConvolveOp(oglc, pSrc, edgeZero,
0N/A kernelWidth, kernelHeight, b);
0N/A SKIP_BYTES(b, kernelWidth * kernelHeight * sizeof(jfloat));
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DISABLE_CONVOLVE_OP:
0N/A {
0N/A OGLBufImgOps_DisableConvolveOp(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_ENABLE_RESCALE_OP:
0N/A {
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jboolean nonPremult = NEXT_BOOLEAN(b);
0N/A jint numFactors = 4;
0N/A unsigned char *scaleFactors = b;
0N/A unsigned char *offsets = (b + numFactors * sizeof(jfloat));
0N/A OGLBufImgOps_EnableRescaleOp(oglc, pSrc, nonPremult,
0N/A scaleFactors, offsets);
0N/A SKIP_BYTES(b, numFactors * sizeof(jfloat) * 2);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DISABLE_RESCALE_OP:
0N/A {
0N/A OGLBufImgOps_DisableRescaleOp(oglc);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_ENABLE_LOOKUP_OP:
0N/A {
0N/A jlong pSrc = NEXT_LONG(b);
0N/A jboolean nonPremult = NEXT_BOOLEAN(b);
0N/A jboolean shortData = NEXT_BOOLEAN(b);
0N/A jint numBands = NEXT_INT(b);
0N/A jint bandLength = NEXT_INT(b);
0N/A jint offset = NEXT_INT(b);
0N/A jint bytesPerElem = shortData ? sizeof(jshort):sizeof(jbyte);
0N/A void *tableValues = b;
0N/A OGLBufImgOps_EnableLookupOp(oglc, pSrc, nonPremult, shortData,
0N/A numBands, bandLength, offset,
0N/A tableValues);
0N/A SKIP_BYTES(b, numBands * bandLength * bytesPerElem);
0N/A }
0N/A break;
0N/A case sun_java2d_pipe_BufferedOpCodes_DISABLE_LOOKUP_OP:
0N/A {
0N/A OGLBufImgOps_DisableLookupOp(oglc);
0N/A }
0N/A break;
0N/A
0N/A default:
0N/A J2dRlsTraceLn1(J2D_TRACE_ERROR,
0N/A "OGLRenderQueue_flushBuffer: invalid opcode=%d", opcode);
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A }
0N/A return;
0N/A }
0N/A }
0N/A
0N/A if (oglc != NULL) {
0N/A RESET_PREVIOUS_OP();
0N/A if (sync) {
0N/A j2d_glFinish();
0N/A } else {
0N/A j2d_glFlush();
0N/A }
4632N/A OGLSD_Flush(env);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Returns a pointer to the "current" context, as set by the last SET_SURFACES
0N/A * or SET_SCRATCH_SURFACE operation.
0N/A */
0N/AOGLContext *
0N/AOGLRenderQueue_GetCurrentContext()
0N/A{
0N/A return oglc;
0N/A}
0N/A
0N/A/**
0N/A * Returns a pointer to the "current" destination surface, as set by the last
0N/A * SET_SURFACES operation.
0N/A */
0N/AOGLSDOps *
0N/AOGLRenderQueue_GetCurrentDestination()
0N/A{
0N/A return dstOps;
0N/A}
0N/A
0N/A/**
0N/A * Used to track whether we are within a series of simple primitive operations
0N/A * or texturing operations. The op parameter determines the nature of the
0N/A * operation that is to follow. Valid values for this op parameter are:
0N/A *
0N/A * GL_QUADS
0N/A * GL_LINES
0N/A * GL_LINE_LOOP
0N/A * GL_LINE_STRIP
0N/A * (basically any of the valid parameters for glBegin())
0N/A *
0N/A * GL_TEXTURE_2D
0N/A * GL_TEXTURE_RECTANGLE_ARB
0N/A *
0N/A * OGL_STATE_RESET
0N/A * OGL_STATE_CHANGE
0N/A * OGL_STATE_MASK_OP
0N/A * OGL_STATE_GLYPH_OP
0N/A *
0N/A * Note that the above constants are guaranteed to be unique values. The
0N/A * last few are defined to be negative values to differentiate them from
0N/A * the core GL* constants, which are defined to be non-negative.
0N/A *
0N/A * For simple primitives, this method allows us to batch similar primitives
0N/A * within the same glBegin()/glEnd() pair. For example, if we have 100
0N/A * consecutive FILL_RECT operations, we only have to call glBegin(GL_QUADS)
0N/A * for the first op, and then subsequent operations will consist only of
0N/A * glVertex*() calls, which helps improve performance. The glEnd() call
0N/A * only needs to be issued before an operation that cannot happen within a
0N/A * glBegin()/glEnd() pair (e.g. updating the clip), or one that requires a
0N/A * different primitive mode (e.g. GL_LINES).
0N/A *
0N/A * For operations that involve texturing, this method helps us to avoid
0N/A * calling glEnable(GL_TEXTURE_2D) and glDisable(GL_TEXTURE_2D) around each
0N/A * operation. For example, if we have an alternating series of ISO_BLIT
0N/A * and MASK_BLIT operations (both of which involve texturing), we need
0N/A * only to call glEnable(GL_TEXTURE_2D) before the first ISO_BLIT operation.
0N/A * The glDisable(GL_TEXTURE_2D) call only needs to be issued before an
0N/A * operation that cannot (or should not) happen while texturing is enabled
0N/A * (e.g. a context change, or a simple primitive operation like GL_QUADS).
0N/A */
0N/Avoid
0N/AOGLRenderQueue_CheckPreviousOp(jint op)
0N/A{
0N/A if (previousOp == op) {
0N/A // The op is the same as last time, so we can return immediately.
0N/A return;
0N/A }
0N/A
430N/A J2dTraceLn1(J2D_TRACE_VERBOSE,
430N/A "OGLRenderQueue_CheckPreviousOp: new op=%d", op);
430N/A
0N/A switch (previousOp) {
0N/A case GL_TEXTURE_2D:
0N/A case GL_TEXTURE_RECTANGLE_ARB:
0N/A if (op == OGL_STATE_CHANGE) {
0N/A // Optimization: Certain state changes (those marked as
0N/A // OGL_STATE_CHANGE) are allowed while texturing is enabled.
0N/A // In this case, we can allow previousOp to remain as it is and
0N/A // then return early.
0N/A return;
0N/A } else {
0N/A // Otherwise, op must be a primitive operation, or a reset, so
0N/A // we will disable texturing.
0N/A j2d_glDisable(previousOp);
0N/A // This next step of binding to zero should not be strictly
0N/A // necessary, but on some older Nvidia boards (e.g. GeForce 2)
0N/A // problems will arise if GL_TEXTURE_2D and
0N/A // GL_TEXTURE_RECTANGLE_ARB are bound at the same time, so we
0N/A // will do this just to be safe.
0N/A j2d_glBindTexture(previousOp, 0);
0N/A }
0N/A break;
0N/A case OGL_STATE_MASK_OP:
0N/A OGLVertexCache_DisableMaskCache(oglc);
0N/A break;
0N/A case OGL_STATE_GLYPH_OP:
0N/A OGLTR_DisableGlyphVertexCache(oglc);
0N/A break;
430N/A case OGL_STATE_PGRAM_OP:
430N/A OGLRenderer_DisableAAParallelogramProgram();
430N/A break;
0N/A case OGL_STATE_RESET:
0N/A case OGL_STATE_CHANGE:
0N/A // No-op
0N/A break;
0N/A default:
0N/A // In this case, op must be one of:
0N/A // - the start of a different primitive type (glBegin())
0N/A // - a texturing operation
0N/A // - a state change (not allowed within glBegin()/glEnd() pairs)
0N/A // - a reset
0N/A // so we must first complete the previous primitive operation.
0N/A j2d_glEnd();
0N/A break;
0N/A }
0N/A
0N/A switch (op) {
0N/A case GL_TEXTURE_2D:
0N/A case GL_TEXTURE_RECTANGLE_ARB:
0N/A // We are starting a texturing operation, so enable texturing.
0N/A j2d_glEnable(op);
0N/A break;
0N/A case OGL_STATE_MASK_OP:
0N/A OGLVertexCache_EnableMaskCache(oglc);
0N/A break;
0N/A case OGL_STATE_GLYPH_OP:
0N/A OGLTR_EnableGlyphVertexCache(oglc);
0N/A break;
430N/A case OGL_STATE_PGRAM_OP:
430N/A OGLRenderer_EnableAAParallelogramProgram();
430N/A break;
0N/A case OGL_STATE_RESET:
0N/A case OGL_STATE_CHANGE:
0N/A // No-op
0N/A break;
0N/A default:
0N/A // We are starting a primitive operation, so call glBegin() with
0N/A // the given primitive type.
0N/A j2d_glBegin(op);
0N/A break;
0N/A }
0N/A
0N/A previousOp = op;
0N/A}
0N/A
0N/A#endif /* !HEADLESS */