Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/java2d/d3d/D3DRenderQueue.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"26#include <malloc.h>27#include "sun_java2d_pipe_BufferedOpCodes.h"2829#include "jlong.h"30#include "D3DBlitLoops.h"31#include "D3DBufImgOps.h"32#include "D3DPipelineManager.h"33#include "D3DContext.h"34#include "D3DMaskBlit.h"35#include "D3DMaskFill.h"36#include "D3DPaints.h"37#include "D3DRenderQueue.h"38#include "D3DRenderer.h"39#include "D3DSurfaceData.h"40#include "D3DTextRenderer.h"41#include "Trace.h"42#include "awt_Toolkit.h"4344BOOL DWMIsCompositionEnabled();4546/**47* References to the "current" context and destination surface.48*/49static D3DContext *d3dc = NULL;50static D3DSDOps *dstOps = NULL;51static BOOL bLostDevices = FALSE;5253typedef struct {54byte *buffer;55int limit;56jobject runnable;57} FlushBufferStruct;5859HRESULT60D3DRQ_SwapBuffers(D3DPipelineManager *pMgr, D3DSDOps *d3dsdo,61int x1, int y1, int x2, int y2)62{63HRESULT res;64D3DContext *pCtx;65IDirect3DSwapChain9 *pSwapChain;66RECT srcRect, dstRect, *pSrcRect, *pDstRect;6768J2dTraceLn(J2D_TRACE_INFO, "D3DRQ_SwapBuffers");69J2dTraceLn4(J2D_TRACE_VERBOSE, " x1=%d y1=%d x2=%d y2=%d",70x1, y1, x2, y2);7172RETURN_STATUS_IF_NULL(d3dsdo, E_FAIL);73RETURN_STATUS_IF_NULL(d3dsdo->pResource, E_FAIL);74RETURN_STATUS_IF_NULL(pSwapChain=d3dsdo->pResource->GetSwapChain(), E_FAIL);7576pCtx = D3DRQ_GetCurrentContext();77if (pCtx != NULL) {78// flush the current vertex queue here, just in case79res = d3dc->FlushVertexQueue();80D3DRQ_MarkLostIfNeeded(res, dstOps);81pCtx = NULL;82}83// end scene for this destination84res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx);85RETURN_STATUS_IF_FAILED(res);8687pCtx->EndScene();8889// This is a workaround for what apparently is a DWM bug.90// If the dimensions of the back-buffer don't match the dimensions of91// the window, Present() will flash the whole window with black.92// The workaround is to detect this situation and not do a present.93// It is ok to do so since a repaint event is coming due to the resize that94// just happened.95//96// REMIND: this will need to be updated if we switch to creating97// back-buffers of the size of the client area instead of the whole window98// (use GetClientRect() instead of GetWindowRect()).99if (DWMIsCompositionEnabled()) {100RECT r;101D3DPRESENT_PARAMETERS params;102103pSwapChain->GetPresentParameters(¶ms);104GetWindowRect(params.hDeviceWindow, &r);105int ww = r.right - r.left;106int wh = r.bottom - r.top;107if (ww != params.BackBufferWidth || wh != params.BackBufferHeight) {108J2dTraceLn4(J2D_TRACE_WARNING,109"D3DRQ_SwapBuffers: surface/window dimensions mismatch: "\110"win: w=%d h=%d, bb: w=%d h=%d",111ww, wh, params.BackBufferWidth, params.BackBufferHeight);112113return S_OK;114}115}116117if (d3dsdo->swapEffect == D3DSWAPEFFECT_COPY) {118J2dTraceLn(J2D_TRACE_VERBOSE, " D3DSWAPEFFECT_COPY");119if (x1 < 0) x1 = 0;120if (y1 < 0) y1 = 0;121if (x2 > d3dsdo->width) x2 = d3dsdo->width;122if (y2 > d3dsdo->height) y2 = d3dsdo->height;123if (x2 <= x1 || y2 <= y1) {124// nothing to present125return S_OK;126}127srcRect.left = x1;128srcRect.top = y1;129srcRect.right = x2;130srcRect.bottom = y2;131132dstRect = srcRect;133134pSrcRect = &srcRect;135pDstRect = &dstRect;136// only offset in windowed mode137if (pCtx!= NULL && pCtx->GetPresentationParams()->Windowed) {138OffsetRect(pDstRect, d3dsdo->xoff, d3dsdo->yoff);139} else {140// some boards (Nvidia) have problems with copy strategy and141// non-null src/dest rectangles in fs mode; unfortunately this142// means that we'll paint over fs window decorations143pSrcRect = NULL;144pDstRect = NULL;145}146} else {147if (d3dsdo->swapEffect == D3DSWAPEFFECT_FLIP) {148J2dTraceLn(J2D_TRACE_VERBOSE, " D3DSWAPEFFECT_FLIP");149} else {150J2dTraceLn(J2D_TRACE_VERBOSE, " D3DSWAPEFFECT_DISCARD");151}152// src and dest rectangles must be NULL for FLIP/DISCARD153pSrcRect = NULL;154pDstRect = NULL;155}156157res = pSwapChain->Present(pSrcRect, pDstRect, 0, NULL, 0);158res = D3DRQ_MarkLostIfNeeded(res, d3dsdo);159160return res;161}162163HRESULT164D3DRQ_MarkLostIfNeeded(HRESULT res, D3DSDOps *d3dops)165{166if (res == D3DERR_DEVICELOST || res == D3DERR_DEVICENOTRESET) {167D3DContext *pCtx;168169J2dTraceLn(J2D_TRACE_WARNING, "D3DRQ_MarkLostIfNeeded: device lost");170bLostDevices = TRUE;171172// only mark surfaces belonging to the lost device173if (d3dops != NULL &&174SUCCEEDED(res = D3DPipelineManager::GetInstance()->175GetD3DContext(d3dops->adapter, &pCtx)))176{177IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();178if (pd3dDevice) {179HRESULT res1 = pd3dDevice->TestCooperativeLevel();180if (res1 != D3DERR_DEVICELOST && res1 != D3DERR_DEVICENOTRESET){181// this surface's device is not lost, do not mark it182return res;183}184}185}186D3DSD_MarkLost(d3dops);187}188return res;189}190191void D3DRQ_FlushBuffer(void *pParam)192{193FlushBufferStruct *pFlush = (FlushBufferStruct*)pParam;194JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);195unsigned char *b, *end;196int limit;197HRESULT res = S_OK;198BOOL bSync = FALSE;199200b = pFlush->buffer;201limit = pFlush->limit;202J2dTraceLn1(J2D_TRACE_INFO, "D3DRQ_flushBuffer: limit=%d", limit);203204end = b + limit;205206D3DPipelineManager *pMgr = D3DPipelineManager::GetInstance();207if (pMgr == NULL) {208J2dRlsTraceLn(J2D_TRACE_WARNING, "D3DRQ_flushBuffer: null manager");209return;210}211212if (bLostDevices) {213if (SUCCEEDED(res = pMgr->HandleLostDevices())) {214bLostDevices = FALSE;215}216}217218while (b < end) {219jint opcode = NEXT_INT(b);220221J2dTraceLn1(J2D_TRACE_VERBOSE, "D3DRQ_flushBuffer: opcode=%d", opcode);222223switch (opcode) {224225// draw ops226case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:227{228jint x1 = NEXT_INT(b);229jint y1 = NEXT_INT(b);230jint x2 = NEXT_INT(b);231jint y2 = NEXT_INT(b);232233CONTINUE_IF_NULL(d3dc);234res = D3DRenderer_DrawLine(d3dc, x1, y1, x2, y2);235}236break;237case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:238{239jint x = NEXT_INT(b);240jint y = NEXT_INT(b);241jint w = NEXT_INT(b);242jint h = NEXT_INT(b);243CONTINUE_IF_NULL(d3dc);244res = D3DRenderer_DrawRect(d3dc, x, y, w, h);245}246break;247case sun_java2d_pipe_BufferedOpCodes_DRAW_POLY:248{249jint nPoints = NEXT_INT(b);250jboolean isClosed = NEXT_BOOLEAN(b);251jint transX = NEXT_INT(b);252jint transY = NEXT_INT(b);253jint *xPoints = (jint *)b;254jint *yPoints = ((jint *)b) + nPoints;255CONTINUE_IF_NULL(d3dc);256res = D3DRenderer_DrawPoly(d3dc, nPoints, isClosed,257transX, transY,258xPoints, yPoints);259SKIP_BYTES(b, nPoints * BYTES_PER_POLY_POINT);260}261break;262case sun_java2d_pipe_BufferedOpCodes_DRAW_PIXEL:263{264jint x = NEXT_INT(b);265jint y = NEXT_INT(b);266267CONTINUE_IF_NULL(d3dc);268res = D3DRenderer_DrawLine(d3dc, x, y, x, y);269}270break;271case sun_java2d_pipe_BufferedOpCodes_DRAW_SCANLINES:272{273jint count = NEXT_INT(b);274res = D3DRenderer_DrawScanlines(d3dc, count, (jint *)b);275SKIP_BYTES(b, count * BYTES_PER_SCANLINE);276}277break;278case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:279{280jfloat x11 = NEXT_FLOAT(b);281jfloat y11 = NEXT_FLOAT(b);282jfloat dx21 = NEXT_FLOAT(b);283jfloat dy21 = NEXT_FLOAT(b);284jfloat dx12 = NEXT_FLOAT(b);285jfloat dy12 = NEXT_FLOAT(b);286jfloat lwr21 = NEXT_FLOAT(b);287jfloat lwr12 = NEXT_FLOAT(b);288289CONTINUE_IF_NULL(d3dc);290res = D3DRenderer_DrawParallelogram(d3dc,291x11, y11,292dx21, dy21,293dx12, dy12,294lwr21, lwr12);295}296break;297case sun_java2d_pipe_BufferedOpCodes_DRAW_AAPARALLELOGRAM:298{299jfloat x11 = NEXT_FLOAT(b);300jfloat y11 = NEXT_FLOAT(b);301jfloat dx21 = NEXT_FLOAT(b);302jfloat dy21 = NEXT_FLOAT(b);303jfloat dx12 = NEXT_FLOAT(b);304jfloat dy12 = NEXT_FLOAT(b);305jfloat lwr21 = NEXT_FLOAT(b);306jfloat lwr12 = NEXT_FLOAT(b);307308CONTINUE_IF_NULL(d3dc);309res = D3DRenderer_DrawAAParallelogram(d3dc,310x11, y11,311dx21, dy21,312dx12, dy12,313lwr21, lwr12);314}315break;316317// fill ops318case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:319{320jint x = NEXT_INT(b);321jint y = NEXT_INT(b);322jint w = NEXT_INT(b);323jint h = NEXT_INT(b);324325CONTINUE_IF_NULL(d3dc);326res = D3DRenderer_FillRect(d3dc, x, y, w, h);327}328break;329case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:330{331jfloat x11 = NEXT_FLOAT(b);332jfloat y11 = NEXT_FLOAT(b);333jfloat dx21 = NEXT_FLOAT(b);334jfloat dy21 = NEXT_FLOAT(b);335jfloat dx12 = NEXT_FLOAT(b);336jfloat dy12 = NEXT_FLOAT(b);337338CONTINUE_IF_NULL(d3dc);339res = D3DRenderer_FillParallelogram(d3dc,340x11, y11,341dx21, dy21,342dx12, dy12);343}344break;345case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:346{347jfloat x11 = NEXT_FLOAT(b);348jfloat y11 = NEXT_FLOAT(b);349jfloat dx21 = NEXT_FLOAT(b);350jfloat dy21 = NEXT_FLOAT(b);351jfloat dx12 = NEXT_FLOAT(b);352jfloat dy12 = NEXT_FLOAT(b);353354CONTINUE_IF_NULL(d3dc);355res = D3DRenderer_FillAAParallelogram(d3dc,356x11, y11,357dx21, dy21,358dx12, dy12);359}360break;361case sun_java2d_pipe_BufferedOpCodes_FILL_SPANS:362{363jint count = NEXT_INT(b);364res = D3DRenderer_FillSpans(d3dc, count, (jint *)b);365SKIP_BYTES(b, count * BYTES_PER_SPAN);366}367break;368369// text-related ops370case sun_java2d_pipe_BufferedOpCodes_DRAW_GLYPH_LIST:371{372jint numGlyphs = NEXT_INT(b);373jint packedParams = NEXT_INT(b);374jfloat glyphListOrigX = NEXT_FLOAT(b);375jfloat glyphListOrigY = NEXT_FLOAT(b);376jboolean usePositions = EXTRACT_BOOLEAN(packedParams,377OFFSET_POSITIONS);378jboolean subPixPos = EXTRACT_BOOLEAN(packedParams,379OFFSET_SUBPIXPOS);380jboolean rgbOrder = EXTRACT_BOOLEAN(packedParams,381OFFSET_RGBORDER);382jint lcdContrast = EXTRACT_BYTE(packedParams,383OFFSET_CONTRAST);384unsigned char *images = b;385unsigned char *positions;386jint bytesPerGlyph;387if (usePositions) {388positions = (b + numGlyphs * BYTES_PER_GLYPH_IMAGE);389bytesPerGlyph = BYTES_PER_POSITIONED_GLYPH;390} else {391positions = NULL;392bytesPerGlyph = BYTES_PER_GLYPH_IMAGE;393}394res = D3DTR_DrawGlyphList(d3dc, dstOps,395numGlyphs, usePositions,396subPixPos, rgbOrder, lcdContrast,397glyphListOrigX, glyphListOrigY,398images, positions);399SKIP_BYTES(b, numGlyphs * bytesPerGlyph);400}401break;402403// copy-related ops404case sun_java2d_pipe_BufferedOpCodes_COPY_AREA:405{406jint x = NEXT_INT(b);407jint y = NEXT_INT(b);408jint w = NEXT_INT(b);409jint h = NEXT_INT(b);410jint dx = NEXT_INT(b);411jint dy = NEXT_INT(b);412res = D3DBlitLoops_CopyArea(env, d3dc, dstOps,413x, y, w, h, dx, dy);414}415break;416case sun_java2d_pipe_BufferedOpCodes_BLIT:417{418jint packedParams = NEXT_INT(b);419jint sx1 = NEXT_INT(b);420jint sy1 = NEXT_INT(b);421jint sx2 = NEXT_INT(b);422jint sy2 = NEXT_INT(b);423jdouble dx1 = NEXT_DOUBLE(b);424jdouble dy1 = NEXT_DOUBLE(b);425jdouble dx2 = NEXT_DOUBLE(b);426jdouble dy2 = NEXT_DOUBLE(b);427jlong pSrc = NEXT_LONG(b);428jlong pDst = NEXT_LONG(b);429jint hint = EXTRACT_BYTE(packedParams, OFFSET_HINT);430jboolean texture = EXTRACT_BOOLEAN(packedParams,431OFFSET_TEXTURE);432jboolean rtt = EXTRACT_BOOLEAN(packedParams,433OFFSET_RTT);434jboolean xform = EXTRACT_BOOLEAN(packedParams,435OFFSET_XFORM);436jboolean isoblit = EXTRACT_BOOLEAN(packedParams,437OFFSET_ISOBLIT);438if (isoblit) {439res = D3DBlitLoops_IsoBlit(env, d3dc, pSrc, pDst,440xform, hint, texture, rtt,441sx1, sy1, sx2, sy2,442dx1, dy1, dx2, dy2);443D3DRQ_MarkLostIfNeeded(res, (D3DSDOps*)pSrc);444} else {445jint srctype = EXTRACT_BYTE(packedParams, OFFSET_SRCTYPE);446res = D3DBlitLoops_Blit(env, d3dc, pSrc, pDst,447xform, hint, srctype, texture,448sx1, sy1, sx2, sy2,449dx1, dy1, dx2, dy2);450}451}452break;453case sun_java2d_pipe_BufferedOpCodes_SURFACE_TO_SW_BLIT:454{455jint sx = NEXT_INT(b);456jint sy = NEXT_INT(b);457jint dx = NEXT_INT(b);458jint dy = NEXT_INT(b);459jint w = NEXT_INT(b);460jint h = NEXT_INT(b);461jint dsttype = NEXT_INT(b);462jlong pSrc = NEXT_LONG(b);463jlong pDst = NEXT_LONG(b);464res = D3DBlitLoops_SurfaceToSwBlit(env, d3dc,465pSrc, pDst, dsttype,466sx, sy, dx, dy, w, h);467D3DRQ_MarkLostIfNeeded(res, (D3DSDOps*)pSrc);468}469break;470case sun_java2d_pipe_BufferedOpCodes_MASK_FILL:471{472jint x = NEXT_INT(b);473jint y = NEXT_INT(b);474jint w = NEXT_INT(b);475jint h = NEXT_INT(b);476jint maskoff = NEXT_INT(b);477jint maskscan = NEXT_INT(b);478jint masklen = NEXT_INT(b);479unsigned char *pMask = (masklen > 0) ? b : NULL;480res = D3DMaskFill_MaskFill(d3dc, x, y, w, h,481maskoff, maskscan, masklen, pMask);482SKIP_BYTES(b, masklen);483}484break;485case sun_java2d_pipe_BufferedOpCodes_MASK_BLIT:486{487jint dstx = NEXT_INT(b);488jint dsty = NEXT_INT(b);489jint width = NEXT_INT(b);490jint height = NEXT_INT(b);491jint masklen = width * height * sizeof(jint);492res = D3DMaskBlit_MaskBlit(env, d3dc,493dstx, dsty, width, height, b);494SKIP_BYTES(b, masklen);495}496break;497498// state-related ops499case sun_java2d_pipe_BufferedOpCodes_SET_RECT_CLIP:500{501jint x1 = NEXT_INT(b);502jint y1 = NEXT_INT(b);503jint x2 = NEXT_INT(b);504jint y2 = NEXT_INT(b);505CONTINUE_IF_NULL(d3dc);506res = d3dc->SetRectClip(x1, y1, x2, y2);507}508break;509case sun_java2d_pipe_BufferedOpCodes_BEGIN_SHAPE_CLIP:510{511CONTINUE_IF_NULL(d3dc);512res = d3dc->BeginShapeClip();513}514break;515case sun_java2d_pipe_BufferedOpCodes_SET_SHAPE_CLIP_SPANS:516{517jint count = NEXT_INT(b);518res = D3DRenderer_FillSpans(d3dc, count, (jint *)b);519SKIP_BYTES(b, count * BYTES_PER_SPAN);520}521break;522case sun_java2d_pipe_BufferedOpCodes_END_SHAPE_CLIP:523{524CONTINUE_IF_NULL(d3dc);525res = d3dc->EndShapeClip();526}527break;528case sun_java2d_pipe_BufferedOpCodes_RESET_CLIP:529{530CONTINUE_IF_NULL(d3dc);531res = d3dc->ResetClip();532}533break;534case sun_java2d_pipe_BufferedOpCodes_SET_ALPHA_COMPOSITE:535{536jint rule = NEXT_INT(b);537jfloat extraAlpha = NEXT_FLOAT(b);538jint flags = NEXT_INT(b);539CONTINUE_IF_NULL(d3dc);540res = d3dc->SetAlphaComposite(rule, extraAlpha, flags);541}542break;543case sun_java2d_pipe_BufferedOpCodes_SET_XOR_COMPOSITE:544{545jint xorPixel = NEXT_INT(b);546// res = d3dc->SetXorComposite(d3dc, xorPixel);547}548break;549case sun_java2d_pipe_BufferedOpCodes_RESET_COMPOSITE:550{551CONTINUE_IF_NULL(d3dc);552res = d3dc->ResetComposite();553}554break;555case sun_java2d_pipe_BufferedOpCodes_SET_TRANSFORM:556{557jdouble m00 = NEXT_DOUBLE(b);558jdouble m10 = NEXT_DOUBLE(b);559jdouble m01 = NEXT_DOUBLE(b);560jdouble m11 = NEXT_DOUBLE(b);561jdouble m02 = NEXT_DOUBLE(b);562jdouble m12 = NEXT_DOUBLE(b);563res = d3dc->SetTransform(m00, m10, m01, m11, m02, m12);564}565break;566case sun_java2d_pipe_BufferedOpCodes_RESET_TRANSFORM:567{568CONTINUE_IF_NULL(d3dc);569res = d3dc->ResetTransform();570}571break;572573// context-related ops574case sun_java2d_pipe_BufferedOpCodes_SET_SURFACES:575{576jlong pSrc = NEXT_LONG(b);577jlong pDst = NEXT_LONG(b);578D3DContext *oldd3dc = NULL;579if (d3dc != NULL) {580oldd3dc = d3dc;581d3dc = NULL;582oldd3dc->UpdateState(STATE_CHANGE);583}584dstOps = (D3DSDOps *)jlong_to_ptr(pDst);585res = pMgr->GetD3DContext(dstOps->adapter, &d3dc);586if (FAILED(res)) {587J2dRlsTraceLn(J2D_TRACE_ERROR,588"D3DRQ_FlushBuffer: failed to get context");589D3DRQ_ResetCurrentContextAndDestination();590break;591}592// REMIND: we may also want to do EndScene on each593// render target change so that the GPU can go work on594// whatever is already in the queue595if (oldd3dc != d3dc && oldd3dc != NULL) {596res = oldd3dc->EndScene();597}598CONTINUE_IF_NULL(dstOps->pResource);599res = d3dc->SetRenderTarget(dstOps->pResource->GetSurface());600}601break;602case sun_java2d_pipe_BufferedOpCodes_SET_SCRATCH_SURFACE:603{604jint screen = NEXT_INT(b);605jint adapter = pMgr->GetAdapterOrdinalForScreen(screen);606D3DContext *oldd3dc = NULL;607608if (d3dc != NULL) {609oldd3dc = d3dc;610d3dc = NULL;611}612res = pMgr->GetD3DContext(adapter, &d3dc);613if (FAILED(res)) {614J2dRlsTraceLn(J2D_TRACE_ERROR,615"D3DRQ_FlushBuffer: failed to get context");616D3DRQ_ResetCurrentContextAndDestination();617} else if (oldd3dc != d3dc && oldd3dc != NULL) {618res = oldd3dc->EndScene();619}620}621break;622case sun_java2d_pipe_BufferedOpCodes_FLUSH_SURFACE:623{624jlong pData = NEXT_LONG(b);625D3DSDOps *d3dsdo = (D3DSDOps *)jlong_to_ptr(pData);626D3DSD_Flush(d3dsdo);627if (dstOps == d3dsdo) {628dstOps = NULL;629}630}631break;632case sun_java2d_pipe_BufferedOpCodes_DISPOSE_SURFACE:633{634jlong pData = NEXT_LONG(b);635D3DSDOps *d3dsdo = (D3DSDOps *)jlong_to_ptr(pData);636D3DSD_Flush(d3dsdo);637if (dstOps == d3dsdo) {638dstOps = NULL;639}640}641break;642case sun_java2d_pipe_BufferedOpCodes_DISPOSE_CONFIG:643{644jlong pConfigInfo = NEXT_LONG(b);645CONTINUE_IF_NULL(d3dc);646// REMIND: does this need to be implemented for D3D?647}648break;649case sun_java2d_pipe_BufferedOpCodes_INVALIDATE_CONTEXT:650{651// flush just in case there are any pending operations in652// the hardware pipe653if (d3dc != NULL) {654res = d3dc->EndScene();655}656657// invalidate the references to the current context and658// destination surface that are maintained at the native level659D3DRQ_ResetCurrentContextAndDestination();660}661break;662663case sun_java2d_pipe_BufferedOpCodes_SYNC:664{665bSync = TRUE;666}667break;668669case sun_java2d_pipe_BufferedOpCodes_RESTORE_DEVICES:670{671J2dTraceLn(J2D_TRACE_INFO, "D3DRQ_FlushBuffer: RESTORE_DEVICES");672if (SUCCEEDED(res = pMgr->HandleLostDevices())) {673bLostDevices = FALSE;674} else {675bLostDevices = TRUE;676}677}678break;679680case sun_java2d_pipe_BufferedOpCodes_SAVE_STATE:681{682CONTINUE_IF_NULL(d3dc);683684res = d3dc->SaveState();685}686break;687688case sun_java2d_pipe_BufferedOpCodes_RESTORE_STATE:689{690CONTINUE_IF_NULL(d3dc);691692res = d3dc->RestoreState();693}694break;695696// multibuffering ops697case sun_java2d_pipe_BufferedOpCodes_SWAP_BUFFERS:698{699jlong sdo = NEXT_LONG(b);700jint x1 = NEXT_INT(b);701jint y1 = NEXT_INT(b);702jint x2 = NEXT_INT(b);703jint y2 = NEXT_INT(b);704705res = D3DRQ_SwapBuffers(pMgr, (D3DSDOps *)jlong_to_ptr(sdo),706x1, y1, x2, y2);707}708break;709710// special no-op (mainly used for achieving 8-byte alignment)711case sun_java2d_pipe_BufferedOpCodes_NOOP:712break;713714// paint-related ops715case sun_java2d_pipe_BufferedOpCodes_RESET_PAINT:716{717res = D3DPaints_ResetPaint(d3dc);718}719break;720case sun_java2d_pipe_BufferedOpCodes_SET_COLOR:721{722jint pixel = NEXT_INT(b);723res = D3DPaints_SetColor(d3dc, pixel);724}725break;726case sun_java2d_pipe_BufferedOpCodes_SET_GRADIENT_PAINT:727{728jboolean useMask= NEXT_BOOLEAN(b);729jboolean cyclic = NEXT_BOOLEAN(b);730jdouble p0 = NEXT_DOUBLE(b);731jdouble p1 = NEXT_DOUBLE(b);732jdouble p3 = NEXT_DOUBLE(b);733jint pixel1 = NEXT_INT(b);734jint pixel2 = NEXT_INT(b);735res = D3DPaints_SetGradientPaint(d3dc, useMask, cyclic,736p0, p1, p3,737pixel1, pixel2);738}739break;740case sun_java2d_pipe_BufferedOpCodes_SET_LINEAR_GRADIENT_PAINT:741{742jboolean useMask = NEXT_BOOLEAN(b);743jboolean linear = NEXT_BOOLEAN(b);744jint cycleMethod = NEXT_INT(b);745jint numStops = NEXT_INT(b);746jfloat p0 = NEXT_FLOAT(b);747jfloat p1 = NEXT_FLOAT(b);748jfloat p3 = NEXT_FLOAT(b);749void *fractions, *pixels;750fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));751pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));752res = D3DPaints_SetLinearGradientPaint(d3dc, dstOps,753useMask, linear,754cycleMethod, numStops,755p0, p1, p3,756fractions, pixels);757}758break;759case sun_java2d_pipe_BufferedOpCodes_SET_RADIAL_GRADIENT_PAINT:760{761jboolean useMask = NEXT_BOOLEAN(b);762jboolean linear = NEXT_BOOLEAN(b);763jint numStops = NEXT_INT(b);764jint cycleMethod = NEXT_INT(b);765jfloat m00 = NEXT_FLOAT(b);766jfloat m01 = NEXT_FLOAT(b);767jfloat m02 = NEXT_FLOAT(b);768jfloat m10 = NEXT_FLOAT(b);769jfloat m11 = NEXT_FLOAT(b);770jfloat m12 = NEXT_FLOAT(b);771jfloat focusX = NEXT_FLOAT(b);772void *fractions, *pixels;773fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));774pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));775res = D3DPaints_SetRadialGradientPaint(d3dc, dstOps,776useMask, linear,777cycleMethod, numStops,778m00, m01, m02,779m10, m11, m12,780focusX,781fractions, pixels);782}783break;784case sun_java2d_pipe_BufferedOpCodes_SET_TEXTURE_PAINT:785{786jboolean useMask= NEXT_BOOLEAN(b);787jboolean filter = NEXT_BOOLEAN(b);788jlong pSrc = NEXT_LONG(b);789jdouble xp0 = NEXT_DOUBLE(b);790jdouble xp1 = NEXT_DOUBLE(b);791jdouble xp3 = NEXT_DOUBLE(b);792jdouble yp0 = NEXT_DOUBLE(b);793jdouble yp1 = NEXT_DOUBLE(b);794jdouble yp3 = NEXT_DOUBLE(b);795res = D3DPaints_SetTexturePaint(d3dc, useMask, pSrc, filter,796xp0, xp1, xp3,797yp0, yp1, yp3);798}799break;800801// BufferedImageOp-related ops802case sun_java2d_pipe_BufferedOpCodes_ENABLE_CONVOLVE_OP:803{804jlong pSrc = NEXT_LONG(b);805jboolean edgeZero = NEXT_BOOLEAN(b);806jint kernelWidth = NEXT_INT(b);807jint kernelHeight = NEXT_INT(b);808res = D3DBufImgOps_EnableConvolveOp(d3dc, pSrc, edgeZero,809kernelWidth, kernelHeight, b);810SKIP_BYTES(b, kernelWidth * kernelHeight * sizeof(jfloat));811}812break;813case sun_java2d_pipe_BufferedOpCodes_DISABLE_CONVOLVE_OP:814{815res = D3DBufImgOps_DisableConvolveOp(d3dc);816}817break;818case sun_java2d_pipe_BufferedOpCodes_ENABLE_RESCALE_OP:819{820jlong pSrc = NEXT_LONG(b); // unused821jboolean nonPremult = NEXT_BOOLEAN(b);822jint numFactors = 4;823unsigned char *scaleFactors = b;824unsigned char *offsets = (b + numFactors * sizeof(jfloat));825res = D3DBufImgOps_EnableRescaleOp(d3dc, nonPremult,826scaleFactors, offsets);827SKIP_BYTES(b, numFactors * sizeof(jfloat) * 2);828}829break;830case sun_java2d_pipe_BufferedOpCodes_DISABLE_RESCALE_OP:831{832D3DBufImgOps_DisableRescaleOp(d3dc);833}834break;835case sun_java2d_pipe_BufferedOpCodes_ENABLE_LOOKUP_OP:836{837jlong pSrc = NEXT_LONG(b); // unused838jboolean nonPremult = NEXT_BOOLEAN(b);839jboolean shortData = NEXT_BOOLEAN(b);840jint numBands = NEXT_INT(b);841jint bandLength = NEXT_INT(b);842jint offset = NEXT_INT(b);843jint bytesPerElem = shortData ? sizeof(jshort):sizeof(jbyte);844void *tableValues = b;845res = D3DBufImgOps_EnableLookupOp(d3dc, nonPremult, shortData,846numBands, bandLength, offset,847tableValues);848SKIP_BYTES(b, numBands * bandLength * bytesPerElem);849}850break;851case sun_java2d_pipe_BufferedOpCodes_DISABLE_LOOKUP_OP:852{853res = D3DBufImgOps_DisableLookupOp(d3dc);854}855break;856857default:858J2dRlsTraceLn1(J2D_TRACE_ERROR,859"D3DRQ_flushBuffer: invalid opcode=%d", opcode);860return;861}862// we may mark the surface lost repeatedly but that won't do much harm863res = D3DRQ_MarkLostIfNeeded(res, dstOps);864}865866if (d3dc != NULL) {867res = d3dc->EndScene();868// REMIND: EndScene is not really enough to flush the869// whole d3d pipeline870871// REMIND: there may be an issue with BeginScene/EndScene872// for each flushQueue, because of the blits, which flush873// the queue874if (bSync) {875res = d3dc->Sync();876}877}878879// REMIND: we need to also handle hard errors here as well, and disable880// particular context if needed881D3DRQ_MarkLostIfNeeded(res, dstOps);882883if (!JNU_IsNull(env, pFlush->runnable)) {884J2dTraceLn(J2D_TRACE_VERBOSE, " executing runnable");885JNU_CallMethodByName(env, NULL, pFlush->runnable, "run", "()V");886}887}888889/**890* Returns a pointer to the "current" context, as set by the last SET_SURFACES891* or SET_SCRATCH_SURFACE operation.892*/893D3DContext *894D3DRQ_GetCurrentContext()895{896return d3dc;897}898899/**900* Returns a pointer to the "current" destination surface, as set by the last901* SET_SURFACES operation.902*/903D3DSDOps *904D3DRQ_GetCurrentDestination()905{906return dstOps;907}908909/**910* Resets current context and destination surface.911*/912void913D3DRQ_ResetCurrentContextAndDestination()914{915J2dTraceLn(J2D_TRACE_INFO, "D3DRQ_ResetCurrentContextAndDestination");916917d3dc = NULL;918dstOps = NULL;919}920921extern "C"922{923924/*925* Class: sun_java2d_d3d_D3DRenderQueue926* Method: flushBuffer927* Signature: (JILjava/lang/Runnable;)V928*/929JNIEXPORT void JNICALL930Java_sun_java2d_d3d_D3DRenderQueue_flushBuffer931(JNIEnv *env, jobject d3drq, jlong buf, jint limit, jobject runnable)932{933FlushBufferStruct bufstr;934// just in case we forget to init any new fields935ZeroMemory(&bufstr, sizeof(FlushBufferStruct));936937bufstr.buffer = (unsigned char *)jlong_to_ptr(buf);938if (bufstr.buffer == NULL) {939J2dRlsTraceLn(J2D_TRACE_ERROR,940"D3DRenderQueue_flushBuffer: cannot get direct buffer address");941return;942}943bufstr.limit = limit;944945bufstr.runnable = JNU_IsNull(env, runnable) ?946NULL : env->NewGlobalRef(runnable);947AwtToolkit::GetInstance().InvokeFunction(D3DRQ_FlushBuffer, &bufstr);948if (!JNU_IsNull(env, bufstr.runnable)) {949env->DeleteGlobalRef(bufstr.runnable);950}951}952953}954955956