Skip to content
Browse files

Use ARC

  • Loading branch information...
1 parent 5be306a commit 933b29352a1852470d93ae8612f806ad1a1de3c8 @phoboslab committed Feb 10, 2013
Showing with 325 additions and 510 deletions.
  1. +2 −0 Ejecta.xcodeproj/project.pbxproj
  2. +1 −1 Source/AppDelegate.h
  3. +2 −10 Source/AppDelegate.m
  4. +0 −3 Source/Ejecta/EJAppViewController.m
  5. +2 −2 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.h
  6. +1 −7 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.m
  7. +2 −2 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.h
  8. +2 −5 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.m
  9. +1 −1 Source/Ejecta/EJAudio/EJBindingAudio.h
  10. +2 −11 Source/Ejecta/EJAudio/EJBindingAudio.m
  11. +3 −5 Source/Ejecta/EJAudio/EJOpenALBuffer.m
  12. +1 −3 Source/Ejecta/EJAudio/EJOpenALManager.m
  13. +12 −11 Source/Ejecta/EJBindingBase.h
  14. +6 −9 Source/Ejecta/EJBindingBase.m
  15. +1 −7 Source/Ejecta/EJBindingEjectaCore.m
  16. +5 −5 Source/Ejecta/EJBindingEventedBase.h
  17. +0 −3 Source/Ejecta/EJBindingEventedBase.m
  18. +35 −38 Source/Ejecta/EJCanvas/2D/EJBindingCanvasContext2D.m
  19. +2 −6 Source/Ejecta/EJCanvas/2D/EJBindingCanvasGradient.m
  20. +2 −6 Source/Ejecta/EJCanvas/2D/EJBindingCanvasPattern.m
  21. +1 −1 Source/Ejecta/EJCanvas/2D/EJBindingImageData.h
  22. +1 −3 Source/Ejecta/EJCanvas/2D/EJBindingImageData.m
  23. +26 −28 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.h
  24. +99 −121 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.m
  25. +4 −8 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DScreen.m
  26. +1 −1 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.h
  27. +5 −10 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.m
  28. +1 −1 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.h
  29. +0 −6 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.m
  30. +2 −2 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.h
  31. +0 −4 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.m
  32. +18 −33 Source/Ejecta/EJCanvas/2D/EJFont.mm
  33. +0 −1 Source/Ejecta/EJCanvas/2D/EJGLProgram2D.m
  34. +1 −1 Source/Ejecta/EJCanvas/2D/EJImageData.h
  35. +2 −6 Source/Ejecta/EJCanvas/2D/EJImageData.m
  36. +1 −1 Source/Ejecta/EJCanvas/2D/EJPath.h
  37. +20 −21 Source/Ejecta/EJCanvas/2D/EJPath.mm
  38. +1 −1 Source/Ejecta/EJCanvas/EJBindingCanvas.h
  39. +0 −2 Source/Ejecta/EJCanvas/EJBindingCanvas.m
  40. +3 −10 Source/Ejecta/EJCanvas/EJBindingImage.m
  41. +1 −1 Source/Ejecta/EJCanvas/EJCanvasContext.h
  42. +1 −1 Source/Ejecta/EJCanvas/EJTexture.h
  43. +6 −17 Source/Ejecta/EJCanvas/EJTexture.m
  44. +2 −2 Source/Ejecta/EJCanvas/WebGL/EJBindingCanvasContextWebGL.h
  45. +3 −11 Source/Ejecta/EJCanvas/WebGL/EJBindingCanvasContextWebGL.m
  46. +5 −20 Source/Ejecta/EJCanvas/WebGL/EJBindingWebGLObjects.m
  47. +1 −1 Source/Ejecta/EJCanvas/WebGL/EJCanvasContextWebGL.h
  48. +2 −4 Source/Ejecta/EJCanvas/WebGL/EJCanvasContextWebGL.m
  49. +4 −0 Source/Ejecta/EJConvert.h
  50. +2 −3 Source/Ejecta/EJConvert.m
  51. +3 −3 Source/Ejecta/EJJavaScriptView.h
  52. +1 −1 Source/Ejecta/EJJavaScriptView.m
  53. +1 −7 Source/Ejecta/EJTimer.m
  54. +0 −3 Source/Ejecta/EJUtils.h
  55. +2 −6 Source/Ejecta/EJUtils.m
  56. +0 −2 Source/Ejecta/EJUtils/EJBindingAdBanner.m
  57. +4 −8 Source/Ejecta/EJUtils/EJBindingGameCenter.m
  58. +19 −23 Source/Ejecta/EJUtils/EJBindingHttpRequest.m
  59. +0 −1 Source/Ejecta/EJUtils/EJBindingTouchInput.m
