Skip to content

Commit

Permalink
No more flicker on resize; some whitespace changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobile User authored and Mobile User committed Jul 11, 2010
1 parent e334da7 commit bf53eb9
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 67 deletions.
31 changes: 19 additions & 12 deletions food/anp.cpp
Expand Up @@ -26,6 +26,7 @@ void init_randomctx() {
_assert(randomctx);
}


CGRect rectFromRectF(const ANPRectF rectf) {
return CGRectMake(rectf.left, movie_h - rectf.bottom, rectf.right - rectf.left, rectf.bottom - rectf.top);
}
Expand Down Expand Up @@ -1132,9 +1133,6 @@ static bool cur_dirty_valid;
extern "C" void refresh_size();
bool surface_impl_lock(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI* dirtyRect) {
notice("%s surface=%p", __func__, surface);
if(pending_movie_w != movie_w || pending_movie_h != movie_h) {
refresh_size();
}
if(temp_sz != IOSurfaceGetAllocSize(sfc)) {
log("alloc %d", temp_sz);
if(temp) free(temp);
Expand All @@ -1144,12 +1142,7 @@ bool surface_impl_lock(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI
}
//log("dirtyRect=%p", dirtyRect);
// sanity, not security check, fwiw
if(dirtyRect && (dirtyRect->left >= (int)IOSurfaceGetWidth(sfc) || dirtyRect->top >= (int)IOSurfaceGetHeight(sfc) || dirtyRect->right >= (int)IOSurfaceGetWidth(sfc) || dirtyRect->bottom >= (int)IOSurfaceGetHeight(sfc))) {
dirtyRect = false;
}

if(dirtyRect) {
//log("%d,%d,%d,%d", dirtyRect->left, dirtyRect->top, dirtyRect->right, dirtyRect->bottom);
if(dirtyRect && !(dirtyRect->left >= (int)IOSurfaceGetWidth(sfc) || dirtyRect->top >= (int)IOSurfaceGetHeight(sfc) || dirtyRect->right >= (int)IOSurfaceGetWidth(sfc) || dirtyRect->bottom >= (int)IOSurfaceGetHeight(sfc))) {
cur_dirty_valid = true;
cur_dirty = *dirtyRect;
} else {
Expand All @@ -1160,12 +1153,14 @@ bool surface_impl_lock(JNIEnv* env, jobject surface, ANPBitmap* bitmap, ANPRectI
bitmap->width = sfc ? IOSurfaceGetWidth(sfc) : 0;
bitmap->height = sfc ? IOSurfaceGetHeight(sfc) : 0;
bitmap->rowBytes = bitmap->width * 4;
locked = true;
return true;
}

//#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;
Expand All @@ -1182,18 +1177,30 @@ void surface_impl_unlock(JNIEnv* env, jobject surface) {
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));
}

if(sfc_dirty) {
sfc_dirty = false;
_assertZero(use_surface(food, (int) IOSurfaceGetID(sfc)));
}

if(cur_dirty_valid) {
_assertZero(display_sync(food, cur_dirty.left, cur_dirty.top, cur_dirty.right, cur_dirty.bottom));
} else {
_assertZero(display_sync(food, 0, 0, IOSurfaceGetWidth(sfc), IOSurfaceGetHeight(sfc)));
}
//memcpy(IOSurfaceGetBaseAddress(sfc), temp, IOSurfaceGetAllocSize(sfc));
/*int fd = open("foo.txt", O_WRONLY | O_CREAT, 0755);
write(fd, IOSurfaceGetBaseAddress(sfc), IOSurfaceGetAllocSize(sfc));
close(fd);*/
if(pending_movie_w != movie_w || pending_movie_h != movie_h) {
refresh_size();
}
locked = false;
}
//

extern "C"
void iface_getvalue(NPNVariable typ, ANPInterface *ptr) {
Expand Down
28 changes: 12 additions & 16 deletions food/classes.c
Expand Up @@ -29,7 +29,7 @@ void *make_av(void *a, void *v) {
struct method_generic *entry = RawDataGetPtr(ret);
entry->a = a ? stub(a) : NULL;
entry->v = v ? stub(v) : NULL;
return ret;
return ret;
}

void *make_a(void *func) {
Expand Down Expand Up @@ -168,7 +168,7 @@ void afdClose(jobject obj, jvalue *a) {

jobject afdGetFD(jobject obj, jvalue *a) {
dict descriptor = named_dict("aFileDescriptor");
//s(descriptor,
//s(descriptor,
s(descriptor, "descriptor[I]", CFRetain(g(obj, "fd")));
return new_jobject(descriptor);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ jobject getAssetFileDescriptor(jclass cls, jvalue *a) {

_assert(fd > 0);
s(descriptor, "fd", intToTypeRef(fd));

return new_jobject(descriptor);
}

Expand Down Expand Up @@ -237,11 +237,11 @@ jobject new_fps(jclass cls, va_list v) {
s(fps, "toggleFullScreen[(Z)V]", make_a(toggleFullScreen));
notice("new_fps cls=%p ctx=%p %lx %ld %ld", cls, ctx, one, two, three);
do_jni_onload();

fps_obj = new_jobject(fps);
fps_npp = (void *) one;
refresh_size();

return fps_obj;
}

Expand All @@ -265,7 +265,7 @@ jobject getClassLoader(jobject obj, va_list v) {
}

jobject localeToString(jobject obj, jvalue *a) {
return new_jobject(new_stringobject("en-US"));
return new_jobject(new_stringobject("en-US"));
}

jobject localeGetDefault(jclass cls, jvalue *a) {
Expand Down Expand Up @@ -382,6 +382,7 @@ static IOSurfaceRef make_iosurface() {
return ret;
}


void do_jni_surface_created(NPP npp_, jobject j) {
log("do_jni_surface_created");
int npp = typeRefToInt(g(j, "npp"));
Expand Down Expand Up @@ -410,20 +411,15 @@ void do_jni_surface_changed(NPP npp, jobject j) {
void (*nsch)(JNIEnv *, jobject, jint, jint, jint, jint) = RawPtrGet(g(cls, "nativeSurfaceChanged[(IIII)V]"));
nsch(&env, j, (int) npp, 1 /* rgba 888; 565 => 2; see FPS$2.ddx */, movie_w, movie_h);
notice("ok I called nsch %p", nsch);

if(sfc) {
IOSurfaceRef sfc_ = sfc;
sfc = NULL;
CFRelease(sfc_);
}
sfc = make_iosurface();

_assertZero(use_surface(food, (int) IOSurfaceGetID(sfc)));
sfc_dirty = true;
if(sfc) CFRelease(sfc);
sfc = make_iosurface();
}

jclass system_impl_loadJavaClass(NPP instance, const char* className) {
notice("loadJavaClass: %s", className);

char *cn = strdup(className), *p = cn;
while(1) {
if(!*p) break;
Expand All @@ -450,6 +446,6 @@ int set_movie_size(int rpcfd, int w, int h) {
log("set_movie_size: %dx%d", w, h);
pending_movie_w = w;
pending_movie_h = h;
if(fps_npp && !already_created_surface) refresh_size();
if((fps_npp && !already_created_surface) || !locked) refresh_size();
return 0;
}
6 changes: 4 additions & 2 deletions food/common.c
Expand Up @@ -78,7 +78,7 @@ void *RawPtrGet(const void *value) {
static const void *myRetain(CFAllocatorRef allocator, const void *value) {
struct raw_data *raw = (void *) value;
if(raw->isa == raw_data_isa || raw->isa == raw_ptr_isa) {
raw->retaincount++;
raw->retaincount++;
} else {
CFRetain(value);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ void rpc_init(const char *rpcname) {
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(0x7f000001);
addr.sin_port = htons(atoi(rpcname));

int tru = 1;
setsockopt(serv, SOL_SOCKET, SO_REUSEADDR, &tru, sizeof(tru));
setsockopt(serv, SOL_SOCKET, SO_REUSEPORT, &tru, sizeof(tru));
Expand Down Expand Up @@ -243,3 +243,5 @@ uint64_t getus() {
return ((uint64_t) tp.tv_sec) * 1000000 + (uint64_t) tp.tv_usec;
}
#endif

bool locked, sfc_dirty;
5 changes: 3 additions & 2 deletions food/common.h
Expand Up @@ -97,12 +97,13 @@ void _assertZero_(int test, const char *label, const char *file, int line, const
}
#endif

extern bool locked;
extern IOSurfaceRef sfc;
extern bool sfc_dirty;
extern int food;
extern int movie_w, movie_h, pending_movie_w, pending_movie_h;


#define logreal(fmt, args...) logreal_(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(fmt), ##args))
#define logreal(fmt, args...) logreal_(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(fmt), ##args))

#define logx(level, args...) (LOG_LEVEL >= (level) ? (logreal(args)) : (void)0)
#define LOG_LEVEL 0
Expand Down
26 changes: 13 additions & 13 deletions food/food.c
Expand Up @@ -61,7 +61,7 @@ void *stubify(void *addy, const char *id, bool needs_mprotect) {
base = stubs;
}
void *ret = base;

if(id && STUB_DEBUG) {
// Debug fun!
char *dstr; asprintf(&dstr, "%s called from %%p\n", id);
Expand All @@ -80,7 +80,7 @@ void *stubify(void *addy, const char *id, bool needs_mprotect) {
*base++ = (uint32_t) printf;
*base++ = (uint32_t) dstr;
*base++ = p;
} else {
} else {
*base++ = 0x43f0e92d;
*base++ = 0xe89db007;
*base++ = 0xb08c01f0;
Expand All @@ -91,13 +91,13 @@ void *stubify(void *addy, const char *id, bool needs_mprotect) {

*base++ = p;
}

if(needs_mprotect) {
_assertZero(mprotect(ret, getpagesize(), PROT_READ | PROT_EXEC));
} else {
stubs = base;
}

ret = (char *)ret + 1;
CFDictionarySetValue(existing_stubs, addy, ret);
return ret;
Expand All @@ -122,8 +122,8 @@ int hook_fprintf(FILE *stream, const char *format, ...) {
static void *getsym(char *id) {
if(!strcmp(id, "fprintf")) id = "hook_fprintf";
if(!strcmp(id, "__errno")) id = "__error";
if(!strcmp(id, "mmap")) id = "rmmap";
if(!strcmp(id, "mprotect")) id = "rmprotect";
if(!strcmp(id, "mmap")) id = "rmmap";
if(!strcmp(id, "mprotect")) id = "rmprotect";
if(!strcmp(id, "sysconf")) id = "rsysconf";
if(!strcmp(id, "uname")) id = "runame";
if(!strcmp(id, "__dso_handle")) return &zero;
Expand Down Expand Up @@ -177,7 +177,7 @@ static void base_load_elf(int fd, Elf32_Sym **symtab, int *symtab_size, void ***
if(sz_ > sz) sz = sz_;
free(ph);
}

sz = (sz + 0xfff) & ~0xfff;

reloc_base = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
Expand Down Expand Up @@ -262,7 +262,7 @@ static void base_load_elf(int fd, Elf32_Sym **symtab, int *symtab_size, void ***
Elf32_Word *offset = v2v(rel->r_offset);
Elf32_Word sym = ELF32_R_SYM(rel->r_info);
Elf32_Word type = ELF32_R_TYPE(rel->r_info);

if(type == R_ARM_RELATIVE) {
// notice("Increasing %x which was %x -> %x", offset, *offset, (*offset + (Elf32_Word) reloc_base));
*offset += (Elf32_Word) reloc_base;
Expand All @@ -282,7 +282,7 @@ static void base_load_elf(int fd, Elf32_Sym **symtab, int *symtab_size, void ***
}

do_patches();

lseek(fd, ehdr.e_phoff, SEEK_SET);
phnum = ehdr.e_phnum;
while(phnum--) {
Expand All @@ -307,15 +307,15 @@ static void base_load_elf(int fd, Elf32_Sym **symtab, int *symtab_size, void ***

extern void fds_init();
extern void go(void *NP_Initialize_ptr, void *JNI_OnLoad_ptr);

extern void GSFontInitialize();

int main(int argc, char **argv) {
chdir(dirname(argv[0]));
setvbuf(stdout, NULL, _IONBF, 0);

char *rpcname = NULL;

argc--; argv++;
while(argc--) {
char *p = *argv++;
Expand All @@ -338,15 +338,15 @@ int main(int argc, char **argv) {
stubs = stubs_base;

existing_stubs = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);

add("/usr/lib/libcrypto.dylib");
add("/usr/lib/libssl.dylib");
add("/usr/lib/libm.dylib");
add("/usr/lib/libSystem.B.dylib");
add("./libcutils.dylib");
add("./libutils.dylib");
add("./libgccstuff.dylib");

add("./libicudata.42.1.dylib");
add("./libicui18n.42.1.dylib");
add("./libicuio.42.1.dylib");
Expand Down
14 changes: 7 additions & 7 deletions food/food_wrapper.c
Expand Up @@ -3,19 +3,19 @@
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* @APPLE_APACHE_LICENSE_HEADER_END@
*/
#include <sys/types.h>
Expand Down Expand Up @@ -138,7 +138,7 @@ int main(int argc __attribute__((unused)), char *argv[])

if(kev.udata != NULL) {
syslog(LOG_WARNING, "got a kev with udata %d", (int) kev.udata);
close((int)kev.ident);
close((int)kev.ident);
kill((pid_t)kev.udata, SIGKILL);
continue;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ int main(int argc __attribute__((unused)), char *argv[])
send(r, req, msgsize, 0);
free(req);
free(sekrit);

pid_t pid = fork();
switch (pid) {
case -1:
Expand All @@ -230,7 +230,7 @@ int main(int argc __attribute__((unused)), char *argv[])
continue;
}
}


setpgid(0, 0);

Expand Down
6 changes: 3 additions & 3 deletions food/multistuff.c
Expand Up @@ -379,16 +379,16 @@ jshort impl_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID) {

struct method_void { void (*v)(jobject, va_list); void (*a)(jobject, const jvalue *); };
void impl_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args) {
const void *meth = CFDictionaryGetValue(obj, (CFStringRef)
const void *meth = CFDictionaryGetValue(obj, (CFStringRef)
methodID);
if(!meth) { log("Unknown method (A): %@", methodID); _abort(); }
struct method_void *st;
struct method_void *st;
_assert(st = RawDataGetPtr(meth));
if(!st->a) { log("No A impl: %@", methodID); _abort(); }
st->a(obj, args);
}
void impl_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args) {
const void *meth = CFDictionaryGetValue(obj, (CFStringRef)
const void *meth = CFDictionaryGetValue(obj, (CFStringRef)
methodID);
if(!meth) { log("Unknown method (V): %@", methodID); _abort(); }
struct method_void *st;
Expand Down

0 comments on commit bf53eb9

Please sign in to comment.