Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation problem with ARC in some compilers. #384

Merged
merged 1 commit into from Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions platforms/iOS/vm/OSX/sqSqueakOSXMetalView.h
Expand Up @@ -83,6 +83,9 @@
id<MTLRenderPipelineState> screenQuadPipelineState;
id<MTLRenderPipelineState> layerScreenQuadPipelineState;
id<MTLBuffer> screenQuadVertexBuffer;

NSArray *extraDrawingLayers;
unsigned int allocatedExtraDrawingLayers;
}

+ (BOOL) isMetalViewSupported;
Expand Down
148 changes: 90 additions & 58 deletions platforms/iOS/vm/OSX/sqSqueakOSXMetalView.m
Expand Up @@ -49,6 +49,8 @@
extern SqueakOSXAppDelegate *gDelegateApp;
extern struct VirtualMachine* interpreterProxy;

static sqSqueakOSXMetalView *mainMetalView;

#define STRINGIFY_SHADER(src) #src
static const char *squeakMainShadersSrc =
#include "SqueakMainShaders.metal"
Expand All @@ -74,16 +76,22 @@
float translationX, translationY;
} LayerTransformation;

typedef struct ExtraLayer
{
@interface sqSqueakOSXMetalViewExtraDrawingLayer : NSObject {
id<MTLTexture> texture;
int x, y;
int w, h;
} ExtraLayer;
int w, h;
}

static sqSqueakOSXMetalView *mainMetalView;
static ExtraLayer extraLayers[MAX_NUMBER_OF_EXTRA_LAYERS];
static unsigned int allocatedExtraLayers = 0;
@property (nonatomic,assign) int x;
@property (nonatomic,assign) int y;
@property (nonatomic,assign) int w;
@property (nonatomic,assign) int h;
@property (nonatomic,strong) id<MTLTexture> texture;
@end

@implementation sqSqueakOSXMetalViewExtraDrawingLayer
@synthesize x, y, w, h, texture;
@end