View
2 Ejecta.xcodeproj/project.pbxproj
@@ -670,6 +670,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COMPRESS_PNG_FILES = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
@@ -695,6 +696,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COMPRESS_PNG_FILES = NO;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
View
2 Source/AppDelegate.h
@@ -3,7 +3,7 @@
@interface AppDelegate : NSObject <UIApplicationDelegate>
-@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) EJAppViewController *ejApp;
@end
View
12 Source/AppDelegate.m
@@ -9,20 +9,12 @@ @implementation AppDelegate
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- //Optionally set the idle timer disabled, this prevents the device from sleep when not being interacted with by touch. ie. games with motion control.
+ //Optionally set the idle timer disabled, this prevents the device from sleep when not
+ // being interacted with by touch. ie. games with motion control.
[application setIdleTimerDisabled:YES];
self.ejApp = [EJAppViewController instance];
window.rootViewController = self.ejApp;
return YES;
}
-#pragma mark -
-#pragma mark Memory management
-
-- (void)dealloc {
- [self.ejApp release];
- [super dealloc];
-}
-
-
@end
View
3 Source/Ejecta/EJAppViewController.m
@@ -36,9 +36,6 @@ +(id)alloc {
return nil;
}
-- (void)dealloc {
- [super dealloc];
-}
- (void)didReceiveMemoryWarning {
[[EJJavaScriptView sharedView] clearCaches];
View
4 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.h
@@ -6,11 +6,11 @@
@interface EJAudioSourceAVAudio : NSObject <EJAudioSource, AVAudioPlayerDelegate> {
NSString *path;
AVAudioPlayer *player;
- NSObject<EJAudioSourceDelegate> *delegate;
+ NSObject<EJAudioSourceDelegate> *__weak delegate;
}
@property (nonatomic) float currentTime;
@property (nonatomic) float duration;
-@property (nonatomic, assign) NSObject<EJAudioSourceDelegate> *delegate;
+@property (nonatomic, weak) NSObject<EJAudioSourceDelegate> *delegate;
@end
View
8 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.m
@@ -7,19 +7,13 @@ @implementation EJAudioSourceAVAudio
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
player.delegate = self;
}
return self;
}
-- (void)dealloc {
- [path release];
- [player release];
-
- [super dealloc];
-}
- (void)play {
[player play];
View
4 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.h
@@ -14,11 +14,11 @@
BOOL looping;
NSTimer *endTimer;
- NSObject<EJAudioSourceDelegate> *delegate;
+ NSObject<EJAudioSourceDelegate> *__weak delegate;
}
@property (nonatomic) float currentTime;
@property (nonatomic) float duration;
-@property (nonatomic, assign) NSObject<EJAudioSourceDelegate> *delegate;
+@property (nonatomic, weak) NSObject<EJAudioSourceDelegate> *delegate;
@end
View
7 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.m
@@ -7,9 +7,9 @@ @implementation EJAudioSourceOpenAL
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
- buffer = [[EJOpenALBuffer cachedBufferWithPath:pathp] retain];
+ buffer = [EJOpenALBuffer cachedBufferWithPath:pathp];
alGenSources(1, &sourceId);
alSourcei(sourceId, AL_BUFFER, buffer.bufferId);
@@ -24,11 +24,8 @@ - (void)dealloc {
alDeleteSources(1, &sourceId);
}
- [buffer release];
- [path release];
[endTimer invalidate];
- [super dealloc];
}
- (void)play {
View
2 Source/Ejecta/EJAudio/EJBindingAudio.h
@@ -30,7 +30,7 @@ typedef enum {
@property (nonatomic) BOOL loop;
@property (nonatomic) BOOL ended;
@property (nonatomic) float volume;
-@property (nonatomic, retain) NSString *path;
+@property (nonatomic, strong) NSString *path;
@property (nonatomic) EJAudioPreload preload;
@end
View
13 Source/Ejecta/EJAudio/EJBindingAudio.m
@@ -20,19 +20,12 @@ - (id)initWithContext:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef
return self;
}
-- (void)dealloc {
- [source release];
- [path release];
- [super dealloc];
-}
- (void)setSourcePath:(NSString *)pathp {
if( !path || ![path isEqualToString:pathp] ) {
- [path release];
- [source release];
source = NULL;
- path = [pathp retain];
+ path = pathp;
if( preload != kEJAudioPreloadNone ) {
[self load];
}
@@ -54,7 +47,6 @@ - (void)load {
selector:@selector(loadOperation:) object:fullPath];
loadOp.threadPriority = 0.2;
[[EJJavaScriptView sharedView].opQueue addOperation:loadOp];
- [loadOp release];
}
- (void)loadOperation:(NSString *)fullPath {
@@ -72,14 +64,13 @@ - (void)loadOperation:(NSString *)fullPath {
src = [[EJAudioSourceAVAudio alloc] initWithPath:fullPath];
}
src.delegate = self;
- [src autorelease];
[self performSelectorOnMainThread:@selector(endLoad:) withObject:src waitUntilDone:NO];
}
}
- (void)endLoad:(NSObject<EJAudioSource> *)src {
- source = [src retain];
+ source = src;
[source setLooping:loop];
[source setVolume:volume];
View
8 Source/Ejecta/EJAudio/EJOpenALBuffer.m
@@ -10,7 +10,7 @@ @implementation EJOpenALBuffer
@synthesize duration;
+ (id)cachedBufferWithPath:(NSString *)path {
- EJOpenALBuffer *buffer = [[EJJavaScriptView sharedView].openALManager.buffers[path] retain];
+ EJOpenALBuffer *buffer = [EJJavaScriptView sharedView].openALManager.buffers[path];
if( !buffer ) {
buffer = [[EJOpenALBuffer alloc] initWithPath:path];
[EJJavaScriptView sharedView].openALManager.buffers[path] = buffer;
@@ -20,7 +20,7 @@ + (id)cachedBufferWithPath:(NSString *)path {
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
NSURL *url = [NSURL fileURLWithPath:pathp];
void *data = [self getAudioDataWithURL:url];
@@ -35,12 +35,10 @@ - (id)initWithPath:(NSString *)pathp {
- (void)dealloc {
[[EJJavaScriptView sharedView].openALManager.buffers removeObjectForKey:path];
- [path release];
if( bufferId ) {
alDeleteBuffers(1, &bufferId);
}
- [super dealloc];
}
- (void*)getAudioDataWithURL:(NSURL *)url {
@@ -49,7 +47,7 @@ - (void*)getAudioDataWithURL:(NSURL *)url {
// Open the file
ExtAudioFileRef file = NULL;
- OSStatus error = ExtAudioFileOpenURL((CFURLRef)url, &file);
+ OSStatus error = ExtAudioFileOpenURL((__bridge CFURLRef)url, &file);
if( error ) {
NSLog(@"OpenALSource: ExtAudioFileOpenURL FAILED, Error = %ld", error);
goto Exit;
View
4 Source/Ejecta/EJAudio/EJOpenALManager.m
@@ -6,7 +6,7 @@ @implementation EJOpenALManager
-(id)init {
if( self = [super init] ) {
// Create a non-retaining Dictionary to hold the cached buffers
- buffers = (NSMutableDictionary*)CFDictionaryCreateMutable(NULL, 8, &kCFCopyStringDictionaryKeyCallBacks, NULL);
+ buffers = (NSMutableDictionary*)CFBridgingRelease(CFDictionaryCreateMutable(NULL, 8, &kCFCopyStringDictionaryKeyCallBacks, NULL));
device = alcOpenDevice(NULL);
if( device ) {
@@ -18,11 +18,9 @@ -(id)init {
}
- (void)dealloc {
- [buffers release];
alcDestroyContext( context );
alcCloseDevice( device );
- [super dealloc];
}
@end
View
23 Source/Ejecta/EJBindingBase.h
@@ -39,10 +39,11 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
size_t argc, \
const JSValueRef argv[], \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
- JSValueRef ret = (JSValueRef)objc_msgSend(instance, @selector(_func_##NAME:argc:argv:), ctx, argc, argv); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
+ JSValueRef ret = (__bridge JSValueRef)objc_msgSend( \
+ instance, @selector(_func_##NAME:argc:argv:), ctx, argc, argv); \
return ret ? ret : ej_global_undefined; \
} \
__EJ_GET_POINTER_TO(_func_##NAME)\
@@ -61,10 +62,10 @@ extern JSValueRef ej_global_undefined;
JSContextRef ctx, \
JSObjectRef object, \
JSStringRef propertyName, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
- return (JSValueRef)objc_msgSend(instance, @selector(_get_##NAME:), ctx); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
+ return (__bridge JSValueRef)objc_msgSend(instance, @selector(_get_##NAME:), ctx); \
} \
__EJ_GET_POINTER_TO(_get_##NAME)\
\
@@ -83,9 +84,9 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
JSStringRef propertyName, \
JSValueRef value, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
objc_msgSend(instance, @selector(_set_##NAME:value:), ctx, value); \
return true; \
} \
@@ -106,7 +107,7 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
size_t argc, \
const JSValueRef argv[], \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
static bool didShowWarning; \
if( !didShowWarning ) { \
@@ -136,7 +137,7 @@ extern JSValueRef ej_global_undefined;
JSStringRef _str = JSValueToStringCopy(ctx, value, NULL); \
const JSChar *_strptr = JSStringGetCharactersPtr( _str ); \
int _length = JSStringGetLength(_str)-1; \
- const char ** _names = _##NAME##EnumNames; \
+ const char **_names = _##NAME##EnumNames; \
int _target; \
EJ_MAP_EXT(0, _EJ_LITERAL(else), _EJ_BIND_ENUM_COMPARE, __VA_ARGS__) \
else { JSStringRelease( _str ); return; } \
@@ -164,7 +165,7 @@ static inline bool JSStrIsEqualToStr( const JSChar *s1, const char *s2, int leng
JSContextRef ctx, \
JSObjectRef object, \
JSStringRef propertyName, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
return JSValueMakeNumber(ctx, VALUE); \
} \
View
15 Source/Ejecta/EJBindingBase.m
@@ -3,8 +3,8 @@
void _ej_class_finalize(JSObjectRef object) {
- id instance = (id)JSObjectGetPrivate(object);
- [instance release];
+ id instance;
+ instance = (__bridge_transfer id)JSObjectGetPrivate(object);
}
NSData *NSDataFromString( NSString *str ) {
@@ -45,7 +45,6 @@ + (JSClassRef)getJSClass {
}
+ (void)clearJSClassCache {
- [CachedJSClasses release];
CachedJSClasses = NULL;
}
@@ -88,12 +87,12 @@ + (JSClassRef)createJSClass {
values[i].attributes = kJSPropertyAttributeDontDelete;
SEL get = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_get_%@", name]);
- values[i].getProperty = (JSObjectGetPropertyCallback)[self performSelector:get];
+ values[i].getProperty = (__bridge void *)objc_msgSend(self, get);
// Property has a setter? Otherwise mark as read only
SEL set = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_set_%@", name]);
if( [self respondsToSelector:set] ) {
- values[i].setProperty = (JSObjectSetPropertyCallback)[self performSelector:set];
+ values[i].setProperty = (__bridge void *)objc_msgSend(self, set);
}
else {
values[i].attributes |= kJSPropertyAttributeReadOnly;
@@ -110,7 +109,7 @@ + (JSClassRef)createJSClass {
functions[i].attributes = kJSPropertyAttributeDontDelete;
SEL call = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_func_%@", name]);
- functions[i].callAsFunction = (JSObjectCallAsFunctionCallback)[self performSelector:call];
+ functions[i].callAsFunction = (__bridge void *)objc_msgSend(self, call);
}
JSClassDefinition classDef = kJSClassDefinitionEmpty;
@@ -123,8 +122,6 @@ + (JSClassRef)createJSClass {
free( values );
free( functions );
- [properties release];
- [methods release];
return class;
}
@@ -133,7 +130,7 @@ + (JSObjectRef)createJSObjectWithContext:(JSContextRef)ctx instance:(EJBindingBa
JSClassRef jsClass = [self getJSClass];
JSObjectRef obj = JSObjectMake( ctx, jsClass, NULL );
- JSObjectSetPrivate( obj, (void *)instance );
+ JSObjectSetPrivate( obj, (__bridge_retained void *)instance );
instance->jsObject = obj;
return obj;
View
8 Source/Ejecta/EJBindingEjectaCore.m
@@ -8,11 +8,9 @@
@implementation EJBindingEjectaCore
- (void)dealloc {
- [urlToOpen release];
if( getTextCallback ) {
JSValueUnprotect([EJJavaScriptView sharedView].jsGlobalContext, getTextCallback);
}
- [super dealloc];
}
EJ_BIND_FUNCTION(log, ctx, argc, argv ) {
@@ -58,14 +56,12 @@ - (void)dealloc {
NSString *url = JSValueToNSString( ctx, argv[0] );
if( argc == 2 ) {
- [urlToOpen release];
- urlToOpen = [url retain];
+ urlToOpen = url;
NSString *confirm = JSValueToNSString( ctx, argv[1] );
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open Browser?" message:confirm delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alert.tag = kEJCoreAlertViewOpenURL;
[alert show];
- [alert release];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
@@ -90,7 +86,6 @@ - (void)dealloc {
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = kEJCoreAlertViewGetText;
[alert show];
- [alert release];
return NULL;
}
@@ -99,7 +94,6 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)index
if( index == 1 ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlToOpen]];
}
- [urlToOpen release];
urlToOpen = nil;
}
View
10 Source/Ejecta/EJBindingEventedBase.h
@@ -9,10 +9,10 @@
JSContextRef ctx, \
JSObjectRef object, \
JSStringRef propertyName, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
- return (JSValueRef)objc_msgSend(instance, @selector(getCallbackWith:ctx:), ( @ #NAME), ctx); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
+ return (__bridge JSValueRef)objc_msgSend(instance, @selector(getCallbackWith:ctx:), ( @ #NAME), ctx); \
} \
__EJ_GET_POINTER_TO(_get_on##NAME) \
\
@@ -21,9 +21,9 @@
JSObjectRef object, \
JSStringRef propertyName, \
JSValueRef value, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
objc_msgSend(instance, @selector(setCallbackWith:ctx:callback:), ( @ #NAME), ctx, value); \
return true; \
} \
View
3 Source/Ejecta/EJBindingEventedBase.m
@@ -21,16 +21,13 @@ - (void)dealloc {
JSValueUnprotect(ctx, [callbackValue pointerValue]);
}
}
- [eventListeners release];
// Unprotect all event callbacks
for( NSString *name in onCallbacks ) {
NSValue *listener = onCallbacks[name];
JSValueUnprotect(ctx, [(NSValue *)listener pointerValue]);
}
- [onCallbacks release];
- [super dealloc];
}
- (JSObjectRef)getCallbackWith:(NSString *)name ctx:(JSContextRef)ctx {
View
73 Source/Ejecta/EJCanvas/2D/EJBindingCanvasContext2D.m
@@ -19,16 +19,12 @@ @implementation EJBindingCanvasContext2D
- (id)initWithCanvas:(JSObjectRef)canvas renderingContext:(EJCanvasContext2D *)renderingContextp {
if( self = [super initWithContext:NULL argc:0 argv:NULL] ) {
jsView = [EJJavaScriptView sharedView]; // Keep a local copy - may be faster?
- renderingContext = [renderingContextp retain];
+ renderingContext = renderingContextp;
jsCanvas = canvas;
}
return self;
}
-- (void)dealloc {
- [renderingContext release];
- [super dealloc];
-}
EJ_BIND_GET(canvas, ctx) {
return jsCanvas;
@@ -44,27 +40,27 @@ - (void)dealloc {
"xor" // kEJCompositeOperationXOR
);
-EJ_BIND_ENUM(lineCap, renderingContext.state->lineCap,
+EJ_BIND_ENUM(lineCap, renderingContext.state.lineCap,
"butt", // kEJLineCapButt
"round", // kEJLineCapRound
"square" // kEJLineCapSquare
);
-EJ_BIND_ENUM(lineJoin, renderingContext.state->lineJoin,
+EJ_BIND_ENUM(lineJoin, renderingContext.state.lineJoin,
"miter", // kEJLineJoinMiter
"bevel", // kEJLineJoinBevel
"round" // kEJLineJoinRound
);
-EJ_BIND_ENUM(textAlign, renderingContext.state->textAlign,
+EJ_BIND_ENUM(textAlign, renderingContext.state.textAlign,
"start", // kEJTextAlignStart
"end", // kEJTextAlignEnd
"left", // kEJTextAlignLeft
"center", // kEJTextAlignCenter
"right" // kEJTextAlignRight
);
-EJ_BIND_ENUM(textBaseline, renderingContext.state->textBaseline,
+EJ_BIND_ENUM(textBaseline, renderingContext.state.textBaseline,
"alphabetic", // kEJTextBaselineAlphabetic
"middle", // kEJTextBaselineMiddle
"top", // kEJTextBaselineTop
@@ -74,18 +70,19 @@ - (void)dealloc {
);
EJ_BIND_GET(fillStyle, ctx ) {
- if( renderingContext.fillObject ) {
- if( [renderingContext.fillObject isKindOfClass:[EJCanvasPattern class]] ) {
- EJCanvasPattern *pattern = (EJCanvasPattern *)renderingContext.fillObject;
+ NSObject<EJFillable> *fillable = renderingContext.state.fillObject;
+ if( fillable ) {
+ if( [fillable isKindOfClass:[EJCanvasPattern class]] ) {
+ EJCanvasPattern *pattern = (EJCanvasPattern *)fillable;
return [EJBindingCanvasPattern createJSObjectWithContext:ctx pattern:pattern];
}
- else if( [renderingContext.fillObject isKindOfClass:[EJCanvasGradient class]] ) {
- EJCanvasGradient *gradient = (EJCanvasGradient *)renderingContext.fillObject;
+ else if( [fillable isKindOfClass:[EJCanvasGradient class]] ) {
+ EJCanvasGradient *gradient = (EJCanvasGradient *)fillable;
return [EJBindingCanvasGradient createJSObjectWithContext:ctx gradient:gradient];
}
}
else {
- return ColorRGBAToJSValue(ctx, renderingContext.state->fillColor);
+ return ColorRGBAToJSValue(ctx, renderingContext.state.fillColor);
}
return NULL;
@@ -97,53 +94,53 @@ - (void)dealloc {
NSObject<EJFillable> *fillable;
if( (fillable = [EJBindingCanvasPattern patternFromJSValue:value]) ) {
- renderingContext.fillObject = fillable;
+ renderingContext.state.fillObject = fillable;
}
else if( (fillable = [EJBindingCanvasGradient gradientFromJSValue:value]) ) {
- renderingContext.fillObject = fillable;
+ renderingContext.state.fillObject = fillable;
}
}
else {
// Should be a color string
- renderingContext.state->fillColor = JSValueToColorRGBA(ctx, value);
- renderingContext.fillObject = NULL;
+ renderingContext.state.fillColor = JSValueToColorRGBA(ctx, value);
+ renderingContext.state.fillObject = NULL;
}
}
EJ_BIND_GET(strokeStyle, ctx ) {
- return ColorRGBAToJSValue(ctx, renderingContext.state->strokeColor);
+ return ColorRGBAToJSValue(ctx, renderingContext.state.strokeColor);
}
EJ_BIND_SET(strokeStyle, ctx, value) {
- renderingContext.state->strokeColor = JSValueToColorRGBA(ctx, value);
+ renderingContext.state.strokeColor = JSValueToColorRGBA(ctx, value);
}
EJ_BIND_GET(globalAlpha, ctx ) {
- return JSValueMakeNumber(ctx, renderingContext.state->globalAlpha );
+ return JSValueMakeNumber(ctx, renderingContext.state.globalAlpha );
}
EJ_BIND_SET(globalAlpha, ctx, value) {
- renderingContext.state->globalAlpha = MIN(1,MAX(JSValueToNumberFast(ctx, value),0));
+ renderingContext.state.globalAlpha = MIN(1,MAX(JSValueToNumberFast(ctx, value),0));
}
EJ_BIND_GET(lineWidth, ctx) {
- return JSValueMakeNumber(ctx, renderingContext.state->lineWidth);
+ return JSValueMakeNumber(ctx, renderingContext.state.lineWidth);
}
EJ_BIND_SET(lineWidth, ctx, value) {
- renderingContext.state->lineWidth = JSValueToNumberFast(ctx, value);
+ renderingContext.state.lineWidth = JSValueToNumberFast(ctx, value);
}
EJ_BIND_GET(miterLimit, ctx) {
- return JSValueMakeNumber(ctx, renderingContext.state->miterLimit);
+ return JSValueMakeNumber(ctx, renderingContext.state.miterLimit);
}
EJ_BIND_SET(miterLimit, ctx, value) {
- renderingContext.state->miterLimit = JSValueToNumberFast(ctx, value);
+ renderingContext.state.miterLimit = JSValueToNumberFast(ctx, value);
}
EJ_BIND_GET(font, ctx) {
- EJFontDescriptor *font = renderingContext.state->font;
+ EJFontDescriptor *font = renderingContext.state.font;
NSString *name = [NSString stringWithFormat:@"%dpx %@", (int)font.size, font.name];
return NSStringToJSValue(ctx, name);
}
@@ -165,7 +162,7 @@ - (void)dealloc {
EJFontDescriptor *font = [EJFontDescriptor descriptorWithName:@(name) size:size];
if( font ) {
- renderingContext.font = font;
+ renderingContext.state.font = font;
}
JSStringRelease(jsString);
@@ -227,7 +224,7 @@ - (void)dealloc {
EJ_BIND_FUNCTION(drawImage, ctx, argc, argv) {
if( argc < 3 || !JSValueIsObject(ctx, argv[0]) ) return NULL;
- NSObject<EJDrawable> *drawable = (NSObject<EJDrawable> *)JSObjectGetPrivate((JSObjectRef)argv[0]);
+ NSObject<EJDrawable> *drawable = JSValueGetNativeObject(argv[0]);
EJTexture *image = drawable.texture;
float scale = image.contentScale;
@@ -305,7 +302,7 @@ - (void)dealloc {
EJ_UNPACK_ARGV(short sw, short sh);
NSMutableData *pixels = [NSMutableData dataWithLength:sw * sh * 4];
- EJImageData *imageData = [[[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels] autorelease];
+ EJImageData *imageData = [[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels];
EJBindingImageData *binding = [[EJBindingImageData alloc] initWithImageData:imageData];
return [EJBindingImageData createJSObjectWithContext:ctx instance:binding];
@@ -314,7 +311,7 @@ - (void)dealloc {
EJ_BIND_FUNCTION(putImageData, ctx, argc, argv) {
if( argc < 3 ) { return NULL; }
- EJBindingImageData *jsImageData = (EJBindingImageData *)JSObjectGetPrivate((JSObjectRef)argv[0]);
+ EJBindingImageData *jsImageData = JSValueGetNativeObject(argv[0]);
EJ_UNPACK_ARGV_OFFSET(1, float dx, float dy);
jsView.currentRenderingContext = renderingContext;
@@ -337,7 +334,7 @@ - (void)dealloc {
EJ_UNPACK_ARGV(short sw, short sh);
NSMutableData *pixels = [NSMutableData dataWithLength:sw * sh * 4];
- EJImageData *imageData = [[[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels] autorelease];
+ EJImageData *imageData = [[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels];
EJBindingImageData *binding = [[EJBindingImageData alloc] initWithImageData:imageData];
return [EJBindingImageData createJSObjectWithContext:ctx instance:binding];
@@ -346,7 +343,7 @@ - (void)dealloc {
EJ_BIND_FUNCTION(putImageDataHD, ctx, argc, argv) {
if( argc < 3 ) { return NULL; }
- EJBindingImageData *jsImageData = (EJBindingImageData *)JSObjectGetPrivate((JSObjectRef)argv[0]);
+ EJBindingImageData *jsImageData = JSValueGetNativeObject(argv[0]);
EJ_UNPACK_ARGV_OFFSET(1, float dx, float dy);
jsView.currentRenderingContext = renderingContext;
@@ -358,7 +355,7 @@ - (void)dealloc {
EJVector2 p1, p2;
EJ_UNPACK_ARGV(p1.x, p1.y, p2.x, p2.y);
- EJCanvasGradient *gradient = [[[EJCanvasGradient alloc] initLinearGradientWithP1:p1 p2:p2] autorelease];
+ EJCanvasGradient *gradient = [[EJCanvasGradient alloc] initLinearGradientWithP1:p1 p2:p2];
return [EJBindingCanvasGradient createJSObjectWithContext:ctx gradient:gradient];
}
@@ -367,13 +364,13 @@ - (void)dealloc {
float r1, r2;
EJ_UNPACK_ARGV(p1.x, p1.y, r1, p2.x, p2.y, r2);
- EJCanvasGradient *gradient = [[[EJCanvasGradient alloc] initRadialGradientWithP1:p1 r1:r1 p2:p2 r2:r2] autorelease];
+ EJCanvasGradient *gradient = [[EJCanvasGradient alloc] initRadialGradientWithP1:p1 r1:r1 p2:p2 r2:r2];
return [EJBindingCanvasGradient createJSObjectWithContext:ctx gradient:gradient];
}
EJ_BIND_FUNCTION(createPattern, ctx, argc, argv) {
if( argc < 1 ) { return NULL; }
- NSObject<EJDrawable> *drawable = (NSObject<EJDrawable> *)JSObjectGetPrivate((JSObjectRef)argv[0]);
+ NSObject<EJDrawable> *drawable = JSValueGetNativeObject(argv[0]);
EJTexture *image = drawable.texture;
if( !image ) { return NULL; }
@@ -391,7 +388,7 @@ - (void)dealloc {
repeat = kEJCanvasPatternNoRepeat;
}
}
- EJCanvasPattern *pattern = [[[EJCanvasPattern alloc] initWithTexture:image repeat:repeat] autorelease];
+ EJCanvasPattern *pattern = [[EJCanvasPattern alloc] initWithTexture:image repeat:repeat];
return [EJBindingCanvasPattern createJSObjectWithContext:ctx pattern:pattern];
}
View
8 Source/Ejecta/EJCanvas/2D/EJBindingCanvasGradient.m
@@ -5,22 +5,18 @@ @implementation EJBindingCanvasGradient
+ (JSObjectRef)createJSObjectWithContext:(JSContextRef)ctx gradient:(EJCanvasGradient *)gradient {
EJBindingCanvasGradient *binding = [[EJBindingCanvasGradient alloc] initWithContext:ctx argc:0 argv:NULL];
- binding->gradient = [gradient retain];
+ binding->gradient = gradient;
return [self createJSObjectWithContext:ctx instance:binding];
}
+ (EJCanvasGradient *)gradientFromJSValue:(JSValueRef)value {
if( !value ) { return NULL; }
- EJBindingCanvasGradient *binding = (EJBindingCanvasGradient *)JSObjectGetPrivate((JSObjectRef)value);
+ EJBindingCanvasGradient *binding = JSValueGetNativeObject(value);
return (binding && [binding isMemberOfClass:[EJBindingCanvasGradient class]]) ? binding->gradient : NULL;
}
-- (void)dealloc {
- [gradient release];
- [super dealloc];
-}
EJ_BIND_FUNCTION(addColorStop, ctx, argc, argv) {
if( argc < 2 ) { return NULL; }
View
8 Source/Ejecta/EJCanvas/2D/EJBindingCanvasPattern.m
@@ -4,21 +4,17 @@ @implementation EJBindingCanvasPattern
+ (JSObjectRef)createJSObjectWithContext:(JSContextRef)ctx pattern:(EJCanvasPattern *)pattern {
EJBindingCanvasPattern *binding = [[EJBindingCanvasPattern alloc] initWithContext:ctx argc:0 argv:NULL];
- binding->pattern = [pattern retain];
+ binding->pattern = pattern;
return [self createJSObjectWithContext:ctx instance:binding];
}
+ (EJCanvasPattern *)patternFromJSValue:(JSValueRef)value {
if( !value ) { return NULL; }
- EJBindingCanvasPattern *binding = (EJBindingCanvasPattern *)JSObjectGetPrivate((JSObjectRef)value);
+ EJBindingCanvasPattern *binding = JSValueGetNativeObject(value);
return (binding && [binding isMemberOfClass:[EJBindingCanvasPattern class]]) ? binding->pattern : NULL;
}
-- (void)dealloc {
- [pattern release];
- [super dealloc];
-}
@end
View
2 Source/Ejecta/EJCanvas/2D/EJBindingImageData.h
@@ -10,6 +10,6 @@
- (id)initWithImageData:(EJImageData *)data;
@property (readonly, nonatomic) EJImageData *imageData;
-@property (readonly, nonatomic) EJTexture *texture;
+@property (weak, readonly, nonatomic) EJTexture *texture;
@end
View
4 Source/Ejecta/EJCanvas/2D/EJBindingImageData.m
@@ -7,7 +7,7 @@ @implementation EJBindingImageData
- (id)initWithImageData:(EJImageData *)data {
if( self = [super initWithContext:NULL argc:0 argv:NULL] ) {
- imageData = [data retain];
+ imageData = data;
dataArray = NULL;
}
return self;
@@ -19,8 +19,6 @@ - (void)dealloc {
JSValueUnprotect(ctx, dataArray);
}
- [imageData release];
- [super dealloc];
}
- (EJImageData *)imageData {
View
54 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.h
@@ -7,7 +7,6 @@
#import "EJFont.h"
#import "EJGLProgram2D.h"
-#define EJ_CANVAS_STATE_STACK_SIZE 16
#define EJ_CANVAS_VERTEX_BUFFER_SIZE 1600 // 1600 * 20b = ~32kb
extern EJVertex EJCanvasVertexBuffer[EJ_CANVAS_VERTEX_BUFFER_SIZE];
@@ -57,26 +56,30 @@ typedef enum {
@protocol EJFillable
@end
-typedef struct {
- CGAffineTransform transform;
-
- EJCompositeOperation globalCompositeOperation;
- EJColorRGBA fillColor;
- NSObject<EJFillable> *fillObject;
- EJColorRGBA strokeColor;
- float globalAlpha;
-
- float lineWidth;
- EJLineCap lineCap;
- EJLineJoin lineJoin;
- float miterLimit;
-
- EJTextAlign textAlign;
- EJTextBaseline textBaseline;
- EJFontDescriptor *font;
-
- EJPath *clipPath;
-} EJCanvasState;
+
+@interface EJCanvasState : NSObject <NSCopying>
+
+@property (nonatomic) CGAffineTransform transform;
+
+@property (nonatomic) EJCompositeOperation globalCompositeOperation;
+@property (nonatomic) EJColorRGBA fillColor;
+@property (nonatomic, retain) NSObject<EJFillable> *fillObject;
+@property (nonatomic) EJColorRGBA strokeColor;
+@property (nonatomic) float globalAlpha;
+
+@property (nonatomic) float lineWidth;
+@property (nonatomic) EJLineCap lineCap;
+@property (nonatomic) EJLineJoin lineJoin;
+@property (nonatomic) float miterLimit;
+
+@property (nonatomic) EJTextAlign textAlign;
+@property (nonatomic) EJTextBaseline textBaseline;
+@property (nonatomic, strong) EJFontDescriptor *font;
+
+@property (nonatomic, strong) EJPath *clipPath;
+
+@end
+
@class EJJavaScriptView;
@interface EJCanvasContext2D : EJCanvasContext {
@@ -94,12 +97,9 @@ typedef struct {
int vertexBufferIndex;
int stateIndex;
- EJCanvasState stateStack[EJ_CANVAS_STATE_STACK_SIZE];
+ NSMutableArray *stateStack;
EJCanvasState *state;
- BOOL useRetinaResolution;
- float backingStoreRatio;
-
NSCache *fontCache;
EJJavaScriptView *app;
@@ -177,10 +177,8 @@ typedef struct {
- (void)clip;
- (void)resetClip;
-@property (nonatomic) EJCanvasState *state;
+@property (nonatomic, readonly) EJCanvasState *state;
@property (nonatomic) EJCompositeOperation globalCompositeOperation;
-@property (nonatomic, retain) EJFontDescriptor *font;
-@property (nonatomic, retain) NSObject<EJFillable> *fillObject;
@property (nonatomic, assign) float backingStoreRatio;
@property (nonatomic) BOOL useRetinaResolution;
@property (nonatomic) BOOL imageSmoothingEnabled;
View
220 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.m
@@ -5,6 +5,36 @@
#import "EJCanvasPattern.h"
#import "EJCanvasGradient.h"
+
+@implementation EJCanvasState
+- (id)copyWithZone:(NSZone *)zone {
+ EJCanvasState * copy = [[EJCanvasState allocWithZone:zone] init];
+
+ copy->_transform = _transform;
+
+ copy->_globalCompositeOperation = _globalCompositeOperation;
+ copy->_fillColor = _fillColor;
+ copy->_fillObject = _fillObject;
+ copy->_strokeColor = _strokeColor;
+ copy->_globalAlpha = _globalAlpha;
+
+ copy->_lineWidth = _lineWidth;
+ copy->_lineCap = _lineCap;
+ copy->_lineJoin = _lineJoin;
+ copy->_miterLimit = _miterLimit;
+
+ copy->_textAlign = _textAlign;
+ copy->_textBaseline = _textBaseline;
+ copy->_font = _font;
+
+ copy->_clipPath = _clipPath;
+ return copy;
+}
+
+@end
+
+
+
@implementation EJCanvasContext2D
EJVertex EJCanvasVertexBuffer[EJ_CANVAS_VERTEX_BUFFER_SIZE];
@@ -19,31 +49,29 @@ @implementation EJCanvasContext2D
[kEJCompositeOperationXOR] = {GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
};
-
@synthesize state;
-@synthesize backingStoreRatio;
-@synthesize useRetinaResolution;
-@synthesize imageSmoothingEnabled;
- (id)initWithWidth:(short)widthp height:(short)heightp {
if( self = [super init] ) {
app = [EJJavaScriptView sharedView];
glContext = app.glContext2D;
-
- memset(stateStack, 0, sizeof(stateStack));
+
+ state = [[EJCanvasState alloc] init];
+ state.globalAlpha = 1;
+ state.globalCompositeOperation = kEJCompositeOperationSourceOver;
+ state.transform = CGAffineTransformIdentity;
+ state.lineWidth = 1;
+ state.lineCap = kEJLineCapButt;
+ state.lineJoin = kEJLineJoinMiter;
+ state.miterLimit = 10;
+ state.textBaseline = kEJTextBaselineAlphabetic;
+ state.textAlign = kEJTextAlignStart;
+ state.font = [EJFontDescriptor descriptorWithName:@"Helvetica" size:10];
+ state.clipPath = nil;
+
+ stateStack = [[NSMutableArray alloc] initWithCapacity:8];
stateIndex = 0;
- state = &stateStack[stateIndex];
- state->globalAlpha = 1;
- state->globalCompositeOperation = kEJCompositeOperationSourceOver;
- state->transform = CGAffineTransformIdentity;
- state->lineWidth = 1;
- state->lineCap = kEJLineCapButt;
- state->lineJoin = kEJLineJoinMiter;
- state->miterLimit = 10;
- state->textBaseline = kEJTextBaselineAlphabetic;
- state->textAlign = kEJTextAlignStart;
- state->font = [[EJFontDescriptor descriptorWithName:@"Helvetica" size:10] retain];
- state->clipPath = nil;
+ stateStack[stateIndex] = state;
bufferWidth = width = widthp;
bufferHeight = height = heightp;
@@ -52,7 +80,7 @@ - (id)initWithWidth:(short)widthp height:(short)heightp {
vertexTranslate = EJVector2Make(-1.0f, -1.0f);
path = [[EJPath alloc] init];
- backingStoreRatio = 1;
+ self.backingStoreRatio = 1;
fontCache = [[NSCache alloc] init];
fontCache.countLimit = 8;
@@ -70,25 +98,15 @@ - (void)dealloc {
EAGLContext *oldContext = [EAGLContext currentContext];
[EAGLContext setCurrentContext:glContext];
- [fontCache release];
-
- // Release all fonts, clip paths and patterns from the stack
- for( int i = 0; i < stateIndex + 1; i++ ) {
- [stateStack[i].font release];
- [stateStack[i].clipPath release];
- [stateStack[i].fillObject release];
- }
if( viewFrameBuffer ) { glDeleteFramebuffers( 1, &viewFrameBuffer); }
if( viewRenderBuffer ) { glDeleteRenderbuffers(1, &viewRenderBuffer); }
if( msaaFrameBuffer ) { glDeleteFramebuffers( 1, &msaaFrameBuffer); }
if( msaaRenderBuffer ) { glDeleteRenderbuffers(1, &msaaRenderBuffer); }
if( stencilBuffer ) { glDeleteRenderbuffers(1, &stencilBuffer); }
- [path release];
[EAGLContext setCurrentContext:oldContext];
- [super dealloc];
}
- (void)create {
@@ -157,7 +175,7 @@ - (void)prepare {
glViewport(0, 0, bufferWidth, bufferHeight);
- EJCompositeOperation op = state->globalCompositeOperation;
+ EJCompositeOperation op = state.globalCompositeOperation;
glBlendFunc( EJCompositeOperationFuncs[op].source, EJCompositeOperationFuncs[op].destination );
currentTexture = nil;
currentProgram = nil;
@@ -171,7 +189,7 @@ - (void)prepare {
glDisable(GL_DEPTH_TEST);
}
- if( state->clipPath ) {
+ if( state.clipPath ) {
glDepthFunc(GL_EQUAL);
}
else {
@@ -469,139 +487,104 @@ - (void)setImageSmoothingEnabled:(BOOL)enabled {
}
- (void)setGlobalCompositeOperation:(EJCompositeOperation)op {
- if( op == state->globalCompositeOperation ) { return; }
+ if( op == state.globalCompositeOperation ) { return; }
[self flushBuffers];
glBlendFunc( EJCompositeOperationFuncs[op].source, EJCompositeOperationFuncs[op].destination );
- state->globalCompositeOperation = op;
+ state.globalCompositeOperation = op;
}
- (EJCompositeOperation)globalCompositeOperation {
- return state->globalCompositeOperation;
-}
-
-- (void)setFont:(EJFontDescriptor *)font {
- [state->font release];
- state->font = [font retain];
-}
-
-- (EJFontDescriptor *)font {
- return state->font;
-}
-
-- (void)setFillObject:(NSObject<EJFillable> *)fillObject {
- [state->fillObject release];
- state->fillObject = [fillObject retain];
+ return state.globalCompositeOperation;
}
-- (NSObject<EJFillable> *)fillObject {
- return state->fillObject;
-}
-
-
-- (void)save {
- if( stateIndex == EJ_CANVAS_STATE_STACK_SIZE-1 ) {
- NSLog(@"Warning: EJ_CANVAS_STATE_STACK_SIZE (%d) reached", EJ_CANVAS_STATE_STACK_SIZE);
- return;
- }
-
- stateStack[stateIndex+1] = stateStack[stateIndex];
- stateIndex++;
- state = &stateStack[stateIndex];
- [state->font retain];
- [state->fillObject retain];
- [state->clipPath retain];
+- (void)save {
+ state = state.copy;
+ stateStack[++stateIndex] = state;
+ state = stateStack[stateIndex];
}
- (void)restore {
if( stateIndex == 0 ) { return; }
- EJCompositeOperation oldCompositeOp = state->globalCompositeOperation;
- EJPath *oldClipPath = state->clipPath;
-
- // Clean up current state
- [state->font release];
- [state->fillObject release];
+ EJCompositeOperation oldCompositeOp = state.globalCompositeOperation;
+ EJPath *oldClipPath = state.clipPath;
- if( state->clipPath && state->clipPath != stateStack[stateIndex-1].clipPath ) {
+ if( state.clipPath && state.clipPath != ((EJCanvasState *)stateStack[stateIndex-1]).clipPath ) {
[self resetClip];
}
- [state->clipPath release];
-
- // Load state from stack
- stateIndex--;
- state = &stateStack[stateIndex];
- path.transform = state->transform;
+ state = stateStack[--stateIndex];
+ path.transform = state.transform;
// Set Composite op, if different
- if( state->globalCompositeOperation != oldCompositeOp ) {
- self.globalCompositeOperation = state->globalCompositeOperation;
+ if( state.globalCompositeOperation != oldCompositeOp ) {
+ self.globalCompositeOperation = state.globalCompositeOperation;
}
// Render clip path, if present and different
- if( state->clipPath && state->clipPath != oldClipPath ) {
+ if( state.clipPath && state.clipPath != oldClipPath ) {
[self setProgram:app.glProgram2DFlat];
- [state->clipPath drawPolygonsToContext:self target:kEJPathPolygonTargetDepth];
+ [state.clipPath drawPolygonsToContext:self target:kEJPathPolygonTargetDepth];
}
}
- (void)rotate:(float)angle {
- state->transform = CGAffineTransformRotate( state->transform, angle );
- path.transform = state->transform;
+ state.transform = CGAffineTransformRotate( state.transform, angle );
+ path.transform = state.transform;
}
- (void)translateX:(float)x y:(float)y {
- state->transform = CGAffineTransformTranslate( state->transform, x, y );
- path.transform = state->transform;
+ state.transform = CGAffineTransformTranslate( state.transform, x, y );
+ path.transform = state.transform;
}
- (void)scaleX:(float)x y:(float)y {
- state->transform = CGAffineTransformScale( state->transform, x, y );
- path.transform = state->transform;
+ state.transform = CGAffineTransformScale( state.transform, x, y );
+ path.transform = state.transform;
}
- (void)transformM11:(float)m11 m12:(float)m12 m21:(float)m21 m22:(float)m22 dx:(float)dx dy:(float)dy {
CGAffineTransform t = CGAffineTransformMake( m11, m12, m21, m22, dx, dy );
- state->transform = CGAffineTransformConcat( t, state->transform );
- path.transform = state->transform;
+ state.transform = CGAffineTransformConcat( t, state.transform );
+ path.transform = state.transform;
}
- (void)setTransformM11:(float)m11 m12:(float)m12 m21:(float)m21 m22:(float)m22 dx:(float)dx dy:(float)dy {
- state->transform = CGAffineTransformMake( m11, m12, m21, m22, dx, dy );
- path.transform = state->transform;
+ state.transform = CGAffineTransformMake( m11, m12, m21, m22, dx, dy );
+ path.transform = state.transform;
}
- (void)drawImage:(EJTexture *)texture sx:(float)sx sy:(float)sy sw:(float)sw sh:(float)sh dx:(float)dx dy:(float)dy dw:(float)dw dh:(float)dh {
float tw = texture.width;
float th = texture.height;
- EJColorRGBA color = {.rgba = {255, 255, 255, 255 * state->globalAlpha}};
+ EJColorRGBA color = {.rgba = {255, 255, 255, 255 * state.globalAlpha}};
[self setProgram:app.glProgram2DTexture];
[self setTexture:texture];
- [self pushTexturedRectX:dx y:dy w:dw h:dh tx:sx/tw ty:sy/th tw:sw/tw th:sh/th color:color withTransform:state->transform];
+ [self pushTexturedRectX:dx y:dy w:dw h:dh tx:sx/tw ty:sy/th tw:sw/tw th:sh/th color:color withTransform:state.transform];
}
- (void)fillRectX:(float)x y:(float)y w:(float)w h:(float)h {
- if( state->fillObject ) {
- EJColorRGBA color = {.rgba = {255, 255, 255, 255 * state->globalAlpha}};
- [self pushFilledRectX:x y:y w:w h:h fillable:state->fillObject color:color withTransform:state->transform];
+ if( state.fillObject ) {
+ EJColorRGBA color = {.rgba = {255, 255, 255, 255 * state.globalAlpha}};
+ [self pushFilledRectX:x y:y w:w h:h fillable:state.fillObject color:color withTransform:state.transform];
}
else {
[self setProgram:app.glProgram2DFlat];
- EJColorRGBA color = state->fillColor;
- color.rgba.a = (float)color.rgba.a * state->globalAlpha;
- [self pushRectX:x y:y w:w h:h color:color withTransform:state->transform];
+ EJColorRGBA color = state.fillColor;
+ color.rgba.a = (float)color.rgba.a * state.globalAlpha;
+ [self pushRectX:x y:y w:w h:h color:color withTransform:state.transform];
}
}
- (void)strokeRectX:(float)x y:(float)y w:(float)w h:(float)h {
// strokeRect should not affect the current path, so we create
// a new, tempPath instead.
EJPath *tempPath = [[EJPath alloc] init];
- tempPath.transform = state->transform;
+ tempPath.transform = state.transform;
[tempPath moveToX:x y:y];
[tempPath lineToX:x+w y:y];
@@ -611,17 +594,16 @@ - (void)strokeRectX:(float)x y:(float)y w:(float)w h:(float)h {
[self setProgram:app.glProgram2DFlat];
[tempPath drawLinesToContext:self];
- [tempPath release];
}
- (void)clearRectX:(float)x y:(float)y w:(float)w h:(float)h {
[self setProgram:app.glProgram2DFlat];
- EJCompositeOperation oldOp = state->globalCompositeOperation;
+ EJCompositeOperation oldOp = state.globalCompositeOperation;
self.globalCompositeOperation = kEJCompositeOperationDestinationOut;
static EJColorRGBA white = {.hex = 0xffffffff};
- [self pushRectX:x y:y w:w h:h color:white withTransform:state->transform];
+ [self pushRectX:x y:y w:w h:h color:white withTransform:state.transform];
self.globalCompositeOperation = oldOp;
}
@@ -664,11 +646,11 @@ - (EJImageData*)getImageDataScaled:(float)scale flipped:(bool)flipped sx:(short)
pixels = [NSMutableData dataWithBytesNoCopy:scaledPixels length:size];
}
- return [[[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels] autorelease];
+ return [[EJImageData alloc] initWithWidth:sw height:sh pixels:pixels];
}
- (EJImageData*)getImageDataSx:(short)sx sy:(short)sy sw:(short)sw sh:(short)sh {
- return [self getImageDataScaled:backingStoreRatio flipped:NO sx:sx sy:sy sw:sw sh:sh];
+ return [self getImageDataScaled:self.backingStoreRatio flipped:NO sx:sx sy:sy sw:sw sh:sh];
}
- (EJImageData*)getImageDataHDSx:(short)sx sy:(short)sy sw:(short)sw sh:(short)sh {
@@ -694,7 +676,7 @@ - (void)putImageData:(EJImageData*)imageData dx:(float)dx dy:(float)dy {
}
- (void)putImageDataHD:(EJImageData*)imageData dx:(float)dx dy:(float)dy {
- [self putImageData:imageData scaled:backingStoreRatio dx:dx dy:dy];
+ [self putImageData:imageData scaled:self.backingStoreRatio dx:dx dy:dy];
}
- (void)beginPath {
@@ -724,12 +706,12 @@ - (void)lineToX:(float)x y:(float)y {
}
- (void)bezierCurveToCpx1:(float)cpx1 cpy1:(float)cpy1 cpx2:(float)cpx2 cpy2:(float)cpy2 x:(float)x y:(float)y {
- float scale = CGAffineTransformGetScale( state->transform );
+ float scale = CGAffineTransformGetScale( state.transform );
[path bezierCurveToCpx1:cpx1 cpy1:cpy1 cpx2:cpx2 cpy2:cpy2 x:x y:y scale:scale];
}
- (void)quadraticCurveToCpx:(float)cpx cpy:(float)cpy x:(float)x y:(float)y {
- float scale = CGAffineTransformGetScale( state->transform );
+ float scale = CGAffineTransformGetScale( state.transform );
[path quadraticCurveToCpx:cpx cpy:cpy x:x y:y scale:scale];
}
@@ -756,47 +738,43 @@ - (EJFont *)getFontWithDescriptor:(EJFontDescriptor *)desc filled:(BOOL)filled {
NSString *cacheKey = (filled ? desc.identFilled : desc.identOutlined);
EJFont *font = [fontCache objectForKey:cacheKey];
if( !font ) {
- font = [[EJFont alloc] initWithDescriptor:desc fill:filled contentScale:backingStoreRatio];
+ font = [[EJFont alloc] initWithDescriptor:desc fill:filled contentScale:self.backingStoreRatio];
[fontCache setObject:font forKey:cacheKey];
- [font autorelease];
}
return font;
}
- (void)fillText:(NSString *)text x:(float)x y:(float)y {
- EJFont *font = [self getFontWithDescriptor:state->font filled:YES];
+ EJFont *font = [self getFontWithDescriptor:state.font filled:YES];
[self setProgram:app.glProgram2DAlphaTexture];
[font drawString:text toContext:self x:x y:y];
}
- (void)strokeText:(NSString *)text x:(float)x y:(float)y {
- EJFont *font = [self getFontWithDescriptor:state->font filled:NO];
+ EJFont *font = [self getFontWithDescriptor:state.font filled:NO];
[self setProgram:app.glProgram2DAlphaTexture];
[font drawString:text toContext:self x:x y:y];
}
- (EJTextMetrics)measureText:(NSString *)text {
- EJFont *font = [self getFontWithDescriptor:state->font filled:YES];
+ EJFont *font = [self getFontWithDescriptor:state.font filled:YES];
return [font measureString:text forContext:self];
}
- (void)clip {
[self flushBuffers];
- [state->clipPath release];
- state->clipPath = nil;
- state->clipPath = path.copy;
+ state.clipPath = path.copy;
[self setProgram:app.glProgram2DFlat];
- [state->clipPath drawPolygonsToContext:self target:kEJPathPolygonTargetDepth];
+ [state.clipPath drawPolygonsToContext:self target:kEJPathPolygonTargetDepth];
}
- (void)resetClip {
- if( state->clipPath ) {
+ if( state.clipPath ) {
[self flushBuffers];
- [state->clipPath release];
- state->clipPath = nil;
+ state.clipPath = nil;
glDepthMask(GL_TRUE);
glClear(GL_DEPTH_BUFFER_BIT);
View
12 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DScreen.m
@@ -13,7 +13,7 @@ - (void)create {
CGRect frame = CGRectMake(0, 0, width, height);
CGSize screen = app.bounds.size;
- float contentScale = (useRetinaResolution && [UIScreen mainScreen].scale == 2) ? 2 : 1;
+ float contentScale = (self.useRetinaResolution && [UIScreen mainScreen].scale == 2) ? 2 : 1;
float aspect = frame.size.width / frame.size.height;
if( scalingMode == kEJScalingModeFitWidth ) {
@@ -27,7 +27,7 @@ - (void)create {
float internalScaling = frame.size.width / (float)width;
app.internalScaling = internalScaling;
- backingStoreRatio = internalScaling * contentScale;
+ self.backingStoreRatio = internalScaling * contentScale;
bufferWidth = frame.size.width * contentScale;
bufferHeight = frame.size.height * contentScale;
@@ -40,7 +40,7 @@ - (void)create {
@"msaa: %@",
width, height, aspect,
internalScaling, frame.size.width, frame.size.height,
- (useRetinaResolution ? @"yes" : @"no"),
+ (self.useRetinaResolution ? @"yes" : @"no"),
frame.size.width * contentScale, frame.size.height * contentScale,
(msaaEnabled ? [NSString stringWithFormat:@"yes (%d samples)", msaaSamples] : @"no")
);
@@ -68,10 +68,6 @@ - (void)create {
[app addSubview:glview];
}
-- (void)dealloc {
- [glview release];
- [super dealloc];
-}
- (void)setWidth:(short)newWidth {
@@ -88,7 +84,7 @@ - (void)setHeight:(short)newHeight {
- (EJImageData*)getImageDataSx:(short)sx sy:(short)sy sw:(short)sw sh:(short)sh {
// Take care of the flipped screen layout
- return [self getImageDataScaled:backingStoreRatio flipped:YES sx:sx sy:sy sw:sw sh:sh];
+ return [self getImageDataScaled:self.backingStoreRatio flipped:YES sx:sx sy:sy sw:sw sh:sh];
}
- (EJImageData*)getImageDataHDSx:(short)sx sy:(short)sy sw:(short)sw sh:(short)sh {
View
2 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.h
@@ -5,6 +5,6 @@
EJTexture *texture;
}
-@property (readonly, nonatomic) EJTexture *texture;
+@property (weak, readonly, nonatomic) EJTexture *texture;
@end
View
15 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.m
@@ -3,16 +3,16 @@
@implementation EJCanvasContext2DTexture
- (void)create {
- backingStoreRatio = (useRetinaResolution && [UIScreen mainScreen].scale == 2) ? 2 : 1;
- bufferWidth = width * backingStoreRatio;
- bufferHeight = height * backingStoreRatio;
+ self.backingStoreRatio = (self.useRetinaResolution && [UIScreen mainScreen].scale == 2) ? 2 : 1;
+ bufferWidth = width * self.backingStoreRatio;
+ bufferHeight = height * self.backingStoreRatio;
// This creates the frame- and renderbuffers
[super create];
// Create the texture and set it as the rendering target for this framebuffer
texture = [[EJTexture alloc] initAsRenderTargetWithWidth:width height:height
- fbo:viewFrameBuffer contentScale:backingStoreRatio];
+ fbo:viewFrameBuffer contentScale:self.backingStoreRatio];
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.textureId, 0);
@@ -23,15 +23,10 @@ - (void)create {
glClear(GL_COLOR_BUFFER_BIT);
}
-- (void)dealloc {
- [texture release];
- [super dealloc];
-}
- (void)recreate {
- [texture release];
texture = [[EJTexture alloc] initAsRenderTargetWithWidth:width height:height
- fbo:viewFrameBuffer contentScale:backingStoreRatio];
+ fbo:viewFrameBuffer contentScale:self.backingStoreRatio];
bufferWidth = texture.width;
bufferHeight = texture.height;
View
2 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.h
@@ -33,7 +33,7 @@ typedef struct {
- (NSData *)getPixelsWithWidth:(int)width forSortedStops:(NSArray *)stops;
@property (readonly, nonatomic) EJCanvasGradientType type;
-@property (readonly, nonatomic) EJTexture *texture;
+@property (weak, readonly, nonatomic) EJTexture *texture;
@property (readonly, nonatomic) EJVector2 p1;
@property (readonly, nonatomic) EJVector2 p2;
@property (readonly, nonatomic) float r1;
View
6 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.m
@@ -30,18 +30,12 @@ - (id)initRadialGradientWithP1:(EJVector2)p1p r1:(float)r1p p2:(EJVector2)p2p r2
return self;
}
-- (void)dealloc {
- [texture release];
- [colorStops release];
- [super dealloc];
-}
- (void)addStopWithColor:(EJColorRGBA)color at:(float)pos {
EJCanvasGradientColorStop stop = { .pos = pos, .color = color, .order = colorStops.count };
[colorStops addObject:[NSValue value:&stop withObjCType:@encode(EJCanvasGradientColorStop)]];
// Release current texture; it's invalid now
- [texture release];
texture = NULL;
}
View
4 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.h
@@ -10,13 +10,13 @@ typedef enum {
} EJCanvasPatternRepeat;
@interface EJCanvasPattern : NSObject <EJFillable> {
- EJTexture *texture;
+ EJTexture *__weak texture;
EJCanvasPatternRepeat repeat;
}
- (id)initWithTexture:(EJTexture *)texturep repeat:(EJCanvasPatternRepeat)repeatp;
-@property (readonly, nonatomic) EJTexture *texture;
+@property (weak, readonly, nonatomic) EJTexture *texture;
@property (readonly, nonatomic) EJCanvasPatternRepeat repeat;
@end
View
4 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.m
@@ -13,9 +13,5 @@ - (id)initWithTexture:(EJTexture *)texturep repeat:(EJCanvasPatternRepeat)repeat
return self;
}
-- (void)dealloc {
- [texture release];
- [super dealloc];
-}
@end
View
51 Source/Ejecta/EJCanvas/2D/EJFont.mm
@@ -14,21 +14,15 @@ + (id)descriptorWithName:(NSString *)name size:(float)size {
}
EJFontDescriptor *descriptor = [[EJFontDescriptor alloc] init];
- descriptor->name = [name retain];
+ descriptor->name = name;
descriptor->size = size;
- descriptor->identFilled = [[NSString stringWithFormat:@"%@:F:%.2f", name, size] retain];
- descriptor->identOutlined = [[NSString stringWithFormat:@"%@:O:%.2f", name, size] retain];
+ descriptor->identFilled = [NSString stringWithFormat:@"%@:F:%.2f", name, size];
+ descriptor->identOutlined = [NSString stringWithFormat:@"%@:O:%.2f", name, size];
- return [descriptor autorelease];
+ return descriptor;
}
-- (void)dealloc {
- [identFilled release];
- [identOutlined release];
- [name release];
- [super dealloc];
-}
@end
@@ -39,17 +33,13 @@ @implementation EJFontLayout
- (id)initWithGlyphLayout:(NSData *)layout glyphCount:(int)count metrics:(EJTextMetrics)metricsp {
if( self = [super init] ) {
- glyphLayout = [layout retain];
+ glyphLayout = layout;
glyphCount = count;
metrics = metricsp;
}
return self;
}
-- (void)dealloc {
- [glyphLayout release];
- [super dealloc];
-}
- (EJFontGlyphLayout *)glyphLayout {
return (EJFontGlyphLayout *)glyphLayout.bytes;
@@ -82,7 +72,7 @@ - (id)initWithDescriptor:(EJFontDescriptor *)desc fill:(BOOL)fillp contentScale:
contentScale = contentScalep;
fill = fillp;
- ctMainFont = CTFontCreateWithName((CFStringRef)desc.name, desc.size, NULL);
+ ctMainFont = CTFontCreateWithName((__bridge CFStringRef)desc.name, desc.size, NULL);
cgMainFont = CTFontCopyGraphicsFont(ctMainFont, NULL);
if( ctMainFont ) {
@@ -114,7 +104,7 @@ + (void)loadFontAtPath:(NSString*)path{
return;
}
CFErrorRef error;
- CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
+ CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if( !CTFontManagerRegisterGraphicsFont(font, &error) ){
CFStringRef errorDescription = CFErrorCopyDescription(error);
@@ -129,13 +119,10 @@ - (void)dealloc {
CGFontRelease(cgMainFont);
CFRelease(ctMainFont);
- [textures release];
- [layoutCache release];
free(glyphsBuffer);
free(positionsBuffer);
- [super dealloc];
}
- (unsigned short)createGlyph:(CGGlyph)glyph withFont:(CTFontRef)font {
@@ -175,7 +162,6 @@ - (unsigned short)createGlyph:(CGGlyph)glyph withFont:(CTFontRef)font {
txLineX = txLineY = txLineH = 0;
texture = [[EJTexture alloc] initWithWidth:EJ_FONT_TEXTURE_SIZE height:EJ_FONT_TEXTURE_SIZE format:GL_ALPHA];
[textures addObject:texture];
- [texture release];
}
else {
texture = [textures lastObject];
@@ -245,11 +231,10 @@ - (EJFontLayout *)getLayoutForString:(NSString *)string {
// Create attributed line
NSAttributedString *attributes = [[NSAttributedString alloc]
initWithString:string
- attributes:@{ (id)kCTFontAttributeName: (id)ctMainFont }];
+ attributes:@{ (id)kCTFontAttributeName: (__bridge id)ctMainFont }];
- CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attributes);
+ CTLineRef line = CTLineCreateWithAttributedString((__bridge CFAttributedStringRef)attributes);
- [attributes release];
// Get line metrics; sadly, ascent and descent are broken: 'ascent' equals
// the total height (i.e. what should be ascent + descent) and 'descent'
@@ -338,7 +323,7 @@ - (EJFontLayout *)getLayoutForString:(NSString *)string {
CFRelease(line);
- return [layout autorelease];
+ return layout;
}
- (float)getYOffsetForBaseline:(EJTextBaseline)baseline {
@@ -364,25 +349,25 @@ - (void)drawString:(NSString *)string toContext:(EJCanvasContext2D *)context x:(
EJFontLayout *layout = [self getLayoutForString:string];
// Figure out the x position with the current textAlign.
- if(context.state->textAlign != kEJTextAlignLeft) {
- if( context.state->textAlign == kEJTextAlignRight || context.state->textAlign == kEJTextAlignEnd ) {
+ if(context.state.textAlign != kEJTextAlignLeft) {
+ if( context.state.textAlign == kEJTextAlignRight || context.state.textAlign == kEJTextAlignEnd ) {
x -= layout.metrics.width;
}
- else if( context.state->textAlign == kEJTextAlignCenter ) {
+ else if( context.state.textAlign == kEJTextAlignCenter ) {
x -= layout.metrics.width/2.0f;
}
}
- y += [self getYOffsetForBaseline:context.state->textBaseline];
+ y += [self getYOffsetForBaseline:context.state.textBaseline];
x = roundf(x);
y = roundf(y);
// Fill or stroke color?
EJCanvasState *state = context.state;
- EJColorRGBA color = fill ? state->fillColor : state->strokeColor;
- color.rgba.a = (float)color.rgba.a * state->globalAlpha;
+ EJColorRGBA color = fill ? state.fillColor : state.strokeColor;
+ color.rgba.a = (float)color.rgba.a * state.globalAlpha;
// Go through all glyphs - bind textures as needed - and draw
EJFontGlyphLayout *layoutBuffer = layout.glyphLayout;
@@ -401,7 +386,7 @@ - (void)drawString:(NSString *)string toContext:(EJCanvasContext2D *)context x:(
[context pushTexturedRectX:gx y:gy w:glyphInfo->w h:glyphInfo->h
tx:glyphInfo->tx ty:glyphInfo->ty+glyphInfo->th tw:glyphInfo->tw th:-glyphInfo->th
- color:color withTransform:state->transform];
+ color:color withTransform:state.transform];
i++;
}
@@ -411,7 +396,7 @@ - (void)drawString:(NSString *)string toContext:(EJCanvasContext2D *)context x:(
- (EJTextMetrics)measureString:(NSString*)string forContext:(EJCanvasContext2D *)context {
if( string.length == 0 ) { return {0}; }
- float yOffset = [self getYOffsetForBaseline:context.state->textBaseline];
+ float yOffset = [self getYOffsetForBaseline:context.state.textBaseline];
EJTextMetrics metrics = [self getLayoutForString:string].metrics;
metrics.width = ceilf(metrics.width);
View
1 Source/Ejecta/EJCanvas/2D/EJGLProgram2D.m
@@ -31,7 +31,6 @@ - (id)initWithVertexShader:(NSString *)vertexShaderFile fragmentShader:(NSString
- (void)dealloc {
if( program ) { glDeleteProgram(program); }
- [super dealloc];
}
- (void)bindAttributeLocations {
View
2 Source/Ejecta/EJCanvas/2D/EJImageData.h
@@ -8,7 +8,7 @@
- (id)initWithWidth:(int)width height:(int)height pixels:(NSMutableData *)pixels;
-@property (readonly, nonatomic) EJTexture *texture;
+@property (weak, readonly, nonatomic) EJTexture *texture;
@property (readonly, nonatomic) int width;
@property (readonly, nonatomic) int height;
@property (readonly, nonatomic) NSMutableData *pixels;
View
8 Source/Ejecta/EJCanvas/2D/EJImageData.m
@@ -8,18 +8,14 @@ - (id)initWithWidth:(int)widthp height:(int)heightp pixels:(NSMutableData *)pixe
if( self = [super init] ) {
width = widthp;
height = heightp;
- pixels = [pixelsp retain];
+ pixels = pixelsp;
}
return self;
}
-- (void)dealloc {
- [pixels release];
- [super dealloc];
-}
- (EJTexture *)texture {
- return [[[EJTexture alloc] initWithWidth:width height:height pixels:pixels] autorelease];
+ return [[EJTexture alloc] initWithWidth:width height:height pixels:pixels];
}
@end
View
2 Source/Ejecta/EJCanvas/2D/EJPath.h
@@ -26,7 +26,7 @@ typedef enum {
CGAffineTransform transform;
}
-@property (nonatomic,assign) CGAffineTransform transform;;
+@property (nonatomic, assign) CGAffineTransform transform;
- (void)push:(EJVector2)v;
- (void)reset;
View
41 Source/Ejecta/EJCanvas/2D/EJPath.mm
@@ -20,7 +20,6 @@ @interface EJPath() {
@implementation EJPath
-
@synthesize transform;
- (id)init {
@@ -321,8 +320,8 @@ - (void)drawPolygonsToContext:(EJCanvasContext2D *)context target:(EJPathPolygon
if( longestSubpath < 3 ) { return; }
EJCanvasState *state = context.state;
- EJColorRGBA color = state->fillColor;
- color.rgba.a = (float)color.rgba.a * state->globalAlpha;
+ EJColorRGBA color = state.fillColor;
+ color.rgba.a = (float)color.rgba.a * state.globalAlpha;
// For potentially concave polygons (those with more than 3 unique vertices), we
@@ -392,7 +391,7 @@ - (void)drawPolygonsToContext:(EJCanvasContext2D *)context target:(EJPathPolygon
glStencilFunc(GL_NOTEQUAL, 0x00, 0xff);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
- if( state->fillObject && target == kEJPathPolygonTargetColor ) {
+ if( state.fillObject && target == kEJPathPolygonTargetColor ) {
// If we have a fill pattern or gradient, we have to do some extra work to unproject the
// Quad we're drawing, so we can then project it _with_ the pattern/gradient again
@@ -406,10 +405,10 @@ - (void)drawPolygonsToContext:(EJCanvasContext2D *)context target:(EJPathPolygon
EJVector2 tmin = { MIN(p1.x, MIN(p2.x,MIN(p3.x, p4.x))), MIN(p1.y, MIN(p2.y,MIN(p3.y, p4.y))) };
EJVector2 tmax = { MAX(p1.x, MAX(p2.x,MAX(p3.x, p4.x))), MAX(p1.y, MAX(p2.y,MAX(p3.y, p4.y))) };
- color = (EJColorRGBA){.rgba = {255, 255, 255, 255 * state->globalAlpha}};
+ color = (EJColorRGBA){.rgba = {255, 255, 255, 255 * state.globalAlpha}};
[context
pushFilledRectX:tmin.x y:tmin.y w:tmax.x-tmin.x h:tmax.y-tmin.y
- fillable:state->fillObject color:color withTransform:transform];
+ fillable:state.fillObject color:color withTransform:transform];
}
else {
[context
@@ -432,7 +431,7 @@ - (void)drawPolygonsToContext:(EJCanvasContext2D *)context target:(EJPathPolygon
- (void)drawArcToContext:(EJCanvasContext2D *)context atPoint:(EJVector2)point v1:(EJVector2)p1 v2:(EJVector2)p2 color:(EJColorRGBA)color {
EJCanvasState *state = context.state;
- float width2 = state->lineWidth/2;
+ float width2 = state.lineWidth/2;
EJVector2
v1 = EJVector2Normalize(EJVector2Sub(p1, point)),
@@ -452,7 +451,7 @@ - (void)drawArcToContext:(EJCanvasContext2D *)context atPoint:(EJVector2)point v
}
// 1 step per 5 pixel
- float pxScale = CGAffineTransformGetScale(state->transform);
+ float pxScale = CGAffineTransformGetScale(state.transform);
int numSteps = ceilf( (angle2 * width2 * pxScale) / 5.0f );
if( numSteps == 1 ) {
@@ -496,23 +495,23 @@ - (void)drawLinesToContext:(EJCanvasContext2D *)context {
EJCanvasState *state = context.state;
// Find the width of the line as it is projected onto the screen.
- float projectedLineWidth = CGAffineTransformGetScale( state->transform ) * state->lineWidth;
+ float projectedLineWidth = CGAffineTransformGetScale( state.transform ) * state.lineWidth;
// Figure out if we need to add line caps and set the cap texture coord for square or round caps.
// For thin lines we disable texturing and line caps.
- float width2 = state->lineWidth/2;
- BOOL addCaps = (projectedLineWidth > 2 && (state->lineCap == kEJLineCapRound || state->lineCap == kEJLineCapSquare));
+ float width2 = state.lineWidth/2;
+ BOOL addCaps = (projectedLineWidth > 2 && (state.lineCap == kEJLineCapRound || state.lineCap == kEJLineCapSquare));
// The miter limit is the maximum allowed ratio of the miter length to half the line width.
- BOOL addMiter = (state->lineJoin == kEJLineJoinMiter);
- float miterLimit = (state->miterLimit * width2);
+ BOOL addMiter = (state.lineJoin == kEJLineJoinMiter);
+ float miterLimit = (state.miterLimit * width2);
- EJColorRGBA color = state->strokeColor;
- color.rgba.a = (float)color.rgba.a * state->globalAlpha;
+ EJColorRGBA color = state.strokeColor;
+ color.rgba.a = (float)color.rgba.a * state.globalAlpha;
// Enable stencil test when drawing transparent lines.
// Cycle through all bits, so that the stencil buffer only has to be cleared after eight stroke operations
- BOOL useStencil = (color.rgba.a < 0xff || state->globalCompositeOperation != kEJCompositeOperationSourceOver);
+ BOOL useStencil = (color.rgba.a < 0xff || state.globalCompositeOperation != kEJCompositeOperationSourceOver);
if( useStencil ) {
[context flushBuffers];
[context createStencilBufferOnce];
@@ -583,7 +582,7 @@ - (void)drawLinesToContext:(EJCanvasContext2D *)context {
// Start cap
if( addCaps && !subPathIsClosed ) {
- if( state->lineCap == kEJLineCapSquare ) {
+ if( state.lineCap == kEJLineCapSquare ) {
EJVector2 capExt = { -nextExt.y, nextExt.x };
EJVector2 cap11 = EJVector2Add( miter21, capExt );
EJVector2 cap12 = EJVector2Add( miter22, capExt );
@@ -607,7 +606,7 @@ - (void)drawLinesToContext:(EJCanvasContext2D *)context {
BOOL miterA