Permalink
Browse files

Speed improvements

  • Loading branch information...
1 parent 7ee7541 commit 82b7841d95341f614b649ad8d79436bd825fd495 @comex committed Jun 24, 2010
@@ -19,7 +19,7 @@
}
@property (retain) Server *server;
- (void)useSurface:(IOSurfaceRef)sfc;
-- (void)displaySync;
+- (void)displaySyncInRect:(CGRect *)rect;
- (CGSize)movieSize;
- (void)diedWithError:(NSString *)error;
@@ -95,7 +95,7 @@ - (NSURL *)baseURL {
return nil;
}
-- (void)displaySync {
+- (void)displaySyncInRect:(CGRect *)rect {
CGImageRef image = CGImageCreate(
IOSurfaceGetWidth(sfc),
IOSurfaceGetHeight(sfc),
@@ -22,7 +22,7 @@
@property (retain) Server *server;
- (void)useSurface:(IOSurfaceRef)sfc;
-- (void)displaySync;
+- (void)displaySyncInRect:(CGRect *)rect;
- (CGSize)movieSize;
- (void)diedWithError:(NSString *)error;
@@ -99,10 +99,11 @@ - (id)evaluateWebScript:(NSString *)script {
- (void)useSurface:(IOSurfaceRef)sfc_ {
if(sfc) CFRelease(sfc);
sfc = sfc_;
+ self.layer.contents = (id) sfc;
}
-- (void)displaySync {
+- (void)displaySyncInRect:(CGRect *)rect {
if(!sfc || !IOSurfaceGetWidth(sfc)) return;
/* CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, IOSurfaceGetBaseAddress(sfc), IOSurfaceGetAllocSize(sfc), NULL);
CGImageRef image = CGImageCreate(
@@ -122,8 +123,12 @@ - (void)displaySync {
CFRelease(data);
self.layer.contents = (id) image;
CFRelease(image);*/
- self.layer.contents = (id) sfc;
- self.layer.opacity = self.layer.opacity == 1.0 ? 0.9999 : 1.0;
+ //self.layer.contents = (id) sfc;
+ if(rect->size.width) {
+ [self.layer setNeedsDisplayInRect:*rect];
+ } else {
+ [self.layer setNeedsDisplay];
+ }
}
- (NSDictionary *)paramsDict {
View
@@ -19,6 +19,7 @@
#import <Foundation/Foundation.h>
#include <unistd.h>
#include <notify.h>
+#include <QuartzCore/QuartzCore.h>
#define BORING 0
#define FOOD_ROOT "/var/mobile/"
@@ -208,9 +209,10 @@ int use_surface(int rpc_fd, int surface) {
return 0;
}
-int display_sync(int rpc_fd) {
+int display_sync(int rpc_fd, int l, int t, int r, int b) {
Server *self = get_server(rpc_fd);
- [self->delegate performSelector:@selector(displaySync)];
+ CGRect rect = CGRectMake(l, t, r-l, b-t);
+ [self->delegate performSelector:@selector(displaySyncInRect:) withObject:(id)&rect];
return 0;
}
View
10 control
@@ -0,0 +1,10 @@
+Package: frash
+Architecture: armv7
+Name: frash
+Version: 0.00
+Priority: optional
+Description: All your base are belong to us?
+Homepage: http://github.com/comex/frash
+Maintainer: comex <comexk@gmail.com>
+Section: Utilities
+
View
@@ -1,7 +1,15 @@
export SDK := /var/sdk
all: food food_wrapper
-STUFF := -mthumb -g3 -Wreturn-type -Wall -DHAVE_MACOSX_IPC -DOS_PATH_SEPARATOR="'/'" -DHAVE_PTHREADS -DHAVE_POSIX_FILEMAP -DHAVE_LITTLE_ENDIAN -I. -I../rpc -I../utils -I../utils/libcutils -isysroot $(SDK) -arch armv7 -ffixed-r9 -Werror
+
+STUFF = -mthumb -Wreturn-type -Wall -DHAVE_MACOSX_IPC -DOS_PATH_SEPARATOR="'/'" -DHAVE_PTHREADS -DHAVE_POSIX_FILEMAP -DHAVE_LITTLE_ENDIAN -I. -I../rpc -I../utils -I../utils/libcutils -isysroot $(SDK) -arch armv7 -ffixed-r9 -Werror -Wno-uninitialized -g3 -O2
+DEBUG = 1
+
+#ifeq "$(DEBUG)" "1"
+#STUFF += -g3
+#else
+#STUFF += -O2
+#endif
%.o: %.cpp common.h ../rpc/food_rpc1.h
g++-4.2 $(STUFF) -c -o $@ $<
View
@@ -1,6 +1,4 @@
-- pthread_cond_timedwait
- invocation arguments
-- make Flash shut up when home is pressed (but Safari is not actually stopped)
- make it think it's fullscreen or otherwise fix mouse
- keyboard
- video?
View
@@ -105,8 +105,8 @@ struct ANPAudioTrack {
void aqtry_(OSStatus ret, const char *name) {
if(!ret) return;
- notice("Audio error in %s:", name);
- notice("%d", (int) ret);
+ err("Audio error in %s:", name);
+ err("%d", (int) ret);
_abort();
}
#define aqtry(x) aqtry_(x, #x)
@@ -155,7 +155,7 @@ ANPAudioTrack* audiotrack_impl_newTrack(uint32_t sampleRate, // sampling rat
switch(sampleFormat) {
case kPCM16Bit_ANPSampleFormat: bits = 16; break;
case kPCM8Bit_ANPSampleFormat: bits = 8; break;
- default: _assert(false);
+ default: _abort();
}
FillOutASBDForLPCM(fmt, sampleRate, channelCount, bits, bits, false, false, false);
aqtry(AudioQueueNewOutput(&fmt, trackCallbackProc, result, NULL, NULL, 0, &result->aq));
@@ -1128,6 +1128,8 @@ void event_impl_postEvent(NPP inst, const ANPEvent* event) {
static void *temp;
static size_t temp_sz;
+static ANPRectI cur_dirty;
+static bool cur_dirty_valid;
// ANPSurfaceInterfaceV0
extern "C" void refresh_size();
@@ -1138,9 +1140,18 @@ bool surface_impl_lock(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI
}
if(temp_sz != IOSurfaceGetAllocSize(sfc)) {
if(temp) free(temp);
- temp = calloc(1, IOSurfaceGetAllocSize(sfc));
+ temp = calloc(1, IOSurfaceGetAllocSize(sfc) + 128);
//memset(temp, 0xff, IOSurfaceGetAllocSize(sfc));
temp_sz = IOSurfaceGetAllocSize(sfc);
+ dirtyRect = NULL; // it is probably invalid
+ }
+ //log("dirtyRect=%p", dirtyRect);
+ if(dirtyRect) {
+ //log("%d,%d,%d,%d", dirtyRect->left, dirtyRect->top, dirtyRect->right, dirtyRect->bottom);
+ cur_dirty_valid = true;
+ cur_dirty = *dirtyRect;
+ } else {
+ cur_dirty_valid = false;
}
bitmap->baseAddr = temp;
bitmap->format = kRGBA_8888_ANPBitmapFormat;
@@ -1152,16 +1163,33 @@ bool surface_impl_lock(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI
//#include <fcntl.h>
extern "C" void rgba_bgra_copy(void *dest, void *src, void *end);
+
void surface_impl_unlock(JNIEnv* env, jobject surface) {
notice("%s surface=%p", __func__, surface);
if(!sfc || !IOSurfaceGetWidth(sfc) || !IOSurfaceGetHeight(sfc)) return;
- void *end = (void *) ((char*)temp + IOSurfaceGetAllocSize(sfc));
- rgba_bgra_copy(IOSurfaceGetBaseAddress(sfc), temp, end);
+ if(cur_dirty_valid) {
+ int rowsize = (cur_dirty.right - cur_dirty.left) * 4;
+ int fullrowsize = IOSurfaceGetBytesPerRow(sfc);
+ int rowoffset = cur_dirty.top * fullrowsize + cur_dirty.left * 4;
+ char *start = ((char *) IOSurfaceGetBaseAddress(sfc)) + rowoffset;
+ char *tempstart = ((char *) temp) + rowoffset;
+ char *end = tempstart + rowsize;
+ for(int y = cur_dirty.top; y < cur_dirty.bottom; y++) {
+ rgba_bgra_copy((void *) start, (void *) tempstart, (void *) end);
+ start += fullrowsize;
+ tempstart += fullrowsize;
+ end += fullrowsize;
+ }
+ _assertZero(display_sync(food, cur_dirty.left, cur_dirty.top, cur_dirty.right, cur_dirty.bottom));
+ } else {
+ void *end = (void *) ((char *)temp + IOSurfaceGetAllocSize(sfc));
+ rgba_bgra_copy(IOSurfaceGetBaseAddress(sfc), temp, end);
+ _assertZero(display_sync(food, 0, 0, 0, 0));
+ }
//memcpy(IOSurfaceGetBaseAddress(sfc), temp, IOSurfaceGetAllocSize(sfc));
/*int fd = open("foo.txt", O_WRONLY | O_CREAT, 0755);
write(fd, IOSurfaceGetBaseAddress(sfc), IOSurfaceGetAllocSize(sfc));
close(fd);*/
- _assertZero(display_sync(food));
}
//
View
@@ -191,7 +191,7 @@ jobject getAssetFileDescriptor(jclass cls, jvalue *a) {
s(descriptor, "getLength[()J]", make_a(afdGetLength));
int fd;
- log("opening %@", astName);
+ notice("opening %@", astName);
if(CFEqual(astName, CFSTR("oem.cfg"))) {
fd = oemcfg_fd;
} else {
@@ -351,7 +351,7 @@ void init_classes() {
static IOSurfaceRef make_iosurface() {
CFMutableDictionaryRef dict;
int pitch = movie_w * 4;
- int allocSize = pitch * movie_h + 64;
+ int allocSize = pitch * movie_h + 128;
int bytesPerElement = 4;
char pixelFormat[4] = {'A', 'R', 'G', 'B'};
View
@@ -5,6 +5,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <spawn.h>
@@ -219,3 +220,11 @@ void _abort_(const char *file, int line) {
err("_abort() %s:%d", file, line);
exit(1);
}
+
+#if TIMING
+uint64_t getus() {
+ struct timeval tp;
+ gettimeofday(&tp, NULL);
+ return ((uint64_t) tp.tv_sec) * 1000000 + (uint64_t) tp.tv_usec;
+}
+#endif
View
@@ -87,7 +87,6 @@ void _abort_(const char *file, int line);
void _assert_(bool test, const char *label, const char *file, int line, const char *func);
void _assertZero_(int test, const char *label, const char *file, int line, const char *func);
-#define _abort() _abort_(__FILE__, __LINE__)
#define _assert(x) _assert_((x), #x, __FILE__, __LINE__, __func__)
#define _assertZero(x) _assertZero_((int) (x), #x, __FILE__, __LINE__, __func__)
@@ -108,4 +107,10 @@ extern int movie_w, movie_h, pending_movie_w, pending_movie_h;
#define notice(args...) logx(3, args)
#define log(args...) logx(1, args)
#define err(args...) logx(0, args)
-
+#define TIMING 1
+#if TIMING
+uint64_t getus();
+#define TIME(thing) do { uint64_t _ta = getus(); thing; uint64_t _tb = getus(); log("[%.4ld us] %s", (long int) (_tb - _ta), #thing); } while(0)
+#else
+#define TIME(thing) thing
+#endif
View
@@ -49,7 +49,7 @@ int prctl(int option, unsigned long arg2, unsigned long arg3 , unsigned long arg
}
int cacheflush(char *start, char *end, int flags) {
- fprintf(stderr, "cacheflush %p %p %d\n", start, end, flags);
+ //fprintf(stderr, "cacheflush %p %p %d\n", start, end, flags);
sys_dcache_flush(start, (size_t) (end - start));
sys_icache_invalidate(start, (size_t) (end - start));
return 0;
@@ -184,22 +184,22 @@ const char *_ctype_ = _C_ctype_;
void *rmmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) {
// Linux and OSX use different values for MAP_ANON(YMOUS)
if(flags & 0x1000) {
- fprintf(stderr, "MAP_EXECUTAbLE\n");
+ //fprintf(stderr, "MAP_EXECUTAbLE\n");
flags &= ~0x1000;
}
if(flags & 0x20) {
- fprintf(stderr, "MAP_RENAME\n");
+ //fprintf(stderr, "MAP_RENAME\n");
flags &= ~0x20;
flags |= MAP_ANON;
}
void *ret = mmap(addr, len, prot, flags, fd, offset);
- fprintf(stderr, "addr:%p len:%d prot:%d flags:%x fd:%d offset:%x\n", addr, (int) len, prot, flags, fd, (int) offset);
- fprintf(stderr, "mmap ret: %p\n", ret);
+ //fprintf(stderr, "addr:%p len:%d prot:%d flags:%x fd:%d offset:%x\n", addr, (int) len, prot, flags, fd, (int) offset);
+ //fprintf(stderr, "mmap ret: %p\n", ret);
return ret;
}
int rmprotect(void *addr, size_t len, int prot) {
- fprintf(stderr, "mprotect %p (%d): %x\n", addr, (int) len, prot);
+ //fprintf(stderr, "mprotect %p (%d): %x\n", addr, (int) len, prot);
return mprotect(addr, len, prot);
}
View
BIN food/food
Binary file not shown.
Oops, something went wrong.

0 comments on commit 82b7841

Please sign in to comment.