Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8252795: Lanai: Refactor native implementation of MTLPaint
  • Loading branch information
Alexey Ushakov committed Sep 15, 2020
1 parent d638a78 commit 243c84199602f910ffa48bb1c695feb1d5d7e08e
@@ -24,7 +24,8 @@ - (void)updateEncoder:(id<MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
renderOptions:(const RenderOptions *)renderOptions
forceUpdate:(jboolean)forceUpdate;
@property jboolean aa;
@property (assign) jboolean aa;
@property (retain) MTLPaint* paint;
@end

@implementation EncoderStates {
@@ -59,6 +60,7 @@ @implementation EncoderStates {
MTLTransform * _transform;
}
@synthesize aa = _isAA;
@synthesize paint = _paint;

- (id)init {
self = [super init];
@@ -142,23 +144,24 @@ - (void)updatePipelineState:(id<MTLRenderCommandEncoder>)encoder
&& _srcFlags.isOpaque == renderOptions->srcFlags.isOpaque && _srcFlags.isPremultiplied == renderOptions->srcFlags.isPremultiplied)
return;

[_paint copyFrom:mtlc.paint];
self.paint = mtlc.paint;
[_composite copyFrom:mtlc.composite];
_isTexture = renderOptions->isTexture;
_interpolationMode = renderOptions->interpolation;
_isAA = renderOptions->isAA;
_srcFlags = renderOptions->srcFlags;

if ((jint)[mtlc.composite getCompositeState] == sun_java2d_SunGraphics2D_COMP_XOR) {

[mtlc.paint setXorModePipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:_pipelineStateStorage];
} else {
[mtlc.paint setPipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:_pipelineStateStorage];
[mtlc.paint setPipelineState:encoder
context:mtlc
renderOptions:renderOptions
pipelineStateStorage:_pipelineStateStorage];
}
}

@@ -59,7 +59,7 @@
* */
@interface MTLContext : NSObject
@property (readonly) MTLComposite * composite;
@property (readonly) MTLPaint * paint;
@property (readwrite, retain) MTLPaint * paint;
@property (readonly) MTLTransform * transform;
@property (readonly) MTLClip * clip;

@@ -100,7 +100,7 @@ @implementation MTLContext {
@synthesize textureFunction,
vertexCacheEnabled, aaEnabled, device, library, pipelineStateStorage,
commandQueue, blitCommandQueue, vertexBuffer,
texturePool;
texturePool, paint=_paint;

extern void initSamplers(id<MTLDevice> device);

@@ -318,12 +318,12 @@ - (jint)createBlitTextureFormat:(jint)internalFormat pixelFormat:(jint)pixelForm

- (void)resetPaint {
J2dTraceLn(J2D_TRACE_INFO, "MTLContext.resetPaint");
[_paint reset];
self.paint = [[[MTLPaint alloc] init] autorelease];
}

- (void)setColorPaint:(int)pixel {
J2dTraceLn5(J2D_TRACE_INFO, "MTLContext.setColorPaint: pixel=%08x [r=%d g=%d b=%d a=%d]", pixel, (pixel >> 16) & (0xFF), (pixel >> 8) & 0xFF, (pixel) & 0xFF, (pixel >> 24) & 0xFF);
[_paint setColor:pixel];
self.paint = [[[MTLColorPaint alloc] initWithColor:pixel] autorelease];
}

- (void)setGradientPaintUseMask:(jboolean)useMask
@@ -335,13 +335,13 @@ - (void)setGradientPaintUseMask:(jboolean)useMask
pixel2:(jint) pixel2
{
J2dTraceLn(J2D_TRACE_INFO, "MTLContext.setGradientPaintUseMask");
[_paint setGradientUseMask:useMask
cyclic:cyclic
p0:p0
p1:p1
p3:p3
pixel1:pixel1
pixel2:pixel2];
self.paint = [[[MTLGradPaint alloc] initWithUseMask:useMask
cyclic:cyclic
p0:p0
p1:p1
p3:p3
pixel1:pixel1
pixel2:pixel2] autorelease];
}

- (void)setLinearGradientPaint:(jboolean)useMask
@@ -359,15 +359,15 @@ - (void)setLinearGradientPaint:(jboolean)useMask
pixels:(jint*)pixels
{
J2dTraceLn(J2D_TRACE_INFO, "MTLContext.setLinearGradientPaint");
[_paint setLinearGradient:useMask
self.paint = [[[MTLLinearGradPaint alloc] initWithUseMask:useMask
linear:linear
cycleMethod:cycleMethod
numStops:numStops
p0:p0
p1:p1
p3:p3
fractions:fractions
pixels:pixels];
pixels:pixels] autorelease];
}

- (void)setRadialGradientPaint:(jboolean)useMask
@@ -385,19 +385,19 @@ - (void)setRadialGradientPaint:(jboolean)useMask
pixels:(void *)pixels
{
J2dTraceLn(J2D_TRACE_INFO, "MTLContext.setRadialGradientPaint");
[_paint setRadialGradient:useMask
linear:linear
cycleMethod:cycleMethod
numStops:numStops
m00:m00
m01:m01
m02:m02
m10:m10
m11:m11
m12:m12
focusX:focusX
fractions:fractions
pixels:pixels];
self.paint = [[[MTLRadialGradPaint alloc] initWithUseMask:useMask
linear:linear
cycleMethod:cycleMethod
numStops:numStops
m00:m00
m01:m01
m02:m02
m10:m10
m11:m11
m12:m12
focusX:focusX
fractions:fractions
pixels:pixels] autorelease];
}

- (void)setTexturePaint:(jboolean)useMask
@@ -419,16 +419,15 @@ - (void)setTexturePaint:(jboolean)useMask

J2dTraceLn1(J2D_TRACE_INFO, "MTLContext.setTexturePaint [tex=%p]", srcOps->pTexture);


[_paint setTexture:useMask
textureID:srcOps->pTexture
filter:filter
xp0:xp0
xp1:xp1
xp3:xp3
yp0:yp0
yp1:yp1
yp3:yp3];
self.paint = [[[MTLTexturePaint alloc] initWithUseMask:useMask
textureID:srcOps->pTexture
filter:filter
xp0:xp0
xp1:xp1
xp3:xp3
yp0:yp0
yp1:yp1
yp3:yp3] autorelease] ;
}

- (id<MTLCommandBuffer>)createCommandBuffer {
@@ -27,6 +27,7 @@
#define MTLPaints_h_Included

#import <Metal/Metal.h>
#import <awt/common.h>
#include "RenderOptions.h"

#define sun_java2d_SunGraphics2D_PAINT_UNDEFINED -1
@@ -41,68 +42,104 @@
* */

@interface MTLPaint : NSObject
- (id)init;

- (id)initWithState:(jint)state;
- (BOOL)isEqual:(MTLPaint *)other; // used to compare requested with cached
- (void)copyFrom:(MTLPaint *)other; // used to save cached
- (NSString *)getDescription;
- (jint)getColor;
- (void)reset;

- (void)setColor:(jint)pixelColor;
- (void)setGradientUseMask:(jboolean)useMask
cyclic:(jboolean)cyclic
p0:(jdouble)p0
p1:(jdouble)p1
p3:(jdouble)p3
pixel1:(jint)pixel1
pixel2:(jint)pixel2;

- (void)setLinearGradient:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jboolean)cycleMethod
numStops:(jint)numStops
p0:(jfloat)p0
p1:(jfloat)p1
p3:(jfloat)p3
fractions:(jfloat *)fractions
pixels:(jint *)pixels;

- (void)setRadialGradient:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jint)cycleMethod
numStops:(jint)numStops
m00:(jfloat)m00
m01:(jfloat)m01
m02:(jfloat)m02
m10:(jfloat)m10
m11:(jfloat)m11
m12:(jfloat)m12
focusX:(jfloat)focusX
fractions:(void *)fractions
pixels:(void *)pixels;

