< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m

Print this page

        

*** 35,89 **** #include "MTLRenderQueue.h" #include "MTLSurfaceData.h" #include "MTLUtils.h" #import "MTLLayer.h" - void MTLRenderer_FillParallelogramMetal( - MTLContext* mtlc, id<MTLTexture> dest, jfloat x, jfloat y, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) - { - if (mtlc == NULL || dest == nil) - return; - - J2dTraceLn7(J2D_TRACE_INFO, - "MTLRenderer_FillParallelogramMetal " - "(x=%6.2f y=%6.2f " - "dx1=%6.2f dy1=%6.2f " - "dx2=%6.2f dy2=%6.2f dst tex=%p)", - x, y, - dx1, dy1, - dx2, dy2, dest); - - struct Vertex verts[PGRAM_VERTEX_COUNT] = { - { {(2.0*x/dest.width) - 1.0, - 2.0*(1.0 - y/dest.height) - 1.0, 0.0}}, - - { {2.0*(x+dx1)/dest.width - 1.0, - 2.0*(1.0 - (y+dy1)/dest.height) - 1.0, 0.0}}, - - { {2.0*(x+dx2)/dest.width - 1.0, - 2.0*(1.0 - (y+dy2)/dest.height) - 1.0, 0.0}}, - - { {2.0*(x+dx1)/dest.width - 1.0, - 2.0*(1.0 - (y+dy1)/dest.height) - 1.0, 0.0}}, - - { {2.0*(x + dx1 + dx2)/dest.width - 1.0, - 2.0*(1.0 - (y+ dy1 + dy2)/dest.height) - 1.0, 0.0}}, - - { {2.0*(x+dx2)/dest.width - 1.0, - 2.0*(1.0 - (y+dy2)/dest.height) - 1.0, 0.0}, - }}; - - // Encode render command. - id<MTLRenderCommandEncoder> mtlEncoder = [mtlc createRenderEncoderForDest:dest]; - if (mtlEncoder == nil) - return; - - [mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer]; - [mtlEncoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount: PGRAM_VERTEX_COUNT]; - [mtlEncoder endEncoding]; - } - /** * Note: Some of the methods in this file apply a "magic number" * translation to line segments. The OpenGL specification lays out the * "diamond exit rule" for line rasterization, but it is loose enough to * allow for a wide range of line rendering hardware. (It appears that --- 35,44 ----
*** 144,154 **** id<MTLRenderCommandEncoder> mtlEncoder = [mtlc createRenderEncoderForDest:dest]; if (mtlEncoder == nil) return; const int verticesCount = 5; ! struct Vertex vertices[verticesCount] = { {{x, y, 0.0}}, {{x + w, y, 0.0}}, {{x + w, y + h, 0.0}}, {{x, y + h, 0.0}}, {{x, y, 0.0}}, --- 99,109 ---- id<MTLRenderCommandEncoder> mtlEncoder = [mtlc createRenderEncoderForDest:dest]; if (mtlEncoder == nil) return; const int verticesCount = 5; ! struct Vertex vertices[5] = { {{x, y, 0.0}}, {{x + w, y, 0.0}}, {{x + w, y + h, 0.0}}, {{x, y + h, 0.0}}, {{x, y, 0.0}},
*** 258,270 **** } void MTLRenderer_FillRect(MTLContext *mtlc, BMTLSDOps * dstOps, jint x, jint y, jint w, jint h) { - //TODO - J2dTraceNotImplPrimitive("MTLRenderer_FillRect"); J2dTraceLn(J2D_TRACE_INFO, "MTLRenderer_FillRect"); } const int SPAN_BUF_SIZE=64; void --- 213,250 ---- } void MTLRenderer_FillRect(MTLContext *mtlc, BMTLSDOps * dstOps, jint x, jint y, jint w, jint h) { J2dTraceLn(J2D_TRACE_INFO, "MTLRenderer_FillRect"); + + if (mtlc == NULL || dstOps == NULL || dstOps->pTexture == NULL) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLRenderer_FillRect: current dest is null"); + return; + } + + struct Vertex verts[PGRAM_VERTEX_COUNT] = { + { {x, y, 0.0}}, + { {x, y+h, 0.0}}, + { {x+w, y+h, 0.0}}, + { {x+w, y+h, 0.0}}, + { {x+w, y, 0.0}}, + { {x, y, 0.0}, + }}; + + + id<MTLTexture> dest = dstOps->pTexture; + J2dTraceLn5(J2D_TRACE_INFO, "MTLRenderer_FillRect (x=%d y=%d w=%d h=%d), dst tex=%p", x, y, w, h, dest); + + // Encode render command. + id<MTLRenderCommandEncoder> mtlEncoder = [mtlc createRenderEncoderForDest:dest]; + if (mtlEncoder == nil) + return; + + [mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer]; + [mtlEncoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount: PGRAM_VERTEX_COUNT]; + [mtlEncoder endEncoding]; } const int SPAN_BUF_SIZE=64; void
*** 368,378 **** jfloat fx11, jfloat fy11, jfloat dx21, jfloat dy21, jfloat dx12, jfloat dy12, jfloat lwr21, jfloat lwr12) { - //TODO J2dTraceNotImplPrimitive("MTLRenderer_DrawParallelogram"); // dx,dy for line width in the "21" and "12" directions. jfloat ldx21 = dx21 * lwr21; jfloat ldy21 = dy21 * lwr21; jfloat ldx12 = dx12 * lwr12; --- 348,357 ----
*** 389,400 **** --- 368,443 ---- "dx2=%6.2f dy2=%6.2f lwr2=%6.2f)", fx11, fy11, dx21, dy21, lwr21, dx12, dy12, lwr12); + + // Only need to generate 4 quads if the interior still + // has a hole in it (i.e. if the line width ratio was + // less than 1.0) + if (lwr21 < 1.0f && lwr12 < 1.0f) { + + // Note: "TOP", "BOTTOM", "LEFT" and "RIGHT" here are + // relative to whether the dxNN variables are positive + // and negative. The math works fine regardless of + // their signs, but for conceptual simplicity the + // comments will refer to the sides as if the dxNN + // were all positive. "TOP" and "BOTTOM" segments + // are defined by the dxy21 deltas. "LEFT" and "RIGHT" + // segments are defined by the dxy12 deltas. + + // Each segment includes its starting corner and comes + // to just short of the following corner. Thus, each + // corner is included just once and the only lengths + // needed are the original parallelogram delta lengths + // and the "line width deltas". The sides will cover + // the following relative territories: + // + // T T T T T R + // L R + // L R + // L R + // L R + // L B B B B B + + // TOP segment, to left side of RIGHT edge + // "width" of original pgram, "height" of hor. line size + fx11 = ox11; + fy11 = oy11; + MTLRenderer_FillParallelogram(mtlc, dstOps, fx11, fy11, dx21, dy21, ldx12, ldy12); + + // RIGHT segment, to top of BOTTOM edge + // "width" of vert. line size , "height" of original pgram + fx11 = ox11 + dx21; + fy11 = oy11 + dy21; + MTLRenderer_FillParallelogram(mtlc, dstOps, fx11, fy11, ldx21, ldy21, dx12, dy12); + + // BOTTOM segment, from right side of LEFT edge + // "width" of original pgram, "height" of hor. line size + fx11 = ox11 + dx12 + ldx21; + fy11 = oy11 + dy12 + ldy21; + MTLRenderer_FillParallelogram(mtlc, dstOps, fx11, fy11, dx21, dy21, ldx12, ldy12); + + // LEFT segment, from bottom of TOP edge + // "width" of vert. line size , "height" of inner pgram + fx11 = ox11 + ldx12; + fy11 = oy11 + ldy12; + MTLRenderer_FillParallelogram(mtlc, dstOps, fx11, fy11, ldx21, ldy21, dx12, dy12); + } else { + // The line width ratios were large enough to consume + // the entire hole in the middle of the parallelogram + // so we can just issue one large quad for the outer + // parallelogram. + dx21 += ldx21; + dy21 += ldy21; + dx12 += ldx12; + dy12 += ldy12; + MTLRenderer_FillParallelogram(mtlc, dstOps, ox11, oy11, dx21, dy21, dx12, dy12); + } } + static GLhandleARB aaPgramProgram = 0; /* * This shader fills the space between an outer and inner parallelogram. * It can be used to draw an outline by specifying both inner and outer
< prev index next >