Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/BlitBg.c
41159 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "GraphicsPrimitiveMgr.h"26#include "Region.h"2728#include "sun_java2d_loops_BlitBg.h"2930/*31* Class: sun_java2d_loops_BlitBg32* Method: BlitBg33* Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;Ljava/awt/Composite;IIIIIII)V34*/35JNIEXPORT void JNICALL Java_sun_java2d_loops_BlitBg_BlitBg36(JNIEnv *env, jobject self,37jobject srcData, jobject dstData,38jobject comp, jobject clip, jint bgColor,39jint srcx, jint srcy, jint dstx, jint dsty, jint width, jint height)40{41SurfaceDataOps *srcOps;42SurfaceDataOps *dstOps;43SurfaceDataRasInfo srcInfo;44SurfaceDataRasInfo dstInfo;45NativePrimitive *pPrim;46CompositeInfo compInfo;47RegionData clipInfo;48jint dstFlags;4950pPrim = GetNativePrim(env, self);51if (pPrim == NULL) {52return;53}54if (pPrim->pCompType->getCompInfo != NULL) {55(*pPrim->pCompType->getCompInfo)(env, &compInfo, comp);56}57if (Region_GetInfo(env, clip, &clipInfo)) {58return;59}6061srcOps = SurfaceData_GetOps(env, srcData);62if (srcOps == 0) {63return;64}65dstOps = SurfaceData_GetOps(env, dstData);66if (dstOps == 0) {67return;68}6970srcInfo.bounds.x1 = srcx;71srcInfo.bounds.y1 = srcy;72srcInfo.bounds.x2 = srcx + width;73srcInfo.bounds.y2 = srcy + height;74dstInfo.bounds.x1 = dstx;75dstInfo.bounds.y1 = dsty;76dstInfo.bounds.x2 = dstx + width;77dstInfo.bounds.y2 = dsty + height;78srcx -= dstx;79srcy -= dsty;80SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);81if (srcOps->Lock(env, srcOps, &srcInfo, pPrim->srcflags) != SD_SUCCESS) {82return;83}8485dstFlags = pPrim->dstflags;86if (!Region_IsRectangular(&clipInfo)) {87dstFlags |= SD_LOCK_PARTIAL_WRITE;88}89if (dstOps->Lock(env, dstOps, &dstInfo, dstFlags) != SD_SUCCESS) {90SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);91return;92}93SurfaceData_IntersectBlitBounds(&dstInfo.bounds, &srcInfo.bounds,94srcx, srcy);95Region_IntersectBounds(&clipInfo, &dstInfo.bounds);9697if (!Region_IsEmpty(&clipInfo)) {98jint bgpixel = bgColor;99srcOps->GetRasInfo(env, srcOps, &srcInfo);100dstOps->GetRasInfo(env, dstOps, &dstInfo);101if (pPrim->pDstType->pixelFor) {102bgpixel = (*pPrim->pDstType->pixelFor)(&dstInfo, bgpixel);103}104if (srcInfo.rasBase && dstInfo.rasBase) {105SurfaceDataBounds span;106jint savesx = srcInfo.bounds.x1;107jint savedx = dstInfo.bounds.x1;108Region_StartIteration(env, &clipInfo);109while (Region_NextIteration(&clipInfo, &span)) {110void *pSrc = PtrCoord(srcInfo.rasBase,111srcx + span.x1, srcInfo.pixelStride,112srcy + span.y1, srcInfo.scanStride);113void *pDst = PtrCoord(dstInfo.rasBase,114span.x1, dstInfo.pixelStride,115span.y1, dstInfo.scanStride);116/*117* Fix for 4804375118* REMIND: There should probably be a better119* way to give the span coordinates to the120* inner loop. This is only really needed121* for the 1, 2, and 4 bit loops.122*/123srcInfo.bounds.x1 = srcx + span.x1;124dstInfo.bounds.x1 = span.x1;125(*pPrim->funcs.blitbg)(pSrc, pDst,126span.x2 - span.x1, span.y2 - span.y1,127bgpixel,128&srcInfo, &dstInfo, pPrim, &compInfo);129}130Region_EndIteration(env, &clipInfo);131srcInfo.bounds.x1 = savesx;132dstInfo.bounds.x1 = savedx;133}134SurfaceData_InvokeRelease(env, dstOps, &dstInfo);135SurfaceData_InvokeRelease(env, srcOps, &srcInfo);136}137SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);138SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);139}140141142