- (void)setTexture:(jboolean)useMask
textureID:(id<MTLTexture>)textureID
filter:(jboolean)filter
xp0:(jdouble)xp0
xp1:(jdouble)xp1
xp3:(jdouble)xp3
yp0:(jdouble)yp0
yp1:(jdouble)yp1
yp3:(jdouble)yp3;

// For the current paint mode and passed composite (and flags):
// 1. Selects vertex+fragment shader (and corresponding pipelineDesc) and set pipelineState
// 2. Prepares corresponding buffers of vertex and fragment shaders

- (void)setPipelineState:(id <MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
renderOptions:(const RenderOptions *)renderOptions
pipelineStateStorage:(MTLPipelineStatesStorage *)pipelineStateStorage;


- (void)setXorModePipelineState:(id <MTLRenderCommandEncoder>)encoder
context:(MTLContext *)mtlc
renderOptions:(const RenderOptions *)renderOptions
pipelineStateStorage:(MTLPipelineStatesStorage *)pipelineStateStorage;
@end

@interface MTLColorPaint : MTLPaint
- (id)initWithColor:(jint)color;
@property (nonatomic, readonly) jint color;
@end

@interface MTLBaseGradPaint : MTLPaint {
@public
jint _cyclic;
}
- (id)initWithState:(jint)state
mask:(jboolean)useMask
cyclic:(jboolean)cyclic;
@end

@interface MTLGradPaint : MTLBaseGradPaint

- (id)initWithUseMask:(jboolean)useMask
cyclic:(jboolean)cyclic
p0:(jdouble)p0
p1:(jdouble)p1
p3:(jdouble)p3
pixel1:(jint)pixel1
pixel2:(jint)pixel2;
@end

@interface MTLBaseMultiGradPaint : MTLBaseGradPaint

- (id)initWithState:(jint)state
mask:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jboolean)cycleMethod
numStops:(jint)numStops
fractions:(jfloat *)fractions
pixels:(jint *)pixels;
@end

@interface MTLLinearGradPaint : MTLBaseMultiGradPaint

- (id)initWithUseMask:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jboolean)cycleMethod
numStops:(jint)numStops
p0:(jfloat)p0
p1:(jfloat)p1
p3:(jfloat)p3
fractions:(jfloat *)fractions
pixels:(jint *)pixels;
@end

@interface MTLRadialGradPaint : MTLBaseMultiGradPaint

- (id)initWithUseMask:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jint)cycleMethod
numStops:(jint)numStops
m00:(jfloat)m00
m01:(jfloat)m01
m02:(jfloat)m02
m10:(jfloat)m10
m11:(jfloat)m11
m12:(jfloat)m12
focusX:(jfloat)focusX
fractions:(void *)fractions
pixels:(void *)pixels;
@end

@interface MTLTexturePaint : MTLPaint

- (id)initWithUseMask:(jboolean)useMask
textureID:(id <MTLTexture>)textureID
filter:(jboolean)filter
xp0:(jdouble)xp0
xp1:(jdouble)xp1
xp3:(jdouble)xp3
yp0:(jdouble)yp0
yp1:(jdouble)yp1
yp3:(jdouble)yp3;
@end

#endif /* MTLPaints_h_Included */

0 comments on commit 243c841

Please sign in to comment.