static NSString *stringWithCharacter(unichar character) {
return [NSString stringWithCharacters: &character length: 1];
Expand Down Expand Up @@ -138,6 +146,12 @@ - (void)initialize {

self.paused = YES;
self.enableSetNeedsDisplay = NO;

NSMutableArray *drawingLayers = [NSMutableArray arrayWithCapacity: MAX_NUMBER_OF_EXTRA_LAYERS];
for(int i = 0; i < MAX_NUMBER_OF_EXTRA_LAYERS; ++i) {
[drawingLayers addObject: [sqSqueakOSXMetalViewExtraDrawingLayer new]];
}
extraDrawingLayers = drawingLayers;

inputMark = NSMakeRange(NSNotFound, 0);
inputSelection = NSMakeRange(0, 0);
Expand Down Expand Up @@ -329,11 +343,11 @@ -(void)drawRect:(NSRect)rect
// Draw the screen rectangle.
[self drawScreenRect: rect];

unsigned int drawnExtraLayerMask = 0;
for(unsigned int i = 0; i < MAX_NUMBER_OF_EXTRA_LAYERS && drawnExtraLayerMask != allocatedExtraLayers; ++i) {
if(allocatedExtraLayers & (1 << i)) {
[self drawExtraLayer: i];
drawnExtraLayerMask |= 1 << i;
unsigned int drawnExtraDrawingLayerMask = 0;
for(unsigned int i = 0; i < MAX_NUMBER_OF_EXTRA_LAYERS && drawnExtraDrawingLayerMask != allocatedExtraDrawingLayers; ++i) {
if(allocatedExtraDrawingLayers & (1 << i)) {
[self drawExtraDrawingLayer: i];
drawnExtraDrawingLayerMask |= 1 << i;
}
}

Expand Down Expand Up @@ -400,9 +414,9 @@ -(void)drawScreenRect:(NSRect)rect {
vertexCount: 4];
}

- (void) drawExtraLayer: (unsigned int) extraLayerIndex {
ExtraLayer *layer = &extraLayers[extraLayerIndex];
if(!layer->texture)
- (void) drawExtraDrawingLayer: (unsigned int) extraDrawingLayerIndex {
sqSqueakOSXMetalViewExtraDrawingLayer *layer = extraDrawingLayers[extraDrawingLayerIndex];
if(!layer.texture)
return;

if(layerScreenQuadPipelineState == nil || screenQuadVertexBuffer == nil)
Expand All @@ -412,14 +426,14 @@ - (void) drawExtraLayer: (unsigned int) extraLayerIndex {

NSRect screenRect = self.frame;
LayerTransformation transformation;
transformation.scaleX = (float)layer->w / screenRect.size.width;
transformation.scaleY = (float)layer->h / screenRect.size.height;
transformation.translationX = (2.0f*layer->x + layer->w) / screenRect.size.width - 1.0f;
transformation.translationY = 1.0f - (2.0f*layer->y + layer->h) / screenRect.size.height;
transformation.scaleX = (float)layer.w / screenRect.size.width;
transformation.scaleY = (float)layer.h / screenRect.size.height;
transformation.translationX = (2.0f*layer.x + layer.w) / screenRect.size.width - 1.0f;
transformation.translationY = 1.0f - (2.0f*layer.y + layer.h) / screenRect.size.height;

[currentRenderEncoder setVertexBuffer: screenQuadVertexBuffer offset: 0 atIndex: 0];
[currentRenderEncoder setVertexBytes: &transformation length: sizeof(transformation) atIndex: 1];
[currentRenderEncoder setFragmentTexture: layer->texture atIndex: 0];
[currentRenderEncoder setFragmentTexture: layer.texture atIndex: 0];

// Draw the the 4 vertices of the of the screen quad.
[currentRenderEncoder drawPrimitives: MTLPrimitiveTypeTriangleStrip
Expand Down Expand Up @@ -872,68 +886,86 @@ - (void) ioSetFullScreen: (sqInt) fullScreen {
- (void) preDrawThelayers {
}

@end

id<MTLDevice>
getMainWindowMetalDevice(void) {
return mainMetalView ? mainMetalView.device : nil;
}


id<MTLCommandQueue>
getMainWindowMetalCommandQueue(void) {
return mainMetalView ? mainMetalView.graphicsCommandQueue : nil;
}

unsigned int
createMetalTextureLayerHandle(void) {
- (unsigned int) createTextureLayerHandle {
unsigned int i;
unsigned int bit;
for(i = 0; i < MAX_NUMBER_OF_EXTRA_LAYERS; ++i) {
bit = 1<<i;
if(!(allocatedExtraLayers & bit)) {
allocatedExtraLayers |= bit;
if(!(allocatedExtraDrawingLayers & bit)) {
allocatedExtraDrawingLayers |= bit;
return i + 1;
}
}
return 0;
}

void
destroyMetalTextureLayerHandle(unsigned int handle) {
- (void) destroyTextureLayerHandle: (unsigned int) handle {
unsigned int bit = 1 << (handle - 1);
if(allocatedExtraLayers & bit) {
ExtraLayer *layer = &extraLayers[handle - 1];
if(layer->texture) {
RELEASEOBJ(layer->texture);
layer->texture = nil;
if(allocatedExtraDrawingLayers & bit) {
sqSqueakOSXMetalViewExtraDrawingLayer *layer = extraDrawingLayers[handle - 1];
if(layer.texture) {
RELEASEOBJ(layer.texture);
layer.texture = nil;
}

allocatedExtraLayers &= ~bit;
allocatedExtraDrawingLayers &= ~bit;

// Redraw the screen.
if(mainMetalView)
[mainMetalView draw];
}
[self draw];
}
}

void
setMetalTextureLayerContent(unsigned int handle, id<MTLTexture> texture, int x, int y, int w, int h) {
- (void) setExtraLayer: (unsigned int) handle texture: (id<MTLTexture>) texture x: (int) x y: (int) y w: (int) w h: (int) h {
unsigned int bit = 1 << (handle - 1);
if(allocatedExtraLayers & bit) {
ExtraLayer *layer = &extraLayers[handle - 1];
if(allocatedExtraDrawingLayers & bit) {
sqSqueakOSXMetalViewExtraDrawingLayer *layer = extraDrawingLayers[handle - 1];
RETAINOBJ(texture);
if(layer->texture)
if(layer.texture)
RELEASEOBJ(texture);
layer->texture = texture;
layer->x = x;
layer->y = y;
layer->w = w;
layer->h = h;
layer.texture = texture;
layer.x = x;
layer.y = y;
layer.w = w;
layer.h = h;

// Swap the buffers
if(mainMetalView)
[mainMetalView draw];
}
}

@end

id<MTLDevice>
getMainWindowMetalDevice(void) {
return mainMetalView ? mainMetalView.device : nil;
}


id<MTLCommandQueue>
getMainWindowMetalCommandQueue(void) {
return mainMetalView ? mainMetalView.graphicsCommandQueue : nil;
}

unsigned int
createMetalTextureLayerHandle(void) {
return mainMetalView ? [ mainMetalView createTextureLayerHandle ] : 0;
}

void
destroyMetalTextureLayerHandle(unsigned int handle) {
if(!mainMetalView)
return;

[ mainMetalView destroyTextureLayerHandle: handle ];
}

void
setMetalTextureLayerContent(unsigned int handle, id<MTLTexture> texture, int x, int y, int w, int h) {
if(!mainMetalView)
return;

[ mainMetalView setExtraLayer: handle texture: texture x: x y: y w: w h: h];
}

#endif // USE_METAL
2 changes: 1 addition & 1 deletion platforms/iOS/vm/SqueakPureObjc_Prefix.pch
Expand Up @@ -10,7 +10,7 @@
#endif

#if __has_feature(objc_arc)
# define RELEASEOBJ(o) o
# define RELEASEOBJ(o) (void)o
# define RETAINOBJ(o) o
# define AUTORELEASEOBJ(o) o
# define SUPERDEALLOC
Expand Down