jdk/src/share/native/sun/java2d/loops/DrawRect.c
author flar
Mon, 06 Dec 2010 21:45:48 -0800
changeset 7487 9b031d062ede
parent 5506 202f599c92aa
permissions -rw-r--r--
6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines Reviewed-by: jgodinez, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2001, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "LineUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_java2d_loops_DrawRect.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Class:     sun_java2d_loops_DrawRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Method:    DrawRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IIII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
Java_sun_java2d_loops_DrawRect_DrawRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    (JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     jobject sg2d, jobject sData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     jint x, jint y, jint w, jint h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    SurfaceDataOps *sdOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    SurfaceDataRasInfo rasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    NativePrimitive *pPrim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    CompositeInfo compInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    jint lox, loy, hix, hiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    if (w < 0 || h < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    pPrim = GetNativePrim(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    if (pPrim == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    if (pPrim->pCompType->getCompInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    sdOps = SurfaceData_GetOps(env, sData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    if (sdOps == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    lox = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    loy = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    hix = x + w + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    hiy = y + h + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    if (hix < lox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        hix = 0x7fffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    if (hiy < loy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        hiy = 0x7fffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    if (rasInfo.bounds.x1 < lox) rasInfo.bounds.x1 = lox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (rasInfo.bounds.y1 < loy) rasInfo.bounds.y1 = loy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    if (rasInfo.bounds.x2 > hix) rasInfo.bounds.x2 = hix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (rasInfo.bounds.y2 > hiy) rasInfo.bounds.y2 = hiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        rasInfo.bounds.y2 > rasInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        sdOps->GetRasInfo(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (rasInfo.rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            DrawLineFunc *pLine = pPrim->funcs.drawline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            int loyin = (loy == rasInfo.bounds.y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            int hiyin = (hiy == rasInfo.bounds.y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            int xsize = (rasInfo.bounds.x2 - rasInfo.bounds.x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            int ysize = (rasInfo.bounds.y2 - rasInfo.bounds.y1 - loyin - hiyin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
             * To avoid drawing the corners twice (both for performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
             * and because XOR erases them otherwise) and to maximize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
             * number of pixels we draw in the horizontal portions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
             * which are more cache-friendly, we include the corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
             * pixels only in the top and bottom segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
             * We also protect against degenerate rectangles where we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
             * would draw the same line for top & bottom or left & right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (loyin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                /* Line across the top */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                (*pLine)(&rasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                         rasInfo.bounds.x1, rasInfo.bounds.y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                         pixel, xsize, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                         BUMP_POS_PIXEL, 0, BUMP_NOOP, 0, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (lox == rasInfo.bounds.x1 && ysize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                /* Line down the left side */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                (*pLine)(&rasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                         rasInfo.bounds.x1, rasInfo.bounds.y1 + loyin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                         pixel, ysize, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                         BUMP_POS_SCAN, 0, BUMP_NOOP, 0, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (hix == rasInfo.bounds.x2 && ysize > 0 && lox != hix - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                /* Line down the right side */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                (*pLine)(&rasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                         rasInfo.bounds.x2 - 1, rasInfo.bounds.y1 + loyin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                         pixel, ysize, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                         BUMP_POS_SCAN, 0, BUMP_NOOP, 0, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (hiyin && loy != hiy - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                /* Line across the bottom */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                (*pLine)(&rasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                         rasInfo.bounds.x1, rasInfo.bounds.y2 - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                         pixel, xsize, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                         BUMP_POS_PIXEL, 0, BUMP_NOOP, 0, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}