src/java.desktop/share/native/common/java2d/opengl/OGLBlitLoops.c
author serb
Sun, 19 May 2019 17:20:21 -0700
changeset 58616 be9ef671a1b6
parent 47216 71c04702a3d5
child 58626 a9ed3d93cca3
permissions -rw-r--r--
8221497: Optional Panes in Swing Reviewed-by: prr, alitvinov, mschoene, rhalade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1723
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1723
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1723
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1723
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1723
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "OGLBlitLoops.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "OGLRenderQueue.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "OGLSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
25127
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
    37
#include <stdlib.h> // malloc
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
    38
#include <string.h> // memcpy
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
    39
#include "IntArgbPre.h"
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
extern OGLPixelFormat PixelFormats[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Inner loop used for copying a source OpenGL "Surface" (window, pbuffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * etc.) to a destination OpenGL "Surface".  Note that the same surface can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * be used as both the source and destination, as is the case in a copyArea()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * operation.  This method is invoked from OGLBlitLoops_IsoBlit() as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * OGLBlitLoops_CopyArea().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The standard glCopyPixels() mechanism is used to copy the source region
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * into the destination region.  If the regions have different dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the source will be scaled into the destination as appropriate (only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * nearest neighbor filtering will be applied for simple scale operations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
OGLBlitSurfaceToSurface(OGLContext *oglc, OGLSDOps *srcOps, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                        jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                        jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    GLfloat scalex, scaley;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    jint srcw = sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jint srch = sy2 - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    scalex = ((GLfloat)(dx2-dx1)) / srcw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    scaley = ((GLfloat)(dy2-dy1)) / srch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // the following lines account for the fact that glCopyPixels() copies a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // region whose lower-left corner is at (x,y), but the source parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // (sx1,sy1) we are given here point to the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // source region... so here we play with the sy1 and dy1 parameters so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // that they point to the lower-left corners of the regions...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    sx1 = srcOps->xOffset + sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    sy1 = srcOps->yOffset + srcOps->height - sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    dy1 = dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    if (oglc->extraAlpha != 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        OGLContext_SetExtraAlpha(oglc->extraAlpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // see OGLBlitSwToSurface() for more info on the following two lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    j2d_glRasterPos2i(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    j2d_glBitmap(0, 0, 0, 0, (GLfloat)dx1, (GLfloat)-dy1, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (scalex == 1.0f && scaley == 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        j2d_glCopyPixels(sx1, sy1, srcw, srch, GL_COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        j2d_glPixelZoom(scalex, scaley);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        j2d_glCopyPixels(sx1, sy1, srcw, srch, GL_COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        j2d_glPixelZoom(1.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    if (oglc->extraAlpha != 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        OGLContext_SetExtraAlpha(1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Inner loop used for copying a source OpenGL "Texture" to a destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * OpenGL "Surface".  This method is invoked from OGLBlitLoops_IsoBlit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * This method will copy, scale, or transform the source texture into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * destination depending on the transform state, as established in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * and OGLContext_SetTransform().  If the source texture is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * transformed in any way when rendered into the destination, the filtering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * method applied is determined by the hint parameter (can be GL_NEAREST or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * GL_LINEAR).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
OGLBlitTextureToSurface(OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        OGLSDOps *srcOps, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        jboolean rtt, jint hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                        jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    GLdouble tx1, ty1, tx2, ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    if (rtt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * The source is a render-to-texture surface.  These surfaces differ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * from regular texture objects in that the bottom scanline (of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * the actual image content) coincides with the top edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * texture object.  Therefore, we need to adjust the sy1/sy2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * coordinates relative to the top scanline of the image content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * In texture coordinates, the top-left corner of the image content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * would be at:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         *     (0.0, (imgHeight/texHeight))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * while the bottom-right corner corresponds to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         *     ((imgWidth/texWidth), 0.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        sy1 = srcOps->height - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        sy2 = srcOps->height - sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (srcOps->textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // The GL_ARB_texture_rectangle extension requires that we specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // texture coordinates in the range [0,srcw] and [0,srch] instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // [0,1] as we would normally do in the case of GL_TEXTURE_2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        tx1 = (GLdouble)sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        ty1 = (GLdouble)sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        tx2 = (GLdouble)sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ty2 = (GLdouble)sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // Otherwise we need to convert the source bounds into the range [0,1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        tx1 = ((GLdouble)sx1) / srcOps->textureWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        ty1 = ((GLdouble)sy1) / srcOps->textureHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        tx2 = ((GLdouble)sx2) / srcOps->textureWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        ty2 = ((GLdouble)sy2) / srcOps->textureHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // Note that we call CHECK_PREVIOUS_OP(texTarget) in IsoBlit(), which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // will call glEnable(texTarget) as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    j2d_glBindTexture(srcOps->textureTarget, srcOps->textureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    OGLSD_UPDATE_TEXTURE_FILTER(srcOps, hint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    j2d_glBegin(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    j2d_glTexCoord2d(tx1, ty1); j2d_glVertex2d(dx1, dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    j2d_glTexCoord2d(tx2, ty1); j2d_glVertex2d(dx2, dy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    j2d_glTexCoord2d(tx2, ty2); j2d_glVertex2d(dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    j2d_glTexCoord2d(tx1, ty2); j2d_glVertex2d(dx1, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    j2d_glEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * Inner loop used for copying a source system memory ("Sw") surface to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * destination OpenGL "Surface".  This method is invoked from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * OGLBlitLoops_Blit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * The standard glDrawPixels() mechanism is used to copy the source region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * into the destination region.  If the regions have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * dimensions, the source will be scaled into the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * as appropriate (only nearest neighbor filtering will be applied for simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * scale operations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
OGLBlitSwToSurface(OGLContext *oglc, SurfaceDataRasInfo *srcInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                   OGLPixelFormat *pf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                   jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                   jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    GLfloat scalex, scaley;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    scalex = ((GLfloat)(dx2-dx1)) / (sx2-sx1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    scaley = ((GLfloat)(dy2-dy1)) / (sy2-sy1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    if (oglc->extraAlpha != 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        OGLContext_SetExtraAlpha(oglc->extraAlpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    if (!pf->hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        // if the source surface does not have an alpha channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // we need to ensure that the alpha values are forced to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // the current extra alpha value (see OGLContext_SetExtraAlpha()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // for more information)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        j2d_glPixelTransferf(GL_ALPHA_BIAS, oglc->extraAlpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // This is a rather intriguing (yet totally valid) hack... If we were to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // specify a raster position that is outside the surface bounds, the raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    // position would be invalid and nothing would be rendered.  However, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // can use a widely known trick to move the raster position outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // surface bounds while maintaining its status as valid.  The following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // call to glBitmap() renders a no-op bitmap, but offsets the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // raster position from (0,0) to the desired location of (dx1,-dy1)...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    j2d_glRasterPos2i(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    j2d_glBitmap(0, 0, 0, 0, (GLfloat)dx1, (GLfloat)-dy1, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    j2d_glPixelZoom(scalex, -scaley);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   210
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   211
    GLvoid *pSrc = PtrCoord(srcInfo->rasBase, sx1, srcInfo->pixelStride,
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   212
                                              sy1, srcInfo->scanStride);
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   213
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   214
    // in case pixel stride is not a multiple of scanline stride the copy
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   215
    // has to be done line by line (see 6207877)
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   216
    if (srcInfo->scanStride % srcInfo->pixelStride != 0) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   217
        jint width = sx2-sx1;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   218
        jint height = sy2-sy1;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   219
        while (height > 0) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   220
            j2d_glDrawPixels(width, 1, pf->format, pf->type, pSrc);
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   221
            j2d_glBitmap(0, 0, 0, 0, (GLfloat)0, (GLfloat)-scaley, NULL);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   222
            pSrc = PtrAddBytes(pSrc, srcInfo->scanStride);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   223
            height--;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   224
        }
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   225
    } else {
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   226
        j2d_glDrawPixels(sx2-sx1, sy2-sy1, pf->format, pf->type, pSrc);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   227
    }
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   228
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    j2d_glPixelZoom(1.0, 1.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    if (oglc->extraAlpha != 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        OGLContext_SetExtraAlpha(1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    if (!pf->hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // restore scale/bias to their original values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        j2d_glPixelTransferf(GL_ALPHA_BIAS, 0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * Inner loop used for copying a source system memory ("Sw") surface or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * OpenGL "Surface" to a destination OpenGL "Surface", using an OpenGL texture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * tile as an intermediate surface.  This method is invoked from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * OGLBlitLoops_Blit() for "Sw" surfaces and OGLBlitLoops_IsoBlit() for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * "Surface" surfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * This method is used to transform the source surface into the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * Pixel rectangles cannot be arbitrarily transformed (without the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * GL_EXT_pixel_transform extension, which is not supported on most modern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * hardware).  However, texture mapped quads do respect the GL_MODELVIEW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * transform matrix, so we use textures here to perform the transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * operation.  This method uses a tile-based approach in which a small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * subregion of the source surface is copied into a cached texture tile.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * texture tile is then mapped into the appropriate location in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * destination surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * REMIND: this only works well using GL_NEAREST for the filtering mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 *         (GL_LINEAR causes visible stitching problems between tiles,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *         but this can be fixed by making use of texture borders)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
OGLBlitToSurfaceViaTexture(OGLContext *oglc, SurfaceDataRasInfo *srcInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                           OGLPixelFormat *pf, OGLSDOps *srcOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                           jboolean swsurface, jint hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                           jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                           jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    GLdouble tx1, ty1, tx2, ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    GLdouble dx, dy, dw, dh, cdw, cdh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    jint tw, th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    jint sx, sy, sw, sh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    GLint glhint = (hint == OGLSD_XFORM_BILINEAR) ? GL_LINEAR : GL_NEAREST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    jboolean adjustAlpha = (pf != NULL && !pf->hasAlpha);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   275
    jboolean slowPath;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    if (oglc->blitTextureID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (!OGLContext_InitBlitTileTexture(oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            J2dRlsTraceLn(J2D_TRACE_ERROR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                "OGLBlitToSurfaceViaTexture: could not init blit tile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    tx1 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    ty1 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    tw = OGLC_BLIT_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    th = OGLC_BLIT_TILE_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    cdw = (dx2-dx1) / (((GLdouble)(sx2-sx1)) / OGLC_BLIT_TILE_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    cdh = (dy2-dy1) / (((GLdouble)(sy2-sy1)) / OGLC_BLIT_TILE_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    j2d_glEnable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    j2d_glBindTexture(GL_TEXTURE_2D, oglc->blitTextureID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glhint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glhint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    if (adjustAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // if the source surface does not have an alpha channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // we need to ensure that the alpha values are forced to 1.0f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        j2d_glPixelTransferf(GL_ALPHA_BIAS, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   305
    // in case pixel stride is not a multiple of scanline stride the copy
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   306
    // has to be done line by line (see 6207877)
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   307
    slowPath = srcInfo->scanStride % srcInfo->pixelStride != 0;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   308
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    for (sy = sy1, dy = dy1; sy < sy2; sy += th, dy += cdh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        sh = ((sy + th) > sy2) ? (sy2 - sy) : th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        dh = ((dy + cdh) > dy2) ? (dy2 - dy) : cdh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        for (sx = sx1, dx = dx1; sx < sx2; sx += tw, dx += cdw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            dw = ((dx + cdw) > dx2) ? (dx2 - dx) : cdw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            tx2 = ((GLdouble)sw) / tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            ty2 = ((GLdouble)sh) / th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (swsurface) {
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   321
                GLvoid *pSrc = PtrCoord(srcInfo->rasBase,
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   322
                                        sx, srcInfo->pixelStride,
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   323
                                        sy, srcInfo->scanStride);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   324
                if (slowPath) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   325
                    jint tmph = sh;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   326
                    while (tmph > 0) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   327
                        j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   328
                                            0, sh - tmph, sw, 1,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   329
                                            pf->format, pf->type,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   330
                                            pSrc);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   331
                        pSrc = PtrAddBytes(pSrc, srcInfo->scanStride);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   332
                        tmph--;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   333
                    }
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   334
                } else {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   335
                    j2d_glTexSubImage2D(GL_TEXTURE_2D, 0,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   336
                                        0, 0, sw, sh,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   337
                                        pf->format, pf->type,
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   338
                                        pSrc);
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   339
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                // the texture image is "right side up", so we align the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                // upper-left texture corner with the upper-left quad corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                j2d_glBegin(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                j2d_glTexCoord2d(tx1, ty1); j2d_glVertex2d(dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                j2d_glTexCoord2d(tx2, ty1); j2d_glVertex2d(dx + dw, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                j2d_glTexCoord2d(tx2, ty2); j2d_glVertex2d(dx + dw, dy + dh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                j2d_glTexCoord2d(tx1, ty2); j2d_glVertex2d(dx, dy + dh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                j2d_glEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                // this accounts for lower-left origin of the source region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                jint newsx = srcOps->xOffset + sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                jint newsy = srcOps->yOffset + srcOps->height - (sy + sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                j2d_glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                        0, 0, newsx, newsy, sw, sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                // the texture image is "upside down" after the last step, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                // we align the bottom-left texture corner with the upper-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                // quad corner (and vice versa) to effectively flip the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // texture image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                j2d_glBegin(GL_QUADS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                j2d_glTexCoord2d(tx1, ty2); j2d_glVertex2d(dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                j2d_glTexCoord2d(tx2, ty2); j2d_glVertex2d(dx + dw, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                j2d_glTexCoord2d(tx2, ty1); j2d_glVertex2d(dx + dw, dy + dh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                j2d_glTexCoord2d(tx1, ty1); j2d_glVertex2d(dx, dy + dh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                j2d_glEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    if (adjustAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        // restore scale/bias to their original values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        j2d_glPixelTransferf(GL_ALPHA_BIAS, 0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    j2d_glDisable(GL_TEXTURE_2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * Inner loop used for copying a source system memory ("Sw") surface to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * destination OpenGL "Texture".  This method is invoked from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * OGLBlitLoops_Blit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 * The source surface is effectively loaded into the OpenGL texture object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 * which must have already been initialized by OGLSD_initTexture().  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 * that this method is only capable of copying the source surface into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 * destination surface (i.e. no scaling or general transform is allowed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 * This restriction should not be an issue as this method is only used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
 * currently to cache a static system memory image into an OpenGL texture in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * a hidden-acceleration situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
OGLBlitSwToTexture(SurfaceDataRasInfo *srcInfo, OGLPixelFormat *pf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                   OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                   jint dx1, jint dy1, jint dx2, jint dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
{
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   397
    jboolean adjustAlpha = (pf != NULL && !pf->hasAlpha);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    j2d_glBindTexture(dstOps->textureTarget, dstOps->textureID);
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   399
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   400
    if (adjustAlpha) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   401
        // if the source surface does not have an alpha channel,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   402
        // we need to ensure that the alpha values are forced to 1.0f
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   403
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 0.0f);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   404
        j2d_glPixelTransferf(GL_ALPHA_BIAS, 1.0f);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   405
    }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   406
1723
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   407
    // in case pixel stride is not a multiple of scanline stride the copy
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   408
    // has to be done line by line (see 6207877)
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   409
    if (srcInfo->scanStride % srcInfo->pixelStride != 0) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   410
        jint width = dx2 - dx1;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   411
        jint height = dy2 - dy1;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   412
        GLvoid *pSrc = srcInfo->rasBase;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   413
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   414
        while (height > 0) {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   415
            j2d_glTexSubImage2D(dstOps->textureTarget, 0,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   416
                                dx1, dy2 - height, width, 1,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   417
                                pf->format, pf->type, pSrc);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   418
            pSrc = PtrAddBytes(pSrc, srcInfo->scanStride);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   419
            height--;
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   420
        }
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   421
    } else {
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   422
        j2d_glTexSubImage2D(dstOps->textureTarget, 0,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   423
                            dx1, dy1, dx2-dx1, dy2-dy1,
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   424
                            pf->format, pf->type, srcInfo->rasBase);
4a616c1eac0b 6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents: 2
diff changeset
   425
    }
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   426
    if (adjustAlpha) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   427
        // restore scale/bias to their original values
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   428
        j2d_glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   429
        j2d_glPixelTransferf(GL_ALPHA_BIAS, 0.0f);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents: 12047
diff changeset
   430
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 * General blit method for copying a native OpenGL surface (of type "Surface"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 * or "Texture") to another OpenGL "Surface".  If texture is JNI_TRUE, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 * method will invoke the Texture->Surface inner loop; otherwise, one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
 * Surface->Surface inner loops will be invoked, depending on the transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
 * state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
 * REMIND: we can trick these blit methods into doing XOR simply by passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 *         in the (pixel ^ xorpixel) as the pixel value and preceding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 *         blit with a fillrect...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
OGLBlitLoops_IsoBlit(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                     OGLContext *oglc, jlong pSrcOps, jlong pDstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                     jboolean xform, jint hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                     jboolean texture, jboolean rtt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                     jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                     jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    OGLSDOps *srcOps = (OGLSDOps *)jlong_to_ptr(pSrcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    OGLSDOps *dstOps = (OGLSDOps *)jlong_to_ptr(pDstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    SurfaceDataRasInfo srcInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    jint sw    = sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    jint sh    = sy2 - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    jdouble dw = dx2 - dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    jdouble dh = dy2 - dy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    J2dTraceLn(J2D_TRACE_INFO, "OGLBlitLoops_IsoBlit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    if (sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        J2dTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                   "OGLBlitLoops_IsoBlit: invalid dimensions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    RETURN_IF_NULL(srcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    srcInfo.bounds.x1 = sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    srcInfo.bounds.y1 = sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    srcInfo.bounds.x2 = sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    srcInfo.bounds.y2 = sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    SurfaceData_IntersectBoundsXYXY(&srcInfo.bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                    0, 0, srcOps->width, srcOps->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    if (srcInfo.bounds.x2 > srcInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        srcInfo.bounds.y2 > srcInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (srcInfo.bounds.x1 != sx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            dx1 += (srcInfo.bounds.x1 - sx1) * (dw / sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            sx1 = srcInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (srcInfo.bounds.y1 != sy1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            dy1 += (srcInfo.bounds.y1 - sy1) * (dh / sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            sy1 = srcInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (srcInfo.bounds.x2 != sx2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            dx2 += (srcInfo.bounds.x2 - sx2) * (dw / sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            sx2 = srcInfo.bounds.x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (srcInfo.bounds.y2 != sy2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            dy2 += (srcInfo.bounds.y2 - sy2) * (dh / sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            sy2 = srcInfo.bounds.y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        J2dTraceLn2(J2D_TRACE_VERBOSE, "  texture=%d hint=%d", texture, hint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        J2dTraceLn4(J2D_TRACE_VERBOSE, "  sx1=%d sy1=%d sx2=%d sy2=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    sx1, sy1, sx2, sy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        J2dTraceLn4(J2D_TRACE_VERBOSE, "  dx1=%f dy1=%f dx2=%f dy2=%f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (texture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            GLint glhint = (hint == OGLSD_XFORM_BILINEAR) ? GL_LINEAR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                            GL_NEAREST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            CHECK_PREVIOUS_OP(srcOps->textureTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            OGLBlitTextureToSurface(oglc, srcOps, dstOps, rtt, glhint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                    sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                    dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            jboolean viaTexture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                // we must use the via-texture codepath when there is a xform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                viaTexture = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                // look at the vendor to see which codepath is faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                // (this has been empirically determined; see 5020009)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                switch (OGLC_GET_VENDOR(oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                case OGLC_VENDOR_NVIDIA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    // the via-texture codepath tends to be faster when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    // there is either a simple scale OR an extra alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    viaTexture =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        (sx2-sx1) != (jint)(dx2-dx1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        (sy2-sy1) != (jint)(dy2-dy1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        oglc->extraAlpha != 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                case OGLC_VENDOR_ATI:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    // the via-texture codepath tends to be faster only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    // there is an extra alpha involved (scaling or not)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    viaTexture = (oglc->extraAlpha != 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    // just use the glCopyPixels() codepath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    viaTexture = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            if (viaTexture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                OGLBlitToSurfaceViaTexture(oglc, &srcInfo, NULL, srcOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                           JNI_FALSE, hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                           sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                           dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                OGLBlitSurfaceToSurface(oglc, srcOps, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                        sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                        dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
 * General blit method for copying a system memory ("Sw") surface to a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
 * OpenGL surface (of type "Surface" or "Texture").  If texture is JNI_TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
 * this method will invoke the Sw->Texture inner loop; otherwise, one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
 * Sw->Surface inner loops will be invoked, depending on the transform state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
OGLBlitLoops_Blit(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                  OGLContext *oglc, jlong pSrcOps, jlong pDstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                  jboolean xform, jint hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                  jint srctype, jboolean texture,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                  jint sx1, jint sy1, jint sx2, jint sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                  jdouble dx1, jdouble dy1, jdouble dx2, jdouble dy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    SurfaceDataOps *srcOps = (SurfaceDataOps *)jlong_to_ptr(pSrcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    OGLSDOps *dstOps = (OGLSDOps *)jlong_to_ptr(pDstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    SurfaceDataRasInfo srcInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    OGLPixelFormat pf = PixelFormats[srctype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    jint sw    = sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    jint sh    = sy2 - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    jdouble dw = dx2 - dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    jdouble dh = dy2 - dy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    J2dTraceLn(J2D_TRACE_INFO, "OGLBlitLoops_Blit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    if (sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0 || srctype < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        J2dTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                   "OGLBlitLoops_Blit: invalid dimensions or srctype");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    RETURN_IF_NULL(srcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    srcInfo.bounds.x1 = sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    srcInfo.bounds.y1 = sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    srcInfo.bounds.x2 = sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    srcInfo.bounds.y2 = sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    if (srcOps->Lock(env, srcOps, &srcInfo, SD_LOCK_READ) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        J2dTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                   "OGLBlitLoops_Blit: could not acquire lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    if (srcInfo.bounds.x2 > srcInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        srcInfo.bounds.y2 > srcInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        srcOps->GetRasInfo(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (srcInfo.rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (srcInfo.bounds.x1 != sx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                dx1 += (srcInfo.bounds.x1 - sx1) * (dw / sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                sx1 = srcInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (srcInfo.bounds.y1 != sy1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                dy1 += (srcInfo.bounds.y1 - sy1) * (dh / sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                sy1 = srcInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (srcInfo.bounds.x2 != sx2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                dx2 += (srcInfo.bounds.x2 - sx2) * (dw / sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                sx2 = srcInfo.bounds.x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            if (srcInfo.bounds.y2 != sy2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                dy2 += (srcInfo.bounds.y2 - sy2) * (dh / sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                sy2 = srcInfo.bounds.y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            J2dTraceLn3(J2D_TRACE_VERBOSE, "  texture=%d srctype=%d hint=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        texture, srctype, hint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            J2dTraceLn4(J2D_TRACE_VERBOSE, "  sx1=%d sy1=%d sx2=%d sy2=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                        sx1, sy1, sx2, sy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            J2dTraceLn4(J2D_TRACE_VERBOSE, "  dx1=%f dy1=%f dx2=%f dy2=%f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
58616
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   635
            // Note: we will calculate x/y positions in the raster manually
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   636
            j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
be9ef671a1b6 8221497: Optional Panes in Swing
serb
parents: 47216
diff changeset
   637
            j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                              srcInfo.scanStride / srcInfo.pixelStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, pf.alignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if (texture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                // These coordinates will always be integers since we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                // only ever do a straight copy from sw to texture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                // Thus these casts are "safe" - no loss of precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                OGLBlitSwToTexture(&srcInfo, &pf, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                                   (jint)dx1, (jint)dy1, (jint)dx2, (jint)dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                jboolean viaTexture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                if (xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    // we must use the via-texture codepath when there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    // is a xform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    viaTexture = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    // look at the vendor to see which codepath is faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    // (this has been empirically determined; see 5020009)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    switch (OGLC_GET_VENDOR(oglc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    case OGLC_VENDOR_NVIDIA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                        // the via-texture codepath tends to be faster when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                        // there is either a simple scale OR an extra alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                        viaTexture =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                            (sx2-sx1) != (jint)(dx2-dx1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                            (sy2-sy1) != (jint)(dy2-dy1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                            oglc->extraAlpha != 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        break;
21229
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   666
#ifdef MACOSX
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   667
                    case OGLC_VENDOR_ATI:
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   668
                        // see 8024461
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   669
                        viaTexture = JNI_TRUE;
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   670
                        break;
dfcbcf500680 8024461: [macosx] Java crashed on mac10.9 for swing and 2d function manual test
jchen
parents: 13237
diff changeset
   671
#endif
28076
64c048b63cea 8059944: [OGL] Metrics for a method choice copying of texture should be improved
serb
parents: 26751
diff changeset
   672
                    case OGLC_VENDOR_INTEL:
64c048b63cea 8059944: [OGL] Metrics for a method choice copying of texture should be improved
serb
parents: 26751
diff changeset
   673
                        viaTexture = JNI_TRUE;
64c048b63cea 8059944: [OGL] Metrics for a method choice copying of texture should be improved
serb
parents: 26751
diff changeset
   674
                        break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                        // just use the glDrawPixels() codepath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                        viaTexture = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                if (viaTexture) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    OGLBlitToSurfaceViaTexture(oglc, &srcInfo, &pf, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                               JNI_TRUE, hint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                               sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                               dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    OGLBlitSwToSurface(oglc, &srcInfo, &pf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                                       sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                       dx1, dy1, dx2, dy2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        SurfaceData_InvokeRelease(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
/**
25127
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   703
 * This method makes vertical flip of the provided area of Surface and convert
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   704
 * pixel's data from argbPre to argb format if requested.
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   705
 */
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   706
void flip(void *pDst, juint w, juint h, jint scanStride, jboolean convert) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   707
    const size_t clippedStride = 4 * w;
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   708
    void *tempRow = (h > 1 && !convert) ? malloc(clippedStride) : NULL;
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   709
    juint i = 0;
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   710
    juint step = 0;
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   711
    // vertical flip and convert argbpre to argb if necessary
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   712
    for (; i < h / 2; ++i) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   713
        juint *r1 = PtrAddBytes(pDst, (i * scanStride));
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   714
        juint *r2 = PtrAddBytes(pDst, (h - i - 1) * scanStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   715
        if (tempRow) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   716
            // fast path
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   717
            memcpy(tempRow, r1, clippedStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   718
            memcpy(r1, r2, clippedStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   719
            memcpy(r2, tempRow, clippedStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   720
        } else {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   721
            // slow path
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   722
            for (step = 0; step < w; ++step) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   723
                juint tmp = r1[step];
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   724
                if (convert) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   725
                    LoadIntArgbPreTo1IntArgb(r2, 0, step, r1[step]);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   726
                    LoadIntArgbPreTo1IntArgb(&tmp, 0, 0, r2[step]);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   727
                } else {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   728
                    r1[step] = r2[step];
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   729
                    r2[step] = tmp;
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   730
                }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   731
            }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   732
        }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   733
    }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   734
    // convert the middle line if necessary
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   735
    if (convert && h % 2) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   736
        juint *r1 = PtrAddBytes(pDst, (i * scanStride));
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   737
        for (step = 0; step < w; ++step) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   738
            LoadIntArgbPreTo1IntArgb(r1, 0, step, r1[step]);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   739
        }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   740
    }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   741
    if (tempRow) {
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   742
        free(tempRow);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   743
    }
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   744
}
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   745
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   746
/**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
 * Specialized blit method for copying a native OpenGL "Surface" (pbuffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
 * window, etc.) to a system memory ("Sw") surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
OGLBlitLoops_SurfaceToSwBlit(JNIEnv *env, OGLContext *oglc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                             jlong pSrcOps, jlong pDstOps, jint dsttype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                             jint srcx, jint srcy, jint dstx, jint dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                             jint width, jint height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    OGLSDOps *srcOps = (OGLSDOps *)jlong_to_ptr(pSrcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    SurfaceDataOps *dstOps = (SurfaceDataOps *)jlong_to_ptr(pDstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    SurfaceDataRasInfo srcInfo, dstInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    OGLPixelFormat pf = PixelFormats[dsttype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    J2dTraceLn(J2D_TRACE_INFO, "OGLBlitLoops_SurfaceToSwBlit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    if (width <= 0 || height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        J2dTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            "OGLBlitLoops_SurfaceToSwBlit: dimensions are non-positive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    RETURN_IF_NULL(srcOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    srcInfo.bounds.x1 = srcx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    srcInfo.bounds.y1 = srcy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    srcInfo.bounds.x2 = srcx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    srcInfo.bounds.y2 = srcy + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    dstInfo.bounds.x1 = dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    dstInfo.bounds.y1 = dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    dstInfo.bounds.x2 = dstx + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    dstInfo.bounds.y2 = dsty + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    if (dstOps->Lock(env, dstOps, &dstInfo, SD_LOCK_WRITE) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        J2dTraceLn(J2D_TRACE_WARNING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            "OGLBlitLoops_SurfaceToSwBlit: could not acquire dst lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    SurfaceData_IntersectBoundsXYXY(&srcInfo.bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                    0, 0, srcOps->width, srcOps->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    SurfaceData_IntersectBlitBounds(&dstInfo.bounds, &srcInfo.bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                    srcx - dstx, srcy - dsty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    if (srcInfo.bounds.x2 > srcInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        srcInfo.bounds.y2 > srcInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        dstOps->GetRasInfo(env, dstOps, &dstInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (dstInfo.rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            void *pDst = dstInfo.rasBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            srcx = srcInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            srcy = srcInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            dstx = dstInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            dsty = dstInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            width = srcInfo.bounds.x2 - srcInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            height = srcInfo.bounds.y2 - srcInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
25127
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   808
            pDst = PtrAddBytes(pDst, dstx * dstInfo.pixelStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   809
            pDst = PtrAddBytes(pDst, dsty * dstInfo.scanStride);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   810
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            j2d_glPixelStorei(GL_PACK_ROW_LENGTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                              dstInfo.scanStride / dstInfo.pixelStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            j2d_glPixelStorei(GL_PACK_ALIGNMENT, pf.alignment);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   814
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   815
            if (srcOps->isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   816
                // For some reason Apple's OpenGL implementation will
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   817
                // read back zero values from the alpha channel of an
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   818
                // opaque surface when using glReadPixels(), so here we
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   819
                // force the resulting pixels to be fully opaque.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   820
                j2d_glPixelTransferf(GL_ALPHA_BIAS, 1.0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   821
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   822
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            J2dTraceLn4(J2D_TRACE_VERBOSE, "  sx=%d sy=%d w=%d h=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                        srcx, srcy, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            J2dTraceLn2(J2D_TRACE_VERBOSE, "  dx=%d dy=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                        dstx, dsty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            // this accounts for lower-left origin of the source region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            srcx = srcOps->xOffset + srcx;
25127
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   831
            srcy = srcOps->yOffset + srcOps->height - srcy - height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
25127
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   833
            // Note that glReadPixels() is extremely slow!
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   834
            // So we call it only once and flip the image using memcpy.
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   835
            j2d_glReadPixels(srcx, srcy, width, height,
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   836
                             pf.format, pf.type, pDst);
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   837
            // It was checked above that width and height are positive.
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   838
            flip(pDst, (juint) width, (juint) height, dstInfo.scanStride,
e92fa066b0e0 8041129: [OGL] surface->sw blit is extremely slow
serb
parents: 23010
diff changeset
   839
                 !pf.isPremult && !srcOps->isOpaque);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   840
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   841
            if (srcOps->isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   842
                j2d_glPixelTransferf(GL_ALPHA_BIAS, 0.0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   843
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   844
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            j2d_glPixelStorei(GL_PACK_ROW_LENGTH, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            j2d_glPixelStorei(GL_PACK_ALIGNMENT, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        SurfaceData_InvokeRelease(env, dstOps, &dstInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
OGLBlitLoops_CopyArea(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                      OGLContext *oglc, OGLSDOps *dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                      jint x, jint y, jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                      jint dx, jint dy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    SurfaceDataBounds srcBounds, dstBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    J2dTraceLn(J2D_TRACE_INFO, "OGLBlitLoops_CopyArea");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    RETURN_IF_NULL(oglc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    RETURN_IF_NULL(dstOps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    RESET_PREVIOUS_OP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    J2dTraceLn4(J2D_TRACE_VERBOSE, "  x=%d y=%d w=%d h=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    J2dTraceLn2(J2D_TRACE_VERBOSE, "  dx=%d dy=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    srcBounds.x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    srcBounds.y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    srcBounds.x2 = srcBounds.x1 + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    srcBounds.y2 = srcBounds.y1 + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    dstBounds.x1 = x + dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    dstBounds.y1 = y + dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    dstBounds.x2 = dstBounds.x1 + width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    dstBounds.y2 = dstBounds.y1 + height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    // 6430601: manually clip src/dst parameters to work around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    // some bugs in Sun's and Apple's OpenGL implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    // (it's a good idea to restrict the source parameters anyway, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    // passing out of range parameters to glCopyPixels() will result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    // an OpenGL error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    SurfaceData_IntersectBoundsXYXY(&srcBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                    0, 0, dstOps->width, dstOps->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    SurfaceData_IntersectBoundsXYXY(&dstBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                    0, 0, dstOps->width, dstOps->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    SurfaceData_IntersectBlitBounds(&dstBounds, &srcBounds, -dx, -dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    if (dstBounds.x1 < dstBounds.x2 && dstBounds.y1 < dstBounds.y2) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   893
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   894
        if (dstOps->isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   895
            // For some reason Apple's OpenGL implementation will fail
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   896
            // to render glCopyPixels() when the src/dst rectangles are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   897
            // overlapping and glColorMask() has disabled writes to the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   898
            // alpha channel.  The workaround is to temporarily re-enable
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   899
            // the alpha channel during the glCopyPixels() operation.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   900
            j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   901
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   902
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   903
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        OGLBlitSurfaceToSurface(oglc, dstOps, dstOps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                                srcBounds.x1, srcBounds.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                                srcBounds.x2, srcBounds.y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                dstBounds.x1, dstBounds.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                dstBounds.x2, dstBounds.y2);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   909
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   910
        if (dstOps->isOpaque) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   911
            j2d_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   912
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   913
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
#endif /* !HEADLESS */