Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DRenderer.cpp
32288 views
/*1* Copyright (c) 2007, 2008, 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 "D3DPipeline.h"2627#include "sun_java2d_d3d_D3DRenderer.h"2829#include "D3DContext.h"30#include "D3DRenderer.h"31#include "D3DRenderQueue.h"3233HRESULT D3DPIPELINE_API34D3DRenderer_DrawLine(D3DContext *d3dc,35jint x1, jint y1, jint x2, jint y2)36{37J2dTraceLn4(J2D_TRACE_INFO,38"D3DRenderer_doDrawLineD3D x1=%-4d y1=%-4d x2=%-4d y2=%-4d",39x1, y1, x2, y2);40d3dc->BeginScene(STATE_RENDEROP);41return d3dc->pVCacher->DrawLine(x1, y1, x2, y2);42}4344HRESULT D3DPIPELINE_API45D3DRenderer_DrawRect(D3DContext *d3dc,46jint x, jint y, jint w, jint h)47{48J2dTraceLn4(J2D_TRACE_INFO,49"D3DRenderer_DrawRect x=%-4d y=%-4d w=%-4d h=%-4d",50x, y, w, h);5152d3dc->BeginScene(STATE_RENDEROP);53return d3dc->pVCacher->DrawRect(x, y, x + w, y + h);54}5556HRESULT D3DPIPELINE_API57D3DRenderer_FillRect(D3DContext *d3dc,58jint x, jint y, jint w, jint h)59{60J2dTraceLn4(J2D_TRACE_INFO,61"D3DRenderer_FillRect x=%-4d y=%-4d w=%-4d h=%-4d",62x, y, w, h);6364d3dc->BeginScene(STATE_RENDEROP);65return d3dc->pVCacher->FillRect(x, y, x + w, y + h);66}6768HRESULT D3DPIPELINE_API69D3DRenderer_DrawPoly(D3DContext *d3dc,70jint nPoints, jboolean isClosed,71jint transX, jint transY,72jint *xPoints, jint *yPoints)73{74J2dTraceLn(J2D_TRACE_INFO, "D3DRenderer_DrawPoly");7576if (d3dc == NULL || xPoints == NULL || yPoints == NULL) {77J2dRlsTraceLn(J2D_TRACE_ERROR,78"D3DRenderer_DrawPoly: d3dc, xPoints or yPoints is NULL");79return E_FAIL;80}8182d3dc->BeginScene(STATE_RENDEROP);83return d3dc->pVCacher->DrawPoly(nPoints, isClosed, transX, transY,84xPoints, yPoints);85}8687HRESULT D3DPIPELINE_API88D3DRenderer_DrawScanlines(D3DContext *d3dc,89jint scanlineCount, jint *scanlines)90{91J2dTraceLn(J2D_TRACE_INFO, "D3DRenderer_DrawScanlines");9293if (d3dc == NULL) {94return E_FAIL;95}96if (scanlines == NULL || scanlineCount <= 0) {97return D3D_OK;98}99100d3dc->BeginScene(STATE_RENDEROP);101return d3dc->pVCacher->DrawScanlines(scanlineCount, scanlines);102}103104HRESULT D3DPIPELINE_API105D3DRenderer_FillSpans(D3DContext *d3dc, jint spanCount, jint *spans)106{107J2dTraceLn(J2D_TRACE_INFO, "D3DRenderer_FillSpans");108if (d3dc == NULL) {109return E_FAIL;110}111112d3dc->BeginScene(STATE_RENDEROP);113return d3dc->pVCacher->FillSpans(spanCount, spans);114}115116HRESULT D3DPIPELINE_API117D3DRenderer_FillParallelogram(D3DContext *d3dc,118jfloat fx11, jfloat fy11,119jfloat dx21, jfloat dy21,120jfloat dx12, jfloat dy12)121{122J2dTraceLn6(J2D_TRACE_INFO,123"D3DRenderer_FillParallelogram "124"x=%6.2f y=%6.2f "125"dx1=%6.2f dy1=%6.2f "126"dx2=%6.2f dy2=%6.2f ",127fx11, fy11,128dx21, dy21,129dx12, dy12);130131d3dc->BeginScene(STATE_RENDEROP);132return d3dc->pVCacher->FillParallelogram(fx11, fy11,133dx21, dy21,134dx12, dy12);135}136137HRESULT D3DPIPELINE_API138D3DRenderer_DrawParallelogram(D3DContext *d3dc,139jfloat fx11, jfloat fy11,140jfloat dx21, jfloat dy21,141jfloat dx12, jfloat dy12,142jfloat lwr21, jfloat lwr12)143{144HRESULT res;145146J2dTraceLn8(J2D_TRACE_INFO,147"D3DRenderer_DrawParallelogram "148"x=%6.2f y=%6.2f "149"dx1=%6.2f dy1=%6.2f lwr1=%6.2f "150"dx2=%6.2f dy2=%6.2f lwr2=%6.2f ",151fx11, fy11,152dx21, dy21, lwr21,153dx12, dy12, lwr12);154155// dx,dy for line width in the "21" and "12" directions.156jfloat ldx21 = dx21 * lwr21;157jfloat ldy21 = dy21 * lwr21;158jfloat ldx12 = dx12 * lwr12;159jfloat ldy12 = dy12 * lwr12;160161// calculate origin of the outer parallelogram162jfloat ox11 = fx11 - (ldx21 + ldx12) / 2.0f;163jfloat oy11 = fy11 - (ldy21 + ldy12) / 2.0f;164165res = d3dc->BeginScene(STATE_RENDEROP);166RETURN_STATUS_IF_FAILED(res);167168// Only need to generate 4 quads if the interior still169// has a hole in it (i.e. if the line width ratio was170// less than 1.0)171if (lwr21 < 1.0f && lwr12 < 1.0f) {172// Note: "TOP", "BOTTOM", "LEFT" and "RIGHT" here are173// relative to whether the dxNN variables are positive174// and negative. The math works fine regardless of175// their signs, but for conceptual simplicity the176// comments will refer to the sides as if the dxNN177// were all positive. "TOP" and "BOTTOM" segments178// are defined by the dxy21 deltas. "LEFT" and "RIGHT"179// segments are defined by the dxy12 deltas.180181// Each segment includes its starting corner and comes182// to just short of the following corner. Thus, each183// corner is included just once and the only lengths184// needed are the original parallelogram delta lengths185// and the "line width deltas". The sides will cover186// the following relative territories:187//188// T T T T T R189// L R190// L R191// L R192// L R193// L B B B B B194195// TOP segment, to left side of RIGHT edge196// "width" of original pgram, "height" of hor. line size197fx11 = ox11;198fy11 = oy11;199res = d3dc->pVCacher->FillParallelogram(fx11, fy11,200dx21, dy21,201ldx12, ldy12);202203// RIGHT segment, to top of BOTTOM edge204// "width" of vert. line size , "height" of original pgram205fx11 = ox11 + dx21;206fy11 = oy11 + dy21;207res = d3dc->pVCacher->FillParallelogram(fx11, fy11,208ldx21, ldy21,209dx12, dy12);210211// BOTTOM segment, from right side of LEFT edge212// "width" of original pgram, "height" of hor. line size213fx11 = ox11 + dx12 + ldx21;214fy11 = oy11 + dy12 + ldy21;215res = d3dc->pVCacher->FillParallelogram(fx11, fy11,216dx21, dy21,217ldx12, ldy12);218219// LEFT segment, from bottom of TOP edge220// "width" of vert. line size , "height" of inner pgram221fx11 = ox11 + ldx12;222fy11 = oy11 + ldy12;223res = d3dc->pVCacher->FillParallelogram(fx11, fy11,224ldx21, ldy21,225dx12, dy12);226} else {227// The line width ratios were large enough to consume228// the entire hole in the middle of the parallelogram229// so we can just issue one large quad for the outer230// parallelogram.231dx21 += ldx21;232dy21 += ldy21;233dx12 += ldx12;234dy12 += ldy12;235236res = d3dc->pVCacher->FillParallelogram(ox11, oy11,237dx21, dy21,238dx12, dy12);239}240241return res;242}243244HRESULT D3DPIPELINE_API245D3DRenderer_FillAAParallelogram(D3DContext *d3dc,246jfloat fx11, jfloat fy11,247jfloat dx21, jfloat dy21,248jfloat dx12, jfloat dy12)249{250IDirect3DDevice9 *pd3dDevice;251HRESULT res;252253J2dTraceLn6(J2D_TRACE_INFO,254"D3DRenderer_FillAAParallelogram "255"x=%6.2f y=%6.2f "256"dx1=%6.2f dy1=%6.2f "257"dx2=%6.2f dy2=%6.2f ",258fx11, fy11,259dx21, dy21,260dx12, dy12);261262res = d3dc->BeginScene(STATE_AAPGRAMOP);263RETURN_STATUS_IF_FAILED(res);264265pd3dDevice = d3dc->Get3DDevice();266if (pd3dDevice == NULL) {267return E_FAIL;268}269270res = d3dc->pVCacher->FillParallelogramAA(fx11, fy11,271dx21, dy21,272dx12, dy12);273return res;274}275276HRESULT D3DPIPELINE_API277D3DRenderer_DrawAAParallelogram(D3DContext *d3dc,278jfloat fx11, jfloat fy11,279jfloat dx21, jfloat dy21,280jfloat dx12, jfloat dy12,281jfloat lwr21, jfloat lwr12)282{283IDirect3DDevice9 *pd3dDevice;284// dx,dy for line width in the "21" and "12" directions.285jfloat ldx21, ldy21, ldx12, ldy12;286// parameters for "outer" parallelogram287jfloat ofx11, ofy11, odx21, ody21, odx12, ody12;288// parameters for "inner" parallelogram289jfloat ifx11, ify11, idx21, idy21, idx12, idy12;290HRESULT res;291292J2dTraceLn8(J2D_TRACE_INFO,293"D3DRenderer_DrawAAParallelogram "294"x=%6.2f y=%6.2f "295"dx1=%6.2f dy1=%6.2f lwr1=%6.2f "296"dx2=%6.2f dy2=%6.2f lwr2=%6.2f ",297fx11, fy11,298dx21, dy21, lwr21,299dx12, dy12, lwr12);300301res = d3dc->BeginScene(STATE_AAPGRAMOP);302RETURN_STATUS_IF_FAILED(res);303304pd3dDevice = d3dc->Get3DDevice();305if (pd3dDevice == NULL) {306return E_FAIL;307}308309// calculate true dx,dy for line widths from the "line width ratios"310ldx21 = dx21 * lwr21;311ldy21 = dy21 * lwr21;312ldx12 = dx12 * lwr12;313ldy12 = dy12 * lwr12;314315// calculate coordinates of the outer parallelogram316ofx11 = fx11 - (ldx21 + ldx12) / 2.0f;317ofy11 = fy11 - (ldy21 + ldy12) / 2.0f;318odx21 = dx21 + ldx21;319ody21 = dy21 + ldy21;320odx12 = dx12 + ldx12;321ody12 = dy12 + ldy12;322323// Only process the inner parallelogram if the line width ratio324// did not consume the entire interior of the parallelogram325// (i.e. if the width ratio was less than 1.0)326if (lwr21 < 1.0f && lwr12 < 1.0f) {327// calculate coordinates of the inner parallelogram328ifx11 = fx11 + (ldx21 + ldx12) / 2.0f;329ify11 = fy11 + (ldy21 + ldy12) / 2.0f;330idx21 = dx21 - ldx21;331idy21 = dy21 - ldy21;332idx12 = dx12 - ldx12;333idy12 = dy12 - ldy12;334335res = d3dc->pVCacher->DrawParallelogramAA(ofx11, ofy11,336odx21, ody21,337odx12, ody12,338ifx11, ify11,339idx21, idy21,340idx12, idy12);341} else {342// Just invoke a regular fill on the outer parallelogram343res = d3dc->pVCacher->FillParallelogramAA(ofx11, ofy11,344odx21, ody21,345odx12, ody12);346}347348return res;349}350351#ifndef D3D_PPL_DLL352353extern "C"354{355356JNIEXPORT void JNICALL357Java_sun_java2d_d3d_D3DRenderer_drawPoly358(JNIEnv *env, jobject d3dr,359jintArray xpointsArray, jintArray ypointsArray,360jint nPoints, jboolean isClosed,361jint transX, jint transY)362{363jint *xPoints, *yPoints;364365J2dTraceLn(J2D_TRACE_INFO, "D3DRenderer_drawPoly");366367xPoints = (jint *)env->GetPrimitiveArrayCritical(xpointsArray, NULL);368if (xPoints != NULL) {369yPoints = (jint *)env->GetPrimitiveArrayCritical(ypointsArray, NULL);370if (yPoints != NULL) {371D3DContext *d3dc = D3DRQ_GetCurrentContext();372373D3DRenderer_DrawPoly(d3dc,374nPoints, isClosed,375transX, transY,376xPoints, yPoints);377378if (d3dc != NULL) {379HRESULT res = d3dc->EndScene();380D3DRQ_MarkLostIfNeeded(res,381D3DRQ_GetCurrentDestination());382}383env->ReleasePrimitiveArrayCritical(ypointsArray, yPoints, JNI_ABORT);384}385env->ReleasePrimitiveArrayCritical(xpointsArray, xPoints, JNI_ABORT);386}387}388389}390391#endif // D3D_PPL_DLL392393394