Permalink
Browse files

No more flicker on resize; some whitespace changes.

  • Loading branch information...
1 parent e334da7 commit bf53eb962844b9a181c27e0307b8e2de454c40c9 Mobile User committed Jul 11, 2010
Showing with 73 additions and 67 deletions.
  1. +19 −12 food/anp.cpp
  2. +12 −16 food/classes.c
  3. +4 −2 food/common.c
  4. +3 −2 food/common.h
  5. +13 −13 food/food.c
  6. +7 −7 food/food_wrapper.c
  7. +3 −3 food/multistuff.c
  8. +2 −2 food/myjni.c
  9. +10 −10 food/np.c
View
@@ -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);
}
@@ -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);
@@ -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 {
@@ -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;
@@ -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) {
View
@@ -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) {
@@ -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);
}
@@ -200,7 +200,7 @@ jobject getAssetFileDescriptor(jclass cls, jvalue *a) {
_assert(fd > 0);
s(descriptor, "fd", intToTypeRef(fd));
-
+
return new_jobject(descriptor);
}
@@ -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;
}
@@ -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) {
@@ -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"));
@@ -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;
@@ -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;
}
View
@@ -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);
}
@@ -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));
@@ -243,3 +243,5 @@ uint64_t getus() {
return ((uint64_t) tp.tv_sec) * 1000000 + (uint64_t) tp.tv_usec;
}
#endif
+
+bool locked, sfc_dirty;
View
@@ -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
View
@@ -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);
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -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;
@@ -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--) {
@@ -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++;
@@ -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");
View
@@ -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>
@@ -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;
}
@@ -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:
@@ -230,7 +230,7 @@ int main(int argc __attribute__((unused)), char *argv[])
continue;
}
}
-
+
setpgid(0, 0);
View
@@ -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;
Oops, something went wrong.

0 comments on commit bf53eb9

Please sign in to comment.